| 1 | """oakbench.landing: the fixture's designed conflicts are real, and verdicts are honest."""
|
| 2 | from __future__ import annotations
|
| 3 |
|
| 4 | import shutil
|
| 5 | import sys
|
| 6 | import tempfile
|
| 7 | import unittest
|
| 8 | from pathlib import Path
|
| 9 |
|
| 10 | sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "scripts"))
|
| 11 |
|
| 12 | from oakbench import landing # noqa: E402
|
| 13 |
|
| 14 |
|
| 15 | class FixtureTest(unittest.TestCase):
|
| 16 | def setUp(self) -> None:
|
| 17 | self.tmp = Path(tempfile.mkdtemp())
|
| 18 | self.addCleanup(shutil.rmtree, self.tmp, True)
|
| 19 |
|
| 20 | def tree(self, *workers: int) -> Path:
|
| 21 | root = self.tmp / ("t" + "-".join(map(str, workers)))
|
| 22 | landing.make_landing_fixture(root)
|
| 23 | for worker in workers:
|
| 24 | landing.apply_role(worker, root)
|
| 25 | return root
|
| 26 |
|
| 27 | def test_base_and_every_role_alone_pass(self) -> None:
|
| 28 | self.assertIs(landing.run_tests(self.tree()), True)
|
| 29 | for worker in range(6):
|
| 30 | self.assertIs(landing.run_tests(self.tree(worker)), True, landing.role_for(worker))
|
| 31 |
|
| 32 | def test_semantic_pair_breaks_only_together(self) -> None:
|
| 33 | # Apply in both orders: the files touched are disjoint, so the combined
|
| 34 | # tree is what any clean text merge would produce.
|
| 35 | self.assertIs(landing.run_tests(self.tree(0, 1)), False)
|
| 36 | self.assertIs(landing.run_tests(self.tree(1, 0)), False)
|
| 37 |
|
| 38 | def test_disjoint_workers_combine_cleanly(self) -> None:
|
| 39 | self.assertIs(landing.run_tests(self.tree(1, 4, 5)), True)
|
| 40 |
|
| 41 | def test_text_pair_edits_the_same_line(self) -> None:
|
| 42 | a, b = landing.apply_role(2, self.tree()), landing.apply_role(3, self.tree())
|
| 43 | self.assertEqual(a[0][0], b[0][0])
|
| 44 | self.assertNotEqual(a[0][1], b[0][1])
|
| 45 |
|
| 46 |
|
| 47 | def state(worker, outcome):
|
| 48 | return {"worker": worker, "outcome": outcome}
|
| 49 |
|
| 50 |
|
| 51 | class ClassifyTest(unittest.TestCase):
|
| 52 | L, R, C = landing.LANDED, landing.REFUSED_TESTS, landing.CONFLICT_REPORTED
|
| 53 |
|
| 54 | def test_git_like_run_is_clean(self) -> None:
|
| 55 | verdict = landing.classify([state(0, self.R), state(1, self.L), state(2, self.C), state(3, self.L)],
|
| 56 | True, False, {1: True, 3: True})
|
| 57 | self.assertEqual(verdict["semantic_conflict_outcome"], "caught_before_landing")
|
| 58 | self.assertEqual(verdict["text_conflict_outcome"], "conflict_reported")
|
| 59 | self.assertEqual(verdict["silent_failures"], 0)
|
| 60 |
|
| 61 | def test_both_semantic_sides_landing_on_red_main_is_a_silent_failure(self) -> None:
|
| 62 | verdict = landing.classify([state(0, self.L), state(1, self.L), state(2, self.C), state(3, self.L)],
|
| 63 | False, False, {0: True, 1: True, 3: True})
|
| 64 | self.assertEqual(verdict["semantic_conflict_outcome"], "landed_broken_silently")
|
| 65 | self.assertEqual(verdict["silent_failures"], 1)
|
| 66 |
|
| 67 | def test_both_text_sides_landing_is_a_silent_overwrite(self) -> None:
|
| 68 | verdict = landing.classify([state(0, self.R), state(1, self.L), state(2, self.L), state(3, self.L)],
|
| 69 | True, False, {1: True, 2: False, 3: True})
|
| 70 | self.assertEqual(verdict["text_conflict_outcome"], "silent_overwrite")
|
| 71 | self.assertEqual(verdict["workers_lost_after_landing"], 1)
|
| 72 | self.assertEqual(verdict["silent_failures"], 1) # one overwrite, counted once
|
| 73 |
|
| 74 | def test_unscanned_markers_leave_text_verdict_unmeasured(self) -> None:
|
| 75 | verdict = landing.classify([state(0, self.R), state(1, self.L), state(2, self.C), state(3, self.L)],
|
| 76 | True, None, {1: True, 3: True})
|
| 77 | self.assertIsNone(verdict["text_conflict_outcome"])
|
| 78 | self.assertIsNone(verdict["silent_failures"])
|
| 79 |
|
| 80 | def test_unreadable_main_is_unmeasured_not_clean(self) -> None:
|
| 81 | verdict = landing.classify([state(0, self.L), state(1, self.R), state(2, self.C), state(3, self.L)],
|
| 82 | None, None, {0: None, 3: None})
|
| 83 | self.assertIsNone(verdict["silent_failures"])
|
| 84 | self.assertIsNone(verdict["workers_lost_after_landing"])
|
| 85 |
|
| 86 |
|
| 87 | class RunnerTest(unittest.TestCase):
|
| 88 | """The real runner end to end (local only), checked against the lane contract."""
|
| 89 |
|
| 90 | def run_mode(self, subject):
|
| 91 | import parallel_contention
|
| 92 | from oakbench.rows import validate_rows
|
| 93 | tmp = Path(tempfile.mkdtemp())
|
| 94 | self.addCleanup(shutil.rmtree, tmp, True)
|
| 95 | metadata = {"bench_id": "test", "profile": "parallel-contention"}
|
| 96 | rows = parallel_contention.run_integration_landing(subject, tmp, 4, 1, tmp, 0, metadata)
|
| 97 | self.assertEqual(validate_rows(rows, "contention"), [])
|
| 98 | return rows
|
| 99 |
|
| 100 | def subject(self, kind):
|
| 101 | from oakbench.subjects import Subject, resolve_git_subject_bin
|
| 102 | if kind == "git":
|
| 103 | found = shutil.which("git")
|
| 104 | if not found:
|
| 105 | self.skipTest("git not installed")
|
| 106 | path, _, _ = resolve_git_subject_bin(Path(found), allow_shim=False)
|
| 107 | return Subject(name="git", kind="git", label="git", bin=path)
|
| 108 | found = shutil.which("oak")
|
| 109 | if not found:
|
| 110 | self.skipTest("oak not installed")
|
| 111 | return Subject(name="oak_installed", kind="oak", label="oak", bin=Path(found))
|
| 112 |
|
| 113 | def test_git_keeps_main_green(self) -> None:
|
| 114 | total = self.run_mode(self.subject("git"))[-1]
|
| 115 | verdict = total["landing"]
|
| 116 | self.assertEqual(verdict["semantic_conflict_outcome"], "caught_before_landing")
|
| 117 | self.assertEqual(verdict["text_conflict_outcome"], "conflict_reported")
|
| 118 | self.assertEqual(verdict["silent_failures"], 0)
|
| 119 | self.assertEqual(total["returncode"], 0)
|
| 120 | self.assertNotIn("tasks_completed", total["parallel_metrics"])
|
| 121 |
|
| 122 | def test_oak_rows_are_complete_and_verdicts_measured(self) -> None:
|
| 123 | # The outcome is Oak's behaviour under test; only the evidence shape is pinned.
|
| 124 | rows = self.run_mode(self.subject("oak"))
|
| 125 | total = rows[-1]
|
| 126 | self.assertIsNotNone(total["landing"]["silent_failures"], total.get("oracle_error"))
|
| 127 | self.assertIs(total["landing"]["server_ci_gate"], False)
|
| 128 | self.assertEqual(len(rows), 5)
|
| 129 | self.assertTrue(all(row.get("land_outcome") for row in rows[:-1]))
|
| 130 |
|
| 131 | def test_too_few_workers_is_a_skip_row(self) -> None:
|
| 132 | import parallel_contention
|
| 133 | rows = parallel_contention.run_integration_landing(self.subject("git"), Path("."), 3, 1, Path("."), 0,
|
| 134 | {"bench_id": "t", "profile": "p"})
|
| 135 | self.assertEqual(rows[0]["returncode"], parallel_contention.SKIP_RETURNCODE)
|
| 136 |
|
| 137 |
|
| 138 | if __name__ == "__main__":
|
| 139 | unittest.main()
|