Skip to content

Commit 650b2b0

Browse files
committed
fix(metadata-protocol): the move-in undo writes the registry back in the member that puts the row; both write censuses record it (#38150)
undoLanded now calls applyRegistryWriteThrough right after its repo.put, so the stored-row write census reads the write and its route in one member. The write-through caller census counts ten sites, traced. Claude-Session: https://claude.ai/code/session_01L9qibyHmxFV4bTFZ5BKnUz Co-authored-by: Claude <noreply@anthropic.com>
1 parent 5ea8aad commit 650b2b0

3 files changed

Lines changed: 31 additions & 6 deletions

File tree

‎packages/metadata-protocol/src/protocol-package-move-in.ts‎

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ export class ProtocolPackageMoveInFacet {
445445
* and save doors already moved the in-memory registry: put each item back
446446
* at its package-less address, from its restored body.
447447
*/
448-
private static async restoreRegistry(host: MoveHost, items: readonly LooseItem[], target: string): Promise<void> {
448+
static async restoreRegistry(host: MoveHost, items: readonly LooseItem[], target: string): Promise<void> {
449449
for (const item of items) {
450450
const body = bodyOf(item.active);
451451
if (!item.active || !body) continue;
@@ -476,7 +476,7 @@ export class ProtocolPackageMoveInFacet {
476476
* remove the row written into the target, put the loose row back as it was
477477
* stored, then put the registry back at the package-less address.
478478
*/
479-
private static async undoLanded(
479+
static async undoLanded(
480480
host: MoveHost,
481481
landed: ReadonlyArray<{ item: LooseItem; state: 'active' | 'draft' }>,
482482
target: string,
@@ -511,7 +511,20 @@ export class ProtocolPackageMoveInFacet {
511511
packageId: null,
512512
...(item.member ? { member: item.member } : {}),
513513
} as never);
514-
if (state === 'active') await ProtocolPackageMoveInFacet.restoreRegistry(host, [item], target);
514+
// The registry is put back here, after the put, so the census
515+
// (protocol.view-expansion-reconcile-call-sites.test.ts) reads
516+
// the write and its write-through in one member.
517+
if (state === 'active') {
518+
const [entry] = host.storedOverlayEntries({ type: item.type }, [row as never]);
519+
await host.applyRegistryWriteThrough({
520+
type: item.type,
521+
name: entry?.name ?? item.name,
522+
item: entry?.data ?? body,
523+
packageId: null,
524+
organizationId: null,
525+
reboundFrom: { packageId: target },
526+
});
527+
}
515528
} catch (err: any) {
516529
console.error(
517530
`[Protocol] moveIntoPackage: the refused move of ${item.type}/${item.name} into '${target}' could `

‎packages/metadata-protocol/src/protocol.object-registry-write-through-spelling.test.ts‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
// The trace, measured on `origin/main` — all four routes fold at the producer
3939
// ---------------------------------------------------------------------------
4040
// `applyObjectRegistryMutation` has exactly ONE caller
41-
// (`applyRegistryWriteThrough`), which has exactly EIGHT:
41+
// (`applyRegistryWriteThrough`), which has exactly TEN:
4242
//
4343
// 1. `saveMetaItem` passes `singularTypeForRepo`, and the method
4444
// already ran `canonicalizeMetaRequestType`.
@@ -78,6 +78,14 @@
7878
// `'view'`: it heals the old-shape `view` row a
7979
// `form` save, publish or delete re-saved, so no
8080
// stored spelling reaches it.
81+
// 9. `restoreRegistry` (#38150) passes the item's type as the move-in
82+
// door folded it through `canonicalMetaType`
83+
// when it judged the selection: it puts each
84+
// moved item back at its package-less address
85+
// after a rolled-back move.
86+
// 10. `undoLanded` (#38150) passes the same folded type: it writes back
87+
// through each loose row a refused move put
88+
// back with no transaction to cover it.
8189
//
8290
// Both fold maps resolve the plural — `PLURAL_TO_SINGULAR.objects === 'object'`
8391
// and `canonicalMetaUrlType('objects') === 'object'` — so no route can deliver
@@ -610,9 +618,9 @@ describe('[#8862] the `applyRegistryWriteThrough` caller set stays closed', () =
610618
const sources = [source, ...SPLIT_MODULES.map((file) => readFileSync(fileURLToPath(new URL(`./${file}`, import.meta.url)), 'utf8'))];
611619
const sitesOf = (pattern: RegExp) => sources.flatMap((text) => text.match(pattern) ?? []);
612620

613-
it('has exactly eight call sites, all traced in this file’s header', () => {
621+
it('has exactly ten call sites, all traced in this file’s header', () => {
614622
const callSites = sitesOf(/\b(?:this|host)\.applyRegistryWriteThrough\(/g);
615-
expect(callSites).toHaveLength(8);
623+
expect(callSites).toHaveLength(10);
616624
});
617625

618626
it('`applyObjectRegistryMutation` is reached only through the write-through', () => {

‎packages/metadata-protocol/src/protocol.view-expansion-reconcile-call-sites.test.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,9 @@ const WRITES: ReadonlyArray<{ readonly member: string; readonly verb: string; re
178178
{ member: 'undoLandedPromotions', verb: 'repo.restoreVersion(', route: { sameMember: 'restoreArtifactRegistryView' } },
179179
{ member: 'undoLandedPromotions', verb: 'repo.delete(', route: { sameMember: 'restoreArtifactRegistryView' } },
180180
{ member: 'undoLandedPromotions', verb: 'repo.put(', route: { sameMember: 'restoreArtifactRegistryView' } },
181+
// [#38150] A refused move into a package puts back each loose row no transaction covered (the
182+
// objects; every row on a runtime that cannot roll back), and writes the registry back through.
183+
{ member: 'undoLanded', verb: 'repo.put(', route: { sameMember: 'applyRegistryWriteThrough' } },
181184
// [ADR-0159 D5] A `form` save, publish or delete removes (or re-saves) the old-shape `view` row of
182185
// its name in the same transaction; each door heals the registry from the rows handed back.
183186
{ member: 'applyOldShapeFormRowRemovals', verb: 'repo.delete(', route: { handedTo: 'module callers', then: 'healOldShapeFormRowRemovals' } },
@@ -287,6 +290,7 @@ describe('[#29985] the census reads the modules the split moved bodies to', () =
287290
'protocol-form-writes.ts: applyOldShapeFormRowRemovals',
288291
'protocol-form-writes.ts: applyOldShapeFormRowRemovals',
289292
'protocol-form-writes.ts: restoreOldShapeFormRowRemovals',
293+
'protocol-package-move-in.ts: undoLanded',
290294
'protocol-packageless-overlay-migration.ts: migratePackagelessOverlays',
291295
]);
292296
});

0 commit comments

Comments
 (0)