Skip to content

Commit 14a4c74

Browse files
committed
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 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QSeKYo86w1wqy2z2fMrryr
1 parent dbc1765 commit 14a4c74

5 files changed

Lines changed: 132 additions & 5 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@objectstack/scenarios': patch
3+
---
4+
5+
`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.

‎docs/qa/scenarios/builds/travel_expense.provenance.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"card": "travel_expense",
3-
"cardSha256": "29162eefb46055941a0263686c2853246b4c408d41acb90c6abe22f68886a768",
3+
"cardSha256": "212abedb6b59a5ac0c6921c25bdcc4dc057cbc25e866a9cd2ed962920368a00d",
44
"build": "travel_expense.json",
55
"sha256": "4ab7e603101e6adee0ede53563a13a9a830c8323d8e3f702222986042e726fd8",
66
"runner": "ec227fc7",

‎packages/qa/scenarios/README.md‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,10 @@ files only: no model, no network, and no score of its own — every figure is th
288288
- **Template and ask modes** author no first build: the row is the build they were supplied. `run --template F`
289289
writes the file's name and sha256 at the record's top level (`template`), so runs on one template share a row; a
290290
record that names no file (written before the key) is a row of its own, never summed with another; an ask mode on
291-
`this run’s from-scratch build` takes that run's scratch author.
291+
`this run’s from-scratch build` takes that run's scratch author. When `F.provenance.json` sits beside the
292+
template and names the same card with another `cardSha256` than the sha256 of the card file the run grades, `run`
293+
prints a `warning: template provenance:` line before the card runs (and grades it anyway); the committed
294+
`docs/qa/scenarios/builds/` provenances are pinned to their cards in `test/runner/template-provenance.test.ts`.
292295
- **Never summed silently**: a table's runs must share the prompt choice, the package source, the ask repeats and the
293296
driver (a replay is its own driver), the ask skills (`--ask-skills`: names and sha256; a record without them
294297
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`).

‎packages/qa/scenarios/src/runner/cli.ts‎

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@
142142
import { execSync } from 'node:child_process';
143143
import { mkdirSync, mkdtempSync, readFileSync, writeFileSync } from 'node:fs';
144144
import { tmpdir } from 'node:os';
145-
import { dirname, join, resolve } from 'node:path';
145+
import { basename, dirname, join, resolve } from 'node:path';
146146
import { fileURLToPath } from 'node:url';
147147

148148
import { formatRefusal, libraryOf, loadScenarios, readCapabilityAreas, type LoadedScenario } from '../loader.js';
@@ -470,6 +470,46 @@ export function loadedCardStamp(loaded: Pick<LoadedScenario, 'fileSha256' | 'car
470470
return { id: loaded.card.id, sha256: loaded.fileSha256 };
471471
}
472472

473+
/** The provenance file beside a verified build: `builds/F.json` → `builds/F.provenance.json` (`docs/qa/scenarios/README.md`, Verified builds). */
474+
export function templateProvenancePath(path: string): string {
475+
return path.replace(/(\.json)?$/, '.provenance.json');
476+
}
477+
478+
/**
479+
* The line `run` prints when the `--template` file's provenance names another
480+
* card file than the one the run grades: its `cardSha256` is the sha256 of the
481+
* card file's bytes, the hash the record stamps (`CardStamp`), and it changes
482+
* by PR with the card. Undefined when the two agree, when the template has no
483+
* provenance file beside it, or when the provenance is another card's. A
484+
* warning, never a refusal: the run still grades the card it loaded.
485+
*/
486+
export function templateProvenanceWarning(
487+
path: string,
488+
card: CardStamp,
489+
read: (provenancePath: string) => string | undefined = (p) => {
490+
try {
491+
return readFileSync(p, 'utf8');
492+
} catch {
493+
return undefined;
494+
}
495+
},
496+
): string | undefined {
497+
const provenancePath = templateProvenancePath(path);
498+
const text = read(provenancePath);
499+
if (text === undefined) return undefined;
500+
const file = basename(provenancePath);
501+
let provenance: { card?: unknown; cardSha256?: unknown };
502+
try {
503+
provenance = JSON.parse(text);
504+
} catch {
505+
return `template provenance: ${file} is not JSON, so nothing says which card the template was verified against`;
506+
}
507+
if (typeof provenance.card === 'string' && provenance.card !== card.id) return undefined;
508+
if (typeof provenance.cardSha256 !== 'string') return `template provenance: ${file} names no cardSha256, so nothing says which ${card.id} card the template was verified against`;
509+
if (provenance.cardSha256 === card.sha256) return undefined;
510+
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`;
511+
}
512+
473513
export async function main(argv: readonly string[]): Promise<number> {
474514
// `summary` reads records back; it runs nothing (`summary.ts`).
475515
if (argv[0] === 'summary') return summaryMain(argv.slice(1));
@@ -592,11 +632,14 @@ export async function main(argv: readonly string[]): Promise<number> {
592632
if (loaded.card.asOf !== undefined && loaded.card.asOf !== scenario.card.asOf) {
593633
console.log(`dates: the card's ${loaded.card.asOf} is run as ${scenario.card.asOf}, every card date moved by the same days`);
594634
}
635+
// The card file the run graded, as it was loaded (`CardStamp`): the record and the scorecard name its hash.
636+
const card = loadedCardStamp(loaded);
637+
// A verified build's provenance names the card file it was verified against; one that names another is stale.
638+
const staleProvenance = args.template ? templateProvenanceWarning(args.template, card) : undefined;
639+
if (staleProvenance) console.log(`warning: ${staleProvenance}`);
595640
publishedVersions = new Set();
596641
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 } : {}) });
597642
const packages: PackageSource = workspace ? workspace.source : { source: 'published', versions: [...publishedVersions].sort() };
598-
// The card file the run graded, as it was loaded (`CardStamp`): the record and the scorecard name its hash.
599-
const card = loadedCardStamp(loaded);
600643
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);
601644
const file = join(outDir, `${date}-scenario-${scenario.card.id}.json`);
602645
writeFileSync(file, JSON.stringify(record, null, 2));
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
/**
4+
* A verified build's provenance names the card file it was verified against
5+
* (`builds/F.provenance.json` `cardSha256`, `docs/qa/scenarios/README.md`
6+
* Verified builds); `run --template F` warns when it names another card file
7+
* than the one the run grades (`templateProvenanceWarning`, `src/runner/cli.ts`).
8+
* The committed fixtures are read too: a card edit that does not refresh its
9+
* build's provenance fails here, in the PR that made it.
10+
*/
11+
12+
import { createHash } from 'node:crypto';
13+
import { readdirSync, readFileSync } from 'node:fs';
14+
import { dirname, join, resolve } from 'node:path';
15+
import { fileURLToPath } from 'node:url';
16+
17+
import { describe, expect, it } from 'vitest';
18+
19+
import { loadScenarioFile, readCapabilityAreas } from '../../src/index.js';
20+
import { loadedCardStamp, templateProvenancePath, templateProvenanceWarning } from '../../src/runner/cli.js';
21+
22+
const HERE = dirname(fileURLToPath(import.meta.url));
23+
const CARDS = resolve(HERE, '../../../../../docs/qa/scenarios');
24+
const BUILDS = join(CARDS, 'builds');
25+
const AREAS = readCapabilityAreas(resolve(HERE, '../../../../../docs/qa/platform-checklist/areas'));
26+
27+
const A = 'a'.repeat(64);
28+
const B = 'b'.repeat(64);
29+
const card = { id: 'travel_expense', sha256: A };
30+
const reading = (text: string | undefined) => () => text;
31+
32+
describe('templateProvenanceWarning — run --template F against a card', () => {
33+
it('reads the provenance beside the template', () => {
34+
expect(templateProvenancePath('docs/qa/scenarios/builds/travel_expense.json')).toBe('docs/qa/scenarios/builds/travel_expense.provenance.json');
35+
});
36+
37+
it('says nothing when the provenance names the card file the run grades', () => {
38+
expect(templateProvenanceWarning('t.json', card, reading(JSON.stringify({ card: 'travel_expense', cardSha256: A })))).toBeUndefined();
39+
});
40+
41+
it('warns, naming both hashes, when the provenance names another card file', () => {
42+
const line = templateProvenanceWarning('t.json', card, reading(JSON.stringify({ card: 'travel_expense', cardSha256: B })));
43+
expect(line).toBeDefined();
44+
expect(line).toContain('t.provenance.json');
45+
expect(line).toContain(A.slice(0, 12));
46+
expect(line).toContain(B.slice(0, 12));
47+
});
48+
49+
it('warns when the provenance is unreadable as JSON or names no card hash', () => {
50+
expect(templateProvenanceWarning('t.json', card, reading('{'))).toBeDefined();
51+
expect(templateProvenanceWarning('t.json', card, reading(JSON.stringify({ card: 'travel_expense' })))).toBeDefined();
52+
});
53+
54+
it("says nothing for a template with no provenance, or one verified on another card", () => {
55+
expect(templateProvenanceWarning('t.json', card, reading(undefined))).toBeUndefined();
56+
expect(templateProvenanceWarning('t.json', card, reading(JSON.stringify({ card: 'order_to_cash', cardSha256: B })))).toBeUndefined();
57+
});
58+
});
59+
60+
describe('the committed verified builds (docs/qa/scenarios/builds/)', () => {
61+
const provenances = readdirSync(BUILDS).filter((f) => f.endsWith('.provenance.json'));
62+
63+
it('has a provenance for each build', () => {
64+
expect(provenances.length).toBeGreaterThan(0);
65+
});
66+
67+
it.each(provenances)('%s names the card file as the loader reads it, and the build file as it is', (file) => {
68+
const provenance = JSON.parse(readFileSync(join(BUILDS, file), 'utf8')) as { card: string; cardSha256: string; build: string; sha256: string };
69+
const { card: loaded, refusals } = loadScenarioFile(join(CARDS, `${provenance.card}.json`), { areas: AREAS, library: 'open' });
70+
expect(refusals).toEqual([]);
71+
const stamp = loadedCardStamp(loaded!);
72+
expect(provenance.cardSha256).toBe(stamp.sha256);
73+
expect(templateProvenanceWarning(join(BUILDS, provenance.build), stamp)).toBeUndefined();
74+
expect(provenance.sha256).toBe(createHash('sha256').update(readFileSync(join(BUILDS, provenance.build))).digest('hex'));
75+
});
76+
});

0 commit comments

Comments
 (0)