Skip to content

lease(merge-lane-gate-authority-compare): frozen contract 7d322b2e (r5) + lease - #86

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

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

Conversation

@rizzstack-coordinator

Copy link
Copy Markdown
Contributor

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

  • Repo mojomast/rizzstack; base e6fb6119bba3fd7c6e200f8ad70f4931a3203f34; lease branch feat/merge-lane-gate-authority-compare-r5; contract 7d322b2e4f7fb6890c9a9bc4c17565aaa902299c0a928b490fac2cf14b05b379.
  • Owner approval line (verbatim in review.approved_by): Kyle: approved: merge-lane-gate-authority-compare 7d322b2e4f7fb6890c9a9bc4c17565aaa902299c0a928b490fac2cf14b05b379 (RED 2cf03fd224850b5819fbc9e29025c4e185c8eba8 on red/w1d-gate-authority-compare-r5).
  • RED red/w1d-gate-authority-compare-r5 2cf03fd224850b5819fbc9e29025c4e185c8eba8: one tests-only commit, direct parent e6fb6119, +192/-0 in tests/test_merge_lane_v5.py.

Corrections in r5 (owner review of r4): AC-004's 300 entries are 300 distinct non-gate files (docs/f000.md ... docs/f299.md), so GATE_AUTHORITY_COMPARE_LIMIT is what refuses, not the gate-path branch; AC-004 is regression: true because the limit and non-list refusal are on main since #49 and it fails at the RED only because of the compare direction; the stale counts and old AC references are cleaned (error flag AC-006, equal-SHA AC-007).

Isolated evidence (empty HOME and XDG dirs): base e6fb6119 Ran 179 tests, OK; RED 2cf03fd2 Ran 187 tests, FAILED (failures=7) across 4 test methods (AC-001 pair, AC-002's two paths, AC-003's behind subtest, AC-004's two paths), 0 errors. tdd red: behavioral_failure, valid. Freeze collected 187 ids, every AC reference resolved.

commit 2cf03fd224850b5819fbc9e29025c4e185c8eba8
Author: Hermes (coordinator) <hermes@localhost>
Date:   Tue Dec 1 22:34:53 2026 -0500

    test(merge-lane): W1d RED r5 - 300 distinct non-gate files for the limit case

diff --git a/tests/test_merge_lane_v5.py b/tests/test_merge_lane_v5.py
@@ -2104,0 +2105,192 @@ class GateLookupHardeningTests(unittest.TestCase):
+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, run_base=None):
+        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": run_base or 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, run_base=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(run_base=run_base)],
+            "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_run_tied_to_an_older_base_is_refused(self):
+        """Ancestry alone is not proof: the run must have judged the base tip."""
+        facts, _api = self.facts(run_base="b" * 40)
+        self.assertEqual(
+            lane.gate_authority_state(facts, self.head(), []),
+            (False, "gate_authority_wrong_base", self.RUN_ID),
+        )
+
+    def test_an_incomplete_or_malformed_file_list_is_refused(self):
+        """A truncated or unreadable compare file list can never prove the gate."""
+        for files in ("not-a-list", [{"filename": "docs/f%03d.md" % index, "status": "modified"} for index in range(300)]):
+            with self.subTest(files=type(files).__name__):
+                facts, _api = self.facts(compare_files=files)
+                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, reverse in (("diverged", "diverged"), ("behind", "ahead")):
+            with self.subTest(status=status):
+                facts, _api = self.facts(base_status=status, head_status=reverse)
+                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),
+        )
+
+

Earlier cuts 7ac505af/#83, a2ce4269/#84 and feb3863e/#85 and b9a610fb/r4 are withdrawn, never merged; their PRs are closed and branches kept. supersedes is empty because none reached the base.

@rizzstack-coordinator

Copy link
Copy Markdown
Contributor Author

Superseded by the r6 cut for the host r4 findings: AC-004 now also refuses a missing files key and a malformed entry, and AC-005 refuses a run with no entry base sha (compare still ahead); the blast radius no longer claims operand-only. New RED red/w1d-gate-authority-compare-r6 @ c6d2560 (one commit, parent e6fb611, +211/-0) and new contract 55360719423009b1fe4da094220813c3acd87d01e630486f14c8411a8460aa3d (owner line requested). 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