Skip to content

lease(merge-lane-gate-authority-compare): frozen contract feb3863e (r3) + lease - #85

Closed
rizzstack-coordinator[bot] wants to merge 1 commit into
mainfrom
lease/merge-lane-gate-authority-compare-r3
Closed

rizzstack-coordinator[bot] wants to merge 1 commit into
mainfrom
lease/merge-lane-gate-authority-compare-r3

Conversation

@rizzstack-coordinator

Copy link
Copy Markdown
Contributor

Lease PR (r3) for the W1D merge-lane fix. Two files only: the frozen contract and its lease.

Facts

  • Repo mojomast/rizzstack. Base e6fb6119bba3fd7c6e200f8ad70f4931a3203f34.
  • Contract merge-lane-gate-authority-compare, sha256 feb3863e7940fcb195815d2c3ff2a1140ce3b092d76d693995245fa7c9f94131.
  • Owner approval line (verbatim, in review.approved_by): Kyle: approved: merge-lane-gate-authority-compare feb3863e7940fcb195815d2c3ff2a1140ce3b092d76d693995245fa7c9f94131 (RED 5246de7f1912855cc4e5d60974263337e274eb01 on red/w1d-gate-authority-compare-r2).
  • RED red/w1d-gate-authority-compare-r2 head 5246de7f1912855cc4e5d60974263337e274eb01: one tests-only commit, direct parent e6fb6119, +174/-0 in tests/test_merge_lane_v5.py.
  • Lease branch named for implementation: feat/merge-lane-gate-authority-compare-r3.

The r1 findings and how this cut fixes them

  1. The RED head's direct parent was not the declared base. The r2 branch had two commits. This cut is a single commit made directly on e6fb6119; git rev-parse 5246de7f^ is e6fb6119. The complete RED delta is in that one tree.
  2. AC-002 exercised only .github/scripts/lease_tamper.py. The test now loops both .github/scripts/lease_tamper.py and .github/workflows/gate-authority.yml through gate_authority_facts and requires gate_authority_stale_gate for each.

Evidence

Isolated empty HOME and XDG dirs:

  • base e6fb6119: Ran 179 tests, OK.
  • RED 5246de7f: Ran 185 tests in 3.739s, FAILED (failures=4) — the two AC-001 cases plus AC-002's two subTest paths; 0 errors.

hermes bundlebees tdd red: behavioral_failure, red: valid.
hermes bundlebees contract freeze: tests collected: 185 ids at source_rev, every AC reference resolved.

The RED commit

commit 5246de7f1912855cc4e5d60974263337e274eb01
Author: Hermes (coordinator) <hermes@localhost>
Date:   Tue Dec 1 22:07:36 2026 -0500

    test(merge-lane): W1d RED r3 - one commit from main, gate script and workflow paths

diff --git a/tests/test_merge_lane_v5.py b/tests/test_merge_lane_v5.py
index cfc39e4..01a5f38 100644
--- a/tests/test_merge_lane_v5.py
+++ b/tests/test_merge_lane_v5.py
@@ -2102,5 +2102,179 @@ class GateLookupHardeningTests(unittest.TestCase):
         self.assertTrue(out["gate_authority"]["head_check_present"])
 
 
+class GateAuthorityCompareDirectionTests(unittest.TestCase):
+    """W1d: the gated head must contain the current base tip.
+
+    The trusted ``pull_request_target`` run's ``head_sha`` is the pull-request
+    head, not a base commit.  Proving that the run judged the current base
+    therefore means comparing ``base_tip...run.head_sha``: ``ahead`` says the
+    gated head contains the base tip, ``identical`` says it is the tip.  The
+    reverse compare reports ``behind`` for every normal PR whose branch has
+    moved past the base, which is the shape that refused rizzstack#73 while its
+    gate run was green and pinned to exactly the current main.
+    """
+
+    REPO = "mojomast/rizzstack"
+    SUITE = 111
+    RUN_ID = 9
+    PR = 73
+    WORKFLOW = ".github/workflows/gate-authority.yml"
+
+    def base(self):
+        return "c" * 40
+
+    def head(self):
+        return "a" * 40
+
+    def workflow_run(self):
+        head = self.head()
+        base = self.base()
+        return {
+            "id": self.RUN_ID,
+            "check_suite_id": self.SUITE,
+            "path": self.WORKFLOW,
+            "event": "pull_request_target",
+            "head_sha": head,
+            "status": "completed",
+            "conclusion": "success",
+            "created_at": "2026-12-02T01:30:38Z",
+            "run_started_at": "2026-12-02T01:30:36Z",
+            "pull_requests": [
+                {
+                    "number": self.PR,
+                    "head": {"sha": head},
+                    "base": {"ref": "main", "sha": base},
+                }
+            ],
+            "repository": {"full_name": self.REPO},
+            "head_repository": {"full_name": self.REPO},
+        }
+
+    def pr(self):
+        return {
+            "number": self.PR,
+            "head": {"sha": self.head()},
+            "base": {"ref": "main", "sha": self.base()},
+        }
+
+    def facts(self, base_status="ahead", head_status="behind", compare_error=None,
+              compare_files=None):
+        """Drive gate_authority_facts through a GitHub double in both directions.
+
+        The base-first key is the direction the fix must request; the head-first
+        key reproduces GitHub's real answer for the reversed direction, so the
+        old code reaches a measured ``behind`` instead of an unreadable fact.
+        """
+        head = self.head()
+        base = self.base()
+        responses = {
+            "git/ref/heads/main": {"object": {"sha": base}},
+            "check-suites/%d" % self.SUITE: {"app": {"slug": "github-actions"}},
+            "compare/%s...%s" % (base, head): (
+                compare_error
+                if compare_error is not None
+                else {
+                    "status": base_status,
+                    "files": compare_files
+                    if compare_files is not None
+                    else [{"filename": "scripts/merge_lane_v5.py", "status": "modified"}],
+                }
+            ),
+            "compare/%s...%s" % (head, base): (
+                compare_error
+                if compare_error is not None
+                else {"status": head_status, "files": []}
+            ),
+        }
+        api = _FakeApi(responses)
+        out = lane.gate_authority_facts(
+            self.REPO,
+            self.PR,
+            self.pr(),
+            [self.workflow_run()],
+            "test-token",
+            api_url="https://api.test",
+            http=api,
+            demanded=True,
+        )
+        return out, api
+
+    def identical_facts(self):
+        """The equal-SHA case: the run's head is the base tip itself."""
+        sha = "d" * 40
+        run = self.workflow_run()
+        run["head_sha"] = sha
+        run["pull_requests"][0]["head"]["sha"] = sha
+        run["pull_requests"][0]["base"]["sha"] = sha
+        pr = {"number": self.PR, "head": {"sha": sha}, "base": {"ref": "main", "sha": sha}}
+        api = _FakeApi({
+            "git/ref/heads/main": {"object": {"sha": sha}},
+            "check-suites/%d" % self.SUITE: {"app": {"slug": "github-actions"}},
+            "compare/%s...%s" % (sha, sha): {"status": "identical", "files": []},
+        })
+        out = lane.gate_authority_facts(
+            self.REPO, self.PR, pr, [run], "test-token",
+            api_url="https://api.test", http=api, demanded=True,
+        )
+        return out, api
+
+    def test_a_gate_run_at_the_head_is_proven_against_an_ancestor_base(self):
+        """The #73 shape: run head == PR head, base an ancestor, all green."""
+        facts, _api = self.facts()
+        self.assertEqual(
+            lane.gate_authority_state(facts, self.head(), []),
+            (True, None, self.RUN_ID),
+        )
+
+    def test_the_compare_is_directed_from_the_base_tip_to_the_gated_head(self):
+        """The lane must ask GitHub for base_tip...head, not head...base_tip."""
+        _facts, api = self.facts()
+        compares = [url for url in api.calls if "/compare/" in url]
+        self.assertEqual(len(compares), 1)
+        self.assertIn("compare/%s...%s" % (self.base(), self.head()), compares[0])
+
+    def test_a_changed_gate_path_in_the_compare_still_refuses(self):
+        """The base-first compare's file list still feeds the gate-code check."""
+        for filename in (".github/scripts/lease_tamper.py", ".github/workflows/gate-authority.yml"):
+            with self.subTest(filename=filename):
+                facts, _api = self.facts(
+                    compare_files=[{"filename": filename, "status": "modified"}]
+                )
+                self.assertEqual(
+                    lane.gate_authority_state(facts, self.head(), []),
+                    (False, "gate_authority_stale_gate", self.RUN_ID),
+                )
+
+    def test_a_base_that_moved_past_the_gated_head_is_refused(self):
+        """A base the gated head does not contain is still a wrong base."""
+        for status in ("diverged", "behind"):
+            with self.subTest(status=status):
+                facts, _api = self.facts(base_status=status, head_status=status)
+                self.assertEqual(
+                    lane.gate_authority_state(facts, self.head(), []),
+                    (False, "gate_authority_wrong_base", self.RUN_ID),
+                )
+
+    def test_an_unreadable_compare_refuses(self):
+        """An unreadable compare is flagged unreadable and refused as unproven."""
+        facts, _api = self.facts(compare_error=lane.FetchError("compare unavailable"))
+        self.assertTrue(facts["error"])
+        self.assertIsNone(facts["runs"][0]["compare_status"])
+        self.assertEqual(
+            lane.gate_authority_state(facts, self.head(), []),
+            (False, "gate_authority_unproven", None),
+        )
+
+    def test_an_identical_compare_is_accepted(self):
+        """A run whose head is the base tip is proven (equal SHA, identical)."""
+        facts, api = self.identical_facts()
+        sha = "d" * 40
+        self.assertIn("compare/%s...%s" % (sha, sha), " ".join(api.calls))
+        self.assertEqual(
+            lane.gate_authority_state(facts, sha, []),
+            (True, None, self.RUN_ID),
+        )
+
+
 if __name__ == "__main__":
     unittest.main()

Chain

Earlier cuts 7ac505af (PR #83) and a2ce4269 (PR #84) are withdrawn, never merged; both PRs are closed and their branches kept. supersedes is empty because neither predecessor reached the base. This is the contract intended to land.

@rizzstack-coordinator

Copy link
Copy Markdown
Contributor Author

Superseded by the r4 cut for host r2: ancestry alone does not prove which base the run judged, and a 300-file compare can truncate the gate-path check. New RED red/w1d-gate-authority-compare-r3 @ b9a610f (one commit, parent e6fb611, +192/-0) and new contract f6b8e536095f6941ff7dc9fd238f3aa4bdd35a2c8586fd7a4d0f9b192d379c9a (owner approval pending; adds the run-base-sha AC). Branch kept; nothing merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants