A fake tracedecay binary that echoes how `--args` reached it.
(work: Path)
| 103 | |
| 104 | |
| 105 | def write_fake_bin(work: Path) -> Path: |
| 106 | """A fake tracedecay binary that echoes how `--args` reached it.""" |
| 107 | fake = work / "fake-tracedecay.py" |
| 108 | fake.write_text( |
| 109 | """#!/usr/bin/env python3 |
| 110 | import json, sys |
| 111 | argv = sys.argv[1:] |
| 112 | value = argv[argv.index("--args") + 1] |
| 113 | at_file = value.startswith("@") |
| 114 | payload = open(value[1:], encoding="utf-8").read() if at_file else value |
| 115 | args = json.loads(payload) |
| 116 | inner = json.dumps({ |
| 117 | "status": "ok", |
| 118 | "at_file": at_file, |
| 119 | "payload_bytes": len(payload.encode("utf-8")), |
| 120 | "args_keys": sorted(args.keys()), |
| 121 | }) |
| 122 | print(json.dumps({"content": [{"type": "text", "text": inner}]})) |
| 123 | """, |
| 124 | encoding="utf-8", |
| 125 | ) |
| 126 | fake.chmod(0o755) |
| 127 | return fake |
| 128 | |
| 129 | |
| 130 | def main(): |