Skip to content

Commit 2be906e

Browse files
committed
test(drivers): 剥掉 33 处已死的 bypassTenantAudit 选项转型,换回编译期检查 (#6754)
`SqlDriver.create/find/update/delete` 声明的是 `options?: DriverOptions`, `bypassTenantAudit` 是 `DriverOptionsSchema` 上的合法键(spec 17.0.0 起, #4311),所以这些 `as any` 早就不需要了。它们不是无害的:转型关掉的是**整个 选项对象**的检查,于是这些站点上任何键名拼错都不报错。 `TursoDriver` 一并纳入:PR #6755(#6402)已把 17 个 override 的 `options?: any` 全部收窄成 `options?: DriverOptions`,turso 当初被单独拆出去 的唯一理由已经消失;#6394 也已落地,`as never` 残留为零。留着这 4 处就没有 第二个人来收。 逐包实测(依赖闭包先构建,避免读到过期的 `dist/*.d.ts`): | 包 | 剥掉 | 文件 | |---|---:|---:| | driver-sql | 11 | 6 | | driver-sqlite-wasm | 19 | 8 | | driver-turso | 4 | 2 | 其中 `sqlite-wasm-pagination-conformance.test.ts:34` 是单据的 grep 漏掉的第 19 处 —— 形状是 `as unknown as Parameters<SqliteWasmDriver['find']>[2]`。 两处具名 const(`sql-driver-limit-zero-presence.test.ts` 的 `READ`、 `sqlite-wasm-pagination-conformance.test.ts` 的 `READ_OPTIONS`)只删转型**不 足以**换回检查:超额属性检查只对直接位置上的新鲜字面量生效。实测确认, `const READ = { tenantId: 't1', bypassTenantAuditt: true }` 在只删转型的情况下 EXIT=0、零报错 —— 拼错被静默吞掉。因此这两处改为 `: DriverOptions` 标注,让 字面量在声明处受检。 ⛔ 未触碰 `packages/objectql/src/engine-unknown-option.test.ts` 的 2 处:那是 另一个包、另一种形状(转型套在传给 `engine.find(...)` 的查询对象上,不是 `DriverOptions` 参数),且 `bypassTenantAudit` 出现在该文件自己的 `PASSTHROUGH` 漂移钉里 —— 剥掉等于删掉被测对象。属 engine-core 车道。 纯测试改动,无 changeset。 Refs #6754, #6394, #6402, #6755 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MVa7roTgq6gGty2bG2KiEf
1 parent 73bff86 commit 2be906e

16 files changed

Lines changed: 36 additions & 34 deletions

packages/drivers/driver-sql/src/sql-driver-calendar-day-upper-bound.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ describe('bare-day $lte on Field.datetime — the #3777 repro', () => {
6161
await driver.create(
6262
'task',
6363
{ id, title: id, created_at: new Date(at), created_on: at.slice(0, 10) },
64-
{ bypassTenantAudit: true } as any,
64+
{ bypassTenantAudit: true },
6565
);
6666
}
6767
});

packages/drivers/driver-sql/src/sql-driver-limit-zero-presence.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161

6262
import { describe, it, expect, beforeAll, afterAll } from 'vitest';
6363
import knexLib from 'knex';
64+
import type { DriverOptions } from '@objectstack/spec/data';
6465
import { SqlDriver } from './index.js';
6566

6667
const TABLE = 'os6577_zero_page';
@@ -96,7 +97,7 @@ function paginationTail(sql: string): string {
9697
return m ? m[0].toLowerCase() : '';
9798
}
9899

99-
const READ = { bypassTenantAudit: true } as any;
100+
const READ: DriverOptions = { bypassTenantAudit: true };
100101

101102
describe('driver-sql — `limit: 0` returns no records on every door (#6577)', () => {
102103
let driver: InspectableSqlDriver;

packages/drivers/driver-sql/src/sql-driver-runtime-token-default.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ describe('SqlDriver — defaultValue runtime tokens never become a column DEFAUL
108108

109109
// A system/anonymous write: exactly the seed-replay shape that produced the
110110
// two dangling `sys_user:current_user` references #4551's audit reported.
111-
await driver.create('field_zoo', { id: 'z1', title: 'specimen' }, { bypassTenantAudit: true } as any);
111+
await driver.create('field_zoo', { id: 'z1', title: 'specimen' }, { bypassTenantAudit: true });
112112

113113
const row = await knexInstance('field_zoo').where('id', 'z1').first();
114114
expect(row.f_owner).toBeNull();
@@ -118,7 +118,7 @@ describe('SqlDriver — defaultValue runtime tokens never become a column DEFAUL
118118
it('an explicitly supplied user id is still stored (the column is a normal lookup)', async () => {
119119
const driver = makeDriver();
120120
await driver.initObjects(fieldZoo as any);
121-
await driver.create('field_zoo', { id: 'z2', title: 't', f_owner: 'usr_42' }, { bypassTenantAudit: true } as any);
121+
await driver.create('field_zoo', { id: 'z2', title: 't', f_owner: 'usr_42' }, { bypassTenantAudit: true });
122122
const row = await knexInstance('field_zoo').where('id', 'z2').first();
123123
expect(row.f_owner).toBe('usr_42');
124124
});
@@ -128,7 +128,7 @@ describe('SqlDriver — defaultValue runtime tokens never become a column DEFAUL
128128
it("REGRESSION: 'NOW()' still gets its driver-native default and stores a canonical instant", async () => {
129129
const driver = makeDriver();
130130
await driver.initObjects(fieldZoo as any);
131-
await driver.create('field_zoo', { id: 'z3', title: 't' }, { bypassTenantAudit: true } as any);
131+
await driver.create('field_zoo', { id: 'z3', title: 't' }, { bypassTenantAudit: true });
132132
const row = await knexInstance('field_zoo').where('id', 'z3').first();
133133
expect(row.f_seen_at).toMatch(ISO_Z);
134134
expect(String(row.f_seen_at)).not.toContain('NOW()');
@@ -217,7 +217,7 @@ describe('SqlDriver — defaultValue runtime tokens never become a column DEFAUL
217217
expect(info.f_owner.defaultValue ?? null).toBeNull();
218218
expect(await driver.detectManagedDrift(fieldZoo as any)).toEqual([]);
219219

220-
await driver.create('field_zoo', { id: 'after', title: 'C' }, { bypassTenantAudit: true } as any);
220+
await driver.create('field_zoo', { id: 'after', title: 'C' }, { bypassTenantAudit: true });
221221
const row = await knexInstance('field_zoo').where('id', 'after').first();
222222
expect(row.f_owner).toBeNull();
223223
});
@@ -244,7 +244,7 @@ describe('SqlDriver — defaultValue runtime tokens never become a column DEFAUL
244244
expect(String(info.f_seen_at.defaultValue ?? '')).toContain('strftime');
245245
expect(String(info.f_status.defaultValue ?? '')).toContain('open');
246246

247-
await driver.create('field_zoo', { id: 'post', title: 'D' }, { bypassTenantAudit: true } as any);
247+
await driver.create('field_zoo', { id: 'post', title: 'D' }, { bypassTenantAudit: true });
248248
const row = await knexInstance('field_zoo').where('id', 'post').first();
249249
expect(row.f_seen_at).toMatch(ISO_Z);
250250
expect(row.f_status).toBe('open');

packages/drivers/driver-sql/src/sql-driver-temporal-conformance.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ function declareDatetimeSweep(cell: DialectCell): void {
193193
on: r.on,
194194
why: r.why,
195195
},
196-
{ bypassTenantAudit: true } as any,
196+
{ bypassTenantAudit: true },
197197
);
198198
}
199199
});
@@ -307,7 +307,7 @@ function declareTimeSweep(cell: DialectCell): void {
307307
at: r.writerForm === 'native' ? new Date(`1970-01-01T${r.at}Z`) : r.at,
308308
why: r.why,
309309
},
310-
{ bypassTenantAudit: true } as any,
310+
{ bypassTenantAudit: true },
311311
);
312312
}
313313
});

packages/drivers/driver-sql/src/sql-driver-tenant-audit-posture.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ describe('#5262 — tenant-audit fires on a posture-only walled deployment', ()
143143
await driver.create(
144144
'account',
145145
{ id: 'x1', organization_id: 'org_a', name: 'X1' },
146-
{ bypassTenantAudit: true } as any,
146+
{ bypassTenantAudit: true },
147147
);
148148
expect(tenantAuditWarned()).toBe(false);
149149
});

packages/drivers/driver-sql/src/sql-driver-tenant-scope.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ describe('SqlDriver tenant scope (organization_id)', () => {
433433
await driver.create(
434434
'account',
435435
{ id: 'x1', organization_id: 'org_a', name: 'X1' },
436-
{ bypassTenantAudit: true } as any,
436+
{ bypassTenantAudit: true },
437437
);
438438
expect(warnSpy).toHaveLength(0);
439439
});

packages/drivers/driver-sqlite-wasm/src/sqlite-wasm-aggregation-conformance.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ describe('[#6409] driver-sqlite-wasm — aggregate vocabulary conformance', () =
7070
},
7171
]);
7272
for (const row of AGGREGATION_ROWS) {
73-
await driver.create(OBJECT, { ...row }, { bypassTenantAudit: true } as any);
73+
await driver.create(OBJECT, { ...row }, { bypassTenantAudit: true });
7474
}
7575
});
7676

packages/drivers/driver-sqlite-wasm/src/sqlite-wasm-driver-calendar-day-upper-bound.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ describe('SqliteWasmDriver — bare-day $lte covers the whole day (#3777)', () =
2929
await driver.create(
3030
'task',
3131
{ id, title: id, created_at: new Date(at) },
32-
{ bypassTenantAudit: true } as any,
32+
{ bypassTenantAudit: true },
3333
);
3434
}
3535
});

packages/drivers/driver-sqlite-wasm/src/sqlite-wasm-driver-tenant-scope.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ describe('SqliteWasmDriver tenant scope (organization_id)', () => {
332332
await driver.create(
333333
'account',
334334
{ id: 'x1', organization_id: 'org_a', name: 'X1' },
335-
{ bypassTenantAudit: true } as any,
335+
{ bypassTenantAudit: true },
336336
);
337337
expect(warnSpy).toHaveLength(0);
338338
} finally {

packages/drivers/driver-sqlite-wasm/src/sqlite-wasm-empty-field-constraint.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ describe('[#5240] driver-sqlite-wasm inherits the zero-operator field-constraint
3232
await driver.initObjects([
3333
{ name: 'deal', fields: { stage: { type: 'string' }, owner: { type: 'string' } } },
3434
]);
35-
await driver.create('deal', { id: '1', stage: 'won', owner: 'u1' }, { bypassTenantAudit: true } as any);
36-
await driver.create('deal', { id: '2', stage: 'lost', owner: 'u2' }, { bypassTenantAudit: true } as any);
35+
await driver.create('deal', { id: '1', stage: 'won', owner: 'u1' }, { bypassTenantAudit: true });
36+
await driver.create('deal', { id: '2', stage: 'lost', owner: 'u2' }, { bypassTenantAudit: true });
3737
});
3838

3939
afterAll(async () => {
@@ -44,7 +44,7 @@ describe('[#5240] driver-sqlite-wasm inherits the zero-operator field-constraint
4444
const rows = await driver.find(
4545
'deal',
4646
{ object: 'deal', fields: ['id'], where } as any,
47-
{ bypassTenantAudit: true } as any,
47+
{ bypassTenantAudit: true },
4848
);
4949
return (rows as any[]).map((r) => String(r.id)).sort();
5050
};

0 commit comments

Comments
 (0)