#!/usr/bin/env python3 """T3 子进程:读取既有账本,尝试一次请求,应被拦且零出站。""" from __future__ import annotations import json import sys from pathlib import Path import httpx sys.path.insert(0, str(Path(__file__).resolve().parents[2])) from spike.hel857.ledger import AccountingTransport, BudgetBlocked, FakeTransport, Ledger # noqa: E402 def main() -> int: led = Ledger(Path(sys.argv[1])) fake = FakeTransport() client = httpx.Client(transport=AccountingTransport(fake, led), base_url="http://fake.invalid") blocked = False msg = "" try: client.post("/v1/chat/completions", json={"messages": [{"role": "user", "content": "跨进程"}]}) except BudgetBlocked as e: blocked = True msg = str(e) print(json.dumps({ "blocked": blocked, "message": msg, "fake_attempts": fake.attempts, "used_seen_by_child": led.used(), "pid": __import__("os").getpid(), })) return 0 if __name__ == "__main__": raise SystemExit(main())