Skip to content

Commit 4bf7501

Browse files
committed
test(metadata-protocol): the two by-path pins read the moved preamble from its module
protocol.lookup-artifact-item-call-sites reads envelopePackageId's one definition from protocol-package-bindings.ts and asserts protocol.ts imports it (no copy); protocol.read-verb-canonical-fold reads the four door request aliases from protocol-door-requests.ts when protocol.ts imports them from there. Claude-Session: https://claude.ai/code/session_01ADHkmR4MjTzeUv5x6tNkbk Co-authored-by: Claude <noreply@anthropic.com>
1 parent 214cfbb commit 4bf7501

2 files changed

Lines changed: 24 additions & 6 deletions

File tree

‎packages/metadata-protocol/src/protocol.lookup-artifact-item-call-sites.test.ts‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ const SOURCE = readFileSync(fileURLToPath(new URL('./protocol.ts', import.meta.u
4444
const SEAM_FILE = 'protocol-artifact-lookup.ts';
4545
const SEAM = readFileSync(fileURLToPath(new URL(`./${SEAM_FILE}`, import.meta.url)), 'utf8');
4646
const CALLEE = 'lookupArtifactItem(';
47+
/**
48+
* [#25467 E0] The module the protocol.ts preamble's package-binding helpers moved
49+
* to, `envelopePackageId` among them; protocol.ts imports the one definition.
50+
*/
51+
const BINDINGS_FILE = 'protocol-package-bindings.ts';
52+
const BINDINGS = readFileSync(fileURLToPath(new URL(`./${BINDINGS_FILE}`, import.meta.url)), 'utf8');
4753

4854
/** A class member's header in `protocol.ts`: four spaces, optional modifiers, its name, its parameter list. */
4955
const MEMBER_HEADER = /^ {4}(?:(?:private|public|protected|static|async|override|readonly)\s+)*([A-Za-z_$][\w$]*)\s*(?:<[^>]*>)?\(/;
@@ -183,7 +189,11 @@ describe('[#22024] every lookupArtifactItem( in protocol.ts has a recorded dispo
183189
});
184190

185191
it('both read doors take their envelope from one rule, the served item\'s own package when none is named', () => {
186-
expect(SOURCE).toMatch(/\nfunction envelopePackageId\(requestedPackageId: string \| undefined, served: unknown\): string \| undefined \{/);
192+
// [#25467 E0] The rule is defined once, in the bindings module, and protocol.ts
193+
// imports that definition rather than carrying a copy of its own.
194+
expect(BINDINGS).toMatch(/\nfunction envelopePackageId\(requestedPackageId: string \| undefined, served: unknown\): string \| undefined \{/);
195+
expect(SOURCE).not.toMatch(/\nfunction envelopePackageId\(/);
196+
expect(SOURCE).toMatch(/\nimport \{[^}]*\benvelopePackageId,[^}]*\} from '\.\/protocol-package-bindings\.js';/);
187197
expect(SOURCE).toContain('const itemPackageId = envelopePackageId(packageId, it);');
188198
expect(SITES.filter((site) => site.disposition === 'served-package envelope').map((site) => site.member).sort())
189199
.toEqual(['readFlattenedMetaItems', 'readMetaItem']);

‎packages/metadata-protocol/src/protocol.read-verb-canonical-fold.test.ts‎

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -247,14 +247,22 @@ describe('#9157 — the population, re-derived from the code rather than from th
247247
return lines.slice(line, end === undefined || end < 0 ? lines.length : end).join('\n');
248248
};
249249
const METHOD_OR_PRIVATE = /^ {4}(?:private |protected )?(?:static )?(?:async )?[A-Za-z_][A-Za-z0-9_]*\s*\(/;
250+
// [#25467 E0] The four door request aliases moved with the rest of the
251+
// protocol.ts preamble to `protocol-door-requests.ts`; an alias is read
252+
// there only when protocol.ts imports it from that module, so the
253+
// signature judged is still the one the class names.
254+
const doorRequests = readFileSync(fileURLToPath(new URL('./protocol-door-requests.ts', import.meta.url)), 'utf8');
255+
const doorImport = /\nimport type \{([^}]*)\} from '\.\/protocol-door-requests\.js';/.exec(src)?.[1] ?? '';
250256
const aliasLiteral = (name: string): string | undefined => {
251-
const at = src.indexOf(`\ntype ${name} = {`);
257+
const home = src.includes(`\ntype ${name} = {`) ? src
258+
: new RegExp(`\\b${name}\\b`).test(doorImport) ? doorRequests : src;
259+
const at = home.indexOf(`\ntype ${name} = {`);
252260
if (at < 0) return undefined;
253-
const open = src.indexOf('{', at);
261+
const open = home.indexOf('{', at);
254262
let depth = 0;
255-
for (let i = open; i < src.length; i++) {
256-
if (src[i] === '{') depth++;
257-
else if (src[i] === '}' && --depth === 0) return src.slice(open, i + 1);
263+
for (let i = open; i < home.length; i++) {
264+
if (home[i] === '{') depth++;
265+
else if (home[i] === '}' && --depth === 0) return home.slice(open, i + 1);
258266
}
259267
return undefined;
260268
};

0 commit comments

Comments
 (0)