44 lines
1.4 KiB
Python
Executable File
44 lines
1.4 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
"""CommandPlan/CommandPatchSet JSON을 frozen command analysis와 대조한다."""
|
|
from __future__ import annotations
|
|
|
|
import argparse
|
|
import json
|
|
import os
|
|
import sys
|
|
|
|
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
|
from command_pedagogy import validate_command_patch_set, validate_command_plan # noqa: E402
|
|
|
|
|
|
def _load(path: str) -> dict:
|
|
with open(path, encoding="utf-8") as fh:
|
|
value = json.load(fh)
|
|
if not isinstance(value, dict):
|
|
raise ValueError(f"JSON object가 아니다: {path}")
|
|
return value
|
|
|
|
|
|
def main() -> int:
|
|
ap = argparse.ArgumentParser(description="command-pedagogy first-class artifact를 검증한다")
|
|
ap.add_argument("kind", choices=("plan", "patch"))
|
|
ap.add_argument("artifact")
|
|
ap.add_argument("--analysis", required=True, help="frozen deterministic analysis JSON")
|
|
args = ap.parse_args()
|
|
try:
|
|
artifact = _load(args.artifact)
|
|
analysis = _load(args.analysis)
|
|
if args.kind == "plan":
|
|
validate_command_plan(artifact, analysis=analysis)
|
|
else:
|
|
validate_command_patch_set(artifact, analysis=analysis)
|
|
except (OSError, json.JSONDecodeError, ValueError) as exc:
|
|
print(f"COMMAND ARTIFACT: FAIL — {exc}", file=sys.stderr)
|
|
return 1
|
|
print(f"COMMAND ARTIFACT: PASS — {args.kind} {args.artifact}")
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|