#!/usr/bin/env python3 """Build a method-blind curation queue for exact-environment Test packages.""" from __future__ import annotations import argparse import json import os from pathlib import Path from common import read_json, write_json, write_jsonl from plan_case_expansion import suggested_fixture def executable_candidates(item: dict, stub: dict) -> list[str]: values = [ *(item.get("native_executables") or []), *(stub.get("suggested_native_executables") or []), ] return list(dict.fromkeys(str(value) for value in values if value)) def package_bin_entries(prefix: Path, package: str, version: str, build: str) -> list[dict[str, str]]: record_path = prefix / "conda-meta" / f"{package}-{version}-{build}.json" if not record_path.is_file(): return [] record = read_json(record_path) relative_paths = list(record.get("files") or []) relative_paths.extend( entry.get("_path", "") for entry in (record.get("paths_data") or {}).get("paths", []) ) entries = [] for relative in dict.fromkeys(relative_paths): path = prefix / relative if not relative.startswith("bin/") or "/" in relative[4:]: continue if path.is_file() and os.access(path, os.X_OK): entries.append({"name": path.name, "path": str(path)}) return entries def main() -> int: parser = argparse.ArgumentParser() parser.add_argument("--ready-manifest", type=Path, required=True) parser.add_argument("--install-summary", type=Path, required=True) parser.add_argument("--case-root", type=Path, required=True) parser.add_argument("--out", type=Path, required=True) parser.add_argument("--summary-out", type=Path, required=True) args = parser.parse_args() ready = read_json(args.ready_manifest) installs = { row["name"]: row for row in read_json(args.install_summary)["results"] if row.get("status") == "installed_exact" } rows = [] for item in ready["items"]: package = item["package"] install = installs[package] prefix = Path(install["prefix"]) stub_path = args.case_root / f"{package}.json" stub = read_json(stub_path) candidates = executable_candidates(item, stub) matched_candidates = [ {"name": name, "path": str(prefix / "bin" / name)} for name in candidates if (prefix / "bin" / name).is_file() and os.access(prefix / "bin" / name, os.X_OK) ] packaged_entries = package_bin_entries(prefix, package, item["version"], item["build"]) installed = list({entry["path"]: entry for entry in [*matched_candidates, *packaged_entries]}.values()) help_path = Path(item["help_path"]) help_text = help_path.read_text(encoding="utf-8", errors="ignore") if help_path.is_file() else "" blockers = [] if not help_text.strip(): blockers.append("missing_help") if not installed: blockers.append("suggested_executable_not_found_in_exact_environment") rows.append( { "package": package, "version": item["version"], "build": item["build"], "environment": str(prefix), "help_path": str(help_path), "help_lines": len(help_text.splitlines()), "candidate_executables": candidates, "matched_suggested_executables": matched_candidates, "target_package_bin_entries": packaged_entries, "installed_candidate_executables": installed, "suggested_fixture": suggested_fixture(item, help_text), "category": item.get("category"), "complexity": item.get("complexity"), "strict_core": bool(item.get("strict_core", False)), "curation_status": "ready_for_endpoint_curation" if not blockers else "blocked_preflight", "blockers": blockers, "target_endpoint": None, "native_command": None, "validators": None, "semantic_oracle": None, "generation_started": False, } ) rows.sort(key=lambda row: (row["curation_status"] != "ready_for_endpoint_curation", row["complexity"] or "", row["package"])) write_jsonl(args.out, rows) summary = { "source_ready_manifest": str(args.ready_manifest), "source_ready_manifest_sha256": __import__("hashlib").sha256(args.ready_manifest.read_bytes()).hexdigest(), "total": len(rows), "ready_for_endpoint_curation": sum(row["curation_status"] == "ready_for_endpoint_curation" for row in rows), "blocked_preflight": sum(row["curation_status"] == "blocked_preflight" for row in rows), "generation_started": False, "blocked_packages": [ {"package": row["package"], "blockers": row["blockers"]} for row in rows if row["blockers"] ], } write_json(args.summary_out, summary) print(json.dumps(summary, indent=2, ensure_ascii=False)) return 0 if __name__ == "__main__": raise SystemExit(main())