Prechádzať zdrojové kódy

fix(packaging): bind review-compact ARTIFACT from TD tip

Prevent delivery HEAD from collapsing into ARTIFACT-SOURCE when building
dual-edge source-closure relations for review-compact provenance.

Co-authored-by: Cursor <cursoragent@cursor.com>
root 3 mesiacov pred
rodič
commit
f193176a15
1 zmenil súbory, kde vykonal 58 pridanie a 58 odobranie
  1. 58 58
      package_for_agent_analysis.py

+ 58 - 58
package_for_agent_analysis.py

@@ -1129,64 +1129,8 @@ def collect_analysis_inputs(
 
             bitstream_obj = binding.get("bitstream") if isinstance(binding.get("bitstream"), dict) else {}
             head = str(provenance.get("head") or "")
-            artifact = str(
-                binding.get("artifact_source_commit")
-                or binding.get("commit_full")
-                or binding.get("commit")
-                or ""
-            )
-            delivery = head or artifact
-            if not artifact:
-                artifact = delivery
-            ref_pointer = pkg_prov.build_reference_pointer(
-                artifact_commit=artifact,
-                delivery_commit=delivery,
-                reference_changed=False,
-                reference_reused=True,
-                repo_root=root,
-                summary_only=False,
-            )
-            bit_sha = str(
-                binding.get("bitstream_sha256")
-                or bitstream_obj.get("sha256")
-                or ""
-            )
-            # Config fingerprint is motor-polarity masks, not project_config_sha256.
-            config_fp = motor_polarity_config_identity(root)["sha256"]
-            td_run = str(binding.get("td_run_id") or binding.get("run_id") or "")
-            if not td_run:
-                for report_meta in binding.get("td_reports") or []:
-                    if not isinstance(report_meta, dict):
-                        continue
-                    report_path = Path(str(report_meta.get("path") or ""))
-                    if report_path.is_file():
-                        try:
-                            report_payload = json.loads(
-                                report_path.read_text(encoding="utf-8-sig")
-                            )
-                        except (OSError, json.JSONDecodeError):
-                            continue
-                        td_run = str(
-                            report_payload.get("run_id")
-                            or report_payload.get("td_run_id")
-                            or ""
-                        )
-                        if td_run:
-                            break
-            ref_fp = pkg_prov.reference_set_fingerprint(root)
-            if not bit_sha:
-                raise PackagingError("release_set_id requires bound bitstream sha256")
-            if not td_run:
-                raise PackagingError("release_set_id requires td run_id from bound receipt")
-            release_set_id = pkg_prov.compute_release_set_id(
-                artifact_commit=artifact,
-                delivery_commit=delivery,
-                bitstream_sha256=bit_sha,
-                config_fingerprint=config_fp,
-                td_run_id=td_run,
-                reference_set_fingerprint_sha256=ref_fp["sha256"],
-            )
-            # Real dual-edge source-closure compare (same authority as firmware packager).
+            # Load TD report early: ARTIFACT-SOURCE is the production-input tip from
+            # the bound TD report (or canonical ARTIFACT_DEFAULT), NOT delivery HEAD.
             from build_firmware_package import (  # noqa: WPS433
                 OLD_BASELINE_COMMIT_DEFAULT,
                 generate_source_closure_comparison,
@@ -1227,6 +1171,62 @@ def collect_analysis_inputs(
                     "source-closure relations require a TD report with "
                     "synthesis_input_manifest.inputs (pass --td-report)"
                 )
+
+            report_artifact = str(
+                td_report_payload.get("commit_full")
+                or td_report_payload.get("commit")
+                or ""
+            )
+            artifact = str(
+                binding.get("artifact_source_commit")
+                or report_artifact
+                or pkg_prov.ARTIFACT_DEFAULT
+                or ""
+            )
+            delivery = head or artifact
+            if not artifact:
+                artifact = delivery
+            # Guard: do not silently collapse ARTIFACT into DELIVERY when a TD
+            # production tip is known and differs from HEAD.
+            if report_artifact and artifact == delivery and report_artifact != delivery:
+                artifact = report_artifact
+
+            ref_pointer = pkg_prov.build_reference_pointer(
+                artifact_commit=artifact,
+                delivery_commit=delivery,
+                reference_changed=False,
+                reference_reused=True,
+                repo_root=root,
+                summary_only=False,
+            )
+            bit_sha = str(
+                binding.get("bitstream_sha256")
+                or bitstream_obj.get("sha256")
+                or td_report_payload.get("bitstream_sha256")
+                or ""
+            )
+            # Config fingerprint is motor-polarity masks, not project_config_sha256.
+            config_fp = motor_polarity_config_identity(root)["sha256"]
+            td_run = str(
+                binding.get("td_run_id")
+                or binding.get("run_id")
+                or td_report_payload.get("run_id")
+                or td_report_payload.get("td_run_id")
+                or ""
+            )
+            ref_fp = pkg_prov.reference_set_fingerprint(root)
+            if not bit_sha:
+                raise PackagingError("release_set_id requires bound bitstream sha256")
+            if not td_run:
+                raise PackagingError("release_set_id requires td run_id from bound receipt")
+            release_set_id = pkg_prov.compute_release_set_id(
+                artifact_commit=artifact,
+                delivery_commit=delivery,
+                bitstream_sha256=bit_sha,
+                config_fingerprint=config_fp,
+                td_run_id=td_run,
+                reference_set_fingerprint_sha256=ref_fp["sha256"],
+            )
             art_to_del = generate_source_closure_comparison(
                 td_report=td_report_payload,
                 artifact_commit=artifact,