Skip to content

Commit 32c7bc0

Browse files
committed
fix(scripts): follow the protocol.ts split's host calls in the durability census; parse through ts-parse
check-durability-degradation-log-level read three moved catch blocks as inventing an answer, lost one read seam, and kept two stale FAILURE_PROPAGATION_SITES keys, all because the codemod split moved the bodies into section modules: - A moved body that delegates its catch to the class's guard as host.rethrowUnlessMetadataStoreUnprovisioned(error) now reaches that guard through the same HOST CALL rule isReadCall already follows. - A host.x() call resolves to the class member x first, through its stub, even when the module declares x itself (x's own moved body, whose extra host parameter failed the arity check). This restores rollbackToPackageCommit's seam around revertCommit. - migrateStoredMetadata and duplicatePackage are keyed by their new modules. The census reads the base's numbers again: 51 durability seams (9 propagating), 102 read seams (13 discriminated). Three self-test rows pin the two rules (the read-seam floor goes 67 -> 70); removing either rule turns exactly its row red. The codemod now parses through ts-parse.mjs (parseSourceFile, createProgramChecked), as check:parse-guard requires. Claude-Session: https://claude.ai/code/session_01WGufzgddMBbTQd9yVo4Yuz Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 639d940 commit 32c7bc0

2 files changed

Lines changed: 102 additions & 16 deletions

File tree

‎scripts/check-durability-degradation-log-level.mjs‎

Lines changed: 92 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,8 @@ const FAILURE_PROPAGATION_CALLEES = new Map([
563563
*/
564564
const FAILURE_PROPAGATION_SITES = new Map([
565565
[
566-
'packages/metadata-protocol/src/protocol.ts::migrateStoredMetadata',
566+
// [#29985] The body moved to `protocol-save.ts` with the codemod split.
567+
'packages/metadata-protocol/src/protocol-save.ts::migrateStoredMetadata',
567568
{
568569
callees: [['record', 'effect']],
569570
why:
@@ -575,7 +576,8 @@ const FAILURE_PROPAGATION_SITES = new Map([
575576
},
576577
],
577578
[
578-
'packages/metadata-protocol/src/protocol.ts::duplicatePackage',
579+
// [#29985] The body moved to `protocol-package-commits.ts` with the codemod split.
580+
'packages/metadata-protocol/src/protocol-package-commits.ts::duplicatePackage',
579581
{
580582
callees: [['failed.push', 'effect']],
581583
why:
@@ -3345,6 +3347,12 @@ function createHostSplit(load) {
33453347
return api;
33463348
}
33473349

3350+
/** [#29985] Is this call `host.x(…)` — through ruling E's host parameter (`HOST_SPLIT.hostParam`)? */
3351+
function viaHostParameter(call) {
3352+
const expr = call.expression;
3353+
return ts.isPropertyAccessExpression(expr) && ts.isIdentifier(expr.expression) && expr.expression.text === HOST_SPLIT.hostParam;
3354+
}
3355+
33483356
/**
33493357
* Does this call perform a storage READ — directly, or through a same-file
33503358
* wrapper? See `MAX_READ_WRAPPER_DEPTH` for why wrappers are followed, and
@@ -3367,7 +3375,14 @@ function isReadCall(node, functionBodies, seen = new Set(), depth = 0, maxDepth
33673375
let body = functionBodies.get(name, node);
33683376
let bodies = functionBodies;
33693377
// #25467: own-file first; only an unresolved name may be a host call.
3370-
if (!body && functionBodies.split) {
3378+
// [#29985] …except a call through ruling E's `host` parameter: `host.x(…)`
3379+
// reaches the class's member `x` whatever the module declares, and a
3380+
// section module routinely declares `x` itself (the moved body of that very
3381+
// member, with the extra `host` parameter, so the own-file answer failed
3382+
// the arity check and the seam left the census).
3383+
const hostHop = functionBodies.split && viaHostParameter(node) ? functionBodies.split.hostCall(node, functionBodies) : undefined;
3384+
if (hostHop) ({ body, bodies } = hostHop);
3385+
else if (!body && functionBodies.split) {
33713386
const hop = functionBodies.split.hostCall(node, functionBodies);
33723387
if (hop) ({ body, bodies } = hop);
33733388
}
@@ -3543,7 +3558,19 @@ function establishesBenign(expr, ctx) {
35433558
const seen = ctx.guardSeen ?? new Set();
35443559
const depth = ctx.guardDepth ?? 0;
35453560
if (seen.has(name) || depth >= MAX_GUARD_DEPTH) return false;
3546-
const body = ctx.functionBodies.get(name, call);
3561+
let body = ctx.functionBodies.get(name, call);
3562+
let guardBodies = ctx.functionBodies;
3563+
// [#29985] A body the host split moved (ruling E) reaches the guard it
3564+
// delegated to in `protocol.ts` as `host.guard(error)`: the same HOST CALL
3565+
// `isReadCall` follows, by the same precedence, answered from the host
3566+
// class's own method — the guard the call reached before the body moved,
3567+
// and nothing wider.
3568+
const hostHop = ctx.functionBodies.split && viaHostParameter(call) ? ctx.functionBodies.split.hostCall(call, ctx.functionBodies) : undefined;
3569+
if (hostHop) ({ body, bodies: guardBodies } = hostHop);
3570+
else if (!body && ctx.functionBodies.split) {
3571+
const hop = ctx.functionBodies.split.hostCall(call, ctx.functionBodies);
3572+
if (hop) ({ body, bodies: guardBodies } = hop);
3573+
}
35473574
if (!body || !ts.isBlock(body)) return false;
35483575
const exits = [];
35493576
const consulted = new Set();
@@ -3552,6 +3579,7 @@ function establishesBenign(expr, ctx) {
35523579
false,
35533580
{
35543581
...ctx,
3582+
functionBodies: guardBodies,
35553583
usedDiscriminators: consulted,
35563584
guardSeen: new Set([...seen, name]),
35573585
guardDepth: depth + 1,
@@ -5025,6 +5053,9 @@ const SELF_TEST_BATTERIES = Object.freeze({
50255053
'passes: #25467 E1 — a stub that hands its body anything but `protocolHost(this)` is not followed': 1,
50265054
'BOUND (#25467 E1): the `host.x()` hop IS a hop — a third hop through the host is still refused': 1,
50275055
'BOUND (#25467 E1): the same host ladder IS a seam one hop deeper — the pin above is not vacuous': 1,
5056+
'passes: #29985 — a moved body\'s catch that delegates to a `protocol.ts` guard as `host.guard(error)` answers on the discriminated branch': 1,
5057+
'flags: #29985 — negative control: the same delegation to a host guard that asks no error type still invents the answer': 1,
5058+
'flags: #29985 — `host.x()` in a module that declares x itself (x\'s own moved body) is the class member x, through its stub': 1,
50285059
'ledger (read seams): a stale entry PASSES and is reported; an unledgered seam still FAILS (#26444)': 1,
50295060
'ledger (read seams): a ledgered file on disk the scan never READ is refused; a deleted one passes (#26444)': 1,
50305061
}),
@@ -5038,7 +5069,7 @@ const SELF_TEST_BATTERIES = Object.freeze({
50385069
// `undefined` and the comparison fails loudly.
50395070
const SELF_TEST_BATTERY_FLOOR = Object.freeze({
50405071
selfTest: 70,
5041-
selfTestReadSeams: 67,
5072+
selfTestReadSeams: 70,
50425073
});
50435074

50445075
// The roster's TOTAL, checked from BOTH verdict sites. Each entry checks only
@@ -6353,6 +6384,11 @@ function selfTestReadSeams() {
63536384
private async findOverlay(t: string) { return await this.lookup(t); }
63546385
async getItem(t: string) { return await this.findOverlay(t); }
63556386
private static async readStatic(engine: any, t: string) { return await engine.find(t, {}); }
6387+
private rethrowUnlessGone(error: unknown): void {
6388+
if (isMissingTableError(error)) return;
6389+
throw error;
6390+
}
6391+
private shrugOff(error: unknown): void { void error; }
63566392
async listRowsMoved(id: string) {
63576393
return listRowsMoved(protocolHost(this), id);
63586394
}
@@ -6364,6 +6400,9 @@ function selfTestReadSeams() {
63646400
readonly tidy: ObjectStackProtocolImplementation['tidy'];
63656401
readonly getItem: ObjectStackProtocolImplementation['getItem'];
63666402
readonly readStatic: (typeof ObjectStackProtocolImplementation)['readStatic'];
6403+
readonly rethrowUnlessGone: ObjectStackProtocolImplementation['rethrowUnlessGone'];
6404+
readonly listRowsMoved: ObjectStackProtocolImplementation['listRowsMoved'];
6405+
readonly shrugOff: ObjectStackProtocolImplementation['shrugOff'];
63676406
readonly untyped: (t: string) => Promise<unknown[]>;
63686407
}`;
63696408
const E1_MODULE_HEAD = `
@@ -7611,6 +7650,54 @@ function selfTestReadSeams() {
76117650
expectViolation: true,
76127651
expectSeams: 1,
76137652
},
7653+
{
7654+
// [#29985] \`metaTypeNamespaceExists\` and \`listCommits\`'s shape once moved:
7655+
// the catch delegates to the host class's discriminating guard.
7656+
name: 'passes: #29985 — a moved body\'s catch that delegates to a `protocol.ts` guard as `host.guard(error)` answers on the discriminated branch',
7657+
files: {
7658+
[`${HOST_SPLIT.dir}/protocol.ts`]: E1_HOST,
7659+
[`${HOST_SPLIT.dir}/protocol-host.ts`]: E1_HOST_MODULE,
7660+
[`${HOST_SPLIT.dir}/protocol-uninstall.ts`]: E1_MODULE_HEAD + `
7661+
export async function listRows(host: Pick<ProtocolHost, 'findRows' | 'rethrowUnlessGone'>, id: string) {
7662+
try { return await host.findRows(id); }
7663+
catch (error) { host.rethrowUnlessGone(error); return []; }
7664+
}`,
7665+
},
7666+
expectViolation: false,
7667+
expectSeams: 1,
7668+
expectDiscriminatorsUsed: ['isMissingTableError'],
7669+
},
7670+
{
7671+
// [#29985] \`rollbackToPackageCommit\` guarding \`host.revertCommit(…)\` once
7672+
// both bodies sit in one section module: the module declares the
7673+
// moved \`revertCommit\` itself, with the extra \`host\` parameter.
7674+
name: 'flags: #29985 — `host.x()` in a module that declares x itself (x\'s own moved body) is the class member x, through its stub',
7675+
files: {
7676+
[`${HOST_SPLIT.dir}/protocol.ts`]: E1_HOST,
7677+
[`${HOST_SPLIT.dir}/protocol-host.ts`]: E1_HOST_MODULE,
7678+
[`${HOST_SPLIT.dir}/protocol-uninstall.ts`]: E1_MODULE_HEAD + `
7679+
export async function rollBack(host: Pick<ProtocolHost, 'listRowsMoved'>, id: string) {
7680+
try { return await host.listRowsMoved(id); }
7681+
catch { return []; }
7682+
}`,
7683+
},
7684+
expectViolation: true,
7685+
expectSeams: 1,
7686+
},
7687+
{
7688+
name: 'flags: #29985 — negative control: the same delegation to a host guard that asks no error type still invents the answer',
7689+
files: {
7690+
[`${HOST_SPLIT.dir}/protocol.ts`]: E1_HOST,
7691+
[`${HOST_SPLIT.dir}/protocol-host.ts`]: E1_HOST_MODULE,
7692+
[`${HOST_SPLIT.dir}/protocol-uninstall.ts`]: E1_MODULE_HEAD + `
7693+
export async function listRows(host: Pick<ProtocolHost, 'findRows' | 'shrugOff'>, id: string) {
7694+
try { return await host.findRows(id); }
7695+
catch (error) { host.shrugOff(error); return []; }
7696+
}`,
7697+
},
7698+
expectViolation: true,
7699+
expectSeams: 1,
7700+
},
76147701
{
76157702
name: 'passes: #25467 E1 — negative control: a moved body whose `host.x()` reaches no storage wrapper is no seam',
76167703
files: {

‎scripts/codemod-split-protocol.mjs‎

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ import { join } from 'node:path';
119119
import { fileURLToPath, pathToFileURL } from 'node:url';
120120

121121
import { isEntrypoint } from './invoked-as.mjs';
122-
import { parseSourceFile } from './ts-parse.mjs';
122+
import { createProgramChecked, parseSourceFile } from './ts-parse.mjs';
123123

124124
const ROOT = join(fileURLToPath(new URL('.', import.meta.url)), '..');
125125
const PKG_REL = 'packages/metadata-protocol';
@@ -240,8 +240,7 @@ function refuse(message) {
240240
* identifier to its declaration in this file, an import specifier included.
241241
*/
242242
function program(ts, fileName, text) {
243-
parseSourceFile(fileName, text);
244-
const sf = ts.createSourceFile(fileName, text, ts.ScriptTarget.Latest, true, ts.ScriptKind.TS);
243+
const sf = parseSourceFile(fileName, text);
245244
const host = {
246245
getSourceFile: (name) => (name === fileName ? sf : undefined),
247246
writeFile() {},
@@ -253,7 +252,7 @@ function program(ts, fileName, text) {
253252
fileExists: (name) => name === fileName,
254253
readFile: () => undefined,
255254
};
256-
const prog = ts.createProgram([fileName], { noLib: true, noResolve: true, target: ts.ScriptTarget.ES2022, strict: true }, host);
255+
const prog = createProgramChecked([fileName], { noLib: true, noResolve: true, target: ts.ScriptTarget.ES2022, strict: true }, host);
257256
return { sf, checker: prog.getTypeChecker() };
258257
}
259258

@@ -448,7 +447,7 @@ function sectionTable(ts, sf, cls, anchors) {
448447
function literalLineIndices(ts, bodyText) {
449448
const prefix = 'function f() ';
450449
const text = prefix + bodyText;
451-
const sf = ts.createSourceFile('x.ts', text, ts.ScriptTarget.Latest, true, ts.ScriptKind.TS);
450+
const sf = parseSourceFile('x.ts', text);
452451
const starts = new Set();
453452
const visit = (node) => {
454453
if (ts.isNoSubstitutionTemplateLiteral(node) || ts.isTemplateHead(node) || ts.isTemplateMiddle(node) || ts.isTemplateTail(node) || ts.isStringLiteral(node)) {
@@ -476,7 +475,7 @@ function literalLineIndices(ts, bodyText) {
476475
*/
477476
function undoBody(ts, movedBodyText, privateStatics) {
478477
const prefix = 'function f(host: any) ';
479-
const sf = ts.createSourceFile('x.ts', prefix + movedBodyText, ts.ScriptTarget.Latest, true, ts.ScriptKind.TS);
478+
const sf = parseSourceFile('x.ts', prefix + movedBodyText);
480479
const sites = [];
481480
const visit = (node) => {
482481
if (ts.isIdentifier(node) && node.text === 'host' && ts.isPropertyAccessExpression(node.parent) && node.parent.expression === node) {
@@ -494,7 +493,7 @@ function undoBody(ts, movedBodyText, privateStatics) {
494493

495494
/** The body text of the one exported function in `fnText` (what `planMove` writes). */
496495
function functionBodyOf(ts, fnText) {
497-
const sf = ts.createSourceFile('x.ts', fnText, ts.ScriptTarget.Latest, true, ts.ScriptKind.TS);
496+
const sf = parseSourceFile('x.ts', fnText);
498497
const fn = sf.statements.find((s) => ts.isFunctionDeclaration(s));
499498
return fn && fn.body ? fnText.slice(fn.body.getStart(sf), fn.body.getEnd()) : null;
500499
}
@@ -925,7 +924,7 @@ function usedImportNames(ts, text) {
925924
* multi-line one as one binding per line. Pure. Returns `{ text, removed }`.
926925
*/
927926
function pruneImports(ts, text, used) {
928-
const sf = ts.createSourceFile(HOST_PATH, text, ts.ScriptTarget.Latest, true, ts.ScriptKind.TS);
927+
const sf = parseSourceFile(HOST_PATH, text);
929928
const edits = [];
930929
const removed = [];
931930
for (const st of sf.statements) {
@@ -1003,8 +1002,8 @@ function verify(T, baseText, headText, baseHostText, headHostText, moduleTexts)
10031002
const failures = [];
10041003
const moved = [];
10051004
const checks = [];
1006-
const baseSf = ts.createSourceFile(HOST_PATH, baseText, ts.ScriptTarget.Latest, true, ts.ScriptKind.TS);
1007-
const headSf = ts.createSourceFile(HOST_PATH, headText, ts.ScriptTarget.Latest, true, ts.ScriptKind.TS);
1005+
const baseSf = parseSourceFile(HOST_PATH, baseText);
1006+
const headSf = parseSourceFile(HOST_PATH, headText);
10081007
const baseCls = hs.classOf(baseSf, CLASS_NAME);
10091008
const headCls = hs.classOf(headSf, CLASS_NAME);
10101009
if (!baseCls || !headCls) return { failures: [`no class ${CLASS_NAME} at base or head`], moved, checks, linesBefore: 0, linesAfter: 0 };
@@ -1014,7 +1013,7 @@ function verify(T, baseText, headText, baseHostText, headHostText, moduleTexts)
10141013
const modules = new Map();
10151014
for (const [file, text] of moduleTexts) {
10161015
if (!text.includes(MARK)) continue;
1017-
const sf = ts.createSourceFile(join(SRC_DIR, file), text, ts.ScriptTarget.Latest, true, ts.ScriptKind.TS);
1016+
const sf = parseSourceFile(join(SRC_DIR, file), text);
10181017
const fns = new Map();
10191018
for (const st of sf.statements) {
10201019
if (ts.isFunctionDeclaration(st) && st.name && st.body && hasModifier(ts, st, ts.SyntaxKind.ExportKeyword)) fns.set(st.name.text, st);

0 commit comments

Comments
 (0)