run_planner_validation_commands_live.py
1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env /usr/local/miniconda3/bin/python
from __future__ import annotations
import argparse
import json
import os
from pathlib import Path
import subprocess
from typing import Any
ROOT = Path(__file__).resolve().parents[1]
DEFAULT_PLAN = ROOT / 'data' / 'pgvector_eval' / 'music20' / 'phase1_extraction_plan_report.json'
DEFAULT_OUTPUT = ROOT / 'data' / 'pgvector_eval' / 'music20' / 'planner_validation_commands_runner_report.json'
def main() -> None:
ap = argparse.ArgumentParser()
ap.add_argument('--plan', default=str(DEFAULT_PLAN))
ap.add_argument('--dsn', required=True)
ap.add_argument('--output', default=str(DEFAULT_OUTPUT))
ap.add_argument('--only', nargs='*')
args = ap.parse_args()
plan = json.loads(Path(args.plan).read_text(encoding='utf-8'))
commands: dict[str, str] = plan['validation_commands']
selected = args.only or list(commands.keys())
report: dict[str, Any] = {}
for key in selected:
if key not in commands:
raise SystemExit(f'unknown validation command: {key}')
cmd = commands[key]
proc = subprocess.run(
cmd,
cwd=ROOT,
shell=True,
text=True,
capture_output=True,
env={**os.environ, 'PG_DSN': args.dsn},
)
report[key] = {
'command': cmd,
'returncode': proc.returncode,
'stdout_tail': proc.stdout[-1200:],
'stderr_tail': proc.stderr[-1200:],
'passed': proc.returncode == 0,
}
report['summary'] = {
'selected': selected,
'executed_count': len(selected),
'all_passed': all(item['passed'] for key, item in report.items() if key != 'summary'),
}
out = Path(args.output)
out.parent.mkdir(parents=True, exist_ok=True)
out.write_text(json.dumps(report, ensure_ascii=False, indent=2), encoding='utf-8')
print(json.dumps(report, ensure_ascii=False, indent=2))
if __name__ == '__main__':
main()