Skip to content

Commit 9915480

Browse files
committed
fix(metadata-protocol): realign the SysMetadataEngine test doubles' transaction signature with the contract (#5696)
CI's `TypeScript Type Check` went red where a scoped `pnpm --filter … typecheck` could not: @objectstack/metadata-protocol has no `typecheck` script, so its errors are only ever seen by the DEBT ledger's `--re-measure`, which reported 63 -> 70 (+7). All seven were one shape. Six test doubles stand in for `SysMetadataEngine`, whose `transaction?` member is typed FROM the contract (`IObjectQLEngine['transaction']`), and each declared its callback as `(ctx: any) => Promise<T>` — one parameter, from before the callback gained its `info` argument. A double may be narrower than the producer; it may not contradict it. Each now declares `(ctx: any, info: { owned: boolean })` and passes `{ owned: true }` at the call — the honest value, since every one of these doubles OPENS the transaction it stands in for, which is exactly what `ObjectQL.transaction` reports on its own open branch. Re-measured: 63 raw errors, the frozen count, with zero transaction-related errors remaining. `check-type-check-coverage --re-measure` reports no upward drift. metadata-protocol: 49 files / 502 tests pass. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019Q7oc7ASjh8yxyS3Yz78We
1 parent 718028b commit 9915480

6 files changed

Lines changed: 10 additions & 10 deletions

packages/metadata-protocol/src/protocol-publish-drafts-endpoint-gate.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,8 @@ function makeStubEngine(namespace?: string) {
169169
rows.delete(found.key);
170170
return { deleted: 1 };
171171
},
172-
async transaction<T>(cb: (ctx: any) => Promise<T>): Promise<T> {
173-
return cb(undefined);
172+
async transaction<T>(cb: (ctx: any, info: { owned: boolean }) => Promise<T>): Promise<T> {
173+
return cb(undefined, { owned: true });
174174
},
175175
registry: {
176176
registerItem: () => {},

packages/metadata-protocol/src/protocol-publish-drafts-org-scope.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,8 @@ function makeStubEngine() {
166166
rows.delete(found.key);
167167
return { deleted: 1 };
168168
},
169-
async transaction<T>(cb: (ctx: any) => Promise<T>): Promise<T> {
170-
return cb(undefined);
169+
async transaction<T>(cb: (ctx: any, info: { owned: boolean }) => Promise<T>): Promise<T> {
170+
return cb(undefined, { owned: true });
171171
},
172172
registry: {
173173
registerItem: () => {},

packages/metadata-protocol/src/protocol.read-decorations.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ function makeStubEngine() {
9292
assertEngineDeleteDispatch(opts);
9393
return { deleted: 0 };
9494
},
95-
async transaction<T>(cb: (ctx: any) => Promise<T>): Promise<T> { return cb(undefined); },
95+
async transaction<T>(cb: (ctx: any, info: { owned: boolean }) => Promise<T>): Promise<T> { return cb(undefined, { owned: true }); },
9696
async syncObjectSchema() { /* no DDL in this stub */ },
9797
registry: {
9898
listItems: () => [],

packages/metadata-protocol/src/sys-metadata-repository.draft-drain.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,13 +180,13 @@ function makeFakeEngine() {
180180
rows.delete(found.key);
181181
return { deleted: 1 };
182182
},
183-
async transaction<T>(cb: (ctx: any) => Promise<T>): Promise<T> {
183+
async transaction<T>(cb: (ctx: any, info: { owned: boolean }) => Promise<T>): Promise<T> {
184184
const rowsSnapshot = new Map(Array.from(rows, ([k, r]) => [k, { ...r }] as const));
185185
const historySnapshot = historyRows.map((h) => ({ ...h }));
186186
const outer = pendingRollback;
187187
pendingRollback = rowsSnapshot;
188188
try {
189-
return await cb({ txn: true });
189+
return await cb({ txn: true }, { owned: true });
190190
} catch (err) {
191191
rows.clear();
192192
for (const [k, r] of rowsSnapshot) rows.set(k, r);

packages/metadata-protocol/src/sys-metadata-repository.history-counters.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,11 +158,11 @@ function makeFakeEngine() {
158158
rows.delete(found.key);
159159
return { deleted: 1 };
160160
},
161-
async transaction<T>(cb: (ctx: any) => Promise<T>): Promise<T> {
161+
async transaction<T>(cb: (ctx: any, info: { owned: boolean }) => Promise<T>): Promise<T> {
162162
const rowsSnapshot = new Map(Array.from(rows, ([k, r]) => [k, { ...r }] as const));
163163
const historySnapshot = historyRows.map((h) => ({ ...h }));
164164
try {
165-
return await cb({ txn: true });
165+
return await cb({ txn: true }, { owned: true });
166166
} catch (err) {
167167
// ACID: a txn body that throws commits nothing at all.
168168
rows.clear();

packages/metadata-protocol/src/sys-metadata-repository.recorded-by.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ function makeFakeEngine() {
9696
rows.delete(found.key);
9797
return { deleted: 1 };
9898
},
99-
async transaction<T>(cb: (ctx: any) => Promise<T>): Promise<T> { return cb(undefined); },
99+
async transaction<T>(cb: (ctx: any, info: { owned: boolean }) => Promise<T>): Promise<T> { return cb(undefined, { owned: true }); },
100100
};
101101
}
102102

0 commit comments

Comments
 (0)