Skip to content

Commit 042f406

Browse files
committed
test(driver-sql): type the fixture log sinks so error stays OPTIONAL (#9609)
The level-recording fixture supplies `error`, so its inferred logger type made `error` REQUIRED — and the no-error-sink twin, whose entire job is to be a sink without one, then could not extend it (TS2416/TS2322). Both fixtures now annotate `FakeLogSink`, which spells `error?` exactly as `SqlDriver` declares it. That is the contract under test, not a workaround: the optional `error` is the whole reason `logDurabilityFailure` needs a fallback. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XqDQYVU5smx29ts9pAErja
1 parent c6cff31 commit 042f406

1 file changed

Lines changed: 19 additions & 3 deletions

File tree

‎packages/drivers/driver-sql/src/sql-driver-deferred-ddl-lock-wait.test.ts‎

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,22 @@ const WIDGET = {
5555
/** One statement, tagged with the pinned session it was issued on. */
5656
interface Issued { session: number; sql: string; bindings: unknown[] }
5757

58+
/**
59+
* [#9609] The driver's logger shape, with `error` OPTIONAL exactly as
60+
* `SqlDriver` declares it.
61+
*
62+
* Spelled out rather than inferred from each fixture's object literal: an
63+
* inferred type makes `error` REQUIRED on whichever fixture happens to supply
64+
* it, and then the no-error-sink twin below cannot extend it — which reads as a
65+
* TypeScript puzzle when it is really the contract under test. `error?` is the
66+
* whole reason `logDurabilityFailure` needs a fallback.
67+
*/
68+
type FakeLogSink = {
69+
warn: (msg: string, meta?: any) => void;
70+
info?: (msg: string, meta?: any) => void;
71+
error?: (msg: string, meta?: any) => void;
72+
};
73+
5874
/**
5975
* MySQL's lock-wait timeout as mysql2 raises it, wrapped the way knex re-throws
6076
* it — the wrapper is the point: a recognizer reading only the top-level error
@@ -112,7 +128,7 @@ class FakeMysqlDriver extends SqlDriver {
112128
*/
113129
logs: Array<{ level: 'warn' | 'error'; msg: string; meta?: any }> = [];
114130

115-
protected override logger = {
131+
protected override logger: FakeLogSink = {
116132
warn: (msg: string, meta?: any) => { this.logs.push({ level: 'warn', msg, meta }); },
117133
error: (msg: string, meta?: any) => { this.logs.push({ level: 'error', msg, meta }); },
118134
info: () => {},
@@ -196,8 +212,8 @@ function makeDriver(): FakeMysqlDriver {
196212
* that only looks at the driver with a full sink.
197213
*/
198214
class NoErrorSinkDriver extends FakeMysqlDriver {
199-
protected override logger = {
200-
warn: (msg: string, meta?: any) => { this.logs.push({ level: 'warn' as const, msg, meta }); },
215+
protected override logger: FakeLogSink = {
216+
warn: (msg: string, meta?: any) => { this.logs.push({ level: 'warn', msg, meta }); },
201217
info: () => {},
202218
};
203219
}

0 commit comments

Comments
 (0)