// Run the dispatch commit's verifier in a disposable checkout of the exact stamp. import { execFileSync } from "node:child_process" import { lstatSync, mkdtempSync, rmSync } from "node:fs" import { tmpdir } from "node:os" import { join } from "node:path" import { isGeneratedReleasePath, isReleaseNotesPath, stampRefusals, versionRefusals } from "./release-state-paths.mjs" const [pin, stamp, version, nativeVersion] = process.argv.slice(2) const run = (cmd, args, cwd = process.cwd()) => execFileSync(cmd, args, { cwd, encoding: "utf8", maxBuffer: 64 * 1024 * 1024 }) const git = (...args) => run("git", args) if (![pin, stamp].every((sha) => /^[0-9a-f]{40}$/.test(sha))) throw new Error("expected full pin and stamp SHAs") if (git("rev-parse", "HEAD").trim() !== stamp || git("rev-parse", `${stamp}^1`).trim() !== pin) throw new Error("stamp checkout or parent mismatch") git("diff", "--quiet", stamp, "--") const refused = [...versionRefusals(pin, stamp, version, nativeVersion), ...stampRefusals(pin, stamp)] if (refused.length) throw new Error(refused.join("\n")) const changed = git("diff", "--no-renames", "--name-only", "-z", pin, stamp).split("\0").filter(Boolean) for (const path of changed) { const before = git("ls-tree", "-z", pin, "--", path) const after = git("ls-tree", "-z", stamp, "--", path) if ((before && !/^100(644|755) blob /.test(before)) || (after && !/^100(644|755) blob /.test(after))) throw new Error(`not a regular release file: ${path}`) if (before && after && before.slice(0, 6) !== after.slice(0, 6)) throw new Error(`mode changed: ${path}`) } // Recreate the release notes from the pin's fragments, including deletions, // package logs and newly created log files. Compare Git modes as well as bytes. const scratch = mkdtempSync(join(tmpdir(), "release-stamp-proof-")) const basis = join(scratch, "pin") try { git("worktree", "add", "--quiet", "--detach", basis, pin) const date = new Date(Number(git("show", "-s", "--format=%ct", stamp)) * 1000).toISOString().slice(0, 10) run("bun", ["script/stamp-release-changelog.ts", version, date], basis) run("git", ["add", "-A"], basis) const replay = run("git", ["write-tree"], basis).trim() const docsMismatch = git("diff", "--no-renames", "--name-only", "-z", replay, stamp) .split("\0") .filter(isReleaseNotesPath) if (docsMismatch.length) throw new Error(`release notes differ from replay: ${docsMismatch.join(", ")}`) } finally { try { git("worktree", "remove", "--force", basis) } finally { rmSync(scratch, { recursive: true, force: true }) } } // A path matching a bundle glob is not evidence. Remove changed outputs so a // generator that silently ignores a forged/extra file cannot validate it. for (const path of changed.filter(isGeneratedReleasePath)) { if (!git("ls-tree", pin, "--", path) || !lstatSync(path).isFile()) throw new Error(`unsupported generated output: ${path}`) rmSync(path) } console.log(`Release notes match their replay at ${pin}; checking generated bytes at ${stamp}.`) run("bun", ["install", "--frozen-lockfile", "--ignore-scripts"]) run("node", ["packages/omo-senpi/plugin/scripts/build-extension.mjs"]) run("bun", ["script/build-codex-install.ts"]) run("bun", ["script/build-service-auth.ts"]) run("node", ["packages/omo-senpi/plugin/scripts/build-extension.mjs", "--check"]) run("node", ["packages/omo-senpi/plugin/scripts/build-install.mjs", "--check"]) run("bun", ["run", "bundle-inputs:check"]) run("bun", ["run", "brand-logo:check"]) run("bun", ["test", "./script/codex-install-bundle-freshness.test.ts"]) run("bun", ["script/build-service-auth.ts", "--check"]) const stale = git("diff", "--name-only", "-z", stamp, "--").split("\0").filter(Boolean) if (stale.length) throw new Error(`generated bytes differ from stamp: ${stale.join(", ")}`) if (git("ls-files", "--others", "--exclude-standard", "-z")) throw new Error("untracked generator outputs")