Skip to content

Commit 0571f19

Browse files
committed
fix(metadata-protocol, rest): every /layers refusal of a name several packages hold carries details.candidates (ADR-0150 D5)
The REST /meta/:type/:name/layers catch now asks handleRouteError for the package-scoped candidates, as the plain read's catch does, so the plain read's refusal the door's owner step answers and the served-holders refusal of step 1c carry details.candidates on RestServer as on the dispatcher. The step-1c refusal of a name whose active rows two packages hold (the package-less writes' sentence, code and status, unchanged) now carries its holders by shape as a package-scoped refusal, so both transports answer them as details.candidates. The save and delete doors' answer does not move. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QsR2jTkZnXtRhuEiiyidvJ
1 parent a557fa3 commit 0571f19

8 files changed

Lines changed: 88 additions & 19 deletions

‎packages/metadata-protocol/src/protocol-meta-layered-reads.ts‎

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,44 @@ export async function packagelessLayeredReadRefusal(host: Pick<ProtocolHost, 'de
103103
if (judged !== undefined) return undefined;
104104
const address = await host.packagelessAddress(PLURAL_TO_SINGULAR[type] ?? type, name, member);
105105
return address.candidates.length > 1
106-
? packagelessAddressAmbiguityRefusal('layered read', type, name, address.candidates)
106+
? withPackageCandidates(
107+
packagelessAddressAmbiguityRefusal('layered read', type, name, address.candidates),
108+
PLURAL_TO_SINGULAR[type] ?? type, name, address.candidates,
109+
)
107110
: undefined;
108111
}
109112

113+
/**
114+
* [#32622, ADR-0150 D5] The package-less writes' refusal, as the layered door
115+
* answers it (#28337: its sentence, code, status and `?package=` remedy,
116+
* unchanged), with the holders it names carried as a package-scoped refusal's
117+
* `refusal.candidates` (`[{ kind: 'package', packageId }, …]`, the `/actions`
118+
* shape), so each transport answers them as `details.candidates`, as for every
119+
* other `/layers` refusal. Carried by SHAPE (`refusal.status: 'refused'`),
120+
* which the one recogniser reads (`packageScopedRefusalCandidates` in
121+
* `@objectstack/types`), because the type this refusal judges need not be one
122+
* the package-scoped resolver covers. The save and delete doors' answer of
123+
* the same rows does not move.
124+
*/
125+
function withPackageCandidates(
126+
error: Error & { code: 'RESOURCE_CONFLICT'; status: 409 },
127+
type: string,
128+
name: string,
129+
packageIds: readonly string[],
130+
): Error & { code: 'RESOURCE_CONFLICT'; status: 409 } {
131+
return Object.assign(error, {
132+
refusal: {
133+
status: 'refused' as const,
134+
reason: 'ambiguous-in-environment' as const,
135+
type,
136+
name,
137+
callerPackageId: null,
138+
candidates: packageIds.map((packageId) => ({ kind: 'package' as const, packageId })),
139+
message: error.message,
140+
},
141+
});
142+
}
143+
110144
/** The body of `ObjectStackProtocolImplementation#getMetaItemLayered`; the method's docblock there is its contract. */
111145
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: {
112146
type: string;

‎packages/metadata-protocol/src/protocol.packageless-layered-read-refusal.test.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,14 @@ describe('[#28337] packagelessLayeredReadRefusal', () => {
139139
);
140140
// The holder list is the save's, sorted.
141141
expect(saveRefusal.message).toContain(`('${PKG_A}', '${PKG_B}')`);
142+
// [#32622, ADR-0150 D5] …and carried as the package-scoped refusal's
143+
// candidates, which each door answers as `details.candidates`.
144+
expect((refusal as any).refusal?.status).toBe('refused');
145+
expect((refusal as any).refusal?.candidates).toEqual([
146+
{ kind: 'package', packageId: PKG_A },
147+
{ kind: 'package', packageId: PKG_B },
148+
]);
149+
expect(saveRefusal.refusal, 'the save\'s answer does not move').toBeUndefined();
142150
// The plural URL spelling is the same item.
143151
expect((await protocol.packagelessLayeredReadRefusal({ type: 'dashboards', name: 'twin_dash' }))?.message)
144152
.toBe(refusal!.message);

‎packages/rest/src/meta-disabled-package-doors.test.ts‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -569,10 +569,11 @@ describe('[#32354] RestServer: stored rows judged over the served set', () => {
569569
expect([read.status, read.body?.code], JSON.stringify(read.body)).toEqual([409, 'RESOURCE_CONFLICT']);
570570
expect([...(read.body?.details?.candidates ?? [])].map((c: any) => c.packageId).sort(), JSON.stringify(read.body))
571571
.toEqual([OTHER_PKG, THIRD_PKG].sort());
572-
// The layered door answers a package-scoped refusal by its sentence alone, as for two registry holders (#32622).
572+
// [#32622, ADR-0150 D5] The layered door names the same served holders as `details.candidates`.
573573
const layers = await host.layers('dashboard', 'three_rows_dash');
574-
expect(layers.status, JSON.stringify(layers.body)).toBe(409);
575-
for (const pkg of [OTHER_PKG, THIRD_PKG]) expect(JSON.stringify(layers.body)).toContain(pkg);
574+
expect([layers.status, layers.body?.code], JSON.stringify(layers.body)).toEqual([409, 'RESOURCE_CONFLICT']);
575+
expect([...(layers.body?.details?.candidates ?? [])].map((c: any) => c.packageId).sort(), JSON.stringify(layers.body))
576+
.toEqual([OTHER_PKG, THIRD_PKG].sort());
576577
// [contract review S3] Bare /published asks the plain read first and answers its refusal.
577578
const published = await host.published('dashboard', 'three_rows_dash');
578579
expect([published.status, published.body?.code ?? published.body?.error?.code], JSON.stringify(published.body))

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,12 @@ export function registerMetaItemReadRoutes(this: MetaItemReadRouteHost, scope: M
366366
}
367367
await this.serveMetaItemLayered(req, res, environmentId, p, maskPosture);
368368
} catch (error: any) {
369-
handleRouteError(res, error);
369+
// [#32622, ADR-0150 D5] A package-scoped refusal of the
370+
// layered read carries its holders as `details.candidates`,
371+
// as the plain read's catch answers it (#32201) and the
372+
// deprecated `?layers=` spelling, which that catch serves,
373+
// already did; anything else answers as before.
374+
handleRouteError(res, error, undefined, { packageScopedCandidates: true });
370375
}
371376
},
372377
metadata: {

‎packages/rest/src/meta-layers-ambiguous-package.test.ts‎

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,11 @@ const matchesWhere = (row: Record<string, unknown>, where: Record<string, unknow
4545
return whereValueMatches(row[k], v);
4646
});
4747

48-
/** In-memory `sys_metadata` carrying a REAL `SchemaRegistry`. */
49-
function makeHarness() {
48+
/**
49+
* In-memory `sys_metadata` carrying a REAL `SchemaRegistry`. `services`: the
50+
* kernel services the protocol reads (a `metadata` service copy), none by default.
51+
*/
52+
function makeHarness(services?: Map<string, unknown>) {
5053
const registry = new SchemaRegistry({ multiTenant: false });
5154
(registry as any).logLevel = 'silent';
5255
const rows = new Map<string, any>();
@@ -93,7 +96,7 @@ function makeHarness() {
9396
},
9497
async syncObjectSchema() { /* no physical storage in this double */ },
9598
};
96-
const protocol = new ObjectStackProtocolImplementation(engine, undefined, 'env_test');
99+
const protocol = new ObjectStackProtocolImplementation(engine, services ? () => services as Map<string, any> : undefined, 'env_test');
97100
return { protocol, registry, rows };
98101
}
99102

@@ -173,8 +176,14 @@ describe('[#28337] RestServer: the layered view of a name two packages hold, nam
173176
for (const read of [host.layers, host.layersFlag]) {
174177
const refused = await read('twin_dash');
175178
expect({ status: refused.status, code: codeOf(refused) }).toEqual({ status: save.status, code: codeOf(save) });
176-
// One envelope shape for the read and the writes on this transport.
177-
expect(Object.keys(refused.body ?? {}).sort()).toEqual(Object.keys(save.body ?? {}).sort());
179+
// One envelope shape for the read and the writes on this transport, and
180+
// [#32622, ADR-0150 D5] the read's holders as `details.candidates` beside it.
181+
expect(Object.keys(refused.body ?? {}).sort()).toEqual([...Object.keys(save.body ?? {}), 'details'].sort());
182+
expect(refused.body?.details?.candidates).toEqual([
183+
{ kind: 'package', packageId: PKG_A },
184+
{ kind: 'package', packageId: PKG_B },
185+
]);
186+
expect(save.body?.details, 'the writes\' answer does not move').toBeUndefined();
178187
const message = messageOf(refused);
179188
expect(message.startsWith('Name the package this layered read is for, then send it again')).toBe(true);
180189
expect(message).toContain('?package=');
@@ -211,3 +220,4 @@ describe('[#28337] RestServer: the layered view of a name two packages hold, nam
211220
}
212221
}, 60_000);
213222
});
223+

‎packages/runtime/src/domains/meta-disabled-holder-served-stack.test.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,10 +285,11 @@ describe.each([
285285
expect([read.status, codeOf(read.body)], JSON.stringify(read.body)).toEqual([409, 'RESOURCE_CONFLICT']);
286286
expect([...(read.body?.error?.details?.candidates ?? [])].map((c: any) => c.packageId).sort(), JSON.stringify(read.body))
287287
.toEqual([ROW_E, ROW_F].sort());
288-
// The layered door answers a package-scoped refusal by its sentence alone, as for two registry holders (#32622).
288+
// [#32622, ADR-0150 D5] The layered door names the same served holders as `details.candidates`.
289289
const layers = await get(booted.kernel, '/meta/dashboard/three_rows_dash/layers');
290290
expect([layers.status, codeOf(layers.body)], JSON.stringify(layers.body)).toEqual([409, 'RESOURCE_CONFLICT']);
291-
for (const id of [ROW_E, ROW_F]) expect(JSON.stringify(layers.body)).toContain(id);
291+
expect([...(layers.body?.error?.details?.candidates ?? [])].map((c: any) => c.packageId).sort(), JSON.stringify(layers.body))
292+
.toEqual([ROW_E, ROW_F].sort());
292293
// [contract review S3] Bare /published asks the plain read first and answers its refusal.
293294
const published = await get(booted.kernel, '/meta/dashboard/three_rows_dash/published');
294295
expect([published.status, codeOf(published.body)], JSON.stringify(published.body)).toEqual([409, 'RESOURCE_CONFLICT']);

‎packages/runtime/src/domains/meta-layers-ambiguous-package.test.ts‎

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -204,12 +204,20 @@ for (const [doorName, boot] of DOORS) {
204204
const read = await door.send('GET', path, query);
205205
expect([read.status, codeOf(read.body)], `${spelling}: ${JSON.stringify(read.body)}`)
206206
.toEqual([save.status, codeOf(save.body)]);
207-
// The same envelope this door wraps the writes' refusal in.
207+
// The same envelope this door wraps the writes' refusal in, and
208+
// [#32622, ADR-0150 D5] the read's holders as `details.candidates`
209+
// where this door's envelope carries the refusal's fields.
208210
const keys = (b: any) => Object.keys(b ?? {}).sort();
209-
expect(keys(read.body), spelling).toEqual(keys(save.body));
210-
if (read.body?.error && typeof read.body.error === 'object') {
211-
expect(keys(read.body.error), spelling).toEqual(keys(save.body.error));
212-
}
211+
const withDetails = (b: any) => [...Object.keys(b ?? {}), 'details'].sort();
212+
const nested = read.body?.error && typeof read.body.error === 'object';
213+
expect(keys(read.body), spelling).toEqual(nested ? keys(save.body) : withDetails(save.body));
214+
if (nested) expect(keys(read.body.error), spelling).toEqual(withDetails(save.body.error));
215+
const fields = nested ? read.body.error : read.body;
216+
expect(fields?.details?.candidates, spelling).toEqual([
217+
{ kind: 'package', packageId: PKG_A },
218+
{ kind: 'package', packageId: PKG_B },
219+
]);
220+
expect((nested ? save.body.error : save.body)?.details, `${spelling}: the writes' answer does not move`).toBeUndefined();
213221
const message = messageOf(read.body);
214222
expect(message.startsWith('Name the package this layered read is for, then send it again'), message).toBe(true);
215223
expect(message, spelling).toContain('?package=');

‎packages/runtime/src/domains/meta-qualified-item-read.test.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -872,8 +872,10 @@ describe('#32183 × #32310 — the caller arm judges the served holders', () =>
872872
* two packages register answers the read's `409 RESOURCE_CONFLICT` naming both
873873
* holders as `details.candidates`, as the item read does. The refusal leaves
874874
* through `errorFromThrown`, which composes `details` from
875-
* `resolveThrownHttpError`. Only this cell of #32622 is covered here: a stored
876-
* row's layered refusal, and the REST `/layers` door, are not.
875+
* `resolveThrownHttpError`. This is the dispatcher's registry-holder cell; the
876+
* stored-row cells and the REST `/layers` door are pinned beside the #28337
877+
* and #32354 pins (`meta-layers-ambiguous-package.test.ts`,
878+
* `meta-disabled-holder-served-stack.test.ts` and their REST twins).
877879
*/
878880
describe('#32250 — the dispatcher /layers 409 names the holders', () => {
879881
it('a name two packages register: 409 RESOURCE_CONFLICT with both as details.candidates', async () => {

0 commit comments

Comments
 (0)