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
2 changes: 1 addition & 1 deletion .github/ci/delivery_evidence.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
50 changes: 35 additions & 15 deletions .github/ci/delivery_verify.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 } } '
Expand Down Expand Up @@ -545,15 +533,44 @@ 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"))
parser.add_argument("--proof-kind", choices=("admission", "qualified"))
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:
Expand All @@ -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))


Expand Down
13 changes: 13 additions & 0 deletions .github/ci/shadow_scope.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
48 changes: 48 additions & 0 deletions tests/test_ci_cutover.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import io
import json
import os
import runpy
import subprocess
import sys
import zipfile
Expand Down Expand Up @@ -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)})
Expand Down
5 changes: 3 additions & 2 deletions tests/test_lane_helpers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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
Expand Down
Loading