Skip to content

fix: trim whitespace from env-provided secrets#20

Merged
deepfates merged 1 commit into
mainfrom
fix/trim-env-secrets
May 29, 2026
Merged

fix: trim whitespace from env-provided secrets#20
deepfates merged 1 commit into
mainfrom
fix/trim-env-secrets

Conversation

@deepfates

Copy link
Copy Markdown
Owner

Problem

The `verify` CI job failed every live LLM test with:

```
invalid value for header (only printable ASCII characters are allowed) "x-api-key": "[REDACTED]\n"
```

CI-injected secrets commonly carry a trailing newline. An untrimmed `api_key` smuggled into the `x-api-key` HTTP header is rejected by Mint/Finch as a non-printable character, taking down all of `LiveAnthropicTest`, `FamiliarEvalSignalTest`, and `RealLLMIntegrationTest`.

Fix

Trim whitespace from values read from environment variables in both env-reading helpers in `Cantrip.LLM` (`env/4` and `env_first/1`) via a new `trim_env/1`. This normalizes secrets (and model names, base URLs) before they reach the HTTP layer.

Verification

  • `mix test test/real_llm_config_test.exs` — 6 tests, 0 failures (incl. new trimming regression test)
  • `RUN_REAL_LLM_TESTS=1 CANTRIP_LLM_PROVIDER=anthropic mix test test/live_anthropic_test.exs --include integration` — 3 tests, 0 failures against the real Anthropic API

CI-injected secrets often carry a trailing newline. An untrimmed
api_key smuggled into the x-api-key HTTP header is rejected as a
non-printable character, failing every live LLM test. Trim values
read from environment variables in both env helpers.
@deepfates deepfates merged commit f4b1231 into main May 29, 2026
3 of 4 checks passed
@deepfates deepfates deleted the fix/trim-env-secrets branch May 29, 2026 07:49
meefs pushed a commit to meefs/cantrip that referenced this pull request May 29, 2026
Test debt surfaced by actually running the live suite: the code-medium
test declared `gates: [:done, :list_dir]` as bare atoms without a root
dependency. Pre-deepfates#20, list_dir was "effectively unscoped" and tolerated
missing root. Post-deepfates#20 (Cantrip.Gate.Path.validate/2 fail-closed on
missing root), list_dir correctly errors, which made every iteration
in the live test fail at the gate call.

The cleanup work was correct; the live test wasn't updated to match the
tightened security contract. Fix: pass `dependencies: %{root: File.cwd!()}`
to the list_dir gate. All three live_anthropic_test tests now pass.

Underscores why we should have been running live tests against the
cleanup branch instead of treating them as "needs user's API key."
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