style: clear the lint lane — drop redundant assertions and non-thenable awaits

eslint --fix removed the no-unnecessary-type-assertion hits the review
knives introduced; the two await-thenable errors were vi.runAllTicks()
awaits in the cache spec, replaced with advanceTimersByTimeAsync(0) (the
fake-timer-safe microtask drain). Repo-wide eslint, dual-aggregate tsc,
and the focused 100% coverage set all green.
This commit is contained in:
imccyu
2026-07-28 13:02:21 +08:00
parent 019dd7d894
commit 931dd934e3
3 changed files with 10 additions and 10 deletions

View File

@@ -39,7 +39,7 @@ const marksUnit = (stateVersion = 1): ProjectionDefinition<'cache-test/marks', M
key: 'cache-test/marks',
schema: z.object({ marks: z.array(z.string()) }),
init: () => null,
apply: (state, event) => (event.type === 'cache-test/mark' ? (event as SessionEvent<'cache-test/mark'>).data : state),
apply: (state, event) => (event.type === 'cache-test/mark' ? (event).data : state),
view: state => state ?? { marks: [] },
stateVersion,
})
@@ -163,7 +163,7 @@ describe('SessionProjectionCache write policy', () => {
await vi.advanceTimersByTimeAsync(249)
expect(storedRows(pool, session.id)).toBeUndefined()
await vi.advanceTimersByTimeAsync(1)
await vi.runAllTicks()
await vi.advanceTimersByTimeAsync(0)
expect(storedRows(pool, session.id)?.['cache-test/marks']?.state).toEqual({ marks: ['slow'] })
})
@@ -181,7 +181,7 @@ describe('SessionProjectionCache write policy', () => {
apply: (state: unknown) => state,
view: () => null as never,
stateVersion: 1,
} as never)
})
await expect(ctx.sessionProjectionCache.write(clean)).rejects.toThrow('not losslessly JSON-serializable')
})
@@ -193,7 +193,7 @@ describe('SessionProjectionCache write policy', () => {
mark(armed, ['pending']) // timer armed, no write yet
mark(cleaned, ['done'])
endTurn(cleaned) // mandatory write; markClean leaves {pending: 0, timer: undefined} in the map
await vi.runAllTicks()
await vi.advanceTimersByTimeAsync(0)
await fiber.dispose()
// The armed timer died with the plugin: advancing time writes nothing.
await vi.advanceTimersByTimeAsync(10_000)
@@ -224,7 +224,7 @@ describe('SessionProjectionCache cold read', () => {
{ type: 'turn/start', seq: 0, time: 0, data: { turn: 1, trigger: { kind: 'message', source: { kind: 'user' } } } },
]
for (const m of marks) {
events.push({ type: 'cache-test/mark', seq: events.length, time: events.length, data: { marks: m } } as SessionEvent)
events.push({ type: 'cache-test/mark', seq: events.length, time: events.length, data: { marks: m } })
}
events.push({ type: 'turn/end', seq: events.length, time: events.length, data: { turn: 1, reason: { kind: 'completed' } } })
return events

View File

@@ -300,7 +300,7 @@ export class SessionProjectionRegistry extends Service {
if (row === undefined || row.stateVersion !== def.stateVersion) continue
values[def.key] = def.schema.parse(def.view(row.state))
}
return values as Partial<SessionProjectionMap>
return values
}
/**
@@ -352,7 +352,7 @@ export class SessionProjectionRegistry extends Service {
refreshed[def.key] = { stateVersion: def.stateVersion, observedSeq: endSeq, state }
}
return {
snapshot: { asOfSeq: endSeq, values: values as ProjectionSnapshot['values'] },
snapshot: { asOfSeq: endSeq, values: values },
checkpoint: refreshed,
}
}

View File

@@ -224,7 +224,7 @@ describe('SessionProjectionRegistry drive', () => {
ctx.sessionProjections.register(marksUnit())
ctx.sessionProjections.register(countUnit())
const tail: SessionEvent[] = [
{ type: 'test/mark', seq: 3, time: 3, data: { marks: ['new'] } } as SessionEvent,
{ type: 'test/mark', seq: 3, time: 3, data: { marks: ['new'] } },
{ type: 'turn/end', seq: 4, time: 4, data: { turn: 1, reason: { kind: 'completed' } } },
]
// marks row usable (watermark 2, tail starts at 3); count row mismatched — but
@@ -236,8 +236,8 @@ describe('SessionProjectionRegistry drive', () => {
// The full-log re-read (baseSeq 0) refolds the mismatched key from init.
const full: SessionEvent[] = [
{ type: 'turn/start', seq: 0, time: 0, data: { turn: 1, trigger: { kind: 'message', source: { kind: 'user' } } } },
{ type: 'test/mark', seq: 1, time: 1, data: { marks: ['old'] } } as SessionEvent,
{ type: 'test/mark', seq: 2, time: 2, data: { marks: ['old', '2'] } } as SessionEvent,
{ type: 'test/mark', seq: 1, time: 1, data: { marks: ['old'] } },
{ type: 'test/mark', seq: 2, time: 2, data: { marks: ['old', '2'] } },
...tail,
]
const { snapshot, checkpoint } = ctx.sessionProjections.restore({