From 14a4c74e6cabc575ca67cd681a9d59b018ca2158 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 25 Nov 2026 17:55:19 +0000 Subject: [PATCH 1/3] fix(scenarios): refresh travel_expense build provenance cardSha256; run --template warns on a stale one The verified build's provenance named card sha256 29162eef..., the card before #36320 and #36617; the card file on main hashes to 212abedb... (sha256 of the file's bytes, as the loader stamps it). Since the build was authored only the card's prompt and run sections changed; expect and iterate did not, so the build file and its verified scores stand. run --template F now prints a warning when F.provenance.json names the same card with another cardSha256, and a test pins each committed provenance to its card and build file. Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01QSeKYo86w1wqy2z2fMrryr --- .../36491-template-provenance-card-sha.md | 5 ++ .../builds/travel_expense.provenance.json | 2 +- packages/qa/scenarios/README.md | 5 +- packages/qa/scenarios/src/runner/cli.ts | 49 +++++++++++- .../test/runner/template-provenance.test.ts | 76 +++++++++++++++++++ 5 files changed, 132 insertions(+), 5 deletions(-) create mode 100644 .changeset/36491-template-provenance-card-sha.md create mode 100644 packages/qa/scenarios/test/runner/template-provenance.test.ts diff --git a/.changeset/36491-template-provenance-card-sha.md b/.changeset/36491-template-provenance-card-sha.md new file mode 100644 index 00000000000..1823898c3bc --- /dev/null +++ b/.changeset/36491-template-provenance-card-sha.md @@ -0,0 +1,5 @@ +--- +'@objectstack/scenarios': patch +--- + +`run --template F` warns when `F.provenance.json` beside the template names another `cardSha256` than the sha256 of the card file the run grades, so a verified build whose provenance went stale after a card edit is named before the card runs. The run still grades the card it loaded. diff --git a/docs/qa/scenarios/builds/travel_expense.provenance.json b/docs/qa/scenarios/builds/travel_expense.provenance.json index cd6ecc42715..69dcc0fec28 100644 --- a/docs/qa/scenarios/builds/travel_expense.provenance.json +++ b/docs/qa/scenarios/builds/travel_expense.provenance.json @@ -1,6 +1,6 @@ { "card": "travel_expense", - "cardSha256": "29162eefb46055941a0263686c2853246b4c408d41acb90c6abe22f68886a768", + "cardSha256": "212abedb6b59a5ac0c6921c25bdcc4dc057cbc25e866a9cd2ed962920368a00d", "build": "travel_expense.json", "sha256": "4ab7e603101e6adee0ede53563a13a9a830c8323d8e3f702222986042e726fd8", "runner": "ec227fc7", diff --git a/packages/qa/scenarios/README.md b/packages/qa/scenarios/README.md index 059fc93012e..c0feb487e4d 100644 --- a/packages/qa/scenarios/README.md +++ b/packages/qa/scenarios/README.md @@ -288,7 +288,10 @@ files only: no model, no network, and no score of its own — every figure is th - **Template and ask modes** author no first build: the row is the build they were supplied. `run --template F` writes the file's name and sha256 at the record's top level (`template`), so runs on one template share a row; a record that names no file (written before the key) is a row of its own, never summed with another; an ask mode on - `this run’s from-scratch build` takes that run's scratch author. + `this run’s from-scratch build` takes that run's scratch author. When `F.provenance.json` sits beside the + template and names the same card with another `cardSha256` than the sha256 of the card file the run grades, `run` + prints a `warning: template provenance:` line before the card runs (and grades it anyway); the committed + `docs/qa/scenarios/builds/` provenances are pinned to their cards in `test/runner/template-provenance.test.ts`. - **Never summed silently**: a table's runs must share the prompt choice, the package source, the ask repeats and the driver (a replay is its own driver), the ask skills (`--ask-skills`: names and sha256; a record without them reads `none`), the door arm (`--modes door`, below; a record without one reads `skills: none · rules: none`), the card file they graded (`card`, below; a record without it reads `card: not recorded`), and the schema masking of the apps they booted (`--schema-masking off`, below; a record without it reads `schema masking: on`). diff --git a/packages/qa/scenarios/src/runner/cli.ts b/packages/qa/scenarios/src/runner/cli.ts index db493b8f7b1..7e5cbb4d804 100644 --- a/packages/qa/scenarios/src/runner/cli.ts +++ b/packages/qa/scenarios/src/runner/cli.ts @@ -142,7 +142,7 @@ import { execSync } from 'node:child_process'; import { mkdirSync, mkdtempSync, readFileSync, writeFileSync } from 'node:fs'; import { tmpdir } from 'node:os'; -import { dirname, join, resolve } from 'node:path'; +import { basename, dirname, join, resolve } from 'node:path'; import { fileURLToPath } from 'node:url'; import { formatRefusal, libraryOf, loadScenarios, readCapabilityAreas, type LoadedScenario } from '../loader.js'; @@ -470,6 +470,46 @@ export function loadedCardStamp(loaded: Pick string | undefined = (p) => { + try { + return readFileSync(p, 'utf8'); + } catch { + return undefined; + } + }, +): string | undefined { + const provenancePath = templateProvenancePath(path); + const text = read(provenancePath); + if (text === undefined) return undefined; + const file = basename(provenancePath); + let provenance: { card?: unknown; cardSha256?: unknown }; + try { + provenance = JSON.parse(text); + } catch { + return `template provenance: ${file} is not JSON, so nothing says which card the template was verified against`; + } + if (typeof provenance.card === 'string' && provenance.card !== card.id) return undefined; + if (typeof provenance.cardSha256 !== 'string') return `template provenance: ${file} names no cardSha256, so nothing says which ${card.id} card the template was verified against`; + if (provenance.cardSha256 === card.sha256) return undefined; + return `template provenance: ${file} names card ${card.id} sha256 ${provenance.cardSha256.slice(0, 12)}, but the card this run grades is sha256 ${card.sha256.slice(0, 12)} — refresh its cardSha256 by PR`; +} + export async function main(argv: readonly string[]): Promise { // `summary` reads records back; it runs nothing (`summary.ts`). if (argv[0] === 'summary') return summaryMain(argv.slice(1)); @@ -592,11 +632,14 @@ export async function main(argv: readonly string[]): Promise { if (loaded.card.asOf !== undefined && loaded.card.asOf !== scenario.card.asOf) { console.log(`dates: the card's ${loaded.card.asOf} is run as ${scenario.card.asOf}, every card date moved by the same days`); } + // The card file the run graded, as it was loaded (`CardStamp`): the record and the scorecard name its hash. + const card = loadedCardStamp(loaded); + // A verified build's provenance names the card file it was verified against; one that names another is stale. + const staleProvenance = args.template ? templateProvenanceWarning(args.template, card) : undefined; + if (staleProvenance) console.log(`warning: ${staleProvenance}`); publishedVersions = new Set(); const cardRun = await runCard(scenario, driver, ops, { modes: args.modes, iterateRun: args.iterateRun, admin: ADMIN, ...(template ? { templateArtifact: template } : {}), ...(args.askRepeats !== undefined ? { askRepeats: args.askRepeats } : {}), ...(promptChoice ? { promptChoice } : {}), ...(schemaMasking === 'off' ? { schemaMasking } : {}) }); const packages: PackageSource = workspace ? workspace.source : { source: 'published', versions: [...publishedVersions].sort() }; - // The card file the run graded, as it was loaded (`CardStamp`): the record and the scorecard name its hash. - const card = loadedCardStamp(loaded); const record = withSuppliedTemplate(runRecord({ run: `${date}-scenario-${scenario.card.id}`, date, ...(framework ? { framework } : {}), packages, driver: info, runner: 'scenario-runner', evidenceDir: work, card, ...(schemaMasking === 'off' ? { schemaMasking: 'off' as const } : {}) }, cardRun), cardRun, supplied); const file = join(outDir, `${date}-scenario-${scenario.card.id}.json`); writeFileSync(file, JSON.stringify(record, null, 2)); diff --git a/packages/qa/scenarios/test/runner/template-provenance.test.ts b/packages/qa/scenarios/test/runner/template-provenance.test.ts new file mode 100644 index 00000000000..c69426f5d53 --- /dev/null +++ b/packages/qa/scenarios/test/runner/template-provenance.test.ts @@ -0,0 +1,76 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. + +/** + * A verified build's provenance names the card file it was verified against + * (`builds/F.provenance.json` `cardSha256`, `docs/qa/scenarios/README.md` + * Verified builds); `run --template F` warns when it names another card file + * than the one the run grades (`templateProvenanceWarning`, `src/runner/cli.ts`). + * The committed fixtures are read too: a card edit that does not refresh its + * build's provenance fails here, in the PR that made it. + */ + +import { createHash } from 'node:crypto'; +import { readdirSync, readFileSync } from 'node:fs'; +import { dirname, join, resolve } from 'node:path'; +import { fileURLToPath } from 'node:url'; + +import { describe, expect, it } from 'vitest'; + +import { loadScenarioFile, readCapabilityAreas } from '../../src/index.js'; +import { loadedCardStamp, templateProvenancePath, templateProvenanceWarning } from '../../src/runner/cli.js'; + +const HERE = dirname(fileURLToPath(import.meta.url)); +const CARDS = resolve(HERE, '../../../../../docs/qa/scenarios'); +const BUILDS = join(CARDS, 'builds'); +const AREAS = readCapabilityAreas(resolve(HERE, '../../../../../docs/qa/platform-checklist/areas')); + +const A = 'a'.repeat(64); +const B = 'b'.repeat(64); +const card = { id: 'travel_expense', sha256: A }; +const reading = (text: string | undefined) => () => text; + +describe('templateProvenanceWarning — run --template F against a card', () => { + it('reads the provenance beside the template', () => { + expect(templateProvenancePath('docs/qa/scenarios/builds/travel_expense.json')).toBe('docs/qa/scenarios/builds/travel_expense.provenance.json'); + }); + + it('says nothing when the provenance names the card file the run grades', () => { + expect(templateProvenanceWarning('t.json', card, reading(JSON.stringify({ card: 'travel_expense', cardSha256: A })))).toBeUndefined(); + }); + + it('warns, naming both hashes, when the provenance names another card file', () => { + const line = templateProvenanceWarning('t.json', card, reading(JSON.stringify({ card: 'travel_expense', cardSha256: B }))); + expect(line).toBeDefined(); + expect(line).toContain('t.provenance.json'); + expect(line).toContain(A.slice(0, 12)); + expect(line).toContain(B.slice(0, 12)); + }); + + it('warns when the provenance is unreadable as JSON or names no card hash', () => { + expect(templateProvenanceWarning('t.json', card, reading('{'))).toBeDefined(); + expect(templateProvenanceWarning('t.json', card, reading(JSON.stringify({ card: 'travel_expense' })))).toBeDefined(); + }); + + it("says nothing for a template with no provenance, or one verified on another card", () => { + expect(templateProvenanceWarning('t.json', card, reading(undefined))).toBeUndefined(); + expect(templateProvenanceWarning('t.json', card, reading(JSON.stringify({ card: 'order_to_cash', cardSha256: B })))).toBeUndefined(); + }); +}); + +describe('the committed verified builds (docs/qa/scenarios/builds/)', () => { + const provenances = readdirSync(BUILDS).filter((f) => f.endsWith('.provenance.json')); + + it('has a provenance for each build', () => { + expect(provenances.length).toBeGreaterThan(0); + }); + + it.each(provenances)('%s names the card file as the loader reads it, and the build file as it is', (file) => { + const provenance = JSON.parse(readFileSync(join(BUILDS, file), 'utf8')) as { card: string; cardSha256: string; build: string; sha256: string }; + const { card: loaded, refusals } = loadScenarioFile(join(CARDS, `${provenance.card}.json`), { areas: AREAS, library: 'open' }); + expect(refusals).toEqual([]); + const stamp = loadedCardStamp(loaded!); + expect(provenance.cardSha256).toBe(stamp.sha256); + expect(templateProvenanceWarning(join(BUILDS, provenance.build), stamp)).toBeUndefined(); + expect(provenance.sha256).toBe(createHash('sha256').update(readFileSync(join(BUILDS, provenance.build))).digest('hex')); + }); +}); From af13a9a6a55eff72efb115c68f86da3b5f10d6b9 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 25 Nov 2026 18:22:06 +0000 Subject: [PATCH 2/3] test(scenarios): pin the template provenance warning without reading the fixtures The committed-fixture pin read docs/qa/scenarios/builds/, a radius the package does not declare; it is dropped from this change. The warning's own cases stay, plus one that reads the provenance from disk. Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01QSeKYo86w1wqy2z2fMrryr --- packages/qa/scenarios/README.md | 3 +- .../test/runner/template-provenance.test.ts | 46 ++++++------------- 2 files changed, 15 insertions(+), 34 deletions(-) diff --git a/packages/qa/scenarios/README.md b/packages/qa/scenarios/README.md index c0feb487e4d..304eeddd3bf 100644 --- a/packages/qa/scenarios/README.md +++ b/packages/qa/scenarios/README.md @@ -290,8 +290,7 @@ files only: no model, no network, and no score of its own — every figure is th record that names no file (written before the key) is a row of its own, never summed with another; an ask mode on `this run’s from-scratch build` takes that run's scratch author. When `F.provenance.json` sits beside the template and names the same card with another `cardSha256` than the sha256 of the card file the run grades, `run` - prints a `warning: template provenance:` line before the card runs (and grades it anyway); the committed - `docs/qa/scenarios/builds/` provenances are pinned to their cards in `test/runner/template-provenance.test.ts`. + prints a `warning: template provenance:` line before the card runs, and grades the card anyway. - **Never summed silently**: a table's runs must share the prompt choice, the package source, the ask repeats and the driver (a replay is its own driver), the ask skills (`--ask-skills`: names and sha256; a record without them reads `none`), the door arm (`--modes door`, below; a record without one reads `skills: none · rules: none`), the card file they graded (`card`, below; a record without it reads `card: not recorded`), and the schema masking of the apps they booted (`--schema-masking off`, below; a record without it reads `schema masking: on`). diff --git a/packages/qa/scenarios/test/runner/template-provenance.test.ts b/packages/qa/scenarios/test/runner/template-provenance.test.ts index c69426f5d53..eb9cf9aeb47 100644 --- a/packages/qa/scenarios/test/runner/template-provenance.test.ts +++ b/packages/qa/scenarios/test/runner/template-provenance.test.ts @@ -2,27 +2,18 @@ /** * A verified build's provenance names the card file it was verified against - * (`builds/F.provenance.json` `cardSha256`, `docs/qa/scenarios/README.md` - * Verified builds); `run --template F` warns when it names another card file + * (`builds/F.provenance.json` `cardSha256`, the scenarios README's Verified + * builds); `run --template F` warns when it names another card file * than the one the run grades (`templateProvenanceWarning`, `src/runner/cli.ts`). - * The committed fixtures are read too: a card edit that does not refresh its - * build's provenance fails here, in the PR that made it. */ -import { createHash } from 'node:crypto'; -import { readdirSync, readFileSync } from 'node:fs'; -import { dirname, join, resolve } from 'node:path'; -import { fileURLToPath } from 'node:url'; +import { mkdtempSync, writeFileSync } from 'node:fs'; +import { tmpdir } from 'node:os'; +import { join } from 'node:path'; import { describe, expect, it } from 'vitest'; -import { loadScenarioFile, readCapabilityAreas } from '../../src/index.js'; -import { loadedCardStamp, templateProvenancePath, templateProvenanceWarning } from '../../src/runner/cli.js'; - -const HERE = dirname(fileURLToPath(import.meta.url)); -const CARDS = resolve(HERE, '../../../../../docs/qa/scenarios'); -const BUILDS = join(CARDS, 'builds'); -const AREAS = readCapabilityAreas(resolve(HERE, '../../../../../docs/qa/platform-checklist/areas')); +import { templateProvenancePath, templateProvenanceWarning } from '../../src/runner/cli.js'; const A = 'a'.repeat(64); const B = 'b'.repeat(64); @@ -31,7 +22,7 @@ const reading = (text: string | undefined) => () => text; describe('templateProvenanceWarning — run --template F against a card', () => { it('reads the provenance beside the template', () => { - expect(templateProvenancePath('docs/qa/scenarios/builds/travel_expense.json')).toBe('docs/qa/scenarios/builds/travel_expense.provenance.json'); + expect(templateProvenancePath('cards/builds/x.json')).toBe('cards/builds/x.provenance.json'); }); it('says nothing when the provenance names the card file the run grades', () => { @@ -55,22 +46,13 @@ describe('templateProvenanceWarning — run --template F against a card', () => expect(templateProvenanceWarning('t.json', card, reading(undefined))).toBeUndefined(); expect(templateProvenanceWarning('t.json', card, reading(JSON.stringify({ card: 'order_to_cash', cardSha256: B })))).toBeUndefined(); }); -}); - -describe('the committed verified builds (docs/qa/scenarios/builds/)', () => { - const provenances = readdirSync(BUILDS).filter((f) => f.endsWith('.provenance.json')); - - it('has a provenance for each build', () => { - expect(provenances.length).toBeGreaterThan(0); - }); - it.each(provenances)('%s names the card file as the loader reads it, and the build file as it is', (file) => { - const provenance = JSON.parse(readFileSync(join(BUILDS, file), 'utf8')) as { card: string; cardSha256: string; build: string; sha256: string }; - const { card: loaded, refusals } = loadScenarioFile(join(CARDS, `${provenance.card}.json`), { areas: AREAS, library: 'open' }); - expect(refusals).toEqual([]); - const stamp = loadedCardStamp(loaded!); - expect(provenance.cardSha256).toBe(stamp.sha256); - expect(templateProvenanceWarning(join(BUILDS, provenance.build), stamp)).toBeUndefined(); - expect(provenance.sha256).toBe(createHash('sha256').update(readFileSync(join(BUILDS, provenance.build))).digest('hex')); + it('reads the provenance file from disk beside the template by default', () => { + const dir = mkdtempSync(join(tmpdir(), 'scenario-provenance-')); + const template = join(dir, 'travel_expense.json'); + writeFileSync(template, '{}'); + expect(templateProvenanceWarning(template, card)).toBeUndefined(); + writeFileSync(join(dir, 'travel_expense.provenance.json'), JSON.stringify({ card: 'travel_expense', cardSha256: B })); + expect(templateProvenanceWarning(template, card)).toContain(B.slice(0, 12)); }); }); From 0d4f42ec4956fc1ad9e92b29b6979e7051e8d753 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 25 Nov 2026 18:50:58 +0000 Subject: [PATCH 3/3] chore(changeset): declaration lines on the template provenance changeset Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01QSeKYo86w1wqy2z2fMrryr --- .changeset/36491-template-provenance-card-sha.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.changeset/36491-template-provenance-card-sha.md b/.changeset/36491-template-provenance-card-sha.md index 1823898c3bc..615219a66cc 100644 --- a/.changeset/36491-template-provenance-card-sha.md +++ b/.changeset/36491-template-provenance-card-sha.md @@ -3,3 +3,6 @@ --- `run --template F` warns when `F.provenance.json` beside the template names another `cardSha256` than the sha256 of the card file the run grades, so a verified build whose provenance went stale after a card edit is named before the card runs. The run still grades the card it loaded. + +Clause-②: no +Metadata-protocol: none