| 1 | #!/usr/bin/env python3 |
| 2 | """Measure canonical production-built tool catalogs by visible mode. |
| 3 | |
| 4 | This delegates to an ignored Rust test that runs the production registry, |
| 5 | catalog, and active-request planner with inert wiring. Token counts are |
| 6 | deterministic estimates using ceil(serialized_bytes/4). |
| 7 | """ |
| 8 | |
| 9 | from __future__ import annotations |
| 10 | |
| 11 | import json |
| 12 | import subprocess |
| 13 | import sys |
| 14 | |
| 15 | |
| 16 | MARKER = "TOOL_CATALOG_METRICS " |
| 17 | |
| 18 | |
| 19 | def main() -> int: |
| 20 | cmd = [ |
| 21 | "cargo", |
| 22 | "test", |
| 23 | "--locked", |
| 24 | "-p", |
| 25 | "codewhale-tui", |
| 26 | "--bin", |
| 27 | "codewhale-tui", |
| 28 | "print_mode_tool_catalog_metrics", |
| 29 | "--", |
| 30 | "--ignored", |
| 31 | "--nocapture", |
| 32 | "--test-threads=1", |
| 33 | ] |
| 34 | proc = subprocess.run(cmd, text=True, capture_output=True, check=False) |
| 35 | sys.stderr.write(proc.stderr) |
| 36 | |
| 37 | combined = proc.stdout.splitlines() + proc.stderr.splitlines() |
| 38 | for line in combined: |
| 39 | if MARKER in line: |
| 40 | metrics = json.loads(line.split(MARKER, 1)[1]) |
| 41 | print(json.dumps(metrics, indent=2, sort_keys=True)) |
| 42 | return proc.returncode |
| 43 | |
| 44 | sys.stdout.write(proc.stdout) |
| 45 | sys.stderr.write("missing TOOL_CATALOG_METRICS marker\n") |
| 46 | return proc.returncode or 1 |
| 47 | |
| 48 | |
| 49 | if __name__ == "__main__": |
| 50 | raise SystemExit(main()) |
| 51 |