Skip to content

bug(scripts): detect-environment.sh selects three .env files that do not exist #15143

Description

@mrveiss

Found while resolving the first batch of #15127.

autobot-infrastructure/shared/scripts/utilities/detect-environment.sh picks an env file per
detected environment and then exports it. Four of the five branches name a file that is not
tracked anywhere in the repo:

line selected file exists
39 .env.wsl-docker-desktop no
44 .env.linux-native no
49 .env.linux-native no
53 .env.distributed no
57 .env.localhost yes

The tracked env files are .env.docker, .env.example, .env.localhost, .env.native-vm,
.env.network, .env.network-template and docker/.env.docker. The generator and validator that
own this inventory — generate-env-files.py and validate-env-files.py — know only
localhost, native-vm and network, so the script's vocabulary and the real inventory have
fully diverged.

This is not in #15127's list because the script is referenced (from the scripts README.md), so
the unreferenced-script guard never looked at it. Referenced is not the same as working.

Context: utilities/load-env.sh was a fork of this same job with the same defect and was retired in
#15127's first batch. This one is referenced and documented, so it should be corrected rather than
retired — either by mapping the branches onto the three modes that exist, or by generating the
missing files.

Acceptance criteria

  • Every branch selects a file the repo actually provides, or fails with a message naming what is
    missing rather than exporting nothing.
  • A test asserts each selectable env-file name against the tracked set, and fails if that set is
    empty.

Refs #15127

Activity

  1. added
    area: ci-gatesWave 0 · cluster P — CI gates & merge integrity
    on Sep 1, 2026
  2. added this to the v0.9.0 milestone on Sep 12, 2026
  3. mrveiss commented on Sep 13, 2026

    @mrveiss
    OwnerAuthor

    Post-merge closure audit: both ACs verified on main at 0abe0d4. Fixed by PR #16553, merge commit dadd176.

    • "Every branch selects a file the repo actually provides, or fails with a message naming what is missing rather than exporting nothing." ✅ I took the branches from detect_environment()'s five possible outputs and checked each against detect-environment.sh:

      .env.localhost is tracked at the repo root on main; it is one of the 6 root .env* files.

    • "A test asserts each selectable env-file name against the tracked set, and fails if that set is empty." ✅ In repo_tests/detect_environment_env_files_test.py:

      • :68 test_resolved_branches_select_a_tracked_file asserts that the selected file is in _tracked_env_files().
      • :63 test_the_tracked_set_is_not_empty fails if the set is empty.
      • A Reach floor of 6 (:44) catches the set shrinking.
      • Caveat: _tracked_env_files (:32-34) globs the working tree rather than calling git ls-files. The two are identical in a clean CI checkout, but an untracked local .env* file would count as tracked.

    Outside these ACs: ENV_FILE is relative to the current directory. If the script is sourced from anywhere other than the repo root, the selected file is reported "not found, using defaults" (:69). This behaviour predates the PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions