Skip to content
20 changes: 20 additions & 0 deletions .changeset/34041-disabled-holder-bare-read-every-type.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
'@objectstack/metadata-protocol': patch
'@objectstack/rest': patch
'@objectstack/runtime': patch
---

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

Clause-②: no
Metadata-protocol: none

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.

- The plain read answered `404` (the disabled body, withheld) although an enabled package ships the name. FROM `404`, TO the enabled holder's item.
- `/layers` served the disabled holder's body as `effective`. FROM that body, TO the enabled holder's item.
- `/published` answered `404` on both transports. FROM `404`, TO the enabled holder's item.

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.

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.
27 changes: 23 additions & 4 deletions packages/metadata-protocol/src/protocol-meta-item-face.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,8 @@ export async function packagelessRowWithheld(
/**
* [#32183] The package whose stack a read naming no package takes, for a
* name a disabled package also holds: the one holder ADR-0150 D3 resolves
* over the served set. `undefined` leaves the read as it was: a type the
* registry does not read by package, a name no disabled package holds (the
* over the served set. `undefined` leaves the read as it was: a type judged
* elsewhere ({@link SERVED_HOLDER_JUDGED_ELSEWHERE}), a name no disabled package holds (the
* read is `main`'s, untouched), the environment's own item (D3 (a) serves
* it), no served holder (the withheld arm of the face) or two or more (the
* read's own refusal).
Expand All @@ -225,10 +225,23 @@ export async function packagelessRowWithheld(
* holder's body while the by-name read served the enabled one. Shared by
* the face and the layered read, so both read one stack. Optional-called:
* a registry without these reads leaves every read as it was.
*
* [#34041, ADR-0150 D3] …and for a type the registry does not read by
* package (a `doc`, `view`, `translation`, `hook`, …) too: a disabled package
* holds no name of any type. Such a type's layers are the metadata service's
* copy, which it keeps by name alone (the body registered last), and the
* registry's first composite, so either one could be the disabled holder's.
* The face then withheld it, and the bare read answered 404 although an
* enabled package ships the name; `/layers` served the disabled body. Read at
* the served holder's address, the read is that holder's exact read, which
* never answers another package's copy (`serviceCopyOfAnotherPackage`).
* Not an `object` (one package owns the name; the face refuses a disabled
* package's) and not an `action` (judged over every holder by its own bare
* judge, `judgeBareActionRead`, which serves the one enabled holder already).
*/
export function servedHolderAddressOf(registry: any, type: string, name: string): string | undefined {
if (typeof registry?.readsByPackage !== 'function' || registry.readsByPackage(type) !== true) return undefined;
if (typeof registry.packageScopedHoldersOf !== 'function' || typeof registry.isPackageDisabled !== 'function') return undefined;
if (SERVED_HOLDER_JUDGED_ELSEWHERE.has(type)) return undefined;
if (typeof registry?.packageScopedHoldersOf !== 'function' || typeof registry.isPackageDisabled !== 'function') return undefined;
const every: readonly string[] = registry.packageScopedHoldersOf(type, name, null, { includeDisabledPackages: true }) ?? [];
if (!every.some((id) => registry.isPackageDisabled(id) === true)) return undefined;
const served: readonly string[] = registry.packageScopedHoldersOf(type, name, null) ?? [];
Expand All @@ -239,6 +252,12 @@ export function servedHolderAddressOf(registry: any, type: string, name: string)
return served[0];
}

/**
* [#34041] The types whose bare read {@link servedHolderAddressOf} never
* re-addresses: each is judged against a disabled package elsewhere.
*/
const SERVED_HOLDER_JUDGED_ELSEWHERE: ReadonlySet<string> = new Set(['object', 'action', 'package']);

/**
* [#32354, ADR-0150 D3] The served holder of a name for a read naming no
* package, judged over the stored rows too: what {@link servedHolderAddressOf}
Expand Down
94 changes: 94 additions & 0 deletions packages/objectql/src/package-scoped-exact-qualifier.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -830,6 +830,100 @@ describe('[#34040] the exact read never serves the service\'s copy of another pa
});
});

/**
* [#34041, ADR-0150 D3] A disabled package holds no name, of any type: beside
* one enabled holder, the read naming no package serves that holder's item, and
* so does `/layers`. For a type the registry does not read by package, the read
* reached the layer it reads by name alone (the service's copy, kept for the
* package registered last, else the registry's first composite) and the face
* withheld it when it was the disabled holder's.
*
* BASE (measured before the fix, origin/main 01598d93, this fixture): with
* beta disabled, every type below answered no item whenever that layer was
* beta's (the service keeping beta's copy, or no service copy and beta
* registered first), and `/layers` served beta's body as `effective`.
*/
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', () => {
const NOT_READ_BY_PACKAGE = MetadataTypeSchema.options.filter((type) => !(PACKAGE_SCOPED_READ_TYPES as readonly string[]).includes(type));
/** The security catalog keeps one package holder of these: a second holder is refused (the #34040 describe pins it). */
const ONE_HOLDER = ['position', 'capability'];
/** Judged against a disabled package by their own bare judges: the object's owner refusal, the action's `judgeBareActionRead`. */
const JUDGED_ELSEWHERE = ['object', 'action'];
const TWO_HOLDER = NOT_READ_BY_PACKAGE.filter((type) => !ONE_HOLDER.includes(type) && !JUDGED_ELSEWHERE.includes(type));

it('the enumeration: every type the registry does not read by package is pinned below, one-holder, or judged elsewhere', () => {
expect([...TWO_HOLDER].sort()).toEqual(
['assignment_rule', 'datasource', 'doc', 'external_catalog', 'field', 'hook', 'job', 'object_extension', 'queue', 'seed', 'sharing_rule', 'translation', 'view'],
);
});

const bodyOf = (type: string, packageId: string) => ({
name: 'shared', label: `${packageId.split('.').pop()} ${type}`, ...(type === 'action' ? { type: 'url', target: 'https://example.com' } : {}),
});
/** The protocol over this fixture's engine: no service, or a service keeping `kept`'s copy for every read. */
const protocolKeeping = (type: string, kept: string | undefined) => {
if (kept === undefined) return protocol;
const copy = { ...bodyOf(type, kept), _packageId: kept };
const metadata = { get: vi.fn(async () => copy), getDiagnosed: vi.fn(async () => ({ data: copy, degraded: false, errors: [] })) };
return new ObjectStackProtocolImplementation(engine as never, () => new Map<string, unknown>([['metadata', metadata]]));
};
/** The plain read's and `/layers`' labels, for each service state: none, alpha's copy, beta's copy. */
const bareLabels = async (type: string) => {
const seen: Array<[string, unknown, unknown]> = [];
for (const kept of [undefined, A, B]) {
const served = protocolKeeping(type, kept);
const plain = labelOf(await served.getMetaItem({ type, name: 'shared' }));
const layered = ((await served.getMetaItemLayered({ type, name: 'shared' })) as { effective?: { label?: string } }).effective?.label;
seen.push([kept ?? 'no service copy', plain, layered]);
}
return seen;
};

it.each(TWO_HOLDER.flatMap((type) => [[type, 'beta registered last', [A, B]], [type, 'beta registered first', [B, A]]] as const))(
'%s, %s: beta disabled, the plain read and /layers serve alpha\'s item whichever layer holds beta\'s; both disabled, no item',
async (type, _order, order) => {
for (const id of order) registry.registerItem(type, bodyOf(type, id) as never, 'name' as never, id);
registry.disablePackage(B);
const alpha = `alpha ${type}`;
expect(await bareLabels(type)).toEqual([['no service copy', alpha, alpha], [A, alpha, alpha], [B, alpha, alpha]]);
// CONTROL: no enabled holder, no served holder: the withheld item, as before.
registry.disablePackage(A);
expect(labelOf(await protocolKeeping(type, B).getMetaItem({ type, name: 'shared' })), `${type}, both disabled`).toBeUndefined();
},
);

it.each([['beta registered last', [A, B]], ['beta registered first', [B, A]]] as const)(
'CONTROL — doc, %s: two enabled holders are refused 409 naming both, before and after beta is disabled and enabled again',
async (_order, order) => {
for (const id of order) registry.registerItem('doc', bodyOf('doc', id) as never, 'name' as never, id);
const expectRefused = async () => {
const err = await refusalOf(() => protocolKeeping('doc', order[1]).getMetaItem({ type: 'doc', name: 'shared' }));
expect([err.code, err.status, [...err.refusal.candidates].map((c) => (c as { packageId?: string }).packageId).sort()]).toEqual(['RESOURCE_CONFLICT', 409, [A, B]]);
};
await expectRefused();
registry.disablePackage(B);
expect(labelOf(await protocolKeeping('doc', B).getMetaItem({ type: 'doc', name: 'shared' }))).toBe('alpha doc');
registry.enablePackage(B);
await expectRefused();
},
);

it.each([['beta registered last', [A, B]], ['beta registered first', [B, A]]] as const)(
'CONTROL — action, %s: judged by its own bare judge, beta disabled serves alpha\'s, unchanged',
async (_order, order) => {
for (const id of order) registry.registerItem('action', bodyOf('action', id) as never, 'name' as never, id);
registry.disablePackage(B);
expect(await bareLabels('action')).toEqual([['no service copy', 'alpha action', 'alpha action'], [A, 'alpha action', 'alpha action'], [B, 'alpha action', 'alpha action']]);
},
);

it('CONTROL — no disabled holder: a view two enabled packages ship reads as before, the service\'s copy', async () => {
for (const id of [A, B]) registry.registerItem('view', bodyOf('view', id) as never, 'name' as never, id);
expect(labelOf(await protocolKeeping('view', B).getMetaItem({ type: 'view', name: 'shared' }))).toBe('beta view');
expect(labelOf(await protocolKeeping('view', A).getMetaItem({ type: 'view', name: 'shared' }))).toBe('alpha view');
});
});

/**
* [#31699 F2, the epic's ruling on the contract review] Two packages of one
* App share the App's customization pair, so a locale Studio added there with
Expand Down
7 changes: 6 additions & 1 deletion packages/rest/src/meta-item-history-routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1340,6 +1340,11 @@ export function registerMetaItemPublishedRoute(this: MetaItemPublishedRouteHost,
// read the protocol takes at that package's address,
// `servedHolderAddressOf`), and every registry holder of
// the name. Two served holders are refused above.
// [#34041, ADR-0150 D3] …and of every other type that read
// re-addresses (a `doc`, `view`, `translation`, …), all but
// an `action`, which its own bare judge serves: the
// metadata service keeps such a type by name alone, so its
// snapshot can be the disabled holder's body.
let mixedOwner: string | undefined;
let mixedHolders: readonly string[] = [];
if (publishedMetaType !== 'object' && publishedMetaType !== 'package'
Expand All @@ -1357,7 +1362,7 @@ export function registerMetaItemPublishedRoute(this: MetaItemPublishedRouteHost,
const owner = envelope?.packageId;
const ownerType = canonicalMetaUrlType(type);
if (!withheld && typeof owner === 'string' && typeof registry.packageScopedHoldersOf === 'function'
&& typeof registry.readsByPackage === 'function' && registry.readsByPackage(ownerType) === true) {
&& ownerType !== 'action') {
const holders: readonly string[] = registry.packageScopedHoldersOf(
ownerType, name, null, { includeDisabledPackages: true },
) ?? [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -331,3 +331,66 @@ describe.each([
await expectRefusedNamingBoth();
});
});

// [#34041, ADR-0150 D3] A disabled package holds no name, so beside one
// enabled holder of a doc every bare door serves that holder's doc. The
// artifact door's manager keeps a `doc` by name alone (the body registered
// last), and the read naming no package was re-addressed to the served holder
// only for a type the registry reads by package (`servedHolderAddressOf`), so
// the service's copy, the disabled body's when it registered last, was the
// layer read and then withheld. Measured on this rig before the fix
// (origin/main 01598d93): with beta disabled and registered last, the plain
// read, `/layers` and `/published` answered 404 on both transports.
describe.each([
{ order: 'the disabled holder registered last', packages: [ALPHA, BETA] },
{ order: 'the disabled holder registered first', packages: [BETA, ALPHA] },
])('[#34041] the bare doc doors beside one enabled and one disabled holder of one doc name, $order', ({ packages }) => {
let booted: Booted | undefined;

beforeAll(async () => {
booted = await bootArtifactKernel(packages, docBodyOf([ALPHA, BETA]));
}, 120_000);

afterAll(async () => {
if (!booted) return;
if (booted.kernel.getState() === 'running') await booted.kernel.shutdown();
rmSync(booted.root, { recursive: true, force: true });
});

it('the fixture: the metadata service keeps the doc of the body registered last', async () => {
const service = booted!.kernel.getService<MetadataManager>('metadata');
expect((await service.get('doc', 'shared_doc') as { _packageId?: unknown } | undefined)?._packageId).toBe(packages[packages.length - 1]);
});

it('beta disabled: the plain read, /layers and /published serve alpha\'s doc on both transports, never beta\'s', async () => {
booted!.engine.registry.disablePackage(BETA);
try {
const answers = await bareDoors(booted!, 'doc', 'shared_doc');
// Every door at once, so a red names each door that answered otherwise.
expect(answers.map((answer) => [answer.door, answer.status, ...(answer.door.endsWith('/layers')
? [answer.body?.code?.label, answer.body?.effective?.label]
: [answer.body?.item?.label ?? answer.body?.label])]))
.toEqual(answers.map((answer) => [answer.door, 200, ...(answer.door.endsWith('/layers') ? ['alpha doc', 'alpha doc'] : ['alpha doc'])]));
for (const answer of answers) expect(JSON.stringify(answer.body ?? null), answer.door).not.toContain('# beta');
} finally {
booted!.engine.registry.enablePackage(BETA);
}
});

it('CONTROL: both disabled, every bare door answers 404; both enabled again, every bare door refuses 409 naming both', async () => {
booted!.engine.registry.disablePackage(ALPHA);
booted!.engine.registry.disablePackage(BETA);
try {
const answers = await bareDoors(booted!, 'doc', 'shared_doc');
expect(answers.map((answer) => [answer.door, answer.status])).toEqual(answers.map((answer) => [answer.door, 404]));
for (const answer of answers) expect(JSON.stringify(answer.body ?? null), answer.door).not.toMatch(/# (alpha|beta)/);
} finally {
booted!.engine.registry.enablePackage(ALPHA);
booted!.engine.registry.enablePackage(BETA);
}
for (const answer of await bareDoors(booted!, 'doc', 'shared_doc')) {
expect([answer.status, errorCodeOf(answer.body), answer.door], JSON.stringify(answer.body)).toEqual([409, 'RESOURCE_CONFLICT', answer.door]);
for (const id of [ALPHA, BETA]) expect(JSON.stringify(answer.body ?? null), answer.door).toContain(id);
}
});
});
6 changes: 5 additions & 1 deletion packages/runtime/src/domains/meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1636,6 +1636,10 @@ export async function handleMetadataRequest(deps: DomainHandlerDeps, path: strin
// package's address, `servedHolderAddressOf`), and every registry
// holder of the name, as `RestServer`'s `/published` reads them. Two
// served holders are refused by the plain read.
// [#34041, ADR-0150 D3] …and of every other type that read re-addresses
// (a `doc`, `view`, `translation`, …), all but an `action`, which its
// own bare judge serves: the metadata service keeps such a type by name
// alone, so its snapshot can be the disabled holder's body.
let mixedOwner: string | undefined;
let mixedHolders: readonly string[] = [];
if (publishedType !== 'object' && publishedType !== 'package'
Expand All @@ -1652,7 +1656,7 @@ export async function handleMetadataRequest(deps: DomainHandlerDeps, path: strin
return { handled: true, response: deps.error('Not found', 404) };
}
if (typeof owner === 'string' && typeof registry.packageScopedHoldersOf === 'function'
&& typeof registry.readsByPackage === 'function' && registry.readsByPackage(publishedType) === true) {
&& publishedType !== 'action') {
const holders: readonly string[] = registry.packageScopedHoldersOf(
publishedType, name, null, { includeDisabledPackages: true },
) ?? [];
Expand Down
Loading