diff --git a/.forgejo/workflows/build-grid-rs.yaml b/.forgejo/workflows/build-grid-rs.yaml index e102bb63..01d0394b 100644 --- a/.forgejo/workflows/build-grid-rs.yaml +++ b/.forgejo/workflows/build-grid-rs.yaml @@ -79,6 +79,14 @@ jobs: echo "$REGISTRY_TOKEN" | docker login "$REGISTRY" -u "$OWNER" --password-stdin + # The build context is the crate dir, but the json_weights_golden + # test compares against priv/algo/band_weights.json at the repo + # root. Stage it into the context so `cargo test` inside the image + # can reach it; without this the test aborts and no image is + # produced (grid-rs CI was red from 2fd88a94 onward). + mkdir -p rust/prop_grid_rs/priv/algo + cp priv/algo/band_weights.json rust/prop_grid_rs/priv/algo/ + DOCKER_BUILDKIT=1 docker build \ --file rust/prop_grid_rs/Dockerfile \ --build-arg BUILDKIT_INLINE_CACHE=1 \ diff --git a/rust/prop_grid_rs/Dockerfile b/rust/prop_grid_rs/Dockerfile index 08856acd..8404451e 100644 --- a/rust/prop_grid_rs/Dockerfile +++ b/rust/prop_grid_rs/Dockerfile @@ -115,6 +115,12 @@ COPY Cargo.toml Cargo.lock* ./ COPY src ./src COPY tests ./tests +# `json_weights_golden` compares the compiled-in band weights against +# priv/algo/band_weights.json, which lives outside this build context. +# The workflow stages it into the context first; WORKDIR is /src, so +# CARGO_MANIFEST_DIR/../../priv lands at /priv. +COPY priv /priv + RUN --mount=type=cache,target=/usr/local/cargo/registry,sharing=locked \ --mount=type=cache,target=/usr/local/cargo/git,sharing=locked \ cargo clippy --release --all-targets -- -D warnings \ diff --git a/rust/prop_grid_rs/tests/json_weights_golden.rs b/rust/prop_grid_rs/tests/json_weights_golden.rs index bb84aa49..f6ad8823 100644 --- a/rust/prop_grid_rs/tests/json_weights_golden.rs +++ b/rust/prop_grid_rs/tests/json_weights_golden.rs @@ -98,12 +98,20 @@ fn assert_weights_equal(label: &str, got: &Weights, expected: &Weights) { /// threads for `#[test]` functions in this binary. static ENSURE_ENV: std::sync::Once = std::sync::Once::new(); +/// Absolute path to the repo's calibration JSON, resolved from the +/// crate root rather than the cwd. `cargo test` runs with the cwd at +/// the crate root, but the Docker build stages the file at an absolute +/// path, and a bare relative path silently resolved to a nonexistent +/// file there — which is what turned this golden test into a hard CI +/// failure that blocked every prop-grid-rs image build. +const BAND_WEIGHTS_JSON: &str = concat!( + env!("CARGO_MANIFEST_DIR"), + "/../../priv/algo/band_weights.json" +); + fn ensure_json_env() { ENSURE_ENV.call_once(|| { - std::env::set_var( - "PROP_BAND_WEIGHTS_JSON", - "../../priv/algo/band_weights.json", - ); + std::env::set_var("PROP_BAND_WEIGHTS_JSON", BAND_WEIGHTS_JSON); }); } @@ -111,8 +119,7 @@ fn ensure_json_env() { fn json_override_weights_match_file() { ensure_json_env(); - let json_path = "../../priv/algo/band_weights.json"; - let expected = parse_json_override_weights(json_path); + let expected = parse_json_override_weights(BAND_WEIGHTS_JSON); for band in band_config::all_bands() { let w = band.weights();