diff --git a/.github/scripts/id-pr-checks.txt b/.github/scripts/id-pr-checks.txt index 63812a0983..be01f8ed59 100644 --- a/.github/scripts/id-pr-checks.txt +++ b/.github/scripts/id-pr-checks.txt @@ -40,4 +40,5 @@ crash-gate-sampled crash-gate-sweep crash-gate-control crash-gate-ingest +just-recipes-drift doc diff --git a/pkgs/id/flake.nix b/pkgs/id/flake.nix index 89edb4b201..dc93a74435 100644 --- a/pkgs/id/flake.nix +++ b/pkgs/id/flake.nix @@ -343,6 +343,12 @@ crash-gate-sweep = mkCheck "crash-gate-sweep" "crash-gate-sweep"; crash-gate-control = mkCheck "crash-gate-control" "crash-gate-control"; crash-gate-ingest = mkCheck "crash-gate-ingest" "crash-gate-ingest"; + # Drift guard for the generated just-recipes.json (#2729): fails + # when the checked-in JSON disagrees with the justfile on the + # semantic recipe fields. The recipe projects out generation + # noise (absolute source path, body serialisation), so this is + # green on any correctly regenerated file. + just-recipes-drift = mkCheck "just-recipes-drift" "just-recipes-check && bash scripts/just-recipes-check-test.sh"; # Playwright E2E tests (requires building the binary + browser binaries) test-e2e = pkgs.stdenv.mkDerivation { diff --git a/pkgs/id/just-recipes.json b/pkgs/id/just-recipes.json index 43cc1198f0..86e545c3b4 100644 --- a/pkgs/id/just-recipes.json +++ b/pkgs/id/just-recipes.json @@ -250,6 +250,65 @@ "namepath": "root::mcpx-stop", "shebang": false }, + "mcpx-test-affected": { + "attributes": [{ "group": "util" }], + "body": [ + ["python3 pkgs/mcpx/scripts/affected-tests.py --base ", [["variable", "base"]], " ", [["variable", "args"]]] + ], + "dependencies": [], + "doc": "agent test tiers from code#1966 (policy: pkgs/mcpx/TESTING.md)", + "name": "mcpx-test-affected", + "parameters": [ + { + "default": "origin/main", + "export": false, + "flag": false, + "help": null, + "kind": "singular", + "long": null, + "max": null, + "min": null, + "multiple": false, + "name": "base", + "pattern": null, + "short": null, + "value": null + }, + { + "default": null, + "export": false, + "flag": false, + "help": null, + "kind": "star", + "long": null, + "max": null, + "min": null, + "multiple": false, + "name": "args", + "pattern": null, + "short": null, + "value": null + } + ], + "priors": 0, + "private": false, + "quiet": false, + "namepath": "root::mcpx-test-affected", + "shebang": false + }, + "rebuild": { + "attributes": [{ "group": "nixos" }], + "body": [["#!/usr/bin/env bash"], ["set -euo pipefail"], ["just update-inputs-all"], ["just switch"]], + "dependencies": [], + "doc": "Update all flake inputs, then rebuild and switch NixOS configuration", + "name": "rebuild", + "parameters": [], + "priors": 0, + "private": false, + "quiet": false, + "namepath": "root::rebuild", + "shebang": true + }, "stage-docs": { "attributes": [{ "group": "docs" }], "body": [["./scripts/stage-docs.sh ", [["variable", "args"]]]], @@ -665,7 +724,7 @@ "windows_shell": null, "working_directory": null }, - "source": "/home/hatch/git/worktrees/queue-1283-551/root.just", + "source": "/home/user/git/fleet/4094-2729-just-recipes-drift/root.just", "unexports": [], "warnings": [] } @@ -750,7 +809,7 @@ }, "bench": { "attributes": [], - "body": [["cargo bench --bench world_bench -- ", ["variable", "args"]]], + "body": [["cargo bench --bench world_bench -- ", [["variable", "args"]]]], "dependencies": [], "doc": "Run the F11.8 benchmark harness (issue #539): journal append+fsync, checkpoint compaction, guest replay, session fan-out", "name": "bench", @@ -1454,7 +1513,7 @@ ["@echo \"✓ Crash gate (sampled + corpus replay) passed\""] ], "dependencies": [], - "doc": "excluded everywhere (they rewrite the checked-in corpus files).", + "doc": "losing all PR coverage.", "name": "crash-gate-sampled", "parameters": [], "priors": 0, @@ -1613,6 +1672,19 @@ "namepath": "just-recipes", "shebang": false }, + "just-recipes-check": { + "attributes": [{ "group": "deps" }], + "body": [["bash scripts/just-recipes-check.sh"]], + "dependencies": [], + "doc": "Fail when just-recipes.json has drifted from this justfile (#2729)", + "name": "just-recipes-check", + "parameters": [], + "priors": 0, + "private": false, + "quiet": false, + "namepath": "just-recipes-check", + "shebang": false + }, "kill": { "attributes": [{ "group": "run" }], "body": [["-pkill -xf \".*/id serve.*\""]], @@ -3096,7 +3168,7 @@ "windows_shell": null, "working_directory": null }, - "source": "/home/hatch/git/worktrees/queue-1283-551/pkgs/id/justfile", + "source": "/home/user/git/fleet/4094-2729-just-recipes-drift/pkgs/id/justfile", "unexports": [], "warnings": [] } diff --git a/pkgs/id/justfile b/pkgs/id/justfile index fa74e2a730..6b86d6efe0 100644 --- a/pkgs/id/justfile +++ b/pkgs/id/justfile @@ -202,6 +202,11 @@ just-recipes: just --dump --dump-format json > just-recipes.json biome format --write --config-path . just-recipes.json +# Fail when just-recipes.json has drifted from this justfile (#2729) +[group('deps')] +just-recipes-check: + bash scripts/just-recipes-check.sh + # ============================================================================= # Testing # ============================================================================= diff --git a/pkgs/id/scripts/just-recipes-check-test.sh b/pkgs/id/scripts/just-recipes-check-test.sh new file mode 100644 index 0000000000..755eb876c3 --- /dev/null +++ b/pkgs/id/scripts/just-recipes-check-test.sh @@ -0,0 +1,41 @@ +#!/usr/bin/env bash +set -euo pipefail + +script="$(cd "$(dirname "$0")" && pwd)/just-recipes-check.sh" +tmp="$(mktemp -d)" +trap 'rm -rf "$tmp"' EXIT +mkdir "$tmp/bin" "$tmp/work" +printf '#!%s\n' "$(command -v bash)" > "$tmp/bin/just" +cat >> "$tmp/bin/just" <<'EOF' +cat "$FRESH" +EOF +chmod +x "$tmp/bin/just" +export PATH="$tmp/bin:$PATH" FRESH="$tmp/fresh.json" +cd "$tmp/work" +cat > just-recipes.json <<'EOF' +{"source":"old", "recipes":{"run":{"doc":"run", "private":false, "parameters":[{"name":"arg", "kind":"singular", "default":null, "export":false, "flag":false}], "dependencies":[{"recipe":"dep", "arguments":[["string", "a"]], "star":null}], "body":[["old"]]}}, "aliases":{"r":{"target":"run"}}} +EOF +cp just-recipes.json "$FRESH" +check_pass() { if ! bash "$script" > "$tmp/output" 2>&1; then cat "$tmp/output"; exit 1; fi; } +check_fail() { if bash "$script" > "$tmp/output" 2>&1; then echo "unexpected success: $1" >&2; exit 1; fi; } +change() { jq "$1" just-recipes.json > "$FRESH"; } + +check_pass +change '.source = "new" | .recipes.run.body = [["new"]]' +check_pass +change '.recipes.run.parameters[0].export = true' +check_fail 'parameter export' +change '.recipes.run.parameters[0].flag = true' +check_fail 'parameter flag' +change '.recipes.run.dependencies[0].arguments[0][1] = "b"' +check_fail 'dependency argument' +change '.recipes.run.dependencies[0].star = true' +check_fail 'dependency star' +change '.aliases.r.target = "dep"' +check_fail 'alias target' +printf '{' > "$FRESH" +check_fail 'invalid fresh JSON' +cp just-recipes.json "$FRESH" +printf '{' > just-recipes.json +check_fail 'invalid committed JSON' +echo 'just-recipes-check tests passed' diff --git a/pkgs/id/scripts/just-recipes-check.sh b/pkgs/id/scripts/just-recipes-check.sh new file mode 100644 index 0000000000..8345b2b1b2 --- /dev/null +++ b/pkgs/id/scripts/just-recipes-check.sh @@ -0,0 +1,23 @@ +#!/usr/bin/env bash +set -euo pipefail +tmp="$(mktemp -d)" +trap 'rm -rf "$tmp"' EXIT +just --dump --dump-format json > "$tmp/fresh.json" +# Compare semantic fields only: recipe presence, doc, parameters, +# dependencies and the private flag, plus alias targets. The top-level +# `source` is an absolute path from the generating machine and recipe +# bodies serialise differently between just versions (the `bench` +# nesting, #2729), so both are projected out — a byte diff would +# false-positive forever. +project() { + jq -S '{recipes: (.recipes | to_entries | map({key, value: {doc: .value.doc, parameters: .value.parameters, dependencies: .value.dependencies, private: (.value.private // false)}}) | from_entries), aliases: ((.aliases // {}) | to_entries | map({key, value: .value.target}) | from_entries)}' "$1" +} +# Project separately: failures inside process substitutions are otherwise hidden +# by diff's exit status and can incorrectly report a match. +project just-recipes.json > "$tmp/committed.json" +project "$tmp/fresh.json" > "$tmp/projected.json" +if ! diff "$tmp/committed.json" "$tmp/projected.json"; then + echo "error: just-recipes.json has drifted from the justfile — run 'just lockfiles' and commit the result" >&2 + exit 1 +fi +echo "✓ just-recipes.json matches the justfile"