Skip to content

test(claude-code): authenticate the real-host E2E with the saved credential - #2707

Merged
hidb4ai merged 1 commit into
oceanbase:masterfrom
Fengzdadi:test/claude-code-e2e-saved-credential
Nov 18, 2026
Merged

hidb4ai merged 1 commit into
oceanbase:masterfrom
Fengzdadi:test/claude-code-e2e-saved-credential

Conversation

@Fengzdadi

@Fengzdadi Fengzdadi commented Nov 18, 2026 •

Copy link
Copy Markdown
Collaborator

Which issue or RFC does this PR close?

No tracking issue. It follows the real-host Claude Code E2E (#2686) and the plugin MCP headersHelper that reads the saved credential (#2669).

Rationale for this change

The documented Claude Code path is that powercontext setup claude-code saves the client's POWERCONTEXT_CLAUDE_AUTHORIZATION for its server_url. The hooks read that saved credential when the variable is not set, and the plugin MCP server gets it from the headersHelper (scripts/mcp_headers.py). The static ${POWERCONTEXT_CLAUDE_AUTHORIZATION:-} header in .mcp.json applies only when nothing is saved.

The real-host E2E set POWERCONTEXT_CLAUDE_AUTHORIZATION for every claude run. The hooks therefore used the variable, and MCP authenticated through the static header. Removing the static header from .mcp.json failed the tools case, and removing headersHelper did not. The suite did not cover the saved-credential path that sessions without the variable depend on. The E2E token also contains only letters and hyphens. Claude Code 2.1.277 removes credential-like values (digits, _ + / =) from a headersHelper's environment, the cause of #1530, so the old setup also hid that stripping.

What changes are included in this PR?

  • tests/e2e/test_claude_code_host_service_chain.py:
    • Only setup receives POWERCONTEXT_CLAUDE_AUTHORIZATION. It saves the credential for this Server under $CLAUDE_CONFIG_DIR/powercontext/credentials.json.
    • claude runs without the variable. An inherited value from the developer's or CI's environment was already dropped with the other POWERCONTEXT_* variables; the comment now says why that matters here.
    • The hooks now authenticate with the saved credential (the Server is loopback), and MCP authenticates with the header from headersHelper.
    • The fixture asserts that setup reports authorization_state == "configured", so a credential that setup did not save fails at setup and names the cause, not later as a missing prepare record or a failed MCP server.

The hook scripts' handling of an exported POWERCONTEXT_CLAUDE_AUTHORIZATION stays covered by tests/e2e/test_claude_code_service_chain.py, which runs them directly against a Server. This suite does not exercise Claude Code's expansion of the static .mcp.json header: whenever setup has saved a credential, the headersHelper header replaces it.

No plugin, product, CI or documentation change. Nothing in .github/ or docs/ described this E2E's credential handling.

Are there any user-facing changes?

No. This PR changes one test.

How was this change tested?

  • CLAUDE_CODE_CLI_BIN=<claude 2.1.277> UV_OFFLINE=1 uv run --frozen pytest tests/e2e/test_claude_code_host_service_chain.py tests/e2e/test_host_model_messages.py -v, the files the claude-code-host job runs, on macOS (arm64): 4 passed in each of three runs, in 15.4, 15.8 and 17.2 s. Not run on Linux locally; the claude-code-host job runs on Linux.

  • The same cases with POWERCONTEXT_CLAUDE_AUTHORIZATION="Bearer wrong-inherited-value" exported in the outer environment: 3 passed, so an inherited value does not reach claude.

  • A temporary probe in mcp_headers.py, reverted afterwards, logged each headersHelper run in all three cases. Each run had CLAUDE_CONFIG_DIR, no POWERCONTEXT_CLAUDE_AUTHORIZATION, and CLAUDE_CODE_MCP_SERVER_URL set to this Server's /mcp endpoint, and each emitted the saved Authorization header.

  • Each mutation below was applied, the cases were run, and the files were restored and checked byte for byte with sha256:

    Mutation Result
    .mcp.json without headersHelper tools fails: claude_turn_error_400: API Error: 400 fixture_tool_unavailable_remember_memory, because the MCP server failed to connect and offered no tools
    mcp_headers.py always emits {} tools fails with the same error; mcp_servers reports plugin:powercontext:powercontext as failed
    .mcp.json without the static headers block 3 passed, as expected: MCP no longer depends on the variable
    Setup runs without the variable, so nothing is saved all three cases fail at setup with powercontext_setup_saved_no_credential (not_configured)
    Same, with the setup assertion also removed recall fails (no captured Source; the hook reports authentication_failed), bootstrap fails (no bootstrap record), tools fails (fixture_tool_unavailable_remember_memory)
  • uv run ruff check and uv run ruff format --check on the changed file; UV_OFFLINE=1 uv run --frozen pytest tests/claude_code_plugin -q: 150 passed; make check, including ty: passed.

AI usage statement

Claude Code (Claude Opus 5.5) wrote the change and this description, and ran the verification above.

…ential

Only setup receives POWERCONTEXT_CLAUDE_AUTHORIZATION, and claude runs without it, so the hooks read the credential setup saved and the plugin MCP server gets it from its headersHelper, as in a session that does not inherit the variable. The fixture now fails early when setup saved no credential.
@Fengzdadi
Fengzdadi requested a review from PsiACE as a code owner November 18, 2026 03:42

@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.

Reviewed efacf75. No blocking findings. Restricting the authorization environment variable to setup correctly exercises saved-credential authentication for hooks and MCP, and the setup assertion makes missing persistence fail early. This test-only change adds no database tables or public interfaces.

Validated the four host/model cases on Linux with Claude Code 2.1.277 and the frozen dependency environment, including an incorrect inherited authorization value; all passed. The 150 plugin tests and changed-file Ruff checks also passed. CI is green. This verifies the real host/plugin/Server chain with fixture models, not live-provider behavior. Merge confidence: 90/100.

@hidb4ai
hidb4ai merged commit 5164a76 into oceanbase:master Nov 18, 2026
44 checks passed
@hidb4ai hidb4ai added the 1.6.0 v1.6.0 release tracking label Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

1.6.0 v1.6.0 release tracking

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants