Public: anyone can read this; the crew can change it.
Crew: run the game agent tests in ubuntu:24.04 before an agent.sh release, recorded on the release #18274
Merged 5h 51m ago, live in production
scout/forge:scout/18271-crew-run-the-game-agent-tests-in-ubuntu → main 0 commits fork
8 files
changed +321
−6
docs/ops/ROLL.md +9
| @@ -148,6 +148,15 @@ tag `v<version>` whose message is the release record (`{"version", | ||
| 148 | 148 | "migrations", "ids"}`); push that tag to the forge's own repository, where |
| 149 | 149 | `release/shipped.ts` reads it for `/releases.json`, the children's standings |
| 150 | 150 | and the behind watch, and to the mirror, where it starts `release.yml`. |
| 151 | When the commit changes `src/games/agent.sh` since the last tag, `--tag` first | |
| 152 | runs the game agent tests (`test/game-agent-*.test.ts`) in `ubuntu:24.04` with | |
| 153 | docker (the box's OS), refuses the tag if they fail, and records | |
| 154 | `"agentTests": {"image", "files", "at"}` in the tag message (#18271). The | |
| 155 | container installs curl and jq first (the one use of the network) and fails if a tool is missing, | |
| 156 | so skipped tests cannot pass. The release keeper's own cut does not run them: when agent.sh | |
| 157 | changed since the last tag it writes `"agentUnchecked": true` in the record instead. Both are | |
| 158 | shown: `/releases.json` carries an `agentTests` sentence on such a release and the terminal's | |
| 159 | changelog row repeats it. | |
| 151 | 160 | Nothing is committed: a commit to main would void every gate in flight |
| 152 | 161 | (#6640). `src/core/releases-before-tags.json` keeps the releases cut before |
| 153 | 162 | this, frozen. |
scripts/cut-release.ts +34 −1
| @@ -9,6 +9,15 @@ | ||
| 9 | 9 | * stderr, the load check to run before the tag is pushed (`release-load.ts`, #9504). |
| 10 | 10 | */ |
| 11 | 11 | |
| 12 | import { readdirSync } from "node:fs"; | |
| 13 | import { | |
| 14 | AGENT_IMAGE, | |
| 15 | AGENT_SCRIPT, | |
| 16 | agentTestFiles, | |
| 17 | decideAgentTests, | |
| 18 | dockerArgs, | |
| 19 | withAgentTests, | |
| 20 | } from "../src/release/agent_tests.ts"; | |
| 12 | 21 | import { migrationFiles, NUMBERED } from "../src/core/schema.ts"; |
| 13 | 22 | import { loadCheckHint } from "../src/perf/baseline.ts"; |
| 14 | 23 | import { compareVersions } from "../src/kernel/versions.ts"; |
| @@ -26,7 +35,31 @@ if (newest !== undefined && compareVersions(version, newest.version) <= 0) { | ||
| 26 | 35 | console.error(`cut-release: ${version} is not newer than ${newest.version}, the newest release`); |
| 27 | 36 | process.exit(1); |
| 28 | 37 | } |
| 29 | const record = JSON.stringify(recordFor(version, migrationFiles, NUMBERED)); | |
| 38 | // The standing rule (#18271): a release that changes agent.sh runs the game agent tests in | |
| 39 | // ubuntu:24.04 first, and says so on the record; a red run cuts nothing. | |
| 40 | const git = (args: string[]) => Bun.spawnSync(["git", ...args], { cwd: root, stderr: "pipe" }); | |
| 41 | const lines = (r: { stdout: Buffer }) => r.stdout.toString().split("\n").filter((l) => l !== ""); | |
| 42 | const tip = newest === undefined ? undefined : git(["rev-parse", "--verify", "--quiet", `refs/tags/v${newest.version}^{commit}`]); | |
| 43 | const base = tip !== undefined && tip.exitCode === 0 ? tip.stdout.toString().trim() : undefined; | |
| 44 | // With no tag to compare to, the agent is taken as changed. | |
| 45 | const changed = base === undefined ? undefined : lines(git(["diff", "--name-only", `${base}..HEAD`, "--", AGENT_SCRIPT])); | |
| 46 | // Without --tag nothing is cut, so nothing is run: the record is only printed. | |
| 47 | const verdict = decideAgentTests({ | |
| 48 | changed, | |
| 49 | tag: flag === "--tag", | |
| 50 | files: agentTestFiles(readdirSync(`${root}/test`).map((n) => `test/${n}`)), | |
| 51 | now: Date.now, | |
| 52 | run: (files) => { | |
| 53 | console.error(`cut-release: ${AGENT_SCRIPT} changed; running ${files.length} game agent test files in ${AGENT_IMAGE}`); | |
| 54 | return Bun.spawnSync(dockerArgs(root, process.execPath, files), { stdout: "inherit", stderr: "inherit" }).exitCode; | |
| 55 | }, | |
| 56 | }); | |
| 57 | if ("refuse" in verdict) { | |
| 58 | console.error(`cut-release: ${verdict.refuse}; no release cut`); | |
| 59 | process.exit(1); | |
| 60 | } | |
| 61 | const agentTests = verdict.agentTests; | |
| 62 | const record = JSON.stringify(withAgentTests(recordFor(version, migrationFiles, NUMBERED), agentTests)); | |
| 30 | 63 | if (flag === "--tag") { |
| 31 | 64 | const made = Bun.spawnSync(["git", "tag", "--annotate", "--file=-", `v${version}`, "HEAD"], { |
| 32 | 65 | cwd: root, |
src/keeper/wire.ts +15 −1
| @@ -30,6 +30,7 @@ import { bootStall } from "../perf/live.ts"; | ||
| 30 | 30 | import { writePause } from "./pause.ts"; |
| 31 | 31 | import { running } from "../kernel/version.ts"; |
| 32 | 32 | import { compareVersions } from "../kernel/versions.ts"; |
| 33 | import { AGENT_SCRIPT, uncheckedMark } from "../release/agent_tests.ts"; | |
| 33 | 34 | import { readTags, recordFor } from "../release/shipped.ts"; |
| 34 | 35 | import { checkoutRelease, preflightRelease } from "../release/checkout.ts"; |
| 35 | 36 | import { mainCheckRunning } from "../release/main_check_idle.ts"; |
| @@ -138,6 +139,17 @@ export function keeperPorts(app: App, input: { forgeUrl: string; deployment: str | ||
| 138 | 139 | : kubeDeployer({ credentials: serviceAccount(), deployment: input.deployment, container: input.container }); |
| 139 | 140 | const probeHeaders = ownProbeHeaders(app.config.dataDir); |
| 140 | 141 | const at = (version: string) => runGit(["rev-parse", "--verify", "--quiet", `refs/tags/v${version}^{commit}`], { cwd: dir() }); |
| 142 | // `{ agentUnchecked: true }` when agent.sh changed since the newest tag (or there is none). | |
| 143 | const uncheckedAgent = async (version: string, sha: string): Promise<{ agentUnchecked?: true }> => { | |
| 144 | const tags = await readTags(dir()); | |
| 145 | const top = tags.ok | |
| 146 | ? [...tags.value].filter((t) => VERSION.test(t.version) && compareVersions(t.version, version) < 0).sort((a, b) => compareVersions(b.version, a.version))[0] | |
| 147 | : undefined; | |
| 148 | const base = top === undefined ? undefined : await at(top.version); | |
| 149 | if (base === undefined || !base.ok || !OID.test(base.value)) return uncheckedMark(undefined); | |
| 150 | const diff = await runGit(["diff", "--name-only", `${base.value}..${sha}`, "--", AGENT_SCRIPT], { cwd: dir() }); | |
| 151 | return uncheckedMark(diff.ok ? diff.value.split("\n") : undefined); | |
| 152 | }; | |
| 141 | 153 | return { |
| 142 | 154 | ...(input.swap === true ? { minIntervalMs: SWAP_INTERVAL_MS } : {}), |
| 143 | 155 | db: app.db, |
| @@ -173,7 +185,9 @@ export function keeperPorts(app: App, input: { forgeUrl: string; deployment: str | ||
| 173 | 185 | // The record `scripts/cut-release.ts` writes. The migrations are this process's: the keeper |
| 174 | 186 | // cuts only when main has moved past a live tag, and each forge cuts the code it was built |
| 175 | 187 | // from at the earliest. |
| 176 | const record = JSON.stringify(recordFor(version, migrationFiles, NUMBERED)); | |
| 188 | // The keeper does not run the game agent tests (a docker run, by hand: docs/ops/ROLL.md), so | |
| 189 | // when agent.sh changed since the last tag the record says so, loudly (#18271). | |
| 190 | const record = JSON.stringify({ ...recordFor(version, migrationFiles, NUMBERED), ...(await uncheckedAgent(version, sha)) }); | |
| 177 | 191 | const made = await runGit(["tag", "--annotate", "--file=-", `v${version}`, sha], { |
| 178 | 192 | cwd: dir(), |
| 179 | 193 | stdin: `${record}\n`, |
src/release/agent_tests.ts added +111
| @@ -0,0 +1,111 @@ | ||
| 1 | /** | |
| 2 | * The standing rule before an agent.sh release (#18271, part 2 of #18250): | |
| 3 | * a release whose commit changes `src/games/agent.sh` since the last tag | |
| 4 | * runs the game agent tests in `ubuntu:24.04`, the box's own OS, and the | |
| 5 | * release record says they passed. `scripts/cut-release.ts` runs them and | |
| 6 | * refuses the tag when they fail; this module is the plain data around that: | |
| 7 | * what counts as touching the agent, the docker command, the record kept. | |
| 8 | */ | |
| 9 | ||
| 10 | export const AGENT_SCRIPT = "src/games/agent.sh"; | |
| 11 | export const AGENT_IMAGE = "ubuntu:24.04"; | |
| 12 | const AGENT_TEST = /^test\/game-agent-[a-z0-9-]+\.test\.ts$/; | |
| 13 | ||
| 14 | /** What the release record says of the agent tests: the image, how many files ran, when. */ | |
| 15 | export interface AgentTests { | |
| 16 | readonly image: string; | |
| 17 | readonly files: number; | |
| 18 | readonly at: number; | |
| 19 | } | |
| 20 | ||
| 21 | /** True when a list of changed paths (`git diff --name-only`) includes the box agent. */ | |
| 22 | export function touchesAgent(changed: readonly string[]): boolean { | |
| 23 | return changed.includes(AGENT_SCRIPT); | |
| 24 | } | |
| 25 | ||
| 26 | /** The game agent test files among `names`, sorted. */ | |
| 27 | export function agentTestFiles(names: readonly string[]): string[] { | |
| 28 | return names.filter((n) => AGENT_TEST.test(n)).sort(); | |
| 29 | } | |
| 30 | ||
| 31 | /** | |
| 32 | * What runs in the container: a bare ubuntu:24.04 has no curl or jq, and the agent tests skip | |
| 33 | * themselves without them, so the tools are installed first (the one use of the network) and | |
| 34 | * checked, and a missing one fails the run instead of letting skipped tests pass. | |
| 35 | */ | |
| 36 | const BOX_SCRIPT = | |
| 37 | "export DEBIAN_FRONTEND=noninteractive; " + | |
| 38 | "apt-get update -qq >/dev/null && apt-get install -y -qq --no-install-recommends curl jq ca-certificates >/dev/null || exit 1; " + | |
| 39 | "for t in bash curl jq timeout sha256sum; do command -v $t >/dev/null || { echo \"missing $t\" >&2; exit 1; }; done; " + | |
| 40 | 'exec bun test "$@"'; | |
| 41 | ||
| 42 | /** | |
| 43 | * The docker argv that runs `files` in the box's OS: the checkout read-only at /repo, the bun | |
| 44 | * binary at /usr/local/bin/bun, a tmpfs for scratch. | |
| 45 | */ | |
| 46 | export function dockerArgs(root: string, bun: string, files: readonly string[]): string[] { | |
| 47 | return [ | |
| 48 | "docker", "run", "--rm", | |
| 49 | "-v", `${root}:/repo:ro`, | |
| 50 | "-v", `${bun}:/usr/local/bin/bun:ro`, | |
| 51 | "--tmpfs", "/tmp:exec", "-e", "TMPDIR=/tmp", "-e", "HOME=/tmp", | |
| 52 | "-w", "/repo", AGENT_IMAGE, | |
| 53 | "sh", "-c", BOX_SCRIPT, "agent-tests", ...files, | |
| 54 | ]; | |
| 55 | } | |
| 56 | ||
| 57 | /** The record with the agent tests added; the same record when they were not needed. */ | |
| 58 | export function withAgentTests<T extends object>(record: T, ran: AgentTests | undefined): T & { agentTests?: AgentTests } { | |
| 59 | return ran === undefined ? record : { ...record, agentTests: ran }; | |
| 60 | } | |
| 61 | ||
| 62 | /** An `agentTests` field from a parsed tag message, or undefined when absent or malformed. */ | |
| 63 | export function parseAgentTests(raw: unknown): AgentTests | undefined { | |
| 64 | if (typeof raw !== "object" || raw === null) return undefined; | |
| 65 | const { image, files, at } = raw as Record<string, unknown>; | |
| 66 | if (image !== AGENT_IMAGE || !Number.isSafeInteger(files) || (files as number) < 1) return undefined; | |
| 67 | if (!Number.isSafeInteger(at) || (at as number) <= 0) return undefined; | |
| 68 | return { image, files: files as number, at: at as number }; | |
| 69 | } | |
| 70 | ||
| 71 | /** | |
| 72 | * What the standing rule decides: refuse the tag, or the record to carry (none when not needed). | |
| 73 | */ | |
| 74 | export type Verdict = { readonly refuse: string } | { readonly agentTests: AgentTests | undefined }; | |
| 75 | ||
| 76 | /** | |
| 77 | * The rule as one decision. `changed` is the paths changed since the last tag, or undefined when | |
| 78 | * there is no earlier tag (the agent counts as changed). Nothing runs unless the tag is being | |
| 79 | * cut (`tag`) and the agent changed; a red run refuses and records nothing. `run` gets the test | |
| 80 | * files and answers the exit code. | |
| 81 | */ | |
| 82 | export function decideAgentTests(input: { | |
| 83 | readonly changed: readonly string[] | undefined; | |
| 84 | readonly tag: boolean; | |
| 85 | readonly files: readonly string[]; | |
| 86 | readonly run: (files: readonly string[]) => number; | |
| 87 | readonly now: () => number; | |
| 88 | }): Verdict { | |
| 89 | const changed = input.changed === undefined || touchesAgent(input.changed); | |
| 90 | if (!input.tag || !changed) return { agentTests: undefined }; | |
| 91 | if (input.files.length === 0) return { refuse: `${AGENT_SCRIPT} changed and no game agent test file was found` }; | |
| 92 | const code = input.run(input.files); | |
| 93 | if (code !== 0) return { refuse: `the game agent tests failed in ${AGENT_IMAGE} (exit ${code})` }; | |
| 94 | return { agentTests: { image: AGENT_IMAGE, files: input.files.length, at: input.now() } }; | |
| 95 | } | |
| 96 | ||
| 97 | /** The keeper's loud mark on a tag it cut without the tests: the agent changed and nothing ran. */ | |
| 98 | export const UNCHECKED = "agent.sh changed; the game agent tests were not run for this release"; | |
| 99 | ||
| 100 | /** How a release's record speaks of the agent tests; empty when agent.sh was not in play. */ | |
| 101 | export function agentWords(r: { agentTests?: AgentTests; agentUnchecked?: boolean }): string { | |
| 102 | if (r.agentTests !== undefined) return `agent tests passed in ${r.agentTests.image} (${r.agentTests.files} files)`; | |
| 103 | return r.agentUnchecked === true ? UNCHECKED : ""; | |
| 104 | } | |
| 105 | ||
| 106 | /** | |
| 107 | * The mark the keeper's cut carries: `changed` as in `decideAgentTests`; undefined when unreadable. | |
| 108 | */ | |
| 109 | export function uncheckedMark(changed: readonly string[] | undefined): { agentUnchecked?: true } { | |
| 110 | return changed === undefined || touchesAgent(changed) ? { agentUnchecked: true } : {}; | |
| 111 | } |
src/release/shipped.ts +13 −3
| @@ -15,6 +15,7 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | |
| 17 | 17 | import before from "../core/releases-before-tags.json" with { type: "json" }; |
| 18 | import { parseAgentTests, type AgentTests } from "./agent_tests.ts"; | |
| 18 | 19 | import { runGit } from "../git/env.ts"; |
| 19 | 20 | import { err, ok, type Result } from "../kernel/result.ts"; |
| 20 | 21 | import { compareVersions } from "../kernel/versions.ts"; |
| @@ -25,6 +26,10 @@ export interface Shipped { | ||
| 25 | 26 | readonly migrations: number; |
| 26 | 27 | /** The stamped ones among them, by name; absent on a release from before #1837. */ |
| 27 | 28 | readonly ids?: readonly string[]; |
| 29 | /** The game agent tests run in ubuntu:24.04 for a release that changed agent.sh (#18271). */ | |
| 30 | readonly agentTests?: AgentTests; | |
| 31 | /** Set by the release keeper when agent.sh changed and it cut the tag without the tests. */ | |
| 32 | readonly agentUnchecked?: boolean; | |
| 28 | 33 | /** When the tag was cut (epoch ms); absent on a frozen release. */ |
| 29 | 34 | readonly at?: number; |
| 30 | 35 | } |
| @@ -47,13 +52,18 @@ export function parseRecord(message: string): Omit<Shipped, "at"> | undefined { | ||
| 47 | 52 | return undefined; |
| 48 | 53 | } |
| 49 | 54 | if (typeof doc !== "object" || doc === null) return undefined; |
| 50 | const { version, migrations, ids } = doc as Record<string, unknown>; | |
| 55 | const { version, migrations, ids, agentTests, agentUnchecked } = doc as Record<string, unknown>; | |
| 56 | const ran = parseAgentTests(agentTests); | |
| 57 | const extra = { | |
| 58 | ...(ran === undefined ? {} : { agentTests: ran }), | |
| 59 | ...(agentUnchecked === true && ran === undefined ? { agentUnchecked: true } : {}), | |
| 60 | }; | |
| 51 | 61 | if (typeof version !== "string" || !VERSION.test(version)) return undefined; |
| 52 | 62 | if (!Number.isSafeInteger(migrations) || (migrations as number) < 0) return undefined; |
| 53 | if (ids === undefined) return { version, migrations: migrations as number }; | |
| 63 | if (ids === undefined) return { version, migrations: migrations as number, ...extra }; | |
| 54 | 64 | if (!Array.isArray(ids) || ids.length > MAX_IDS || !ids.every((i) => typeof i === "string" && ID.test(i))) |
| 55 | 65 | return undefined; |
| 56 | return { version, migrations: migrations as number, ids: ids as string[] }; | |
| 66 | return { version, migrations: migrations as number, ids: ids as string[], ...extra }; | |
| 57 | 67 | } |
| 58 | 68 | |
| 59 | 69 | /** The frozen releases and the tagged ones as one list, newest first; a tag wins over a frozen entry of its version. */ |
src/tui/screens/changelog.ts +3
| @@ -18,6 +18,8 @@ import { rangeOf, rangeWords } from "../../release/range.ts"; | ||
| 18 | 18 | import { commitLog } from "../../git/read.ts"; |
| 19 | 19 | import { repoDir } from "../../git/repos.ts"; |
| 20 | 20 | import { speedLines } from "../../perf/release_speed.ts"; |
| 21 | import { agentWords } from "../../release/agent_tests.ts"; | |
| 22 | import { shippedReleases } from "../../release/shipped.ts"; | |
| 21 | 23 | import { forgeChangelog, type ReleaseEntry } from "../../release/changelog.ts"; |
| 22 | 24 | import { readLandings, type Landing } from "../../release/landings.ts"; |
| 23 | 25 | import { nearMilestones, nearWords, type Near } from "../../web/pages/milestones_near.ts"; |
| @@ -61,6 +63,7 @@ export function changelogRows(entries: readonly ReleaseEntry[], speed: ReadonlyM | ||
| 61 | 63 | releaseRange(e), |
| 62 | 64 | e.pulls.map((p) => `#${p.number} ${plainTitle(p.title)}`.trim()).join("; "), |
| 63 | 65 | speed.get(e.version) ?? "", |
| 66 | agentWords(shippedReleases().find((r) => r.version === e.version) ?? {}), | |
| 64 | 67 | ), |
| 65 | 68 | })); |
| 66 | 69 | } |
src/web/standards.ts +4 −1
| @@ -64,6 +64,7 @@ import { announcedVersion, running, shortOf, UNSTAMPED } from "../kernel/version | ||
| 64 | 64 | import { GUIDE } from "../view/guide.ts"; |
| 65 | 65 | import { loadMcp } from "../http/mcp/load.ts"; |
| 66 | 66 | import { timePhase, timePhaseAsync } from "../core/route_timing.ts"; |
| 67 | import { agentWords } from "../release/agent_tests.ts"; | |
| 67 | 68 | import { shippedReleases, type Shipped } from "../release/shipped.ts"; |
| 68 | 69 | import { UNINDEXED_PAGES } from "./page_links.ts"; |
| 69 | 70 | |
| @@ -270,7 +271,7 @@ export function changePassword(): Response { | ||
| 270 | 271 | } |
| 271 | 272 | |
| 272 | 273 | /** |
| 273 | * GET /releases.json — `{ releases: [{ name, url }] }`, newest first, read | |
| 274 | * GET /releases.json — `{ releases: [{ name, url, agentTests? }] }`, newest first, read | |
| 274 | 275 | * by a child forge (`core/parent_releases.ts`). Public and read-only. The |
| 275 | 276 | * link of each is its entry on /changelog (`/changelog#<version>`). |
| 276 | 277 | */ |
| @@ -283,6 +284,8 @@ export function releasesJson(ctx: Ctx): Response { | ||
| 283 | 284 | releases: list.map((r) => ({ |
| 284 | 285 | name: r.version, |
| 285 | 286 | url: `${origin}/changelog#${encodeURIComponent(r.version)}`, |
| 287 | // What the record says of the game agent tests (#18271): only on a release it matters to. | |
| 288 | ...(r.agentTests === undefined && r.agentUnchecked !== true ? {} : { agentTests: agentWords(r) }), | |
| 286 | 289 | })), |
| 287 | 290 | }); |
| 288 | 291 | const etag = `"${new Bun.CryptoHasher("sha256").update(body).digest("hex").slice(0, 32)}"`; |
test/release-agent-tests.test.ts added +132
| @@ -0,0 +1,132 @@ | ||
| 1 | /** | |
| 2 | * An agent.sh release runs the game agent tests in ubuntu:24.04 and says so on the record (#18271). | |
| 3 | */ | |
| 4 | import { describe, expect, test } from "bun:test"; | |
| 5 | import { changelogRows } from "../src/tui/screens/changelog.ts"; | |
| 6 | import { createApp } from "../src/app.ts"; | |
| 7 | import { serve } from "../src/http/server.ts"; | |
| 8 | import { mkdtemp } from "node:fs/promises"; | |
| 9 | import { tmpdir } from "node:os"; | |
| 10 | import { join } from "node:path"; | |
| 11 | import { AGENT_IMAGE, uncheckedMark, agentWords, decideAgentTests, agentTestFiles, dockerArgs, parseAgentTests, touchesAgent, withAgentTests } from "../src/release/agent_tests.ts"; | |
| 12 | import { parseRecord, setTagged } from "../src/release/shipped.ts"; | |
| 13 | ||
| 14 | const ran = { image: AGENT_IMAGE, files: 6, at: 1_700_000_000_000 }; | |
| 15 | ||
| 16 | const files = ["test/game-agent-exec.test.ts", "test/game-agent-update.test.ts"]; | |
| 17 | const decide = (changed: string[] | undefined, tag: boolean, code: number) => { | |
| 18 | const calls: (readonly string[])[] = []; | |
| 19 | const verdict = decideAgentTests({ | |
| 20 | changed, tag, files, now: () => 5, | |
| 21 | run: (f) => (calls.push(f), code), | |
| 22 | }); | |
| 23 | return { verdict, calls }; | |
| 24 | }; | |
| 25 | ||
| 26 | describe("the rule: when the tests run and what refuses", () => { | |
| 27 | test("agent.sh unchanged runs nothing", () => { | |
| 28 | const r = decide([], true, 0); | |
| 29 | expect(r.calls).toEqual([]); | |
| 30 | expect(r.verdict).toEqual({ agentTests: undefined }); | |
| 31 | }); | |
| 32 | test("changed with --tag and a green run records it", () => { | |
| 33 | const r = decide(["src/games/agent.sh"], true, 0); | |
| 34 | expect(r.calls).toEqual([files]); | |
| 35 | expect(r.verdict).toEqual({ agentTests: { image: AGENT_IMAGE, files: 2, at: 5 } }); | |
| 36 | }); | |
| 37 | test("changed with a red run refuses and records nothing", () => { | |
| 38 | const r = decide(["src/games/agent.sh"], true, 1); | |
| 39 | expect("refuse" in r.verdict && r.verdict.refuse).toContain("exit 1"); | |
| 40 | expect("agentTests" in r.verdict).toBe(false); | |
| 41 | }); | |
| 42 | test("changed without --tag runs nothing", () => { | |
| 43 | const r = decide(["src/games/agent.sh"], false, 1); | |
| 44 | expect(r.calls).toEqual([]); | |
| 45 | expect(r.verdict).toEqual({ agentTests: undefined }); | |
| 46 | }); | |
| 47 | test("no earlier tag counts as changed", () => { | |
| 48 | expect(decide(undefined, true, 0).calls).toEqual([files]); | |
| 49 | expect(decide(undefined, false, 0).calls).toEqual([]); | |
| 50 | }); | |
| 51 | test("no test file found refuses rather than passing nothing", () => { | |
| 52 | const v = decideAgentTests({ changed: undefined, tag: true, files: [], run: () => 0, now: () => 1 }); | |
| 53 | expect("refuse" in v).toBe(true); | |
| 54 | }); | |
| 55 | }); | |
| 56 | ||
| 57 | describe("what a person sees", () => { | |
| 58 | test("a passed run, an unchecked keeper cut, and neither", () => { | |
| 59 | expect(agentWords({ agentTests: ran })).toContain("passed in ubuntu:24.04"); | |
| 60 | expect(agentWords({ agentUnchecked: true })).toContain("were not run"); | |
| 61 | expect(agentWords({})).toBe(""); | |
| 62 | }); | |
| 63 | test("the keeper's mark reads back, and a run wins over it", () => { | |
| 64 | expect(parseRecord('{"version":"1.2.3","migrations":4,"agentUnchecked":true}')?.agentUnchecked).toBe(true); | |
| 65 | const both = JSON.stringify({ version: "1.2.3", migrations: 4, agentUnchecked: true, agentTests: ran }); | |
| 66 | expect(parseRecord(both)?.agentUnchecked).toBeUndefined(); | |
| 67 | }); | |
| 68 | test("the keeper marks an agent change it cut unchecked, and only that", () => { | |
| 69 | expect(uncheckedMark(["src/games/agent.sh"])).toEqual({ agentUnchecked: true }); | |
| 70 | expect(uncheckedMark([""])).toEqual({}); | |
| 71 | expect(uncheckedMark(undefined)).toEqual({ agentUnchecked: true }); | |
| 72 | }); | |
| 73 | test("/releases.json and the terminal's changelog row show it", async () => { | |
| 74 | const app = createApp({ dataDir: await mkdtemp(join(tmpdir(), "forge-agent-tests-")), port: 0 }); | |
| 75 | const servers = await serve(app); | |
| 76 | try { | |
| 77 | setTagged([ | |
| 78 | { version: "9.0.2", migrations: 1, agentTests: ran }, | |
| 79 | { version: "9.0.1", migrations: 1, agentUnchecked: true }, | |
| 80 | { version: "9.0.0", migrations: 1 }, | |
| 81 | ]); | |
| 82 | const body = (await (await fetch(`${servers.url}/releases.json`)).json()) as { releases: { name: string; agentTests?: string }[] }; | |
| 83 | const by = new Map(body.releases.map((r) => [r.name, r.agentTests])); | |
| 84 | expect(by.get("9.0.2")).toContain("passed"); | |
| 85 | expect(by.get("9.0.1")).toContain("were not run"); | |
| 86 | expect(by.has("9.0.0") && by.get("9.0.0") !== undefined).toBe(false); | |
| 87 | const row = (version: string) => | |
| 88 | changelogRows([{ version, date: "2026-12-01T00:00:00Z", pulls: [], oid: "" }])[0]!.meta ?? ""; | |
| 89 | expect(row("9.0.1")).toContain("were not run"); | |
| 90 | expect(row("9.0.2")).toContain("passed"); | |
| 91 | } finally { | |
| 92 | setTagged([]); | |
| 93 | servers.stop(); | |
| 94 | } | |
| 95 | }); | |
| 96 | test("the container installs the tools and fails when one is missing", () => { | |
| 97 | const script = dockerArgs("/r", "/b", files).join(" "); | |
| 98 | expect(script).toContain("apt-get install"); | |
| 99 | expect(script).toContain("jq"); | |
| 100 | expect(script).toContain("missing $t"); | |
| 101 | }); | |
| 102 | }); | |
| 103 | ||
| 104 | describe("agent tests before release", () => { | |
| 105 | test("only a change to agent.sh counts", () => { | |
| 106 | expect(touchesAgent(["src/games/agent.sh"])).toBe(true); | |
| 107 | expect(touchesAgent(["src/games/agent_sh.d.ts", "README.md"])).toBe(false); | |
| 108 | }); | |
| 109 | test("picks the game agent test files", () => { | |
| 110 | expect(agentTestFiles(["test/game-agent-update.test.ts", "test/game-box.test.ts", "test/game-agent-exec.test.ts", "test/x/game-agent-a.test.ts"])).toEqual([ | |
| 111 | "test/game-agent-exec.test.ts", | |
| 112 | "test/game-agent-update.test.ts", | |
| 113 | ]); | |
| 114 | }); | |
| 115 | test("the docker command is ubuntu:24.04, read-only, with the files", () => { | |
| 116 | const args = dockerArgs("/r", "/b/bun", ["test/game-agent-exec.test.ts"]); | |
| 117 | expect(args.slice(0, 2)).toEqual(["docker", "run"]); | |
| 118 | expect(args).toContain("/r:/repo:ro"); | |
| 119 | expect(args.indexOf(AGENT_IMAGE)).toBeLessThan(args.indexOf("test/game-agent-exec.test.ts")); | |
| 120 | }); | |
| 121 | test("the record carries the run, and reads back", () => { | |
| 122 | const text = JSON.stringify(withAgentTests({ version: "1.2.3", migrations: 4 }, ran)); | |
| 123 | expect(parseRecord(text)?.agentTests).toEqual(ran); | |
| 124 | expect(withAgentTests({ version: "1.2.3", migrations: 4 }, undefined)).toEqual({ version: "1.2.3", migrations: 4 }); | |
| 125 | expect(parseRecord('{"version":"1.2.3","migrations":4}')?.agentTests).toBeUndefined(); | |
| 126 | }); | |
| 127 | test("a malformed run is dropped, not trusted", () => { | |
| 128 | expect(parseAgentTests({ ...ran, image: "alpine" })).toBeUndefined(); | |
| 129 | expect(parseAgentTests({ ...ran, files: 0 })).toBeUndefined(); | |
| 130 | expect(parseAgentTests("yes")).toBeUndefined(); | |
| 131 | }); | |
| 132 | }); |
new above
offline