Просмотр исходного кода

test(session): keep migration assertions type-aware

Treat Vitest asymmetric matchers as unknown expected values and spell void assertion callbacks explicitly. This preserves the migration identity and refusal checks under the full type-aware lint configuration without relaxing validation or suppressing a rule.
Tianyi Cui 1 месяц назад
Родитель
Сommit
cfc10f7e1f

+ 2 - 2
packages/session/session-persistence-jsonl/tests/jsonl.spec.ts

@@ -197,7 +197,7 @@ function withMigratedEmptyHead(log: readonly SessionEvent[]): readonly unknown[]
     {
       type: 'system/message', seq: 2, time: log[1]!.time, surfaceOp: 'append',
       data: { turn: 1, step: 1, message: {
-        id: expect.stringMatching(/^v2-to-v3-system-[0-9a-f]{64}$/),
+        id: expect.stringMatching(/^v2-to-v3-system-[0-9a-f]{64}$/) as unknown,
         role: 'system', content: [], source: { kind: 'plugin', plugin: '@deepseek-ai/dsh-system-prompt' },
       } },
     },
@@ -875,7 +875,7 @@ describe('JsonlSessionPersistence: immutable format generations', () => {
 
     await expect(ctx.sessionPersistence.open(id, access)).rejects.toMatchObject({
       name: 'SessionFormatUnsupportedError',
-      message: expect.stringContaining('surface before first step'),
+      message: expect.stringContaining('surface before first step') as unknown,
     })
     await ctx.sessionPersistence.flush()
 

+ 11 - 9
packages/test-support/llm-replay/tests/session-format-corpus.spec.ts

@@ -104,33 +104,35 @@ describe('corpus unsupported policy', () => {
   const refused = (): never => { throw new SessionFormatUnsupportedMigrationError(refusal.reason) }
 
   it('rejects an unlisted migration refusal', () => {
-    expect(() => assertRestoration('unlisted', 2, refused, undefined)).toThrow('current-format restoration')
+    expect(() => { assertRestoration('unlisted', 2, refused, undefined) }).toThrow('current-format restoration')
   })
 
   it('rejects an exception that starts restoring successfully', () => {
-    expect(() => assertRestoration('supported', 2, () => [], refusal)).toThrow('expected unsupported migration')
+    expect(() => { assertRestoration('supported', 2, () => [], refusal) }).toThrow('expected unsupported migration')
   })
 
   it('rejects a changed refusal reason', () => {
-    expect(() => assertRestoration('changed', 2, refused, { ...refusal, reason: 'different' })).toThrow('exact refusal reason')
+    expect(() => { assertRestoration('changed', 2, refused, { ...refusal, reason: 'different' }) }).toThrow('exact refusal reason')
   })
 
   it('rejects corruption masquerading as an unsupported migration', () => {
-    expect(() => assertRestoration('corrupt', 2, () => { throw new Error(refusal.reason) }, refusal))
+    expect(() => { assertRestoration('corrupt', 2, () => { throw new Error(refusal.reason) }, refusal) })
       .toThrow('expected unsupported migration')
   })
 
   it('rejects a mismatched source generation', () => {
-    expect(() => assertRestoration('wrong-version', 1, refused, refusal)).toThrow('inventoried source generation')
+    expect(() => { assertRestoration('wrong-version', 1, refused, refusal) }).toThrow('inventoried source generation')
   })
 
   it('never exempts a current-generation fixture', () => {
-    expect(() => assertRestoration('current', SESSION_FORMAT_VERSION, refused, {
-      ...refusal, sourceVersion: SESSION_FORMAT_VERSION,
-    })).toThrow('current-generation fixtures cannot be unsupported')
+    expect(() => {
+      assertRestoration('current', SESSION_FORMAT_VERSION, refused, {
+        ...refusal, sourceVersion: SESSION_FORMAT_VERSION,
+      })
+    }).toThrow('current-generation fixtures cannot be unsupported')
   })
 
   it('accepts only the exact typed historical refusal', () => {
-    expect(() => assertRestoration('historical', 2, refused, refusal)).not.toThrow()
+    expect(() => { assertRestoration('historical', 2, refused, refusal) }).not.toThrow()
   })
 })