mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-05 12:24:30 +01:00
fix(goals): validate the goal RPC output before returning it
This commit is contained in:
1 parent
cbe92c92ad
commit
5db74e3fa7
2 files changed
+13
-1
No files matched your search
@@ -91,6 +91,15 @@ describe('readSessionGoal', () => {
|
||||
})
|
||||
})
|
||||
|
||||
it.each([
|
||||
['an unknown status', goalWith({ status: 'bogus' as GoalState['status'] })],
|
||||
['a missing objective', goalWithout('objective')],
|
||||
['a non-object output', 'not a goal'],
|
||||
])('reports a goal with %s as unsupported', async (_label, output) => {
|
||||
const call = vi.fn().mockResolvedValue({ output })
|
||||
await expect(readSessionGoal(createApi(call), { sessionID: SESSION_ID })).resolves.toEqual({ supported: false })
|
||||
})
|
||||
|
||||
it('reports an unavailable rpc as unsupported', async () => {
|
||||
const call = vi.fn().mockRejectedValue(rpcError('rpc.unavailable', 'RPC is unavailable: opencode.goal'))
|
||||
await expect(readSessionGoal(createApi(call), { sessionID: SESSION_ID })).resolves.toEqual({ supported: false })
|
||||
|
||||
@@ -50,7 +50,10 @@ export async function readSessionGoal(
|
||||
input: { sessionID: input.sessionID },
|
||||
...(input.directory ? { location: { directory: input.directory } } : {}),
|
||||
})
|
||||
return { supported: true, goal: (result.output ?? null) as GoalState | null }
|
||||
const output: unknown = result.output ?? null
|
||||
if (output === null) return { supported: true, goal: null }
|
||||
if (!isGoalState(output)) return { supported: false }
|
||||
return { supported: true, goal: output }
|
||||
} catch (error) {
|
||||
if (isRpcError(error) && error.type === 'rpc.unavailable') return { supported: false }
|
||||
throw error
|
||||
|
||||
Reference in new issue
Block a user