From 3ba8c97dd4f5269461f52ef90c342256f97bd497 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 17 Sep 2026 22:32:51 +0000 Subject: [PATCH] fix(scripts): relate the recorded @object-ui version to the objectui pin MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit check-sdui-manifest read `objectuiPackagesVersion` as a presence check only: the record could name a pin and a version with nothing asking whether that version is the one the pinned commit declares. The generator's default makes that the live shape — with `--objectui-version` unset it reuses the version already in the record, so a regeneration after a pin bump re-records the NEW pin under the OLD version while every check here stayed green. The new check reads `packages/core/package.json` at the pinned commit from an objectui checkout (OBJECTUI_ROOT, else the ../objectui sibling) and fails when it disagrees with the record. That checkout is an oracle a required lint job does not have, so an absent one is REPORTED, never scored: the success line names the leg that did not run, and --require-objectui turns that gap into an exit 1 for callers that hold a checkout. An oracle present and unable to answer is a failure, not a skip. Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01JbZnqu8bt6YqfJsr9vaFb3 --- scripts/check-sdui-manifest.mjs | 283 +++++++++++++++++++++++++++++--- 1 file changed, 259 insertions(+), 24 deletions(-) diff --git a/scripts/check-sdui-manifest.mjs b/scripts/check-sdui-manifest.mjs index 9e29c9d2c31..57a68e3dcea 100644 --- a/scripts/check-sdui-manifest.mjs +++ b/scripts/check-sdui-manifest.mjs @@ -5,8 +5,14 @@ * check-sdui-manifest — freshness + integrity gate for the repo-root * `sdui.manifest.json` (#12924, ruled 2026-08-29: wire it, 签入 + 新鲜度门禁). * - * node scripts/check-sdui-manifest.mjs # gate this tree - * node scripts/check-sdui-manifest.mjs --self-test # verify the checker itself + * node scripts/check-sdui-manifest.mjs # gate this tree + * node scripts/check-sdui-manifest.mjs --require-objectui # …and REFUSE to skip check 4 + * node scripts/check-sdui-manifest.mjs --self-test # verify the checker itself + * + * Check 4 reads an objectui checkout: `OBJECTUI_ROOT`, else the `../objectui` + * sibling — the same two places `scripts/bump-objectui.sh` and + * `scripts/objectui-range.mjs` look, deliberately NOT a second env spelling for + * one checkout. * * ## What rots here, and which check catches it * @@ -30,6 +36,17 @@ * — the same moment `check-sdui-lockstep` already forces a parser parity * re-verification, and the moment an objectui checkout is guaranteed to * exist (the bump required one). + * 4. VERSION ↔ PIN CORRESPONDENCE — the record's `objectuiPackagesVersion` is + * the version `packages/core/package.json` DECLARES at the pinned commit. + * Checks 1-3 reach both fields and relate neither: the version was read + * as a presence check only, so the record could name pin C and version V + * with nothing asking whether V is C's version at all (#18611). The live + * way to write that record is the generator's own default — + * `--objectui-version` unset makes it REUSE the version already in the + * record, so a regeneration after a pin bump keeps the OLD version string + * while re-recording the NEW pin, and checks 1-3 stay green throughout. + * This is the only check here that needs an input from outside this tree, + * so it is the only one that can report NOT CHECKED — see below. * * ## What this deliberately does NOT do, and where that risk is held * @@ -43,10 +60,31 @@ * from the same install, identical sha256), so the remedy this gate prints * always converges. * - * Absence is loud, everywhere (#13014/#4690): every input is asserted before - * any verdict; a missing one exits 1 naming which. No `⚠` + exit 0. + * Check 4 does NOT prove that the published `@object-ui` tarballs at that + * version were BUILT from the pinned commit. They are not: objectui bumps its + * version only at release, so the version a mid-release commit declares names a + * tarball built from an earlier commit. That gap is a PRODUCER question + * (#17735 — which mechanism writes the artefact) and is not ruled here. What + * check 4 asserts is exactly the relation the record claims and nothing wider: + * the two fields it carries describe ONE objectui commit. The claim printed on + * success is kept as narrow as what ran. + * + * Check 4's oracle is an objectui CHECKOUT, which a required lint job does not + * have and must not clone (network in a required job — the shape declined + * above). So absence of the checkout is REPORTED, never converted into a + * verdict: the success line then states which leg did not run and how to run + * it, and `--require-objectui` makes that absence an exit 1 for the callers + * that DO hold a checkout (a pin bump; any job that has already cloned + * objectui). An unreadable answer with the checkout in hand is a failure, not a + * gap — see `readPinnedDeclaredVersion`'s three outcomes. + * + * Absence is loud, everywhere (#13014/#4690): every input THIS TREE owns is + * asserted before any verdict; a missing one exits 1 naming which. No `⚠` + + * exit 0 — and no line claiming a leg that did not run, which is the same + * failure with better manners. */ +import { execFileSync } from 'node:child_process'; import { createHash } from 'node:crypto'; import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs'; import { tmpdir } from 'node:os'; @@ -64,6 +102,23 @@ const READ_PATHS = { pin: '.objectui-sha', }; +/** + * Where check 4 looks for an objectui checkout when `OBJECTUI_ROOT` is unset. + * + * ⛔ Not a `READ_PATHS` entry and not a watch hint: it is outside this tree, so + * no diff of THIS repo can move it and `dispatch-gates` has nothing to derive + * from it. The pin hint below is what makes a `.objectui-sha` bump derive this + * gate, which is the diff check 4 exists for. + */ +const OBJECTUI_SIBLING = '../objectui'; + +/** + * The file whose `version` names the `@object-ui/*` set one objectui commit + * declares — the same file the moved-pin remedy has always told operators to + * read, now read by the gate instead of by hand. + */ +const OBJECTUI_VERSION_FILE = 'packages/core/package.json'; + /** * The population this gate reads, declared for `scripts/pm/dispatch-gates.mjs`. * @@ -95,8 +150,73 @@ const ROOT_WATCH_HINTS = [ '.objectui-sha/**', ]; -/** Gate one tree. Returns a list of problems; empty = green. */ -export function checkTree(root) { +/** + * What the PINNED objectui commit declares as its `@object-ui/*` version. + * + * THREE outcomes, kept apart on purpose — collapsing them is how a check like + * this reads a false zero: + * + * - `resolved` — the checkout answered; `version` is what the pin declares. + * - `unreachable` — nothing could be asked: no checkout, or one that does not + * carry the pinned commit (a shallow clone usually will not). NOT a + * disagreement — `checkTree` never converts it into one. + * - `unsupported` — a checkout IS in hand, carries the commit, and still + * cannot answer: no `packages/core/package.json` there, or one that does + * not parse or declares no `version`. That is a broken pin, so it is RED. + * + * `objectuiRoot` wins over `OBJECTUI_ROOT` so a caller (the self-test) can pin + * the oracle and be immune to the ambient environment. + */ +export function readPinnedDeclaredVersion(pin, { root = DEFAULT_ROOT, objectuiRoot } = {}) { + const where = objectuiRoot ?? process.env.OBJECTUI_ROOT ?? join(root, OBJECTUI_SIBLING); + const short = String(pin).slice(0, 12); + + // Shape first: `.objectui-sha` is hand-editable, and `git cat-file` on a + // malformed ref fails the same way a missing commit does. Naming the real + // reason beats reporting "the checkout does not carry it". + if (!/^[0-9a-f]{40}$/.test(String(pin))) { + return { status: 'unreachable', where, reason: `.objectui-sha does not hold a 40-character commit sha, so no checkout can be asked what it declares.` }; + } + if (!existsSync(join(where, '.git'))) { + return { status: 'unreachable', where, reason: `no objectui checkout at ${where} (no .git there). Set OBJECTUI_ROOT to one that carries the pin.` }; + } + + const git = (args) => { + try { + return { ok: true, out: execFileSync('git', ['-C', where, ...args], { encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'], maxBuffer: 16 * 1024 * 1024 }) }; + } catch (e) { + return { ok: false, err: String(e?.stderr || e?.message || e).trim().split('\n')[0] }; + } + }; + + if (!git(['cat-file', '-e', `${pin}^{commit}`]).ok) { + return { status: 'unreachable', where, reason: `the objectui checkout at ${where} does not carry commit ${short}… (a shallow clone will not — 'git -C ${where} fetch --depth=1 origin ${pin}' brings it in).` }; + } + const shown = git(['show', `${pin}:${OBJECTUI_VERSION_FILE}`]); + if (!shown.ok) { + return { status: 'unsupported', where, reason: `objectui commit ${short}… has no ${OBJECTUI_VERSION_FILE} (git: ${shown.err}). The pin names a commit that cannot declare an @object-ui version.` }; + } + let declared; + try { + declared = JSON.parse(shown.out)?.version; + } catch (e) { + return { status: 'unsupported', where, reason: `${OBJECTUI_VERSION_FILE} at objectui ${short}… does not parse as JSON: ${e.message}` }; + } + if (typeof declared !== 'string' || declared === '') { + return { status: 'unsupported', where, reason: `${OBJECTUI_VERSION_FILE} at objectui ${short}… declares no string \`version\`.` }; + } + return { status: 'resolved', where, version: declared }; +} + +/** + * Gate one tree. Returns a list of problems; empty = green. + * + * `onVersionLeg` is called exactly once with check 4's outcome whenever the leg + * is evaluated, so the caller can print a success line that claims only what + * ran. `requireObjectui` turns an `unreachable` oracle into a problem, for the + * callers that hold a checkout. + */ +export function checkTree(root, { objectuiRoot, requireObjectui = false, onVersionLeg } = {}) { const problems = []; const artefactPath = join(root, READ_PATHS.artefact); const recordPath = join(root, READ_PATHS.record); @@ -164,13 +284,50 @@ export function checkTree(root) { return problems; } const pin = readFileSync(pinPath, 'utf8').trim(); + + // Check 4's oracle, read once. It is asked about the LIVE pin, so when the pin + // has moved the version it yields is the one the regeneration must install — + // which is what the moved-pin remedy below has always asked the operator to go + // and read by hand. + const versionLeg = readPinnedDeclaredVersion(pin, { root, objectuiRoot }); + onVersionLeg?.(versionLeg); + if (pin !== record.objectuiSha) { problems.push( `.objectui-sha has moved to ${pin.slice(0, 12)}… but sdui.manifest.json was generated at ${String(record.objectuiSha).slice(0, 12)}…\n` + ' A pin bump changes which registry the shipped console runs; the manifest must follow it (同步一次就烂 is\n' + ' the failure mode this gate exists for). Regenerate against the new pin:\n' + - ' node scripts/gen-sdui-manifest-node.mjs --objectui-version {the @object-ui version the new pin ships}\n' + - " (read it from the objectui checkout's packages/core/package.json — the bump already required that checkout).", + (versionLeg.status === 'resolved' + ? ` node scripts/gen-sdui-manifest-node.mjs --objectui-version ${versionLeg.version}\n` + + ` (${versionLeg.version} is what the new pin's ${OBJECTUI_VERSION_FILE} declares, read from ${versionLeg.where}.)` + : ' node scripts/gen-sdui-manifest-node.mjs --objectui-version {the @object-ui version the new pin ships}\n' + + " (read it from the objectui checkout's packages/core/package.json — the bump already required that checkout)."), + ); + // The version leg is NOT reported on top of this one: with the pin moved, + // the record describes a different commit by construction, so a second + // problem would restate this one rather than add a finding. + return problems; + } + + // ── Check 4 (#18611) ──────────────────────────────────────────────────── + if (versionLeg.status === 'resolved' && versionLeg.version !== record.objectuiPackagesVersion) { + problems.push( + `the record's two objectui fields describe different commits: objectuiPackagesVersion is ${JSON.stringify(record.objectuiPackagesVersion)},\n` + + ` but objectui ${pin.slice(0, 12)}… — the pin the record itself names — declares ${JSON.stringify(versionLeg.version)} in ${OBJECTUI_VERSION_FILE}\n` + + ` (read from ${versionLeg.where}). The manifest was generated from the published ${record.objectuiPackagesVersion} packages, so it\n` + + ' describes a registry this pin does not name. The generator REUSES the version already recorded when\n' + + ' --objectui-version is not passed, which is how a regeneration re-records a new pin under an old version.\n' + + ` Regenerate against the pin: node scripts/gen-sdui-manifest-node.mjs --objectui-version ${versionLeg.version}`, + ); + } else if (versionLeg.status === 'unsupported') { + problems.push( + `cannot judge objectuiPackagesVersion against the pin, with an objectui checkout in hand: ${versionLeg.reason}\n` + + ' An oracle that is present and cannot answer is a failure, never a skip.', + ); + } else if (versionLeg.status === 'unreachable' && requireObjectui) { + problems.push( + `--require-objectui was passed and check 4 could not run: ${versionLeg.reason}\n` + + ' Point OBJECTUI_ROOT at a checkout that carries the pin, or drop the flag where no checkout exists.', ); } return problems; @@ -215,6 +372,11 @@ const SELF_TEST_BATTERIES = Object.freeze({ 'moved pin is RED': 1, 'empty components is RED': 1, 'missing record is RED': 1, + 'pin-declared version agreeing with the record passes': 1, + 'pin-declared version disagreeing with the record is RED': 1, + 'an unreachable objectui checkout is not a version verdict': 1, + '--require-objectui turns an unreachable checkout RED': 1, + 'a pinned commit with no packages/core/package.json is RED': 1, }); // DELETING an entry silences that battery's floor exactly as effectively as @@ -223,24 +385,24 @@ const SELF_TEST_BATTERIES = Object.freeze({ // the literal above, so the roster falls below this number; the table // cross-check in the floor block is the other half, and names WHICH label // collided. -const SELF_TEST_BATTERY_FLOOR = 6; +const SELF_TEST_BATTERY_FLOOR = 11; function selfTest() { - const mk = (mutate) => { + const mk = (mutate, { pin = 'a'.repeat(40), version = '0.0.0-selftest' } = {}) => { const root = mkdtempSync(join(tmpdir(), 'sdui-manifest-check-')); // fixture tree: artefact + record + pin, green by construction const manifest = { components: { flex: { type: 'flex', inputs: [] } } }; const raw = JSON.stringify(manifest, null, 2); const scriptsDir = join(root, 'scripts'); mkdirSync(scriptsDir, { recursive: true }); - writeFileSync(join(root, '.objectui-sha'), 'a'.repeat(40) + '\n'); + writeFileSync(join(root, '.objectui-sha'), pin + '\n'); writeFileSync(join(root, 'sdui.manifest.json'), raw); writeFileSync( join(scriptsDir, 'sdui-manifest.record.json'), JSON.stringify( { - objectuiSha: 'a'.repeat(40), - objectuiPackagesVersion: '0.0.0-selftest', + objectuiSha: pin, + objectuiPackagesVersion: version, sha256: createHash('sha256').update(raw).digest('hex'), components: 1, }, @@ -252,11 +414,48 @@ function selfTest() { return root; }; + /** + * A throwaway objectui: ONE commit, declaring `version` in + * `packages/core/package.json` — or, with `omitVersionFile`, declaring + * nothing, which is the `unsupported` outcome's fixture. + * + * A real git repository, not a stub: check 4 resolves the pin through `git + * cat-file` / `git show`, and a stubbed resolver would leave exactly that + * resolution unexercised — the half where a missing commit must read + * `unreachable` rather than "the versions differ". + */ + const mkObjectui = ({ version = '0.0.0-selftest', omitVersionFile = false } = {}) => { + const dir = mkdtempSync(join(tmpdir(), 'sdui-manifest-objectui-')); + const git = (...args) => execFileSync('git', ['-C', dir, ...args], { encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'] }); + execFileSync('git', ['init', '-q', '-b', 'main', dir], { stdio: ['ignore', 'pipe', 'pipe'] }); + if (omitVersionFile) { + writeFileSync(join(dir, 'README.md'), 'an objectui commit that declares no @object-ui version\n'); + } else { + mkdirSync(join(dir, 'packages', 'core'), { recursive: true }); + writeFileSync(join(dir, OBJECTUI_VERSION_FILE), JSON.stringify({ name: '@object-ui/core', version }, null, 2)); + } + git('add', '-A'); + git('-c', 'user.name=selftest', '-c', 'user.email=selftest@example.invalid', '-c', 'commit.gpgsign=false', 'commit', '-q', '--no-verify', '-m', 'fixture'); + return { dir, sha: git('rev-parse', 'HEAD').trim() }; + }; + + // An oracle path that CANNOT resolve: a never-created child of a fresh temp + // dir. Every row passes its oracle explicitly, so `OBJECTUI_ROOT` in the + // ambient environment can neither green nor red this self-test. + const NO_OBJECTUI = join(mkdtempSync(join(tmpdir(), 'sdui-manifest-no-objectui-')), 'objectui'); + const blind = { objectuiRoot: NO_OBJECTUI }; + + // Check 4's oracles (#18611). The fixture tree pins the throwaway commit, so + // the ONLY thing varying across these rows is the version relation itself. + const agreeing = mkObjectui({ version: '0.0.0-selftest' }); + const disagreeing = mkObjectui({ version: '9.9.9-not-the-recorded-one' }); + const noVersionFile = mkObjectui({ omitVersionFile: true }); + const cases = [ - ['green fixture passes', mk(), 0], - ['missing artefact is RED', mk((r) => rmSync(join(r, 'sdui.manifest.json'))), 1], - ['hand-edited artefact (hash mismatch) is RED', mk((r) => writeFileSync(join(r, 'sdui.manifest.json'), '{"components":{"flex":{"type":"flex"}}}')), 1], - ['moved pin is RED', mk((r) => writeFileSync(join(r, '.objectui-sha'), 'b'.repeat(40))), 1], + ['green fixture passes', mk(), 0, blind], + ['missing artefact is RED', mk((r) => rmSync(join(r, 'sdui.manifest.json'))), 1, blind], + ['hand-edited artefact (hash mismatch) is RED', mk((r) => writeFileSync(join(r, 'sdui.manifest.json'), '{"components":{"flex":{"type":"flex"}}}')), 1, blind], + ['moved pin is RED', mk((r) => writeFileSync(join(r, '.objectui-sha'), 'b'.repeat(40))), 1, blind], ['empty components is RED', mk((r) => { const raw = JSON.stringify({ components: {} }, null, 2); writeFileSync(join(r, 'sdui.manifest.json'), raw); @@ -264,8 +463,22 @@ function selfTest() { rec.sha256 = createHash('sha256').update(raw).digest('hex'); rec.components = 0; writeFileSync(join(r, 'scripts', 'sdui-manifest.record.json'), JSON.stringify(rec)); - }), 1], - ['missing record is RED', mk((r) => rmSync(join(r, 'scripts', 'sdui-manifest.record.json'))), 1], + }), 1, blind], + ['missing record is RED', mk((r) => rmSync(join(r, 'scripts', 'sdui-manifest.record.json'))), 1, blind], + + // ── Check 4: the version the PIN declares (#18611) ──────────────────── + // + // The RED row is the one that carries this check: before it existed, a + // record naming pin C and a version C never declared was green here, and + // the two rows below it are the controls that keep the red honest — the + // same disagreeing tree reads GREEN with no oracle (so `unreachable` is not + // silently scored as a match) and RED under --require-objectui (so the + // reported gap is one a caller can refuse). + ['pin-declared version agreeing with the record passes', mk(undefined, { pin: agreeing.sha, version: '0.0.0-selftest' }), 0, { objectuiRoot: agreeing.dir }], + ['pin-declared version disagreeing with the record is RED', mk(undefined, { pin: disagreeing.sha, version: '0.0.0-selftest' }), 1, { objectuiRoot: disagreeing.dir }], + ['an unreachable objectui checkout is not a version verdict', mk(undefined, { pin: disagreeing.sha, version: '0.0.0-selftest' }), 0, blind], + ['--require-objectui turns an unreachable checkout RED', mk(undefined, { pin: disagreeing.sha, version: '0.0.0-selftest' }), 1, { objectuiRoot: NO_OBJECTUI, requireObjectui: true }], + ['a pinned commit with no packages/core/package.json is RED', mk(undefined, { pin: noVersionFile.sha, version: '0.0.0-selftest' }), 1, { objectuiRoot: noVersionFile.dir }], ]; // The ledger this self-test's floor is evaluated against (#13489). @@ -275,9 +488,9 @@ function selfTest() { }; let failures = 0; - for (const [name, root, want] of cases) { + for (const [name, root, want, options] of cases) { registerCase(name); - const problems = checkTree(root); + const problems = checkTree(root, options); const got = problems.length ? 1 : 0; if (got !== want) { failures++; @@ -365,7 +578,10 @@ function selfTest() { console.error(`✗ check-sdui-manifest self-test: ${failures} failure(s) (cases and floor).`); process.exit(1); } - console.log(`✓ check-sdui-manifest self-test: ${cases.length} cases behave (green passes; absence, tamper, moved pin, emptiness are RED).`); + console.log( + `✓ check-sdui-manifest self-test: ${cases.length} cases behave (green passes; absence, tamper, moved pin, emptiness, ` + + 'a version the pin does not declare, and an oracle that cannot answer are RED; an absent oracle is reported, not scored).', + ); return SELF_TEST_VERDICT; } @@ -381,7 +597,11 @@ if (isEntrypoint(import.meta.url)) { process.exit(1); } } else { - const problems = checkTree(DEFAULT_ROOT); + let versionLeg; + const problems = checkTree(DEFAULT_ROOT, { + requireObjectui: process.argv.includes('--require-objectui'), + onVersionLeg: (leg) => { versionLeg = leg; }, + }); if (problems.length) { console.error('✗ check-sdui-manifest:'); for (const p of problems) console.error(` ${p}`); @@ -390,7 +610,22 @@ if (isEntrypoint(import.meta.url)) { const record = JSON.parse(readFileSync(join(DEFAULT_ROOT, 'scripts', 'sdui-manifest.record.json'), 'utf8')); console.log( `✓ check-sdui-manifest: sdui.manifest.json is present, intact (sha256 ${String(record.sha256).slice(0, 12)}…, ` + - `${record.components} components) and fresh at objectui pin ${String(record.objectuiSha).slice(0, 12)}….`, + `${record.components} components) and recorded at the live objectui pin ${String(record.objectuiSha).slice(0, 12)}….`, ); + // The claim is only ever as wide as the leg that ran (#18611): a run without + // an objectui checkout says so, in the same breath, rather than letting the + // line above be read as "fresh at the pin" in every sense. + if (versionLeg?.status === 'resolved') { + console.log( + ` @object-ui ${record.objectuiPackagesVersion} is the version objectui ${String(record.objectuiSha).slice(0, 12)}… declares ` + + `in ${OBJECTUI_VERSION_FILE} (read from ${versionLeg.where}).`, + ); + } else { + console.log( + ` NOT CHECKED — objectuiPackagesVersion ${JSON.stringify(record.objectuiPackagesVersion)} was not compared with what the pin declares: ` + + `${versionLeg?.reason ?? 'the version leg did not run.'}\n` + + ' Re-run with an objectui checkout (OBJECTUI_ROOT=… or a ../objectui sibling); add --require-objectui to make this gap an exit 1.', + ); + } } }