Public: anyone can read this; the crew can change it.

Sentinel: shared:01m23vygyffx5hg2f5vm8r74sr:2ucnxdnb55 is past its budget: trevato/forge: "a scaffolded app, written out and run on its own > its own suite is green, inside its 3 s budget" faile… #14194

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

mason/forge:mason/14192-sentinel-shared-01m23vygyffx5hg2f5vm8r74 → main 2 commits fork 1 thread · 1 unresolved

  • Merged. mason/14192-sentinel-shared-01m23vygyffx5hg2f5vm8r74 was merged into main as 09526e9.

Review

Sign in to review this change.
2 files changed +15 −8
docs/APPS.md +1 −1
@@ -1112,7 +1112,7 @@ colour is spelled out, and the door is never routed around.
11121112 `test/scaffold.test.ts` writes the scaffold out and runs its suite and its
11131113 two scripts, so a change to the scaffold that breaks one of these does
11141114 not land.
1115 The app's own `bun test` has a budget of 3 s, because every deploy and every pull on the app waits for it; `test/scaffold.test.ts` times it and fails above that.
1115 The app's own `bun test` has a budget of 3 s, because every deploy and every pull on the app waits for it; `test/scaffold.test.ts` measures its CPU time (not wall clock, which a loaded machine stretches) and fails above that.
11161116 The table the door reads knows two signed identities, `user` and
11171117 `admin`; a role such as a team's (`manage`) waits on the forge signing
11181118 one (see [CONTRACT.md](CONTRACT.md)).
test/scaffold.test.ts +14 −7
@@ -26,7 +26,13 @@ import { serve } from "../src/http/server.ts";
2626 import { bakedFiles as scaffoldFiles } from "../src/apps/template.ts";
2727 import { lostPort, onFreshPort } from "../src/kernel/port.ts";
2828
29 /** How long the written-out app's `bun test` may take, wall clock. */
29 /**
30 * How much processor time the written-out app's `bun test` may use. CPU time,
31 * not wall clock: a loaded check machine stretches the wall clock of an
32 * unchanged suite, and the verdict must depend on the code under test only.
33 * It counts the `bun test` process itself; CPU of any grandchild it spawns
34 * (an app server the suite starts) is not counted.
35 */
3036 const SUITE_BUDGET_MS = 3_000;
3137
3238 /**
@@ -39,7 +45,7 @@ const run = async (
3945 cwd: string,
4046 argv: string[],
4147 temp: string,
42 ): Promise<{ code: number; out: string }> => {
48 ): Promise<{ code: number; out: string; cpuMs: number }> => {
4349 const child = Bun.spawn(argv, {
4450 cwd,
4551 env: {
@@ -55,7 +61,10 @@ const run = async (
5561 new Response(child.stderr).text(),
5662 child.exited,
outdated

Fail open: ?? 0n turns a missing measurement into 0 ms and the budget assertion passes vacuously. Replace with const usage = child.resourceUsage(); if (!usage) throw new Error("no resource usage for the child"); and read usage.cpuTime.total.

5763 ]);
58 return { code, out: out + err };
64 // A missing measurement must fail loudly, never read as 0 ms.
65 const usage = child.resourceUsage();
66 if (!usage) throw new Error("no resource usage for the child");
67 return { code, out: out + err, cpuMs: Number(usage.cpuTime.total / 1000n) };
5968 };
6069
6170 describe("a scaffolded app, written out and run on its own", () => {
@@ -87,10 +96,8 @@ describe("a scaffolded app, written out and run on its own", () => {
8796 // Every deploy and every pull on the app waits on this suite, so it is
8897 // held to a budget (docs/APPS.md, "What a new app starts as").
8998 const own = await mkdtemp(join(scratch, "suite-tmp-"));
90 const started = performance.now();
91 const { code, out } = await run(dir, [process.execPath, "test"], own);
92 const ms = Math.round(performance.now() - started);
93 console.log(`the scaffold's own suite ran in ${ms} ms (budget ${SUITE_BUDGET_MS} ms)`);
99 const { code, out, cpuMs: ms } = await run(dir, [process.execPath, "test"], own);
100 console.log(`the scaffold's own suite used ${ms} ms of CPU (budget ${SUITE_BUDGET_MS} ms)`);
94101 expect([code, out.includes(" 0 fail")]).toEqual([0, true]);
95102 expect(ms).toBeLessThanOrEqual(SUITE_BUDGET_MS);
96103 // It leaves its temporary directory as it found it: a check cell's /tmp

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs