|
@@ -537,6 +537,11 @@ def review_exclusion_reason(relative: str, *, is_dir: bool, profile: str) -> str
|
|
|
return "run_id_marker"
|
|
return "run_id_marker"
|
|
|
if name in {"evidence-batch-summary.txt"}:
|
|
if name in {"evidence-batch-summary.txt"}:
|
|
|
return "stale_run_summary"
|
|
return "stale_run_summary"
|
|
|
|
|
+ # Adversarial payload blobs are generated in temp during tests; never ship them
|
|
|
|
|
+ # long-term inside review-compact / review-debug volumes.
|
|
|
|
|
+ if is_under(lower, "tests/fixtures/package_adversarial/payloads"):
|
|
|
|
|
+ if profile in {"review-compact", "review-debug"}:
|
|
|
|
|
+ return "adversarial_fixture_payload"
|
|
|
for prefix, reason in REVIEW_ORIGINAL_ROOT_EXCLUSIONS.items():
|
|
for prefix, reason in REVIEW_ORIGINAL_ROOT_EXCLUSIONS.items():
|
|
|
if is_under(lower, prefix):
|
|
if is_under(lower, prefix):
|
|
|
return reason
|
|
return reason
|
|
@@ -1296,34 +1301,286 @@ def _git_bytes(git: str, args: list[str], *, cwd: Path) -> bytes | None:
|
|
|
return payload
|
|
return payload
|
|
|
|
|
|
|
|
|
|
|
|
|
-def build_td_source_closure_binding_hook(root: Path) -> dict[str, object]:
|
|
|
|
|
- """Record TD source-closure binding hooks without requiring a live bitstream."""
|
|
|
|
|
|
|
+SHA256_HEX_RE = re.compile(r"^[0-9a-f]{64}$")
|
|
|
|
|
+COMMIT_FULL_RE = re.compile(r"^[0-9a-f]{40}$")
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+def _resolve_commit_full(root: Path, commit: str | None = None) -> str | None:
|
|
|
|
|
+ if commit and COMMIT_FULL_RE.fullmatch(commit.strip().casefold()):
|
|
|
|
|
+ return commit.strip().casefold()
|
|
|
|
|
+ git = shutil.which("git")
|
|
|
|
|
+ if git is None:
|
|
|
|
|
+ return None
|
|
|
|
|
+ code, payload = run_capture([git, "rev-parse", "HEAD"], cwd=root)
|
|
|
|
|
+ if code != 0:
|
|
|
|
|
+ return None
|
|
|
|
|
+ text = payload.decode("ascii", errors="replace").strip().casefold()
|
|
|
|
|
+ return text if COMMIT_FULL_RE.fullmatch(text) else None
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+def _collect_td_report_bindings(
|
|
|
|
|
+ report_paths: Iterable[Path],
|
|
|
|
|
+) -> list[dict[str, object]]:
|
|
|
|
|
+ rows: list[dict[str, object]] = []
|
|
|
|
|
+ for path in report_paths:
|
|
|
|
|
+ resolved = path.expanduser().resolve(strict=False)
|
|
|
|
|
+ if not resolved.is_file():
|
|
|
|
|
+ rows.append(
|
|
|
|
|
+ {
|
|
|
|
|
+ "path": str(path),
|
|
|
|
|
+ "status": "missing",
|
|
|
|
|
+ "sha256": None,
|
|
|
|
|
+ "bytes": None,
|
|
|
|
|
+ }
|
|
|
|
|
+ )
|
|
|
|
|
+ continue
|
|
|
|
|
+ rows.append(
|
|
|
|
|
+ {
|
|
|
|
|
+ "path": str(resolved),
|
|
|
|
|
+ "status": "present",
|
|
|
|
|
+ "sha256": sha256_file(resolved),
|
|
|
|
|
+ "bytes": resolved.stat().st_size,
|
|
|
|
|
+ "name": resolved.name,
|
|
|
|
|
+ }
|
|
|
|
|
+ )
|
|
|
|
|
+ rows.sort(key=lambda row: str(row.get("path", "")).casefold())
|
|
|
|
|
+ return rows
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+def discover_bitstream_candidates(
|
|
|
|
|
+ root: Path,
|
|
|
|
|
+ *,
|
|
|
|
|
+ evidence_root: Path | None = None,
|
|
|
|
|
+) -> list[Path]:
|
|
|
|
|
+ """Locate candidate bitstreams for optional binding (does not require TD rebuild)."""
|
|
|
|
|
+ candidates: list[Path] = []
|
|
|
|
|
+ search_roots = []
|
|
|
|
|
+ if evidence_root is not None:
|
|
|
|
|
+ search_roots.append(evidence_root.expanduser().resolve(strict=False))
|
|
|
|
|
+ search_roots.extend(
|
|
|
|
|
+ [
|
|
|
|
|
+ root / "evidence" / "bitstream",
|
|
|
|
|
+ root / "td" / "build",
|
|
|
|
|
+ ]
|
|
|
|
|
+ )
|
|
|
|
|
+ env_bit = os.environ.get("PRODU2_BITSTREAM_PATH", "").strip()
|
|
|
|
|
+ if env_bit:
|
|
|
|
|
+ candidates.append(Path(env_bit).expanduser())
|
|
|
|
|
+ for base in search_roots:
|
|
|
|
|
+ if not base.is_dir():
|
|
|
|
|
+ continue
|
|
|
|
|
+ candidates.extend(sorted(base.rglob("*.bit")))
|
|
|
|
|
+ named = base / "prod2u_p4_normal_v3.bit"
|
|
|
|
|
+ if named.is_file():
|
|
|
|
|
+ candidates.append(named)
|
|
|
|
|
+ fw = base / "fw.bit"
|
|
|
|
|
+ if fw.is_file():
|
|
|
|
|
+ candidates.append(fw)
|
|
|
|
|
+ # Deduplicate while preserving order.
|
|
|
|
|
+ seen: set[str] = set()
|
|
|
|
|
+ unique: list[Path] = []
|
|
|
|
|
+ for path in candidates:
|
|
|
|
|
+ key = str(path.resolve(strict=False))
|
|
|
|
|
+ if key in seen:
|
|
|
|
|
+ continue
|
|
|
|
|
+ seen.add(key)
|
|
|
|
|
+ if path.is_file():
|
|
|
|
|
+ unique.append(path)
|
|
|
|
|
+ return unique
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+def build_td_source_closure_binding(
|
|
|
|
|
+ root: Path,
|
|
|
|
|
+ *,
|
|
|
|
|
+ bitstream_path: Path | None = None,
|
|
|
|
|
+ td_report_paths: Iterable[Path] | None = None,
|
|
|
|
|
+ evidence_root: Path | None = None,
|
|
|
|
|
+ commit: str | None = None,
|
|
|
|
|
+ require_bitstream: bool = False,
|
|
|
|
|
+) -> dict[str, object]:
|
|
|
|
|
+ """Build TD source-closure binding; bind real bitstream when supplied.
|
|
|
|
|
+
|
|
|
|
|
+ Without a bitstream the status remains ``hook_ready`` (or ``hook_partial``).
|
|
|
|
|
+ When a bitstream (+ optional TD reports) is provided, status becomes ``bound``
|
|
|
|
|
+ with full commit SHA, source-manifest SHA, project SHA, and bitstream SHA-256.
|
|
|
|
|
+ Integrators supply the real tip bitstream later; this path must not stay
|
|
|
|
|
+ forever deferred once artifacts exist.
|
|
|
|
|
+ """
|
|
|
|
|
+ root = root.expanduser().resolve(strict=True)
|
|
|
manifest = root / "src" / "generated" / "td-source-manifest.json"
|
|
manifest = root / "src" / "generated" / "td-source-manifest.json"
|
|
|
project = root / "projects" / "prod2u-door-temp" / "project.json"
|
|
project = root / "projects" / "prod2u-door-temp" / "project.json"
|
|
|
|
|
+ commit_full = _resolve_commit_full(root, commit)
|
|
|
binding: dict[str, object] = {
|
|
binding: dict[str, object] = {
|
|
|
- "schema": "cpld-td-source-closure-binding-hook-v1",
|
|
|
|
|
|
|
+ "schema": "cpld-td-source-closure-binding-v1",
|
|
|
"status": "hook_ready",
|
|
"status": "hook_ready",
|
|
|
"note": (
|
|
"note": (
|
|
|
- "Bindings are recorded for remote review; recompute against an existing "
|
|
|
|
|
- "bitstream receipt when production inputs are unchanged. Full TD rebuild "
|
|
|
|
|
- "is out of scope for review-compact packaging."
|
|
|
|
|
|
|
+ "Binding path accepts a real bitstream + full commit + source-manifest + "
|
|
|
|
|
+ "TD reports. When those artifacts are absent, status stays hook_ready; "
|
|
|
|
|
+ "it must not remain deferred once the integrator supplies them."
|
|
|
),
|
|
),
|
|
|
|
|
+ "commit_full": commit_full,
|
|
|
|
|
+ "commit_short": commit_full[:8] if commit_full else None,
|
|
|
"td_source_manifest_path": "src/generated/td-source-manifest.json",
|
|
"td_source_manifest_path": "src/generated/td-source-manifest.json",
|
|
|
"td_source_manifest_sha256": None,
|
|
"td_source_manifest_sha256": None,
|
|
|
"project_config_path": "projects/prod2u-door-temp/project.json",
|
|
"project_config_path": "projects/prod2u-door-temp/project.json",
|
|
|
"project_config_sha256": None,
|
|
"project_config_sha256": None,
|
|
|
|
|
+ "bitstream": None,
|
|
|
|
|
+ "td_reports": [],
|
|
|
"bitstream_binding": "deferred_to_evidence_receipt",
|
|
"bitstream_binding": "deferred_to_evidence_receipt",
|
|
|
|
|
+ # Legacy alias kept for older consumers still looking for the hook schema.
|
|
|
|
|
+ "legacy_schema_alias": "cpld-td-source-closure-binding-hook-v1",
|
|
|
}
|
|
}
|
|
|
if manifest.is_file():
|
|
if manifest.is_file():
|
|
|
binding["td_source_manifest_sha256"] = sha256_file(manifest)
|
|
binding["td_source_manifest_sha256"] = sha256_file(manifest)
|
|
|
else:
|
|
else:
|
|
|
binding["status"] = "hook_partial"
|
|
binding["status"] = "hook_partial"
|
|
|
- binding["td_source_manifest_sha256"] = None
|
|
|
|
|
if project.is_file():
|
|
if project.is_file():
|
|
|
binding["project_config_sha256"] = sha256_file(project)
|
|
binding["project_config_sha256"] = sha256_file(project)
|
|
|
|
|
+ else:
|
|
|
|
|
+ binding["status"] = "hook_partial"
|
|
|
|
|
+
|
|
|
|
|
+ resolved_bit = bitstream_path
|
|
|
|
|
+ if resolved_bit is None:
|
|
|
|
|
+ discovered = discover_bitstream_candidates(root, evidence_root=evidence_root)
|
|
|
|
|
+ if len(discovered) == 1:
|
|
|
|
|
+ resolved_bit = discovered[0]
|
|
|
|
|
+ elif len(discovered) > 1 and evidence_root is not None:
|
|
|
|
|
+ # Prefer evidence_root hits when multiple exist.
|
|
|
|
|
+ evidence_hits = [
|
|
|
|
|
+ path
|
|
|
|
|
+ for path in discovered
|
|
|
|
|
+ if str(path.resolve(strict=False)).startswith(
|
|
|
|
|
+ str(evidence_root.expanduser().resolve(strict=False))
|
|
|
|
|
+ )
|
|
|
|
|
+ ]
|
|
|
|
|
+ if len(evidence_hits) == 1:
|
|
|
|
|
+ resolved_bit = evidence_hits[0]
|
|
|
|
|
+
|
|
|
|
|
+ report_list = list(td_report_paths or [])
|
|
|
|
|
+ if not report_list and evidence_root is not None:
|
|
|
|
|
+ evidence = evidence_root.expanduser().resolve(strict=False)
|
|
|
|
|
+ for pattern in (
|
|
|
|
|
+ "**/td-primary-receipt.json",
|
|
|
|
|
+ "**/final_td_report.json",
|
|
|
|
|
+ "**/original-final_td_report.json",
|
|
|
|
|
+ "**/TD-PROVENANCE.json",
|
|
|
|
|
+ ):
|
|
|
|
|
+ report_list.extend(sorted(evidence.glob(pattern)))
|
|
|
|
|
+ binding["td_reports"] = _collect_td_report_bindings(report_list)
|
|
|
|
|
+
|
|
|
|
|
+ if resolved_bit is None:
|
|
|
|
|
+ if require_bitstream:
|
|
|
|
|
+ binding["status"] = "bind_failed"
|
|
|
|
|
+ binding["bitstream_binding"] = "missing_bitstream"
|
|
|
|
|
+ binding["note"] = "require_bitstream=true but no bitstream was provided or discovered"
|
|
|
|
|
+ return binding
|
|
|
|
|
+
|
|
|
|
|
+ bit_path = resolved_bit.expanduser().resolve(strict=False)
|
|
|
|
|
+ if not bit_path.is_file():
|
|
|
|
|
+ binding["status"] = "bind_failed"
|
|
|
|
|
+ binding["bitstream_binding"] = "missing_bitstream"
|
|
|
|
|
+ binding["bitstream"] = {"path": str(resolved_bit), "status": "missing"}
|
|
|
|
|
+ return binding
|
|
|
|
|
+
|
|
|
|
|
+ digest = sha256_file(bit_path)
|
|
|
|
|
+ if not SHA256_HEX_RE.fullmatch(digest):
|
|
|
|
|
+ binding["status"] = "bind_failed"
|
|
|
|
|
+ binding["bitstream_binding"] = "invalid_bitstream_sha256"
|
|
|
|
|
+ return binding
|
|
|
|
|
+
|
|
|
|
|
+ binding["bitstream"] = {
|
|
|
|
|
+ "path": str(bit_path),
|
|
|
|
|
+ "name": bit_path.name,
|
|
|
|
|
+ "sha256": digest,
|
|
|
|
|
+ "bytes": bit_path.stat().st_size,
|
|
|
|
|
+ "status": "present",
|
|
|
|
|
+ }
|
|
|
|
|
+ if (
|
|
|
|
|
+ commit_full
|
|
|
|
|
+ and binding.get("td_source_manifest_sha256")
|
|
|
|
|
+ and binding.get("project_config_sha256")
|
|
|
|
|
+ ):
|
|
|
|
|
+ binding["status"] = "bound"
|
|
|
|
|
+ binding["bitstream_binding"] = "bound"
|
|
|
|
|
+ binding["note"] = (
|
|
|
|
|
+ "Bound to real bitstream SHA-256, full commit, project config, "
|
|
|
|
|
+ "td-source-manifest, and any supplied TD reports."
|
|
|
|
|
+ )
|
|
|
|
|
+ else:
|
|
|
|
|
+ binding["status"] = "bind_partial"
|
|
|
|
|
+ binding["bitstream_binding"] = "partial"
|
|
|
|
|
+ binding["note"] = (
|
|
|
|
|
+ "Bitstream hashed but commit/manifest/project identity incomplete; "
|
|
|
|
|
+ "not a final closure binding."
|
|
|
|
|
+ )
|
|
|
return binding
|
|
return binding
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+def build_td_source_closure_binding_hook(
|
|
|
|
|
+ root: Path,
|
|
|
|
|
+ *,
|
|
|
|
|
+ bitstream_path: Path | None = None,
|
|
|
|
|
+ td_report_paths: Iterable[Path] | None = None,
|
|
|
|
|
+ evidence_root: Path | None = None,
|
|
|
|
|
+ commit: str | None = None,
|
|
|
|
|
+ require_bitstream: bool = False,
|
|
|
|
|
+) -> dict[str, object]:
|
|
|
|
|
+ """Compatibility wrapper: bind when artifacts exist, else hook_ready."""
|
|
|
|
|
+ return build_td_source_closure_binding(
|
|
|
|
|
+ root,
|
|
|
|
|
+ bitstream_path=bitstream_path,
|
|
|
|
|
+ td_report_paths=td_report_paths,
|
|
|
|
|
+ evidence_root=evidence_root,
|
|
|
|
|
+ commit=commit,
|
|
|
|
|
+ require_bitstream=require_bitstream,
|
|
|
|
|
+ )
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+def run_post_staging_reference_inventory_hook(
|
|
|
|
|
+ repo_root: Path,
|
|
|
|
|
+ *,
|
|
|
|
|
+ staging_complete: bool,
|
|
|
|
|
+ enabled: bool = True,
|
|
|
|
|
+) -> dict[str, object]:
|
|
|
|
|
+ """Refresh REFERENCE-INVENTORY only after staging completes (packager order).
|
|
|
|
|
+
|
|
|
|
|
+ Lane E owns inventory generator honesty / evidence-grade docs. Lane D only
|
|
|
|
|
+ enforces call order: inventory refresh must not run before staging finishes.
|
|
|
|
|
+ """
|
|
|
|
|
+ repo_root = repo_root.expanduser().resolve(strict=True)
|
|
|
|
|
+ report: dict[str, object] = {
|
|
|
|
|
+ "schema": "cpld-reference-inventory-post-staging-hook-v1",
|
|
|
|
|
+ "staging_complete": staging_complete,
|
|
|
|
|
+ "enabled": enabled,
|
|
|
|
|
+ "status": "not_run",
|
|
|
|
|
+ "command": None,
|
|
|
|
|
+ "note": (
|
|
|
|
|
+ "Packager order: finish reference staging, then refresh inventory, "
|
|
|
|
|
+ "then finalize the reference volume."
|
|
|
|
|
+ ),
|
|
|
|
|
+ }
|
|
|
|
|
+ if not enabled:
|
|
|
|
|
+ report["status"] = "skipped_disabled"
|
|
|
|
|
+ return report
|
|
|
|
|
+ if not staging_complete:
|
|
|
|
|
+ report["status"] = "blocked_staging_incomplete"
|
|
|
|
|
+ report["note"] = "Refusing inventory refresh before staging_complete=true"
|
|
|
|
|
+ return report
|
|
|
|
|
+
|
|
|
|
|
+ refresh_py = repo_root / "tools" / "board-viewer" / "refresh_reference_inventory.py"
|
|
|
|
|
+ if not refresh_py.is_file():
|
|
|
|
|
+ report["status"] = "blocked_missing_refresher"
|
|
|
|
|
+ return report
|
|
|
|
|
+
|
|
|
|
|
+ command = [sys.executable, "-B", str(refresh_py), "--root", str(repo_root)]
|
|
|
|
|
+ report["command"] = command
|
|
|
|
|
+ code, payload = run_capture(command, cwd=repo_root, timeout=300)
|
|
|
|
|
+ report["returncode"] = code
|
|
|
|
|
+ report["output_tail"] = payload.decode("utf-8", errors="replace")[-2000:]
|
|
|
|
|
+ report["status"] = "pass" if code == 0 else "fail"
|
|
|
|
|
+ return report
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
_SANITIZED_SNAPSHOT_SKIP_PREFIXES = (
|
|
_SANITIZED_SNAPSHOT_SKIP_PREFIXES = (
|
|
|
"reference/original/",
|
|
"reference/original/",
|
|
|
"node_modules/",
|
|
"node_modules/",
|
|
@@ -1731,7 +1988,8 @@ def package_purpose_text(profile: str, *, package_name: str) -> str:
|
|
|
"Default remote-agent upload package.",
|
|
"Default remote-agent upload package.",
|
|
|
"Layout: source/ (active code+tests) + evidence/ (canonical final receipts, derived board-viewer) + meta/.",
|
|
"Layout: source/ (active code+tests) + evidence/ (canonical final receipts, derived board-viewer) + meta/.",
|
|
|
"Does NOT include a full Git bundle, PDF/BRD/DSN originals, vendor installer zips, or license material.",
|
|
"Does NOT include a full Git bundle, PDF/BRD/DSN originals, vendor installer zips, or license material.",
|
|
|
- "Git provenance is commit/status/log-20/tree manifest/per-file SHA-256 plus TD source-closure binding hooks.",
|
|
|
|
|
|
|
+ "Git provenance is commit/status/log-20/tree manifest/per-file SHA-256 plus TD source-closure binding.",
|
|
|
|
|
+ "meta/td-source-closure-binding.json binds real bitstream SHA-256 + full commit + source-manifest + TD reports when supplied; otherwise hook_ready until the integrator provides the tip bit.",
|
|
|
"Evidence is physically deduplicated; process lane receipts / matrix reruns require review-debug or --include-process-evidence.",
|
|
"Evidence is physically deduplicated; process lane receipts / matrix reruns require review-debug or --include-process-evidence.",
|
|
|
"Result-sensitive logs: PASS/not_run keep summaries; FAIL/BLOCKED/TIMEOUT/CRASH keep full evidence.",
|
|
"Result-sensitive logs: PASS/not_run keep summaries; FAIL/BLOCKED/TIMEOUT/CRASH keep full evidence.",
|
|
|
"Hardware validation remains not_run unless a future task authorizes it.",
|
|
"Hardware validation remains not_run unless a future task authorizes it.",
|