diff --git a/.github/ci-policy.md b/.github/ci-policy.md index 55065673d..57dd4b365 100644 --- a/.github/ci-policy.md +++ b/.github/ci-policy.md @@ -78,6 +78,20 @@ in `.github/scripts/check-mcpx-fix-test.test.sh`, which also run on pushes to main. PRs outside the workflow's `pkgs/mcpx/**` path filter never fire the check. +## fleet-search / atlas-search writer parity guard (#5920) + +`.github/workflows/fleet-search-parity-guard.yml` is a **basic-tier** +check (job `basic: fleet-search pyjson/render parity (#5920)`): +`pkgs/fleet/crates/fleet-search/src/{pyjson,render}.rs` are verbatim +copies of the atlas-search writers (fleet step 5, #5433), and the +guard in `.github/scripts/check-fleet-search-parity.sh` fails when +either pair diverges by anything beyond the pinned four-line parity +header at lines 2-5 of each file -- a changed or removed header fails +too. Shell contract tests live in +`.github/scripts/check-fleet-search-parity.test.sh` and run in the +same job. Intentional changes land in both copies in the same PR; +intentional header changes update the guard script in the same PR. + ## OpenCode metered-provider config guard `.github/workflows/opencode-config-guard.yml` runs the static guard and diff --git a/.github/scripts/check-fleet-search-parity.sh b/.github/scripts/check-fleet-search-parity.sh new file mode 100755 index 000000000..de45a6a97 --- /dev/null +++ b/.github/scripts/check-fleet-search-parity.sh @@ -0,0 +1,88 @@ +#!/usr/bin/env bash +# Byte-parity drift guard for the fleet-search / atlas-search writers +# (#5920, contract origin #5433). +# +# pkgs/fleet/crates/fleet-search/src/{pyjson,render}.rs are verbatim +# copies of pkgs/atlas-search/crates/atlas-search/src/{pyjson,render}.rs +# (fleet step 5, #5433): the output-parity contract lives in these +# writers, so the fleet verb renders service envelopes byte-identically +# to atlas-search. Nothing enforced that after the port, so a fix to a +# float-formatting or escaping edge case in one copy would silently +# break the contract. +# +# Rule: after removing each file's parity header -- the four `//!` +# lines at lines 2-5, directly after the shared first line -- the two +# copies of each pair must be byte-identical. The headers are not +# free-form: this script pins their exact text, so a header that +# changes or disappears fails here too, and an intentional header +# change must update this script in the same PR. Any other divergence +# fails with a diff. +# +# Usage: check-fleet-search-parity.sh [REPO_ROOT] +# REPO_ROOT defaults to the tree two directories above this script. +set -euo pipefail + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +ROOT="${1:-$(cd "$SCRIPT_DIR/../.." && pwd)}" + +ATLAS_DIR="$ROOT/pkgs/atlas-search/crates/atlas-search/src" +FLEET_DIR="$ROOT/pkgs/fleet/crates/fleet-search/src" + +ATLAS_HEADER='//! Source of the verbatim copy in pkgs/fleet'\''s fleet-search crate, +//! ported in fleet step 5 (#5433): the output-parity contract lives +//! in these writers, so mirror every change there. Drift guard: +//! .github/scripts/check-fleet-search-parity.sh (#5920).' + +FLEET_HEADER='//! Ported verbatim from pkgs/atlas-search'\''s bin crate in fleet step 5 +//! (#5433): the output-parity contract lives in these writers, so the +//! fleet verb renders service envelopes byte-identically to atlas-search. +//! Drift guard: .github/scripts/check-fleet-search-parity.sh (#5920).' + +TMP="$(mktemp -d)" +trap 'rm -rf "$TMP"' EXIT + +fail=0 + +# check_pair : compare $ATLAS_DIR/ with $FLEET_DIR/. +check_pair() { + local name="$1" + local atlas="$ATLAS_DIR/$name" fleet="$FLEET_DIR/$name" + local f + for f in "$atlas" "$fleet"; do + if [ ! -f "$f" ]; then + echo "::error::check-fleet-search-parity: missing file: $f (#5920)" + fail=1 + return + fi + done + + # The parity header is lines 2-5 of each copy; pin its exact text. + local got_atlas got_fleet + got_atlas="$(sed -n '2,5p' "$atlas")" + got_fleet="$(sed -n '2,5p' "$fleet")" + if [ "$got_atlas" != "$ATLAS_HEADER" ]; then + echo "::error::check-fleet-search-parity: parity header changed or missing in $atlas -- the header is pinned by this guard; update the header and this script together (#5920)" + fail=1 + fi + if [ "$got_fleet" != "$FLEET_HEADER" ]; then + echo "::error::check-fleet-search-parity: parity header changed or missing in $fleet -- the header is pinned by this guard; update the header and this script together (#5920)" + fail=1 + fi + + # Everything except the parity header (line 1 + lines 6+) must match. + sed '2,5d' "$atlas" >"$TMP/$name.atlas" + sed '2,5d' "$fleet" >"$TMP/$name.fleet" + if ! diff -u "$TMP/$name.atlas" "$TMP/$name.fleet" >"$TMP/$name.diff"; then + echo "::error::check-fleet-search-parity: $name diverged between atlas-search and fleet-search beyond the parity header -- the #5433 byte-parity contract is broken; mirror the change in both copies (#5920)" + cat "$TMP/$name.diff" + fail=1 + fi +} + +check_pair pyjson.rs +check_pair render.rs + +if [ "$fail" -ne 0 ]; then + exit 1 +fi +echo "fleet-search parity: OK - pyjson.rs and render.rs match atlas-search byte-for-byte outside the pinned parity headers (#5433 contract, guard #5920)" diff --git a/.github/scripts/check-fleet-search-parity.test.sh b/.github/scripts/check-fleet-search-parity.test.sh new file mode 100755 index 000000000..e975ac73b --- /dev/null +++ b/.github/scripts/check-fleet-search-parity.test.sh @@ -0,0 +1,93 @@ +#!/usr/bin/env bash +# Contract tests for check-fleet-search-parity.sh (#5920): the guard +# passes the current tree, and fails on body drift in either copy, on +# a changed parity header, and on a removed parity header. +set -euo pipefail + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +GUARD="$SCRIPT_DIR/check-fleet-search-parity.sh" +REPO_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)" +TMP="$(mktemp -d)" +trap 'rm -rf "$TMP"' EXIT + +# Copy the four writer files into a scratch tree shaped like the repo. +make_tree() { + local dest="$1" + mkdir -p "$dest/pkgs/atlas-search/crates/atlas-search/src" \ + "$dest/pkgs/fleet/crates/fleet-search/src" + local pair + for pair in \ + "pkgs/atlas-search/crates/atlas-search/src/pyjson.rs" \ + "pkgs/atlas-search/crates/atlas-search/src/render.rs" \ + "pkgs/fleet/crates/fleet-search/src/pyjson.rs" \ + "pkgs/fleet/crates/fleet-search/src/render.rs"; do + cp "$REPO_ROOT/$pair" "$dest/$pair" + done +} + +RC=0 +run_guard() { # run_guard + RC=0 + bash "$GUARD" "$1" >"$TMP/out" 2>&1 || RC=$? +} + +expect_pass() { # expect_pass + if [ "$RC" -ne 0 ]; then + echo "FAIL: $1 should have passed the guard" >&2 + cat "$TMP/out" >&2 + exit 1 + fi + echo "pass: $1 passes" +} + +expect_fail() { # expect_fail + if [ "$RC" -eq 0 ]; then + echo "FAIL: $1 should have failed the guard" >&2 + cat "$TMP/out" >&2 + exit 1 + fi + echo "pass: $1 fails" +} + +ATLAS_PY="$TMP/tree/pkgs/atlas-search/crates/atlas-search/src/pyjson.rs" +FLEET_PY="$TMP/tree/pkgs/fleet/crates/fleet-search/src/pyjson.rs" +FLEET_RENDER="$TMP/tree/pkgs/fleet/crates/fleet-search/src/render.rs" + +# 1. The current tree, copied verbatim, passes. +make_tree "$TMP/tree" +run_guard "$TMP/tree" +expect_pass "verbatim copies" + +# 2. A body change in the fleet copy only -> fail. +echo "// drift" >>"$FLEET_PY" +run_guard "$TMP/tree" +expect_fail "body drift in fleet pyjson.rs" + +# 3. A body change in the atlas copy only -> fail. +make_tree "$TMP/tree" +sed -i 's/byte-identical/byte-identical-ish/' "$TMP/tree/pkgs/atlas-search/crates/atlas-search/src/render.rs" 2>/dev/null || true +printf '\n// drift\n' >>"$TMP/tree/pkgs/atlas-search/crates/atlas-search/src/render.rs" +run_guard "$TMP/tree" +expect_fail "body drift in atlas render.rs" + +# 4. A changed fleet parity header -> fail. +make_tree "$TMP/tree" +sed -i '2s/Ported verbatim/Copied/' "$FLEET_RENDER" +run_guard "$TMP/tree" +expect_fail "changed fleet parity header" + +# 5. A removed atlas parity header -> fail. +make_tree "$TMP/tree" +sed -i '2,5d' "$ATLAS_PY" +run_guard "$TMP/tree" +expect_fail "removed atlas parity header" + +# 6. The mirrored change in BOTH copies -> pass (the contract is +# parity, not frozen content). +make_tree "$TMP/tree" +echo "// mirrored" >>"$ATLAS_PY" +echo "// mirrored" >>"$FLEET_PY" +run_guard "$TMP/tree" +expect_pass "mirrored change in both copies" + +echo "check-fleet-search-parity: all contract tests pass (#5920)" diff --git a/.github/workflows/fleet-search-parity-guard.yml b/.github/workflows/fleet-search-parity-guard.yml new file mode 100644 index 000000000..bb426d305 --- /dev/null +++ b/.github/workflows/fleet-search-parity-guard.yml @@ -0,0 +1,33 @@ +name: fleet-search-parity-guard + +# CI tier policy: see .github/ci-policy.md +# +# Byte-parity drift guard (#5920, contract origin #5433): the +# fleet-search copies of atlas-search's pyjson.rs / render.rs writers +# must stay byte-identical to the originals outside their pinned +# parity headers, or the fleet verb silently stops rendering service +# envelopes byte-identically to atlas-search. Pure bash -- no nix, no +# toolchain -- so this stays a seconds-long basic check. + +on: + merge_group: + workflow_dispatch: + +permissions: + contents: read + +concurrency: + group: fleet-search-parity-guard-${{ github.event_name == 'push' && github.run_id || github.ref }} + cancel-in-progress: true + +jobs: + parity-guard: + name: "basic: fleet-search pyjson/render parity (#5920)" + runs-on: ubuntu-latest + timeout-minutes: 5 + steps: + - uses: actions/checkout@v7 + - name: Guard contract tests (#5920) + run: bash .github/scripts/check-fleet-search-parity.test.sh + - name: Check fleet-search writers match atlas-search (#5433) + run: bash .github/scripts/check-fleet-search-parity.sh diff --git a/pkgs/atlas-search/crates/atlas-search/src/pyjson.rs b/pkgs/atlas-search/crates/atlas-search/src/pyjson.rs index 0821c6262..224dfb448 100644 --- a/pkgs/atlas-search/crates/atlas-search/src/pyjson.rs +++ b/pkgs/atlas-search/crates/atlas-search/src/pyjson.rs @@ -1,4 +1,8 @@ //! Python-compatible JSON rendering for the CLI's output. +//! Source of the verbatim copy in pkgs/fleet's fleet-search crate, +//! ported in fleet step 5 (#5433): the output-parity contract lives +//! in these writers, so mirror every change there. Drift guard: +//! .github/scripts/check-fleet-search-parity.sh (#5920). //! //! The Python prints envelopes with //! `json.dumps(out, indent=1, ensure_ascii=False)` and renders a diff --git a/pkgs/atlas-search/crates/atlas-search/src/render.rs b/pkgs/atlas-search/crates/atlas-search/src/render.rs index 4afa50401..4b9dc87bf 100644 --- a/pkgs/atlas-search/crates/atlas-search/src/render.rs +++ b/pkgs/atlas-search/crates/atlas-search/src/render.rs @@ -1,4 +1,8 @@ //! The `--text` renderer: a line-for-line port of the Python's +//! Source of the verbatim copy in pkgs/fleet's fleet-search crate, +//! ported in fleet step 5 (#5433): the output-parity contract lives +//! in these writers, so mirror every change there. Drift guard: +//! .github/scripts/check-fleet-search-parity.sh (#5920). //! `render_text` / `snippet`. Values render the way CPython's //! f-strings render them (floats via repr, None as "None", //! `rank_sources` as a Python dict repr). diff --git a/pkgs/fleet/crates/fleet-search/src/pyjson.rs b/pkgs/fleet/crates/fleet-search/src/pyjson.rs index c5ee0a9ec..1a5b97193 100644 --- a/pkgs/fleet/crates/fleet-search/src/pyjson.rs +++ b/pkgs/fleet/crates/fleet-search/src/pyjson.rs @@ -2,6 +2,7 @@ //! Ported verbatim from pkgs/atlas-search's bin crate in fleet step 5 //! (#5433): the output-parity contract lives in these writers, so the //! fleet verb renders service envelopes byte-identically to atlas-search. +//! Drift guard: .github/scripts/check-fleet-search-parity.sh (#5920). //! //! The Python prints envelopes with //! `json.dumps(out, indent=1, ensure_ascii=False)` and renders a diff --git a/pkgs/fleet/crates/fleet-search/src/render.rs b/pkgs/fleet/crates/fleet-search/src/render.rs index a8d91f40b..471a5be2e 100644 --- a/pkgs/fleet/crates/fleet-search/src/render.rs +++ b/pkgs/fleet/crates/fleet-search/src/render.rs @@ -2,6 +2,7 @@ //! Ported verbatim from pkgs/atlas-search's bin crate in fleet step 5 //! (#5433): the output-parity contract lives in these writers, so the //! fleet verb renders service envelopes byte-identically to atlas-search. +//! Drift guard: .github/scripts/check-fleet-search-parity.sh (#5920). //! `render_text` / `snippet`. Values render the way CPython's //! f-strings render them (floats via repr, None as "None", //! `rank_sources` as a Python dict repr).