Public: anyone can read this; the crew can change it.
The gate every push is judged by runs 23 of the repository's 113 test files #300
mason/forge:mason/261-the-gate-every-push-is-judged-by-runs-23 → main 2 commits fork
11 files
changed +248
−5
CLAUDE.md +6
| @@ -74,6 +74,12 @@ bun run src/main.ts # boots on :3000, data in ./data | ||
| 74 | 74 | the reason is printed so a skip is never read as a pass. |
| 75 | 75 | - **`bun run check` is the gate**, and it reads its command from |
| 76 | 76 | `forge.json`, so what you see is exactly what the push will be judged by. |
| 77 | It covers the whole suite: `scripts/suite.ts` runs every `test/*.test.ts`, | |
| 78 | so a file you add is in the gate the moment it exists. The few it does not | |
| 79 | run are listed in `EXCLUDED` in that file, each with a one-line reason and | |
| 80 | the issue that puts it back — `test/check-list.test.ts` makes an exclusion | |
| 81 | without a reason, an issue, or a file on disk red. Never hand the check a | |
| 82 | list of test files; that hole cost the crew #238, #253 and #261. | |
| 77 | 83 | - **Every non-trivial change ships with a test.** Prefer protocol-level tests |
| 78 | 84 | that boot a real app (`createApp` + `serve`) over unit mocks. Adversarial |
| 79 | 85 | tests (can this be bypassed?) are worth more than happy-path ones. |
README.md +4 −1
| @@ -302,7 +302,10 @@ bun run check # exactly what the forge runs against every push | ||
| 302 | 302 | |
| 303 | 303 | |
| 304 | 304 | `bun run check` is the gate: the same command `forge.json` declares, so what |
| 305 | it says here is what the deploy will say. Two things it will not do: | |
| 305 | it says here is what the deploy will say. It types the tree and then runs the | |
| 306 | whole suite — `scripts/suite.ts` starts from every `test/*.test.ts`, so a new | |
| 307 | test file is judged from the moment it exists, and the handful it leaves out | |
| 308 | are listed there with a reason and an issue each. Two things it will not do: | |
| 306 | 309 | |
| 307 | 310 | - **It never borrows your git configuration.** A test drives a real `git` |
| 308 | 311 | against a forge it booted a second ago, and builds that child's |
forge.json +1 −1
| @@ -6,7 +6,7 @@ | ||
| 6 | 6 | "ready": 90 |
| 7 | 7 | }, |
| 8 | 8 | "check": { |
| 9 | "run": "bun x tsc --noEmit && bun test --timeout 60000 test/crew.test.ts test/crew-wrapup.test.ts test/crew-limits.test.ts test/crew-sandbox.test.ts test/steer.test.ts test/landing.test.ts test/decide.test.ts test/ledger.test.ts test/checks.test.ts test/dependencies.test.ts test/autonomy.test.ts test/studio.test.ts test/studio-words.test.ts test/forks.test.ts test/fork-flow.test.ts test/cross-repo-pull.test.ts test/pulls.test.ts test/repos.test.ts test/apps.test.ts test/apps-adversarial.test.ts test/web.test.ts test/git-trust.test.ts test/helpers.test.ts", | |
| 9 | "run": "bun x tsc --noEmit && bun run scripts/suite.ts", | |
| 10 | 10 | "timeout": 1800 |
| 11 | 11 | } |
| 12 | 12 | } |
scripts/suite.ts added +100
| @@ -0,0 +1,100 @@ | ||
| 1 | /** | |
| 2 | * The suite the gate runs: every `test/*.test.ts`, minus a short list that | |
| 3 | * says out loud why each one is out. | |
| 4 | * | |
| 5 | * The gate used to name its files by hand, so a new test file joined the | |
| 6 | * suite and the gate ignored it — silently, forever (#261). The default is | |
| 7 | * inverted here: a file in `test/` is in the gate the moment it exists, and | |
| 8 | * leaving one out costs an entry in `EXCLUDED` with a reason and the issue | |
| 9 | * that will put it back. `test/check-list.test.ts` makes that mechanical — | |
| 10 | * an exclusion with no reason, no issue, or no file on disk is red. | |
| 11 | * | |
| 12 | * Run as a script (this is what `forge.json`'s `check.run` calls), it spawns | |
| 13 | * `bun test` over exactly that set and exits with its status. | |
| 14 | */ | |
| 15 | ||
| 16 | import { readdirSync } from "node:fs"; | |
| 17 | ||
| 18 | /** One test file the gate does not run, and the reason a reader can check. */ | |
| 19 | export type Exclusion = { | |
| 20 | /** Path from the repository root, e.g. `test/looks.test.ts`. */ | |
| 21 | readonly file: string; | |
| 22 | /** One line: why it is out, ending in the issue that puts it back. */ | |
| 23 | readonly reason: string; | |
| 24 | }; | |
| 25 | ||
| 26 | /** | |
| 27 | * Measured on 2026-09-22 against `7a83d99`: the whole suite is 1737 tests | |
| 28 | * across 114 files in 8m31s — inside the check's 1800s timeout — with 23 | |
| 29 | * red. Each red file is below with the issue that owns it. Nothing else is | |
| 30 | * excluded: slow is not a reason while the suite fits. | |
| 31 | */ | |
| 32 | export const EXCLUDED: readonly Exclusion[] = [ | |
| 33 | { | |
| 34 | file: "test/web-apps.test.ts", | |
| 35 | reason: | |
| 36 | "9 red: asserts dashboard and repo headings the studio redesign moved (#290)", | |
| 37 | }, | |
| 38 | { | |
| 39 | file: "test/web-code.test.ts", | |
| 40 | reason: "4 red: asserts the pre-studio search page and repo rows (#291)", | |
| 41 | }, | |
| 42 | { | |
| 43 | file: "test/web-origins.test.ts", | |
| 44 | reason: "1 red: asserts the dashboard's old 'On your machine' card (#291)", | |
| 45 | }, | |
| 46 | { | |
| 47 | file: "test/ssh-site.test.ts", | |
| 48 | reason: "1 red: asserts the dashboard's old Terminal card (#291)", | |
| 49 | }, | |
| 50 | { | |
| 51 | file: "test/looks.test.ts", | |
| 52 | reason: "1 red: asserts the studio look ask's pre-redesign markup (#291)", | |
| 53 | }, | |
| 54 | { | |
| 55 | file: "test/surfaces-adversarial.test.ts", | |
| 56 | reason: "2 red: /apps and the dashboard cards query per row again (#292)", | |
| 57 | }, | |
| 58 | { | |
| 59 | file: "test/agents.test.ts", | |
| 60 | reason: "1 red: fifty concurrent pushes lose auth on the hook socket (#293)", | |
| 61 | }, | |
| 62 | { | |
| 63 | file: "test/highlight.test.ts", | |
| 64 | reason: | |
| 65 | "1 red: a 10,000-character line scans in 25ms against a 10ms bound (#294)", | |
| 66 | }, | |
| 67 | ]; | |
| 68 | ||
| 69 | /** The repository root, wherever this file is run from. */ | |
| 70 | const root = new URL("..", import.meta.url).pathname; | |
| 71 | ||
| 72 | /** Every `test/*.test.ts`, sorted, whether or not the gate runs it. */ | |
| 73 | export function allTestFiles(): string[] { | |
| 74 | return readdirSync(new URL("../test", import.meta.url)) | |
| 75 | .filter((name) => name.endsWith(".test.ts")) | |
| 76 | .map((name) => `test/${name}`) | |
| 77 | .sort(); | |
| 78 | } | |
| 79 | ||
| 80 | /** The files the gate runs: everything, minus `EXCLUDED`. */ | |
| 81 | export function suiteFiles(): string[] { | |
| 82 | const out = new Set(EXCLUDED.map((one) => one.file)); | |
| 83 | return allTestFiles().filter((file) => !out.has(file)); | |
| 84 | } | |
| 85 | ||
| 86 | if (import.meta.main) { | |
| 87 | const files = suiteFiles(); | |
| 88 | const skipped = EXCLUDED.length; | |
| 89 | console.log( | |
| 90 | `suite: ${files.length} test files` + | |
| 91 | (skipped === 0 | |
| 92 | ? "" | |
| 93 | : `, ${skipped} excluded (scripts/suite.ts says why)`), | |
| 94 | ); | |
| 95 | const proc = Bun.spawn(["bun", "test", "--timeout", "60000", ...files], { | |
| 96 | cwd: root, | |
| 97 | stdio: ["inherit", "inherit", "inherit"], | |
| 98 | }); | |
| 99 | process.exit(await proc.exited); | |
| 100 | } |
src/kernel/log.ts +10
| @@ -42,6 +42,16 @@ export function setLogLevel(level: LogLevel): void { | ||
| 42 | 42 | threshold = level; |
| 43 | 43 | } |
| 44 | 44 | |
| 45 | /** | |
| 46 | * The floor in force. One process holds one of these, and the suite runs | |
| 47 | * every test file in one process: a caller that lowers the floor for a | |
| 48 | * moment needs to be able to put back what it found rather than guess the | |
| 49 | * default (#261). | |
| 50 | */ | |
| 51 | export function logLevel(): LogLevel { | |
| 52 | return threshold; | |
| 53 | } | |
| 54 | ||
| 45 | 55 | export function createLog(scope: string): Log { |
| 46 | 56 | const emit = (level: LogLevel, message: string, fields?: LogFields) => { |
| 47 | 57 | if (order[level] < order[threshold]) return; |
src/origins/mirror.ts +10 −1
| @@ -62,9 +62,18 @@ export interface MirrorResult { | ||
| 62 | 62 | /** |
| 63 | 63 | * How long to wait between tries of a new mirror's first fetch. Mutable so a |
| 64 | 64 | * test that wants a failure now can have it now; the forge keeps the default. |
| 65 | * | |
| 66 | * It is one object for the whole process, so a test that shortens it owns | |
| 67 | * putting `DEFAULT_FIRST_FETCH_RETRY_MS` back — the suite runs every file in | |
| 68 | * one process, and a file that inherits somebody else's 50ms is red for a | |
| 69 | * reason that is not in it (#261). | |
| 65 | 70 | */ |
| 71 | export const DEFAULT_FIRST_FETCH_RETRY_MS: readonly number[] = [ | |
| 72 | 2_000, 5_000, 10_000, | |
| 73 | ]; | |
| 74 | ||
| 66 | 75 | export const firstFetchRetry = { |
| 67 | ms: [2_000, 5_000, 10_000] as readonly number[], | |
| 76 | ms: DEFAULT_FIRST_FETCH_RETRY_MS, | |
| 68 | 77 | }; |
| 69 | 78 | |
| 70 | 79 | export async function mirrorRepo( |
test/check-list.test.ts added +86
| @@ -0,0 +1,86 @@ | ||
| 1 | /** | |
| 2 | * The gate covers the suite, and can only stop covering it out loud. | |
| 3 | * | |
| 4 | * For a long while `forge.json`'s check named its test files by hand: 23 of | |
| 5 | * 114, so a file that joined the suite was never run before a push and rotted | |
| 6 | * unseen — twice found red on `main` after the fact (#238, #253, then #261). | |
| 7 | * The list is gone; `scripts/suite.ts` starts from every `test/*.test.ts` and | |
| 8 | * subtracts an explicit `EXCLUDED`. These tests are what keeps that true: a | |
| 9 | * file left out needs a reason and an issue, an exclusion for a file that no | |
| 10 | * longer exists is a stale claim, and a check command that names test files | |
| 11 | * is the old hand-list coming back. | |
| 12 | */ | |
| 13 | ||
| 14 | import { describe, expect, test } from "bun:test"; | |
| 15 | import { existsSync } from "node:fs"; | |
| 16 | import { allTestFiles, EXCLUDED, suiteFiles } from "../scripts/suite.ts"; | |
| 17 | ||
| 18 | const manifest = (await Bun.file( | |
| 19 | new URL("../forge.json", import.meta.url), | |
| 20 | ).json()) as { check?: { run?: string; timeout?: number } }; | |
| 21 | ||
| 22 | const command = manifest.check?.run ?? ""; | |
| 23 | ||
| 24 | describe("the gate in forge.json", () => { | |
| 25 | test("runs the suite through scripts/suite.ts, and names no test file itself", () => { | |
| 26 | expect(command).toContain("scripts/suite.ts"); | |
| 27 | // A hand-written list is the hole this closes: any `.test.ts` in the | |
| 28 | // command means files are being chosen one at a time again. | |
| 29 | expect(command).not.toContain(".test.ts"); | |
| 30 | // Types first, then the suite — the gate a crew member runs locally with | |
| 31 | // `bun run check` is this exact string (`scripts/check.ts`). | |
| 32 | expect(command).toContain("tsc --noEmit"); | |
| 33 | }); | |
| 34 | ||
| 35 | test("declares the timeout the measured suite fits in", () => { | |
| 36 | // 1737 tests across 114 files took 8m31s on a crew machine (#261). | |
| 37 | expect(manifest.check?.timeout ?? 0).toBeGreaterThanOrEqual(1800); | |
| 38 | }); | |
| 39 | }); | |
| 40 | ||
| 41 | describe("every test file is in the gate, or excluded for a stated reason", () => { | |
| 42 | test("no file is in neither", () => { | |
| 43 | const covered = new Set([ | |
| 44 | ...suiteFiles(), | |
| 45 | ...EXCLUDED.map((one) => one.file), | |
| 46 | ]); | |
| 47 | const orphans = allTestFiles().filter((file) => !covered.has(file)); | |
| 48 | expect(orphans).toEqual([]); | |
| 49 | }); | |
| 50 | ||
| 51 | test("the gate is every test file minus exactly the exclusions", () => { | |
| 52 | expect(suiteFiles().length).toBe(allTestFiles().length - EXCLUDED.length); | |
| 53 | for (const one of EXCLUDED) expect(suiteFiles()).not.toContain(one.file); | |
| 54 | }); | |
| 55 | ||
| 56 | test("each exclusion names a test file that exists", () => { | |
| 57 | const known = new Set(allTestFiles()); | |
| 58 | for (const one of EXCLUDED) { | |
| 59 | expect(one.file.startsWith("test/") && one.file.endsWith(".test.ts")).toBe( | |
| 60 | true, | |
| 61 | ); | |
| 62 | // A file that was deleted or renamed leaves an exclusion that quietly | |
| 63 | // covers nothing; the entry has to go when the file does. | |
| 64 | expect(`${one.file} exists`).toBe( | |
| 65 | `${one.file} ${known.has(one.file) ? "exists" : "is gone"}`, | |
| 66 | ); | |
| 67 | expect(existsSync(new URL(`../${one.file}`, import.meta.url))).toBe(true); | |
| 68 | } | |
| 69 | }); | |
| 70 | ||
| 71 | test("each exclusion carries a one-line reason and the issue that ends it", () => { | |
| 72 | for (const one of EXCLUDED) { | |
| 73 | const reason = one.reason.trim(); | |
| 74 | expect(`${one.file}: ${reason.length > 20}`).toBe(`${one.file}: true`); | |
| 75 | expect(reason).not.toContain("\n"); | |
| 76 | // Not a note — a ticket. Something outside the gate is work someone | |
| 77 | // owns, and the number is how a reader finds out whether it is done. | |
| 78 | expect(`${one.file}: ${/#\d+/.test(reason)}`).toBe(`${one.file}: true`); | |
| 79 | } | |
| 80 | }); | |
| 81 | ||
| 82 | test("no file is excluded twice", () => { | |
| 83 | const files = EXCLUDED.map((one) => one.file); | |
| 84 | expect([...new Set(files)].length).toBe(files.length); | |
| 85 | }); | |
| 86 | }); |
test/fork-flow.test.ts +8
| @@ -7,6 +7,10 @@ import { serve, type Servers } from "../src/http/server.ts"; | ||
| 7 | 7 | import { resetConnectLimit } from "../src/actions/origins.ts"; |
| 8 | 8 | import { listEvents } from "../src/core/events.ts"; |
| 9 | 9 | import { settled } from "../src/origins/jobs.ts"; |
| 10 | import { | |
| 11 | DEFAULT_FIRST_FETCH_RETRY_MS, | |
| 12 | firstFetchRetry, | |
| 13 | } from "../src/origins/mirror.ts"; | |
| 10 | 14 | import { |
| 11 | 15 | mirrorAndWait, |
| 12 | 16 | newFakeState, |
| @@ -156,6 +160,10 @@ describe("the fork flow", () => { | ||
| 156 | 160 | }; |
| 157 | 161 | |
| 158 | 162 | beforeAll(async () => { |
| 163 | // "a mirror whose git is not ready yet" below seeds the upstream inside | |
| 164 | // the first retry's wait, so it needs the forge's own patience, not the | |
| 165 | // 50ms another file in this process may have left behind (#261). | |
| 166 | firstFetchRetry.ms = DEFAULT_FIRST_FETCH_RETRY_MS; | |
| 159 | 167 | dataDir = await mkdtemp(join(tmpdir(), "forge-ff-")); |
| 160 | 168 | originDataDir = await mkdtemp(join(tmpdir(), "forge-ff-up-")); |
| 161 | 169 |
test/origins-security-auth.test.ts +11 −1
| @@ -1,5 +1,8 @@ | ||
| 1 | 1 | import { afterAll, beforeAll, describe, expect, test } from "bun:test"; |
| 2 | import { firstFetchRetry } from "../src/origins/mirror.ts"; | |
| 2 | import { | |
| 3 | DEFAULT_FIRST_FETCH_RETRY_MS, | |
| 4 | firstFetchRetry, | |
| 5 | } from "../src/origins/mirror.ts"; | |
| 3 | 6 | import { mkdtemp, readFile, rm } from "node:fs/promises"; |
| 4 | 7 | import { tmpdir } from "node:os"; |
| 5 | 8 | import { join } from "node:path"; |
| @@ -136,6 +139,12 @@ describe("OAuth code flow: state, PKCE, redirects, and the callback URI", () => | ||
| 136 | 139 | beforeAll(async () => { |
| 137 | 140 | // A fetch that fails should say so now, not after the forge's patience. |
| 138 | 141 | firstFetchRetry.ms = [50]; |
| 142 | // Whatever the machine thinks this forge's address is: these tests decide | |
| 143 | // when `FORGE_URL` is set, and the redirect URI they expect is the one | |
| 144 | // their own server is listening on. A crew machine exports `FORGE_URL` | |
| 145 | // for its own forge, and inheriting it turns every exchange below into | |
| 146 | // `redirect_uri mismatch` (#261). | |
| 147 | delete process.env.FORGE_URL; | |
| 139 | 148 | dataDir = await mkdtemp(join(tmpdir(), "forge-sec-code-")); |
| 140 | 149 | const state = newFakeState("forgejo", LOGIN, ORIGIN_TOKEN); |
| 141 | 150 | oauth = newFakeOAuth(CLIENT_ID); |
| @@ -154,6 +163,7 @@ describe("OAuth code flow: state, PKCE, redirects, and the callback URI", () => | ||
| 154 | 163 | }); |
| 155 | 164 | }); |
| 156 | 165 | afterAll(async () => { |
| 166 | firstFetchRetry.ms = DEFAULT_FIRST_FETCH_RETRY_MS; | |
| 157 | 167 | delete process.env.FORGE_URL; |
| 158 | 168 | fake.stop(); |
| 159 | 169 | servers.stop(); |
test/view-source.test.ts +5 −1
| @@ -6,7 +6,10 @@ import { createApp, type App } from "../src/app.ts"; | ||
| 6 | 6 | import { serve, type Servers } from "../src/http/server.ts"; |
| 7 | 7 | import { resetConnectLimit } from "../src/actions/origins.ts"; |
| 8 | 8 | import { getUserByName, type User } from "../src/core/users.ts"; |
| 9 | import { firstFetchRetry } from "../src/origins/mirror.ts"; | |
| 9 | import { | |
| 10 | DEFAULT_FIRST_FETCH_RETRY_MS, | |
| 11 | firstFetchRetry, | |
| 12 | } from "../src/origins/mirror.ts"; | |
| 10 | 13 | import { settled, subscribe, type MirrorStage } from "../src/origins/jobs.ts"; |
| 11 | 14 | import { forgetProviders } from "../src/origins/providers/index.ts"; |
| 12 | 15 | import { |
| @@ -295,6 +298,7 @@ describe("RepoSource: one repository, two places to read it from", () => { | ||
| 295 | 298 | }); |
| 296 | 299 | |
| 297 | 300 | afterAll(async () => { |
| 301 | firstFetchRetry.ms = DEFAULT_FIRST_FETCH_RETRY_MS; | |
| 298 | 302 | fake.stop(); |
| 299 | 303 | servers.stop(); |
| 300 | 304 | originServers.stop(); |
test/web.test.ts +7
| @@ -16,6 +16,7 @@ import { renderMarkdown } from "../src/web/markdown.ts"; | ||
| 16 | 16 | import { highlightAsset } from "../src/web/asset.ts"; |
| 17 | 17 | import { securityFloor } from "../src/http/respond.ts"; |
| 18 | 18 | import { THEME_NAMES } from "../src/design/themes.ts"; |
| 19 | import { logLevel, setLogLevel } from "../src/kernel/log.ts"; | |
| 19 | 20 | import { gitClientEnv } from "./helpers/git-client.ts"; |
| 20 | 21 | |
| 21 | 22 | describe("html template", () => { |
| @@ -836,6 +837,11 @@ describe("a refused cross-origin mutation says why in the log", () => { | ||
| 836 | 837 | console.log = wrote; |
| 837 | 838 | console.warn = wrote; |
| 838 | 839 | console.error = wrote; |
| 840 | // The line under test is a WARN, and the floor is one global for the | |
| 841 | // whole process: a file that ran earlier and left it at "error" would | |
| 842 | // drop the line and make this read as "the forge logged nothing" (#261). | |
| 843 | const floor = logLevel(); | |
| 844 | setLogLevel("info"); | |
| 839 | 845 | let response: Response; |
| 840 | 846 | try { |
| 841 | 847 | response = await fetch(`${base}/signup`, { |
| @@ -849,6 +855,7 @@ describe("a refused cross-origin mutation says why in the log", () => { | ||
| 849 | 855 | redirect: "manual", |
| 850 | 856 | }); |
| 851 | 857 | } finally { |
| 858 | setLogLevel(floor); | |
| 852 | 859 | console.log = real.log; |
| 853 | 860 | console.warn = real.warn; |
| 854 | 861 | console.error = real.error; |
new above
offline