#!/usr/bin/env python3 """Build ten method-blind, native-validated Test cases pending human review.""" from __future__ import annotations import hashlib import json from pathlib import Path from promote_second_batch_cases import attach_execution_plan, attach_generation_interface, validator ROOT = Path(__file__).resolve().parent.parent OUT_ROOT = ROOT / "data/cases/test_native_validated_pending_review" REVIEW_JSON = ROOT / "data/curation/test_batch1_native_review.json" REVIEW_MD = ROOT / "reports/test_batch1_native_review.md" ENV_ROOT = Path("/225040511/miniconda3/envs/experiment1_test_pinned") PROBE_ROOT = ROOT / "runs/test_136_native_curation/batch1" def base(package: str, version: str, build: str, endpoint: str) -> dict: return { "case_id": f"{package}_{endpoint}_test", "split": "test", "server_name": package, "package": package, "version": version, "build": build, "endpoint": endpoint, "contract_ir": None, "curation": { "status": "native_validated_pending_review", "curator": "codex_assisted_method_blind", "reviewer": "", "decision": "pending", "reviewed_on": None, "execution_ready": False, "notes": "Endpoint, fixture, native command, validators, and oracle were fixed before method generation.", }, } def build_cases() -> list[dict]: cases: list[dict] = [] env = ENV_ROOT / "cd-hit-4.8.1-h5ca1c30_13" case = base("cd-hit", "4.8.1", "h5ca1c30_13", "cluster_proteins") case.update({ "fixture_bindings": {"input_file": "data/fixtures/proteins_multi.faa"}, "arguments": {}, "native": {"environment": str(env), "command": [str(env / "bin/cd-hit"), "-i", "{input_file}", "-o", "{output_file}", "-c", "0.9", "-n", "5", "-T", "1", "-M", "100"]}, "outputs": {"output_file": "cd-hit/representatives.faa", "cluster_file": "cd-hit/representatives.faa.clstr"}, "validators": [validator("output_fasta", "output_file", "fasta"), validator("cluster_nonempty", "cluster_file", "nonempty"), validator("cluster_records", "cluster_file", "regex", pattern=r"^>Cluster")], "semantic_oracle": {"kind": "fasta_records_equal", "target": "output_file"}, "runner_notes": "cluster_file is derived by appending .clstr to output_file and is not an endpoint argument.", }) attach_generation_interface(case, "cd-hit", None, [ {"name": "input_file", "value_type": "path", "required": True, "native_binding": "-i"}, {"name": "output_file", "value_type": "path", "required": True, "native_binding": "-o"}, ], "Identity, word length, memory, and single-thread settings are fixed; cluster_file is derived.") attach_execution_plan(case, [{"command": ["cd-hit", "-i", "{input_file}", "-o", "{output_file}", "-c", "0.9", "-n", "5", "-T", "1", "-M", "100"]}]) cases.append(case) for package, version, build, executable, endpoint, command, input_binding, output_binding in [ ("clustalo", "1.2.4", "h503566f_10", "clustalo", "align_proteins", ["clustalo", "-i", "{input_file}", "-o", "{output_file}", "--outfmt=fasta", "--threads=1", "--force"], "-i", "-o"), ("clustalw", "2.1", "hc52dbad_13", "clustalw", "align_proteins", ["clustalw", {"format": "-INFILE={input_file}"}, {"format": "-OUTFILE={output_file}"}, "-OUTPUT=FASTA", "-QUIET"], "-INFILE", "-OUTFILE"), ("famsa", "2.4.1", "h9ee0642_0", "famsa", "align_proteins", ["famsa", "-t", "1", "{input_file}", "{output_file}"], "positional", "positional"), ("muscle", "5.3", "h9948957_3", "muscle", "align_proteins", ["muscle", "-align", "{input_file}", "-output", "{output_file}", "-threads", "1"], "-align", "-output"), ]: env = ENV_ROOT / f"{package}-{version}-{build}" native = [str(env / f"bin/{executable}")] for token in command[1:]: if isinstance(token, dict): native.append(token["format"]) else: native.append(token) case = base(package, version, build, endpoint) case.update({ "fixture_bindings": {"input_file": "data/fixtures/proteins_multi.faa"}, "arguments": {}, "native": {"environment": str(env), "command": native}, "outputs": {"output_file": f"{package}/aligned.faa"}, "validators": [validator("output_exists", "output_file", "exists"), validator("output_fasta", "output_file", "fasta")], "semantic_oracle": {"kind": "fasta_records_equal", "target": "output_file"}, }) attach_generation_interface(case, executable, None, [ {"name": "input_file", "value_type": "path", "required": True, "native_binding": input_binding}, {"name": "output_file", "value_type": "path", "required": True, "native_binding": output_binding}, ], "Output is fixed to FASTA and execution is single-threaded where supported.") attach_execution_plan(case, [{"command": command}]) cases.append(case) env = ENV_ROOT / "pyrodigal-3.7.1-py313h8c92656_1" case = base("pyrodigal", "3.7.1", "py313h8c92656_1", "predict_genes") case.update({ "fixture_bindings": {"input_file": "data/fixtures/test_synthetic_orfs.fa"}, "arguments": {}, "native": {"environment": str(env), "command": [str(env / "bin/pyrodigal"), "-p", "meta", "-i", "{input_file}", "-o", "{output_gff}", "-a", "{output_proteins}", "-d", "{output_genes}", "-j", "1"]}, "outputs": {"output_gff": "pyrodigal/genes.gff", "output_proteins": "pyrodigal/proteins.faa", "output_genes": "pyrodigal/genes.fna"}, "validators": [validator("gff_nonempty", "output_gff", "nonempty"), validator("gff_version", "output_gff", "regex", pattern=r"^##gff-version 3"), validator("proteins", "output_proteins", "fasta"), validator("genes", "output_genes", "fasta")], "semantic_oracle": {"kind": "fasta_records_equal", "target": "output_proteins"}, }) attach_generation_interface(case, "pyrodigal", None, [ {"name": "input_file", "value_type": "path", "required": True, "native_binding": "-i"}, {"name": "output_gff", "value_type": "path", "required": True, "native_binding": "-o"}, {"name": "output_proteins", "value_type": "path", "required": True, "native_binding": "-a"}, {"name": "output_genes", "value_type": "path", "required": True, "native_binding": "-d"}, ], "Metagenomic mode and one worker are fixed for the short synthetic fixture.") attach_execution_plan(case, [{"command": ["pyrodigal", "-p", "meta", "-i", "{input_file}", "-o", "{output_gff}", "-a", "{output_proteins}", "-d", "{output_genes}", "-j", "1"]}]) cases.append(case) env = ENV_ROOT / "samblaster-0.1.26-h9948957_7" case = base("samblaster", "0.1.26", "h9948957_7", "mark_duplicates") case.update({ "fixture_bindings": {"input_sam": "data/fixtures/second_batch_alignments.sam"}, "arguments": {}, "native": {"environment": str(env), "command": [str(env / "bin/samblaster"), "-i", "{input_sam}", "-o", "{output_sam}", "--ignoreUnmated"]}, "outputs": {"output_sam": "samblaster/output.sam"}, "validators": [validator("output_nonempty", "output_sam", "nonempty"), validator("output_sam", "output_sam", "sam")], "semantic_oracle": {"kind": "normalized_text_equal", "target": "output_sam"}, }) attach_generation_interface(case, "samblaster", None, [ {"name": "input_sam", "value_type": "path", "required": True, "native_binding": "-i"}, {"name": "output_sam", "value_type": "path", "required": True, "native_binding": "-o"}, ], "Unmated records are accepted for the deterministic tiny SAM fixture.") attach_execution_plan(case, [{"command": ["samblaster", "-i", "{input_sam}", "-o", "{output_sam}", "--ignoreUnmated"]}]) cases.append(case) env = ENV_ROOT / "ucsc-fatotwobit-482-hdc0a859_0" case = base("ucsc-fatotwobit", "482", "hdc0a859_0", "fasta_to_twobit") case.update({ "fixture_bindings": {"input_fasta": "data/fixtures/reference.fa"}, "arguments": {}, "native": {"environment": str(env), "command": [str(env / "bin/faToTwoBit"), "{input_fasta}", "{output_twobit}"]}, "outputs": {"output_twobit": "ucsc-fatotwobit/reference.2bit"}, "validators": [validator("output_exists", "output_twobit", "exists"), validator("output_nonempty", "output_twobit", "nonempty")], "semantic_oracle": {"kind": "binary_equal", "target": "output_twobit"}, }) attach_generation_interface(case, "faToTwoBit", None, [ {"name": "input_fasta", "value_type": "path", "required": True, "native_binding": "positional"}, {"name": "output_twobit", "value_type": "path", "required": True, "native_binding": "positional"}, ], "The deterministic binary artifact is compared byte-for-byte.") attach_execution_plan(case, [{"command": ["faToTwoBit", "{input_fasta}", "{output_twobit}"]}]) cases.append(case) for package, executable, endpoint, output_name, oracle in [ ("ucsc-twobitinfo", "twoBitInfo", "twobit_info", "info.tsv", "normalized_text_equal"), ("ucsc-twobittofa", "twoBitToFa", "twobit_to_fasta", "reference.fa", "fasta_records_equal"), ]: env = ENV_ROOT / f"{package}-482-hdc0a859_0" output_key = "output_file" case = base(package, "482", "hdc0a859_0", endpoint) case.update({ "fixture_bindings": {"input_twobit": "data/fixtures/test_reference.2bit"}, "arguments": {}, "native": {"environment": str(env), "command": [str(env / f"bin/{executable}"), "{input_twobit}", "{output_file}"]}, "outputs": {output_key: f"{package}/{output_name}"}, "validators": [validator("output_exists", output_key, "exists"), validator("output_nonempty", output_key, "nonempty")], "semantic_oracle": {"kind": oracle, "target": output_key}, }) if package == "ucsc-twobittofa": case["validators"].append(validator("output_fasta", output_key, "fasta")) else: case["validators"].append(validator("sequence_size", output_key, "regex", pattern=r"^chrTiny\s+40$")) attach_generation_interface(case, executable, None, [ {"name": "input_twobit", "value_type": "path", "required": True, "native_binding": "positional"}, {"name": output_key, "value_type": "path", "required": True, "native_binding": "positional"}, ]) attach_execution_plan(case, [{"command": [executable, "{input_twobit}", "{output_file}"]}]) cases.append(case) return cases def main() -> int: cases = build_cases() OUT_ROOT.mkdir(parents=True, exist_ok=True) for case in cases: (OUT_ROOT / f"{case['package']}.json").write_text(json.dumps(case, ensure_ascii=False, indent=2) + "\n", encoding="utf-8") evidence = [] for case in cases: package_dir = PROBE_ROOT / case["package"] files = [] for path in sorted(package_dir.glob("*")): if path.is_file() and path.stat().st_size: files.append({"path": str(path.relative_to(ROOT)), "size": path.stat().st_size, "sha256": hashlib.sha256(path.read_bytes()).hexdigest()}) evidence.append({ "package": case["package"], "case_id": case["case_id"], "endpoint": case["endpoint"], "environment": case["native"]["environment"], "native_command": case["native"]["command"], "validators": case["validators"], "semantic_oracle": case["semantic_oracle"], "outputs": files, "review_decision": "pending", }) payload = {"scope": "test_batch1_method_blind_native_review", "case_count": len(cases), "method_generation_started": False, "cases": evidence} REVIEW_JSON.parent.mkdir(parents=True, exist_ok=True) REVIEW_JSON.write_text(json.dumps(payload, ensure_ascii=False, indent=2) + "\n", encoding="utf-8") lines = ["# Test batch 1 native review", "", "No Direct Prompt or Contract IR artifact was generated before this review.", "", "| Package | Endpoint | Native outputs | Decision |", "|---|---|---:|---|"] for row in evidence: lines.append(f"| {row['package']} | `{row['endpoint']}` | {len(row['outputs'])} | pending |") REVIEW_MD.parent.mkdir(parents=True, exist_ok=True) REVIEW_MD.write_text("\n".join(lines) + "\n", encoding="utf-8") print(json.dumps({"cases": len(cases), "case_root": str(OUT_ROOT), "review_json": str(REVIEW_JSON), "review_md": str(REVIEW_MD)}, indent=2)) return 0 if __name__ == "__main__": raise SystemExit(main())