Skip to content

Commit a182fbe

Browse files
fix(scenarios): travel_expense build provenance names the current card; run --template warns on a stale cardSha256 (#37339)
Fixes #36491 Clause-②: no Metadata-protocol: none ## 维护者速读 - 用户无感:只影响内部场景评测工具,差旅报销的已验证构建记录改成指向现在这张卡,评测跑在不匹配的记录上时会先提示一句。 - 属于场景卡评测的固定样本维护,替每日问数评测解决"记录指向旧卡"的问题。 - 出错时只是多一行或少一行提示,评测照常打分;改动可直接撤回。 - 无 ## What changes - `docs/qa/scenarios/builds/travel_expense.provenance.json`: `cardSha256` `29162eef…` -> `212abedb6b59a5ac0c6921c25bdcc4dc057cbc25e866a9cd2ed962920368a00d`, the sha256 of the raw bytes of `docs/qa/scenarios/travel_expense.json` on `dbc1765a24`. That is the hash the loader computes (`loader.ts` `fileSha256`, `createHash('sha256').update(bytes)`) and every run record stamps (`CardStamp`); there is no canonical form. The issue body names `a8a67be3…`; the card moved again since (#36503 to `68eb89a9…`, #36617 to `212abedb…`). - `packages/qa/scenarios/src/runner/cli.ts`: `templateProvenanceWarning(path, card)` reads `F.provenance.json` beside the `--template F` file; when it names the same card with another `cardSha256` (or none, or is not JSON), `run` prints a `warning: template provenance:` line before the card runs. It never refuses; a missing provenance or one for another card says nothing. It lives in the CLI entry, not the `./runner` export, so the published import surface is unchanged. - `packages/qa/scenarios/README.md`: one sentence under "Template and ask modes". - Changeset: `@objectstack/scenarios` patch. ## Acceptance notes - **Provenance honesty.** The build was authored from card `9d0c7dad…` (the card when #35222 committed it). Practice since #35764 and #36065 has been to refresh `cardSha256` on a card edit with the build untouched, so the field reads as "the card this fixture is current against", while #36617's body reads it as "the card at build time". This PR follows the practice. Measured to back it: between `9d0c7dad…` and `212abedb…` only the card's `prompt` and `run` keys differ; `expect` and `iterate` are byte-identical (top-level `JSON.stringify` compare). A scratch `scoreGraph(artifactToEvalGraph(build), expect)` re-score gives 61/61 on both the `29162eef…` card and the current one. So the `verified` scores still hold for the current card, but `built`/`author` describe a run made against an older prompt (the step-two routing prose from #35098 and the record-triggered flow prose from #36617 are not in it). The provenance still does not record that, and this PR does not add a field for it. - **Other provenances.** `builds/` holds one provenance, so there are no others to refresh. - **Not in this PR: a fixture pin.** I wrote a test that reads `docs/qa/scenarios/builds/` and holds each `cardSha256` equal to its card. That turns the next stale card edit into a red CI run, not only a run-time warning. `check:cross-package-test-inputs` refused it because the radius is undeclared, and declaring it means editing `scripts/cross-package-test-inputs.mjs` and the root `turbo.json`, both outside this card's file surface. I left it out. - **Open PR #37314** changes `docs/qa/scenarios/builds/travel_expense.json` (`protocol ^18 -> ^19`) without touching the provenance. Once it lands, the provenance's `sha256` (`4ab7e603…`) no longer matches the build file, and no `amended` entry records the change. That PR does not overlap these files. ## Verification First read (by risk): 1. `packages/qa/scenarios/src/runner/cli.ts`, `templateProvenanceWarning`: when it stays silent and when it warns. 2. `docs/qa/scenarios/builds/travel_expense.provenance.json`: the one-line hash change. Two-minute check: `sha256sum docs/qa/scenarios/travel_expense.json` prints `212abedb6b59a5ac…`, the same value the provenance now holds. <details><summary>Tests and gates (head 0d4f42e)</summary> - `os-verify-lock.sh -c "pnpm --filter @objectstack/scenarios build && … typecheck && … test"` on `af13a9a6a5` (the test/src tree of the final head): VERDICT command-exit 0; Test Files 43 passed (43), Tests 1342 passed (1342). - Ablation (committed first, restored with `git checkout HEAD --`, `git diff HEAD` empty, blob hash matched): `scripts/ablation-replace.mjs` replaced `if (provenance.cardSha256 === card.sha256) return undefined;` with `return undefined;` (anchor 1 -> 0). `test/runner/template-provenance.test.ts` then went 2 failed / 4 passed, the two warning cases red. - `node scripts/pm/dispatch-gates.mjs --commands` on `af13a9a6a5`: 65 commands, all run; `--ran` reconciliation: 65 derived, 65 run, 0 UNRUN. Non-zero: `check:dual-build-cjs-loads` exit 3 PREREQUISITE NOT MET (needs a whole-workspace build, so NOT MEASURED locally; CI runs it). `check:dts-closure` exit 1 in the batch because `plugin-audit` dist was half-built in this shared tree; after `pnpm --filter @objectstack/plugin-audit build` it exits 0. On `0d4f42ec49` (changeset declaration lines only) the changeset family ran again: `check-changeset-no-major`, `check-empty-changeset`, `check-adr-0087-registration`, `check:changeset-gate-self-tests` and `check:nul-bytes` all exit 0. - `scripts/pm/overlap-check.mjs`: VERDICT clean exit 0. #37314's file list does not intersect this diff. </details> --- 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01QSeKYo86w1wqy2z2fMrryr --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 3801775 commit a182fbe

5 files changed

Lines changed: 116 additions & 5 deletions

File tree

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
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.
6+
7+
Clause-②: no
8+
Metadata-protocol: none

‎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: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,9 @@ 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 the card anyway.
292294
- **Never summed silently**: a table's runs must share the prompt choice, the package source, the ask repeats and the
293295
driver (a replay is its own driver), the ask skills (`--ask-skills`: names and sha256; a record without them
294296
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: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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`, the scenarios README's Verified
6+
* builds); `run --template F` warns when it names another card file
7+
* than the one the run grades (`templateProvenanceWarning`, `src/runner/cli.ts`).
8+
*/
9+
10+
import { mkdtempSync, writeFileSync } from 'node:fs';
11+
import { tmpdir } from 'node:os';
12+
import { join } from 'node:path';
13+
14+
import { describe, expect, it } from 'vitest';
15+
16+
import { templateProvenancePath, templateProvenanceWarning } from '../../src/runner/cli.js';
17+
18+
const A = 'a'.repeat(64);
19+
const B = 'b'.repeat(64);
20+
const card = { id: 'travel_expense', sha256: A };
21+
const reading = (text: string | undefined) => () => text;
22+
23+
describe('templateProvenanceWarning — run --template F against a card', () => {
24+
it('reads the provenance beside the template', () => {
25+
expect(templateProvenancePath('cards/builds/x.json')).toBe('cards/builds/x.provenance.json');
26+
});
27+
28+
it('says nothing when the provenance names the card file the run grades', () => {
29+
expect(templateProvenanceWarning('t.json', card, reading(JSON.stringify({ card: 'travel_expense', cardSha256: A })))).toBeUndefined();
30+
});
31+
32+
it('warns, naming both hashes, when the provenance names another card file', () => {
33+
const line = templateProvenanceWarning('t.json', card, reading(JSON.stringify({ card: 'travel_expense', cardSha256: B })));
34+
expect(line).toBeDefined();
35+
expect(line).toContain('t.provenance.json');
36+
expect(line).toContain(A.slice(0, 12));
37+
expect(line).toContain(B.slice(0, 12));
38+
});
39+
40+
it('warns when the provenance is unreadable as JSON or names no card hash', () => {
41+
expect(templateProvenanceWarning('t.json', card, reading('{'))).toBeDefined();
42+
expect(templateProvenanceWarning('t.json', card, reading(JSON.stringify({ card: 'travel_expense' })))).toBeDefined();
43+
});
44+
45+
it("says nothing for a template with no provenance, or one verified on another card", () => {
46+
expect(templateProvenanceWarning('t.json', card, reading(undefined))).toBeUndefined();
47+
expect(templateProvenanceWarning('t.json', card, reading(JSON.stringify({ card: 'order_to_cash', cardSha256: B })))).toBeUndefined();
48+
});
49+
50+
it('reads the provenance file from disk beside the template by default', () => {
51+
const dir = mkdtempSync(join(tmpdir(), 'scenario-provenance-'));
52+
const template = join(dir, 'travel_expense.json');
53+
writeFileSync(template, '{}');
54+
expect(templateProvenanceWarning(template, card)).toBeUndefined();
55+
writeFileSync(join(dir, 'travel_expense.provenance.json'), JSON.stringify({ card: 'travel_expense', cardSha256: B }));
56+
expect(templateProvenanceWarning(template, card)).toContain(B.slice(0, 12));
57+
});
58+
});

0 commit comments

Comments
 (0)