|
@@ -725,6 +725,7 @@ def load_canonical_td_a1_fields(repo_root: Path | None = None) -> dict[str, Any]
|
|
|
_sha256_bytes(full.read_bytes()) if full.is_file() else None
|
|
_sha256_bytes(full.read_bytes()) if full.is_file() else None
|
|
|
),
|
|
),
|
|
|
"td_binding_status": "pass",
|
|
"td_binding_status": "pass",
|
|
|
|
|
+ "td_policy": "reused_exact_source_bound_td",
|
|
|
"production_binding": "37/37/0/0",
|
|
"production_binding": "37/37/0/0",
|
|
|
"lut": lut,
|
|
"lut": lut,
|
|
|
"mslice": mslice,
|
|
"mslice": mslice,
|
|
@@ -733,6 +734,85 @@ def load_canonical_td_a1_fields(repo_root: Path | None = None) -> dict[str, Any]
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+def format_production_binding(
|
|
|
|
|
+ *,
|
|
|
|
|
+ expected: int,
|
|
|
|
|
+ matched: int,
|
|
|
|
|
+ missing: int,
|
|
|
|
|
+ hash_mismatch: int,
|
|
|
|
|
+) -> str:
|
|
|
|
|
+ """Canonical ``expected/matched/missing/mismatch`` production-binding string."""
|
|
|
|
|
+ return f"{int(expected)}/{int(matched)}/{int(missing)}/{int(hash_mismatch)}"
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+def load_td_identity_fields(
|
|
|
|
|
+ receipt_path: Path | str,
|
|
|
|
|
+ *,
|
|
|
|
|
+ repo_root: Path | None = None,
|
|
|
|
|
+) -> dict[str, Any]:
|
|
|
|
|
+ """Load TD identity from the receipt being packaged (historical or fresh).
|
|
|
|
|
+
|
|
|
|
|
+ Unlike ``load_canonical_td_a1_fields``, this does not require bitstream
|
|
|
|
|
+ ``b4b0eda4…``. Fresh TD receipts bind their own commit, run IDs, bitstream
|
|
|
|
|
+ SHA, and parsed LUT/MSLICE/DSP.
|
|
|
|
|
+ """
|
|
|
|
|
+ path = Path(receipt_path)
|
|
|
|
|
+ if not path.is_file():
|
|
|
|
|
+ raise FileNotFoundError(f"TD receipt not found: {path}")
|
|
|
|
|
+ raw = path.read_bytes()
|
|
|
|
|
+ doc = json.loads(raw.decode("utf-8"))
|
|
|
|
|
+ if not isinstance(doc, dict):
|
|
|
|
|
+ raise ValueError(f"TD receipt is not a JSON object: {path}")
|
|
|
|
|
+ run_id = str(doc.get("run_id") or doc.get("td_artifact_run_id") or "").strip()
|
|
|
|
|
+ if not run_id:
|
|
|
|
|
+ raise ValueError(f"TD receipt missing run_id: {path}")
|
|
|
|
|
+ bitstream = str(doc.get("bitstream_sha256") or "").strip()
|
|
|
|
|
+ if not bitstream:
|
|
|
|
|
+ raise ValueError(f"TD receipt missing bitstream_sha256: {path}")
|
|
|
|
|
+ bound = str(doc.get("commit_full") or doc.get("commit") or "").strip()
|
|
|
|
|
+ if not bound:
|
|
|
|
|
+ raise ValueError(f"TD receipt missing commit: {path}")
|
|
|
|
|
+ verification_run_id = str(doc.get("verification_run_id") or "").strip()
|
|
|
|
|
+ parsed = parse_td_resource_fields(doc)
|
|
|
|
|
+ inputs = doc.get("synthesis_input_manifest")
|
|
|
|
|
+ input_map = inputs.get("inputs") if isinstance(inputs, dict) else None
|
|
|
|
|
+ n_inputs = len(input_map) if isinstance(input_map, dict) else None
|
|
|
|
|
+ production_binding = (
|
|
|
|
|
+ format_production_binding(
|
|
|
|
|
+ expected=n_inputs, matched=n_inputs, missing=0, hash_mismatch=0
|
|
|
|
|
+ )
|
|
|
|
|
+ if n_inputs is not None
|
|
|
|
|
+ else None
|
|
|
|
|
+ )
|
|
|
|
|
+ root = Path(repo_root or ROOT)
|
|
|
|
|
+ try:
|
|
|
|
|
+ rel = str(path.resolve().relative_to(root.resolve())).replace("\\", "/")
|
|
|
|
|
+ except ValueError:
|
|
|
|
|
+ rel = str(path)
|
|
|
|
|
+ status = str(doc.get("status") or "").strip()
|
|
|
|
|
+ policy = (
|
|
|
|
|
+ "reused_exact_source_bound_td"
|
|
|
|
|
+ if bitstream == CANONICAL_TD_A1_BITSTREAM
|
|
|
|
|
+ else "fresh_td"
|
|
|
|
|
+ )
|
|
|
|
|
+ return {
|
|
|
|
|
+ "td_bound_commit": bound,
|
|
|
|
|
+ "artifact_source_commit": bound,
|
|
|
|
|
+ "bitstream_sha256": bitstream,
|
|
|
|
|
+ "td_artifact_run_id": run_id,
|
|
|
|
|
+ "td_verification_run_id": verification_run_id or None,
|
|
|
|
|
+ "td_receipt_path": rel,
|
|
|
|
|
+ "td_receipt_sha256": _sha256_bytes(raw),
|
|
|
|
|
+ "td_binding_status": "pass" if status.casefold() == "pass" else (status or "unknown"),
|
|
|
|
|
+ "td_policy": policy,
|
|
|
|
|
+ "production_binding": production_binding,
|
|
|
|
|
+ "lut": parsed["lut"],
|
|
|
|
|
+ "mslice": parsed["mslice"],
|
|
|
|
|
+ "dsp": parsed["dsp"],
|
|
|
|
|
+ "status": doc.get("status"),
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
def build_shared_release_identity(
|
|
def build_shared_release_identity(
|
|
|
*,
|
|
*,
|
|
|
delivery_commit: str,
|
|
delivery_commit: str,
|
|
@@ -746,12 +826,15 @@ def build_shared_release_identity(
|
|
|
hardware_validation: str = "not_run",
|
|
hardware_validation: str = "not_run",
|
|
|
non_final: bool | None = None,
|
|
non_final: bool | None = None,
|
|
|
claim_bound_bitstream: bool = True,
|
|
claim_bound_bitstream: bool = True,
|
|
|
|
|
+ td_fields: dict[str, Any] | None = None,
|
|
|
extra: dict[str, Any] | None = None,
|
|
extra: dict[str, Any] | None = None,
|
|
|
) -> dict[str, Any]:
|
|
) -> dict[str, Any]:
|
|
|
"""Single shared release identity for review + firmware packages.
|
|
"""Single shared release identity for review + firmware packages.
|
|
|
|
|
|
|
|
- When ``claim_bound_bitstream`` is true, TD fields are loaded from the
|
|
|
|
|
- canonical A1 receipt (never null run_id / receipt SHA).
|
|
|
|
|
|
|
+ When ``td_fields`` is provided (live TD receipt), those fields bind
|
|
|
|
|
+ identity and ``release_set_id``. Otherwise, if ``claim_bound_bitstream``
|
|
|
|
|
+ is true, fields load from the canonical A1 receipt (never null run_id /
|
|
|
|
|
+ receipt SHA).
|
|
|
"""
|
|
"""
|
|
|
stage = package_stage.strip()
|
|
stage = package_stage.strip()
|
|
|
if non_final is None:
|
|
if non_final is None:
|
|
@@ -759,7 +842,12 @@ def build_shared_release_identity(
|
|
|
delivery = str(delivery_commit).strip()
|
|
delivery = str(delivery_commit).strip()
|
|
|
if not delivery:
|
|
if not delivery:
|
|
|
raise ValueError("delivery_commit required")
|
|
raise ValueError("delivery_commit required")
|
|
|
- td = load_canonical_td_a1_fields(repo_root) if claim_bound_bitstream else {}
|
|
|
|
|
|
|
+ if td_fields is not None:
|
|
|
|
|
+ td = dict(td_fields)
|
|
|
|
|
+ elif claim_bound_bitstream:
|
|
|
|
|
+ td = load_canonical_td_a1_fields(repo_root)
|
|
|
|
|
+ else:
|
|
|
|
|
+ td = {}
|
|
|
artifact = str(td.get("artifact_source_commit") or CANONICAL_TD_A1_BOUND_COMMIT)
|
|
artifact = str(td.get("artifact_source_commit") or CANONICAL_TD_A1_BOUND_COMMIT)
|
|
|
td_run = str(td.get("td_artifact_run_id") or "")
|
|
td_run = str(td.get("td_artifact_run_id") or "")
|
|
|
bitstream = str(td.get("bitstream_sha256") or "")
|
|
bitstream = str(td.get("bitstream_sha256") or "")
|
|
@@ -796,7 +884,8 @@ def build_shared_release_identity(
|
|
|
"td_artifact_run_id": td_run or None,
|
|
"td_artifact_run_id": td_run or None,
|
|
|
"td_receipt_sha256": td.get("td_receipt_sha256"),
|
|
"td_receipt_sha256": td.get("td_receipt_sha256"),
|
|
|
"td_binding_status": td.get("td_binding_status") or ("pass" if claim_bound_bitstream else None),
|
|
"td_binding_status": td.get("td_binding_status") or ("pass" if claim_bound_bitstream else None),
|
|
|
- "production_binding": td.get("production_binding") if claim_bound_bitstream else None,
|
|
|
|
|
|
|
+ "td_policy": td.get("td_policy"),
|
|
|
|
|
+ "production_binding": td.get("production_binding") if (claim_bound_bitstream or td) else None,
|
|
|
"production_polarity_fingerprint": config_fingerprint,
|
|
"production_polarity_fingerprint": config_fingerprint,
|
|
|
"reference_set_fingerprint": reference_set_fingerprint,
|
|
"reference_set_fingerprint": reference_set_fingerprint,
|
|
|
"hardware_validation": hardware_validation,
|
|
"hardware_validation": hardware_validation,
|