Skip to content

Commit 7e15ab7

Browse files
committed
fix(metadata-protocol): a listed seed's diagnostics judge the body as its row stores it
The list now serves a seed carrying its row's name, which SeedSchema does not declare, so the served-face decoration flagged every listed seed as invalid on a real boot. A body the merge served its row's name is marked with a symbol key; the list's served exit judges it without that name, the verdict the by-name read gives the same row, and serves it with the name. A stored seed body that spells a name itself keeps its diagnostic. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FEkQ5nBSzc6ktJyjdFcDb3
1 parent 8769f68 commit 7e15ab7

3 files changed

Lines changed: 57 additions & 5 deletions

File tree

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

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,15 @@ import {
2727
resolveItemLock,
2828
resolveOverlayLockLayer,
2929
} from './item-lock.js';
30-
import { decorateMetadataItems } from './metadata-diagnostics.js';
30+
import { decorateMetadataItem } from './metadata-diagnostics.js';
3131
import {
3232
isActionWithheldByDisabledPackage,
3333
isItemOfDisabledPackage,
3434
} from './protocol-authoring-refusals.js';
3535
import { soleShippingPackage } from './protocol-environment-rows.js';
3636
import type { ProtocolHost } from './protocol-host.js';
3737
import { canonicalizeMetaRequestType } from './protocol-meta-type-schema.js';
38-
import { mergePackageAwareOverlay, servedViewExpansion } from './protocol-overlay-merge.js';
38+
import { mergePackageAwareOverlay, servedViewExpansion, withoutServedRowName } from './protocol-overlay-merge.js';
3939
import {
4040
type ShippingPackages,
4141
boundPackageOf,
@@ -77,6 +77,20 @@ export async function getMetaItemsPerPackage(host: Pick<ProtocolHost, 'readFlatt
7777
return host.readFlattenedMetaItems(canonicalizeMetaRequestType(request), 'served', 'per-package');
7878
}
7979

80+
/**
81+
* [#31399] One listed item, decorated for the served face. An item the merge
82+
* served its row's `name` (a body that states none, a `seed`) is judged as the
83+
* row stores it, without that `name` its schema does not declare, which is the
84+
* verdict the by-name read gives the same row; it is served with the name.
85+
* Every other item is decorated as before ({@link decorateMetadataItem}).
86+
*/
87+
function decorateListedItem(type: string, item: unknown): unknown {
88+
const stored = withoutServedRowName(item);
89+
if (stored === undefined) return decorateMetadataItem(type, item);
90+
const { _diagnostics, ...served } = decorateMetadataItem(type, stored);
91+
return { ...served, name: (item as { name: string }).name, ...(_diagnostics !== undefined ? { _diagnostics } : {}) };
92+
}
93+
8094
/** The body of `ObjectStackProtocolImplementation#readFlattenedMetaItems`; the method's docblock there is its contract. */
8195
export async function readFlattenedMetaItems(host: Pick<ProtocolHost, 'artifactLockLayerAt' | 'baseServesBundleMember' | 'convertStoredItem' | 'declinesStoredRow' | 'disabledActionsOf' | 'engine' | 'environmentId' | 'expandStoredViewContainers' | 'findEnvironmentRows' | 'flowRegistrationsOf' | 'foldObjectExtendersFromRegistry' | 'getServicesRegistry' | 'governServedObject' | 'hydrateOverlayIntoRegistry' | 'isStoredEntryOfDeclinedName' | 'isUnservedSealedOverlay' | 'isWritablePackage' | 'lookupArtifactItem' | 'namesWithOwnStoredRow' | 'readActiveOverlayRows' | 'rethrowUnlessMetadataStoreUnprovisioned' | 'shippedArtifactsOf' | 'shippingPackagesOf' | 'shipsBundleName' | 'storedOverlayEntries'>, request: { type: string; packageId?: string; names?: readonly string[]; previewDrafts?: boolean },
8296
audience: 'served' | 'execution',
@@ -929,7 +943,9 @@ export async function readFlattenedMetaItems(host: Pick<ProtocolHost, 'artifactL
929943
type: request.type,
930944
// [#20552] Served: diagnostics + per-type credential redaction.
931945
// Execution: the stored bodies — see `getMetaItemsForExecution`.
932-
items: audience === 'served' ? decorateMetadataItems(request.type, governed) : governed,
946+
// [#31399] An item served its row's `name` (a body that states none)
947+
// is judged as stored, without it, then served with it.
948+
items: audience === 'served' ? governed.map((it) => decorateListedItem(request.type, it)) : governed,
933949
// [#23316] Served only: the engine's verdict on each listed flow —
934950
// see {@link flowRegistrationsOf}. The execution face is the
935951
// engine's own read, so it carries none.

‎packages/metadata-protocol/src/protocol-overlay-merge.ts‎

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,26 @@ interface StoredRowPlace {
5656
readonly name?: string;
5757
}
5858

59+
/**
60+
* [#31399] Marks a listed body that carries its row's `name` because it states
61+
* none of its own ({@link mergePackageAwareOverlay}). A symbol key: object
62+
* spreads along the list keep it, and it never reaches the wire. The list's
63+
* served exit judges such a body's `_diagnostics` without that `name`
64+
* ({@link withoutServedRowName}), since the document's schema does not
65+
* declare it: the verdict is the one the by-name read gives the same row.
66+
*/
67+
export const SERVED_ROW_NAME: unique symbol = Symbol('metadata-protocol.servedRowName');
68+
69+
/**
70+
* [#31399] The body a listed item was stored as, when the list served it its
71+
* row's `name` ({@link SERVED_ROW_NAME}); otherwise `undefined`.
72+
*/
73+
export function withoutServedRowName(item: unknown): Record<string, unknown> | undefined {
74+
if (item === null || typeof item !== 'object' || (item as Record<PropertyKey, unknown>)[SERVED_ROW_NAME] !== true) return undefined;
75+
const { name: _name, [SERVED_ROW_NAME]: _mark, ...stored } = item as Record<PropertyKey, unknown>;
76+
return stored as Record<string, unknown>;
77+
}
78+
5979
/**
6080
* [#21804, ADR-0131 D6, ADR-0048] THE served-row resolution: the order in
6181
* which the stored rows of one item are tried for the CONTENT a read serves.
@@ -375,7 +395,7 @@ export function mergePackageAwareOverlay(
375395
&& data !== null && typeof data === 'object' && !Array.isArray(data)
376396
? stored.name
377397
: undefined;
378-
const body = (rowName !== undefined ? { ...(data as object), name: rowName } : data) as any;
398+
const body = (rowName !== undefined ? { ...(data as object), name: rowName, [SERVED_ROW_NAME]: true } : data) as any;
379399
const bodyName = ownName ?? rowName;
380400
if (bodyName === undefined) continue;
381401
// The base row this record shadows at its own slot (for view-identity

‎packages/metadata-protocol/src/protocol.seed-list-row-name.test.ts‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,11 @@
1818
* same package and name give ONE slot, the stored row's: no duplicate.
1919
* Another package's seed of the same name keeps its own slot.
2020
* 3. The draft preview lists a draft seed row by its row's name too.
21+
* Each listed seed's `_diagnostics` is the by-name read's: the served
22+
* `name` is judged off, as the row stores the body.
2123
* 4. Control: a stored body that states a name keeps it, whatever the row
22-
* says, and the stored body itself is not written by the list.
24+
* says (a seed body spelling the retired `name` keeps its diagnostic),
25+
* and the stored body itself is not written by the list.
2326
*/
2427
// Pays the lint root's first load at collection, never inside a clocked case.
2528
import './lint-root-preload.testkit.js';
@@ -145,6 +148,10 @@ describe('[#31399] §1 N stored seed rows list as N named items', () => {
145148
const item = items.find((i) => i.name === name);
146149
expect(markerOf(item)).toBe(markerOf(read.item));
147150
expect(item.object).toBe(read.item.object);
151+
// …and judged as the row stores it: the served `name` is not a
152+
// seed key, so the list's verdict is the by-name read's.
153+
expect(read.item._diagnostics).toEqual({ valid: true });
154+
expect(item._diagnostics).toEqual(read.item._diagnostics);
148155
}
149156
});
150157

@@ -190,6 +197,15 @@ describe('[#31399] §4 CONTROL — a body that states a name keeps it; the store
190197
expect((res.items as any[]).map((i) => i.name)).toEqual(['body_spelling']);
191198
});
192199

200+
it('a stored seed body that spells a `name` itself is listed under it and keeps its diagnostic, as the by-name read', async () => {
201+
const protocol = harness([seedRow('legacy', { body: { name: 'legacy', ...seedBody('legacy body') } })]);
202+
const items = await listed(protocol);
203+
expect(items.map((i) => i.name)).toEqual(['legacy']);
204+
const read: any = await protocol.getMetaItem({ type: 'seed', name: 'legacy' });
205+
expect(read.item._diagnostics.valid).toBe(false);
206+
expect(items[0]._diagnostics).toEqual(read.item._diagnostics);
207+
});
208+
193209
it('listing does not write the stored seed body', async () => {
194210
const rows = [seedRow('s_one')];
195211
const before = rows[0]!.metadata;

0 commit comments

Comments
 (0)