Skip to content

fix: stop environment leakage in build identity and the unit suite - #179

Merged
n0nuser merged 2 commits into
mainfrom
fix/177-environment-leakage
Aug 13, 2026
Merged

fix: stop environment leakage in build identity and the unit suite#179
n0nuser merged 2 commits into
mainfrom
fix/177-environment-leakage

Conversation

@n0nuser

@n0nuser n0nuser commented Aug 9, 2026

Copy link
Copy Markdown
Owner

Closes #177 — two independent pre-existing bugs, both reproduced on clean main at fbe663b. Neither was caused by #175/#176.

1. task docker-check could never pass

Taskfile.yml:130 used LOCALRAG_BUILD_SHA="$$(git rev-parse HEAD)". The $$ is not consumed as Task escaping — the shell expands it to its own PID, so the image was stamped 99848(git rev-parse HEAD) and the comparison against git rev-parse HEAD always failed. The "rebuild before trusting an end-to-end result" guarantee in AGENTS.md was unenforceable.

The SHA is now resolved by Task itself, as a task-level sh: var. A CI step in the Taskfile smoke job asserts the resolved docker-up command carries the current SHA, so a silent regression fails loudly.

2. The unit suite read the developer's local .env

Env vars and .env outrank YAML (ADR 020) — correct for the app, wrong for tests asserting YAML-layer defaults. With a .env containing API_KEY and a timeout override: 25 failures. Without it: 0.

tests/conftest.py gains an autouse fixture that pins env_file to None and clears the documented flat names (FLAT_TO_PATH + UNGROUPED_FIELDS) for non-integration tests. Integration tests are exempt — they configure themselves from the real environment to reach the running stack. LOG_LEVEL=ERROR is re-asserted to keep runs quiet; no test asserts on it. monkeypatch.setenv inside a test body still wins, since the fixture runs first.

test_configuration_precedence_is_defaults_yaml_dotenv_environment_cli exercises the .env layer deliberately, so it opts back in; its chdir makes tmp_path's .env the only reachable one.

Verification

Condition Result
Hostile .env (API_KEY, LLM_TIMEOUT_SECONDS=120) 480 passed (was 25 failed / 455 passed)
Hostile exported vars (API_KEY, RAG_TOP_K=42, two timeouts) 480 passed
No .env, clean env (the CI condition) 480 passed
task --dry docker-up stamps fbe663b910f2f…, matching git rev-parse HEAD
docker compose build localrag-apidocker run … echo $LOCALRAG_BUILD_SHA returns the real SHA

Ran with Task 3.52.0. The full stack was not started end-to-end (it pulls multi-GB images and models); the chain the bug breaks — Task var → compose build arg → Dockerfile ARG/ENV → image — was verified directly, and /build-info reading os.environ is already covered by tests/test_api.py:161.

Not addressed here

#177 also notes the repo's own .env is not shell-safe (set -a && . ./.env fails on the unquoted RAG_SYSTEM_PROMPT line) and lists API_KEY twice. That file is untracked and local to the maintainer's machine, so it is out of scope for this branch — worth a follow-up on .env.example if the same shape is documented there.

🤖 Generated with Claude Code

https://claude.ai/code/session_01UZ7AySD1EFME3xjMiQNp1p

Two independent bugs, both reproduced on clean main at fbe663b.

`task docker-up` stamped the image with the shell's PID instead of the
Git SHA: `$$` in the command is expanded by the shell as its PID, not
consumed as Task escaping, so `/build-info` returned e.g.
`99848(git rev-parse HEAD)` and `task docker-check` could never pass --
defeating the stale-image guard AGENTS.md relies on. Resolve the SHA as
a Task-level `sh:` var and add a CI step asserting the resolved command
carries the current SHA.

The unit suite also read the developer's own configuration. Env vars and
`.env` outrank YAML (ADR 020), so a local `API_KEY` or timeout override
changed what tests asserted on: 25 failures with a `.env` present, 0
without. An autouse fixture now pins `env_file` to None and clears the
documented flat names for non-integration tests, so a green local run
means what a green CI run means. The precedence test opts back into the
`.env` layer it exercises.

Verified: unit suite green with a hostile `.env`, with hostile exported
vars, and with neither; the built image now carries the real SHA.

Closes #177

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UZ7AySD1EFME3xjMiQNp1p
@n0nuser
n0nuser force-pushed the fix/177-environment-leakage branch from 676e13f to c4dfac1 Compare August 9, 2026 21:20
@n0nuser
n0nuser merged commit 18709cc into main Aug 13, 2026
12 checks passed
@n0nuser
n0nuser deleted the fix/177-environment-leakage branch August 13, 2026 17:03
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.

Build-identity check and unit suite are both broken by environment leakage

1 participant