fix(test): make e2e API-key extraction robust to NUL/ANSI log bytes (MCP-2404) - #668
Merged
Conversation
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
Deploying mcpproxy-docs with
|
| 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 |
📦 Build ArtifactsWorkflow Run: View Run Available Artifacts
How to DownloadOption 1: GitHub Web UI (easiest)
Option 2: GitHub CLI gh run download 27501721374 --repo smart-mcp-proxy/mcpproxy-go
|
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Local QA harness fix (not a product bug).
./scripts/test-api-e2e.shdeterministically exits 1 at startup on local macOS — 30× "server not ready yet" withExtracted API key: Binary f...— so no tests run.Root cause
extract_api_key()usedgrep -o '"api_key": "[^"]*"'over/tmp/mcpproxy_e2e.log. The server log can contain a NUL byte (and ANSI color codes), sogreptreats the file as binary and emitsBinary file … matchesinstead of the match. That string becomes$API_KEY→ every authed curl is rejected →wait_for_servertimes out → exit 1. CI uses a different log path, so it slips through there.Fix
-ato thegrepso it always treats the log as text.$1, defaults to the existing hardcoded path) so the function is unit-testable; all existing no-arg callers are unaffected.scripts/test-extract-api-key.sh, which extracts the realextract_api_key()fromtest-api-e2e.shand asserts it recovers the key from a fixture log containing ANSI escapes + a NUL byte.Verification (TDD)
grep:FAIL: ... got 'Binary file /…/mcpproxy_e2e_fixture… matches'(reproduces the exact symptom).PASS: extract_api_key() returned the key from a NUL/ANSI log.bash -nclean on both files;shellcheckclean on the new test.No Go / CLI / REST / MCP / config / docs surface is touched.
Related MCP-2404