fix(dev): create external network in ensure-env for clean clone #167

Merged
vas2000-work merged 2 commits from fix/pre-commit-clean-clone into main 2026-06-18 04:46:44 +02:00
Owner

Root cause

just pre-commit runs cargo inside docker compose -f compose.dev.yml run --rm --no-deps api .... compose.dev.yml declares the per-developer private network as external: true with name dev-bunyip-private-${USER}. On a fresh clone that network does not exist, so compose aborts with network dev-bunyip-private-<user> declared as external, but could not be found before any check runs. Only the dev-sso recipe created the network; ensure-env (the pre-commit prerequisite) did not.

Once the network blocker is removed, a second clean-clone-only failure surfaces in config::tests::test_config_defaults. Config::from_env() calls dotenvy::dotenv(), which loads the .env that ensure-env generates; that .env carries APP_PORT=4401 (and CORS_ORIGIN, RUST_LOG, HOST_IP), which leaked into the test process and clobbered the asserted code defaults (assert_eq!(config.port, 4000)). The network abort had previously masked this because tests never ran.

Fix

Make ensure-env idempotently create the external network if missing, mirroring the existing dev-sso docker network inspect / docker network create pattern. Pin the keys test_config_defaults exercises to their code defaults before calling from_env() so the on-disk .env (dotenvy is non-overriding) cannot override them, making the assertions deterministic regardless of the working directory's .env.

Verification

just pre-commit on this branch from a clean state exits 0 with all stages green: cargo fmt --all --check, cargo clippy --workspace --all-targets -- -D warnings, cargo build --workspace --all-targets --locked, cargo test --workspace --lib (195 passed in bunyip-domain, all other crates green), ending in [pre-commit] all checks passed.

Refs DEV-370.

## Root cause `just pre-commit` runs cargo inside `docker compose -f compose.dev.yml run --rm --no-deps api ...`. `compose.dev.yml` declares the per-developer `private` network as `external: true` with name `dev-bunyip-private-${USER}`. On a fresh clone that network does not exist, so compose aborts with `network dev-bunyip-private-<user> declared as external, but could not be found` before any check runs. Only the `dev-sso` recipe created the network; `ensure-env` (the pre-commit prerequisite) did not. Once the network blocker is removed, a second clean-clone-only failure surfaces in `config::tests::test_config_defaults`. `Config::from_env()` calls `dotenvy::dotenv()`, which loads the `.env` that `ensure-env` generates; that `.env` carries `APP_PORT=4401` (and CORS_ORIGIN, RUST_LOG, HOST_IP), which leaked into the test process and clobbered the asserted code defaults (`assert_eq!(config.port, 4000)`). The network abort had previously masked this because tests never ran. ## Fix Make `ensure-env` idempotently create the external network if missing, mirroring the existing `dev-sso` `docker network inspect` / `docker network create` pattern. Pin the keys `test_config_defaults` exercises to their code defaults before calling `from_env()` so the on-disk `.env` (dotenvy is non-overriding) cannot override them, making the assertions deterministic regardless of the working directory's `.env`. ## Verification `just pre-commit` on this branch from a clean state exits 0 with all stages green: `cargo fmt --all --check`, `cargo clippy --workspace --all-targets -- -D warnings`, `cargo build --workspace --all-targets --locked`, `cargo test --workspace --lib` (195 passed in bunyip-domain, all other crates green), ending in `[pre-commit] all checks passed`. Refs DEV-370.
fix(dev): create external network in ensure-env for clean clone
All checks were successful
Check / fmt / clippy / build / test (pull_request) Successful in 1m29s
d757a96d3d
pre-commit runs cargo via `docker compose -f compose.dev.yml run ... api`, but compose.dev.yml declares the per-developer `private` network as `external: true` (name `dev-bunyip-private-${USER}`). On a fresh clone that network does not exist, so compose aborts with "network declared as external, but could not be found" before any check runs. Only `dev-sso` created it; `ensure-env` (the pre-commit prerequisite) did not.

Make `ensure-env` idempotently create the external network if missing, mirroring the `dev-sso` recipe's `docker network inspect`/`docker network create` pattern, so a clean checkout can attach the compose stack.

Also fix `config::tests::test_config_defaults`, which now ran for the first time on a clean clone (previously masked by the network abort): Config::from_env() calls dotenvy::dotenv(), loading the .env that ensure-env generates, which leaked APP_PORT=4401 (and friends) and clobbered the asserted code defaults. Pin the keys the test exercises to their code defaults before from_env() so the on-disk .env cannot override them (dotenvy is non-overriding), making the assertions deterministic.

#DEV-370
Merge branch 'main' into fix/pre-commit-clean-clone
All checks were successful
Check / fmt / clippy / build / test (pull_request) Successful in 2m7s
Create release / Create release from merged PR (pull_request) Has been skipped
7f134ffa85
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
psa-systems/bunyip!167
No description provided.