diff --git a/scripts/check-adr-0087-registration.mjs b/scripts/check-adr-0087-registration.mjs index bc082d7904c..3fd7c530417 100644 --- a/scripts/check-adr-0087-registration.mjs +++ b/scripts/check-adr-0087-registration.mjs @@ -418,6 +418,61 @@ // installs before it -- and reports the missing runner as a red input, never as a // pass. The `--self-test` drives that generator path through a fixture generator // under this checkout's `tsx` too, and loads the compiler for the seventh category. +// +// ## An entry this PR adds is filed at or above `PROTOCOL_MAJOR` (#38240) +// +// The second rule, and the one that does not need a breaking changeset: it runs +// on every diff. An entry's filename prefix is the ONLY thing that decides which +// upgrade step lists it (`parseEntry` in the registry generator; no entry carries +// a major field), and `os migrate meta --from N` replays only the steps above N. +// So an entry filed BELOW the protocol major the tree implements is never shown to +// a project upgrading from the major it names: three 19 notes were filed under 18 +// after the 18 -> 19 move and `--from 18` skipped all three (#38142). +// +// What counts as ADDED is the identity, never git's rename guess. In the three +// entry directories a file's key is its name minus the `.` prefix -- the +// generator's `shardNameFor` makes the name a pure function of the id -- and an +// entry is added when its key is absent from the merge base's listing of the same +// directory. A move between majors (`18.x.ts` -> `19.x.ts`, `R100` or edited) keeps +// its key and is not added. Only on a merge base from before the per-entry split +// (#22554), which has no entry files to list, must a `semantic/` entry also be in +// `ledgerAdded` (an id carried over from the committed registry is not new). Never +// on a split-era base: the template carries `id:` lines with no entry file, and +// that conjunct would take a new file for one of those ids out of judgment. +// `retired-keys/` and `retired-defs/` declare no `id:` line, so the key alone +// decides there, and a pre-split base would read all of theirs as added -- a loud +// red on a branch nobody still has, never a silent pass. +// +// `PROTOCOL_MAJOR` is read at HEAD, from the module `os init` reads it from +// (`PROTOCOL_SOURCE`), through `loadProtocolMajor` in +// `scripts/sync-template-versions.mjs` -- the one reader that EVALUATES the export +// rather than re-parsing a second copy of the number. That reader is async and this +// gate is not, so it runs in a child node process, and only when the diff adds an +// entry. A major that cannot be read is a red, never a pass (#4690). +// +// Equal or ABOVE passes: 717 entries were filed under 18 ahead of the 17 -> 18 bump, +// correctly. The cost of a low prefix differs by directory: a `semantic/` note is +// never replayed for `--from` its major; a `retired-keys/` or `retired-defs/` row +// dates the retirement `build-schemas.ts` ages tombstones from, so its clock starts +// a major early. The one case that may sit lower is a BACKFILL -- a note for a change +// that already shipped in a released lower major, filed late. It is declared, not +// inferred, in a changeset the diff adds or edits, one line per entry, printed as an +// exemption on every run: +// +// +// +// The reason must name a release of the entry's own major in digits (`18.4.0`). +// The example the refusal prints carries placeholders (`MINOR`, `PATCH`, `WHY`) that +// `backfillReasonFaults` refuses, so a line pasted from the red unedited stays red. +// +// A separate marker rather than a disposition: a backfill is not a breaking change +// and owes no `adr-0087:` marker, and a changeset carries exactly one of those. +// +// What it does NOT catch, deliberately: an entry that was filed while its prefix WAS +// the protocol major and then stranded when the major moved. 34 `semantic/18.*` +// entries added after `spec@18.6.0` and before the 18 -> 19 move are that shape; +// each was at the major of its day. That is a check at the protocol move, not on an +// added entry, and it is not this rule. import { execFileSync, spawnSync } from 'node:child_process'; import { existsSync, mkdtempSync, mkdirSync, readFileSync, rmSync, symlinkSync, writeFileSync } from 'node:fs'; @@ -427,6 +482,11 @@ import { dirname, join, posix, resolve } from 'node:path'; import { fileURLToPath } from 'node:url'; import { gitFreeEnv } from './git-env.mjs'; import { isEntrypoint } from './invoked-as.mjs'; +// #38240 -- where the protocol major is declared. Its one evaluating reader, +// `loadProtocolMajor`, lives in the same module and runs in a child process +// (`protocolMajorAt`); importing the module here is also what puts it in this +// gate's first-party closure, so a staged copy of the gate carries it. +import { PROTOCOL_SOURCE } from './sync-template-versions.mjs'; import { maskComments, maskCommentsAndLiterals } from './js-comment-mask.mjs'; // #16421 — the DIRECTION ARM, read through the fleet's one declaration reader. // ⛔ Not re-implemented here: the ruling's condition on the arm is that it has a @@ -518,6 +578,7 @@ const SELF_TEST_BATTERIES = Object.freeze({ 'V3: the real repository is the case that matters -- this gate\'s own vocabulary': 10, 'W1-W6 (#22485): the parser-rot witness is GENERATED at head, never read from a committed copy': 9, 'GR1-GR7 (#22554): the migration ledger is GENERATED at build, read from its template and entry files': 13, + 'EM (#38240): an entry this PR adds is filed at or above PROTOCOL_MAJOR': 50, 'CR1-CR3 (#29987): the conversions ledger is split per entry, read from registry.ts and its modules': 3, 'Unit pins on the two pattern-shaped judgements': 29, 'the floors: what the new vocabulary must refuse': 9, @@ -541,7 +602,7 @@ const SELF_TEST_BATTERIES = Object.freeze({ // DELETING an entry silences that battery's floor exactly as effectively as // zeroing it, so the roster's own size is pinned too. -const SELF_TEST_BATTERY_FLOOR = 60; +const SELF_TEST_BATTERY_FLOOR = 61; // The key an assertion is filed under when no battery is open. It is not a // declared battery, so it reds by the same set difference rather than silently @@ -2473,6 +2534,148 @@ export function conversionLedgerTextAt(rev, cwd) { return [registry, ...entries.map((p) => texts.get(p))].join('\n'); } +// --------------------------------------------------------------------------- +// The entry major (#38240): see "An entry this PR adds is filed at or above +// `PROTOCOL_MAJOR`" in the header. +// --------------------------------------------------------------------------- + +/** The `.` prefix of an entry filename, as the registry generator reads it. */ +const ENTRY_MAJOR_RE = /^(\d+)\./; + +/** + * The child that answers `PROTOCOL_MAJOR`: it imports `loadProtocolMajor` from + * `scripts/sync-template-versions.mjs` (argv[2], a file URL) and evaluates the + * file at argv[1] with it. Async there, so it cannot run inside `scan()`. + */ +const PROTOCOL_MAJOR_CHILD = + 'const [file, reader] = process.argv.slice(1);\n' + + 'try {\n' + + ' const { loadProtocolMajor } = await import(reader);\n' + + ' process.stdout.write(String(await loadProtocolMajor(file)));\n' + + '} catch (e) {\n' + + ' process.stderr.write(String(e && e.message ? e.message : e));\n' + + ' process.exit(1);\n' + + '}\n'; + +/** + * The `PROTOCOL_MAJOR` a rev implements: `PROTOCOL_SOURCE` read at that rev and + * EVALUATED by `loadProtocolMajor`, never re-parsed here. `problem` is set, and + * `major` null, when the file is missing or the reader refuses -- a red in `scan()`. + * + * @returns {{ major: number | null, problem: string | null }} + */ +export function protocolMajorAt(rev, cwd) { + const fail = (why) => ({ major: null, problem: `cannot read PROTOCOL_MAJOR at ${rev}: ${why}` }); + const text = showOrNull(rev, PROTOCOL_SOURCE, cwd); + if (text === null) return fail(`${PROTOCOL_SOURCE} does not exist there.`); + const dir = mkdtempSync(join(tmpdir(), 'adr0087-protocol-major-')); + try { + const file = join(dir, 'protocol-version.ts'); + writeFileSync(file, text); + const reader = new URL('./sync-template-versions.mjs', import.meta.url).href; + const r = spawnSync(process.execPath, ['--input-type=module', '-e', PROTOCOL_MAJOR_CHILD, file, reader], { + encoding: 'utf8', + stdio: ['ignore', 'pipe', 'pipe'], + }); + const out = (r.stdout ?? '').trim(); + if (r.status !== 0 || !/^\d+$/.test(out)) { + const said = `${r.stderr ?? ''}${r.error ? String(r.error) : ''}`.trim().split('\n')[0]; + return fail(`${PROTOCOL_SOURCE} did not evaluate to a major (${said || `exit ${r.status}, output "${out}"`}).`); + } + return { major: Number(out), problem: null }; + } finally { + rmSync(dir, { recursive: true, force: true }); + } +} + +/** + * The migration entries a diff ADDS, by identity: a `.ts` file in one of + * `MIGRATION_LEDGER_ENTRY_DIRS` at `head` whose key (the filename minus its + * `.` prefix) the same directory does not hold at `from`. Only when `from` + * predates the per-entry split (it tracks no `MIGRATION_LEDGER_TEMPLATE`, so it + * has no entry files to list) must a `semantic/` entry also be in `ledgerAdded`: + * there an id carried over from the committed registry is not new. Never on a + * split-era base -- the template carries `id:` lines with no entry file (step + * rationale fragments among them), so `ledgerAdded` would drop a new file for one + * of those ids out of judgment, toward green. A file whose + * name carries no numeric prefix is the generator's refusal, not this rule's, and + * is reported with `major: null`. + * + * @param {{ cwd: string, from: string, head: string, ledgerAdded: string[] }} o + * @returns {{ path: string, dir: string, key: string, major: number | null }[]} + */ +export function addedMigrationEntries({ cwd, from, head, ledgerAdded }) { + const keyOf = (name) => name.replace(ENTRY_MAJOR_RE, ''); + const listAt = (rev, dir) => { + let out = ''; + try { out = git(['ls-tree', '--name-only', `${rev}:${dir}`], cwd); } catch { return []; } + return out.split('\n').map((s) => s.trim()).filter((s) => s.endsWith('.ts')); + }; + const registeredKeys = new Set(ledgerAdded.map((id) => `${id.replaceAll('/', '__').replaceAll(':', '__')}.ts`)); + const basePredatesSplit = showOrNull(from, MIGRATION_LEDGER_TEMPLATE, cwd) === null; + const added = []; + for (const dir of MIGRATION_LEDGER_ENTRY_DIRS) { + const baseKeys = new Set(listAt(from, dir).map(keyOf)); + for (const name of listAt(head, dir)) { + const key = keyOf(name); + if (baseKeys.has(key)) continue; + if (basePredatesSplit && dir === MIGRATION_LEDGER_ENTRY_DIRS[0] && !registeredKeys.has(key)) continue; + const m = ENTRY_MAJOR_RE.exec(name); + added.push({ path: `${dir}/${name}`, dir, key, major: m ? Number(m[1]) : null }); + } + } + return added; +} + +/** + * Every `` line in a changeset body. + * Not an `adr-0087:` disposition (that marker's pattern needs the colon right after + * `adr-0087`), so it neither counts toward nor collides with the one-marker rule. + * + * @param {string} body + * @returns {{ path: string, why: string }[]} + */ +export function readBackfillDeclarations(body) { + return [...body.matchAll(//g)] + .map((m) => ({ path: m[1].replace(/^[`'"]|[`'"]$/g, ''), why: m[2].replace(/\s+/g, ' ').trim() })); +} + +/** The minimum length of a backfill line's reason: the floor a `not-required` reason has. */ +const BACKFILL_REASON_MIN = 40; + +/** + * The reason the refusal PRINTS in its example backfill line. It carries a + * placeholder release (`MAJOR.MINOR.PATCH` with letters) and a `WHY` slot, so + * `backfillReasonFaults` refuses it exactly as printed: a line pasted from the + * red, unedited, stays red (EM-R6). Only a reason that names a real release of + * the entry's own major gives the next reader something to re-check. + */ +export function backfillExampleReason(major) { + return `first shipped in @objectstack/spec ${major}.MINOR.PATCH, filed late because WHY`; +} + +/** + * What is wrong with a backfill line's reason for an entry under `major`, as + * clauses for the refusal; empty when it holds. It must reach the length floor, + * name a release of the entry's own major in digits (`18.4.0`, a prerelease + * suffix allowed), and carry no placeholder left from the printed example. + * + * @returns {string[]} + */ +export function backfillReasonFaults(why, major) { + const faults = []; + if (why.length < BACKFILL_REASON_MIN) { + faults.push(`is ${why.length} characters (${BACKFILL_REASON_MIN} characters minimum)`); + } + if (!new RegExp(`(?:^|[^0-9.])${major}\\.\\d+\\.\\d+(?:-[0-9A-Za-z.]+)?(?![0-9])`).test(why)) { + faults.push(`names no released version of major ${major} in digits (${major}.MINOR.PATCH)`); + } + if (/\bMINOR\b|\bPATCH\b|\bWHY\b/.test(why)) { + faults.push('still carries a placeholder from the printed example (MINOR, PATCH or WHY)'); + } + return faults; +} + // --------------------------------------------------------------------------- // Input assertions -- absence is never a pass (#4690) // --------------------------------------------------------------------------- @@ -6489,6 +6692,7 @@ export function scan({ cwd, base, head = 'HEAD' }) { const problems = []; const judged = []; const skipped = []; + const backfillDeclarations = []; for (const line of out.split('\n')) { if (!line.trim()) continue; @@ -6505,6 +6709,9 @@ export function scan({ cwd, base, head = 'HEAD' }) { const headText = showOrNull(head, file, cwd); if (headText === null) continue; // vanished under us; nothing to judge + // Read on EVERY changeset row, breaking or not, before the non-breaking skip: + // a backfill is not a breaking change (#38240). + for (const d of readBackfillDeclarations(headText)) backfillDeclarations.push({ ...d, file }); const parsed = parseChangeset(headText); const decl = breakingDeclaration(parsed); @@ -6841,7 +7048,75 @@ export function scan({ cwd, base, head = 'HEAD' }) { judged.push({ file, verdict: 'not-required', category: d.category, why: d.why, signals: decl.signals }); } - return { problems, judged, skipped, base: from, ledgerAdded, needsExportReader }; + // ---- An entry this PR adds is filed at or above `PROTOCOL_MAJOR` (#38240) ---- + // Judged on every diff, with or without a breaking changeset. The major is read + // only when the diff adds an entry, so every other run spawns nothing. + const addedEntries = addedMigrationEntries({ cwd, from, head, ledgerAdded }); + const backfilled = []; + let protocolMajor = null; + if (addedEntries.length > 0) { + const pm = protocolMajorAt(head, cwd); + if (pm.problem) { + problems.push({ + file: PROTOCOL_SOURCE, + message: + `${pm.problem}\n` + + ` This diff adds ${addedEntries.length} migration entr${addedEntries.length === 1 ? 'y' : 'ies'}, and whether each is filed at or\n` + + ' above the protocol major cannot be judged without it. A major that cannot be read is a\n' + + ' failure, never a pass.', + annotation: `${pm.problem} -- the major of the migration entries this PR adds cannot be judged.`, + }); + } else { + protocolMajor = pm.major; + } + } + if (protocolMajor !== null) { + for (const e of addedEntries) { + if (e.major === null || e.major >= protocolMajor) continue; + const declared = backfillDeclarations.find((d) => d.path === e.path); + const declarationFaults = declared ? backfillReasonFaults(declared.why, e.major) : []; + if (declared && declarationFaults.length === 0) { + backfilled.push({ ...e, why: declared.why, declaredIn: declared.file }); + continue; + } + const renamed = `${e.dir}/${protocolMajor}.${e.key}`; + const isSemantic = e.dir === MIGRATION_LEDGER_ENTRY_DIRS[0]; + problems.push({ + file: e.path, + message: + `adds a migration entry under protocol major ${e.major}, below the current PROTOCOL_MAJOR ${protocolMajor}\n` + + ` (evaluated from ${PROTOCOL_SOURCE} at ${head}).\n` + + (isSemantic + ? ' The filename prefix alone decides which upgrade step lists an entry, and\n' + + ' `os migrate meta --from N` replays only the steps above N. An entry filed below the current\n' + + ` major is never shown to a project upgrading from ${e.major}, the readers it was written for.\n` + : ' The filename prefix dates the retirement: `packages/spec/scripts/build-schemas.ts` reads the\n' + + ' major of this row as the one the key or def was retired in, and lets its tombstone be deleted\n' + + ' once it is one major old. Filed below the current major, that clock starts a major early, so\n' + + ' the tombstone -- and the prescription it shows an upgrading author -- can go a major too soon.\n') + + (declared + ? ` A backfill line names this entry in ${declared.file}, but its reason ${declarationFaults.join(' and ')}.\n` + : '') + + ' fix: file it under the current major --\n' + + ` git mv ${e.path} ${renamed}\n` + + ` The one case that may sit lower is a BACKFILL: a note for a change that already shipped in a\n` + + ` released ${e.major}.x, filed late. Declare it in a changeset this PR adds, naming the exact\n` + + ` release (${e.major}.MINOR.PATCH, in digits) -- the line below is refused until you replace the placeholders:\n` + + ` `, + annotation: + `${e.path} is filed under protocol major ${e.major}, below PROTOCOL_MAJOR ${protocolMajor}: ` + + (isSemantic + ? `\`os migrate meta --from ${e.major}\` never shows it.` + : 'its tombstone starts aging a major early and can be deleted a major too soon.') + + ` Rename it to ${renamed}, or declare a backfill (see this step's log).`, + }); + } + } + + return { + problems, judged, skipped, base: from, ledgerAdded, needsExportReader, + addedEntries, protocolMajor, backfilled, + }; } // --------------------------------------------------------------------------- @@ -6872,7 +7147,8 @@ function report(problems) { ' entry, so `not-required` is the ordinary answer and costs one line.', ].join('\n'), ); - for (const { file } of problems) { + for (const { file, annotation } of problems) { + if (annotation) { console.error(`::error file=${file}::${annotation}`); continue; } console.error( `::error file=${file}::${file} declares a breaking change with no valid ADR-0087 disposition. Add an \`adr-0087:\` marker to the changeset body (see this step's log). A retirement that never reaches the ledger is invisible to every upgrade channel and to every other gate (#6148).`, ); @@ -10940,10 +11216,14 @@ function selfTest() { // HEAD replaces it with its sources (generated era) -- the shape of the PR that // made the change, and of every branch forked before it. An entry carried // across is NOT new; an entry added beside it is. + // The protocol module rides along since #38240: `beta` is an entry this diff + // ADDS, and an added entry is judged against the protocol major at HEAD. const transition = (claim) => run(mk({ baseIds: ['alpha'], files: { [LEDGER_SOURCES[0]]: null, + [PROTOCOL_SOURCE]: readFileSync(join(REPO_ROOT, PROTOCOL_SOURCE), 'utf8') + .replace(/PROTOCOL_VERSION = '[^']*'/, "PROTOCOL_VERSION = '17.0.0'"), ...generatedEra(['alpha', 'beta']), '.changeset/x.md': CS({ body: `**BREAKING** x\n\n\n` }), }, @@ -10952,6 +11232,196 @@ function selfTest() { red('GR7 transition: an entry carried over from the committed era is not new', transition('alpha'), [/none of those ids is NEW in this diff/]); } + // ---- EM (#38240): an entry this PR adds is filed at or above PROTOCOL_MAJOR -- + // + // Generated-era fixtures (template + one file per entry), the shape of `main`. + // PROTOCOL_MAJOR comes from the REAL `protocol-version.ts`, its version string + // swapped, evaluated by the real `loadProtocolMajor` -- never passed in. + battery('EM (#38240): an entry this PR adds is filed at or above PROTOCOL_MAJOR'); + { + const SEM = MIGRATION_LEDGER_ENTRY_DIRS[0]; + const KEYS = MIGRATION_LEDGER_ENTRY_DIRS[1]; + const PROTOCOL = (major) => readFileSync(join(REPO_ROOT, PROTOCOL_SOURCE), 'utf8') + .replace(/PROTOCOL_VERSION = '[^']*'/, `PROTOCOL_VERSION = '${major}.0.0'`); + const ENTRY = (id) => `export const entry = {\n id: '${id}',\n surface: 's',\n};\n`; + const emRepo = ({ head = {}, base = {}, major = 19, protocolAtHead = true }) => mk({ + baseFiles: { + [MIGRATION_LEDGER_TEMPLATE]: 'export const X = {\n semantic: [\n ],\n};\n', + [`${SEM}/18.stock-entry.ts`]: ENTRY('stock-entry'), + [PROTOCOL_SOURCE]: PROTOCOL(major), + ...base, + }, + files: { ...(protocolAtHead ? {} : { [PROTOCOL_SOURCE]: null }), ...head }, + }); + const em = (o) => run(emRepo(o)); + const backfillCs = (line) => CS({ bumps: [['@objectstack/spec', 'patch']], body: `ledger backfill\n\n${line}\n` }); + + // EM-R1: THE #38142 SHAPE -- a new `semantic/18.*` while the tree implements 19. + const r1 = em({ head: { [`${SEM}/18.late-note.ts`]: ENTRY('late-note') } }); + red('EM-R1 an added semantic/18.* under PROTOCOL_MAJOR 19 is refused', r1, [ + new RegExp(`${SEM}/18\\.late-note\\.ts`), + /under protocol major 18, below the current PROTOCOL_MAJOR 19/, + new RegExp(`git mv ${SEM}/18\\.late-note\\.ts ${SEM}/19\\.late-note\\.ts`), + /BACKFILL/, + new RegExp(``), + }, + }); + green('EM-G5 a below-major entry with a backfill line passes', g5); + assert( + g5.backfilled.length === 1 && g5.backfilled[0].declaredIn === '.changeset/backfill.md', + `EM-G5: the backfill is reported with where it was declared -- got ${JSON.stringify(g5.backfilled)}`, + ); + + // EM-R3: a backfill line with no real reason is refused. + red('EM-R3 a backfill line with a short reason is refused', em({ + head: { + [`${SEM}/18.late-note.ts`]: ENTRY('late-note'), + '.changeset/backfill.md': backfillCs(``), + }, + }), [/reason is 4 characters/, /40 characters minimum/]); + + // EM-R4: a backfill line for ANOTHER entry excuses nothing. + red('EM-R4 a backfill line naming another entry does not excuse this one', em({ + head: { + [`${SEM}/18.late-note.ts`]: ENTRY('late-note'), + '.changeset/backfill.md': backfillCs(``), + }, + }), [/under protocol major 18, below the current PROTOCOL_MAJOR 19/]); + + // EM-R5: the rule reads all three entry directories; `retired-keys/` has no + // `id:` line, so `ledgerAdded` cannot be what finds it. + red('EM-R5 an added retired-keys/18.* under PROTOCOL_MAJOR 19 is refused', em({ + head: { [`${KEYS}/18.ui__Thing__gone.ts`]: "export const entry = 'ui/Thing:gone';\n" }, + }), [new RegExp(`${KEYS}/18\\.ui__Thing__gone\\.ts`), new RegExp(`git mv \\S+ ${KEYS}/19\\.ui__Thing__gone\\.ts`)]); + // ...and gives ITS cost, the tombstone aging clock, not the `--from` replay a + // `semantic/` note misses (round 2, L2 N1). + const r5 = em({ head: { [`${KEYS}/18.ui__Thing__gone.ts`]: "export const entry = 'ui/Thing:gone';\n" } }); + const r5text = r5.problems.map((p) => `${p.message}\n${p.annotation}`).join('\n'); + assert( + /build-schemas\.ts/.test(r5text) && /a major too soon/.test(r5text) && !/os migrate meta --from/.test(r5text), + `EM-R5b: a retired-keys refusal names the tombstone aging cost, not the semantic one -- got:\n${r5text}`, + ); + + // EM-R6 (round 2, L2 S1): the backfill line the refusal PRINTS, pasted as + // printed, stays red -- its placeholders are what the reader refuses. + const printed = r1.problems.map((p) => p.message).join('\n').match(//)?.[0] ?? null; + assert(printed !== null, `EM-R6 control: the refusal prints a backfill line -- got:\n${r1.problems.map((p) => p.message).join('\n')}`); + red('EM-R6 the refusal\'s own printed backfill line, pasted unedited, stays red', em({ + head: { [`${SEM}/18.late-note.ts`]: ENTRY('late-note'), '.changeset/backfill.md': backfillCs(printed ?? '') }, + }), [/names no released version of major 18 in digits/, /still carries a placeholder/]); + // ...and the same line with the placeholders filled in passes. + green('EM-G8 the printed line with its placeholders replaced passes', em({ + head: { + [`${SEM}/18.late-note.ts`]: ENTRY('late-note'), + '.changeset/backfill.md': backfillCs((printed ?? '').replace('MINOR.PATCH', '4.0').replace('WHY', 'the note was missed at the time')), + }, + })); + + // EM-R7 (round 2, L2 S2): a base whose TEMPLATE already carries the id (no entry + // file for it). The id is not in `ledgerAdded`, and the new file is judged anyway. + const r7 = emRepo({ + base: { [MIGRATION_LEDGER_TEMPLATE]: "export const X = {\n semantic: [\n {\n id: 'template-only-id',\n surface: 's',\n },\n ],\n};\n" }, + head: { [`${SEM}/18.template-only-id.ts`]: ENTRY('template-only-id') }, + }); + const r7res = run(r7); + red('EM-R7 a new semantic/18.* for an id the base template already carries is refused', r7res, [ + new RegExp(`${SEM}/18\\.template-only-id\\.ts`), /below the current PROTOCOL_MAJOR 19/, + ]); + assert( + !r7res.ledgerAdded.includes('template-only-id'), + `EM-R7 control: the id is NOT in ledgerAdded, so only the key can have found the file -- got ${JSON.stringify(r7res.ledgerAdded)}`, + ); + + // EM-G7 (L1-a nit): the `ledgerAdded` conjunct on the ONE base it exists for, a + // merge base from before the split. An id carried over from the committed + // registry is not new; an id first registered here is, and is judged. + const g7 = run(mk({ + baseIds: ['old-entry-one', 'old-entry-two', 'carried-id'], + baseFiles: { [PROTOCOL_SOURCE]: PROTOCOL(19) }, + files: { + [LEDGER_SOURCES[0]]: null, + [MIGRATION_LEDGER_TEMPLATE]: 'export const X = {\n semantic: [\n ],\n};\n', + [`${SEM}/18.carried-id.ts`]: ENTRY('carried-id'), + [`${SEM}/19.fresh-id.ts`]: ENTRY('fresh-id'), + }, + })); + green('EM-G7 pre-split base: a carried-over id is not added, a new one at the major passes', g7); + assert( + JSON.stringify(g7.addedEntries.map((e) => e.key)) === JSON.stringify(['fresh-id.ts']), + `EM-G7: only the id first registered here is added -- got ${JSON.stringify(g7.addedEntries)}`, + ); + + // EM-R8 (L2 N4): the major is READ, not 19 by habit -- at 20, a new 19.* is red. + red('EM-R8 at PROTOCOL_MAJOR 20 an added semantic/19.* is refused', em({ + major: 20, + head: { [`${SEM}/19.one-behind.ts`]: ENTRY('one-behind') }, + }), [/under protocol major 19, below the current PROTOCOL_MAJOR 20/]); + + // EM-U2: the reason reader, unit-pinned. + const faults = (why, major = 18) => backfillReasonFaults(why, major).length; + assert(faults(backfillExampleReason(18)) > 0, 'EM-U2: the printed example reason is refused as printed'); + assert(faults('first shipped in @objectstack/spec 18.4.0, filed late') === 0, 'EM-U2: a reason naming 18.4.0 holds'); + assert(faults('first shipped in @objectstack/spec 18.0.0-next.2, filed late') === 0, 'EM-U2: a prerelease of the major holds'); + assert(faults('first shipped in the spec package at 19.0.0, filed late here') > 0, 'EM-U2: a release of ANOTHER major is refused'); + assert(faults('first shipped in the spec package at 118.4.0, filed late here') > 0, 'EM-U2: 118.4.0 is not a release of 18'); + + // EM-G6: the same for `retired-keys/`, where the key is the ONLY guard (no + // `id:` line, so no `ledgerAdded` to fall back on). + const g6 = em({ + base: { [`${KEYS}/19.ui__Thing__moved.ts`]: "export const entry = 'ui/Thing:moved';\n" }, + head: { [`${KEYS}/19.ui__Thing__moved.ts`]: null, [`${KEYS}/18.ui__Thing__moved.ts`]: "export const entry = 'ui/Thing:moved';\n" }, + }); + green('EM-G6 a renamed retired-keys entry is not counted as added', g6); + assert(g6.addedEntries.length === 0, `EM-G6: a rename adds nothing -- got ${JSON.stringify(g6.addedEntries)}`); + + // EM-U1: the backfill marker is not an `adr-0087:` disposition. + assert( + readDisposition('').ok === false, + 'EM-U1: an adr-0087-backfill line must not read as an adr-0087 disposition', + ); + } + // ---- CR1-CR3 (#29987): the conversions ledger is split per entry ---------- // // After the codemod split, `registry.ts` imports and lists the conversions and @@ -12034,5 +12504,20 @@ if (isEntrypoint(import.meta.url)) { } } } + // #38240: the entry-major rule, reported on every run that has anything to say. + const added = result.addedEntries.length; + if (added === 0) { + console.log('✓ check-adr-0087-registration: this PR adds no migration entry.'); + } else { + console.log( + `✓ check-adr-0087-registration: ${added} migration entr${added === 1 ? 'y' : 'ies'} added, each at or above PROTOCOL_MAJOR ` + + `${result.protocolMajor}${result.backfilled.length > 0 ? ` or a declared backfill (${result.backfilled.length})` : ''}.`, + ); + for (const b of result.backfilled) { + console.log(` ${b.path} [backfill under ${b.major}, declared in ${b.declaredIn}]`); + console.log(` reason: ${b.why}`); + console.log(`::notice file=${b.path}::ADR-0087 backfill below PROTOCOL_MAJOR ${result.protocolMajor}: ${b.why}`); + } + } } }