|
| 1 | +"""Guard atomic Planner revision updates and reject unexpected manifests.""" |
| 2 | +import unittest |
| 3 | + |
| 4 | +from update_planner import pin_planner |
| 5 | + |
| 6 | + |
| 7 | +class PlannerPinTests(unittest.TestCase): |
| 8 | + revision = "a" * 40 |
| 9 | + manifest = ''.join( |
| 10 | + f'{name} = {{ git = "https://github.com/ProjectASAP/ASAPPlanner", rev = "{"b" * 40}" }}\n' |
| 11 | + for name in ['planner-types', 'asap-aware-mapping', 'asap-frontend-promql', 'asap-frontend-sql'] |
| 12 | + ) |
| 13 | + |
| 14 | + def test_atomic_and_idempotent(self): |
| 15 | + """All four dependencies advance together, without touching other Git pins.""" |
| 16 | + other = 'other = { git = "https://example.com/other", branch = "main" }\n' |
| 17 | + result = pin_planner(self.manifest + other, self.revision) |
| 18 | + self.assertEqual(result.count(f'rev = "{self.revision}"'), 4) |
| 19 | + self.assertTrue(result.endswith(other)) |
| 20 | + self.assertEqual(pin_planner(result, self.revision), result) |
| 21 | + |
| 22 | + def test_accepts_branch_selector(self): |
| 23 | + """A branch-based Planner manifest can be converted to reproducible pins.""" |
| 24 | + result = pin_planner(self.manifest.replace(f'rev = "{"b" * 40}"', 'branch = "main"'), self.revision) |
| 25 | + self.assertEqual(result.count(f'rev = "{self.revision}"'), 4) |
| 26 | + |
| 27 | + def test_rejects_changed_dependency_layout(self): |
| 28 | + """A removed dependency or missing selector requires a deliberate updater change.""" |
| 29 | + for manifest in [self.manifest.split('\n', 1)[1], self.manifest.replace(f', rev = "{"b" * 40}"', '')]: |
| 30 | + with self.subTest(manifest=manifest), self.assertRaises(ValueError): |
| 31 | + pin_planner(manifest, self.revision) |
| 32 | + |
| 33 | + def test_rejects_invalid_revision(self): |
| 34 | + """Branch names and truncated SHAs cannot become immutable pins.""" |
| 35 | + for revision in ['main', 'abc123', 'z' * 40]: |
| 36 | + with self.subTest(revision=revision), self.assertRaises(ValueError): |
| 37 | + pin_planner(self.manifest, revision) |
| 38 | + |
| 39 | + |
| 40 | +if __name__ == '__main__': |
| 41 | + unittest.main() |
0 commit comments