Skip to content

Commit 6cc3f97

Browse files
fix(metadata-protocol,rest,runtime): beside a disabled package, the bare read, /layers and /published serve the one enabled holder of a doc, view or other type the registry does not read by package (#34354)
<!-- claude-projects-attribution: {"github_login":"zhuangjianguo"} --> _Requested by **Steedos** · [project thread](https://claude.ai/code/project/chan_018ETKaNwMZCNRYD7D8Q9Ubb?thread=cmsg_018ETKaNwMZCNRYD7D8Q9UbbNTugWasvhTMrtCZiFGrZYK)_ Fixes #34041 Clause-②: no Metadata-protocol: none ## 维护者速读 - 改了什么:同名元数据由“一个启用包 + 一个停用包”同时发布时,不带包名的读取、`/layers` 和 `/published` 现在都返回启用包的条目。覆盖 doc、view、translation、hook 等所有“注册表不按包读取”的类型(object、action、package 除外)。 - 为什么改:ADR-0150 D3 规定停用的包不持有名字。原来这些类型按名字取第一层(元数据服务里最后注册的副本,或注册表的第一个组合项),如果取到的是停用包的,普通读取返回 404,`/layers` 甚至把停用包的正文当作 effective 返回。 - 风险与回滚:只在“名字的持有者里有停用包、且只剩一个启用持有者”时改变答案。两个启用持有者照旧 409,全部停用照旧 404,action 与保存门不变。回滚即 revert 本 PR。 - 先看:`packages/metadata-protocol/src/protocol-meta-item-face.ts`(`servedHolderAddressOf` 去掉 readsByPackage 门槛,新增 `SERVED_HOLDER_JUDGED_ELSEWHERE`);`packages/rest/src/meta-item-history-routes.ts` 与 `packages/runtime/src/domains/meta.ts` 中 `/published` 的 mixed-owner 分支(同一条件,两处孪生)。 - 两分钟验证:`pnpm --filter @objectstack/runtime exec vitest run src/domains/meta-disabled-holder-artifact-door.test.ts`,预期 23 passed,`[#34041]` 组在两种注册顺序下全部为绿。 - 需要你做的:无,席位落地。 ## What changes ADR-0150 D3 says a disabled package holds no name. For a type the registry reads by package, the read naming no package already took the served holder's address when a disabled package also holds the name (`servedHolderAddressOf`, #32183). Every other type read the layer it finds by name alone. That layer is the metadata service's copy, which belongs to the package registered last, or else the registry's first composite. Either one could be the disabled holder's. The face then withheld it, so the plain read answered 404, and `/layers` served the disabled body as `effective`. - **`servedHolderAddressOf`** (`protocol-meta-item-face.ts`) no longer requires `readsByPackage(type)`. It re-addresses every type except those `SERVED_HOLDER_JUDGED_ELSEWHERE` names: `object` (one owner, refused with its disabled package), `action` (its bare judge `judgeBareActionRead` already serves the one enabled holder; measured unchanged) and `package`. Read at the served holder's address, the read is that holder's exact read, which never answers another package's service copy (`serviceCopyOfAnotherPackage`, #34241). Its callers in `protocol-meta-item-reads.ts` and `protocol-meta-layered-reads.ts` needed no edit. - **The `/published` door twins** (`rest/src/meta-item-history-routes.ts`, `runtime/src/domains/meta.ts`): the mixed-owner arm's `readsByPackage(type) === true` conjunct becomes "type is not `action`" (`object` and `package` are excluded there already). Without this, once the plain read served the enabled holder, the snapshot exit served the metadata service's `getPublished` copy, which is the disabled holder's body (measured: 200 `beta doc` on both transports). The claim amendment (comment 6908475841) widened the file surface to these two files. ## FROM → TO One enabled holder (alpha) and one disabled holder (beta) of a name, for each of `doc`, `view`, `translation`, `field`, `seed`, `datasource`, `external_catalog`, `object_extension`, `hook`, `job`, `sharing_rule`, `queue` and `assignment_rule`: | Door | FROM (main) | TO | |---|---|---| | bare `GET /meta/TYPE/NAME`, when the layer read by name is beta's (the service copy with beta registered last, or the registry's first composite with beta registered first and no copy) | 404 | 200, alpha's item | | bare `/layers`, same states | 200, `effective` = beta's body | 200, `effective` = alpha's item | | bare `/published` (doc, composed rig, beta registered last) | 404 | 200, alpha's doc | | the same doors when the layer read by name is already alpha's | 200, alpha | unchanged | | two enabled holders of a doc | 409 naming both | unchanged | | both holders disabled | 404 | unchanged | | `action`, `object`, `package`; a name no disabled package holds | as on main | unchanged | | bare `PUT /meta/doc/NAME` beside a disabled holder | 403 `NOT_OVERRIDABLE` (sealed) | unchanged | Nothing served becomes refused, so `Clause-②: no` holds as claimed. No authorable key, value or type moves, so `Metadata-protocol: none` holds too. ## Tests - `packages/objectql/src/package-scoped-exact-qualifier.test.ts`, a new top-level describe `[#34041]` beside the #34040 type enumeration. It holds an enumeration pin (every type the registry does not read by package is pinned, one-holder, or judged elsewhere). Per type, in both orders, with beta disabled, the plain read and `/layers` serve alpha in each of three service states (no copy, alpha's copy, beta's copy), and with both disabled there is no item. CONTROLs: a doc with two enabled holders is refused 409 naming both, before and after a disable and re-enable; an action is unchanged; a view with no disabled holder reads as before. - `packages/runtime/src/domains/meta-disabled-holder-artifact-door.test.ts`, a new `describe.each` `[#34041]` on the composed artifact rig (the `MetadataPlugin` artifact door plus `AppPlugin`), on both transports and in both orders. With beta disabled, the plain read, `/layers` (code and effective) and `/published` serve `alpha doc` and never `# beta`. CONTROL: with both disabled, every door answers 404; with both re-enabled, every door refuses 409 naming both. <details><summary>Reverse verification against origin/main 01598d9 (before the fix)</summary> - objectql describe: `Tests 28 failed | 4 passed`. Example, view with beta registered last and the service keeping beta's copy: Received `[undefined, "beta view"]`, Expected `["alpha view", "alpha view"]`. - Composed rig: the dispatcher plain read Received `404 undefined`, Expected `200 "alpha doc"`. - With only the face fix (before the door half): the rig's only red rows were `dispatcher doc/shared_doc/published` and `rest doc/shared_doc/published`, Received `200 "beta doc"`. </details> <details><summary>Ablation (ablation-replace; restore blob equals HEAD; git diff HEAD empty; tree clean)</summary> - Leg 1, the `readsByPackage` gate put back in `servedHolderAddressOf` (metadata-protocol resolves through `dist/` in both suites, so it was rebuilt; `ablation-dist-preflight` found the marker in 2 built files, and after restore and rebuild `--absent` found it in none of 24). objectql: `Tests 28 failed | 352 passed (380)`, e.g. Received `undefined, "beta view"`. Rig: `1 failed | 22 passed`, with all six door rows red. The first attempt at this leg was a no-op: the build folded its string marker away, preflight reported it ABSENT, and nothing ran. It was redone with a marker that reaches `dist/`. - Leg 2, the gate put back in the RestServer `/published` arm (runtime aliases `@objectstack/rest` to `src`): rig `1 failed | 22 passed`, the only red row `rest doc/shared_doc/published`, Received `"beta doc"`. - Leg 3, the gate put back in the dispatcher `/published` arm: rig `1 failed | 22 passed`, the only red row `dispatcher doc/shared_doc/published`, Received `"beta doc"`. </details> ## Acceptance notes - `servedPackagelessSaveAddress` (`protocol-save.ts`, not edited) asks the same judgment. For a doc beside a disabled holder, the bare save is refused 403 `NOT_OVERRIDABLE` (a sealed managed package) both before and after this change, in both orders, so the save is unchanged. This was measured with a scratch probe on the composed rig. - The light harness also shows the second state on main: with no service copy and the disabled holder registered first, the registry's first composite was the disabled body. The fix covers that state too, and the pin enumerates it. ## Verification - **Head 662c7c9** (origin/main 35c9a30 merged in, which brings #33995's edits to the same face and door files; merge-tree was clean and the merge had no conflict): rebuilt; `typecheck` exit 0 for metadata-protocol, objectql, rest and runtime. **NOT MEASURED at this head**: the suites, the two pin files and the derived gates. Reason: a maintainer order to hand off now stopped that run, so the readings below are from the previous head. The next seat (or CI) re-runs them. <details><summary>Suites, typecheck and gates at the previous head 42610dc (origin/main 3b1307e merged in), under the shared verify lock</summary> Touched packages and their direct dependents: - metadata-protocol: Test Files 345 passed, 9 skipped (354); Tests 22956 passed, 45 skipped. - objectql: Test Files 599 passed (599); Tests 13398 passed. - rest: Test Files 413 passed (413); Tests 8497 passed, 350 skipped. - runtime: Test Files 607 passed (607); Tests 11106 passed, 19 skipped. - cli `--project unit`: 421 passed and 2 failed on the first run, because `packages/cli` itself was not built. After `pnpm --filter @objectstack/cli build`, those 2 files pass (29 tests). - client: 812 tests passed. cloud-connection: 1227 passed. plugin-approvals: 1652 passed. plugin-email: 1020 passed. - plugin-security: 6723 passed. service-automation: 4040 passed. service-messaging: 991 passed. service-package: 144 passed. - verify: 439 passed. organizations: 252 passed. plugin-auth: 5646 passed. plugin-dev: 89 passed. hono: 258 passed. http-conformance: 292 passed. The rest: - `typecheck`: metadata-protocol, objectql, rest and runtime all exit 0. - `check:type-check-debt`: exit 0. - eslint `--no-inline-config` on the 5 touched source and test files: exit 0. - `dispatch-gates --commands`: 73 derived, all 73 run. 72 exit 0. `check:query-options-erasure` exit 0, on a rerun after a 300 s local timeout under contention. `check:dual-build-cjs-loads` answered PREREQUISITE NOT MET: it needs every package built, so it is NOT MEASURED locally and is left to CI. - `--ran` reconciliation: 73 derived, 73 run, 0 UNRUN. - `git merge-tree --write-tree`: clean against origin/main, origin/claude/area-E1-32849-nomember (884050f, then 013010a) and PR #33995 (0f5f95d, the one open PR that touched these files; it has since merged). PR #33995 first conflicted on an adjacent insertion in `protocol-meta-item-face.ts`. Moving the new constant below `servedHolderAddressOf` made it clean. </details> --- _Generated by [Claude Code](https://claude.ai/code/session_01QsR2jTkZnXtRhuEiiyidvJ)_ 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent a8e794f commit 6cc3f97

6 files changed

Lines changed: 211 additions & 6 deletions

File tree

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
'@objectstack/metadata-protocol': patch
3+
'@objectstack/rest': patch
4+
'@objectstack/runtime': patch
5+
---
6+
7+
fix(metadata-protocol,rest,runtime): beside a disabled package, the read naming no package, `/layers` and `/published` serve the one enabled holder of a `doc`, `view` or any other type the registry does not read by package
8+
9+
Clause-②: no
10+
Metadata-protocol: none
11+
12+
A disabled package holds no name (ADR-0150 D3). Take a name that one enabled and one disabled package both ship. For a type the registry reads by package, the bare read (`GET /api/v1/meta/TYPE/NAME`), `/layers` and `/published` already served the enabled holder. For every other type they read the layer they find by name alone. That layer is the metadata service's copy, which belongs to the package registered last, or else the registry's first composite. Either one could be the disabled holder's.
13+
14+
- The plain read answered `404` (the disabled body, withheld) although an enabled package ships the name. FROM `404`, TO the enabled holder's item.
15+
- `/layers` served the disabled holder's body as `effective`. FROM that body, TO the enabled holder's item.
16+
- `/published` answered `404` on both transports. FROM `404`, TO the enabled holder's item.
17+
18+
This covers `doc`, `view`, `translation`, `field`, `seed`, `datasource`, `external_catalog`, `object_extension`, `hook`, `job`, `sharing_rule`, `queue` and `assignment_rule`. `object`, `action` and `package` are not changed: an `action`'s own bare judge already serves the enabled holder.
19+
20+
Unchanged: no answer that was served becomes refused. Two enabled holders of a doc are still refused `409` naming both. A name only disabled packages hold still answers `404`. A name no disabled package holds reads as before. The bare save door is unchanged.

‎packages/metadata-protocol/src/protocol-meta-item-face.ts‎

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,8 @@ export async function packagelessRowWithheld(
213213
/**
214214
* [#32183] The package whose stack a read naming no package takes, for a
215215
* name a disabled package also holds: the one holder ADR-0150 D3 resolves
216-
* over the served set. `undefined` leaves the read as it was: a type the
217-
* registry does not read by package, a name no disabled package holds (the
216+
* over the served set. `undefined` leaves the read as it was: a type judged
217+
* elsewhere ({@link SERVED_HOLDER_JUDGED_ELSEWHERE}), a name no disabled package holds (the
218218
* read is `main`'s, untouched), the environment's own item (D3 (a) serves
219219
* it), no served holder (the withheld arm of the face) or two or more (the
220220
* read's own refusal).
@@ -225,10 +225,23 @@ export async function packagelessRowWithheld(
225225
* holder's body while the by-name read served the enabled one. Shared by
226226
* the face and the layered read, so both read one stack. Optional-called:
227227
* a registry without these reads leaves every read as it was.
228+
*
229+
* [#34041, ADR-0150 D3] …and for a type the registry does not read by
230+
* package (a `doc`, `view`, `translation`, `hook`, …) too: a disabled package
231+
* holds no name of any type. Such a type's layers are the metadata service's
232+
* copy, which it keeps by name alone (the body registered last), and the
233+
* registry's first composite, so either one could be the disabled holder's.
234+
* The face then withheld it, and the bare read answered 404 although an
235+
* enabled package ships the name; `/layers` served the disabled body. Read at
236+
* the served holder's address, the read is that holder's exact read, which
237+
* never answers another package's copy (`serviceCopyOfAnotherPackage`).
238+
* Not an `object` (one package owns the name; the face refuses a disabled
239+
* package's) and not an `action` (judged over every holder by its own bare
240+
* judge, `judgeBareActionRead`, which serves the one enabled holder already).
228241
*/
229242
export function servedHolderAddressOf(registry: any, type: string, name: string): string | undefined {
230-
if (typeof registry?.readsByPackage !== 'function' || registry.readsByPackage(type) !== true) return undefined;
231-
if (typeof registry.packageScopedHoldersOf !== 'function' || typeof registry.isPackageDisabled !== 'function') return undefined;
243+
if (SERVED_HOLDER_JUDGED_ELSEWHERE.has(type)) return undefined;
244+
if (typeof registry?.packageScopedHoldersOf !== 'function' || typeof registry.isPackageDisabled !== 'function') return undefined;
232245
const every: readonly string[] = registry.packageScopedHoldersOf(type, name, null, { includeDisabledPackages: true }) ?? [];
233246
if (!every.some((id) => registry.isPackageDisabled(id) === true)) return undefined;
234247
const served: readonly string[] = registry.packageScopedHoldersOf(type, name, null) ?? [];
@@ -239,6 +252,12 @@ export function servedHolderAddressOf(registry: any, type: string, name: string)
239252
return served[0];
240253
}
241254

255+
/**
256+
* [#34041] The types whose bare read {@link servedHolderAddressOf} never
257+
* re-addresses: each is judged against a disabled package elsewhere.
258+
*/
259+
const SERVED_HOLDER_JUDGED_ELSEWHERE: ReadonlySet<string> = new Set(['object', 'action', 'package']);
260+
242261
/**
243262
* [#32354, ADR-0150 D3] The served holder of a name for a read naming no
244263
* package, judged over the stored rows too: what {@link servedHolderAddressOf}

‎packages/objectql/src/package-scoped-exact-qualifier.test.ts‎

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -830,6 +830,100 @@ describe('[#34040] the exact read never serves the service\'s copy of another pa
830830
});
831831
});
832832

833+
/**
834+
* [#34041, ADR-0150 D3] A disabled package holds no name, of any type: beside
835+
* one enabled holder, the read naming no package serves that holder's item, and
836+
* so does `/layers`. For a type the registry does not read by package, the read
837+
* reached the layer it reads by name alone (the service's copy, kept for the
838+
* package registered last, else the registry's first composite) and the face
839+
* withheld it when it was the disabled holder's.
840+
*
841+
* BASE (measured before the fix, origin/main 01598d93, this fixture): with
842+
* beta disabled, every type below answered no item whenever that layer was
843+
* beta's (the service keeping beta's copy, or no service copy and beta
844+
* registered first), and `/layers` served beta's body as `effective`.
845+
*/
846+
describe('[#34041] the read naming no package serves the one enabled holder beside a disabled one, for every type the registry does not read by package', () => {
847+
const NOT_READ_BY_PACKAGE = MetadataTypeSchema.options.filter((type) => !(PACKAGE_SCOPED_READ_TYPES as readonly string[]).includes(type));
848+
/** The security catalog keeps one package holder of these: a second holder is refused (the #34040 describe pins it). */
849+
const ONE_HOLDER = ['position', 'capability'];
850+
/** Judged against a disabled package by their own bare judges: the object's owner refusal, the action's `judgeBareActionRead`. */
851+
const JUDGED_ELSEWHERE = ['object', 'action'];
852+
const TWO_HOLDER = NOT_READ_BY_PACKAGE.filter((type) => !ONE_HOLDER.includes(type) && !JUDGED_ELSEWHERE.includes(type));
853+
854+
it('the enumeration: every type the registry does not read by package is pinned below, one-holder, or judged elsewhere', () => {
855+
expect([...TWO_HOLDER].sort()).toEqual(
856+
['assignment_rule', 'datasource', 'doc', 'external_catalog', 'field', 'hook', 'job', 'object_extension', 'queue', 'seed', 'sharing_rule', 'translation', 'view'],
857+
);
858+
});
859+
860+
const bodyOf = (type: string, packageId: string) => ({
861+
name: 'shared', label: `${packageId.split('.').pop()} ${type}`, ...(type === 'action' ? { type: 'url', target: 'https://example.com' } : {}),
862+
});
863+
/** The protocol over this fixture's engine: no service, or a service keeping `kept`'s copy for every read. */
864+
const protocolKeeping = (type: string, kept: string | undefined) => {
865+
if (kept === undefined) return protocol;
866+
const copy = { ...bodyOf(type, kept), _packageId: kept };
867+
const metadata = { get: vi.fn(async () => copy), getDiagnosed: vi.fn(async () => ({ data: copy, degraded: false, errors: [] })) };
868+
return new ObjectStackProtocolImplementation(engine as never, () => new Map<string, unknown>([['metadata', metadata]]));
869+
};
870+
/** The plain read's and `/layers`' labels, for each service state: none, alpha's copy, beta's copy. */
871+
const bareLabels = async (type: string) => {
872+
const seen: Array<[string, unknown, unknown]> = [];
873+
for (const kept of [undefined, A, B]) {
874+
const served = protocolKeeping(type, kept);
875+
const plain = labelOf(await served.getMetaItem({ type, name: 'shared' }));
876+
const layered = ((await served.getMetaItemLayered({ type, name: 'shared' })) as { effective?: { label?: string } }).effective?.label;
877+
seen.push([kept ?? 'no service copy', plain, layered]);
878+
}
879+
return seen;
880+
};
881+
882+
it.each(TWO_HOLDER.flatMap((type) => [[type, 'beta registered last', [A, B]], [type, 'beta registered first', [B, A]]] as const))(
883+
'%s, %s: beta disabled, the plain read and /layers serve alpha\'s item whichever layer holds beta\'s; both disabled, no item',
884+
async (type, _order, order) => {
885+
for (const id of order) registry.registerItem(type, bodyOf(type, id) as never, 'name' as never, id);
886+
registry.disablePackage(B);
887+
const alpha = `alpha ${type}`;
888+
expect(await bareLabels(type)).toEqual([['no service copy', alpha, alpha], [A, alpha, alpha], [B, alpha, alpha]]);
889+
// CONTROL: no enabled holder, no served holder: the withheld item, as before.
890+
registry.disablePackage(A);
891+
expect(labelOf(await protocolKeeping(type, B).getMetaItem({ type, name: 'shared' })), `${type}, both disabled`).toBeUndefined();
892+
},
893+
);
894+
895+
it.each([['beta registered last', [A, B]], ['beta registered first', [B, A]]] as const)(
896+
'CONTROL — doc, %s: two enabled holders are refused 409 naming both, before and after beta is disabled and enabled again',
897+
async (_order, order) => {
898+
for (const id of order) registry.registerItem('doc', bodyOf('doc', id) as never, 'name' as never, id);
899+
const expectRefused = async () => {
900+
const err = await refusalOf(() => protocolKeeping('doc', order[1]).getMetaItem({ type: 'doc', name: 'shared' }));
901+
expect([err.code, err.status, [...err.refusal.candidates].map((c) => (c as { packageId?: string }).packageId).sort()]).toEqual(['RESOURCE_CONFLICT', 409, [A, B]]);
902+
};
903+
await expectRefused();
904+
registry.disablePackage(B);
905+
expect(labelOf(await protocolKeeping('doc', B).getMetaItem({ type: 'doc', name: 'shared' }))).toBe('alpha doc');
906+
registry.enablePackage(B);
907+
await expectRefused();
908+
},
909+
);
910+
911+
it.each([['beta registered last', [A, B]], ['beta registered first', [B, A]]] as const)(
912+
'CONTROL — action, %s: judged by its own bare judge, beta disabled serves alpha\'s, unchanged',
913+
async (_order, order) => {
914+
for (const id of order) registry.registerItem('action', bodyOf('action', id) as never, 'name' as never, id);
915+
registry.disablePackage(B);
916+
expect(await bareLabels('action')).toEqual([['no service copy', 'alpha action', 'alpha action'], [A, 'alpha action', 'alpha action'], [B, 'alpha action', 'alpha action']]);
917+
},
918+
);
919+
920+
it('CONTROL — no disabled holder: a view two enabled packages ship reads as before, the service\'s copy', async () => {
921+
for (const id of [A, B]) registry.registerItem('view', bodyOf('view', id) as never, 'name' as never, id);
922+
expect(labelOf(await protocolKeeping('view', B).getMetaItem({ type: 'view', name: 'shared' }))).toBe('beta view');
923+
expect(labelOf(await protocolKeeping('view', A).getMetaItem({ type: 'view', name: 'shared' }))).toBe('alpha view');
924+
});
925+
});
926+
833927
/**
834928
* [#31699 F2, the epic's ruling on the contract review] Two packages of one
835929
* App share the App's customization pair, so a locale Studio added there with

‎packages/rest/src/meta-item-history-routes.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1340,6 +1340,11 @@ export function registerMetaItemPublishedRoute(this: MetaItemPublishedRouteHost,
13401340
// read the protocol takes at that package's address,
13411341
// `servedHolderAddressOf`), and every registry holder of
13421342
// the name. Two served holders are refused above.
1343+
// [#34041, ADR-0150 D3] …and of every other type that read
1344+
// re-addresses (a `doc`, `view`, `translation`, …), all but
1345+
// an `action`, which its own bare judge serves: the
1346+
// metadata service keeps such a type by name alone, so its
1347+
// snapshot can be the disabled holder's body.
13431348
let mixedOwner: string | undefined;
13441349
let mixedHolders: readonly string[] = [];
13451350
if (publishedMetaType !== 'object' && publishedMetaType !== 'package'
@@ -1357,7 +1362,7 @@ export function registerMetaItemPublishedRoute(this: MetaItemPublishedRouteHost,
13571362
const owner = envelope?.packageId;
13581363
const ownerType = canonicalMetaUrlType(type);
13591364
if (!withheld && typeof owner === 'string' && typeof registry.packageScopedHoldersOf === 'function'
1360-
&& typeof registry.readsByPackage === 'function' && registry.readsByPackage(ownerType) === true) {
1365+
&& ownerType !== 'action') {
13611366
const holders: readonly string[] = registry.packageScopedHoldersOf(
13621367
ownerType, name, null, { includeDisabledPackages: true },
13631368
) ?? [];

‎packages/runtime/src/domains/meta-disabled-holder-artifact-door.test.ts‎

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,3 +331,66 @@ describe.each([
331331
await expectRefusedNamingBoth();
332332
});
333333
});
334+
335+
// [#34041, ADR-0150 D3] A disabled package holds no name, so beside one
336+
// enabled holder of a doc every bare door serves that holder's doc. The
337+
// artifact door's manager keeps a `doc` by name alone (the body registered
338+
// last), and the read naming no package was re-addressed to the served holder
339+
// only for a type the registry reads by package (`servedHolderAddressOf`), so
340+
// the service's copy, the disabled body's when it registered last, was the
341+
// layer read and then withheld. Measured on this rig before the fix
342+
// (origin/main 01598d93): with beta disabled and registered last, the plain
343+
// read, `/layers` and `/published` answered 404 on both transports.
344+
describe.each([
345+
{ order: 'the disabled holder registered last', packages: [ALPHA, BETA] },
346+
{ order: 'the disabled holder registered first', packages: [BETA, ALPHA] },
347+
])('[#34041] the bare doc doors beside one enabled and one disabled holder of one doc name, $order', ({ packages }) => {
348+
let booted: Booted | undefined;
349+
350+
beforeAll(async () => {
351+
booted = await bootArtifactKernel(packages, docBodyOf([ALPHA, BETA]));
352+
}, 120_000);
353+
354+
afterAll(async () => {
355+
if (!booted) return;
356+
if (booted.kernel.getState() === 'running') await booted.kernel.shutdown();
357+
rmSync(booted.root, { recursive: true, force: true });
358+
});
359+
360+
it('the fixture: the metadata service keeps the doc of the body registered last', async () => {
361+
const service = booted!.kernel.getService<MetadataManager>('metadata');
362+
expect((await service.get('doc', 'shared_doc') as { _packageId?: unknown } | undefined)?._packageId).toBe(packages[packages.length - 1]);
363+
});
364+
365+
it('beta disabled: the plain read, /layers and /published serve alpha\'s doc on both transports, never beta\'s', async () => {
366+
booted!.engine.registry.disablePackage(BETA);
367+
try {
368+
const answers = await bareDoors(booted!, 'doc', 'shared_doc');
369+
// Every door at once, so a red names each door that answered otherwise.
370+
expect(answers.map((answer) => [answer.door, answer.status, ...(answer.door.endsWith('/layers')
371+
? [answer.body?.code?.label, answer.body?.effective?.label]
372+
: [answer.body?.item?.label ?? answer.body?.label])]))
373+
.toEqual(answers.map((answer) => [answer.door, 200, ...(answer.door.endsWith('/layers') ? ['alpha doc', 'alpha doc'] : ['alpha doc'])]));
374+
for (const answer of answers) expect(JSON.stringify(answer.body ?? null), answer.door).not.toContain('# beta');
375+
} finally {
376+
booted!.engine.registry.enablePackage(BETA);
377+
}
378+
});
379+
380+
it('CONTROL: both disabled, every bare door answers 404; both enabled again, every bare door refuses 409 naming both', async () => {
381+
booted!.engine.registry.disablePackage(ALPHA);
382+
booted!.engine.registry.disablePackage(BETA);
383+
try {
384+
const answers = await bareDoors(booted!, 'doc', 'shared_doc');
385+
expect(answers.map((answer) => [answer.door, answer.status])).toEqual(answers.map((answer) => [answer.door, 404]));
386+
for (const answer of answers) expect(JSON.stringify(answer.body ?? null), answer.door).not.toMatch(/# (alpha|beta)/);
387+
} finally {
388+
booted!.engine.registry.enablePackage(ALPHA);
389+
booted!.engine.registry.enablePackage(BETA);
390+
}
391+
for (const answer of await bareDoors(booted!, 'doc', 'shared_doc')) {
392+
expect([answer.status, errorCodeOf(answer.body), answer.door], JSON.stringify(answer.body)).toEqual([409, 'RESOURCE_CONFLICT', answer.door]);
393+
for (const id of [ALPHA, BETA]) expect(JSON.stringify(answer.body ?? null), answer.door).toContain(id);
394+
}
395+
});
396+
});

‎packages/runtime/src/domains/meta.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1636,6 +1636,10 @@ export async function handleMetadataRequest(deps: DomainHandlerDeps, path: strin
16361636
// package's address, `servedHolderAddressOf`), and every registry
16371637
// holder of the name, as `RestServer`'s `/published` reads them. Two
16381638
// served holders are refused by the plain read.
1639+
// [#34041, ADR-0150 D3] …and of every other type that read re-addresses
1640+
// (a `doc`, `view`, `translation`, …), all but an `action`, which its
1641+
// own bare judge serves: the metadata service keeps such a type by name
1642+
// alone, so its snapshot can be the disabled holder's body.
16391643
let mixedOwner: string | undefined;
16401644
let mixedHolders: readonly string[] = [];
16411645
if (publishedType !== 'object' && publishedType !== 'package'
@@ -1652,7 +1656,7 @@ export async function handleMetadataRequest(deps: DomainHandlerDeps, path: strin
16521656
return { handled: true, response: deps.error('Not found', 404) };
16531657
}
16541658
if (typeof owner === 'string' && typeof registry.packageScopedHoldersOf === 'function'
1655-
&& typeof registry.readsByPackage === 'function' && registry.readsByPackage(publishedType) === true) {
1659+
&& publishedType !== 'action') {
16561660
const holders: readonly string[] = registry.packageScopedHoldersOf(
16571661
publishedType, name, null, { includeDisabledPackages: true },
16581662
) ?? [];

0 commit comments

Comments
 (0)