From 91d305cd3c6d3f3d45daaffec8cbc8258e8581b2 Mon Sep 17 00:00:00 2001 From: Marius Ciepluch <11855163+norandom@users.noreply.github.com> Date: Wed, 25 Nov 2026 18:37:30 +0100 Subject: [PATCH] ci: keep the local .env out of the dagger upload By the maintainer's decision of 2026-11-25, recorded in the handover: "dagger/ci.py syncs the git-ignored .env into the local container when run locally, and step 9 runs that script locally for the first time. I have not read how CI supplies what .env holds; that is checked first, so CI keeps what it needs." `.env` is the first entry of the exclude list of the one upload in dagger/ci.py, `client.host().directory(".", exclude=[...])`. The script is CI's dagger job and the same script run locally; the entry matches nothing in CI and removes the root `.env` of the tree when the script runs on a machine that has one. CI keeps what it needs, read before the change: `.github/workflows/ci.yml` (97 lines) sets two literal variables (`UV_NO_SYNC`, `DAGGER_VERSION`), uses no `secrets.*` and no `vars.*`, and has no step that creates or copies a `.env`; the container gets one variable, `UV_NO_SYNC=1`. The names `.env.example` lists, the two API keys, the `VALID_BENCHMARK_*` S3 settings and the two Discord values, are supplied by no workflow. A checkout has no `.env`, because the file is git-ignored; `.env.example` is not matched and stays in the upload. No test reads a `.env` from the tree. That the pattern removes the root `.env` rests on reading, not on a run: the SDK passes the list unchanged to the engine, whose filter matches a pattern without wildcards against the whole relative path (the independent reviewer traced it at v0.21.7, the version CI pins, and ran that filter over a scratch tree; no engine and no container was started). Tests: the new tests/test_dagger_ci_upload.py parses dagger/ci.py as text, so it needs no dagger engine, and asserts that the one exclude list holds `.env`. It failed before the change (the list without the entry, 1 failed) and passes after; with the two test files that read the workflow files, 16 passed. ruff, mypy, the three gates and compileall pass, and the gates print what they printed before the change. An independent reviewer approved the change in one round; its remarks on the wording of the comment and of the test, and on the failure message of the test, are applied. Left for the maintainer's menu, not decided: excluding `.env.*` files as well (a bare pattern would also drop `.env.example`, which a test reads), an in-container check that fails the pipeline if the file ever got in, and `__pycache__` directories, which a local run uploads. --- dagger/ci.py | 1 + tests/test_dagger_ci_upload.py | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 tests/test_dagger_ci_upload.py diff --git a/dagger/ci.py b/dagger/ci.py index 92b38533..60ae44a3 100644 --- a/dagger/ci.py +++ b/dagger/ci.py @@ -30,6 +30,7 @@ async def _run_checks() -> None: source = client.host().directory( ".", exclude=[ + ".env", # local settings and keys (.env.example lists them); CI has no .env: a checkout has only tracked files ".git", ".mypy_cache", ".pytest_cache", diff --git a/tests/test_dagger_ci_upload.py b/tests/test_dagger_ci_upload.py new file mode 100644 index 00000000..06470989 --- /dev/null +++ b/tests/test_dagger_ci_upload.py @@ -0,0 +1,19 @@ +"""The dagger pipeline uploads the working tree to its container; the local .env must stay out of that upload.""" + +import ast +from pathlib import Path + +ROOT = Path(__file__).resolve().parents[1] + + +def _uploaded_excludes() -> list[str]: + """The exclude list of the upload in dagger/ci.py, parsed as text: the test needs no dagger engine.""" + tree = ast.parse((ROOT / "dagger" / "ci.py").read_text()) + keywords = [node for node in ast.walk(tree) if isinstance(node, ast.keyword) and node.arg == "exclude"] + assert len(keywords) == 1, f"dagger/ci.py passes {len(keywords)} exclude lists, expected one" + assert isinstance(keywords[0].value, ast.List), "the exclude list in dagger/ci.py is expected to be a list literal" + return [ast.literal_eval(item) for item in keywords[0].value.elts] + + +def test_the_dagger_upload_leaves_the_local_env_file_out() -> None: + assert ".env" in _uploaded_excludes()