Files
aigc-home/docs/hel-892/minimax-r2v-4ref-api-document-evidence/run_check.py
T

41 lines
1.3 KiB
Python

"""Run one foreground check into exclusive batch-owned files and record its exit."""
import hashlib
import json
import subprocess
import sys
from evidence_logs import KEYS, LOCAL, REPO
def main():
key, cwd, *command = sys.argv[1:]
assert key in KEYS and command
assert json.loads((LOCAL / "preflight.json").read_bytes())["existed_before"] is False
logs, records = LOCAL / "logs", LOCAL / "records"
logs.mkdir(exist_ok=True)
records.mkdir(exist_ok=True)
paths = [logs / f"batch172-mh4r-{key}.{stream}.txt" for stream in ("stdout", "stderr")]
record = records / (key + ".json")
assert not record.exists() and not any(p.exists() for p in paths)
with paths[0].open("xb") as stdout, paths[1].open("xb") as stderr:
result = subprocess.run(command, cwd=REPO / cwd, stdout=stdout, stderr=stderr)
rows = [
dict(name=p.name, bytes=p.stat().st_size, sha256=hashlib.sha256(p.read_bytes()).hexdigest())
for p in paths
]
with record.open("x") as dest:
json.dump(
dict(key=key, cwd=cwd, command=command, returncode=result.returncode, logs=rows),
dest,
ensure_ascii=False,
indent=2,
)
dest.write("\n")
print(key, "exit", result.returncode)
raise SystemExit(result.returncode)
if __name__ == "__main__":
main()