Skip to content

lease(merge-lane-gate-authority-compare): frozen contract 55360719 (r6) + lease - #87

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

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

Conversation

@rizzstack-coordinator

Copy link
Copy Markdown
Contributor

Lease PR (r6) 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-r6; contract 55360719423009b1fe4da094220813c3acd87d01e630486f14c8411a8460aa3d.
  • Owner approval line (verbatim in review.approved_by): Kyle: approved: merge-lane-gate-authority-compare 55360719423009b1fe4da094220813c3acd87d01e630486f14c8411a8460aa3d (RED c6d2560549926f0492da77bdcf448a8776906037 on red/w1d-gate-authority-compare-r6).
  • RED red/w1d-gate-authority-compare-r6 c6d2560549926f0492da77bdcf448a8776906037: one tests-only commit, direct parent e6fb6119, +211/-0 in tests/test_merge_lane_v5.py.

Changes vs r5 (host r4 findings): AC-004 refuses four malformed shapes — non-list, 300 distinct non-gate docs files, a document with no files key, and an entry with no readable filename; AC-005 also refuses a run whose entry carries no base sha, with the compare still reporting ahead; the blast radius now states that the slice changes the operand order AND adds the entry-base-sha check (it is not operand-only). The r5 owner corrections remain (300 distinct docs files so the limit refuses; AC-004 regression true; cleaned counts and AC references).

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

commit c6d2560549926f0492da77bdcf448a8776906037
Author: Hermes (coordinator) <hermes@localhost>
Date:   Tue Dec 1 22:58:26 2026 -0500

    test(merge-lane): W1d RED r6 - missing files key, malformed entry, missing base sha

diff --git a/tests/test_merge_lane_v5.py b/tests/test_merge_lane_v5.py
@@ -2104,0 +2105,211 @@ 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, files_present=True, base_sha_missing=False):
+        """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": []}
+            ),
+        }
+        if not files_present:
+            responses["compare/%s...%s" % (base, head)] = {"status": base_status}
+        run = self.workflow_run(run_base=run_base)
+        if base_sha_missing:
+            run["pull_requests"][0]["base"].pop("sha", None)
+        api = _FakeApi(responses)
+        out = lane.gate_authority_facts(
+            self.REPO,
+            self.PR,
+            self.pr(),
+            [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_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_a_run_without_a_base_sha_is_refused(self):
+        """A run with no entry base sha has not proved which base it judged."""
+        facts, _api = self.facts(base_sha_missing=True)
+        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):
+        """No readable, complete change set can ever prove the gate."""
+        cases = {
+            "non_list": dict(compare_files="not-a-list"),
+            "limit": dict(compare_files=[{"filename": "docs/f%03d.md" % index, "status": "modified"} for index in range(300)]),
+            "missing_key": dict(files_present=False),
+            "malformed_entry": dict(compare_files=[{"status": "modified"}]),
+        }
+        for name, kwargs in cases.items():
+            with self.subTest(case=name):
+                facts, _api = self.facts(**kwargs)
+                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, feb3863e/#85, b9a610fb, 7d322b2e/#86 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 r7 cut for host r5: AC-004 now includes a mixed list (valid non-gate entry beside an unreadable one) and AC-002 a file renamed out of a protected gate path; the historical count note is removed. New RED red/w1d-gate-authority-compare-r7 @ dbf5705 (one commit, parent e6fb611, +215/-0) and new contract 708908296376b5a6451c7b8afabf2f7512b033844015610bdb2cc21618ec310e (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