from __future__ import annotations import hashlib import unittest from pathlib import Path from production_build_agents.run.layout import ( accepted_segment_ref_path, checkpoint_path, delivery_artifact_path, executor_candidate_path, executor_delivery_path, final_production_delivery_path, global_data_delivery_path, plan_json_path, plan_mermaid_path, preprocess_report_path, production_assembly_delivery_path, production_assembly_package_path, production_brief_path, production_media_inspection_path, production_package_path, production_plan_json_path, production_plan_mermaid_path, production_planning_package_path, production_progress_decision_path, production_progress_package_path, production_readiness_report_path, production_run_summary_path, production_tool_output_dir, production_validation_report_path, production_validator_candidate_path, run_lock_path, run_directory, run_metrics_path, run_summary_path, segment_execution_directive_path, segment_package_path, stage_candidate_path, stage_validation_report_path, stage_validator_tool_output_dir, task_package_path, tool_operation_path, tool_output_dir, validation_report_path, validator_tool_output_dir, ) class RunLayoutTest(unittest.TestCase): def test_all_path_formulas_preserve_existing_layout(self) -> None: root = Path("/tmp/production-run") self.assertEqual( run_directory(Path("/tmp"), "production-run"), root, ) self.assertEqual(run_lock_path(root), root / ".run.lock") self.assertEqual(checkpoint_path(root), root / "checkpoints.sqlite") self.assertEqual( checkpoint_path(root, "agent_checkpoints.sqlite"), root / "agent_checkpoints.sqlite", ) self.assertEqual( production_brief_path(root), root / "production_brief.json", ) self.assertEqual( preprocess_report_path(root), root / "preprocess_report.md", ) self.assertEqual( plan_json_path(root, 2), root / "plans" / "global_data_dag.v2.json", ) self.assertEqual( plan_mermaid_path(root, 2), root / "plans" / "global_data_dag.v2.mmd", ) self.assertEqual( task_package_path(root, "Task3", 2), root / "tasks" / "Task3.v2.json", ) self.assertEqual( executor_candidate_path(root, "Task3", 2), root / "artifacts" / "Task3" / "v2" / "executor_candidate.json", ) self.assertEqual( delivery_artifact_path(root, "Task3", 2), root / "artifacts" / "Task3" / "v2" / "delivery_artifact.json", ) self.assertEqual( executor_delivery_path(root, "Task3", 2), root / "executor_results" / "Task3.v2.json", ) self.assertEqual( validation_report_path(root, "Task3", 2), root / "validation_results" / "Task3.v2.json", ) self.assertEqual( stage_candidate_path(root, 2), root / "stage_candidates" / "global_data.v2.json", ) self.assertEqual( stage_validation_report_path(root, 2), root / "stage_validation_results" / "global_data.v2.json", ) self.assertEqual( global_data_delivery_path(root), root / "global_data_stage_delivery.json", ) self.assertEqual(run_summary_path(root), root / "run_summary.json") self.assertEqual(run_metrics_path(root), root / "run_metrics.json") self.assertEqual(tool_output_dir(root), root / "tool_outputs") self.assertEqual( validator_tool_output_dir(root), root / "validator_tool_outputs", ) self.assertEqual( stage_validator_tool_output_dir(root), root / "stage_validator_tool_outputs", ) def test_operation_path_keeps_hashed_filename(self) -> None: root = Path("/tmp/production-run") operation_id = "run-executor-Task1-v1:3" filename = hashlib.sha256(operation_id.encode("utf-8")).hexdigest() self.assertEqual( tool_operation_path(root, operation_id), root / "tool_operations" / f"{filename}.json", ) def test_production_paths_are_versioned_and_isolated(self) -> None: root = Path("/tmp/production-run") self.assertEqual( production_planning_package_path(root, 3), root / "production_planning_packages" / "v3.json", ) self.assertEqual( production_plan_json_path(root, 3), root / "production_plans" / "production_dag.v3.json", ) self.assertEqual( production_plan_mermaid_path(root, 3), root / "production_plans" / "production_dag.v3.mmd", ) self.assertEqual( production_package_path(root, 3), root / "production_packages" / "production.v3.json", ) self.assertEqual( segment_package_path(root, "Segment2", 3), root / "segment_packages" / "Segment2.v3.json", ) self.assertEqual( segment_execution_directive_path(root, "Segment2", 3), root / "segment_directives" / "Segment2.v3.json", ) self.assertEqual( accepted_segment_ref_path(root, "Segment2", 3), root / "accepted_segments" / "Segment2.v3.json", ) self.assertEqual( production_progress_package_path(root, "Segment2", 3), root / "production_progress_packages" / "Segment2.v3.json", ) self.assertEqual( production_progress_decision_path(root, "Segment2", 3), root / "production_progress_decisions" / "Segment2.v3.json", ) self.assertEqual( production_assembly_package_path(root, 3), root / "production_assembly_packages" / "production.v3.json", ) self.assertEqual( production_assembly_delivery_path(root, 3), root / "production_assembly_deliveries" / "production.v3.json", ) self.assertEqual( production_media_inspection_path(root, 3), root / "production_media_inspections" / "production.v3.json", ) self.assertEqual( production_readiness_report_path(root, 3), root / "production_readiness_reports" / "production.v3.json", ) self.assertEqual( production_validator_candidate_path(root, 3), root / "production_validator_candidates" / "production.v3.json", ) self.assertEqual( production_validation_report_path(root, 3), root / "production_validation_reports" / "production.v3.json", ) self.assertEqual( production_tool_output_dir(root, 3), root / "production_tool_outputs" / "v3", ) self.assertEqual( final_production_delivery_path(root), root / "final_production_delivery.json", ) self.assertEqual( production_run_summary_path(root), root / "production_run_summary.json", ) if __name__ == "__main__": unittest.main()