Public: anyone can read this; the crew can change it.
A release asks scripts/return-check.ts before it promotes #17793
Merged 13h 54m ago, live in production
torque/forge:torque/17769-a-release-asks-scripts-return-check-ts-b → main 0 commits fork 3 threads · 3 unresolved
7 files
changed +276
−1
docs/features/nightly-release.md +2
| @@ -14,6 +14,8 @@ If main is ahead of the live version and no snapshot is running, it: | ||
| 14 | 14 | 4. boots it on the stage rig in production shape; |
| 15 | 15 | 5. promotes it with the stay-up watch. |
| 16 | 16 | |
| 17 | **Return check (#17769):** between the build (3) and the promote (5) the tick asks whether the live version's image could take the database back: `bun scripts/return-check.ts v<live version> --allow /srv/forge/release-tick/return-allow.txt --log <release log>`. Exit 1 is a hold, the migrations named in the log and the held issue; exit 2 (it could not look) is a hold too. A person lets a named migration through by adding a line `<migration id> <reason>` to that file; an id without a reason does not count. Everything it said is appended, stamped, to the release log. The check is `src/release/return_check.ts`; it reads words, so it does not prove the old code's writes. Adding the call to `tick.sh` is the owner's host-side step, as the script is not in this repository. | |
| 18 | ||
| 17 | 19 | Any doubt is a hold: nothing is promoted, and an issue titled `The nightly release was held: …` is filed on the forge with the reason and the log tail. Read those issues as the tick's own report; the heartbeat on /releases is a separate record (`release-heartbeat.md`). |
| 18 | 20 | |
| 19 | 21 | **Proven (2026-11-16, on the host):** the fetch, the comparison and the gate (1,524 tests, 0 failed, 86 s). **Not yet run unattended:** the tag, the build, the rig and the promote as one sequence; each is the script used by hand for every release since 2026-11-13. The first real run is the first morning main is ahead. |
scripts/return-check.ts added +60
| @@ -0,0 +1,60 @@ | ||
| 1 | #!/usr/bin/env bun | |
| 2 | /** | |
| 3 | * Whether the image of `<tag>` may take the forge's database back after this tree has migrated it. | |
| 4 | * | |
| 5 | * bun scripts/return-check.ts v0.7.719 [--allow <file>] [--log <file>] | |
| 6 | * | |
| 7 | * One line for each migration since the tag that makes it unproven, and exit 1; exit 0 when there | |
| 8 | * is none; 2 when it could not look. A shipped migration that was changed or removed is named too. | |
| 9 | * `--allow` is a file a person writes: a migration id, a space and the reason, one a line. An id | |
| 10 | * without a reason does not count. `--log` appends what it said, stamped, to the release log. It | |
| 11 | * reads words, so it does not prove the old code's writes. | |
| 12 | */ | |
| 13 | import { appendFileSync, existsSync, readFileSync } from "node:fs"; | |
| 14 | import { migrationFiles } from "../src/core/schema.ts"; | |
| 15 | import { parseAllow, returnVerdict } from "../src/release/return_check.ts"; | |
| 16 | ||
| 17 | const DIR = "src/core/migrations"; | |
| 18 | ||
| 19 | const tag = process.argv[2]; | |
| 20 | const USAGE = "usage: bun scripts/return-check.ts v<version> [--allow <file>] [--log <file>]"; | |
| 21 | /** | |
| 22 | * A flag's value: undefined when the flag is absent; exit 2 when it is last, or followed by a flag. | |
| 23 | */ | |
| 24 | function flagValue(name: string): string | undefined { | |
| 25 | const at = process.argv.indexOf(name); | |
| 26 | if (at < 0) return undefined; | |
| 27 | const value = process.argv[at + 1]; | |
| 28 | if (value === undefined || value.startsWith("--")) { | |
| 29 | console.error(`return-check: ${name} needs a file\n${USAGE}`); | |
| 30 | process.exit(2); | |
| 31 | } | |
| 32 | return value; | |
| 33 | } | |
| 34 | const file = flagValue("--allow"); | |
| 35 | const logFile = flagValue("--log"); | |
| 36 | if (tag === undefined || !/^v\d+\.\d+\.\d+$/.test(tag)) { | |
| 37 | console.error(USAGE); | |
| 38 | process.exit(2); | |
| 39 | } | |
| 40 | const allowed = parseAllow(file !== undefined && existsSync(file) ? readFileSync(file, "utf8") : ""); | |
| 41 | const diff = Bun.spawnSync(["git", "diff", "--name-status", "--no-renames", tag, "HEAD", "--", DIR]); | |
| 42 | if (diff.exitCode !== 0) { | |
| 43 | console.error(`return-check: git could not compare with ${tag}`); | |
| 44 | process.exit(2); | |
| 45 | } | |
| 46 | const changed = diff.stdout | |
| 47 | .toString() | |
| 48 | .split("\n") | |
| 49 | .filter(Boolean) | |
| 50 | .map((line) => { | |
| 51 | const [state, path] = line.split("\t") as [string, string]; | |
| 52 | const id = path.slice(DIR.length + 1).replace(/\.ts$/, ""); | |
| 53 | return { id, state, sql: migrationFiles.find((m) => m.name === id)?.sql }; | |
| 54 | }); | |
| 55 | const { lines, held } = returnVerdict(tag, changed, allowed); | |
| 56 | for (const line of lines) console.log(line); | |
| 57 | if (logFile !== undefined) { | |
| 58 | appendFileSync(logFile, lines.map((l) => `${new Date().toISOString()} ${l}\n`).join("")); | |
| 59 | } | |
| 60 | process.exit(held === 0 ? 0 : 1); |
src/kernel/migrate.ts +28
| @@ -458,3 +458,31 @@ export function notAdditive(sql: string): string[] { | ||
| 458 | 458 | found.push("adds a NOT NULL column without a default"); |
| 459 | 459 | return found; |
| 460 | 460 | } |
| 461 | ||
| 462 | /** | |
| 463 | * What in a migration makes a return to the image before it unproven: the old code must go on | |
| 464 | * reading and writing a database this one changed. All `notAdditive` names, and what it lets pass: | |
| 465 | * a unique index or a trigger (the old code's writes may be refused or changed), rows written to a | |
| 466 | * table that was there before, and a new column with a CHECK or a reference. A table the same | |
| 467 | * migration makes is unknown to the old code, so it counts for nothing. It reads words, not | |
| 468 | * meaning. | |
| 469 | */ | |
| 470 | export function unprovenReturn(sql: string): string[] { | |
| 471 | const code = sql.replace( | |
| 472 | /'(?:[^']|'')*'|"(?:[^"]|"")*"|\/\*[\s\S]*?(?:\*\/|$)|--[^\n]*/g, | |
| 473 | (token) => (token.startsWith("'") ? "''" : token.startsWith('"') ? token.slice(1, -1).replace(/\W/g, "_") : " "), | |
| 474 | ); | |
| 475 | const tables = (pattern: RegExp): string[] => [...code.matchAll(pattern)].map((m) => m[1]!.toLowerCase()); | |
| 476 | const made = new Set(tables(/\bCREATE\s+TABLE\s+(?:IF\s+NOT\s+EXISTS\s+)?[`[]?(\w+)/gi)); | |
| 477 | const found = notAdditive(sql); | |
| 478 | const say = (what: string, pattern: RegExp): void => { | |
| 479 | for (const table of new Set(tables(pattern))) if (!made.has(table)) found.push(`${what} ${table}`); | |
| 480 | }; | |
| 481 | say("adds a unique index on", /\bCREATE\s+UNIQUE\s+INDEX\s+(?:IF\s+NOT\s+EXISTS\s+)?\S+\s+ON\s+[`[]?(\w+)/gi); | |
| 482 | say("adds a trigger on", /\bCREATE\s+(?:TEMP\w*\s+)?TRIGGER\b[^;]*?\bON\s+[`[]?(\w+)/gi); | |
| 483 | say("updates rows of", /\bUPDATE\s+(?:OR\s+\w+\s+)?[`[]?(\w+)[`\]]?\s+SET\b/gi); | |
| 484 | say("deletes rows of", /\bDELETE\s+FROM\s+[`[]?(\w+)/gi); | |
| 485 | say("inserts rows into", /\b(?:INSERT(?:\s+OR\s+\w+)?|REPLACE)\s+INTO\s+[`[]?(\w+)/gi); | |
| 486 | say("adds a column with a CHECK or a reference to", /\bALTER\s+TABLE\s+[`[]?(\w+)[`\]]?\s+ADD\b[^;]*\b(?:CHECK|REFERENCES)\b/gi); | |
| 487 | return found; | |
| 488 | } |
src/release/return_check.ts added +58
| @@ -0,0 +1,58 @@ | ||
| 1 | /** | |
| 2 | * What the release asks before it promotes (#17769): after the build, may the image of the live | |
| 3 | * version take the database back from this tree's migrations? Plain data in, lines out: the | |
| 4 | * script `scripts/return-check.ts` reads git and the allow file, this decides and words it. | |
| 5 | */ | |
| 6 | ||
| 7 | import { unprovenReturn } from "../kernel/migrate.ts"; | |
| 8 | ||
| 9 | /** One migration file that differs from the live tag: its id, git's state letter and its SQL. */ | |
| 10 | export interface ChangedMigration { | |
| 11 | readonly id: string; | |
| 12 | readonly state: string; | |
| 13 | /** The migration's SQL, or undefined when this tree's schema does not list it. */ | |
| 14 | readonly sql: string | undefined; | |
| 15 | } | |
| 16 | ||
| 17 | /** | |
| 18 | * The verdict: the lines for the release log, and how many unproven migrations nobody let through. | |
| 19 | */ | |
| 20 | export interface ReturnVerdict { | |
| 21 | readonly lines: readonly string[]; | |
| 22 | readonly held: number; | |
| 23 | } | |
| 24 | ||
| 25 | /** | |
| 26 | * A person's allow file: `<migration id> <reason>` a line; an id without a reason does not count; | |
| 27 | * a line starting with `#` is a comment; an id written twice keeps its last reason. | |
| 28 | */ | |
| 29 | export function parseAllow(text: string): Map<string, string> { | |
| 30 | const allowed = new Map<string, string>(); | |
| 31 | for (const line of text.split("\n")) { | |
| 32 | if (line.trim().startsWith("#")) continue; | |
| 33 | const m = /^(\S+)\s+(\S.*)$/.exec(line.trim()); | |
| 34 | if (m !== null) allowed.set(m[1]!, m[2]!); | |
| 35 | } | |
| 36 | return allowed; | |
| 37 | } | |
| 38 | ||
| 39 | /** | |
| 40 | * Name each changed migration that makes a return unproven; a person's id and reason lets it by. | |
| 41 | */ | |
| 42 | export function returnVerdict(tag: string, changed: readonly ChangedMigration[], allowed: ReadonlyMap<string, string>): ReturnVerdict { | |
| 43 | const lines: string[] = []; | |
| 44 | let held = 0; | |
| 45 | for (const { id, state, sql } of changed) { | |
| 46 | const why = state !== "A" ? ["changed or removed after it shipped"] : sql === undefined ? ["not in the schema's list"] : unprovenReturn(sql); | |
| 47 | if (why.length === 0) continue; | |
| 48 | const reason = allowed.get(id); | |
| 49 | if (reason !== undefined) { | |
| 50 | lines.push(`${id}: ${why.join(", ")}; let through by a person: ${reason}`); | |
| 51 | continue; | |
| 52 | } | |
| 53 | held++; | |
| 54 | lines.push(`${id}: ${why.join(", ")}`); | |
| 55 | } | |
| 56 | lines.push(`return-check: ${changed.length} migration(s) since ${tag}, ${held} unproven`); | |
| 57 | return { lines, held }; | |
| 58 | } |
test/return-check-release.test.ts added +34
| @@ -0,0 +1,34 @@ | ||
| 1 | import { expect, test } from "bun:test"; | |
| 2 | import { parseAllow, returnVerdict } from "../src/release/return_check.ts"; | |
| 3 | ||
| 4 | const unique = "CREATE UNIQUE INDEX x ON t(a);"; | |
| 5 | const plain = "CREATE TABLE fresh(id INTEGER PRIMARY KEY);"; | |
| 6 | ||
| 7 | test("a migration that makes a return unproven holds the release", () => { | |
| 8 | const v = returnVerdict("v0.7.1", [{ id: "20261201-a", state: "A", sql: unique }], new Map()); | |
| 9 | expect(v.held).toBe(1); | |
| 10 | expect(v.lines[0]).toStartWith("20261201-a:"); | |
| 11 | }); | |
| 12 | ||
| 13 | test("a person's id and reason lets it through, and the log says so", () => { | |
| 14 | const allowed = parseAllow("20261201-a the old build never writes t\n"); | |
| 15 | const v = returnVerdict("v0.7.1", [{ id: "20261201-a", state: "A", sql: unique }], allowed); | |
| 16 | expect(v.held).toBe(0); | |
| 17 | expect(v.lines[0]).toContain("let through by a person: the old build never writes t"); | |
| 18 | }); | |
| 19 | ||
| 20 | test("an id without a reason does not count", () => { | |
| 21 | expect(parseAllow("20261201-a\n").size).toBe(0); | |
| 22 | }); | |
| 23 | ||
| 24 | test("a shipped migration that changed is named; a plain new one is not", () => { | |
| 25 | const v = returnVerdict("v0.7.1", [{ id: "old", state: "M", sql: plain }, { id: "new", state: "A", sql: plain }], new Map()); | |
| 26 | expect(v.held).toBe(1); | |
| 27 | expect(v.lines).toHaveLength(2); | |
| 28 | expect(v.lines[1]).toBe("return-check: 2 migration(s) since v0.7.1, 1 unproven"); | |
| 29 | }); | |
| 30 | ||
| 31 | test("an allow file: blank lines, whitespace, comments and a repeated id", () => { | |
| 32 | const allowed = parseAllow("\n a-1 first reason \n# b-2 not a migration\n\nb-3\nc-4 x\na-1 second reason\n"); | |
| 33 | expect([...allowed]).toEqual([["a-1", "second reason"], ["c-4", "x"]]); | |
| 34 | }); |
test/return-check-script.test.ts added +74
| @@ -0,0 +1,74 @@ | ||
| 1 | import { afterAll, beforeAll, expect, test } from "bun:test"; | |
| 2 | import { mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs"; | |
| 3 | import { join } from "node:path"; | |
| 4 | import { tmpdir } from "node:os"; | |
| 5 | import { gitClientEnv } from "./helpers/git-client.ts"; | |
| 6 | ||
| 7 | const script = join(import.meta.dir, "../scripts/return-check.ts"); | |
| 8 | const ID = "20261201000000-shipped"; | |
| 9 | let repo = ""; | |
| 10 | ||
| 11 | const git = (...args: string[]): void => { | |
| 12 | const r = Bun.spawnSync(["git", "-c", "user.name=t", "-c", "[email protected]", ...args], { cwd: repo, env: gitClientEnv() }); | |
| 13 | if (r.exitCode !== 0) throw new Error(r.stderr.toString()); | |
| 14 | }; | |
| 15 | const run = (...args: string[]): { code: number; out: string; err: string } => { | |
| 16 | const r = Bun.spawnSync(["bun", script, ...args], { cwd: repo, env: gitClientEnv() }); | |
| 17 | return { code: r.exitCode ?? -1, out: r.stdout.toString(), err: r.stderr.toString() }; | |
| 18 | }; | |
| 19 | ||
| 20 | beforeAll(() => { | |
| 21 | repo = mkdtempSync(join(process.env["TMPDIR"] ?? tmpdir(), "return-check-")); | |
| 22 | git("init", "-q"); | |
| 23 | mkdirSync(join(repo, "src/core/migrations"), { recursive: true }); | |
| 24 | writeFileSync(join(repo, "src/core/migrations", `${ID}.ts`), "export default 1;\n"); | |
| 25 | git("add", "-A"); | |
| 26 | git("commit", "-qm", "shipped"); | |
| 27 | git("tag", "v0.0.1"); | |
| 28 | }); | |
| 29 | afterAll(() => rmSync(repo, { recursive: true, force: true })); | |
| 30 | ||
| 31 | test("nothing changed since the tag: exit 0", () => { | |
| 32 | const r = run("v0.0.1"); | |
| 33 | expect(r.code).toBe(0); | |
| 34 | expect(r.out).toContain("0 migration(s) since v0.0.1, 0 unproven"); | |
| 35 | }); | |
| 36 | ||
| 37 | test("a shipped migration that changed: exit 1 with its line, and --allow lets it through", () => { | |
| 38 | writeFileSync(join(repo, "src/core/migrations", `${ID}.ts`), "export default 2;\n"); | |
| 39 | git("commit", "-qam", "edit"); | |
| 40 | const held = run("v0.0.1"); | |
| 41 | expect(held.code).toBe(1); | |
| 42 | expect(held.out).toContain(`${ID}: changed or removed after it shipped`); | |
| 43 | const allow = join(repo, "allow.txt"); | |
| 44 | writeFileSync(allow, `# a note\n${ID} the person checked the old build\n`); | |
| 45 | const passed = run("v0.0.1", "--allow", allow); | |
| 46 | expect(passed.code).toBe(0); | |
| 47 | expect(passed.out).toContain("let through by a person: the person checked the old build"); | |
| 48 | writeFileSync(allow, `${ID}\n`); | |
| 49 | expect(run("v0.0.1", "--allow", allow).code).toBe(1); | |
| 50 | }); | |
| 51 | ||
| 52 | test("--log appends stamped lines and never overwrites", () => { | |
| 53 | const log = join(repo, "release.log"); | |
| 54 | writeFileSync(log, "earlier line\n"); | |
| 55 | run("v0.0.1", "--log", log); | |
| 56 | run("v0.0.1", "--log", log); | |
| 57 | const lines = readFileSync(log, "utf8").trimEnd().split("\n"); | |
| 58 | expect(lines[0]).toBe("earlier line"); | |
| 59 | expect(lines).toHaveLength(5); | |
| 60 | expect(lines[1]).toMatch(/^\d{4}-\d\d-\d\dT[\d:.]+Z \S+: changed or removed after it shipped$/); | |
| 61 | expect(lines[2]).toMatch(/^\d{4}-\d\d-\d\dT[\d:.]+Z return-check: 1 migration\(s\) since v0.0.1, 1 unproven$/); | |
| 62 | }); | |
| 63 | ||
| 64 | test("a bad tag, a tag git cannot find, or a flag with no value: exit 2", () => { | |
| 65 | expect(run("main").code).toBe(2); | |
| 66 | expect(run().code).toBe(2); | |
| 67 | expect(run("v9.9.9").code).toBe(2); | |
| 68 | const noAllow = run("v0.0.1", "--allow"); | |
| 69 | expect(noAllow.code).toBe(2); | |
| 70 | expect(noAllow.err).toContain("--allow needs a file"); | |
| 71 | const noLog = run("v0.0.1", "--log"); | |
| 72 | expect(noLog.code).toBe(2); | |
| 73 | expect(noLog.err).toContain("--log needs a file"); | |
| 74 | }); |
test/schema-additive.test.ts +20 −1
| @@ -14,7 +14,7 @@ import { | ||
| 14 | 14 | migrations, |
| 15 | 15 | NUMBERED, |
| 16 | 16 | } from "../src/core/schema.ts"; |
| 17 | import { notAdditive } from "../src/kernel/migrate.ts"; | |
| 17 | import { notAdditive, unprovenReturn } from "../src/kernel/migrate.ts"; | |
| 18 | 18 | |
| 19 | 19 | describe("migrations are additive across a roll", () => { |
| 20 | 20 | test("the guard names what an old process could not serve under", () => { |
| @@ -66,6 +66,25 @@ describe("migrations are additive across a roll", () => { | ||
| 66 | 66 | expect(notAdditive(sql)).toEqual([]); |
| 67 | 67 | }); |
| 68 | 68 | |
| 69 | test("what makes a return to the image before unproven is named, on tables that were there", () => { | |
| 70 | for (const [sql, why] of [ | |
| 71 | ["CREATE UNIQUE INDEX run_x ON run(x);", "adds a unique index on run"], | |
| 72 | ["CREATE TRIGGER t AFTER INSERT ON run BEGIN SELECT 1; END;", "adds a trigger on run"], | |
| 73 | ["UPDATE run SET reason = 'x';", "updates rows of run"], | |
| 74 | ['DELETE FROM "run" WHERE x = 1;', "deletes rows of run"], | |
| 75 | ["INSERT OR IGNORE INTO run (id) VALUES ('a');", "inserts rows into run"], | |
| 76 | ["ALTER TABLE run ADD COLUMN c TEXT CHECK (c <> '');", "adds a column with a CHECK or a reference to run"], | |
| 77 | ["DROP TABLE run;", "drops a table"], | |
| 78 | ] as const) | |
| 79 | expect(unprovenReturn(sql)).toEqual([why]); | |
| 80 | for (const sql of [ | |
| 81 | "ALTER TABLE run ADD COLUMN why TEXT; CREATE INDEX run_why ON run(why);", | |
| 82 | "CREATE TABLE x (id TEXT REFERENCES run(id) ON UPDATE CASCADE ON DELETE CASCADE); CREATE UNIQUE INDEX x_id ON x(id); INSERT INTO x SELECT id FROM run;", | |
| 83 | "-- UPDATE run SET x = 1\nCREATE TABLE y (id TEXT DEFAULT 'DELETE FROM run');", | |
| 84 | ]) | |
| 85 | expect(unprovenReturn(sql)).toEqual([]); | |
| 86 | }); | |
| 87 | ||
| 69 | 88 | test("every migration not in both releases still in play is additive", () => { |
| 70 | 89 | const inPlay = record.releases.slice(0, 2).map(shipped); |
| 71 | 90 | expect(inPlay.length).toBeGreaterThan(0); |
new above
offline
--allowas the last argument givesfile === undefinedand the check carries on with no allow list; same for--logat line 43. Exit 2 with the usage line instead, so a typo is not a silent hold or a silent missing log.