fix: stop environment leakage in build identity and the unit suite - #179
Merged
Conversation
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
force-pushed
the
fix/177-environment-leakage
branch
from
August 9, 2026 21:20
676e13f to
c4dfac1
Compare
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.
Closes #177 — two independent pre-existing bugs, both reproduced on clean
mainatfbe663b. Neither was caused by #175/#176.1.
task docker-checkcould never passTaskfile.yml:130usedLOCALRAG_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 stamped99848(git rev-parse HEAD)and the comparison againstgit rev-parse HEADalways 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 resolveddocker-upcommand carries the current SHA, so a silent regression fails loudly.2. The unit suite read the developer's local
.envEnv vars and
.envoutrank YAML (ADR 020) — correct for the app, wrong for tests asserting YAML-layer defaults. With a.envcontainingAPI_KEYand a timeout override: 25 failures. Without it: 0.tests/conftest.pygains an autouse fixture that pinsenv_filetoNoneand 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=ERRORis re-asserted to keep runs quiet; no test asserts on it.monkeypatch.setenvinside a test body still wins, since the fixture runs first.test_configuration_precedence_is_defaults_yaml_dotenv_environment_cliexercises the.envlayer deliberately, so it opts back in; itschdirmakestmp_path's.envthe only reachable one.Verification
.env(API_KEY,LLM_TIMEOUT_SECONDS=120)API_KEY,RAG_TOP_K=42, two timeouts).env, clean env (the CI condition)task --dry docker-upfbe663b910f2f…, matchinggit rev-parse HEADdocker compose build localrag-api→docker run … echo $LOCALRAG_BUILD_SHARan 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-inforeadingos.environis already covered bytests/test_api.py:161.Not addressed here
#177 also notes the repo's own
.envis not shell-safe (set -a && . ./.envfails on the unquotedRAG_SYSTEM_PROMPTline) and listsAPI_KEYtwice. 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.exampleif the same shape is documented there.🤖 Generated with Claude Code
https://claude.ai/code/session_01UZ7AySD1EFME3xjMiQNp1p