Преглед изворни кода

fix(packager): exclude vendor OSS CAD/toolchain archives from review packages

Wire common_file_exclusion_reason into analysis scans so root
oss-cad-suite*.tgz and td/bw release archives never enter review-compact
(and fail-closed archive inspection). Keep snapshot profile across
create so compact collections are not re-scanned as full.

Co-authored-by: Cursor <cursoragent@cursor.com>
root пре 3 месеци
родитељ
комит
cc5c828b2b

+ 14 - 2
package_for_agent_analysis.py

@@ -77,7 +77,7 @@ GENERATED_BINARY_SUFFIXES = {
     ".vvp",
 }
 TRANSIENT_SUFFIXES = {".pyc", ".pyo", ".tmp", ".partial", ".part", ".swp", ".swo"}
-ARCHIVE_SUFFIXES = {".zip", ".rar", ".7z"}
+ARCHIVE_SUFFIXES = {".zip", ".rar", ".7z", ".tgz", ".tar"}
 RUNTIME_EVIDENCE_SUFFIXES = {".log", ".logw", ".vcd", ".fst", ".lxt", ".gtkw", ".raw", ".bin"}
 BOARD_VIEWER_GENERATED_ASSETS = {
     "board-copper.svg",
@@ -207,6 +207,7 @@ class SourceSnapshot(NamedTuple):
     extra_exclusions: tuple[dict[str, str], ...]
     candidates: tuple[tuple[object, ...], ...]
     excluded: tuple[tuple[str, str], ...]
+    profile: str = "full"
 
 
 class AnalysisCollection(NamedTuple):
@@ -321,6 +322,7 @@ def _source_snapshot(
             for candidate in candidates
         ),
         excluded=tuple((item["path"], item["rule"]) for item in excluded),
+        profile=profile,
     )
 
 
@@ -456,6 +458,13 @@ def analysis_exclusion_reason(
     secret_reason = handoff.secret_path_reason(relative, is_dir=is_dir)
     if secret_reason:
         return secret_reason
+    # Shared vendor/toolchain installer and generated-file policy (handoff common rules).
+    # Critical for review-compact: root oss-cad-suite*.tgz / td_release_*.zip must never
+    # enter the package and then hit fail-closed archive secret inspection.
+    if not is_dir:
+        common_reason = handoff.common_file_exclusion_reason(relative)
+        if common_reason:
+            return common_reason
     if profile == "code-only":
         for prefix, reason in handoff.CODE_ONLY_ROOT_EXCLUSIONS.items():
             if handoff.is_under(lower, prefix):
@@ -2156,11 +2165,14 @@ def _assert_items_unchanged(
 
 def _assert_source_trees_unchanged(collection: AnalysisCollection, *, profile: str = "full") -> None:
     for snapshot in collection.source_snapshots:
+        # Prefer the profile captured at collection time so review-compact
+        # snapshots are not re-scanned under the create_analysis_package default.
+        check_profile = snapshot.profile or profile
         current = _source_snapshot(
             snapshot.root,
             source_id=snapshot.source_id,
             extra_exclusions=snapshot.extra_exclusions,
-            profile=profile,
+            profile=check_profile,
         )
         if (
             current.candidates != snapshot.candidates

+ 3 - 0
tests/unit/test_package_adversarial_compact.py

@@ -96,6 +96,7 @@ class ReviewCompactContractUnitTests(unittest.TestCase):
             "src/rtl/leak.brd": "compact_excludes_reference_design_blob",
             "src/rtl/leak.dsn": "compact_excludes_reference_design_blob",
             "td_release_2026.1_fake.zip": "vendor_toolchain_archive",
+            "oss-cad-suite-linux.tgz": "vendor_toolchain_archive",
             "anlogic_cd/installer/setup.exe": "vendor_installer_payload",
             "config/.env": "secret_environment_file",
             "secrets/id_ed25519": "private_key_file",
@@ -414,6 +415,7 @@ class ReviewCompactProfileAdversarialTests(unittest.TestCase):
                 "src/rtl/leak.brd",
                 "src/rtl/leak.dsn",
                 "td_release_2026.1_fake.zip",
+                "oss-cad-suite-linux.tgz",
                 "anlogic_cd/installer/setup.exe",
                 "config/.env",
                 "secrets/id_ed25519",
@@ -547,6 +549,7 @@ class ReviewCompactProfileAdversarialTests(unittest.TestCase):
                 max_zip_bytes=5_000_000,
                 target_zip_bytes=4_000_000,
                 force=False,
+                profile=REVIEW_COMPACT_PROFILE,
             )
             package_dir = Path(result["output_dir"])
             volume = package_dir / result["volumes"][0]["file"]

+ 16 - 9
tools/package_agent_handoff.py

@@ -347,14 +347,11 @@ def common_file_exclusion_reason(relative: str) -> str | None:
     if suffix == ".exe":
         return "vendor_executable"
     # Vendor tool installers / release archives must never enter analysis packages.
-    if name.startswith(("bw_release_", "td_release_", "oss-cad-suite")) and suffix in {
-        ".zip",
-        ".tgz",
-        ".tar",
-        ".gz",
-        ".7z",
-        ".rar",
-    }:
+    # Covers root OSS CAD suite .tgz, Anlogic TD/BW release zips, and similar.
+    if name.startswith(("bw_release_", "td_release_", "oss-cad-suite")) and (
+        suffix in {".zip", ".tgz", ".tar", ".gz", ".7z", ".rar"}
+        or name.endswith((".tar.gz", ".tar.bz2", ".tbz2", ".tar.xz", ".txz"))
+    ):
         return "vendor_toolchain_archive"
     if "license" in name and suffix in {".zip", ".tgz", ".7z", ".rar"}:
         return "license_archive"
@@ -534,7 +531,6 @@ def delivery_policy_for_profile(profile: str) -> str:
 
 def review_exclusion_reason(relative: str, *, is_dir: bool, profile: str) -> str | None:
     """Extra exclusions for review-* / archive-local unified packages."""
-    del profile
     lower = relative.casefold()
     name = lower.rsplit("/", 1)[-1]
     if name.startswith(".run_id"):
@@ -554,6 +550,17 @@ def review_exclusion_reason(relative: str, *, is_dir: bool, profile: str) -> str
             return "credential_or_license_file"
         if "license" in name and suffix in {".zip", ".tgz", ".7z", ".rar", ".txt", ".pdf"}:
             return "license_material"
+        # review-compact / review-debug: never ship vendor toolchain installers.
+        # archive-local leaves this to shared common_file_exclusion_reason (may still
+        # exclude; do not broaden compact policy by skipping here).
+        if profile in {"review-compact", "review-debug"}:
+            common_reason = common_file_exclusion_reason(relative)
+            if common_reason in {
+                "vendor_toolchain_archive",
+                "vendor_executable",
+                "license_archive",
+            }:
+                return common_reason
     return None