Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions .changeset/32622-layers-two-holders-candidates.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
'@objectstack/metadata-protocol': patch
'@objectstack/rest': patch
---

fix(metadata-protocol, rest)!: the layered read of a name two packages hold refuses as the plain read does, naming the holders as `details.candidates` (ADR-0150 D3/D5)

Clause-②: no (narrowing)
Metadata-protocol: none

<!-- adr-0087: not-required (no-migration-prescription) No key of any schema is added, removed, renamed or re-shaped, and no export changes shape. The moved answers are reads of a name two packages hold, which now refuse as the plain read of that name already did: no stored row, layer, registry key or authored value changes, so there is nothing for a migration to rewrite and no tombstone. -->

**BREAKING** for a reader of the layers, or of the REST published view, of a name two or more served packages register in code, naming no package. Such a name has no one holder (ADR-0150 D3/D5), and the plain read already refused it. Three answers move, measured in both registration orders:

- FROM: on a host that wires no engine for the REST door chain, `GET /meta/:type/:name/layers` (and `?layers=true`) answered 200 with the layers of the holder that registered first. TO: it answers `409 RESOURCE_CONFLICT` naming both holders as `details.candidates`.
- FROM: in process, the protocol's `getMetaItemLayered({ type, name })` with no `packageId` resolved the holder that registered first. TO: it throws `PackageScopedNameRefusedError` (`RESOURCE_CONFLICT`, 409) naming both, as `getMetaItem` does.
- FROM: on a REST host with no `objectQLProvider`, `GET /meta/:type/:name/published` served the name's package-unbound active row (200) when one stands. With no such row, it went on past its overlay read to the published exit: what the host's metadata service `getPublished` answers, or `501 NOT_IMPLEMENTED` when the host resolves no metadata service. TO: it answers `409 RESOURCE_CONFLICT`, without `details.candidates`. The dispatcher's `/published`, where its engine registry is not reachable, swallows the same refusal. With no such row it serves its snapshot as before. With one, it served that row and now serves the code snapshot instead.

**Not moved.** A name one package holds, and every read naming the package (`?package=`, `packageId`), answer as before. On a host whose door chain has an engine, `/layers` already refused 409; it now also names the holders. The save and delete doors do not move.

The fix for a caller: name the package whose layers it means.

`GET /meta/:type/:name/layers` (and the deprecated `?layers=true`) of a name two or more packages hold, read naming no package, now answers like the plain read on every exit and on both transports: `409 RESOURCE_CONFLICT` with the holders as `details.candidates` (`[{ kind: 'package', packageId }, …]`), never one holder's layers.

- A name two served packages register in code: the protocol's layered read (`getMetaItemLayered`) asks the registry's package-scoped resolver before it reads any layer, as `getMetaItem` does, so it throws the same `PackageScopedNameRefusedError` naming both, in process too, whatever the metadata service holds. It used to answer the holder that registered first, and so did the REST door on a host that wires no engine for its door chain. `?package=` still reads each holder's layers; a name one package holds is unchanged.
- The REST `/layers` route's catch carries the candidates of a package-scoped refusal, as the plain read's catch does. Before, it answered the refusal by its sentence alone (the dispatcher already carried them).
- A name whose active rows two packages hold keeps the package-less writes' refusal (its sentence, code, status and `?package=` remedy) and gains the same `details.candidates`. The save and delete doors' answer does not move.
- Stored-row holders beside a disabled package keep their in-process answer: the protocol's layered read still serves its in-process readers there, and the door refuses.
51 changes: 50 additions & 1 deletion packages/metadata-protocol/src/protocol-meta-layered-reads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,44 @@ export async function packagelessLayeredReadRefusal(host: Pick<ProtocolHost, 'de
if (judged !== undefined) return undefined;
const address = await host.packagelessAddress(PLURAL_TO_SINGULAR[type] ?? type, name, member);
return address.candidates.length > 1
? packagelessAddressAmbiguityRefusal('layered read', type, name, address.candidates)
? withPackageCandidates(
packagelessAddressAmbiguityRefusal('layered read', type, name, address.candidates),
PLURAL_TO_SINGULAR[type] ?? type, name, address.candidates,
)
: undefined;
}

/**
* [#32622, ADR-0150 D5] The package-less writes' refusal, as the layered door
* answers it (#28337: its sentence, code, status and `?package=` remedy,
* unchanged), with the holders it names carried as a package-scoped refusal's
* `refusal.candidates` (`[{ kind: 'package', packageId }, …]`, the `/actions`
* shape), so each transport answers them as `details.candidates`, as for every
* other `/layers` refusal. Carried by SHAPE (`refusal.status: 'refused'`),
* which the one recogniser reads (`packageScopedRefusalCandidates` in
* `@objectstack/types`), because the type this refusal judges need not be one
* the package-scoped resolver covers. The save and delete doors' answer of
* the same rows does not move.
*/
function withPackageCandidates(
error: Error & { code: 'RESOURCE_CONFLICT'; status: 409 },
type: string,
name: string,
packageIds: readonly string[],
): Error & { code: 'RESOURCE_CONFLICT'; status: 409 } {
return Object.assign(error, {
refusal: {
status: 'refused' as const,
reason: 'ambiguous-in-environment' as const,
type,
name,
callerPackageId: null,
candidates: packageIds.map((packageId) => ({ kind: 'package' as const, packageId })),
message: error.message,
},
});
}

/** The body of `ObjectStackProtocolImplementation#getMetaItemLayered`; the method's docblock there is its contract. */
export async function getMetaItemLayered(host: Pick<ProtocolHost, 'artifactLockLayerAt' | 'convertStoredItem' | 'declinesStoredRow' | 'engine' | 'findPairAddedMemberRow' | 'findServedOverlayRow' | 'foldObjectExtendersFromRegistry' | 'getServicesRegistry' | 'governServedObject' | 'isArtifactBacked' | 'isStoredEntryOfDeclinedName' | 'lookupArtifactItem' | 'overlayLockLayerAt' | 'packagelessAddress' | 'packagelessReadAddress' | 'shippedArtifactsOf' | 'readItemActiveRows' | 'readItemFromMetadataService' | 'resolveRowlessExpandedView' | 'resolveWritePackageScope' | 'rethrowUnlessMetadataStoreUnprovisioned' | 'servedLockState' | 'strictDraftReadAddress' | 'throwMetadataServiceUnavailable'>, request: {
type: string;
Expand Down Expand Up @@ -216,6 +250,21 @@ export async function getMetaItemLayered(host: Pick<ProtocolHost, 'artifactLockL
? await judgeBareActionRead(host, request.name)
: undefined;
const exactAddress = await admitExactQualifier(host, { type: request.type, name: request.name, packageId: request.packageId, member });
// [ADR-0150 D3, #32914] …and, naming no package, a type addressed by
// package is judged by the registry's package-scoped resolver, as the
// plain read judges it ({@link getMetaItem}, its `packagelessScopedRead`):
// a name two or more served packages hold is refused naming each
// (`PackageScopedNameRefusedError`, `409 RESOURCE_CONFLICT` with its
// candidates), before any layer is read and whatever the metadata service
// holds. The code layer below otherwise fell back to the artifact lookup's
// first composite, so the read answered the holder that registered first.
// Asked for the judgment only: a name one holder holds keeps the layers
// below as they were. [contract review S1] Stored-row holders are not
// this judgment's: the door refuses them through
// {@link packagelessLayeredReadRefusal}, its step 1c.
if (!request.packageId && host.engine?.registry?.readsByPackage?.(request.type) === true) {
host.engine.registry.resolveItem(request.type, request.name, null, member);
}

// [ADR-0131 D6] Environment → code: the overlay layer is the
// environment's stored row; no organization's row is read.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,14 @@ describe('[#28337] packagelessLayeredReadRefusal', () => {
);
// The holder list is the save's, sorted.
expect(saveRefusal.message).toContain(`('${PKG_A}', '${PKG_B}')`);
// [#32622, ADR-0150 D5] …and carried as the package-scoped refusal's
// candidates, which each door answers as `details.candidates`.
expect((refusal as any).refusal?.status).toBe('refused');
expect((refusal as any).refusal?.candidates).toEqual([
{ kind: 'package', packageId: PKG_A },
{ kind: 'package', packageId: PKG_B },
]);
expect(saveRefusal.refusal, 'the save\'s answer does not move').toBeUndefined();
// The plural URL spelling is the same item.
expect((await protocol.packagelessLayeredReadRefusal({ type: 'dashboards', name: 'twin_dash' }))?.message)
.toBe(refusal!.message);
Expand Down
13 changes: 11 additions & 2 deletions packages/metadata-protocol/src/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4210,7 +4210,9 @@ export class ObjectStackProtocolImplementation implements
* `409 RESOURCE_CONFLICT`, the holders sorted and the `?package=`
* prescription), asked of the same resolution
* ({@link packagelessAddress} at `active`, at the addressed bundle member,
* read in full): one answer to one ambiguity. `undefined` for a name one
* read in full): one answer to one ambiguity. [#32622] It also carries
* its holders as a package-scoped refusal (`refusal.candidates`), so both
* transports answer them as `details.candidates`. `undefined` for a name one
* package holds, none does, or only the package-unbound row does, and for
* every request that names a package (the caller asks only without one).
*
Expand All @@ -4224,7 +4226,10 @@ export class ObjectStackProtocolImplementation implements
* `createMetaLayeredAnswer`), ⛔ never inside {@link getMetaItemLayered}:
* its in-process resolution readers (the security catalog echo, the
* packaged-permission-set lock gate, `/published`) read the layers of a
* name with no package and keep the answer they had.
* name with no package and keep the answer they had. [#32914] Those
* readers do meet the registry's own refusal of a name two packages
* register in code, which {@link getMetaItemLayered} asks as
* `getMetaItem` does.
*
* [#32354, ADR-0150 D3] While a package is disabled, a name the stored
* rows of two or more served packages hold beside it is refused here
Expand Down Expand Up @@ -4289,6 +4294,10 @@ export class ObjectStackProtocolImplementation implements
* layer's MetadataService read reporting `degraded` with nothing
* in the registry to answer instead, carrying the failing loaders'
* messages on `cause`.
* @throws `PackageScopedNameRefusedError` — [#32914, ADR-0150 D3/D5] 409 /
* `RESOURCE_CONFLICT`, naming no package, for a name two or more
* served packages register in code: the registry's own refusal, as
* {@link getMetaItem} throws it, before any layer is read.
*
* [#29814] `opts.withDraft` adds the `draft` layer
* (`GetMetaItemLayeredResponseSchema.draft`): the pending draft row the
Expand Down
7 changes: 4 additions & 3 deletions packages/rest/src/meta-disabled-package-doors.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -569,10 +569,11 @@ describe('[#32354] RestServer: stored rows judged over the served set', () => {
expect([read.status, read.body?.code], JSON.stringify(read.body)).toEqual([409, 'RESOURCE_CONFLICT']);
expect([...(read.body?.details?.candidates ?? [])].map((c: any) => c.packageId).sort(), JSON.stringify(read.body))
.toEqual([OTHER_PKG, THIRD_PKG].sort());
// The layered door answers a package-scoped refusal by its sentence alone, as for two registry holders (#32622).
// [#32622, ADR-0150 D5] The layered door names the same served holders as `details.candidates`.
const layers = await host.layers('dashboard', 'three_rows_dash');
expect(layers.status, JSON.stringify(layers.body)).toBe(409);
for (const pkg of [OTHER_PKG, THIRD_PKG]) expect(JSON.stringify(layers.body)).toContain(pkg);
expect([layers.status, layers.body?.code], JSON.stringify(layers.body)).toEqual([409, 'RESOURCE_CONFLICT']);
expect([...(layers.body?.details?.candidates ?? [])].map((c: any) => c.packageId).sort(), JSON.stringify(layers.body))
.toEqual([OTHER_PKG, THIRD_PKG].sort());
// [contract review S3] Bare /published asks the plain read first and answers its refusal.
const published = await host.published('dashboard', 'three_rows_dash');
expect([published.status, published.body?.code ?? published.body?.error?.code], JSON.stringify(published.body))
Expand Down
7 changes: 6 additions & 1 deletion packages/rest/src/meta-item-read-routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,12 @@ export function registerMetaItemReadRoutes(this: MetaItemReadRouteHost, scope: M
}
await this.serveMetaItemLayered(req, res, environmentId, p, maskPosture);
} catch (error: any) {
handleRouteError(res, error);
// [#32622, ADR-0150 D5] A package-scoped refusal of the
// layered read carries its holders as `details.candidates`,
// as the plain read's catch answers it (#32201) and the
// deprecated `?layers=` spelling, which that catch serves,
// already did; anything else answers as before.
handleRouteError(res, error, undefined, { packageScopedCandidates: true });
}
},
metadata: {
Expand Down
Loading
Loading