caelum0x 894359e5ff feat(railyard): per-app completion pass — money-correct settlement + crate cores
- rago: exactly-once prepaid settlement (deterministic idempotency, unique partial index + in-tx ON CONFLICT guard) — closes the double-charge risk
- mint: double-entry + reserve conservation verified (14 tests)
- ledgerline: atomic settlement outbox + partial recovery index (37 tests)
- abacus: hard per-agent budget enforcement + kill-switch (54 tests)
- vend: crash reaper / in-flight session reconciliation
- turnstile/agent-runtime/ranguard/rit/game-economy/context-passport/rithub: core advanced + tests
2026-09-07 17:17:54 +03:00

89 lines
2.5 KiB
Python

from __future__ import annotations
from collections.abc import AsyncIterator, Mapping
from dataclasses import dataclass
from relay_sdk import HttpResponse, HttpStreamResponse
@dataclass
class Call:
method: str
url: str
headers: dict[str, str]
body: bytes | None
class FakeTransport:
def __init__(self) -> None:
self.responses: list[HttpResponse] = []
self.streams: list[HttpStreamResponse] = []
self.calls: list[Call] = []
def request(
self,
method: str,
url: str,
headers: Mapping[str, str],
body: bytes | None,
) -> HttpResponse:
self.calls.append(Call(method, url, dict(headers), body))
if not self.responses:
raise AssertionError("no fake response queued")
return self.responses.pop(0)
def stream(
self,
method: str,
url: str,
headers: Mapping[str, str],
body: bytes | None,
) -> HttpStreamResponse:
self.calls.append(Call(method, url, dict(headers), body))
if not self.streams:
raise AssertionError("no fake stream queued")
return self.streams.pop(0)
class FakeAsyncTransport:
def __init__(self) -> None:
self.responses: list[HttpResponse] = []
self.streams: list[tuple[int, dict[str, str], list[bytes]]] = []
self.calls: list[Call] = []
async def request(
self,
method: str,
url: str,
headers: Mapping[str, str],
body: bytes | None,
) -> HttpResponse:
self.calls.append(Call(method, url, dict(headers), body))
if not self.responses:
raise AssertionError("no fake response queued")
return self.responses.pop(0)
async def stream(
self,
method: str,
url: str,
headers: Mapping[str, str],
body: bytes | None,
) -> tuple[int, dict[str, str], AsyncIterator[bytes]]:
self.calls.append(Call(method, url, dict(headers), body))
if not self.streams:
raise AssertionError("no fake stream queued")
status, response_headers, chunks = self.streams.pop(0)
async def iterator() -> AsyncIterator[bytes]:
for chunk in chunks:
yield chunk
return status, response_headers, iterator()
def json_response(status: int, value: object, headers: dict[str, str] | None = None) -> HttpResponse:
import json
return HttpResponse(status, headers or {}, json.dumps(value).encode())