mirror of
https://github.com/wu736139669/hapi.git
synced 2026-08-05 06:24:37 +00:00
fix(hub,cli): coerce null session activeAt so resume cannot 500 (#1026)
Legacy rows and inserts left sessions.active_at NULL while SessionSchema required a number, so CLI GET /cli/sessions/:id failed Zod and resume surfaced HTTP 500. Persist active_at on insert, harden hub read coerce, and nullish-transform activeAt in SessionSchema (output stays number). Fixes #1025 Co-authored-by: Debian <heavygee@oos-linux.in.lockhouse> Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
co-authored by
Debian
Cursor
parent
f6ad345339
commit
8ee04500b9
@@ -0,0 +1,49 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { SessionSchema } from './schemas'
|
||||
|
||||
function baseSession(overrides: Record<string, unknown> = {}) {
|
||||
return {
|
||||
id: '11111111-1111-4111-8111-111111111111',
|
||||
namespace: 'default',
|
||||
seq: 0,
|
||||
createdAt: 1_000,
|
||||
updatedAt: 2_000,
|
||||
active: false,
|
||||
activeAt: 1_000,
|
||||
metadata: null,
|
||||
metadataVersion: 0,
|
||||
agentState: null,
|
||||
agentStateVersion: 0,
|
||||
thinking: false,
|
||||
thinkingAt: 0,
|
||||
...overrides
|
||||
}
|
||||
}
|
||||
|
||||
describe('SessionSchema activeAt coerce', () => {
|
||||
it('keeps a numeric activeAt unchanged', () => {
|
||||
const parsed = SessionSchema.safeParse(baseSession({ activeAt: 42 }))
|
||||
expect(parsed.success).toBe(true)
|
||||
if (parsed.success) {
|
||||
expect(parsed.data.activeAt).toBe(42)
|
||||
}
|
||||
})
|
||||
|
||||
it('coerces null activeAt to 0 without failing parse', () => {
|
||||
const parsed = SessionSchema.safeParse(baseSession({ activeAt: null }))
|
||||
expect(parsed.success).toBe(true)
|
||||
if (parsed.success) {
|
||||
expect(parsed.data.activeAt).toBe(0)
|
||||
}
|
||||
})
|
||||
|
||||
it('coerces missing activeAt to 0 without failing parse', () => {
|
||||
const raw = baseSession()
|
||||
delete (raw as { activeAt?: number }).activeAt
|
||||
const parsed = SessionSchema.safeParse(raw)
|
||||
expect(parsed.success).toBe(true)
|
||||
if (parsed.success) {
|
||||
expect(parsed.data.activeAt).toBe(0)
|
||||
}
|
||||
})
|
||||
})
|
||||
@@ -212,7 +212,8 @@ export const SessionSchema = z.object({
|
||||
createdAt: z.number(),
|
||||
updatedAt: z.number(),
|
||||
active: z.boolean(),
|
||||
activeAt: z.number(),
|
||||
// Hub may still emit null for legacy SQLite rows; keep output type number.
|
||||
activeAt: z.number().nullish().transform((value) => value ?? 0),
|
||||
metadata: MetadataSchema.nullable(),
|
||||
metadataVersion: z.number(),
|
||||
agentState: AgentStateSchema.nullable(),
|
||||
|
||||
Reference in New Issue
Block a user