diff --git a/bin/gstack-evidence b/bin/gstack-evidence index e3d2bbab1..62ad8d381 100755 --- a/bin/gstack-evidence +++ b/bin/gstack-evidence @@ -163,6 +163,9 @@ class OutputTail { } } +/** The one spelling a lane label has in the ledger: run and record-ci write it, check reads it (`pnpm lint` is `pnpm_lint`, TRUT-7). */ +const ledgerLabel = (raw: string): string => raw.replace(/[^a-zA-Z0-9._-]/g, "_"); + const ANSI = /\u001B\[[0-?]*[ -/]*[@-~]/g; const strip = (l: string) => l.replace(ANSI, "").replace(/\r$/, ""); const count = (text: string, word: string): number => Number(new RegExp(`(\\d+) ${word}\\b`).exec(text)?.[1] ?? 0); @@ -428,7 +431,7 @@ async function cmdRun(argv: string[]): Promise { const commandString = cmdArgv.length === 1 ? cmdArgv[0] : cmdArgv.join(" "); const shell = cmdArgv.length === 1 ? bashCommandInvocation(cmdArgv[0]) : null; const cmdSha = sha256(commandString); - label = label.replace(/[^a-zA-Z0-9._-]/g, "_"); + label = ledgerLabel(label); // Bookkeeping context — every piece is optional; failures only warn. let paths: ReturnType | undefined; @@ -675,7 +678,8 @@ async function cmdRecordCi(argv: string[]): Promise { const sep = argv.indexOf("--"); const opts = sep < 0 ? argv : argv.slice(0, sep); const get = (name: string) => { const i = opts.indexOf(name); return i >= 0 ? opts[i + 1] : undefined; }; - const label = get("--label")?.replace(/[^a-zA-Z0-9._-]/g, "_"); + const raw = get("--label"); + const label = raw === undefined ? undefined : ledgerLabel(raw); const base = get("--base"); const command = sep < 0 ? "" : argv.slice(sep + 1).join(" "); if (!label || !base || !command || opts.length !== 4) { @@ -771,7 +775,7 @@ function cmdCheck(argv: string[]): number { let allowPaths: string[] = []; for (let i = 0; i < argv.length; i++) { const a = argv[i]; - if (a === "--label") wanted.push({ label: argv[++i] ?? "" }); + if (a === "--label") wanted.push({ label: ledgerLabel(argv[++i] ?? "") }); else if (a === "--expect-cmd") { if (wanted.length === 0) { console.error("gstack-evidence: --expect-cmd requires a preceding --label"); diff --git a/changelog.d/gsta258-l6-label-sanitize.md b/changelog.d/gsta258-l6-label-sanitize.md new file mode 100644 index 000000000..5f88f42b8 --- /dev/null +++ b/changelog.d/gsta258-l6-label-sanitize.md @@ -0,0 +1,4 @@ +- A lane label with a space or a colon, such as `pnpm lint` or `db:test`, no longer goes MISSING right after it carries (TRUT-7, truther#1170). `gstack-evidence` writes a label to the ledger with unsafe characters turned into `_`, but `check`, which `gstack-ship-release finish` and `accept` call, looked it up under the raw label, so /ship stopped with "not FRESH at the pushed head". `run`, `record-ci` and `check` now share one label spelling. + +### Tests +- `test/ship-ci-carry.test.ts`: `accept` with the lanes `pnpm lint` and `db:test` carries both and checks them FRESH, and `gstack-evidence check` finds both. It failed before the fix (`EVIDENCE: MISSING label=pnpm lint`). diff --git a/test/ship-ci-carry.test.ts b/test/ship-ci-carry.test.ts index edc3021dc..9f5c998bd 100644 --- a/test/ship-ci-carry.test.ts +++ b/test/ship-ci-carry.test.ts @@ -122,6 +122,18 @@ describe('finish, push --early and accept (A1)', () => { // Value: protects=finish never runs a mapped lane locally on the stamped tree: it defers it to accept and runs only pregate's preflight stage; accept carries // it from the green run at the pushed head and reruns the pregate there; fails_when=the stamped tree reruns the suite, or accept trusts a run at another tree; // why_new=design fix A1; seam=fake gh, gstack-evidence, gstack-pregate + test('accept checks a carried lane under the label it was recorded with: spaces and colons (TRUT-7)', () => { + const f = fx(); + world(f); + expect(f.run(RELEASE, ['push', '--branch', 'feat', '--early', '--base', 'main'], unattended).status).toBe(0); + for (const label of ['pnpm lint', 'db:test']) { + const ok = f.run(RELEASE, ['accept', '--base', 'main', '--lane', `${label}=${FREE}`, '--wait', '0']); + expect([ok.status, ok.stdout], label).toEqual([0, expect.not.stringContaining('not FRESH')]); + expect(ok.stdout).toMatch(/^EVIDENCE: FRESH /m); + } + for (const label of ['pnpm lint', 'db:test']) expect(f.run(path.join(BIN, 'gstack-evidence'), ['check', '--label', label]).stdout).toMatch(/^EVIDENCE: FRESH /m); + }); + test('finish defers the mapped lane; accept carries it from the green run at the pushed head', () => { const f = fx(); world(f);