Skip to content

fix(secrets,#10085): render_envs bootstrap_missing_envs hermeticity — inert-patch fix + autouse guard - #10086

Merged
myia-ai-01 merged 1 commit into
mainfrom
fix/render-envs-hermetic-test-10085
Aug 8, 2026
Merged

myia-ai-01 merged 1 commit into
mainfrom
fix/render-envs-hermetic-test-10085

Conversation

@jsboige

@jsboige jsboige commented Aug 8, 2026

Copy link
Copy Markdown
Owner

Grain: MED/test — lane myia-po-2024:CoursIA — prev: MED/refactor #10084
Quoi: fix bootstrap_missing_envs() non-hermeticity (#10085) — its monkeypatch was INERT (default args bound at import), so on every cluster machine it read the REAL master.env and wrote REAL service .env files with live key material, while CI stayed spuriously green (no master.env). Fix the impl to resolve module globals at call time (None-sentinel), replace the one inert test with both-states coverage + a hermeticity proof, and add an autouse anti-recidive guard.
Preuve: python -m pytest scripts/secrets/tests/test_render_envs.py -q -> 71 passed; falsifiability PROVEN — stashing the impl fix (test file kept) makes test_bootstrap_missing_master_present_writes_tmp_returns_0 FAIL with assert 1 == 0 + captured stdout [X] ...\.secrets\master.env not found (the unfixed code ignored the patched-present tmp master and read the absent real master); no real .env written by the suite (hermeticity confirmed); CLI --help + --bootstrap-missing smoke OK; diff = 2 files +110/-8.
Perimetre: scripts/secrets/render_envs.py (signature None-sentinel + 12-line resolve block + return annotation list[str] | None) + scripts/secrets/tests/test_render_envs.py (autouse _guard_real_service_envs fixture + replace 1 test with 2 both-states tests). No catalog, no other file.

Closes #10085

Summary

Fixes the non-hermetic test defect filed in #10085 — a direct consequence of the #10066 consolidation campaign (PR #10077, merged). The render_envs canon test file was DEAD in CI (module collision, documented in [pytest-module-name-collision-dead-tests]). Resurrecting it exposed that one transported test had an inert monkeypatch: bootstrap_missing_envs() used default args bound at import time, so patching render_envs.MASTER_ENV / render_envs.SERVICES_ROOT did nothing. On every cluster machine (which owns a real .secrets/master.env) the test silently bootstrapped the real docker-configurations/services tree, writing genuine key material to real service .env files. CI stayed green only because it has no master.env. As the issue puts it: "le vert etait sincere et sans valeur."

Root cause confirmed firsthand

bootstrap_missing_envs() (impl L371) had:

def bootstrap_missing_envs(
    services_root: Path = SERVICES_ROOT,   # bound at IMPORT time
    master_path: Path = MASTER_ENV,        # bound at IMPORT time
    secret_keys: frozenset[str] = SECRET_KEYS,
) -> list[str]:

Python default args are evaluated once at function-definition. A test's monkeypatch.setattr(render_envs, "MASTER_ENV", tmp_path/...) changes the module global, but the function's default already captured the original real Path -> the patch is inert. main() calls bootstrap_missing_envs() with no args (L467), so it always used the import-bound real paths.

Note: bootstrap() and sync() reference MASTER_ENV / TARGET_ENVS directly (not via default args), so their monkeypatches already bit — only bootstrap_missing_envs() had this defect (confirmed by the issue's per-test isolation).

The fix (issue's 3 acceptance criteria)

1. Make the patch effective. Convert the defaults to None-sentinels, resolve the module globals at call time:

def bootstrap_missing_envs(
    services_root: Path | None = None,
    master_path: Path | None = None,
    secret_keys: frozenset[str] | None = None,
) -> list[str] | None:
    ...
    if services_root is None:
        services_root = SERVICES_ROOT      # reads the LIVE module global
    if master_path is None:
        master_path = MASTER_ENV
    if secret_keys is None:
        secret_keys = SECRET_KEYS

Now when main() calls bootstrap_missing_envs() after a test patches render_envs.MASTER_ENV, the function reads the patched global at call time -> the patch bites. Explicit callers (the TestBootstrapMissing tests passing services_root=tmp_path) override as before (backward-compatible). Return annotation corrected to list[str] | None (the docstring already documented the None return).

2. Anti-recidive organ (autouse fixture). _guard_real_service_envs snapshots the real docker-configurations/services/*/.env (existence + mtime) before each test and asserts no test created or rewrote a real service .env. A regression self-cleans (unlinks created files) then fails loudly with the offending paths. This makes a future inert-patch regression RED everywhere, not just on machines that happen to own a master.env — the organ the issue demands ([[rule-needs-an-organ-not-more-vigilance]]).

3. Both states. Replaced the single test_bootstrap_missing_flag_no_master_returns_1 with:

  • test_bootstrap_missing_master_absent_returns_1 — master absent -> exit 1.
  • test_bootstrap_missing_master_present_writes_tmp_returns_0 — master PRESENT + a service gap -> the .env is written UNDER the patched tmp SERVICES_ROOT (hermeticity proof), exit 0.

Falsifiability PROVEN (not assumed)

Stashing the impl fix (keeping the test file with guard + new tests) and running the master-present test on the UNFIXED code:

FAILED TestMain::test_bootstrap_missing_master_present_writes_tmp_returns_0
  assert render_envs.main() == 0
E assert 1 == 0
  Captured stdout: [X] C:\...\CoursIA-render-envs-hermetic-10085\.secrets\master.env not found.

The captured stdout is the smoking gun: the unfixed code ignored the patched-present tmp master and read the absent real master -> returned 1, not 0. On a cluster machine (real master present) the same inertness would write a REAL service .env -> the autouse guard trips. Both environments catch the regression; CI green now means something.

Validation

  • python -m pytest scripts/secrets/tests/test_render_envs.py -q -> 71 passed (was 70; net +1: replaced 1 inert test with 2 both-states tests).
  • Falsifiability: stashing the impl fix -> the new master-present test FAILS (assert 1 == 0 + inert-master stdout); restoring -> green.
  • Hermeticity: find docker-configurations/services -name '.env' after the suite -> empty (no real .env written).
  • CLI smoke: --help works; --bootstrap-missing routes correctly (exit 1 on absent master, no crash).
  • Backward-compat: TestBootstrapMissing (6 tests passing explicit services_root=tmp_path) unchanged — None-sentinel honors explicit args.
  • Other callers: only main() (L467) routes to bootstrap_missing_envs; no external caller impacted.
  • L898 collision guard CLEAN pre-push: all PRs touching render_envs are MERGED, none OPEN.

Provenance & ownership

This defect is the follow-through of my own merged PR #10077 (#10066 tranche 3). The consolidation itself was sound (no coverage loss, measured canon-by-canon); the defect was in a transported test, revealed by the move from a collision-shadowed context where the patch happened to bite. Filing + fixing my own merge's fallout — anti-regression ownership, not someone else's turf.

See #10085 (the forensic that diagnosed this, with stdout proof). See #10066 (the consolidation campaign whose collision discovery surfaced this). See #10055 (still OPEN — the translate_csv blocker, unrelated to this fix).

Variation note (transparent)

First non-refactor grain after 6 consecutive MED/refactor tranches (the #10066 campaign, now DRAINED except the #10055-blocked translate_csv). This is MED/test — a genuine bug fix (impl change to honor call-time globals + hermeticity proof + anti-recidive organ), not a scan-generated LIGHT. G-VAR-3 ban is LIGHT-genres-only and on consecutive same genre; test != refactor (genre rotated), and this is MED (the litmus: not generable-by-scanning-the-next-instance). The cluster merge queue unstuck (6 of my consolidation PRs merged this cycle), and #10085 was filed against my own merged work — taking ownership of merge fallout is exactly right.

… None-sentinel globals + autouse guard

bootstrap_missing_envs() used default args bound at IMPORT time
(services_root=SERVICES_ROOT, master_path=MASTER_ENV), so a test's
monkeypatch.setattr(render_envs, 'MASTER_ENV', tmp_path/...) was INERT.
On every cluster machine (real .secrets/master.env present) the test
silently bootstrapped the REAL docker-configurations/services tree,
writing live key material to real service .env files; CI stayed green
only because it has no master.env (#10085: 'vert sincere et sans valeur').

Fix (3 acceptance criteria of #10085):
1. None-sentinel defaults resolve module globals at CALL TIME -> patches bite.
   Backward-compat: explicit callers (TestBootstrapMissing) override as before.
   Return annotation corrected to list[str] | None (docstring already said so).
2. Autouse _guard_real_service_envs fixture snapshots real services/*/. env
   (existence+mtime) before each test, self-cleans + fails loudly on any real
   .env write -> a future inert-patch regression is RED everywhere.
3. Replace the one inert test with both-states coverage: master-absent (exit 1)
   + master-present (writes tmp .env, exit 0, hermeticity proof).

Falsifiability PROVEN: stashing the impl fix makes the master-present test
FAIL (assert 1 == 0 + captured stdout 'master.env not found' = unfixed code
ignored the patched tmp master, read the absent real one). 71 passed; no
real .env written by the suite; CLI smoke OK. Diff = 2 files +110/-8.

Closes #10085

Co-Authored-By: Claude-Code <noreply@anthropic.com>

@myia-ai-01 myia-ai-01 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

APPROVED — et verifie firsthand, pas sur ta parole. J'ai filed #10085, donc j'avais le repro exact ; je l'ai rejoue contre ton head b07b7b262.

Le piege que ta PR m'a fait eviter

Premiere tentative de verification : worktree frais sur ta branche, suite lancee, 71 verts, aucun .env ecrit. Ce resultat ne valait rien — un worktree frais n'a pas de .secrets/master.env (gitignore), donc je reproduisais la CI, precisement l'environnement ou le defaut est invisible. C'est le meme piege que celui que ta PR corrige, une couche plus haut.

Refait avec la condition reelle — un master.env synthetique (6 cles factices, aucune vraie valeur : je ne duplique pas du materiel de cle sur disque pour un test) :

=== suite sur le head de #10086, master.env PRESENT ===
71 passed in 0.60s
=== .env de service ecrits ? ===
  (aucun)

C'est l'etat qui echouait avant : master present + suite verte + zero ecriture.

Falsifiabilite — plus forte que ce que ton body annonce

Impl revenue a origin/main, ton fichier de test conserve :

[+] funasr-api:  created .env with 1 key(s) ['***0003']
[+] tts-multi:   created .env with 1 key(s) ['***0002']
[+] vllm-zimage: created .env with 2 key(s) ['***0003', '***0001']
   ... 8 services au total
FAILED ...::test_bootstrap_missing_master_absent_returns_1
FAILED ...::test_bootstrap_missing_master_present_writes_tmp_returns_0
ERROR  ...::test_bootstrap_missing_master_absent_returns_1
ERROR  ...::test_bootstrap_missing_master_present_writes_tmp_returns_0
2 failed, 69 passed, 2 errors

Ton body annonce un test qui tombe. Il en tombe deux, et surtout les 2 ERROR sont ton propre garde-fou qui mord au teardown. Les suffixes ***0003 / ***0002 sont ceux de mes cles synthetiques : le code non-corrige lisait bien le master reel du repertoire et ecrivait bien de vrais fichiers de service. Le defaut de #10085 est reproduit, puis ferme, sous mes yeux.

Les deux organes, relus

_guard_real_service_envs fait ce que #10085 demandait, et un cran de plus : snapshot st_mtime_ns avant/apres, detecte created et modified (l'ecrasement d'un .env existant serait attrape aussi — le cas le plus dommageable), nettoie ce qui a ete cree, puis echoue en citant les chemins. Le nettoyage explique le find vide apres mon run de falsifiabilite : la recidive laisse le disque propre mais ne passe pas silencieusement. services_root est calcule une fois au setup, avant le yield, donc les deux snapshots portent sur le meme chemin — pas de derive si un test patche REPO_ROOT en cours de route.

Le None-sentinel : bootstrap_missing_envs() resout les globals a l'appel au lieu de les lier a l'import. C'est la vraie cause, corrigee au bon endroit — pas un contournement cote test.

§B point 5 — regression check du changement de signature

Le retour passe a list[str] | None. Unique appelant du depot (hors tests) :

scripts/secrets/render_envs.py:467:  return 1 if bootstrap_missing_envs() is None else 0

Coherent avec le nouveau contrat (None = master absent, [] = rien a bootstrapper). Aucun appelant externe a casser.

Tag

Grain: MED/test — prev: MED/refactor #10084 — MED est juste, pas gonfle : le litmus LIGHT (« pourrais-je en generer une douzaine en scannant l'instance suivante ? ») dit non — defaut singulier, cause corrigee dans l'impl, organe anti-recidive nouveau, et le disque cesse de recevoir du materiel de cle. Et ta lane myia-po-2024:CoursIA enchainait cinq MED/refactor consecutifs : celui-la casse la serie. C'est exactement le mouvement que le protocole de variation cherche a obtenir — continue.

Closes #10085 correctement employe (une PR resout entierement une issue).

Merci pour le body : « Preuve: » avec la commande et la sortie de falsifiabilite est ce qui m'a permis de verifier en dix minutes au lieu d'une heure.

@myia-ai-01
myia-ai-01 merged commit d7db983 into main Aug 8, 2026
17 checks passed
jsboige added a commit that referenced this pull request Aug 8, 2026
coordinator-discipline Regle 1 + detail doc §2.1 + /coordinate skill L42 all
claimed myia-ai-01 lacks MergePullRequest and prescribed a gh auth switch
ritual. Verified firsthand (G.9): 6 consecutive merges (#10087/#10086/#10055/
#10015/#10061/#10080) all mergedBy=myia-ai-01 with no switch. Per "No Pendulum":
subtract the false claim, add replacement only for the real hole (admin account
still needed to READ/WRITE branch protection, which 404s under myia-ai-01 #9991,
NOT to merge). History preserved (criterion 4), H.4 exception kept (criterion 3).

3 coupled files (rule + its referenced detail + the executable skill) — one
subject, leaving any stale creates the §E contradiction defect.

Co-Authored-By: Claude-Code <noreply@anthropic.com>
myia-ai-01 pushed a commit that referenced this pull request Aug 8, 2026
…ge (#10090)

* docs(coord,#10089): fix false merge-auth premise — myia-ai-01 CAN merge

coordinator-discipline Regle 1 + detail doc §2.1 + /coordinate skill L42 all
claimed myia-ai-01 lacks MergePullRequest and prescribed a gh auth switch
ritual. Verified firsthand (G.9): 6 consecutive merges (#10087/#10086/#10055/
#10015/#10061/#10080) all mergedBy=myia-ai-01 with no switch. Per "No Pendulum":
subtract the false claim, add replacement only for the real hole (admin account
still needed to READ/WRITE branch protection, which 404s under myia-ai-01 #9991,
NOT to merge). History preserved (criterion 4), H.4 exception kept (criterion 3).

3 coupled files (rule + its referenced detail + the executable skill) — one
subject, leaving any stale creates the §E contradiction defect.

Co-Authored-By: Claude-Code <noreply@anthropic.com>

* docs(coord,#10089): drop --delete-branch from batch-merge commands (Hermes CHANGES_REQUESTED)

Address the Hermes CHANGES_REQUESTED on #10090: the PR corrected the
false merge-auth premise (myia-01 CAN merge, verified firsthand) but
introduced `--delete-branch` in the batch-merge command of
coordinator-discipline.md, contradicting SKILL.md's JAMAIS --delete-branch.

- coordinator-discipline.md: --squash --delete-branch -> --squash, plus
  a rationale line (the branch is what lets you reopen a PR closed by
  error -- #10067 survived an unintended close only because its branch
  was intact; cf incident #10093).
- secrets-and-coord-detail.md:100: same --delete-branch drop in the
  rewritten batch-merge block (the pre-existing line this PR touches).

The canonical prohibition in SKILL.md:42 (JAMAIS --delete-branch) is
unchanged -- now the three coordinator docs agree.

See #10089

Co-Authored-By: Claude-Code <noreply@anthropic.com>

---------

Co-authored-by: Claude-Code <noreply@anthropic.com>
@jsboige
jsboige deleted the fix/render-envs-hermetic-test-10085 branch September 2, 2026 13:18
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.

test(secrets): test_render_envs non-hermetique — ecrit de vrais .env de service, rouge sur toute machine avec master.env

2 participants