mirror of
https://github.com/bitbaum/loki.git
synced 2026-12-04 23:08:38 +01:00
FleetCrown was the last app in the fleet without demo access, and the only one where a careless demo is dangerous: it dispatches agents onto a real box, opens real terminals, and spends real API credit. So the demo is sandboxed rather than read-only. It may create projects, edit prompts and move around its own tenant; everything that leaves that tenant is denied at two independent layers. The layers fail differently on purpose. Layer 1 is a route policy applied in authorized(), which every authenticated request already passes through. Layer 2 sits at enqueuePendingCommand — the single row Fleet Runner polls to type into a shell — and does not import the policy, so widening a list by mistake still cannot reach the machine. The tests are the load-bearing half. A deny-list cannot see what it does not name, and this one shipped two invisible holes while being written: eight entries covered paths the proxy matcher excludes and could never have fired, and /api/agent-tokens — which mints credentials — was missed entirely. Both were found by asserting against what is on disk rather than against a fixture. All 65 API families are now classified, and a new one fails the suite until someone says which it is. The reset deletes a user and everything they own, on an instance whose other rows are real. It refuses without DEMO_ACCESS_ENABLED, resolves its target by email alone with no parameter to point it elsewhere, and derives the child tables from the live foreign-key catalog — a hand-written delete order is exactly what silently rotted on aoz-housing. Co-authored-by: Mao Nakamoto <georgy.butaev@revamp-it.ch> Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
42 lines
1.5 KiB
TypeScript
42 lines
1.5 KiB
TypeScript
/**
|
|
* Create (or recreate) the public demo tenant.
|
|
*
|
|
* DEMO_ACCESS_ENABLED=1 DATABASE_URL=... npx tsx scripts/seed-demo.ts
|
|
*
|
|
* Same code path as the nightly cron — see src/lib/demo-seed.ts for what it
|
|
* seeds and, more importantly, for why the wipe is written the way it is.
|
|
*
|
|
* This is destructive to the demo tenant and only to the demo tenant. It
|
|
* refuses without DEMO_ACCESS_ENABLED=1, and it resolves its target by the demo
|
|
* email rather than by anything passed in.
|
|
*/
|
|
import { resetDemoTenant, DemoDisabledError } from "../src/lib/demo-seed";
|
|
|
|
async function main() {
|
|
const { userId, removed, seeded } = await resetDemoTenant();
|
|
|
|
const removedTotal = Object.values(removed).reduce((a, b) => a + b, 0);
|
|
if (removedTotal > 0) {
|
|
console.log(`removed ${removedTotal} row(s) from the previous demo tenant:`);
|
|
for (const [table, n] of Object.entries(removed).sort()) console.log(` ${table}: ${n}`);
|
|
} else {
|
|
console.log("no previous demo tenant found");
|
|
}
|
|
|
|
console.log(`\nseeded demo user ${userId}:`);
|
|
for (const [kind, n] of Object.entries(seeded).sort()) console.log(` ${kind}: ${n}`);
|
|
console.log("\nSign in at /sign-in — the demo button is now live.");
|
|
}
|
|
|
|
main()
|
|
.then(() => process.exit(0))
|
|
.catch((err) => {
|
|
if (err instanceof DemoDisabledError) {
|
|
console.error(`\n${err.message}`);
|
|
console.error("Set DEMO_ACCESS_ENABLED=1 for the instance that should host the demo.");
|
|
process.exit(2);
|
|
}
|
|
console.error(err);
|
|
process.exit(1);
|
|
});
|