Просмотр исходного кода

fix(packager): dedupe workspace and evidence-root canonical paths

Prefer the evidence-root physical copy when allowlist remaps collide on
the same evidence/ path so review-compact packaging stays fail-closed.

Co-authored-by: Cursor <cursoragent@cursor.com>
root 3 месяцев назад
Родитель
Сommit
ef730af40c
2 измененных файлов с 61 добавлено и 1 удалено
  1. 31 0
      package_for_agent_analysis.py
  2. 30 1
      tests/unit/test_evidence_canon.py

+ 31 - 0
package_for_agent_analysis.py

@@ -1278,6 +1278,37 @@ def collect_analysis_inputs(
         )
         items = list(kept_items)
         excluded.extend(filter_excluded)
+        # Workspace allowlist remaps + evidence-root staging can both land on the
+        # same canonical evidence/ path; keep one physical copy (prefer evidence-root).
+        deduped: dict[str, PackageItem] = {}
+        for item in items:
+            key = handoff.windows_collision_key(item.candidate.relative)
+            previous = deduped.get(key)
+            if previous is None:
+                deduped[key] = item
+                continue
+            prefer_new = item.source_id == "evidence-root" and previous.source_id != "evidence-root"
+            keep, drop = (item, previous) if prefer_new else (previous, item)
+            deduped[key] = keep
+            excluded.append(
+                {
+                    "path": drop.original_path or drop.candidate.relative,
+                    "rule": "canonical_path_physical_dedup",
+                }
+            )
+            if evidence_canon_fields is not None:
+                aliases = list(evidence_canon_fields.get("aliases") or [])
+                aliases.append(
+                    {
+                        "physical_path": keep.candidate.relative,
+                        "logical_paths": [
+                            f"evidence/from/{drop.original_path or drop.candidate.relative}"
+                        ],
+                        "reason": "canonical_path_physical_dedup",
+                    }
+                )
+                evidence_canon_fields["aliases"] = aliases
+        items = list(deduped.values())
         if evidence_canon_fields is None:
             evidence_canon_fields = evidence_canon.build_evidence_canon_index_fields(
                 catalog=[

+ 30 - 1
tests/unit/test_evidence_canon.py

@@ -246,7 +246,19 @@ class EvidenceCanonPackagerIntegrationTests(unittest.TestCase):
             temp = Path(tmp)
             repo = temp / "repo"
             write_file(repo, "src/core.v", b"module core; endmodule\n")
+            # Workspace IO path remaps to the same canonical evidence/io path as
+            # an evidence-root copy; packager must physically dedupe.
+            write_file(
+                repo,
+                "docs/IO_EVIDENCE_MATRIX.zh-CN.md",
+                b"# IO evidence workspace\n",
+            )
             evid = temp / "evid"
+            write_file(
+                evid,
+                "IO_EVIDENCE_MATRIX.zh-CN.md",
+                b"# IO evidence staged\n",
+            )
             write_file(
                 evid,
                 "evidence/formal-receipt.json",
@@ -282,11 +294,28 @@ class EvidenceCanonPackagerIntegrationTests(unittest.TestCase):
                 package_name="evidence-root-smoke",
                 evidence_root=evid,
             )
-            paths = {item.candidate.relative for item in collection.items}
+            paths = [item.candidate.relative for item in collection.items]
+            self.assertEqual(
+                paths.count("evidence/io/IO_EVIDENCE_MATRIX.zh-CN.md"),
+                1,
+                "workspace+evidence-root IO must physically dedupe",
+            )
+            io_item = next(
+                item
+                for item in collection.items
+                if item.candidate.relative == "evidence/io/IO_EVIDENCE_MATRIX.zh-CN.md"
+            )
+            self.assertEqual(io_item.source_id, "evidence-root")
             self.assertIn("evidence/formal/formal-receipt.json", paths)
             self.assertIn("evidence/hardware/HARDWARE_BRINGUP_NOTES.zh-CN.md", paths)
             self.assertIn("evidence/bitstream/prod2u_p4_normal_v3.bit", paths)
             self.assertFalse(any("lane-f-td" in path for path in paths))
+            self.assertTrue(
+                any(
+                    row.get("rule") == "canonical_path_physical_dedup"
+                    for row in collection.excluded
+                )
+            )
 
             result = analyzer.create_analysis_package(
                 collection=collection,