Skip to content

test(codex): init lifecycle + cache invalidation + API-key resolution - #179

Merged
claudiusthebot merged 2 commits into
mainfrom
feat/codex-polish-4
May 16, 2026
Merged

test(codex): init lifecycle + cache invalidation + API-key resolution#179
claudiusthebot merged 2 commits into
mainfrom
feat/codex-polish-4

Conversation

@claudiusthebot

Copy link
Copy Markdown
Collaborator

9 new tests for Codex backend init lifecycle invariants. Includes:

  • ensureCodex throws if called before init
  • Same chat id β†’ cached instance
  • Different chat id β†’ fresh instance
  • Re-init invalidates cache
  • API-key precedence (env > config)
  • Falls back to config key when env absent

2314 passing (was 2305), 0 failing.

πŸ€– Generated with Claude Code

@claudiusthebot
claudiusthebot enabled auto-merge (squash) May 16, 2026 00:18
9 new tests in `codex-init.test.ts` covering the Codex backend's
state-lifecycle invariants that aren't exercisable through the
factory test alone:

- `ensureCodex` throws if called before `initCodexAgent`
- Same chat id β†’ cached instance returned
- Different chat id β†’ fresh instance built
- Same chat id after chat-switch β†’ cached again
- `initCodexAgent` re-invocation invalidates the cached instance
  (this is the new behaviour from `docs/backends.md` PR #178)
- Re-init with the same config still invalidates (defensive default)
- Gateway port + frontend label captured on init
- OPENAI_API_KEY env wins over config.openaiApiKey
- Falls back to config.openaiApiKey when env is absent
- Uses env-only when no config key provided

Total: 2314 passing (was 2305), 12 skipped (live), 0 failing.
tsc clean, lint 0 errors / 15 pre-existing warnings.
Previously `talon doctor` always checked for the Claude Code CLI on
PATH, even when the active backend was `kilo` / `opencode` / `codex`.
Result: a Codex user running `doctor` would get a false-positive
"Claude Code not found" issue count.

Now the doctor reads `backend` from the config and checks the right
thing:

- `claude`: looks for `claude` on PATH (or honours `claudeBinary`
  config). Same as before.
- `codex`: looks for `codex` on PATH (`npm i -g @openai/codex` hint
  if missing). Plus checks for OpenAI auth β€” accepts any of:
  `OPENAI_API_KEY` env, `openaiApiKey` in talon.json, or
  `~/.codex/auth.json` (left behind by `codex login`).
- `kilo` / `opencode`: notes that the SDK is bundled (no external
  binary to check).

`Config` type in cli.ts gained `backend?: ... | "codex"` and
`openaiApiKey?: string` to match the runtime schema in
`util/config.ts`.

Tests: 2314 passing (unchanged), 12 skipped, 0 failing.
@claudiusthebot
claudiusthebot merged commit 29135b9 into main May 16, 2026
31 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant