From df6b700fb07eb47e95ec39e264c238ea1ea0a3ec Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Sun, 27 Sep 2026 19:54:38 +0000 Subject: [PATCH 1/4] apply_all: generic semantic already-applied check + machine-readable stack summary - semantic_already_applied(): a landed patch whose surrounding context later drifted (0017 after main #140 grew tests/test_pinned_sources.py) failed both forward and reverse --check although every hunk is on the tree. Now a patch counts as already-applied iff every '+' line is present and every removed line absent in each target file; create/delete patches never qualify. - print_summary(): 'apply_all: summary forward=N already_applied=M skipped=K already_on_tip=0|1' so callers can tell 'whole stack already on tree' from 'forward apply needed' without parsing echoes. --check uses pushd instead of a subshell so the counters survive. Scientific effect: NONE. Co-authored-by: Dylan Roy --- portable/patches/apply_all.sh | 92 +++++++++++++++++++++++++++++++++-- 1 file changed, 88 insertions(+), 4 deletions(-) diff --git a/portable/patches/apply_all.sh b/portable/patches/apply_all.sh index c8966000c..082223904 100755 --- a/portable/patches/apply_all.sh +++ b/portable/patches/apply_all.sh @@ -89,9 +89,61 @@ PATCHES=( "$ROOT/0019-attestations-close-file-handles.patch" ) +# Content-level already-applied test for a unified diff against the current +# tree: for every target file, all '+' lines must be present and all '-' lines +# (that are not re-added) must be absent. Whitespace-stripped line matching; +# a patch that deletes or creates files never qualifies. +semantic_already_applied() { + python3 - "$1" <<'PY' +import sys +from pathlib import Path + +patch = Path(sys.argv[1]).read_text(encoding="utf-8", errors="replace").splitlines() +files = {} +target = None +for line in patch: + if line.startswith("+++ "): + name = line[4:].split("\t")[0].strip() + if name == "/dev/null": + sys.exit(1) + target = name[2:] if name.startswith("b/") else name + files.setdefault(target, ([], [])) + elif line.startswith("--- "): + if line[4:].split("\t")[0].strip() == "/dev/null": + sys.exit(1) + elif target is not None and line.startswith("+") and not line.startswith("+++"): + files[target][0].append(line[1:].strip()) + elif target is not None and line.startswith("-") and not line.startswith("---"): + files[target][1].append(line[1:].strip()) + +if not files: + sys.exit(1) +for name, (added, removed) in files.items(): + path = Path(name) + if not path.is_file(): + sys.exit(1) + tree = {ln.strip() for ln in path.read_text(encoding="utf-8", errors="replace").splitlines()} + added_set = {ln for ln in added if ln} + removed_only = {ln for ln in removed if ln} - added_set + if not added_set and not removed_only: + sys.exit(1) + if not added_set <= tree: + sys.exit(1) + if removed_only & tree: + sys.exit(1) +sys.exit(0) +PY +} + # Batch 231: idempotent apply — if a patch is already on the tree (Path C landed # @ 93a4ecd / PR #64), skip it via reverse --check. Fail only when neither # forward nor reverse applies (real conflict / tip drift). +# Outcome counters (summary line lets callers decide whether the whole stack is +# already on the tree — the tip-drift tolerance signal — without parsing echoes). +N_FORWARD=0 +N_ALREADY=0 +N_SKIPPED=0 + apply_one() { local p="$1" local check_only="${2:-0}" @@ -101,6 +153,7 @@ apply_one() { bn="$(basename "$p")" if [[ ( "$bn" == 0018-* || "$bn" == 0019-* ) && ! -d attestations ]]; then echo "skip (attestations/ absent): ${bn}" + N_SKIPPED=$((N_SKIPPED + 1)) return 0 fi # Batch 378 tip-sync @ebedb78: 0018/0019 already on tip but context drifted @@ -108,10 +161,12 @@ apply_one() { # Treat semantic already-applied as success so keep-prior refresh can proceed. if [[ "$bn" == 0018-* ]] && grep -q '"attestations"' engine/bridge/work_order.py 2>/dev/null; then echo "already-applied (semantic): ${bn}" + N_ALREADY=$((N_ALREADY + 1)) return 0 fi if [[ "$bn" == 0019-* ]] && grep -q 'with open(candidate' tools/attestations_check.py 2>/dev/null; then echo "already-applied (semantic): ${bn}" + N_ALREADY=$((N_ALREADY + 1)) return 0 fi if git apply --check "$p" >/dev/null 2>&1; then @@ -124,10 +179,22 @@ apply_one() { git apply "$p" echo "check-ok: $(basename "$p")" fi + N_FORWARD=$((N_FORWARD + 1)) return 0 fi if git apply --reverse --check "$p" >/dev/null 2>&1; then echo "already-applied: $(basename "$p")" + N_ALREADY=$((N_ALREADY + 1)) + return 0 + fi + # Batch 810 tip-sync @e7652a1: landed patches whose surrounding context later + # drifted (e.g. 0017 after main #140 grew tests/test_pinned_sources.py) fail + # both forward and reverse --check although every hunk is on the tree. Generic + # semantic check: every added line present and every removed line absent in + # each target file ⇒ already-applied. Anything else still fails closed. + if semantic_already_applied "$p"; then + echo "already-applied (semantic): ${bn}" + N_ALREADY=$((N_ALREADY + 1)) return 0 fi echo "error: patch does not apply (forward or reverse): $(basename "$p")" >&2 @@ -143,6 +210,18 @@ apply_series() { done } +# Machine-readable stack summary. already_on_tip=1 iff no patch needed a forward +# apply (every patch already-applied or intentionally skipped) — this is the +# signal tip-drift gates use to tolerate BASE_TIP lagging a moved hardening tip +# once Path C has landed. Any forward apply or failure keeps it 0. +print_summary() { + local on_tip=0 + if [[ "$N_FORWARD" -eq 0 && "$N_ALREADY" -gt 0 ]]; then + on_tip=1 + fi + echo "apply_all: summary forward=${N_FORWARD} already_applied=${N_ALREADY} skipped=${N_SKIPPED} already_on_tip=${on_tip} head=$(git rev-parse --short HEAD 2>/dev/null || echo unknown)" +} + if [[ "$CHECK_ONLY" -eq 1 ]]; then # Disposable worktree so sequential deps validate without dirtying the caller's tree. WT="$(mktemp -d "${TMPDIR:-/tmp}/trial-apply-all-check.XXXXXX")" @@ -151,17 +230,22 @@ if [[ "$CHECK_ONLY" -eq 1 ]]; then } trap cleanup EXIT git worktree add --detach "$WT" HEAD >/dev/null - ( - cd "$WT" - apply_series 1 - ) + # pushd (not a subshell) so the outcome counters survive for print_summary. + pushd "$WT" >/dev/null + if ! apply_series 1; then + popd >/dev/null + exit 1 + fi + popd >/dev/null trap - EXIT cleanup + print_summary echo "Check OK (no changes applied; already-applied patches skipped)." exit 0 fi apply_series 0 +print_summary echo "Applied (or already on tip). Recommended verification:" echo " python3 tools/math_status_check.py" echo " python3 -m pytest -q tests/test_carriers.py tests/test_math_status.py tests/test_inventable_jetmod_probes.py tests/test_gaussian_moments.py tests/test_inventable_jetmod_instrumentation_status.py tests/test_claims.py tests/test_recovery.py" From 46b9e1e2bbc52798eb7423f81ae3c75012b9bb7a Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Sun, 27 Sep 2026 19:54:38 +0000 Subject: [PATCH 2/4] Add path_c_tip_drift_tolerance.sh (fail-closed drift verdict) and ship it in the pack Once Path C landed on hardening, BASE_TIP lagging the moving live tip is tolerable iff VERIFY.path_c_landed is true AND apply_all --check on the live tip reports already_on_tip=1 (no patch needed a forward apply). The helper emits one verdict line and exits 0 tolerated / 1 not / 2 transport. PATH_C_STRICT_TIP=1 restores the pure SHA-equality behaviour. pack_portable ships it (owner dry-runs call it); republish CRITICAL tracks it. Scientific effect: NONE. Co-authored-by: Dylan Roy --- scripts/pack_portable.sh | 1 + scripts/path_c_tip_drift_tolerance.sh | 148 +++++++++++++++++++++ scripts/republish_living_path_c_release.sh | 3 + 3 files changed, 152 insertions(+) create mode 100755 scripts/path_c_tip_drift_tolerance.sh diff --git a/scripts/pack_portable.sh b/scripts/pack_portable.sh index 2eea782a5..b7d49f3e2 100755 --- a/scripts/pack_portable.sh +++ b/scripts/pack_portable.sh @@ -265,6 +265,7 @@ tar -czf "$OUT" -C "$ROOT" \ scripts/refresh_ai_agent_access_inventory.py \ scripts/post_batch322_wake_comments.py \ scripts/assert_path_c_ready.sh \ + scripts/path_c_tip_drift_tolerance.sh \ scripts/write_path_c_status.py \ scripts/refresh_path_c_bundle.sh \ scripts/dispatch_land_path_c.sh \ diff --git a/scripts/path_c_tip_drift_tolerance.sh b/scripts/path_c_tip_drift_tolerance.sh new file mode 100755 index 000000000..77982ea2d --- /dev/null +++ b/scripts/path_c_tip_drift_tolerance.sh @@ -0,0 +1,148 @@ +#!/usr/bin/env bash +# path_c_tip_drift_tolerance.sh — decide whether BASE_TIP lagging the live +# hardening tip is tolerable for the Path C gates. +# +# Background: Path C landed on chatgpt/drive-github-hardening-20260919 (VERIFY +# path_c_landed=true). The hardening tip keeps moving (peer agents merge PRs +# several times per hour) while the coordinator loop keeps BASE_TIP pinned +# ("keep-prior"). The pure `live == BASE_TIP` gates therefore stay red forever +# although nothing is wrong: every portable patch is still on the tree. +# +# Tolerance rule (fail-closed): +# tolerated <=> VERIFY.json path_c_landed is true +# AND apply_all.sh --check on the LIVE tip exits 0 +# AND its summary reports already_on_tip=1 +# (no patch needed a forward apply; each one already-applied +# or intentionally skipped). +# Anything else (patch missing, forward apply needed, apply failure, transport +# failure) is NOT tolerated and the caller keeps its original hard failure. +# +# Set PATH_C_STRICT_TIP=1 to disable tolerance (always exit 1 on drift). +# +# Usage: +# path_c_tip_drift_tolerance.sh [--workdir DIR] [--live-sha SHA] +# --workdir DIR existing checkout of the live hardening tip (no clone) +# --live-sha SHA informational; printed in the verdict +# --verify-file PATH VERIFY.json to read path_c_landed from (tests) +# --help +# Without --workdir a shallow clone of the live hardening tip is made in a +# temp dir (GITHUB_TOKEN / GH_TOKEN / MAIN_PUSH_TOKEN used if present; never +# printed). +# +# Output: one verdict line +# path_c_tip_drift: tolerated=1|0 live= base_tip= reason= ... +# Exit: 0 tolerated, 1 not tolerated, 2 transport / missing inputs. +# Scientific effect: NONE — read-only checks; never flips lemma_closed. +set -euo pipefail + +ROOT="$(cd "$(dirname "$0")/.." && pwd)" +MAIN_REPO="${MAIN_REPO:-d6g8k5htny-coder/main}" +HARDENING_REF="${HARDENING_REF:-chatgpt/drive-github-hardening-20260919}" +APPLY_ALL="${ROOT}/portable/patches/apply_all.sh" +VERIFY_FILE="${ROOT}/portable/path-c-applied-bundle/VERIFY.json" +BASE_TIP_FILE="${ROOT}/portable/patches/BASE_TIP.txt" + +WORKDIR="" +LIVE_SHA="" +while [[ $# -gt 0 ]]; do + case "$1" in + --workdir) WORKDIR="${2:-}"; shift 2 ;; + --live-sha) LIVE_SHA="${2:-}"; shift 2 ;; + --verify-file) VERIFY_FILE="${2:-}"; shift 2 ;; + --help|-h) + sed -n '2,34p' "$0" | sed 's/^# \{0,1\}//' + exit 0 + ;; + *) echo "path_c_tip_drift: unknown arg $1" >&2; exit 2 ;; + esac +done + +BASE_SHA="" +if [[ -f "$BASE_TIP_FILE" ]]; then + # Prefer a full 40-hex SHA; the branch name carries a date (20260919) that a + # loose 7+-hex match would catch first. + BASE_SHA="$(tr -d '\r' <"$BASE_TIP_FILE" | head -n1 | python3 -c 'import re,sys; t=sys.stdin.read(); m=re.search(r"(?i)\b([0-9a-f]{40})\b", t) or re.search(r"(?i)\b(?=[0-9a-f]*[a-f])([0-9a-f]{7,39})\b", t); print(m.group(1).lower() if m else "")')" +fi + +verdict() { + # $1 tolerated 0/1, $2 reason, $3 extra + echo "path_c_tip_drift: tolerated=$1 live=${LIVE_SHA:-unknown} base_tip=${BASE_SHA:-unknown} reason=$2 ${3:-}scientific_effect=NONE" +} + +if [[ "${PATH_C_STRICT_TIP:-0}" == "1" ]]; then + verdict 0 strict_tip_requested + exit 1 +fi + +if [[ ! -f "$APPLY_ALL" ]]; then + verdict 0 missing_apply_all + exit 2 +fi + +LANDED=0 +if [[ -f "$VERIFY_FILE" ]] && python3 -c 'import json,sys; d=json.load(open(sys.argv[1])); sys.exit(0 if d.get("path_c_landed") is True else 1)' "$VERIFY_FILE" 2>/dev/null; then + LANDED=1 +fi +if [[ "$LANDED" -ne 1 ]]; then + verdict 0 path_c_not_landed + exit 1 +fi + +CLEANUP_DIR="" +cleanup() { + if [[ -n "$CLEANUP_DIR" && -d "$CLEANUP_DIR" ]]; then + rm -rf "$CLEANUP_DIR" + fi +} +trap cleanup EXIT + +if [[ -z "$WORKDIR" ]]; then + CLEANUP_DIR="$(mktemp -d "${TMPDIR:-/tmp}/path-c-tip-drift.XXXXXX")" + WORKDIR="$CLEANUP_DIR/main" + CLONE_URL="https://github.com/${MAIN_REPO}.git" + TOK="${GITHUB_TOKEN:-${GH_TOKEN:-${MAIN_PUSH_TOKEN:-}}}" + if [[ -n "$TOK" ]]; then + CLONE_URL="https://x-access-token:${TOK}@github.com/${MAIN_REPO}.git" + fi + if ! git clone -q --depth 1 --branch "$HARDENING_REF" "$CLONE_URL" "$WORKDIR" 2>/dev/null; then + verdict 0 clone_failed + exit 2 + fi +elif [[ ! -d "$WORKDIR/.git" && ! -f "$WORKDIR/.git" ]]; then + verdict 0 workdir_not_git + exit 2 +fi + +HEAD_SHA="$(git -C "$WORKDIR" rev-parse HEAD 2>/dev/null || true)" +if [[ -z "$LIVE_SHA" ]]; then + LIVE_SHA="$HEAD_SHA" +elif [[ -n "$HEAD_SHA" && "$HEAD_SHA" != "$LIVE_SHA" && "$HEAD_SHA" != "${LIVE_SHA}"* && "$LIVE_SHA" != "${HEAD_SHA}"* ]]; then + verdict 0 workdir_head_mismatch "workdir_head=${HEAD_SHA} " + exit 1 +fi + +set +e +CHECK_OUT="$(cd "$WORKDIR" && bash "$APPLY_ALL" --check 2>&1)" +CHECK_EC=$? +set -e +SUMMARY="$(printf '%s\n' "$CHECK_OUT" | grep -E '^apply_all: summary ' | tail -n1 || true)" +if [[ "$CHECK_EC" -ne 0 ]]; then + printf '%s\n' "$CHECK_OUT" | grep -E '^(error|warning):' >&2 || true + verdict 0 apply_all_check_failed "apply_all_exit=${CHECK_EC} " + exit 1 +fi +if [[ -z "$SUMMARY" ]]; then + verdict 0 apply_all_no_summary + exit 1 +fi +FORWARD="$(printf '%s' "$SUMMARY" | sed -n 's/.*forward=\([0-9]*\).*/\1/p')" +ALREADY="$(printf '%s' "$SUMMARY" | sed -n 's/.*already_applied=\([0-9]*\).*/\1/p')" +SKIPPED="$(printf '%s' "$SUMMARY" | sed -n 's/.*skipped=\([0-9]*\).*/\1/p')" +ON_TIP="$(printf '%s' "$SUMMARY" | sed -n 's/.*already_on_tip=\([01]\).*/\1/p')" +EXTRA="forward=${FORWARD:-?} already_applied=${ALREADY:-?} skipped=${SKIPPED:-?} " +if [[ "$ON_TIP" == "1" ]]; then + verdict 1 landed_stack_already_on_live_tip "$EXTRA" + exit 0 +fi +verdict 0 stack_not_fully_on_tip "$EXTRA" +exit 1 diff --git a/scripts/republish_living_path_c_release.sh b/scripts/republish_living_path_c_release.sh index a09431843..9c4660cdf 100755 --- a/scripts/republish_living_path_c_release.sh +++ b/scripts/republish_living_path_c_release.sh @@ -291,6 +291,9 @@ CRITICAL = ( # Batch 327: wake-comment poster paired with wake-batch322 workflow. "scripts/post_batch322_wake_comments.py", "scripts/refresh_path_c_bundle.sh", + # Tip-drift tolerance helper: called by refresh --dry-run and the owner + # land/open-PR dry-runs in the pack; drift here must flag script_stale. + "scripts/path_c_tip_drift_tolerance.sh", "scripts/pack_portable.sh", "scripts/probe_main_write.py", "scripts/probe_main_write_vectors.py", From 62bd6a2ac7050d598694083b23b84beaa52d827c Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Sun, 27 Sep 2026 19:54:53 +0000 Subject: [PATCH 3/4] Path C gates: tolerate BASE_TIP drift when the landed stack is already on the live tip MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The hardening tip moves several times per hour while the coordinator loop keeps BASE_TIP pinned (keep-prior). Every SHA-equality gate therefore stayed red on trial although nothing was wrong (all 16 portable patches on tip). Each gate now consults path_c_tip_drift_tolerance.sh before failing: - assert_path_c_ready.sh: WARN + continue to IDLE_PATH_C_DONE (OK line carries tip_drift_tolerated=1, apply_all_check=ok_already_on_tip) - path_c_dry_run.py: tip_drift_tolerated / apply_all_already_on_tip fields; already_on_tip = landed && (tip_match || tolerated) && apply_check_ok - owner_land_path_c.sh (--dry-run and --from-bundle --dry-run) and owner_open_path_c_pr.sh --dry-run: same already-on-tip idle class - refresh_path_c_bundle.sh --dry-run: exit 0 'TIP_DRIFT tolerated' - ci.yml portable-patches-on-main + path-c-applied-bundle-dry-apply: ::warning instead of ::error; BASE_TIP==VERIFY consistency still hard-fails Hard failure is retained whenever a patch is missing, needs a forward apply, or apply_all fails; PATH_C_STRICT_TIP=1 disables tolerance everywhere. Tests: new tests/test_path_c_tip_drift_tolerance.py (own module so the loop's appends to test_intent.py do not conflict); live dry-run assertions accept tip_drift_tolerated. BASE_TIP stays 2f7a5a9 (loop tests untouched). Scientific effect: NONE — lemma_closed / prizes / premises untouched. Co-authored-by: Dylan Roy --- .github/workflows/ci.yml | 49 ++++--- scripts/assert_path_c_ready.sh | 31 ++++- scripts/owner_land_path_c.sh | 54 ++++++-- scripts/owner_open_path_c_pr.sh | 17 ++- scripts/path_c_dry_run.py | 30 ++++- scripts/refresh_path_c_bundle.sh | 8 ++ tests/test_intent.py | 15 ++- tests/test_path_c_tip_drift_tolerance.py | 158 +++++++++++++++++++++++ 8 files changed, 321 insertions(+), 41 deletions(-) create mode 100644 tests/test_path_c_tip_drift_tolerance.py diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a988d6ab9..177173a79 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -170,17 +170,27 @@ jobs: exit 1 fi if [[ "$TIP" != "$BASE_SHA" ]]; then - echo "::error::tip-drift: live hardening SHA $TIP != BASE_TIP $BASE_SHA" - echo "::error::tip-drift: fix path: ./scripts/refresh_path_c_bundle.sh (refresh BASE_TIP + rebuild path-c-applied-bundle; does NOT push to main hardening)" - echo "::error::tip-drift: dry-sim only in CI — never auto-refresh onto main from Actions" - exit 1 + # Tip-drift tolerance: once Path C landed, BASE_TIP lagging the moving hardening + # tip is tolerated iff every portable patch is already on the live + # tree (path_c_tip_drift_tolerance.sh: apply_all --check already_on_tip=1). + # Otherwise fail loudly as before. + if bash trial/scripts/path_c_tip_drift_tolerance.sh --workdir main-work --live-sha "$TIP"; then + echo "::warning::tip-drift tolerated: live hardening ${TIP:0:7} != BASE_TIP ${BASE_SHA:0:7}; path_c_landed and whole stack already on live tip (keep-prior BASE_TIP)" + else + echo "::error::tip-drift: live hardening SHA $TIP != BASE_TIP $BASE_SHA" + echo "::error::tip-drift: fix path: ./scripts/refresh_path_c_bundle.sh (refresh BASE_TIP + rebuild path-c-applied-bundle; does NOT push to main hardening)" + echo "::error::tip-drift: dry-sim only in CI — never auto-refresh onto main from Actions" + exit 1 + fi + else + echo "tip-drift gate OK: live==BASE_TIP @ ${TIP:0:7}" fi - echo "tip-drift gate OK: live==BASE_TIP @ ${TIP:0:7}" - name: Tip-drift dry-sim (refresh_path_c_bundle --dry-run) run: | set -euo pipefail # Batch 176: exercise refresh helper on tip-stable trees (exit 0 no-op). - # On TIP_DRIFT this exits 1 with the same fix-path message; never pushes to main. + # On TIP_DRIFT this exits 1 with the same fix-path message unless the + # drift is tolerated (Tip-drift tolerance: landed stack already on live tip); never pushes to main. cd trial ./scripts/refresh_path_c_bundle.sh --dry-run - name: Apply portable patches @@ -291,22 +301,25 @@ jobs: echo "::error::tip-drift: empty BASE_TIP or VERIFY.base_tip_sha — fix: ./scripts/refresh_path_c_bundle.sh" exit 1 fi - if [[ "$TIP" != "$BASE_SHA" ]]; then - echo "::error::tip-drift: live hardening SHA $TIP != BASE_TIP $BASE_SHA" - echo "::error::tip-drift: fix path: ./scripts/refresh_path_c_bundle.sh (refresh BASE_TIP + rebuild path-c-applied-bundle; does NOT push to main hardening)" - echo "::error::tip-drift: CI dry-sim only — never auto-refresh onto main from Actions" - exit 1 - fi - if [[ "$TIP" != "$VERIFY_SHA" ]]; then - echo "::error::tip-drift: live hardening SHA $TIP != VERIFY.json base_tip_sha $VERIFY_SHA" - echo "::error::tip-drift: fix path: ./scripts/refresh_path_c_bundle.sh" - exit 1 - fi + # BASE_TIP and VERIFY must always agree with each other (bundle cut consistency). if [[ "$BASE_SHA" != "$VERIFY_SHA" ]]; then echo "::error::tip-drift: BASE_TIP $BASE_SHA != VERIFY.json base_tip_sha $VERIFY_SHA — fix: ./scripts/refresh_path_c_bundle.sh" exit 1 fi - echo "tip-drift gate OK: live==BASE_TIP==VERIFY @ ${TIP:0:7}" + if [[ "$TIP" != "$BASE_SHA" ]]; then + # Tip-drift tolerance: landed stack already on the live tip ⇒ drift tolerated + # (keep-prior BASE_TIP); anything less fails loudly as before. + if bash "${GITHUB_WORKSPACE}/trial/scripts/path_c_tip_drift_tolerance.sh" --workdir main-bundle --live-sha "$TIP"; then + echo "::warning::tip-drift tolerated: live hardening ${TIP:0:7} != BASE_TIP/VERIFY ${BASE_SHA:0:7}; path_c_landed and whole stack already on live tip (keep-prior BASE_TIP)" + else + echo "::error::tip-drift: live hardening SHA $TIP != BASE_TIP $BASE_SHA (== VERIFY.json base_tip_sha)" + echo "::error::tip-drift: fix path: ./scripts/refresh_path_c_bundle.sh (refresh BASE_TIP + rebuild path-c-applied-bundle; does NOT push to main hardening)" + echo "::error::tip-drift: CI dry-sim only — never auto-refresh onto main from Actions" + exit 1 + fi + else + echo "tip-drift gate OK: live==BASE_TIP==VERIFY @ ${TIP:0:7}" + fi # Batch 176: dry-sim refresh helper (tip-stable → exit 0; never pushes to main). echo "--- refresh_path_c_bundle.sh --dry-run (Batch 176 tip-drift dry-sim) ---" (cd "${GITHUB_WORKSPACE}/trial" && ./scripts/refresh_path_c_bundle.sh --dry-run) diff --git a/scripts/assert_path_c_ready.sh b/scripts/assert_path_c_ready.sh index b337937bb..a65d3bc49 100755 --- a/scripts/assert_path_c_ready.sh +++ b/scripts/assert_path_c_ready.sh @@ -142,12 +142,24 @@ if [[ ${#BASE_SHA} -eq 40 && "$LIVE_SHA" == "$BASE_SHA" ]]; then elif [[ ${#BASE_SHA} -ge 7 && ${#BASE_SHA} -lt 40 && "${LIVE_SHA:0:${#BASE_SHA}}" == "$BASE_SHA" ]]; then TIP_OK=1 fi +TIP_DRIFT_TOLERATED=0 if [[ "$TIP_OK" -ne 1 ]]; then - echo "assert_path_c_ready: FAIL tip-drift live=$LIVE_SHA != BASE_TIP=$BASE_SHA" >&2 - echo " refresh BASE_TIP + rebuild path-c-applied-bundle before land" >&2 - exit 1 + # Tip-drift tolerance: once Path C has landed, BASE_TIP lagging a moved hardening tip is + # tolerated iff every portable patch is already on the live tree + # (path_c_tip_drift_tolerance.sh → apply_all --check already_on_tip=1). + # Anything less keeps the hard failure below. + DRIFT_HELPER="${ROOT}/scripts/path_c_tip_drift_tolerance.sh" + if [[ -x "$DRIFT_HELPER" ]] && bash "$DRIFT_HELPER" --workdir "$WORKDIR" --live-sha "$LIVE_SHA"; then + TIP_DRIFT_TOLERATED=1 + echo "assert_path_c_ready: WARN tip-drift live=${LIVE_SHA:0:7} != BASE_TIP=${BASE_SHA:0:7} — tolerated (path_c_landed; stack already on live tip; keep-prior BASE_TIP)" + else + echo "assert_path_c_ready: FAIL tip-drift live=$LIVE_SHA != BASE_TIP=$BASE_SHA" >&2 + echo " refresh BASE_TIP + rebuild path-c-applied-bundle before land" >&2 + exit 1 + fi +else + echo "assert_path_c_ready: tip match OK @ ${LIVE_SHA:0:7}" fi -echo "assert_path_c_ready: tip match OK @ ${LIVE_SHA:0:7}" # Batch 230: Path C already merged on hardening — patches are on tip; do not re-apply. # Batch 246: post-0019 idle — skip redundant apply_all --check when landed+no pending @@ -219,9 +231,16 @@ verify_math_on_tip() { if [[ "$PATH_C_LANDED" -eq 1 && "$PENDING_FOLLOWON" -eq 0 ]]; then echo "assert_path_c_ready: IDLE_PATH_C_DONE tip=${LIVE_SHA:0:7} stack_end=${STACK_END} resolved=${RESOLVED_IDS} pending=[]" - echo "assert_path_c_ready: path_c_landed through tip patches — apply_all --check SKIPPED (redundant; catch 0020 when pending)" + APPLY_CHECK_NOTE="skipped_redundant" + if [[ "$TIP_DRIFT_TOLERATED" -eq 1 ]]; then + # Drift tolerance already ran apply_all --check on the live tip (all already-applied). + APPLY_CHECK_NOTE="ok_already_on_tip" + echo "assert_path_c_ready: path_c_landed through tip patches — apply_all --check ran via drift tolerance (already_on_tip=1)" + else + echo "assert_path_c_ready: path_c_landed through tip patches — apply_all --check SKIPPED (redundant; catch 0020 when pending)" + fi verify_math_on_tip "landed idle tip" - echo "assert_path_c_ready: OK tip=${LIVE_SHA:0:7} idle_status=IDLE_PATH_C_DONE apply_all_check=skipped_redundant stack_end=${STACK_END} path_c_landed=true lemma_closed=false scientific_effect=NONE" + echo "assert_path_c_ready: OK tip=${LIVE_SHA:0:7} idle_status=IDLE_PATH_C_DONE apply_all_check=${APPLY_CHECK_NOTE} tip_drift_tolerated=${TIP_DRIFT_TOLERATED} stack_end=${STACK_END} path_c_landed=true lemma_closed=false scientific_effect=NONE" elif [[ "$PATH_C_LANDED" -eq 1 && "$PENDING_FOLLOWON" -eq 1 ]]; then echo "assert_path_c_ready: path_c_landed=true but pending follow-ons [${PENDING_IDS}] — run apply_all --check (catch 0020+)" echo "assert_path_c_ready: apply_all --check" diff --git a/scripts/owner_land_path_c.sh b/scripts/owner_land_path_c.sh index e9aff7eab..58e166363 100755 --- a/scripts/owner_land_path_c.sh +++ b/scripts/owner_land_path_c.sh @@ -297,17 +297,51 @@ if [[ "$DRY_RUN" -eq 1 ]]; then exit 2 fi echo "live_hardening_sha=$LIVE_SHA" - if [[ "$LIVE_SHA" != "$BASE_TIP_SHA" && "$LIVE_SHA" != "${BASE_TIP_SHA}"* && "$BASE_TIP_SHA" != "${LIVE_SHA}"* ]]; then - echo "owner_land_path_c: ERROR: tip-drift live $LIVE_SHA != BASE_TIP $BASE_TIP_SHA — refresh bundle." >&2 - exit 1 - fi - echo "tip_matches_base=true" git config user.name "owner-land-path-c-dry" git config user.email "41898282+github-actions[bot]@users.noreply.github.com" if ! git checkout --detach "$LIVE_SHA" 2>/dev/null; then git fetch --depth 80 origin "$LIVE_SHA" 2>/dev/null || true git checkout --detach "$LIVE_SHA" || die "cannot checkout live hardening $LIVE_SHA" fi + FB_TIP_DRIFT_TOLERATED=0 + if [[ "$LIVE_SHA" != "$BASE_TIP_SHA" && "$LIVE_SHA" != "${BASE_TIP_SHA}"* && "$BASE_TIP_SHA" != "${LIVE_SHA}"* ]]; then + # Tip-drift tolerance: landed stack already on the live tip ⇒ drift tolerated (idle); + # otherwise keep the hard failure. + DRIFT_HELPER="$TRIAL_ROOT/scripts/path_c_tip_drift_tolerance.sh" + if [[ -f "$DRIFT_HELPER" ]] && bash "$DRIFT_HELPER" --workdir "$FB_WORKDIR/main" --live-sha "$LIVE_SHA"; then + FB_TIP_DRIFT_TOLERATED=1 + echo "tip_matches_base=false tip_drift_tolerated=true (path_c_landed; stack already on live tip; keep-prior BASE_TIP)" + else + echo "owner_land_path_c: ERROR: tip-drift live $LIVE_SHA != BASE_TIP $BASE_TIP_SHA — refresh bundle." >&2 + exit 1 + fi + else + echo "tip_matches_base=true" + fi + if [[ "$FB_TIP_DRIFT_TOLERATED" -eq 1 ]]; then + # Bundle history was cut at BASE_TIP; on a moved tip the .bundle/.patch replay + # is moot — the drift helper already proved every patch is on the tree. + echo "already_applied_on_tip=true" + echo "apply_all_check=OK (via tip-drift tolerance; bundle replay skipped)" + STATUS_OUT="$(python3 tools/math_status_check.py 2>&1)" || { + echo "owner_land_path_c: ERROR: math_status_check failed on live tip." >&2 + echo "$STATUS_OUT" >&2 + exit 1 + } + echo "$STATUS_OUT" + if ! echo "$STATUS_OUT" | grep -q 'lemma_closed=false'; then + echo "owner_land_path_c: ERROR: lemma_closed is not false on live tip." >&2 + exit 1 + fi + if ! echo "$STATUS_OUT" | grep -q 'problems=0'; then + echo "owner_land_path_c: ERROR: math_status problems!=0 on live tip." >&2 + exit 1 + fi + echo "owner_land_path_c: from-bundle dry-run OK — tip-drift tolerated (already_applied_on_tip); lemma_closed=false." + echo "would: NOT push / NOT open PR (Path C stack already on hardening tip; idle)" + echo "Scientific effect: NONE" + exit 0 + fi # Need BASE_TIP object for bundle prerequisite; LIVE_SHA == BASE_TIP when tip_matches. if [[ "$USE_GIT_BUNDLE" -eq 1 ]]; then if ! git fetch "$BUNDLE_GIT" "$BUNDLE_BRANCH"; then @@ -377,12 +411,16 @@ except Exception: d={} print("true" if d.get("path_c_landed") is True else "false") print("true" if d.get("tip_matches_base") is True else "false") -' "$DRY_JSON_OUT" 2>/dev/null || printf 'false\nfalse\n')" +print("true" if d.get("tip_drift_tolerated") is True else "false") +' "$DRY_JSON_OUT" 2>/dev/null || printf 'false\nfalse\nfalse\n')" LANDED_LINE="$(printf '%s\n' "$PATH_C_LANDED" | sed -n '1p')" TIP_MATCH_LINE="$(printf '%s\n' "$PATH_C_LANDED" | sed -n '2p')" + TIP_TOLERATED_LINE="$(printf '%s\n' "$PATH_C_LANDED" | sed -n '3p')" rm -f "$DRY_JSON_OUT" - if [[ "$LANDED_LINE" == "true" && "$TIP_MATCH_LINE" == "true" ]]; then - echo "already_on_tip=true path_c_landed=true tip_matches_base=true" + # Tip-drift tolerance: tip_drift_tolerated (landed + whole stack already on live tip) + # is the same idle class as an exact tip match. + if [[ "$LANDED_LINE" == "true" && ( "$TIP_MATCH_LINE" == "true" || "$TIP_TOLERATED_LINE" == "true" ) ]]; then + echo "already_on_tip=true path_c_landed=true tip_matches_base=${TIP_MATCH_LINE} tip_drift_tolerated=${TIP_TOLERATED_LINE}" echo "would: NOT push / NOT open PR (Path C stack already on hardening tip; idle)" echo "owner_land_path_c: dry-run OK — already-on-tip idle (no no-op land)." echo "Scientific effect: NONE" diff --git a/scripts/owner_open_path_c_pr.sh b/scripts/owner_open_path_c_pr.sh index f7ac2fff7..c33fbb476 100755 --- a/scripts/owner_open_path_c_pr.sh +++ b/scripts/owner_open_path_c_pr.sh @@ -236,12 +236,23 @@ if [[ "$DRY_RUN" -eq 1 ]]; then set +e LIVE_SHA="$(git ls-remote "https://github.com/${REPO}.git" "refs/heads/${HARDENING_REF}" 2>/dev/null | awk '{print $1}' | head -n1)" set -e + TIP_DRIFT_TOLERATED=0 if [[ -n "$LIVE_SHA" ]]; then echo "live_hardening_sha=$LIVE_SHA" if [[ "$LIVE_SHA" != "$BASE_TIP_SHA" && "$LIVE_SHA" != "${BASE_TIP_SHA}"* && "$BASE_TIP_SHA" != "${LIVE_SHA}"* ]]; then - die "tip-drift: live hardening $LIVE_SHA != BASE_TIP $BASE_TIP_SHA — refresh BASE_TIP + rebuild path-c-applied-bundle" + # Tip-drift tolerance: landed stack already on the live tip ⇒ drift tolerated (idle). + # The helper shallow-clones the live tip and runs apply_all --check. + DRIFT_HELPER="$TRIAL_ROOT/scripts/path_c_tip_drift_tolerance.sh" + [[ -f "$DRIFT_HELPER" ]] || DRIFT_HELPER="$(cd "$(dirname "$0")" && pwd)/path_c_tip_drift_tolerance.sh" + if [[ -f "$DRIFT_HELPER" ]] && bash "$DRIFT_HELPER" --live-sha "$LIVE_SHA"; then + TIP_DRIFT_TOLERATED=1 + echo "tip_matches_base=false tip_drift_tolerated=true (path_c_landed; stack already on live tip; keep-prior BASE_TIP)" + else + die "tip-drift: live hardening $LIVE_SHA != BASE_TIP $BASE_TIP_SHA — refresh BASE_TIP + rebuild path-c-applied-bundle" + fi + else + echo "tip_matches_base=true" fi - echo "tip_matches_base=true" else echo "warn: could not ls-remote live hardening tip (transport); skipping live tip-drift" fi @@ -263,6 +274,8 @@ print("true" if d.get("path_c_landed") is True else "false") TIP_OK=0 if [[ -n "$LIVE_SHA" && ( "$LIVE_SHA" == "$BASE_TIP_SHA" || "$LIVE_SHA" == "${BASE_TIP_SHA}"* || "$BASE_TIP_SHA" == "${LIVE_SHA}"* ) ]]; then TIP_OK=1 + elif [[ "$TIP_DRIFT_TOLERATED" -eq 1 ]]; then + TIP_OK=1 elif [[ -z "$LIVE_SHA" && -n "$VERIFY_SHA" && ( "$VERIFY_SHA" == "$BASE_TIP_SHA" || "$VERIFY_SHA" == "${BASE_TIP_SHA}"* || "$BASE_TIP_SHA" == "${VERIFY_SHA}"* ) ]]; then TIP_OK=1 echo "tip_matches_base=true (VERIFY.base_tip_sha; live ls-remote unavailable)" diff --git a/scripts/path_c_dry_run.py b/scripts/path_c_dry_run.py index e3ef2d88d..d1756ad00 100755 --- a/scripts/path_c_dry_run.py +++ b/scripts/path_c_dry_run.py @@ -334,11 +334,17 @@ def main() -> int: ) check = _run(["bash", str(apply_all), "--check"], cwd=apply_wt) apply_exit = check.returncode - apply_out = ((check.stdout or "") + (check.stderr or ""))[-800:] + full_out = (check.stdout or "") + (check.stderr or "") + apply_out = full_out[-800:] report["apply_all_check_exit"] = apply_exit report["apply_all_check_tail"] = apply_out if path_c_landed and apply_exit == 0: report["apply_all_check"] = "ok_already_landed_idempotent" + # apply_all summary: already_on_tip=1 ⇔ no patch needed a forward + # apply (each already-applied or intentionally skipped). + summary_match = re.search(r"^apply_all: summary .*already_on_tip=([01])", full_out, re.M) + stack_already_on_tip = bool(summary_match and summary_match.group(1) == "1") + report["apply_all_already_on_tip"] = stack_already_on_tip _run(["git", "worktree", "remove", "--force", str(apply_wt)], cwd=clone_dir) # Rebase probe: PATH_C_REBASE_ONTO_MAIN after #41 typically CONFLICTS. @@ -433,9 +439,29 @@ def main() -> int: apply_check_ok = bool(apply_ok and hard_shape["accepts"]) report["apply_check_ok"] = apply_check_ok tip_match = report.get("tip_matches_base") is True + # Tip-drift tolerance: BASE_TIP lagging a moved hardening tip is tolerated once Path C + # landed AND apply_all --check on the live tip reports the whole stack + # already on the tree (no forward apply). Fail-closed otherwise; the + # PATH_C_STRICT_TIP=1 env restores the pure SHA-equality gate. + tip_drift_tolerated = bool( + not tip_match + and path_c_landed + and apply_check_ok + and not args.skip_apply_check + and report.get("apply_all_already_on_tip") is True + and os.environ.get("PATH_C_STRICT_TIP") != "1" + ) + report["tip_drift_tolerated"] = tip_drift_tolerated + if tip_drift_tolerated: + report["tip_drift_note"] = ( + f"live hardening {hard_sha[:7]} != BASE_TIP {base_sha[:7]}; tolerated: " + "path_c_landed and every portable patch already on live tip (keep-prior BASE_TIP)" + ) # Batch 261: landed + tip match → idle (same class as owner_land_path_c / # owner_open_path_c_pr already-on-tip). Do not advertise APPLY_READY land. - already_on_tip = bool(path_c_landed and tip_match and apply_check_ok) + already_on_tip = bool( + path_c_landed and (tip_match or tip_drift_tolerated) and apply_check_ok + ) report["already_on_tip"] = already_on_tip if already_on_tip: report["state"] = "IDLE_PATH_C_DONE" diff --git a/scripts/refresh_path_c_bundle.sh b/scripts/refresh_path_c_bundle.sh index 779e2fddd..40d4af784 100755 --- a/scripts/refresh_path_c_bundle.sh +++ b/scripts/refresh_path_c_bundle.sh @@ -237,6 +237,14 @@ if [[ "$DRY_RUN" -eq 1 ]]; then exit 0 fi echo "refresh_path_c_bundle: dry-run TIP_DRIFT ${PRIOR_SHORT} -> ${LIVE_SHORT}" + # Tip-drift tolerance: keep-prior is the steady state once Path C landed — drift is + # tolerated (exit 0, no rebuild needed) iff every portable patch is already on + # the live tip. PATH_C_STRICT_TIP=1 restores the exit-1 behaviour. + DRIFT_HELPER="${ROOT}/scripts/path_c_tip_drift_tolerance.sh" + if [[ -f "$DRIFT_HELPER" ]] && bash "$DRIFT_HELPER" --live-sha "$LIVE_SHA"; then + echo "refresh_path_c_bundle: dry-run OK TIP_DRIFT tolerated ${PRIOR_SHORT} -> ${LIVE_SHORT} (path_c_landed; stack already on live tip; keep-prior BASE_TIP; no rebuild needed)" + exit 0 + fi echo "refresh_path_c_bundle: fix path: ./scripts/refresh_path_c_bundle.sh # updates BASE_TIP + rebuilds .patch+.bundle+VERIFY (does NOT push to main)" exit 1 fi diff --git a/tests/test_intent.py b/tests/test_intent.py index 8ecf32378..039cc43c3 100644 --- a/tests/test_intent.py +++ b/tests/test_intent.py @@ -892,7 +892,11 @@ def test_path_c_dry_run_post_aligned_keep_hardening() -> None: assert result.returncode == 0, result.stderr + result.stdout data = __import__("json").loads(result.stdout) assert data["scientific_effect"] == "NONE" - assert data["tip_matches_base"] is True + # Tip-drift tolerance: exact tip match, or landed stack already on a moved live tip. + assert data["tip_matches_base"] is True or data.get("tip_drift_tolerated") is True + if data.get("tip_drift_tolerated") is True: + assert data.get("path_c_landed") is True + assert data.get("apply_all_already_on_tip") is True assert data["default_aligned"] is True assert data["default_path_c_shape"]["accepts"] is False assert data["hardening_path_c_shape"]["accepts"] is True @@ -8441,7 +8445,8 @@ def test_batch261_path_c_dry_run_idle_when_already_on_tip() -> None: data = json.loads(result.stdout) assert data["scientific_effect"] == "NONE" assert data.get("path_c_landed") is True - assert data.get("tip_matches_base") is True + # Tip-drift tolerance: exact tip match, or landed stack already on a moved live tip. + assert data.get("tip_matches_base") is True or data.get("tip_drift_tolerated") is True assert data["state"] == "IDLE_PATH_C_DONE" assert data["apply_ready"] is False assert data.get("already_on_tip") is True @@ -9528,7 +9533,7 @@ def test_batch269_verify_batch_release_align() -> None: ) assert proc.returncode == 0, (proc.stderr or "") + (proc.stdout or "") combined = (proc.stdout or "") + (proc.stderr or "") - assert "tip stable" in combined or "match=1" in combined + assert "tip stable" in combined or "match=1" in combined or "TIP_DRIFT tolerated" in combined assert _living_tip(combined) brief = json.loads( @@ -10149,7 +10154,7 @@ def test_batch273_apply_verify_honesty_keep_prior() -> None: ) assert proc.returncode == 0, (proc.stderr or "") + (proc.stdout or "") combined = (proc.stdout or "") + (proc.stderr or "") - assert "tip stable" in combined or "match=1" in combined + assert "tip stable" in combined or "match=1" in combined or "TIP_DRIFT tolerated" in combined brief = json.loads( (ROOT / "portable" / "BATCH273_BRIEF.json").read_text(encoding="utf-8") @@ -10268,7 +10273,7 @@ def test_batch275_manifest_verified_batch_release_align() -> None: ) assert proc.returncode == 0, (proc.stderr or "") + (proc.stdout or "") combined = (proc.stdout or "") + (proc.stderr or "") - assert "tip stable" in combined or "match=1" in combined + assert "tip stable" in combined or "match=1" in combined or "TIP_DRIFT tolerated" in combined brief = json.loads( (ROOT / "portable" / "BATCH275_BRIEF.json").read_text(encoding="utf-8") diff --git a/tests/test_path_c_tip_drift_tolerance.py b/tests/test_path_c_tip_drift_tolerance.py new file mode 100644 index 000000000..4aba555bf --- /dev/null +++ b/tests/test_path_c_tip_drift_tolerance.py @@ -0,0 +1,158 @@ +"""Tip-drift tolerance for the Path C gates (engineering only). + +Once Path C landed on the hardening branch, BASE_TIP lagging the moving live +tip is tolerated iff every portable patch is already on the live tree. These +tests pin the fail-closed shape of that rule. They encode repository intent +only and must never be cited as scientific evidence. +""" + +from __future__ import annotations + +import json +import os +import subprocess +import sys +import tempfile +from pathlib import Path + +ROOT = Path(__file__).resolve().parents[1] +HELPER = ROOT / "scripts" / "path_c_tip_drift_tolerance.sh" +APPLY_ALL = ROOT / "portable" / "patches" / "apply_all.sh" + + +def _run(args: list[str], **kw) -> subprocess.CompletedProcess: + env = os.environ.copy() + env.pop("PATH_C_STRICT_TIP", None) + env.update(kw.pop("env", {})) + return subprocess.run( + args, capture_output=True, text=True, check=False, cwd=str(ROOT), env=env, **kw + ) + + +def _verdict(out: str) -> dict[str, str]: + lines = [ln for ln in out.splitlines() if ln.startswith("path_c_tip_drift: ")] + assert lines, out + fields = {} + for tok in lines[-1].split()[1:]: + if "=" in tok: + k, v = tok.split("=", 1) + fields[k] = v + return fields + + +def test_helper_exists_and_help() -> None: + assert HELPER.is_file() + assert HELPER.stat().st_mode & 0o111 + p = _run(["bash", str(HELPER), "--help"]) + assert p.returncode == 0, p.stderr + assert "tolerated" in p.stdout + assert "already_on_tip=1" in p.stdout + assert "PATH_C_STRICT_TIP" in p.stdout + text = HELPER.read_text(encoding="utf-8") + assert "scientific_effect=NONE" in text + assert "lemma_closed" in text + + +def test_apply_all_emits_stack_summary() -> None: + text = APPLY_ALL.read_text(encoding="utf-8") + assert "apply_all: summary forward=" in text + assert "already_on_tip=" in text + assert "semantic_already_applied" in text + # Counters must survive the --check worktree (pushd, not a subshell). + assert 'pushd "$WT"' in text + + +def test_strict_env_disables_tolerance() -> None: + p = _run(["bash", str(HELPER), "--workdir", str(ROOT)], env={"PATH_C_STRICT_TIP": "1"}) + assert p.returncode == 1, p.stdout + p.stderr + v = _verdict(p.stdout) + assert v["tolerated"] == "0" + assert v["reason"] == "strict_tip_requested" + + +def test_not_landed_is_never_tolerated() -> None: + with tempfile.TemporaryDirectory(prefix="drift-notlanded-") as td: + verify = Path(td) / "VERIFY.json" + verify.write_text(json.dumps({"path_c_landed": False}), encoding="utf-8") + p = _run(["bash", str(HELPER), "--workdir", str(ROOT), "--verify-file", str(verify)]) + assert p.returncode == 1, p.stdout + p.stderr + v = _verdict(p.stdout) + assert v["tolerated"] == "0" + assert v["reason"] == "path_c_not_landed" + + +def test_non_git_workdir_is_transport_error() -> None: + with tempfile.TemporaryDirectory(prefix="drift-nongit-") as td: + p = _run(["bash", str(HELPER), "--workdir", td]) + assert p.returncode == 2, p.stdout + p.stderr + v = _verdict(p.stdout) + assert v["tolerated"] == "0" + assert v["reason"] == "workdir_not_git" + + +def test_non_hardening_tree_fails_closed() -> None: + """apply_all refuses a tree without the hardening shape → not tolerated.""" + with tempfile.TemporaryDirectory(prefix="drift-shape-") as td: + subprocess.run(["git", "init", "-q", td], check=True) + (Path(td) / "README.md").write_text("not hardening\n", encoding="utf-8") + subprocess.run(["git", "-C", td, "add", "."], check=True) + subprocess.run( + ["git", "-C", td, "-c", "user.name=t", "-c", "user.email=t@t", "commit", "-qm", "x"], + check=True, + ) + p = _run(["bash", str(HELPER), "--workdir", td]) + assert p.returncode == 1, p.stdout + p.stderr + v = _verdict(p.stdout) + assert v["tolerated"] == "0" + assert v["reason"] == "apply_all_check_failed" + + +def test_gates_consult_the_helper() -> None: + """Every SHA-equality gate must consult the helper before failing on drift.""" + for rel in ( + "scripts/assert_path_c_ready.sh", + "scripts/owner_open_path_c_pr.sh", + "scripts/owner_land_path_c.sh", + "scripts/refresh_path_c_bundle.sh", + ".github/workflows/ci.yml", + ): + text = (ROOT / rel).read_text(encoding="utf-8") + assert "path_c_tip_drift_tolerance.sh" in text, rel + dry = (ROOT / "scripts" / "path_c_dry_run.py").read_text(encoding="utf-8") + assert "tip_drift_tolerated" in dry + assert "apply_all_already_on_tip" in dry + assert "PATH_C_STRICT_TIP" in dry + ci = (ROOT / ".github" / "workflows" / "ci.yml").read_text(encoding="utf-8") + # Both clone-based gates pass their own checkout; hard failure retained. + assert "--workdir main-work" in ci + assert "--workdir main-bundle" in ci + assert ci.count("::error::tip-drift: live hardening SHA") >= 2 + + +def test_live_tip_verdict_is_consistent() -> None: + """Live: on the current hardening tip the helper either tolerates (landed + stack fully on tip) or fails closed with a known reason. Skipped on transport.""" + p = _run(["bash", str(HELPER)], timeout=300) + if p.returncode == 2: + return + v = _verdict(p.stdout) + assert v["tolerated"] in ("0", "1") + if v["tolerated"] == "1": + assert p.returncode == 0 + assert v["reason"] == "landed_stack_already_on_live_tip" + assert v["forward"] == "0" + assert int(v["already_applied"]) > 0 + else: + assert p.returncode == 1 + assert v["reason"] in { + "path_c_not_landed", + "stack_not_fully_on_tip", + "apply_all_check_failed", + } + base = (ROOT / "portable" / "patches" / "BASE_TIP.txt").read_text(encoding="utf-8") + assert v["base_tip"] in base + assert v["scientific_effect"] == "NONE" + + +if __name__ == "__main__": + sys.exit(subprocess.call([sys.executable, "-m", "pytest", "-q", __file__])) From 0a268688570656e7e5a4184d2a44b3bf2e65912b Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Sun, 27 Sep 2026 20:19:40 +0000 Subject: [PATCH 4/4] tests: accept 'TIP_DRIFT tolerated' in the remaining refresh --dry-run assertions Three more variants (lower()-ed and 'dry-run OK tip stable') of the tip-stable check exist in test_intent.py; all now also accept the tolerated keep-prior verdict. No BASE_TIP change. Co-authored-by: Dylan Roy --- tests/test_intent.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/test_intent.py b/tests/test_intent.py index 039cc43c3..db6e10d83 100644 --- a/tests/test_intent.py +++ b/tests/test_intent.py @@ -3824,7 +3824,7 @@ def test_batch173_refresh_path_c_bundle() -> None: env={**os.environ, "GIT_TERMINAL_PROMPT": "0"}, ) assert dry.returncode == 0, dry.stdout + dry.stderr - assert "tip stable" in (dry.stdout + dry.stderr).lower() or "match=1" in (dry.stdout + dry.stderr) + assert "tip stable" in (dry.stdout + dry.stderr).lower() or "match=1" in (dry.stdout + dry.stderr) or "TIP_DRIFT tolerated" in (dry.stdout + dry.stderr) pack = (ROOT / "scripts" / "pack_portable.sh").read_text(encoding="utf-8") assert "refresh_path_c_bundle.sh" in pack @@ -3897,7 +3897,7 @@ def test_batch176_refresh_ci_tip_drift() -> None: env={**os.environ, "GIT_TERMINAL_PROMPT": "0"}, ) assert dry.returncode == 0, dry.stdout + dry.stderr - assert "tip stable" in (dry.stdout + dry.stderr).lower() or "match=1" in (dry.stdout + dry.stderr) + assert "tip stable" in (dry.stdout + dry.stderr).lower() or "match=1" in (dry.stdout + dry.stderr) or "TIP_DRIFT tolerated" in (dry.stdout + dry.stderr) # Bad remote should die cleanly (no KeyError traceback) bad = subprocess.run( @@ -7890,7 +7890,7 @@ def test_batch257_tip_fetch_rate_limit_and_print_owner_unblock_writable() -> Non assert proc.returncode == 0, out assert "tip_fetch_via=" in out assert "git_ls_remote" in out or "gh_api" in out - assert "dry-run OK tip stable" in out or "tip stable" in out + assert "dry-run OK tip stable" in out or "tip stable" in out or "TIP_DRIFT tolerated" in out unblock = (ROOT / "scripts" / "print_owner_unblock.sh").read_text(encoding="utf-8") assert "PATH_C_STATUS.json" in unblock