Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .github/ci-policy.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
88 changes: 88 additions & 0 deletions .github/scripts/check-fleet-search-parity.sh
Original file line number Diff line number Diff line change
@@ -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 <name> : compare $ATLAS_DIR/<name> with $FLEET_DIR/<name>.
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)"
93 changes: 93 additions & 0 deletions .github/scripts/check-fleet-search-parity.test.sh
Original file line number Diff line number Diff line change
@@ -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 <root>
RC=0
bash "$GUARD" "$1" >"$TMP/out" 2>&1 || RC=$?
}

expect_pass() { # expect_pass <name>
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 <name>
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)"
33 changes: 33 additions & 0 deletions .github/workflows/fleet-search-parity-guard.yml
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions pkgs/atlas-search/crates/atlas-search/src/pyjson.rs
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 4 additions & 0 deletions pkgs/atlas-search/crates/atlas-search/src/render.rs
Original file line number Diff line number Diff line change
@@ -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).
Expand Down
1 change: 1 addition & 0 deletions pkgs/fleet/crates/fleet-search/src/pyjson.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions pkgs/fleet/crates/fleet-search/src/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down