|
|
@@ -32,7 +32,23 @@ import package_agent_handoff as handoff # noqa: E402
|
|
|
PackagingError = handoff.PackagingError
|
|
|
CONFIG_SCHEMA = "cpld-agent-analysis-sources-v1"
|
|
|
DEFAULT_CONFIG = ROOT / "config" / "agent_analysis_handoff_sources.json"
|
|
|
-DEFAULT_OUTPUT_DIR = Path.home() / "Downloads" / "CPLD-agent-analysis"
|
|
|
+DEFAULT_OUTPUT_DIR = Path(
|
|
|
+ os.environ.get(
|
|
|
+ "PRODU2_HANDOFF_DIR",
|
|
|
+ str(Path(os.environ.get("TMPDIR", "/tmp")) / "prod2u-handoff"),
|
|
|
+ )
|
|
|
+)
|
|
|
+CONTENT_DEDUP_MIN_BYTES = 4096
|
|
|
+DERIVED_BOARD_VIEWER_ASSETS = frozenset(
|
|
|
+ {
|
|
|
+ "board-copper.svg",
|
|
|
+ "board-silkscreen.svg",
|
|
|
+ "board-mask-edge.svg",
|
|
|
+ "board-data.json",
|
|
|
+ "build-info.json",
|
|
|
+ "import-report.json",
|
|
|
+ }
|
|
|
+)
|
|
|
CATEGORY_ORDER = {
|
|
|
"core": 0,
|
|
|
"hardware": 1,
|
|
|
@@ -272,10 +288,12 @@ def _source_snapshot(
|
|
|
*,
|
|
|
source_id: str,
|
|
|
extra_exclusions: tuple[dict[str, str], ...],
|
|
|
+ profile: str = "full",
|
|
|
) -> SourceSnapshot:
|
|
|
candidates, excluded, _ = scan_analysis_root(
|
|
|
root,
|
|
|
extra_exclusions=extra_exclusions,
|
|
|
+ profile=profile,
|
|
|
)
|
|
|
return SourceSnapshot(
|
|
|
source_id=source_id,
|
|
|
@@ -418,6 +436,7 @@ def analysis_exclusion_reason(
|
|
|
is_dir: bool,
|
|
|
context: handoff.ScanContext,
|
|
|
extra_exclusions: tuple[dict[str, str], ...] = (),
|
|
|
+ profile: str = "full",
|
|
|
) -> str | None:
|
|
|
del context
|
|
|
lower = relative.casefold()
|
|
|
@@ -427,6 +446,13 @@ def analysis_exclusion_reason(
|
|
|
secret_reason = handoff.secret_path_reason(relative, is_dir=is_dir)
|
|
|
if secret_reason:
|
|
|
return secret_reason
|
|
|
+ if profile == "code-only":
|
|
|
+ for prefix, reason in handoff.CODE_ONLY_ROOT_EXCLUSIONS.items():
|
|
|
+ if handoff.is_under(lower, prefix):
|
|
|
+ return reason
|
|
|
+ if not is_dir and handoff.is_under(lower, "tools/board-viewer/generated"):
|
|
|
+ if name in handoff.CODE_ONLY_GENERATED_VISUAL_ASSETS:
|
|
|
+ return "generated_board_viewer_visual_asset"
|
|
|
for item in extra_exclusions:
|
|
|
prefix = str(item.get("path", "")).casefold().strip("/")
|
|
|
if prefix and handoff.is_under(lower, prefix):
|
|
|
@@ -445,8 +471,10 @@ def analysis_exclusion_reason(
|
|
|
"reference/historical": "reference_historical_material",
|
|
|
"reference/original/legacy_rtl": "reference_legacy_rtl",
|
|
|
"receipts/local": "local_runtime_receipt",
|
|
|
- "tools/board-viewer/generated": "generated_board_viewer_output",
|
|
|
+ # Packaged once via external source board-viewer-generated (derived evidence).
|
|
|
+ "tools/board-viewer/generated": "board_viewer_generated_packaged_via_external_source",
|
|
|
"anlogic_cd": "vendor_installer_payload",
|
|
|
+ "node_modules": "node_modules_runtime",
|
|
|
}
|
|
|
for prefix, reason in explicit_roots.items():
|
|
|
if handoff.is_under(lower, prefix):
|
|
|
@@ -499,12 +527,16 @@ def analysis_exclusion_reason(
|
|
|
"htmlcov": "coverage_report",
|
|
|
"build": "build_output",
|
|
|
"runs": "run_state_directory",
|
|
|
+ "node_modules": "node_modules_runtime",
|
|
|
+ ".playwright-browsers": "browser_runtime_cache",
|
|
|
}
|
|
|
for component in parts:
|
|
|
if component in cache_components:
|
|
|
return cache_components[component]
|
|
|
if component == "dist":
|
|
|
return "generated_delivery_output"
|
|
|
+ if component.endswith(".egg-info"):
|
|
|
+ return "python_package_metadata"
|
|
|
|
|
|
if not is_dir:
|
|
|
suffix = Path(name).suffix.casefold()
|
|
|
@@ -539,6 +571,7 @@ def scan_analysis_root(
|
|
|
root: Path,
|
|
|
*,
|
|
|
extra_exclusions: tuple[dict[str, str], ...] = (),
|
|
|
+ profile: str = "full",
|
|
|
) -> tuple[list[handoff.Candidate], list[dict[str, str]], handoff.ScanContext]:
|
|
|
def resolve(relative: str, *, is_dir: bool, context: handoff.ScanContext) -> str | None:
|
|
|
return analysis_exclusion_reason(
|
|
|
@@ -546,9 +579,10 @@ def scan_analysis_root(
|
|
|
is_dir=is_dir,
|
|
|
context=context,
|
|
|
extra_exclusions=extra_exclusions,
|
|
|
+ profile=profile,
|
|
|
)
|
|
|
|
|
|
- return handoff.scan_tree(root, exclusion_resolver=resolve)
|
|
|
+ return handoff.scan_tree(root, exclusion_resolver=resolve, profile=profile)
|
|
|
|
|
|
|
|
|
def resolve_external_sources(
|
|
|
@@ -650,8 +684,13 @@ def _collect_directory_items(
|
|
|
category: str,
|
|
|
prefix: str,
|
|
|
extra_exclusions: tuple[dict[str, str], ...],
|
|
|
+ profile: str = "full",
|
|
|
) -> tuple[list[PackageItem], list[dict[str, str]]]:
|
|
|
- candidates, excluded, _ = scan_analysis_root(root, extra_exclusions=extra_exclusions)
|
|
|
+ candidates, excluded, _ = scan_analysis_root(
|
|
|
+ root,
|
|
|
+ extra_exclusions=extra_exclusions,
|
|
|
+ profile=profile,
|
|
|
+ )
|
|
|
items = [
|
|
|
PackageItem(
|
|
|
candidate=_rebase_candidate(candidate, prefix),
|
|
|
@@ -748,6 +787,7 @@ def collect_analysis_inputs(
|
|
|
config: HandoffConfig,
|
|
|
temp_root: Path,
|
|
|
include_git_bundle: bool = True,
|
|
|
+ profile: str = "full",
|
|
|
) -> AnalysisCollection:
|
|
|
root = repo_root.resolve(strict=True)
|
|
|
temp_root.mkdir(parents=True, exist_ok=True)
|
|
|
@@ -764,6 +804,7 @@ def collect_analysis_inputs(
|
|
|
category="core",
|
|
|
prefix="workspace-current",
|
|
|
extra_exclusions=config.extra_exclusions,
|
|
|
+ profile=profile,
|
|
|
)
|
|
|
items.extend(root_items)
|
|
|
excluded.extend(root_excluded)
|
|
|
@@ -772,6 +813,7 @@ def collect_analysis_inputs(
|
|
|
root,
|
|
|
source_id="workspace-current",
|
|
|
extra_exclusions=config.extra_exclusions,
|
|
|
+ profile=profile,
|
|
|
)
|
|
|
)
|
|
|
sources.append(
|
|
|
@@ -793,6 +835,10 @@ def collect_analysis_inputs(
|
|
|
git_metadata.append(bundle_metadata)
|
|
|
|
|
|
resolved_sources, source_warnings = resolve_external_sources(config.external_sources)
|
|
|
+ if profile == "code-only":
|
|
|
+ resolved_sources = [
|
|
|
+ source for source in resolved_sources if source.id != "board-viewer-generated"
|
|
|
+ ]
|
|
|
warnings.extend(source_warnings)
|
|
|
for source in resolved_sources:
|
|
|
prefix = f"external/{source.id}"
|
|
|
@@ -814,6 +860,7 @@ def collect_analysis_inputs(
|
|
|
category=source.category,
|
|
|
prefix=prefix,
|
|
|
extra_exclusions=config.extra_exclusions,
|
|
|
+ profile=profile,
|
|
|
)
|
|
|
items.extend(source_items)
|
|
|
excluded.extend(source_excluded)
|
|
|
@@ -822,6 +869,7 @@ def collect_analysis_inputs(
|
|
|
source.path,
|
|
|
source_id=source.id,
|
|
|
extra_exclusions=config.extra_exclusions,
|
|
|
+ profile=profile,
|
|
|
)
|
|
|
)
|
|
|
sources.append(
|
|
|
@@ -1228,6 +1276,177 @@ def _item_sort_key(item: PackageItem) -> tuple[int, str, str]:
|
|
|
)
|
|
|
|
|
|
|
|
|
+def _path_basename(relative: str) -> str:
|
|
|
+ return relative.casefold().rsplit("/", 1)[-1]
|
|
|
+
|
|
|
+
|
|
|
+def _is_board_viewer_generated_path(relative: str) -> bool:
|
|
|
+ lower = relative.casefold()
|
|
|
+ return (
|
|
|
+ "board-viewer-generated" in lower
|
|
|
+ or "/tools/board-viewer/generated/" in f"/{lower}/"
|
|
|
+ or lower.startswith("tools/board-viewer/generated/")
|
|
|
+ )
|
|
|
+
|
|
|
+
|
|
|
+def _is_reference_original_path(relative: str) -> bool:
|
|
|
+ lower = f"/{relative.casefold()}/"
|
|
|
+ return "/reference/original/" in lower or lower.startswith("/reference/original/")
|
|
|
+
|
|
|
+
|
|
|
+def _dedup_canonical_path(paths: list[str]) -> str:
|
|
|
+ def rank(path: str) -> tuple[int, int, str]:
|
|
|
+ name = _path_basename(path)
|
|
|
+ in_reference = _is_reference_original_path(path)
|
|
|
+ in_generated = _is_board_viewer_generated_path(path)
|
|
|
+ if name in BOARD_VIEWER_GENERATED_ASSETS or name in DERIVED_BOARD_VIEWER_ASSETS:
|
|
|
+ return (0 if in_generated else 1, 0 if in_reference else 1, path.casefold())
|
|
|
+ if name.endswith((".brd", ".pdf", ".dsn", ".sch")):
|
|
|
+ return (0 if in_reference else 1, 0 if in_generated else 1, path.casefold())
|
|
|
+ return (0 if in_reference else 1, 0 if in_generated else 1, path.casefold())
|
|
|
+
|
|
|
+ return sorted(paths, key=rank)[0]
|
|
|
+
|
|
|
+
|
|
|
+def _should_content_dedup(size: int, relative: str) -> bool:
|
|
|
+ name = _path_basename(relative)
|
|
|
+ if name in DERIVED_BOARD_VIEWER_ASSETS or name.endswith((".brd", ".pdf")):
|
|
|
+ return True
|
|
|
+ return size >= CONTENT_DEDUP_MIN_BYTES
|
|
|
+
|
|
|
+
|
|
|
+def apply_content_dedup(
|
|
|
+ items: tuple[PackageItem, ...],
|
|
|
+ inventory: list[dict[str, object]],
|
|
|
+) -> tuple[tuple[PackageItem, ...], list[dict[str, object]], list[dict[str, str]]]:
|
|
|
+ """Keep one physical copy per identical content hash; record logical aliases."""
|
|
|
+ by_path = {str(row["path"]): row for row in inventory}
|
|
|
+ groups: dict[str, list[PackageItem]] = {}
|
|
|
+ for item in items:
|
|
|
+ row = by_path[item.candidate.relative]
|
|
|
+ sha = str(row["sha256"])
|
|
|
+ size = int(row["size"])
|
|
|
+ if not _should_content_dedup(size, item.candidate.relative):
|
|
|
+ continue
|
|
|
+ groups.setdefault(sha, []).append(item)
|
|
|
+
|
|
|
+ drop_paths: set[str] = set()
|
|
|
+ dedup_records: list[dict[str, object]] = []
|
|
|
+ excluded: list[dict[str, str]] = []
|
|
|
+ for sha, group in sorted(groups.items(), key=lambda pair: pair[0]):
|
|
|
+ if len(group) < 2:
|
|
|
+ continue
|
|
|
+ paths = [item.candidate.relative for item in group]
|
|
|
+ canonical = _dedup_canonical_path(paths)
|
|
|
+ aliases = sorted(path for path in paths if path != canonical)
|
|
|
+ if not aliases:
|
|
|
+ continue
|
|
|
+ size = int(by_path[canonical]["size"])
|
|
|
+ dedup_records.append(
|
|
|
+ {
|
|
|
+ "sha256": sha,
|
|
|
+ "size": size,
|
|
|
+ "physical_path": canonical,
|
|
|
+ "logical_paths": aliases,
|
|
|
+ "reason": "identical_content_single_physical_copy",
|
|
|
+ }
|
|
|
+ )
|
|
|
+ for alias in aliases:
|
|
|
+ drop_paths.add(alias)
|
|
|
+ excluded.append(
|
|
|
+ {
|
|
|
+ "path": alias,
|
|
|
+ "rule": "duplicate_content_logical_alias",
|
|
|
+ }
|
|
|
+ )
|
|
|
+
|
|
|
+ physical_items = tuple(
|
|
|
+ item for item in items if item.candidate.relative not in drop_paths
|
|
|
+ )
|
|
|
+ dedup_records.sort(key=lambda row: str(row["physical_path"]).casefold())
|
|
|
+ excluded.sort(key=lambda row: handoff.windows_collision_key(row["path"]))
|
|
|
+ return physical_items, dedup_records, excluded
|
|
|
+
|
|
|
+
|
|
|
+def classify_derived_evidence(items: tuple[PackageItem, ...]) -> list[dict[str, object]]:
|
|
|
+ derived: list[dict[str, object]] = []
|
|
|
+ for item in items:
|
|
|
+ name = _path_basename(item.candidate.relative)
|
|
|
+ if name not in DERIVED_BOARD_VIEWER_ASSETS:
|
|
|
+ continue
|
|
|
+ if not _is_board_viewer_generated_path(item.candidate.relative):
|
|
|
+ continue
|
|
|
+ role = "derived_from_brd_visual" if name in BOARD_VIEWER_GENERATED_ASSETS else "derived_from_brd_parsed"
|
|
|
+ derived.append(
|
|
|
+ {
|
|
|
+ "path": item.candidate.relative,
|
|
|
+ "asset": name,
|
|
|
+ "role": role,
|
|
|
+ "authority": "analysis_evidence_not_source_closure",
|
|
|
+ "note": "Derived from the original Allegro BRD for remote analysis; not RTL/TD source closure.",
|
|
|
+ }
|
|
|
+ )
|
|
|
+ derived.sort(key=lambda row: str(row["path"]).casefold())
|
|
|
+ return derived
|
|
|
+
|
|
|
+
|
|
|
+def replay_analysis_package(package_dir: Path, *, extract_root: Path) -> dict[str, object]:
|
|
|
+ """Extract a published package and verify SHA256SUMS plus inventory hashes."""
|
|
|
+ package_dir = package_dir.expanduser().resolve(strict=True)
|
|
|
+ extract_root = extract_root.expanduser().resolve(strict=False)
|
|
|
+ if extract_root.exists():
|
|
|
+ raise PackagingError(f"replay extract root already exists: {extract_root}")
|
|
|
+ index_path = package_dir / "HANDOFF-INDEX.json"
|
|
|
+ sums_path = package_dir / "SHA256SUMS.txt"
|
|
|
+ if not index_path.is_file() or not sums_path.is_file():
|
|
|
+ raise PackagingError("package directory is missing HANDOFF-INDEX.json or SHA256SUMS.txt")
|
|
|
+ index = json.loads(index_path.read_text(encoding="utf-8"))
|
|
|
+ extract_root.mkdir(parents=True, exist_ok=False)
|
|
|
+ verified_volumes: list[dict[str, object]] = []
|
|
|
+ for line in sums_path.read_text(encoding="ascii").splitlines():
|
|
|
+ line = line.strip()
|
|
|
+ if not line:
|
|
|
+ continue
|
|
|
+ digest, _, name = line.partition(" ")
|
|
|
+ if not digest or not name:
|
|
|
+ raise PackagingError(f"invalid SHA256SUMS line: {line}")
|
|
|
+ volume_path = package_dir / name
|
|
|
+ actual = handoff.sha256_file(volume_path)
|
|
|
+ if actual != digest:
|
|
|
+ raise PackagingError(f"SHA256SUMS mismatch for {name}")
|
|
|
+ with zipfile.ZipFile(volume_path, "r", allowZip64=True) as archive:
|
|
|
+ archive.extractall(extract_root)
|
|
|
+ verified_volumes.append({"file": name, "sha256": actual})
|
|
|
+ checked_files = 0
|
|
|
+ for item in index.get("files", []):
|
|
|
+ relative = str(item["path"])
|
|
|
+ target = extract_root / "CPLD" / Path(*relative.split("/"))
|
|
|
+ if not target.is_file():
|
|
|
+ raise PackagingError(f"replay missing extracted file: {relative}")
|
|
|
+ digest = handoff.sha256_file(target)
|
|
|
+ if digest != item["sha256"] or target.stat().st_size != int(item["size"]):
|
|
|
+ raise PackagingError(f"replay hash mismatch for {relative}")
|
|
|
+ checked_files += 1
|
|
|
+ for record in index.get("content_dedup", []):
|
|
|
+ physical = extract_root / "CPLD" / Path(*str(record["physical_path"]).split("/"))
|
|
|
+ if not physical.is_file():
|
|
|
+ raise PackagingError(f"replay missing dedup physical file: {record['physical_path']}")
|
|
|
+ for alias in record.get("logical_paths", []):
|
|
|
+ alias_path = extract_root / "CPLD" / Path(*str(alias).split("/"))
|
|
|
+ if alias_path.exists():
|
|
|
+ raise PackagingError(f"replay found duplicated physical alias path: {alias}")
|
|
|
+ return {
|
|
|
+ "status": "pass",
|
|
|
+ "mode": "package_replay",
|
|
|
+ "package_dir": str(package_dir),
|
|
|
+ "extract_root": str(extract_root),
|
|
|
+ "volumes": verified_volumes,
|
|
|
+ "checked_files": checked_files,
|
|
|
+ "content_dedup_groups": len(index.get("content_dedup", [])),
|
|
|
+ "derived_evidence_count": len(index.get("derived_evidence", [])),
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
def _audit_one_item(item: PackageItem) -> dict[str, object]:
|
|
|
if item.scan_archive:
|
|
|
file_inventory = handoff.stream_candidate(item.candidate)
|
|
|
@@ -1377,7 +1596,11 @@ def _write_volume(
|
|
|
written_inventory: list[dict[str, object]] = []
|
|
|
try:
|
|
|
with zipfile.ZipFile(
|
|
|
- path, "w", compression=zipfile.ZIP_DEFLATED, allowZip64=True
|
|
|
+ path,
|
|
|
+ "w",
|
|
|
+ compression=zipfile.ZIP_DEFLATED,
|
|
|
+ compresslevel=9,
|
|
|
+ allowZip64=True,
|
|
|
) as archive:
|
|
|
for item in sorted(items, key=_item_sort_key):
|
|
|
expected = inventory_by_path[item.candidate.relative]
|
|
|
@@ -1611,12 +1834,13 @@ def _assert_items_unchanged(
|
|
|
raise PackagingError(f"source changed during analysis packaging: {item.candidate.relative}")
|
|
|
|
|
|
|
|
|
-def _assert_source_trees_unchanged(collection: AnalysisCollection) -> None:
|
|
|
+def _assert_source_trees_unchanged(collection: AnalysisCollection, *, profile: str = "full") -> None:
|
|
|
for snapshot in collection.source_snapshots:
|
|
|
current = _source_snapshot(
|
|
|
snapshot.root,
|
|
|
source_id=snapshot.source_id,
|
|
|
extra_exclusions=snapshot.extra_exclusions,
|
|
|
+ profile=profile,
|
|
|
)
|
|
|
if (
|
|
|
current.candidates != snapshot.candidates
|
|
|
@@ -1630,7 +1854,9 @@ def _start_here_text(package_name: str, volume_count: int) -> str:
|
|
|
f"# {package_name} 分析交付包\n\n"
|
|
|
f"本目录包含 {volume_count} 个互相独立的普通 ZIP。请先核对 `SHA256SUMS.txt`,"
|
|
|
"再把所有 ZIP 解压到同一个目录。\n\n"
|
|
|
- "`HANDOFF-INDEX.json` 记录每个原始文件的来源、目标卷、大小和 SHA-256。\n"
|
|
|
+ "`HANDOFF-INDEX.json` 记录每个原始文件的来源、目标卷、大小和 SHA-256,"
|
|
|
+ "以及 `excluded`(排除原因)、`derived_evidence`(由原始 BRD 派生的 board-viewer JSON/SVG,"
|
|
|
+ "不是 RTL/TD source closure)和 `content_dedup`(相同大文件只保留一份物理副本时的逻辑归属)。\n"
|
|
|
)
|
|
|
|
|
|
|
|
|
@@ -1679,6 +1905,7 @@ def create_analysis_package(
|
|
|
max_zip_bytes: int,
|
|
|
target_zip_bytes: int,
|
|
|
force: bool,
|
|
|
+ profile: str = "full",
|
|
|
) -> dict[str, object]:
|
|
|
_validate_package_name(package_name)
|
|
|
if max_zip_bytes <= 0 or not 0 < target_zip_bytes < max_zip_bytes:
|
|
|
@@ -1694,9 +1921,21 @@ def create_analysis_package(
|
|
|
run_id = uuid.uuid4().hex
|
|
|
staging = Path(tempfile.mkdtemp(prefix=f".{package_name}.{run_id}.", dir=output_root))
|
|
|
try:
|
|
|
- inventory = _audit_package_items(collection.items)
|
|
|
+ full_inventory = _audit_package_items(collection.items)
|
|
|
+ physical_items, content_dedup, dedup_excluded = apply_content_dedup(
|
|
|
+ collection.items,
|
|
|
+ full_inventory,
|
|
|
+ )
|
|
|
+ inventory = [
|
|
|
+ row
|
|
|
+ for row in full_inventory
|
|
|
+ if str(row["path"]) in {item.candidate.relative for item in physical_items}
|
|
|
+ ]
|
|
|
inventory_by_path = {str(item["path"]): item for item in inventory}
|
|
|
- package_items = collection.items
|
|
|
+ package_excluded = list(collection.excluded) + dedup_excluded
|
|
|
+ package_excluded.sort(key=lambda item: handoff.windows_collision_key(item["path"]))
|
|
|
+ derived_evidence = classify_derived_evidence(physical_items)
|
|
|
+ package_items = physical_items
|
|
|
package_inventory = inventory
|
|
|
package_inventory_by_path = inventory_by_path
|
|
|
large_files: list[dict[str, object]] = []
|
|
|
@@ -1708,19 +1947,19 @@ def create_analysis_package(
|
|
|
package_name=package_name,
|
|
|
number=1,
|
|
|
count=1,
|
|
|
- items=list(sorted(collection.items, key=_item_sort_key)),
|
|
|
+ items=list(sorted(physical_items, key=_item_sort_key)),
|
|
|
inventory_by_path=inventory_by_path,
|
|
|
)
|
|
|
if single_path.stat().st_size < max_zip_bytes:
|
|
|
volume_infos = [single_info]
|
|
|
- groups = [list(sorted(collection.items, key=_item_sort_key))]
|
|
|
+ groups = [list(sorted(physical_items, key=_item_sort_key))]
|
|
|
else:
|
|
|
single_path.unlink()
|
|
|
package_items, large_files, chunk_root = _prepare_large_file_chunks(
|
|
|
staging,
|
|
|
run_id=run_id,
|
|
|
package_name=package_name,
|
|
|
- items=collection.items,
|
|
|
+ items=physical_items,
|
|
|
inventory_by_path=inventory_by_path,
|
|
|
target_zip_bytes=target_zip_bytes,
|
|
|
max_zip_bytes=max_zip_bytes,
|
|
|
@@ -1780,12 +2019,16 @@ def create_analysis_package(
|
|
|
"created_at_utc": _utc_now(),
|
|
|
"package_name": package_name,
|
|
|
"status": collection.status,
|
|
|
+ "profile": profile,
|
|
|
+ "delivery_policy": "code-only" if profile == "code-only" else "inclusion-first",
|
|
|
"max_zip_bytes": max_zip_bytes,
|
|
|
"target_zip_bytes": target_zip_bytes,
|
|
|
"sources": list(collection.sources),
|
|
|
"git": list(collection.git),
|
|
|
"warnings": list(collection.warnings),
|
|
|
- "excluded": list(collection.excluded),
|
|
|
+ "excluded": package_excluded,
|
|
|
+ "content_dedup": content_dedup,
|
|
|
+ "derived_evidence": derived_evidence,
|
|
|
"volumes": volume_infos,
|
|
|
"files": indexed_files,
|
|
|
"large_files": large_files,
|
|
|
@@ -1815,8 +2058,9 @@ def create_analysis_package(
|
|
|
raise PackagingError(f"ZIP volume exceeds strict size limit: {volume_path.name}")
|
|
|
if handoff.sha256_file(volume_path) != info["sha256"]:
|
|
|
raise PackagingError(f"ZIP volume hash changed after verification: {volume_path.name}")
|
|
|
- _assert_items_unchanged(collection.items, inventory_by_path)
|
|
|
- _assert_source_trees_unchanged(collection)
|
|
|
+ full_inventory_by_path = {str(item["path"]): item for item in full_inventory}
|
|
|
+ _assert_items_unchanged(collection.items, full_inventory_by_path)
|
|
|
+ _assert_source_trees_unchanged(collection, profile=profile)
|
|
|
if chunk_root is not None:
|
|
|
shutil.rmtree(chunk_root)
|
|
|
_publish_directory_atomically(staging, final_dir, force=force)
|
|
|
@@ -1827,12 +2071,16 @@ def create_analysis_package(
|
|
|
return {
|
|
|
"status": collection.status,
|
|
|
"mode": "package",
|
|
|
+ "profile": profile,
|
|
|
+ "delivery_policy": "code-only" if profile == "code-only" else "inclusion-first",
|
|
|
"run_id": run_id,
|
|
|
"output_dir": str(final_dir),
|
|
|
"volumes": volume_infos,
|
|
|
"included_file_count": len(inventory),
|
|
|
"included_bytes": sum(int(item["size"]) for item in inventory),
|
|
|
- "excluded_entry_count": len(collection.excluded),
|
|
|
+ "excluded_entry_count": len(package_excluded),
|
|
|
+ "content_dedup_groups": len(content_dedup),
|
|
|
+ "derived_evidence_count": len(derived_evidence),
|
|
|
"warning_count": len(collection.warnings),
|
|
|
}
|
|
|
|
|
|
@@ -1922,6 +2170,7 @@ def explain_analysis_path(
|
|
|
*,
|
|
|
repo_root: Path,
|
|
|
config: HandoffConfig,
|
|
|
+ profile: str = "full",
|
|
|
) -> dict[str, object]:
|
|
|
root = repo_root.resolve(strict=True)
|
|
|
requested = path if path.is_absolute() else root / path
|
|
|
@@ -1957,6 +2206,7 @@ def explain_analysis_path(
|
|
|
is_dir=is_dir,
|
|
|
context=context,
|
|
|
extra_exclusions=config.extra_exclusions,
|
|
|
+ profile=profile,
|
|
|
)
|
|
|
archive_relative = (
|
|
|
f"workspace-current/{relative}"
|
|
|
@@ -2025,6 +2275,26 @@ def build_parser() -> argparse.ArgumentParser:
|
|
|
parser.add_argument("--package-name", help="portable package directory and ZIP base name")
|
|
|
parser.add_argument("--force-overwrite", action="store_true", help="atomically replace an existing package directory")
|
|
|
parser.add_argument("--no-git-bundle", action="store_true", help="omit the git history bundle from the package")
|
|
|
+ parser.add_argument(
|
|
|
+ "--profile",
|
|
|
+ choices=sorted(handoff.HANDOFF_PROFILES),
|
|
|
+ default="full",
|
|
|
+ help=(
|
|
|
+ "inclusion-first full profile packages source+reference+derived board-viewer evidence "
|
|
|
+ "(core/reference split); code-only excludes reference/ and heavy SVG assets"
|
|
|
+ ),
|
|
|
+ )
|
|
|
+ parser.add_argument(
|
|
|
+ "--replay-package",
|
|
|
+ type=Path,
|
|
|
+ metavar="DIR",
|
|
|
+ help="verify SHA256SUMS and replay-extract an existing package directory (selftest)",
|
|
|
+ )
|
|
|
+ parser.add_argument(
|
|
|
+ "--replay-extract-dir",
|
|
|
+ type=Path,
|
|
|
+ help="extract target for --replay-package (must not already exist)",
|
|
|
+ )
|
|
|
return parser
|
|
|
|
|
|
|
|
|
@@ -2033,11 +2303,25 @@ def main(argv: list[str] | None = None) -> int:
|
|
|
package_name = args.package_name or datetime.now(timezone.utc).strftime(
|
|
|
"cpld-agent-analysis-%Y%m%dT%H%M%SZ"
|
|
|
)
|
|
|
- source_root = args.source_root.expanduser().resolve(strict=True)
|
|
|
try:
|
|
|
+ if args.replay_package is not None:
|
|
|
+ extract_root = args.replay_extract_dir or Path(
|
|
|
+ tempfile.mkdtemp(prefix="prod2u-package-replay-", dir=os.environ.get("TMPDIR", "/tmp"))
|
|
|
+ )
|
|
|
+ payload = replay_analysis_package(args.replay_package, extract_root=extract_root)
|
|
|
+ print(json.dumps(payload, ensure_ascii=False, indent=2))
|
|
|
+ return 0
|
|
|
+ source_root = args.source_root.expanduser().resolve(strict=True)
|
|
|
+ if args.profile not in handoff.HANDOFF_PROFILES:
|
|
|
+ raise PackagingError(f"unsupported handoff profile: {args.profile}")
|
|
|
config = load_config(args.config, repo_root=source_root)
|
|
|
if args.explain is not None:
|
|
|
- payload = explain_analysis_path(args.explain, repo_root=source_root, config=config)
|
|
|
+ payload = explain_analysis_path(
|
|
|
+ args.explain,
|
|
|
+ repo_root=source_root,
|
|
|
+ config=config,
|
|
|
+ profile=args.profile,
|
|
|
+ )
|
|
|
else:
|
|
|
seven_zip = find_7z()
|
|
|
_validate_package_name(package_name)
|
|
|
@@ -2049,6 +2333,7 @@ def main(argv: list[str] | None = None) -> int:
|
|
|
config=config,
|
|
|
temp_root=temp_root / "inputs",
|
|
|
include_git_bundle=not args.no_git_bundle,
|
|
|
+ profile=args.profile,
|
|
|
)
|
|
|
preparation = prepare_unsupported_archives(
|
|
|
collection.items,
|
|
|
@@ -2059,6 +2344,19 @@ def main(argv: list[str] | None = None) -> int:
|
|
|
prepared_collection = merge_archive_preparation(collection, preparation)
|
|
|
if args.audit_only:
|
|
|
payload = audit_analysis_collection(prepared_collection)
|
|
|
+ payload["profile"] = args.profile
|
|
|
+ elif args.profile == "code-only":
|
|
|
+ if not prepared_collection.items:
|
|
|
+ raise PackagingError("analysis package has no included files")
|
|
|
+ payload = create_analysis_package(
|
|
|
+ collection=prepared_collection,
|
|
|
+ output_root=output_root,
|
|
|
+ package_name=package_name,
|
|
|
+ max_zip_bytes=config.max_zip_bytes,
|
|
|
+ target_zip_bytes=config.target_zip_bytes,
|
|
|
+ force=args.force_overwrite,
|
|
|
+ profile=args.profile,
|
|
|
+ )
|
|
|
else:
|
|
|
core_collection, reference_collection = _split_collection_by_reference(
|
|
|
prepared_collection
|
|
|
@@ -2074,6 +2372,7 @@ def main(argv: list[str] | None = None) -> int:
|
|
|
max_zip_bytes=config.max_zip_bytes,
|
|
|
target_zip_bytes=config.target_zip_bytes,
|
|
|
force=args.force_overwrite,
|
|
|
+ profile=args.profile,
|
|
|
)
|
|
|
if reference_collection.items:
|
|
|
payload["reference"] = _create_reference_package_with_cache(
|