test(time-context): cover formatter invariant failure

This commit is contained in:
Tianyi Cui
2026-08-09 20:58:06 +08:00
parent 7667efe1c6
commit 1e6e92fb0a

View File

@@ -1,5 +1,5 @@
import { createUserMessage } from '@deepseek-ai/dsh-llm'
import { describe, expect, it } from 'vitest'
import { describe, expect, it, vi } from 'vitest'
import { Context } from 'cordis'
import type { ContentBlock } from '@deepseek-ai/dsh-llm'
import SessionStore, { Session, SessionId, type SessionEvent } from '@deepseek-ai/dsh-session'
@@ -128,6 +128,27 @@ describe('time-context invariants', () => {
}).toThrow(/rendered timestamp does not match the unique browser zone/)
})
it('reports browser-zone timestamp formatter failures as invariant violations', async () => {
const ctx = await setup()
const policy = 'Browser time zone for this request: Asia/Shanghai. '
+ 'Interpret otherwise-unqualified dates and times in this zone.'
const formatToParts = vi.spyOn(Intl.DateTimeFormat.prototype, 'formatToParts')
.mockImplementationOnce(() => { throw new RangeError('formatter unavailable') })
try {
expect(() => {
ctx.emit('session/event', preparing(1, 1, 'Asia/Shanghai'), event(reading(
'1',
'1',
'model-visible message',
'2026-07-14T08:00:00+08:00[Asia/Shanghai]',
policy,
)))
}).toThrow(/browser zone cannot format its durable timestamp: RangeError: formatter unavailable/)
} finally {
formatToParts.mockRestore()
}
})
it('rejects invalid browser provenance loaded across the durable boundary', async () => {
const ctx = await setup()
const timeZone = 'Not/A_Real_Zone'