Quellcode durchsuchen

test(mse): hook_ready TD binding uses an empty tree without canonical bits

Tracked evidence/bitstream/prod2u_p4_normal_v3.bit is now discovered, so
ROOT is bound. Keep fail-closed coverage on a bitstream-free fixture root.

Co-authored-by: Cursor <cursoragent@cursor.com>
root vor 3 Monaten
Ursprung
Commit
e3f23c2e1f
1 geänderte Dateien mit 33 neuen und 14 gelöschten Zeilen
  1. 33 14
      tests/unit/test_td_source_closure_binding.py

+ 33 - 14
tests/unit/test_td_source_closure_binding.py

@@ -30,16 +30,33 @@ class TdSourceClosureBindingTests(unittest.TestCase):
 
 
     def test_hook_ready_without_bitstream(self) -> None:
     def test_hook_ready_without_bitstream(self) -> None:
         handoff = load_handoff()
         handoff = load_handoff()
+        with tempfile.TemporaryDirectory() as tmp:
+            empty = Path(tmp)
+            (empty / "projects" / "prod2u-door-temp").mkdir(parents=True)
+            (empty / "src" / "generated").mkdir(parents=True)
+            (empty / "projects" / "prod2u-door-temp" / "project.json").write_text(
+                "{}", encoding="utf-8"
+            )
+            (empty / "src" / "generated" / "td-source-manifest.json").write_text(
+                "{}", encoding="utf-8"
+            )
+            binding = handoff.build_td_source_closure_binding(empty)
+            self.assertIn(binding["status"], {"hook_ready", "hook_partial"})
+            self.assertEqual(binding["bitstream_binding"], "deferred_to_evidence_receipt")
+            self.assertIsNone(binding["bitstream"])
+
+    def test_repo_canonical_bitstream_is_discovered(self) -> None:
+        handoff = load_handoff()
+        bit = ROOT / "evidence" / "bitstream" / "prod2u_p4_normal_v3.bit"
+        if not bit.is_file():
+            self.skipTest("canonical evidence bitstream not tracked")
         binding = handoff.build_td_source_closure_binding(ROOT)
         binding = handoff.build_td_source_closure_binding(ROOT)
-        self.assertIn(binding["status"], {"hook_ready", "hook_partial"})
-        self.assertEqual(binding["bitstream_binding"], "deferred_to_evidence_receipt")
-        self.assertIsNone(binding["bitstream"])
-        self.assertTrue(
-            str(binding.get("commit_full") or "").startswith("cdf9f76")
-            or len(str(binding.get("commit_full") or "")) == 40
+        self.assertEqual(binding["status"], "bound")
+        self.assertEqual(binding["bitstream_binding"], "bound")
+        self.assertEqual(
+            binding["bitstream"]["sha256"],
+            "f3242a479d6fb75c586a64d2b9c5dd5cf5e5d0576abbc7d0862b044689a83e63",
         )
         )
-        self.assertIsNotNone(binding.get("td_source_manifest_sha256"))
-        self.assertIsNotNone(binding.get("project_config_sha256"))
 
 
     def test_bound_with_real_bitstream_and_report(self) -> None:
     def test_bound_with_real_bitstream_and_report(self) -> None:
         handoff = load_handoff()
         handoff = load_handoff()
@@ -74,12 +91,14 @@ class TdSourceClosureBindingTests(unittest.TestCase):
 
 
     def test_require_bitstream_fails_closed(self) -> None:
     def test_require_bitstream_fails_closed(self) -> None:
         handoff = load_handoff()
         handoff = load_handoff()
-        binding = handoff.build_td_source_closure_binding(
-            ROOT,
-            require_bitstream=True,
-        )
-        self.assertEqual(binding["status"], "bind_failed")
-        self.assertEqual(binding["bitstream_binding"], "missing_bitstream")
+        with tempfile.TemporaryDirectory() as tmp:
+            empty = Path(tmp)
+            binding = handoff.build_td_source_closure_binding(
+                empty,
+                require_bitstream=True,
+            )
+            self.assertEqual(binding["status"], "bind_failed")
+            self.assertEqual(binding["bitstream_binding"], "missing_bitstream")
 
 
     def test_post_staging_inventory_hook_blocks_before_staging(self) -> None:
     def test_post_staging_inventory_hook_blocks_before_staging(self) -> None:
         handoff = load_handoff()
         handoff = load_handoff()