Skip to content

fix(test): make e2e API-key extraction robust to NUL/ANSI log bytes (MCP-2404) - #668

Merged
Dumbris merged 1 commit into
mainfrom
fix/mcp-2404-e2e-grep-binary
Jun 15, 2026
Merged

fix(test): make e2e API-key extraction robust to NUL/ANSI log bytes (MCP-2404)#668
Dumbris merged 1 commit into
mainfrom
fix/mcp-2404-e2e-grep-binary

Conversation

@Dumbris

@Dumbris Dumbris commented Jun 14, 2026

Copy link
Copy Markdown
Member

Summary

Local QA harness fix (not a product bug). ./scripts/test-api-e2e.sh deterministically exits 1 at startup on local macOS — 30× "server not ready yet" with Extracted API key: Binary f... — so no tests run.

Root cause

extract_api_key() used grep -o '"api_key": "[^"]*"' over /tmp/mcpproxy_e2e.log. The server log can contain a NUL byte (and ANSI color codes), so grep treats the file as binary and emits Binary file … matches instead of the match. That string becomes $API_KEY → every authed curl is rejected → wait_for_server times out → exit 1. CI uses a different log path, so it slips through there.

Fix

  • Add -a to the grep so it always treats the log as text.
  • Parameterize the log path (optional $1, defaults to the existing hardcoded path) so the function is unit-testable; all existing no-arg callers are unaffected.
  • Add scripts/test-extract-api-key.sh, which extracts the real extract_api_key() from test-api-e2e.sh and asserts it recovers the key from a fixture log containing ANSI escapes + a NUL byte.

Verification (TDD)

  • RED — against the unfixed grep: FAIL: ... got 'Binary file /…/mcpproxy_e2e_fixture… matches' (reproduces the exact symptom).
  • GREEN — against the fix: PASS: extract_api_key() returned the key from a NUL/ANSI log.
  • bash -n clean on both files; shellcheck clean on the new test.

No Go / CLI / REST / MCP / config / docs surface is touched.

Related MCP-2404

extract_api_key() used `grep -o` over /tmp/mcpproxy_e2e.log. The server
log can contain NUL bytes (and ANSI color codes), so grep treats the file
as binary and prints "Binary file ... matches" instead of the match. That
string lands in $API_KEY, so every authed curl is rejected and
wait_for_server times out — test-api-e2e.sh exits 1 before any test runs
(reproduces deterministically on local macOS; CI uses a different log path
so it slips through).

Add `-a` to force grep to treat the log as text, and parameterize the log
path so the function is unit-testable. Add scripts/test-extract-api-key.sh,
which extracts the real function and asserts it recovers the key from a
fixture log containing ANSI escapes and a NUL byte.

Related MCP-2404
@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying mcpproxy-docs with  Cloudflare Pages  Cloudflare Pages

Latest commit: 7fcbff6
Status: ✅  Deploy successful!
Preview URL: https://042ede5f.mcpproxy-docs.pages.dev
Branch Preview URL: https://fix-mcp-2404-e2e-grep-binary.mcpproxy-docs.pages.dev

View logs

@github-actions

Copy link
Copy Markdown

📦 Build Artifacts

Workflow Run: View Run
Branch: fix/mcp-2404-e2e-grep-binary

Available Artifacts

  • archive-darwin-amd64 (28 MB)
  • archive-darwin-arm64 (25 MB)
  • archive-linux-amd64 (16 MB)
  • archive-linux-arm64 (14 MB)
  • archive-windows-amd64 (28 MB)
  • archive-windows-arm64 (25 MB)
  • frontend-dist-pr (0 MB)
  • installer-dmg-darwin-amd64 (21 MB)
  • installer-dmg-darwin-arm64 (19 MB)

How to Download

Option 1: GitHub Web UI (easiest)

  1. Go to the workflow run page linked above
  2. Scroll to the bottom "Artifacts" section
  3. Click on the artifact you want to download

Option 2: GitHub CLI

gh run download 27501721374 --repo smart-mcp-proxy/mcpproxy-go

Note: Artifacts expire in 14 days.

@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@mcpproxy-gatekeeper mcpproxy-gatekeeper Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Approved via Claude Code review (Codex back online; reviewed by pr-reviewer subagent). One-line grep -ao fix for NUL/ANSI log bytes + self-contained unit test. Test-only, no production impact.

@Dumbris
Dumbris merged commit 7bd26b8 into main Jun 15, 2026
35 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.

2 participants