Public: anyone can read this; the crew can change it.
URGENT: check.run in forge.json is over 1000 characters — every pull's check fails instantly #538
scout/forge:scout/533-urgent-check-run-in-forge-json-is-over-1 → main 5 commits fork
8 files
changed +131
−33
README.md +2 −1
| @@ -376,7 +376,8 @@ bun run check:record # the same, and rewrites scripts/test-times.json | ||
| 376 | 376 | |
| 377 | 377 | `bun run check` is the gate: the same command `forge.json` declares, so what |
| 378 | 378 | it says here is what the deploy will say. It type-checks once, then runs the |
| 379 | test files named in `check.run` as parallel `bun test` shards | |
| 379 | test files named in `scripts/test-files.txt` (`check.run` is just | |
| 380 | `bun scripts/check.ts`; the contract caps a command at 1000 characters) as parallel `bun test` shards | |
| 380 | 381 | (`scripts/test-shards.ts`): one per CPU the process may use, at most eight, |
| 381 | 382 | and `FORGE_CHECK_SHARDS=2` turns that down on a small or busy host. Each |
| 382 | 383 | shard's output is written whole as it finishes; the log ends with every |
forge.json +1 −1
| @@ -6,7 +6,7 @@ | ||
| 6 | 6 | "ready": 90 |
| 7 | 7 | }, |
| 8 | 8 | "check": { |
| 9 | "run": "bun x tsc --noEmit && bun scripts/test-shards.ts --timeout 60000 -- crew crew-wrapup crew-limits crew-sandbox steer landing decide ledger checks dependencies autonomy studio studio-words forks fork-flow cross-repo-pull pulls apps apps-adversarial apps-busy apps-token web git-trust helpers shards migrate vitals guard asks feed feed-page offline share cloud run-secrets forge-cloudflare usage standing board-windows spawn-plan spawn web-apps fleet-ops meter", | |
| 9 | "run": "bun scripts/check.ts", | |
| 10 | 10 | "timeout": 1800 |
| 11 | 11 | } |
| 12 | 12 | } |
scripts/check.ts +47 −26
| @@ -1,38 +1,59 @@ | ||
| 1 | 1 | /** |
| 2 | 2 | * The gate, run the way the forge runs it. |
| 3 | 3 | * |
| 4 | * `forge.json`'s `check.run` is the command every push to a pull must pass. | |
| 5 | * A crew member has to be able to see it green before pushing, and the only | |
| 6 | * way that is true is if there is exactly one copy of the command: this | |
| 7 | * reads it from the manifest and hands it to `/bin/sh -c`, which is what | |
| 8 | * `apps/process.ts` does with an app's check on the deploy side. | |
| 4 | * `forge.json`'s `check.run` is `bun scripts/check.ts`: the one command every | |
| 5 | * push to a pull must pass, short because the contract caps it at 1000 | |
| 6 | * characters. A crew member runs the same command before pushing, so there | |
| 7 | * is exactly one copy of it. | |
| 9 | 8 | * |
| 10 | * `--record` runs the same string with `scripts/test-shards.ts --record` | |
| 11 | * in place of `scripts/test-shards.ts`, which rewrites | |
| 12 | * `scripts/test-times.json` from this run, so the file list still lives | |
| 13 | * only in `forge.json`. | |
| 9 | * It validates `forge.json` first (the contract's own parser, so a bad | |
| 10 | * manifest fails in milliseconds with the contract's message), type-checks, | |
| 11 | * then hands the files named in `scripts/test-files.txt` to | |
| 12 | * `scripts/test-shards.ts` and prints how many it ran. | |
| 13 | * | |
| 14 | * `--record` runs the shards with `--record`, which rewrites | |
| 15 | * `scripts/test-times.json` from this run. | |
| 14 | 16 | */ |
| 15 | 17 | |
| 16 | const manifest = (await Bun.file( | |
| 17 | new URL("../forge.json", import.meta.url), | |
| 18 | ).json()) as { check?: { run?: string } }; | |
| 18 | import { parseCheck } from "../src/apps/manifest.ts"; | |
| 19 | 19 | |
| 20 | const command = manifest.check?.run; | |
| 21 | if (typeof command !== "string" || command.trim() === "") { | |
| 20 | const root = new URL("..", import.meta.url).pathname; | |
| 21 | ||
| 22 | const forgeJson = await Bun.file(`${root}forge.json`).text(); | |
| 23 | const checked = parseCheck(forgeJson, undefined); | |
| 24 | if (!checked.ok) { | |
| 25 | console.error( | |
| 26 | checked.error.kind === "invalid" ? checked.error.message : "forge.json is not an app", | |
| 27 | ); | |
| 28 | process.exit(2); | |
| 29 | } | |
| 30 | if (checked.value === undefined) { | |
| 22 | 31 | console.error("forge.json declares no check.run"); |
| 23 | 32 | process.exit(2); |
| 24 | 33 | } |
| 25 | 34 | |
| 26 | const SHARDS = "scripts/test-shards.ts "; | |
| 27 | const record = process.argv.slice(2).includes("--record"); | |
| 28 | if (record && command.split(SHARDS).length !== 2) { | |
| 29 | console.error("--record: check.run must run scripts/test-shards.ts once"); | |
| 30 | process.exit(2); | |
| 31 | } | |
| 32 | const run = record ? command.replace(SHARDS, `${SHARDS}--record `) : command; | |
| 35 | const files = (await Bun.file(`${root}scripts/test-files.txt`).text()) | |
| 36 | .split("\n") | |
| 37 | .map((line) => line.trim()) | |
| 38 | .filter((line) => line !== "" && !line.startsWith("#")); | |
| 39 | console.log(`check: ${files.length} test files from scripts/test-files.txt`); | |
| 33 | 40 | |
| 34 | const proc = Bun.spawn(["/bin/sh", "-c", run], { | |
| 35 | cwd: new URL("..", import.meta.url).pathname, | |
| 36 | stdio: ["inherit", "inherit", "inherit"], | |
| 37 | }); | |
| 38 | process.exit(await proc.exited); | |
| 41 | const record = process.argv.slice(2).includes("--record"); | |
| 42 | ||
| 43 | async function step(argv: string[]): Promise<number> { | |
| 44 | const proc = Bun.spawn(argv, { cwd: root, stdio: ["inherit", "inherit", "inherit"] }); | |
| 45 | return await proc.exited; | |
| 46 | } | |
| 47 | ||
| 48 | const typed = await step(["bun", "x", "tsc", "--noEmit"]); | |
| 49 | if (typed !== 0) process.exit(typed); | |
| 50 | process.exit( | |
| 51 | await step([ | |
| 52 | "bun", | |
| 53 | "scripts/test-shards.ts", | |
| 54 | ...(record ? ["--record"] : []), | |
| 55 | "--timeout", | |
| 56 | "60000", | |
| 57 | ...files, | |
| 58 | ]), | |
| 59 | ); |
scripts/test-files.txt added +47
| @@ -0,0 +1,47 @@ | ||
| 1 | # The test files the gate runs, one per line. forge.json's check.run is | |
| 2 | # capped at 1000 characters, so the list lives here, not there. | |
| 3 | test/crew.test.ts | |
| 4 | test/crew-wrapup.test.ts | |
| 5 | test/crew-limits.test.ts | |
| 6 | test/crew-sandbox.test.ts | |
| 7 | test/steer.test.ts | |
| 8 | test/landing.test.ts | |
| 9 | test/decide.test.ts | |
| 10 | test/ledger.test.ts | |
| 11 | test/checks.test.ts | |
| 12 | test/dependencies.test.ts | |
| 13 | test/autonomy.test.ts | |
| 14 | test/studio.test.ts | |
| 15 | test/studio-words.test.ts | |
| 16 | test/forks.test.ts | |
| 17 | test/fork-flow.test.ts | |
| 18 | test/cross-repo-pull.test.ts | |
| 19 | test/pulls.test.ts | |
| 20 | test/apps.test.ts | |
| 21 | test/apps-adversarial.test.ts | |
| 22 | test/apps-busy.test.ts | |
| 23 | test/apps-token.test.ts | |
| 24 | test/web.test.ts | |
| 25 | test/git-trust.test.ts | |
| 26 | test/helpers.test.ts | |
| 27 | test/shards.test.ts | |
| 28 | test/migrate.test.ts | |
| 29 | test/vitals.test.ts | |
| 30 | test/asks.test.ts | |
| 31 | test/feed.test.ts | |
| 32 | test/feed-page.test.ts | |
| 33 | test/offline.test.ts | |
| 34 | test/share.test.ts | |
| 35 | test/cloud.test.ts | |
| 36 | test/run-secrets.test.ts | |
| 37 | test/forge-cloudflare.test.ts | |
| 38 | test/usage.test.ts | |
| 39 | test/standing.test.ts | |
| 40 | test/board-windows.test.ts | |
| 41 | test/spawn-plan.test.ts | |
| 42 | test/spawn.test.ts | |
| 43 | test/web-apps.test.ts | |
| 44 | test/fleet-ops.test.ts | |
| 45 | test/apps-check-run.test.ts | |
| 46 | test/meter.test.ts | |
| 47 | test/guard.test.ts |
src/apps/manifest.ts +1 −1
| @@ -278,7 +278,7 @@ function command( | ||
| 278 | 278 | return invalid(`forge.json: ${name}.${key} must be a string`); |
| 279 | 279 | if (value.length > COMMAND_MAX) |
| 280 | 280 | return invalid( |
| 281 | `forge.json: ${name}.${key} is longer than ${COMMAND_MAX} characters`, | |
| 281 | `forge.json: ${name}.${key} is longer than ${COMMAND_MAX} characters; put the command in a script and run that (for example \`bun scripts/check.ts\`)`, | |
| 282 | 282 | ); |
| 283 | 283 | if (value.includes("\0") || value.includes("\n")) |
| 284 | 284 | return invalid(`forge.json: ${name}.${key} must be one line`); |
test/apps-busy.test.ts +1 −1
| @@ -203,7 +203,7 @@ describe("apps that are busy", () => { | ||
| 203 | 203 | "an app whose child is still working survives the sweep, then sleeps once it is done", |
| 204 | 204 | async () => { |
| 205 | 205 | await freshlyAwake(); |
| 206 | expect(await (await viaHost("/work?s=2")).text()).toBe("working"); | |
| 206 | expect(await (await viaHost("/work?s=3")).text()).toBe("working"); | |
| 207 | 207 | // Well past the idle window, and still up: it was asked, and it is busy. |
| 208 | 208 | await Bun.sleep(WINDOW + 700); |
| 209 | 209 | expect(production().state).toBe("running"); |
test/apps-check-run.test.ts added +26
| @@ -0,0 +1,26 @@ | ||
| 1 | import { expect, test } from "bun:test"; | |
| 2 | import { readFileSync } from "node:fs"; | |
| 3 | import { parseCheck } from "../src/apps/manifest.ts"; | |
| 4 | ||
| 5 | test("a check.run over 1000 characters names the limit and suggests a script", () => { | |
| 6 | const long = JSON.stringify({ check: { run: "x".repeat(1001) } }); | |
| 7 | const result = parseCheck(long, undefined); | |
| 8 | expect(result.ok).toBe(false); | |
| 9 | if (!result.ok && result.error.kind === "invalid") { | |
| 10 | expect(result.error.message).toContain("1000 characters"); | |
| 11 | expect(result.error.message).toContain("script"); | |
| 12 | } | |
| 13 | }); | |
| 14 | ||
| 15 | test("this repository's own check.run fits the contract", () => { | |
| 16 | const result = parseCheck(readFileSync("forge.json", "utf8"), undefined); | |
| 17 | expect(result.ok).toBe(true); | |
| 18 | }); | |
| 19 | ||
| 20 | test("every file in scripts/test-files.txt exists", () => { | |
| 21 | const files = readFileSync("scripts/test-files.txt", "utf8") | |
| 22 | .split("\n") | |
| 23 | .filter((l) => l !== "" && !l.startsWith("#")); | |
| 24 | expect(files.length).toBeGreaterThan(0); | |
| 25 | for (const f of files) expect(() => readFileSync(f)).not.toThrow(); | |
| 26 | }); |
test/shards.test.ts +6 −3
| @@ -295,14 +295,17 @@ describe("splitArgs", () => { | ||
| 295 | 295 | expect(splitArgs(["--", name]).ok).toBe(false); |
| 296 | 296 | }); |
| 297 | 297 | |
| 298 | test("forge.json's check fits the manifest and names only files that exist", async () => { | |
| 298 | test("forge.json's check fits the manifest and its test list names only files that exist", async () => { | |
| 299 | 299 | const text = readFileSync(new URL("../forge.json", import.meta.url), "utf8"); |
| 300 | 300 | // The forge's own reading of the manifest, which is what refused it. |
| 301 | 301 | const check = parseCheck(text, undefined); |
| 302 | 302 | expect(check.ok).toBe(true); |
| 303 | 303 | if (!check.ok || check.value === undefined) throw new Error("no check"); |
| 304 | const run = check.value.run; | |
| 305 | const args = run.slice(run.indexOf("scripts/test-shards.ts ") + 23).split(" "); | |
| 304 | // The command is short; the files it runs are listed in scripts/test-files.txt. | |
| 305 | const args = readFileSync(new URL("../scripts/test-files.txt", import.meta.url), "utf8") | |
| 306 | .split("\n") | |
| 307 | .map((line) => line.trim()) | |
| 308 | .filter((line) => line !== "" && !line.startsWith("#")); | |
| 306 | 309 | const split = splitArgs(args); |
| 307 | 310 | expect(split.ok).toBe(true); |
| 308 | 311 | if (!split.ok) return; |
new above
offline