fix(swarm): treat missing worker chat state.db as no-session, not error (#232)
Swarm worker chat readers currently surface a raw "state.db missing" error when a worker profile hasn't been provisioned yet. Treat that condition as "no session" — return an empty message list rather than propagating the file-not-found exception to the UI. Adds a regression test in swarm-chat-reader.test.ts covering the missing state.db path. Worked with Interstellar Code
This commit is contained in:
committed by
GitHub
parent
e230a501ff
commit
00bbace2e1
25
src/server/swarm-chat-reader.test.ts
Normal file
25
src/server/swarm-chat-reader.test.ts
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
import { mkdtempSync, rmSync } from 'node:fs'
|
||||||
|
import { tmpdir } from 'node:os'
|
||||||
|
import { join } from 'node:path'
|
||||||
|
import { describe, expect, it } from 'vitest'
|
||||||
|
import { readWorkerMessages } from './swarm-chat-reader'
|
||||||
|
|
||||||
|
describe('readWorkerMessages', () => {
|
||||||
|
it('treats a missing state.db as an unavailable session, not a UI error', () => {
|
||||||
|
const profilePath = mkdtempSync(join(tmpdir(), 'swarm-chat-reader-'))
|
||||||
|
|
||||||
|
try {
|
||||||
|
const result = readWorkerMessages(profilePath, 30)
|
||||||
|
|
||||||
|
expect(result).toEqual({
|
||||||
|
sessionId: null,
|
||||||
|
sessionTitle: null,
|
||||||
|
messages: [],
|
||||||
|
ok: false,
|
||||||
|
})
|
||||||
|
expect(result.error).toBeUndefined()
|
||||||
|
} finally {
|
||||||
|
rmSync(profilePath, { recursive: true, force: true })
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
@@ -147,7 +147,6 @@ export function readWorkerMessages(profilePath: string, limit: number): SwarmCha
|
|||||||
sessionTitle: null,
|
sessionTitle: null,
|
||||||
messages: [],
|
messages: [],
|
||||||
ok: false,
|
ok: false,
|
||||||
error: `state.db missing at ${dbPath}`,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
|
|||||||
Reference in New Issue
Block a user