Skip to content

Commit 0dc436c

Browse files
committed
test(metadata-protocol): pin each fix-can-be-taken step of the named-base close where it was untested
Claude-Session: https://claude.ai/code/session_01JQwxbZz2XXsYuaJz9sPuGU Co-authored-by: Claude <noreply@anthropic.com>
1 parent 42ff86f commit 0dc436c

1 file changed

Lines changed: 55 additions & 1 deletion

File tree

‎packages/metadata-protocol/src/protocol.named-base-overlay-write.test.ts‎

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,20 @@ const BASE_VERSION = '3.2.0';
5252
const NO_PAIR_BASE = 'com.legacy.app';
5353
/** A writable runtime package: no manifest booted it. */
5454
const WRITABLE = 'com.acme.workspace';
55+
/** A read-only code package whose id forms no pair: an id ending in `.custom` (ADR-0146 D3). */
56+
const NO_PAIR_ID_BASE = 'com.vendor.custom';
57+
/** A read-only code package that records no version, with its pair already installed. */
58+
const NO_VERSION_BASE = 'com.nover.app';
59+
const NO_VERSION_PAIR = 'com.nover.app.custom';
5560

5661
const MANIFESTS: Record<string, Record<string, unknown>> = {
5762
[BASE]: { dependencies: {}, version: BASE_VERSION, namespace: 'acme' },
5863
[PAIR]: { dependencies: { [BASE]: '^3' }, version: '0.1.0', namespace: 'acme_custom' },
5964
[NO_PAIR_BASE]: { dependencies: {}, version: '1.0.0' },
6065
[WRITABLE]: { dependencies: {} },
66+
[NO_PAIR_ID_BASE]: { dependencies: {}, version: '1.0.0', namespace: 'vendor' },
67+
[NO_VERSION_BASE]: { dependencies: {}, namespace: 'nover' },
68+
[NO_VERSION_PAIR]: { dependencies: { [NO_VERSION_BASE]: '*' }, version: '0.1.0', namespace: 'nover_custom' },
6169
};
6270

6371
/** One item of each overlay type the base ships, and a body a write carries. */
@@ -78,6 +86,8 @@ const VIEW = ITEMS[0]!;
7886
const SHIPPED = [
7987
...ITEMS.map((i) => ({ type: i.type, name: i.name, pkg: BASE })),
8088
{ type: 'dashboard', name: 'legacy_board', pkg: NO_PAIR_BASE },
89+
{ type: 'dashboard', name: 'vendor_board', pkg: NO_PAIR_ID_BASE },
90+
{ type: 'dashboard', name: 'nover_board', pkg: NO_VERSION_BASE },
8191
];
8292
const PACKAGED = 'Packaged';
8393

@@ -109,7 +119,7 @@ function makeProtocol() {
109119
const packageRecord = (id: string) => (MANIFESTS[id] ? { manifest: { id, ...MANIFESTS[id] } } : undefined);
110120
const engine: any = {
111121
// A booted code package is read-only (`isWritablePackage` reads `manifests` first).
112-
manifests: new Map([[BASE, {}], [NO_PAIR_BASE, {}]]),
122+
manifests: new Map([[BASE, {}], [NO_PAIR_BASE, {}], [NO_PAIR_ID_BASE, {}], [NO_VERSION_BASE, {}]]),
113123
async find(t: string, q?: { where?: Record<string, unknown>; limit?: number }) {
114124
const rows = table(t).filter((r) => matches(r, q?.where));
115125
return typeof q?.limit === 'number' ? rows.slice(0, q.limit) : rows;
@@ -377,6 +387,50 @@ describe('CONTROLS: the writes the close leaves open, as on main', () => {
377387
* the commit CREATED is reverted by removing the row, which writes nothing and
378388
* stays open.
379389
*/
390+
/**
391+
* Each step of "the fix the refusal names can be taken" (the pair id, the
392+
* ensure door, the base's version, the override write gate admitting the
393+
* declared body) leaves the write naming the base open where it fails: the
394+
* refusal would name a door the author cannot take. The ensure door's step is
395+
* the CONTROL above (`a read-only base whose pair cannot be ensured`); a
396+
* shipped member's closed save is the five-type case at the top.
397+
*/
398+
describe('CONTROLS: every step the fix takes, failing, leaves the write naming the base open (ADR-0146 D1, D11)', () => {
399+
it('a read-only base whose id forms no pair (an id ending in `.custom`) keeps the write naming it: there is no pair to name', async () => {
400+
const { protocol, rows } = makeProtocol();
401+
402+
const saved = await protocol.saveMetaItem({
403+
type: 'dashboard', name: 'vendor_board', item: { name: 'vendor_board', label: 'Vendor', widgets: [] }, packageId: NO_PAIR_ID_BASE,
404+
});
405+
406+
expect(saved).toMatchObject({ success: true });
407+
expect(rows('dashboard', 'vendor_board')).toEqual([{ package_id: NO_PAIR_ID_BASE, state: 'active', label: 'Vendor' }]);
408+
});
409+
410+
it('a read-only base that records no version, its pair installed, keeps the write naming it: there is no `basedOn` to declare', async () => {
411+
const { protocol, rows } = makeProtocol();
412+
413+
const saved = await protocol.saveMetaItem({
414+
type: 'dashboard', name: 'nover_board', item: { name: 'nover_board', label: 'Nover', widgets: [] }, packageId: NO_VERSION_BASE,
415+
});
416+
417+
expect(saved).toMatchObject({ success: true });
418+
expect(rows('dashboard', 'nover_board')).toEqual([{ package_id: NO_VERSION_BASE, state: 'active', label: 'Nover' }]);
419+
});
420+
421+
it('an email template at a locale the base does not ship keeps the write naming the base: the override write gate refuses its declared body', async () => {
422+
const { protocol, rows } = makeProtocol();
423+
const email = ITEMS.find((i) => i.type === 'email_template')!;
424+
425+
const saved = await protocol.saveMetaItem({
426+
type: email.type, name: email.name, item: { ...email.body('Bienvenue'), locale: 'fr-FR' }, packageId: BASE,
427+
});
428+
429+
expect(saved).toMatchObject({ success: true });
430+
expect(rows(email.type, email.name)).toEqual([{ package_id: BASE, state: 'active', label: 'Bienvenue' }]);
431+
});
432+
});
433+
380434
describe('the commit doors: restoring a row bound to the base is closed, removing one stays open (#29390)', () => {
381435
/** Each commit a second apart, so the package rollback's "strictly newer" reads an order. */
382436
let clock = Date.parse('2026-11-02T00:00:00.000Z');

0 commit comments

Comments
 (0)