From 1c1018dc30c8b5715761bb24ee56473676ce7173 Mon Sep 17 00:00:00 2001 From: Brett Heap Date: Fri, 20 Nov 2026 21:39:29 +0000 Subject: [PATCH 1/2] Preserve safe candidate CI refusal diagnostics --- .github/ci/delivery_evidence.py | 2 +- .github/ci/delivery_verify.py | 50 +++++++++++++++++++++++---------- .github/ci/shadow_scope.py | 13 +++++++++ tests/test_ci_cutover.py | 48 +++++++++++++++++++++++++++++++ 4 files changed, 97 insertions(+), 16 deletions(-) diff --git a/.github/ci/delivery_evidence.py b/.github/ci/delivery_evidence.py index c4423484..d165be08 100644 --- a/.github/ci/delivery_evidence.py +++ b/.github/ci/delivery_evidence.py @@ -20,7 +20,7 @@ import shadow_scope as policy import delivery_v13 as v13 import delivery_p07_p09 as exact_pair -from delivery_verify import PendingEvidence, require +from shadow_scope import PendingEvidence, require REPOSITORY = policy.REPOSITORY REPOSITORY_ID = 1434660228 diff --git a/.github/ci/delivery_verify.py b/.github/ci/delivery_verify.py index abe2f7a5..55c5199a 100644 --- a/.github/ci/delivery_verify.py +++ b/.github/ci/delivery_verify.py @@ -21,6 +21,7 @@ import shadow_scope as policy import delivery_v13 as v13 import delivery_p07_p09 as exact_pair +from shadow_scope import PendingEvidence, Refused, require REPOSITORY = policy.REPOSITORY FAST = "openrepotools-pr-fast" @@ -50,19 +51,6 @@ def delivery_scope(pr): return "claude-current" -class Refused(ValueError): - """A fixed-vocabulary refusal safe to expose in the CI log.""" - - -class PendingEvidence(Refused): - """Authenticated work is still running; waiting grants no CI omission.""" - - -def require(condition, reason): - if not condition: - raise Refused(reason) - - def review_page(number, cursor): after = "" if cursor is None else ",after:" + json.dumps(cursor) threads = ('reviewThreads(first:100) { pageInfo { hasNextPage } nodes { isResolved } } ' @@ -545,6 +533,33 @@ def write_record(record, env): output.write(data) +def candidate_failure(stage, error): + # Never interpolate exceptions or traceback data into the job log. Known + # call sites select fixed labels; an unfamiliar failure keeps its stage. + operations = { + "read_base_changes": "base history", + "review_page": "review history", + "ensure_commit": "immutable commit", + "job_log": "job log", + "github": "GitHub evidence", + } + operation = None + trace = error.__traceback__ + while trace: + operation = operations.get(trace.tb_frame.f_code.co_name, operation) + trace = trace.tb_next + if isinstance(error, subprocess.TimeoutExpired): + failure = "timeout" + elif isinstance(error, subprocess.SubprocessError): + failure = "subprocess" + elif isinstance(error, OSError): + failure = "I/O" + else: + failure = "invalid evidence" + detail = f"; operation: {operation}" if operation else "" + return f" Stage: {stage}{detail}; failure: {failure}." + + def main(): parser = argparse.ArgumentParser(description=__doc__) parser.add_argument("mode", choices=("fast", "candidate")) @@ -552,8 +567,10 @@ def main(): parser.add_argument("--require-delivery", action="store_true") args = parser.parse_args() mode = args.mode + stage = "event input" try: event = json.loads(Path(os.environ["GITHUB_EVENT_PATH"]).read_text(encoding="utf-8")) + stage = "candidate verification" result = (verify_fast(os.environ, event, Path.cwd()) if mode == "fast" else verify_candidate(os.environ, event, Path(__file__).resolve().parents[2])) if args.require_delivery: @@ -562,13 +579,16 @@ def main(): if args.proof_kind: require(mode == "candidate", "Proof output requires a candidate phase") # Imported lazily to keep the existing standalone fast CLI unchanged. + stage = "receipt validation" from delivery_evidence import make_record record = make_record(result, args.proof_kind, os.environ) + stage = "receipt write" write_record(record, os.environ) except Refused as error: parser.exit(1, f"Delivery verification refused: {error}.\n") - except policy.ERRORS: - parser.exit(1, "Delivery verification refused: incomplete, stale or unsupported evidence.\n") + except policy.ERRORS as error: + detail = candidate_failure(stage, error) if mode == "candidate" else "" + parser.exit(1, f"Delivery verification refused: incomplete, stale or unsupported evidence.{detail}\n") print(json.dumps(result, sort_keys=True)) diff --git a/.github/ci/shadow_scope.py b/.github/ci/shadow_scope.py index e3c5199a..f648e482 100644 --- a/.github/ci/shadow_scope.py +++ b/.github/ci/shadow_scope.py @@ -25,6 +25,19 @@ UnicodeError, subprocess.SubprocessError) +class Refused(ValueError): + """A fixed-vocabulary refusal safe to expose in the CI log.""" + + +class PendingEvidence(Refused): + """Authenticated work is still running; waiting grants no CI omission.""" + + +def require(condition, reason): + if not condition: + raise Refused(reason) + + def git(root, *args): return subprocess.run(["git", "-C", str(root), *args], check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, diff --git a/tests/test_ci_cutover.py b/tests/test_ci_cutover.py index a92d2fd1..b11eb8c5 100644 --- a/tests/test_ci_cutover.py +++ b/tests/test_ci_cutover.py @@ -9,6 +9,7 @@ import io import json import os +import runpy import subprocess import sys import zipfile @@ -510,6 +511,53 @@ def test_ci_cutover_top_heavy_cli_requires_current_delivery_intent(delivery, tmp assert refused.value.code == 1 +def test_ci_cutover_cli_preserves_fixed_evidence_refusal(cutover, tmp_path, monkeypatch, capsys): + entry = runpy.run_path(str(REPO / ".github/ci/delivery_verify.py")) + event = tmp_path / "event.json" + event.write_text("{}") + monkeypatch.setenv("GITHUB_EVENT_PATH", str(event)) + monkeypatch.setattr(sys, "argv", ["delivery_verify.py", "candidate", "--proof-kind", "admission"]) + monkeypatch.setitem(entry["main"].__globals__, "verify_candidate", lambda *_args: {}) + + def refused(*_args): + cutover.evidence.positive(False) + + monkeypatch.setattr(cutover.evidence, "make_record", refused) + with pytest.raises(SystemExit) as result: + entry["main"]() + captured = capsys.readouterr() + assert result.value.code == 1 + assert captured.out == "" + assert captured.err == "Delivery verification refused: Invalid numeric identity.\n" + + +def test_ci_cutover_cli_reports_candidate_timeout_without_raw_subprocess_data( + cutover, delivery, tmp_path, monkeypatch, capsys): + event = tmp_path / "event.json" + event.write_text("{}") + monkeypatch.setenv("GITHUB_EVENT_PATH", str(event)) + monkeypatch.setattr(sys, "argv", ["delivery_verify.py", "candidate"]) + + def refused(*_args): + cutover.evidence.ensure_commit(tmp_path, "a" * 40) + + def git_failure(_root, *args): + if args[0] == "cat-file": + raise subprocess.CalledProcessError(1, ["private command"], stderr=b"untrusted stderr") + raise subprocess.TimeoutExpired(["private command"], 20, output=b"untrusted stdout", + stderr=b"untrusted stderr") + + monkeypatch.setattr(cutover.policy, "git", git_failure) + monkeypatch.setattr(delivery, "verify_candidate", refused) + with pytest.raises(SystemExit) as result: + delivery.main() + captured = capsys.readouterr() + assert result.value.code == 1 + assert captured.out == "" + assert captured.err == ("Delivery verification refused: incomplete, stale or unsupported evidence. " + "Stage: candidate verification; operation: immutable commit; failure: timeout.\n") + + def test_ci_cutover_proof_writer_uses_only_exclusive_fixed_temp_file(delivery, tmp_path): record = {"fixture": "validated record"} delivery.write_record(record, {"RUNNER_TEMP": str(tmp_path)}) From 72d65a4da111a3c9ce25f859b47e4e5fecf56944 Mon Sep 17 00:00:00 2001 From: Brett Heap Date: Fri, 20 Nov 2026 22:21:26 +0000 Subject: [PATCH 2/2] Check restart intent credential-like field names, not path values --- tests/test_lane_helpers.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/test_lane_helpers.sh b/tests/test_lane_helpers.sh index 91b4eae0..c5d6a9eb 100755 --- a/tests/test_lane_helpers.sh +++ b/tests/test_lane_helpers.sh @@ -16732,7 +16732,8 @@ a14_three "lane-state" 0 "$E" lane-state repoRC-2 SV_BIN="$SANDBOX/svbin" mkdir -p "$SV_BIN" -SV_STATE="$SANDBOX/lane-state" +# Keep a credential-like substring in a legitimate path to exercise the field check. +SV_STATE="$SANDBOX/lane-key-state" mkdir -p "$SV_STATE" export LANES_LANE_STATE_ROOT="$SV_STATE" @@ -16824,7 +16825,7 @@ has "…and the launch mode that authorises a fresh session" "$out" "$(printf ' is "…with a digest of the handoff, computed by the writer" \ "$( [ "$(printf '%s\n' "$out" | awk -F'\t' '$1=="digest"{print length($2)}')" -gt 16 ] && echo yes || echo no )" yes is "…and no field that could carry a credential" \ - "$(printf '%s\n' "$out" | grep -Eci 'token|secret|password|key' || :)" 0 + "$(printf '%s\n' "$out" | cut -f1 | grep -Eci 'token|secret|password|key' || :)" 0 run "$E" set-restart-intent repoSV-1 pending --expect 'none|ready|failed' --operation op-test-2 is "a second /ctx does not supersede an operation in flight" "$rc" 7