Skip to content

test(e2e): run real Codex with the PowerContext plugin against a Server in CI - #2624

Merged
hidb4ai merged 3 commits into
oceanbase:masterfrom
Fengzdadi:test/codex-real-host-e2e
Nov 14, 2026
Merged

hidb4ai merged 3 commits into
oceanbase:masterfrom
Fengzdadi:test/codex-real-host-e2e

Conversation

@Fengzdadi

Copy link
Copy Markdown
Collaborator

Which issue or RFC does this PR close?

No tracking issue. It follows the real-host service chains for Pi (#2531) and OpenCode (#2533). Codex was covered only by calling the plugin's hook scripts directly, so regressions that depend on what Codex itself sends, such as #2287 (fork SessionStart), only surfaced with a manual run.

Rationale for this change

tests/e2e/test_codex_service_chain.py and tests/codex_plugin/ invoke recall.py, session_binding.py and bind_tools.py with hand-built payloads. They cannot catch changes in Codex's hook payloads, in when Codex runs each hook, in how it offers and approves MCP tools, or in hook trust. This PR runs the real codex exec against an in-process Server, installed and trusted the way a user does it.

What changes are included in this PR?

  • tests/e2e/test_codex_host_service_chain.py runs Codex CLI 0.167.2 (CODEX_CLI_BIN) with an isolated HOME, CODEX_HOME and XDG directories. Inherited POWERCONTEXT_*, CODEX_*, OPENAI_* and proxy variables are dropped.
    • The plugin is installed by powercontext setup codex from this checkout, which also saves the Server credential and the MCP header helper. codex exec runs without POWERCONTEXT_CODEX_AUTHORIZATION, so hooks and MCP use the saved credential.
    • The four plugin hooks are trusted through Codex's own app-server (hooks/list, then config/batchWrite of hooks.state), the calls the TUI's /hooks review makes.
    • The fixture builds the plugin's uv environment once after setup. Otherwise the MCP header helper and the SessionStart hook both build it while Codex starts, and on a loaded machine MCP startup misses the first model request.
    • The Server runs in-process with SQLite, bearer auth and no memory schedule; cases flush explicitly.
  • Cases:
    • A prompt captured in one session becomes Memory, and a later session's first model request carries the prepared context unchanged after the prompt. A prompt with a recognized credential is not captured, and the credential never reaches the Server.
    • A resumed session keeps the Scope it bound at startup after the workspace binding changes; a new session follows the new binding. SessionStart runs for startup, resume, startup.
    • With POWERCONTEXT_CODEX_BOOTSTRAP_CONTEXT=true, tagged bootstrap Memory precedes the first prompt once, the receipt is recorded as injected, and the turn's preparation carries the receipt and does not repeat it. Without the setting, only prompt-time recall supplies it.
    • A remember_memory call is refused by codex exec until the tool is approved in the Codex configuration. After approval it writes to the session's Scope although the model names another Scope, and search_memory finds it.
    • POWERCONTEXT_CODEX_PROMPT_RECALL and POWERCONTEXT_CODEX_CAPTURE_PROMPTS act independently.
  • tests/e2e/host_models/ holds a wire-neutral ScriptedTurns script and a streamed /v1/responses fake (ResponsesModelFixture). Codex 0.167 accepts only wire_api = "responses" for a custom provider and offers MCP tools as a mcp__powercontext namespace tool. A Messages API fake can sit beside it. zcode_acceptance/protocol.py is unchanged; its HostModelFixture still serves the Server's generation model.
  • CI: a codex-host job in master.yml installs @openai/codex@0.167.2 from npm, checks codex --version, refuses to run without the binary, runs the cases and uploads codex.log on failure. .github/ci-paths.toml adds a codex suite for the Codex plugin, the new test and fixtures, and the shared ZCode wire fixtures, and adds it to the shared runtime consumers. tests/test_ci_changes.py covers the new rows.

Are there any user-facing changes?

No. This PR changes tests and CI only.

Observations from the real host, not changed here:

  • Codex asks for approval before any PowerContext MCP tool that is not marked read-only, even when the PreToolUse hook answers allow. Under codex exec with approval_policy = "never" the call fails. The Codex integration docs do not mention this.
  • On the first session after setup, the MCP header helper and the hooks build the plugin's uv environment concurrently. Locally under parallel load this made the first session start without PowerContext MCP tools (the server is required: false). Setup could build that environment at install time; that would be a separate change.
  • The gateway path (bug(inference): an unmodified Codex 0.145 cannot complete a turn through an enforcing Server #2420) is not exercised: Codex talks to the model fake directly.

How was this change tested?

  • CODEX_CLI_BIN=<codex 0.167.2> uv run pytest tests/e2e/test_codex_host_service_chain.py on macOS (arm64): 5 passed in about 26 s, also three times in a row with -n 5. Without CODEX_CLI_BIN the cases skip.

  • Each mutation below was applied, the cases were run, and the change was reverted:

    Mutation Failing cases
    Prompt hook returns empty additionalContext recall, bootstrap
    Capture a prompt containing a recognized credential recall
    Recall ignores POWERCONTEXT_CODEX_PROMPT_RECALL settings
    Capture ignores POWERCONTEXT_CODEX_CAPTURE_PROMPTS settings
    Prepare omits the bootstrap receipt bootstrap
    SessionStart does not persist the Session binding resume
    SessionStart injects no bootstrap context bootstrap
    PreToolUse keeps the model's scope_id tools
    SessionStart matcher drops resume resume
    Server marks remember_memory read-only (no approval needed) tools
    Setup writes no MCP http_headers_helper all five
  • make check; uv run pytest tests/test_ci_changes.py tests/test_ci_pipeline.py.

  • The codex-host job itself has not run yet; the npm install path is first exercised by this PR's CI.

  • A self-review (code-review, high) found six issues. Five are fixed: a timed-out codex exec lost its output, the fake failed on a repeated call in a request without tools, the credential check skipped incomplete requests, a malformed event line crashed parsing, and a dead thread-id fallback hid a missing thread.started. Not changed: the Scope and flush helpers repeat the OpenCode test's; sharing them would touch that test.

AI usage statement

Claude Code (Claude Opus 5.5) wrote the test, the model fake, the CI wiring and this description, and ran the local verification.

Copilot AI balanced review requested due to automatic review settings November 13, 2026 07:12

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

@hidb4ai hidb4ai left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new host test still races MCP discovery on Linux, and the Responses fixture has a reproducible pending-call replay error. Details are inline. Full tool-chain acceptance remains unverified: making MCP required in a disposable startup probe got the initial approval-denial step through, but the resumed search_memory call then returned HTTP 422 (invalid_access_request).

Comment thread tests/e2e/host_models/responses.py Resolved
The Responses fake repeats a call whose result the host has not returned
yet, at the address it first issued. `setdefault` still evaluated the
lookup in the request's own tool list, so a repeat in a request that
offered no tools raised KeyError and the fake answered 500. Look the
address up only for a new call.
The plugin's MCP server is optional, and Codex lists a session's first
tools after a one-second grace whether or not it has connected. On a slow
runner the first scripted tool call then finds no PowerContext tools.
Set mcp_optional_startup_grace_ms = 0 so Codex waits for the server, up to
its startup timeout, before the first model request.

@hidb4ai hidb4ai left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-reviewed at f7332c8. Both previous findings are fixed. The real Codex flow now completes approval, session-scope binding, Memory writes and search on Linux with Codex 0.167.2, Python 3.12, SQLite and fixture models. The change remains confined to tests and CI.

@hidb4ai
hidb4ai merged commit 1bc12af into oceanbase:master Nov 14, 2026
13 checks passed
@hidb4ai hidb4ai added the 1.5.2 v1.5.2 release tracking label Nov 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

1.5.2 v1.5.2 release tracking

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants