Skip to content

Commit 55837b7

Browse files
committed
test(metadata-protocol): bind the commit-revert fixtures' rows to the commit's own package
Six suites seeded a package's commit over package-less rows, or served a commit row with no package_id: a shape no publish produces. A revert now addresses the committing package's own rows, so each fixture states that package. The publish audit harness arms its rival write on the second package-scoped read of the name, since the plan scan now names the package. Claude-Session: https://claude.ai/code/session_01JQwxbZ5jYNfPGLvPV8LYRe Co-authored-by: Claude <noreply@anthropic.com>
1 parent 25e194b commit 55837b7

7 files changed

Lines changed: 43 additions & 11 deletions

‎packages/metadata-protocol/src/protocol.extension-field-suffix.test.ts‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,9 +304,15 @@ async function attempt<T>(run: () => Promise<T>): Promise<{ result: T | null; er
304304

305305
afterEach(() => vi.restoreAllMocks());
306306

307-
const commitRow = (items: unknown[]) => ({
307+
/**
308+
* [#29414] `packageId` — the package the commit is recorded for, which a
309+
* revert addresses the rows of; omitted, no `package_id` (the package-less
310+
* rows those cases seed).
311+
*/
312+
const commitRow = (items: unknown[], packageId?: string) => ({
308313
id: 'c1',
309314
commit_id: 'c1',
315+
...(packageId !== undefined ? { package_id: packageId } : {}),
310316
organization_id: null,
311317
operation: 'apply',
312318
message: 'the commit under revert',
@@ -455,7 +461,7 @@ describe('[ADR-0146 D10] the restore doors refuse a stored version carrying a `_
455461
it('revertCommit\'s restore limb reports it in failed[] with the envelope\'s code; nothing is written', async () => {
456462
const h = makeProtocol();
457463
const before = await threeVersionsWithFieldResidueAtV2(h, BOUND);
458-
h.serveCommit(commitRow([{ type: 'object', name: 'probe_ticket', existedBefore: true, prevVersion: 2 }]));
464+
h.serveCommit(commitRow([{ type: 'object', name: 'probe_ticket', existedBefore: true, prevVersion: 2 }], BOUND));
459465
vi.spyOn(console, 'warn').mockImplementation(() => {});
460466

461467
const res = await h.protocol.revertCommit({ commitId: 'c1' });

‎packages/metadata-protocol/src/protocol.item-name-every-door.test.ts‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -391,9 +391,15 @@ async function threeVersionsWithResidueAtV2(h: Harness) {
391391
return { historyBefore: h.historyRows.length, activeBefore: JSON.stringify(stored(h, 'dashboard')) };
392392
}
393393

394-
const commitRow = (items: unknown[]) => ({
394+
/**
395+
* [#29414] `packageId` — the package the commit is recorded for, which a
396+
* revert addresses the rows of; omitted, no `package_id` (the package-less
397+
* rows those cases seed).
398+
*/
399+
const commitRow = (items: unknown[], packageId?: string) => ({
395400
id: 'c1',
396401
commit_id: 'c1',
402+
...(packageId !== undefined ? { package_id: packageId } : {}),
397403
organization_id: null,
398404
operation: 'apply',
399405
message: 'the commit under revert',
@@ -794,7 +800,7 @@ describe('[ADR-0086 D3] the restore doors refuse a stored version whose body `pa
794800
it('revertCommit\'s restore limb reports a disagreeing version in failed[] with the envelope\'s code; nothing is written', async () => {
795801
const h = makeProtocol();
796802
const before = await threeSetVersionsWithOwnerResidueAtV2(h, BOUND, OTHER);
797-
h.serveCommit(commitRow([{ type: 'permission', name: 'probe_member', existedBefore: true, prevVersion: 2 }]));
803+
h.serveCommit(commitRow([{ type: 'permission', name: 'probe_member', existedBefore: true, prevVersion: 2 }], BOUND));
798804
vi.spyOn(console, 'warn').mockImplementation(() => {});
799805

800806
const res = await h.protocol.revertCommit({ commitId: 'c1' });
@@ -812,7 +818,7 @@ describe('[ADR-0086 D3] the restore doors refuse a stored version whose body `pa
812818
it('CONTROL: revertCommit\'s restore limb restores a version whose body agrees with the binding', async () => {
813819
const h = makeProtocol();
814820
await threeSetVersionsWithOwnerResidueAtV2(h, BOUND, BOUND);
815-
h.serveCommit(commitRow([{ type: 'permission', name: 'probe_member', existedBefore: true, prevVersion: 2 }]));
821+
h.serveCommit(commitRow([{ type: 'permission', name: 'probe_member', existedBefore: true, prevVersion: 2 }], BOUND));
816822

817823
const res = await h.protocol.revertCommit({ commitId: 'c1' });
818824

‎packages/metadata-protocol/src/protocol.package-publish-audit-rows.test.ts‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,10 @@ type Harness = {
173173
* between the two reads `promoteDraft` makes (`get` for the parent version,
174174
* then `put`'s own read inside its transaction), which is exactly the
175175
* 409 `METADATA_CONFLICT` the repository raises. Scoped to package-scoped
176-
* active reads so the pre-flight `commitItems` scan — which reads active
177-
* rows WITHOUT a `package_id` — does not consume the one-shot.
176+
* active reads, and armed on the SECOND one of the name: [#29414] the
177+
* pre-flight `commitItems` scan reads the publishing package's active row
178+
* too (it read any package's before), and it runs before the promotion,
179+
* so it must not consume the one-shot.
178180
*/
179181
faults: { failMetadataWriteFor?: string; advanceActiveOnRead?: string };
180182
/** Audit rows that LANDED and were not rolled back. */
@@ -189,6 +191,8 @@ type Harness = {
189191

190192
function makeStubEngine(opts: { failAudit?: boolean } = {}): Harness {
191193
const faults: { failMetadataWriteFor?: string; advanceActiveOnRead?: string } = {};
194+
/** [#29414] The names whose pre-flight plan read has passed (see `advanceActiveOnRead`). */
195+
const planReadPassed = new Set<string>();
192196
const rows = new Map<string, Row>();
193197
const historyRows: HistoryRow[] = [];
194198
const commitRows: any[] = [];
@@ -242,6 +246,10 @@ function makeStubEngine(opts: { failAudit?: boolean } = {}): Harness {
242246
if (faults.advanceActiveOnRead === hit.row.name
243247
&& opts2.where?.state === 'active'
244248
&& 'package_id' in (opts2.where ?? {})) {
249+
if (!planReadPassed.has(hit.row.name)) {
250+
planReadPassed.add(hit.row.name);
251+
return hit.row;
252+
}
245253
delete faults.advanceActiveOnRead;
246254
const asItStood = { ...hit.row };
247255
hit.row.checksum = 'sha256:advanced_by_a_rival';

‎packages/metadata-protocol/src/protocol.recovery-doors-emit-mutation.test.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,11 @@ function matchesWhere(r: Row, where: Record<string, unknown>): boolean {
161161
}
162162

163163
/** One `sys_metadata_commit` row in the driver's snake_case wire shape. */
164+
/** [#29414] Recorded for `PKG`, the package the rows below are bound to: a commit's revert addresses its own package's rows. */
164165
const commitRow = (items: unknown[]) => ({
165166
id: 'c1',
166167
commit_id: 'c1',
168+
package_id: PKG,
167169
organization_id: null,
168170
operation: 'apply',
169171
message: 'the commit under revert',

‎packages/metadata-protocol/src/protocol.recovery-doors-mutation-projector.test.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,11 @@ function matchesWhere(r: Row, where: Record<string, unknown>): boolean {
126126
}
127127

128128
/** One `sys_metadata_commit` row in the driver's snake_case wire shape. */
129+
/** [#29414] Recorded for `PKG`, the package the rows below are bound to: a commit's revert addresses its own package's rows. */
129130
const commitRow = (items: unknown[]) => ({
130131
id: 'c1',
131132
commit_id: 'c1',
133+
package_id: PKG,
132134
organization_id: null,
133135
operation: 'apply',
134136
message: 'the commit under revert',

‎packages/metadata-protocol/src/protocol.revert-stored-type-canonical.test.ts‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,14 +305,17 @@ async function seedRowVerbatim(
305305
const repo = protocol.getOverlayRepo(null);
306306
const ref = { type: args.type, name: args.name, org: 'env' };
307307
// Successive writes to one identity build the lineage a revert restores
308-
// from, so each must present the CURRENT head as its parent.
309-
const existing = await repo.get(ref, { state: 'active' });
308+
// from, so each must present the CURRENT head as its parent. [#29414]
309+
// Bound to the package the commit under revert is recorded for
310+
// (`commitRow`): a commit's revert addresses that package's own rows.
311+
const existing = await repo.get(ref, { state: 'active', packageId: 'app.demo' });
310312
await repo.put(ref, args.body, {
311313
parentVersion: existing?.hash ?? null,
312314
actor: null,
313315
source: 'test.at-rest-residue',
314316
intent: 'runtime-only',
315317
state: 'active',
318+
packageId: 'app.demo',
316319
});
317320
}
318321

‎packages/metadata-protocol/src/protocol.rollback-carries-item-failures.test.ts‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,18 +173,23 @@ function makeProtocol(opts: { unreadableCommits?: readonly string[] } = {}) {
173173
return { protocol, rows, commits };
174174
}
175175

176-
/** Write a row through the repository, which stores `type` exactly as given. */
176+
/**
177+
* Write a row through the repository, which stores `type` exactly as given,
178+
* bound to the package the commits are recorded for: [#29414] a commit's
179+
* revert addresses the committing package's own rows, as its publish wrote them.
180+
*/
177181
async function seed(protocol: any, type: string, name: string, label: string): Promise<void> {
178182
await protocol.ensureOverlayIndex();
179183
const repo = protocol.getOverlayRepo(null);
180184
const ref = { type, name, org: 'env' };
181-
const existing = await repo.get(ref, { state: 'active' });
185+
const existing = await repo.get(ref, { state: 'active', packageId: PKG });
182186
await repo.put(ref, { name, label }, {
183187
parentVersion: existing?.hash ?? null,
184188
actor: null,
185189
source: 'test.rollback-item-failures',
186190
intent: 'runtime-only',
187191
state: 'active',
192+
packageId: PKG,
188193
});
189194
}
190195

0 commit comments

Comments
 (0)