Skip to content

Commit 4843e58

Browse files
committed
test(objectql): type-clean the new transaction contract test under the TEST_DEBT re-measure (#5696)
objectql's test layer is excluded from its own `tsconfig.json`, so `pnpm --filter @objectstack/objectql typecheck` never reads these files — only the ledger's `--re-measure` does, by synthesizing a config with the test globs unexcluded. The new file arrived with 7 errors nothing local reported. Two shapes, both fixed rather than absorbed: - `registry.registerObject(x as any)` — `packageId` is not optional (TS2554). - `promise.catch((e) => e as E)` types the result `E | <resolved type>`, so every property read on it is TS2339. Replaced by a `rejection<E>()` helper that narrows to the rejection AND throws if the call did not reject at all — which the bare `.catch()` would have let pass silently as a green test. Re-measured: zero errors in this file. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019Q7oc7ASjh8yxyS3Yz78We
1 parent 9915480 commit 4843e58

1 file changed

Lines changed: 21 additions & 4 deletions

File tree

packages/objectql/src/engine-transaction-contract.test.ts

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,23 @@ interface Recorded {
2929
args: unknown[];
3030
}
3131

32+
/**
33+
* The error a call rejected with, typed as `E`.
34+
*
35+
* `promise.catch((e) => e as E)` types the result as `E | <resolved type>`, so
36+
* every property read on it is a type error. This narrows to the rejection and
37+
* fails loudly if the call did NOT reject — which a bare `.catch()` would
38+
* silently let through as a passing test.
39+
*/
40+
async function rejection<E>(p: Promise<unknown>): Promise<E> {
41+
try {
42+
await p;
43+
} catch (e) {
44+
return e as E;
45+
}
46+
throw new Error('expected the call to reject, but it resolved');
47+
}
48+
3249
function recordingLogger() {
3350
const records: Recorded[] = [];
3451
const push = (level: Recorded['level']) => (message: string, ...args: unknown[]) =>
@@ -107,7 +124,7 @@ async function engineWith(opts: { transactional: boolean }) {
107124
const driver = makeDriver('primary', { transactional: opts.transactional });
108125
engine.registerDriver(driver, true);
109126
await engine.init();
110-
engine.registry.registerObject({ name: 'thing', fields: { name: { type: 'text' } } } as any);
127+
engine.registry.registerObject({ name: 'thing', fields: { name: { type: 'text' } } } as any, '__test__');
111128
return { rec, engine, driver };
112129
}
113130

@@ -132,9 +149,9 @@ describe('transaction({ require: true }) refuses a driver that cannot roll back
132149
it('carries the boundary-crossing code, the datasource, and the fix', async () => {
133150
const { engine } = await engineWith({ transactional: false });
134151

135-
const err = await engine
136-
.transaction(async () => 'unreachable', undefined, { require: true })
137-
.catch((e: unknown) => e as TransactionUnsupportedError);
152+
const err = await rejection<TransactionUnsupportedError>(
153+
engine.transaction(async () => 'unreachable', undefined, { require: true }),
154+
);
138155

139156
expect(err.code).toBe('ERR_TRANSACTION_UNSUPPORTED');
140157
expect(err.datasource).toBe('primary');

0 commit comments

Comments
 (0)