From cbbf27442c5b5942537d7e5ad177737acf4a9589 Mon Sep 17 00:00:00 2001 From: Grantfox Agent <160465301+emirykl@users.noreply.github.com> Date: Tue, 24 Nov 2026 00:38:21 +0300 Subject: [PATCH] ci: enforce committed snapshot health checks --- .github/workflows/contract.yml | 5 ++++ .github/workflows/web.yml | 6 ++++ .../dashboard/fixture-health-check.test.ts | 16 +++++++++++ docs/CI.md | 6 ++++ scripts/snapshot-ci.test.mjs | 28 +++++++++++++++++++ 5 files changed, 61 insertions(+) create mode 100644 scripts/snapshot-ci.test.mjs diff --git a/.github/workflows/contract.yml b/.github/workflows/contract.yml index e20f433d..5918c156 100644 --- a/.github/workflows/contract.yml +++ b/.github/workflows/contract.yml @@ -38,6 +38,11 @@ jobs: - name: Run round contract unit tests run: cargo test -p sub-rosa-round + - name: Fail if generated contract snapshots differ from committed evidence + run: | + git diff --exit-code -- contracts/round/test_snapshots/test + test -z "$(git ls-files --others --exclude-standard -- contracts/round/test_snapshots/test)" + - name: Check ERRORS.md stays in sync with enum Error run: node scripts/check-round-errors.mjs diff --git a/.github/workflows/web.yml b/.github/workflows/web.yml index e31d4c45..e0cf0ace 100644 --- a/.github/workflows/web.yml +++ b/.github/workflows/web.yml @@ -34,9 +34,15 @@ jobs: - name: Check web CI configuration run: node --test scripts/web-ci.test.mjs + - name: Check snapshot CI configuration + run: node --test scripts/snapshot-ci.test.mjs + - name: Install JS dependencies run: pnpm install --frozen-lockfile --ignore-scripts + - name: Check committed contract snapshot inventory + run: pnpm snapshot:check + - name: Test web run: pnpm web:test diff --git a/apps/web/src/dashboard/fixture-health-check.test.ts b/apps/web/src/dashboard/fixture-health-check.test.ts index 12665b54..6d709681 100644 --- a/apps/web/src/dashboard/fixture-health-check.test.ts +++ b/apps/web/src/dashboard/fixture-health-check.test.ts @@ -3,6 +3,7 @@ import assert from "node:assert/strict"; import { test } from "node:test"; import { DASHBOARD_FIXTURE } from "./fixture.js"; +import { DEMO_TRACE } from "../demo/demo-trace.generated.js"; import { assertDashboardData, DashboardDataHealthCheckError, @@ -12,6 +13,21 @@ test("bundled dashboard fixture contains every field required by the UI", () => assert.doesNotThrow(() => assertDashboardData(DASHBOARD_FIXTURE)); }); +test("dashboard fixture agrees with the committed demo trace", () => { + assert.equal(DASHBOARD_FIXTURE.meta.contractId, DEMO_TRACE.meta.contractId); + assert.equal(DASHBOARD_FIXTURE.meta.roundId, DEMO_TRACE.meta.roundId); + assert.equal(DASHBOARD_FIXTURE.round.revealRound, DEMO_TRACE.meta.revealRound); + assert.equal(DASHBOARD_FIXTURE.meta.fetchedAt, DEMO_TRACE.meta.recordedAt); + assert.equal(DASHBOARD_FIXTURE.round.status, DEMO_TRACE.meta.roundStatus); + assert.equal(DASHBOARD_FIXTURE.round.winner, DEMO_TRACE.keeper.clearWinner); + assert.equal(DASHBOARD_FIXTURE.round.winningBid, DEMO_TRACE.settlement.operatorReceivedUsdc); + assert.equal(DASHBOARD_FIXTURE.settlement?.contractBalance, DEMO_TRACE.keeper.contractBalanceFinal); + assert.deepEqual( + DASHBOARD_FIXTURE.bidders.map(({ address, bidUsdc }) => ({ address, bidUsdc })), + DEMO_TRACE.bidders.map(({ address, bidUsdc }) => ({ address, bidUsdc })), + ); +}); + test("health check identifies a missing required field by its path", () => { const invalidData = structuredClone(DASHBOARD_FIXTURE) as unknown as { meta: { contractId?: string }; diff --git a/docs/CI.md b/docs/CI.md index dabddd1a..ecf1ef64 100644 --- a/docs/CI.md +++ b/docs/CI.md @@ -24,6 +24,12 @@ dependencies without lifecycle scripts, then runs `pnpm web:test`, locally to check `apps/web`; `node --test scripts/web-ci.test.mjs` verifies the CI job configuration. +The same job runs `pnpm snapshot:check` to require the committed contract +snapshot categories, while `web:test` checks the generated demo trace and its +agreement with the dashboard fixture. The contract job regenerates Rust test +snapshots and fails if tracked snapshots change or new snapshots appear. Run +`node --test scripts/snapshot-ci.test.mjs` to verify these CI gates. + Repository-level GitHub Actions settings, including the approval policy for fork pull request workflows, are recorded in [GITHUB_ACTIONS_SECURITY.md](./GITHUB_ACTIONS_SECURITY.md). diff --git a/scripts/snapshot-ci.test.mjs b/scripts/snapshot-ci.test.mjs new file mode 100644 index 00000000..fef29699 --- /dev/null +++ b/scripts/snapshot-ci.test.mjs @@ -0,0 +1,28 @@ +// Copyright (c) 2026 Sub Rosa contributors +import assert from "node:assert/strict"; +import { readFileSync } from "node:fs"; +import { test } from "node:test"; + +const web = readFileSync(new URL("../.github/workflows/web.yml", import.meta.url), "utf8"); +const contract = readFileSync(new URL("../.github/workflows/contract.yml", import.meta.url), "utf8"); +const scripts = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8")).scripts; +const webScripts = JSON.parse(readFileSync(new URL("../apps/web/package.json", import.meta.url), "utf8")).scripts; + +test("web CI blocks on snapshot inventory and dashboard evidence checks", () => { + assert.equal(scripts["snapshot:check"], "node scripts/check-snapshots.mjs"); + assert.match(web, /^ run: node --test scripts\/snapshot-ci\.test\.mjs$/m); + assert.match(web, /^ run: pnpm snapshot:check$/m); + assert.doesNotMatch(web, /\bcontinue-on-error\s*:/); + assert.ok(web.indexOf("pnpm install --frozen-lockfile --ignore-scripts") < web.indexOf("pnpm snapshot:check")); + assert.ok(web.indexOf("pnpm snapshot:check") < web.indexOf("pnpm web:test")); + assert.match(webScripts.test, /src\/dashboard\/fixture-health-check\.test\.ts/); + assert.match(webScripts.test, /src\/demo\/trace-health-check\.test\.ts/); +}); + +test("contract CI rejects regenerated or newly created snapshots", () => { + assert.match(contract, /^ run: cargo test -p sub-rosa-round$/m); + assert.match(contract, /git diff --exit-code -- contracts\/round\/test_snapshots\/test/); + assert.match(contract, /git ls-files --others --exclude-standard -- contracts\/round\/test_snapshots\/test/); + assert.doesNotMatch(contract, /\bcontinue-on-error\s*:/); + assert.ok(contract.indexOf("cargo test -p sub-rosa-round") < contract.indexOf("git diff --exit-code -- contracts/round/test_snapshots/test")); +});