Files
orca/src/shared/require-tui-agent-config.test.ts
T
Jinjing b76a47e468 Add requireTuiAgentConfig to validate agent ids (#16310)
Agent ids persist in automations and settings, so they outlive the
build that wrote them. Direct config lookups fail with unclear
"Cannot read properties of undefined" when an id becomes unknown.
This function validates the agent and throws a clear error message
naming the unknown id.
2026-08-24 15:28:59 -07:00

22 lines
969 B
TypeScript

import { describe, expect, it } from 'vitest'
import type { TuiAgent } from './tui-agent'
import { requireTuiAgentConfig } from './require-tui-agent-config'
describe('requireTuiAgentConfig', () => {
it('returns the config for a known agent', () => {
expect(requireTuiAgentConfig('codex').preflightTrust).toBe('codex')
})
it('names the unknown id instead of throwing a property-of-undefined error', () => {
// A custom-agent id persisted by a branch build, read back by one without the feature.
const stale = 'custom-agent:codex:b2e1ff6f-8932-413a-9133-edffa44e0ee9' as TuiAgent
expect(() => requireTuiAgentConfig(stale)).toThrow(
`Unknown agent "${stale}". This version of Orca has no such agent — pick a different agent and try again.`
)
})
it('rejects a prototype key that Object.hasOwn keeps off the config', () => {
expect(() => requireTuiAgentConfig('toString' as TuiAgent)).toThrow(/Unknown agent "toString"/)
})
})