Skip to content

Commit 90b5cde

Browse files
committed
fix(metadata-protocol): a base's address naming no member serves its canonical member alone
Co-authored-by: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012MmDsS4GoHCgYwA2uv3n3C
1 parent 91cfa33 commit 90b5cde

2 files changed

Lines changed: 26 additions & 10 deletions

File tree

‎packages/metadata-protocol/src/protocol-write-gates.ts‎

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ import { baseAddressServesMember, readOnlyShippingPackages, shippingPackageIds }
4545
import { canonicalMetaType, canonicalizeMetaRequestType } from './protocol-meta-type-schema.js';
4646
import { boundPackageOf } from './protocol-package-bindings.js';
4747
import type { ShippingPackages } from './protocol-package-bindings.js';
48-
import { memberOption } from './protocol-bundle-members.js';
48+
import { bundleMemberDiscriminator, memberOption } from './protocol-bundle-members.js';
4949
import type { MetadataAuditEntry } from './protocol-audit-entry.js';
5050
import { packagedBaseRegimeRow, packagedBaseRegimeSentence } from './packaged-base-regime.js';
5151
import { packagelessCloseSubject } from './protocol-packageless-overlay-migration.js';
@@ -688,17 +688,22 @@ export class ProtocolWriteGatesFacet {
688688
* [#28802] The registry's answer `item` for a bundle member read on the
689689
* address of `base`, when that address serves it
690690
* ({@link baseServesBundleMember}); else, for a read that named no
691-
* member, the base's own member its artifact answers canonical-first,
692-
* and otherwise nothing. An address that ships no member of the name is
693-
* no base of it: `item` as before.
691+
* member, the base's own CANONICAL member, and otherwise nothing. An
692+
* address that ships no member of the name is no base of it: `item` as
693+
* before. [#34682] A read naming no member addresses the canonical member
694+
* (the selector's contract), so a base that ships none answers it with
695+
* nothing, as `?member=<canonical>` is answered; FROM (`main` d947a93cf8):
696+
* the base's first shipped member (`fr-FR`).
694697
*/
695698
static registryMemberServedAt(host: Pick<ProtocolHost, 'baseServesBundleMember' | 'engine' | 'shippedArtifactsOf' | 'shippingPackagesOf' | 'shipsBundleName'>, type: string, name: string, base: string, item: unknown, member: string | undefined): unknown {
696699
const shipping = host.shippingPackagesOf(type);
697700
if (!host.shipsBundleName(type, name, base, shipping)) return item;
698701
if (host.baseServesBundleMember(type, name, base, item, shipping)) return item;
699702
if (member !== undefined) return undefined;
703+
const canonical = bundleMemberDiscriminator(type, undefined);
700704
const own = host.shippedArtifactsOf(type, name, shipping)
701-
.find((artifact) => (artifact as { _packageId?: unknown } | null)?._packageId === base);
705+
.find((artifact) => (artifact as { _packageId?: unknown } | null)?._packageId === base
706+
&& itemDiscriminator(canonicalMetaType(type), artifact) === canonical);
702707
if (own === undefined) return undefined;
703708
const candidate = host.engine.registry.getItem(type, name, base, itemDiscriminator(canonicalMetaType(type), own));
704709
return candidate !== undefined && host.baseServesBundleMember(type, name, base, candidate, shipping) ? candidate : undefined;

‎packages/runtime/src/domains/meta-bundle-member-one-request.test.ts‎

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@
1010
//
1111
// FROM (`main` d947a93cf8), a bundle with no canonical member:
1212
// - shipped in `fr-FR` only: the plain read and `/layers` served the `fr-FR`
13-
// member (200) and the execution read returned it, while `?member=en-US`
14-
// and `/published` answered 404;
13+
// member (200) and the execution read returned it, naming no package and
14+
// naming the shipping package (`?package=`), while `?member=en-US` and
15+
// `/published` answered 404;
1516
// - stored in `fr-FR` only (a package-less row): 404 before a restart, then
1617
// 200 with the `fr-FR` row after it (the hydrated bare slot), while
1718
// `?member=en-US` and `/published` answered 404 on both sides.
@@ -94,12 +95,14 @@ const shape = (answer: Answer, pick: (served: any) => unknown): unknown[] =>
9495
answer.status === 200 ? [200, pick(unwrap(answer.body))] : [answer.status, codeOf(answer.body)];
9596
const doc = (d: any) => (d == null ? d : { name: d.name, locale: d.locale, subject: d.subject, label: d.label });
9697

97-
async function doors(b: Booted, type: string, name: string, member?: string) {
98-
const query: Record<string, string> = member === undefined ? {} : { member };
98+
async function doors(b: Booted, type: string, name: string, member?: string, pkg?: string) {
99+
const query: Record<string, string> = { ...(member === undefined ? {} : { member }), ...(pkg === undefined ? {} : { package: pkg }) };
99100
const protocol = b.kernel.getService('protocol') as any;
100101
let executed: unknown;
101102
try {
102-
executed = doc((await protocol.getMetaItemForExecution({ type, name, ...query }))?.item ?? null);
103+
executed = doc((await protocol.getMetaItemForExecution({
104+
type, name, ...(member === undefined ? {} : { member }), ...(pkg === undefined ? {} : { packageId: pkg }),
105+
}))?.item ?? null);
103106
} catch (e) {
104107
executed = ['threw', (e as { status?: unknown }).status, (e as { code?: unknown }).code];
105108
}
@@ -144,6 +147,14 @@ describe('[#34682] naming no member and naming the canonical member are one requ
144147
expect({ leg, name, read: bare.read, effective: (bare.layers[1] as unknown[] | undefined)?.[0], executed: bare.executed })
145148
.toEqual({ leg, name, read: [200, served], effective: served, executed: served });
146149
}
150+
// …and at the shipping package's own address (`?package=`), for a shipped bundle.
151+
if (name.startsWith('ship_')) {
152+
const atBase = await doors(b, 'email_template', name, undefined, A);
153+
const atBaseNamed = await doors(b, 'email_template', name, CANONICAL, A);
154+
expect({ leg, name, ...atBaseNamed }, JSON.stringify(atBaseNamed)).toEqual({ leg, name, ...atBase });
155+
expect({ leg, name, read: atBase.read, executed: atBase.executed })
156+
.toEqual({ leg, name, read: served === undefined ? [404, 'RESOURCE_NOT_FOUND'] : [200, served], executed: served ?? null });
157+
}
147158
// `/published` takes no member selector: it reads the canonical member alone.
148159
const named400 = await get(b.kernel, `/meta/email_template/${name}/published`, { member: CANONICAL });
149160
expect([leg, name, named400.status, codeOf(named400.body)]).toEqual([leg, name, 400, 'VALIDATION_ERROR']);

0 commit comments

Comments
 (0)