From f79ebeb727a3c6d1ffd7653021809a7082ddca48 Mon Sep 17 00:00:00 2001 From: "Mark E. DeYoung" <1854350+mark-e-deyoung@users.noreply.github.com> Date: Fri, 23 Oct 2026 14:24:04 +0200 Subject: [PATCH 1/4] fix(evidence): identify source head separately from tested checkout --- scripts/ci/generate-trust-pack.sh | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/scripts/ci/generate-trust-pack.sh b/scripts/ci/generate-trust-pack.sh index 4c229533..ede0863c 100755 --- a/scripts/ci/generate-trust-pack.sh +++ b/scripts/ci/generate-trust-pack.sh @@ -2,18 +2,29 @@ set -euo pipefail OUT_DIR="${1:-artifacts/trust-pack}" -mkdir -p "$OUT_DIR" -timestamp="$(date -u +%Y-%m-%dT%H:%M:%SZ)" -sha="$(git rev-parse --short HEAD 2>/dev/null || echo unknown)" +# The checkout can be a synthetic PR merge commit rather than the source head. +# Record both IDs with unambiguous names; refuse provenance-free evidence. +checkout_sha="$(git rev-parse HEAD 2>/dev/null || true)" +source_sha="${WINEBOT_SOURCE_HEAD_SHA:-$checkout_sha}" +for candidate in "$checkout_sha" "$source_sha"; do + if [[ ! "$candidate" =~ ^[0-9a-f]{40}$ ]]; then + echo "Trust pack requires valid full checkout/source Git SHAs" >&2 + exit 1 + fi +done branch="$(git rev-parse --abbrev-ref HEAD 2>/dev/null || echo unknown)" +timestamp="$(date -u +%Y-%m-%dT%H:%M:%SZ)" +mkdir -p "$OUT_DIR" cat > "${OUT_DIR}/summary.md" < Date: Fri, 23 Oct 2026 14:24:23 +0200 Subject: [PATCH 2/4] fix(ci): pass immutable PR source head to trust pack receipt --- .github/workflows/reusable-build-smoke-gate.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/reusable-build-smoke-gate.yml b/.github/workflows/reusable-build-smoke-gate.yml index 82c6604c..ad2442ee 100755 --- a/.github/workflows/reusable-build-smoke-gate.yml +++ b/.github/workflows/reusable-build-smoke-gate.yml @@ -177,6 +177,9 @@ jobs: - name: Generate trust pack artifact if: ${{ inputs.generate_trust_pack }} + env: + # Checkout of a PR may be a synthetic merge; preserve the actual source head. + WINEBOT_SOURCE_HEAD_SHA: ${{ github.event.pull_request.head.sha || github.sha }} run: scripts/ci/generate-trust-pack.sh "${{ inputs.trust_pack_dir }}" - name: Upload trust pack From e249fb068e5cccdc0a4cabd0f8682331ee4f7603 Mon Sep 17 00:00:00 2001 From: "Mark E. DeYoung" <1854350+mark-e-deyoung@users.noreply.github.com> Date: Fri, 23 Oct 2026 14:25:03 +0200 Subject: [PATCH 3/4] test(ci): distinguish exact PR source and tested checkout identities --- tests/test_ci_trust_pack_provenance.py | 93 ++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 tests/test_ci_trust_pack_provenance.py diff --git a/tests/test_ci_trust_pack_provenance.py b/tests/test_ci_trust_pack_provenance.py new file mode 100644 index 00000000..bbba38dd --- /dev/null +++ b/tests/test_ci_trust_pack_provenance.py @@ -0,0 +1,93 @@ +"""Guard exact Git source-versus-checkout provenance in public trust packs.""" + +from __future__ import annotations + +import os +import subprocess +from pathlib import Path + +import pytest + +GENERATOR = Path(__file__).resolve().parents[1] / "scripts/ci/generate-trust-pack.sh" +WORKFLOW = ( + Path(__file__).resolve().parents[1] / ".github/workflows/reusable-build-smoke-gate.yml" +) +CHECKOUT = "b" * 40 +SOURCE = "a" * 40 + + +@pytest.fixture +def workspace(tmp_path: Path) -> Path: + bin_dir = tmp_path / "bin" + bin_dir.mkdir() + fake_git = bin_dir / "git" + fake_git.write_text( + "#!/bin/sh\n" + 'if [ "$1" = "rev-parse" ] && [ "$2" = "HEAD" ]; then\n' + ' printf "%s\\n" "$FAKE_CHECKOUT_SHA"\n' + 'elif [ "$1" = "rev-parse" ] && [ "$2" = "--abbrev-ref" ]; then\n' + ' printf "HEAD\\n"\n' + "else\n" + " exit 7\n" + "fi\n", + encoding="utf-8", + ) + fake_git.chmod(0o755) + return tmp_path + + +def generate(workspace: Path, source: str | None = SOURCE, checkout: str = CHECKOUT): + env = { + **os.environ, + "PATH": f"{workspace / 'bin'}:{os.environ.get('PATH', '')}", + "FAKE_CHECKOUT_SHA": checkout, + } + if source is None: + env.pop("WINEBOT_SOURCE_HEAD_SHA", None) + else: + env["WINEBOT_SOURCE_HEAD_SHA"] = source + output = workspace / "pack" + result = subprocess.run( + ["bash", str(GENERATOR), str(output)], + cwd=workspace, + env=env, + text=True, + capture_output=True, + check=False, + timeout=30, + ) + return result, output + + +def test_merged_checkout_not_misrepresented_as_source(workspace: Path) -> None: + result, out = generate(workspace) + assert result.returncode == 0, result.stderr + summary = (out / "summary.md").read_text(encoding="utf-8") + assert f"- Tested checkout commit: {CHECKOUT}" in summary + assert f"- Source head commit: {SOURCE}" in summary + assert "- Commit: " not in summary + assert (out / "inventory.json").is_file() + + +def test_direct_checkout_defaults_source_to_tested_commit(workspace: Path) -> None: + result, out = generate(workspace, source=None) + assert result.returncode == 0, result.stderr + summary = (out / "summary.md").read_text(encoding="utf-8") + assert f"- Source head commit: {CHECKOUT}" in summary + + +@pytest.mark.parametrize( + ("source", "checkout"), + [("not-a-commit", CHECKOUT), (SOURCE, "invalid-checkout")], +) +def test_invalid_identity_fails_before_publishing( + workspace: Path, source: str, checkout: str +) -> None: + result, out = generate(workspace, source=source, checkout=checkout) + assert result.returncode != 0 + assert not (out / "summary.md").exists() + + +def test_reusable_workflow_supplies_pr_source_head() -> None: + workflow = WORKFLOW.read_text(encoding="utf-8") + assert "WINEBOT_SOURCE_HEAD_SHA: ${{ github.event.pull_request.head.sha || github.sha }}" in workflow From e5c3328d61a7ed51ff7e436e3e7ead3e79e5cfb9 Mon Sep 17 00:00:00 2001 From: "Mark E. DeYoung" <1854350+mark-e-deyoung@users.noreply.github.com> Date: Fri, 23 Oct 2026 14:25:28 +0200 Subject: [PATCH 4/4] test(ci): run trust-pack provenance suite in normal unit gate --- scripts/ci/test.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/ci/test.sh b/scripts/ci/test.sh index 572871e1..bfe80059 100755 --- a/scripts/ci/test.sh +++ b/scripts/ci/test.sh @@ -22,4 +22,5 @@ pytest \ tests/test_diag_bundle.py \ tests/test_auto_view.py \ tests/test_ui_dashboard.py \ - tests/test_ui_accessibility.py + tests/test_ui_accessibility.py \ + tests/test_ci_trust_pack_provenance.py