fix(dev): create external network in ensure-env for clean clone #167
Loading…
Reference in a new issue
No description provided.
Delete branch "fix/pre-commit-clean-clone"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Root cause
just pre-commitruns cargo insidedocker compose -f compose.dev.yml run --rm --no-deps api ....compose.dev.ymldeclares the per-developerprivatenetwork asexternal: truewith namedev-bunyip-private-${USER}. On a fresh clone that network does not exist, so compose aborts withnetwork dev-bunyip-private-<user> declared as external, but could not be foundbefore any check runs. Only thedev-ssorecipe 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()callsdotenvy::dotenv(), which loads the.envthatensure-envgenerates; that.envcarriesAPP_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-envidempotently create the external network if missing, mirroring the existingdev-ssodocker network inspect/docker network createpattern. Pin the keystest_config_defaultsexercises to their code defaults before callingfrom_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-commiton 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.
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