Skip to content

Commit c7cc4e2

Browse files
committed
test(driver-sql): type the transaction options in the no-reading refusal pins
Claude-Session: https://claude.ai/code/session_01L9qibyXo4gSy8DJPNz4ANz Co-authored-by: Claude <noreply@anthropic.com>
1 parent 7f4974a commit c7cc4e2

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

‎packages/drivers/driver-sql/src/sql-driver-fixed-read-leaf-conformance.test.ts‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import {
4242
isSharedRecordIds,
4343
lowerFilterCondition,
4444
type FilterCondition,
45+
type DriverOptions,
4546
type FixedReadLeafRow,
4647
} from '@objectstack/spec/data';
4748
import { SqlDriver, type SqlDriverConfig } from './sql-driver.js';
@@ -653,6 +654,7 @@ function declarePgKeyTypePins(driverOf: () => SqlDriver, knexOf: () => Knex): vo
653654
describe('no reading is refused, never compiled uncast (ADR-0155 D2)', () => {
654655
const charCase = () => PG_KEY_CASES.find((c) => c.ddl === 'character(4)')!;
655656
const leafOf = (object: string) => seamed({ id: { $in: SharedRecordIds.read(object, 'u9') } });
657+
const inTrx = (transaction: Knex.Transaction): DriverOptions => ({ transaction });
656658
const refused = (err: unknown) => {
657659
expect(err, 'refused').toBeInstanceOf(Error);
658660
expect(err).toMatchObject({ code: 'INTERNAL_ERROR', status: 500 });
@@ -673,9 +675,9 @@ function declarePgKeyTypePins(driverOf: () => SqlDriver, knexOf: () => Knex): vo
673675
// The caller's transaction holds the pool's one connection.
674676
const trx = await fresh.beginTransaction();
675677
try {
676-
refused(await fresh.find(EXT(c), { where: leafOf(EXT(c)) }, { transaction: trx } as any).catch((e) => e));
677-
refused(await fresh.count(EXT(c), { where: leafOf(EXT(c)) }, { transaction: trx } as any).catch((e) => e));
678-
refused(await fresh.updateMany(EXT(c), { where: leafOf(EXT(c)) }, { label: 'touched' }, { transaction: trx } as any).catch((e) => e));
678+
refused(await fresh.find(EXT(c), { where: leafOf(EXT(c)) }, inTrx(trx)).catch((e) => e));
679+
refused(await fresh.count(EXT(c), { where: leafOf(EXT(c)) }, inTrx(trx)).catch((e) => e));
680+
refused(await fresh.updateMany(EXT(c), { where: leafOf(EXT(c)) }, { label: 'touched' }, inTrx(trx)).catch((e) => e));
679681
} finally {
680682
await trx.rollback();
681683
}
@@ -701,9 +703,9 @@ function declarePgKeyTypePins(driverOf: () => SqlDriver, knexOf: () => Knex): vo
701703
await trx(TXN).insert([{ id: 'k1', label: 'x' }, { id: 'k2', label: 'x' }]);
702704
await trx(GRANTS).insert({ id: 'srid_pk_txn_g0', object_name: TXN, recipient_type: 'user', recipient_id: 'u9', record_id: 'k1 ', access_level: 'lvl_edit', organization_id: 'org_a' });
703705
// Today's list, in the same transaction, answers k1: the leaf must not answer anything else.
704-
expect(sortedIds(await fresh.find(TXN, { where: seamed({ id: { $in: ['k1 '] } }) }, { transaction: trx } as any))).toEqual(['k1 ']);
705-
refused(await fresh.find(TXN, { where: leafOf(TXN) }, { transaction: trx } as any).catch((e) => e));
706-
refused(await fresh.count(TXN, { where: leafOf(TXN) }, { transaction: trx } as any).catch((e) => e));
706+
expect(sortedIds(await fresh.find(TXN, { where: seamed({ id: { $in: ['k1 '] } }) }, inTrx(trx)))).toEqual(['k1 ']);
707+
refused(await fresh.find(TXN, { where: leafOf(TXN) }, inTrx(trx)).catch((e) => e));
708+
refused(await fresh.count(TXN, { where: leafOf(TXN) }, inTrx(trx)).catch((e) => e));
707709
} finally {
708710
await trx.rollback();
709711
await fresh.disconnect?.();

0 commit comments

Comments
 (0)