Unwrap chunk envelopes in spend-request poll output

This commit is contained in:
Alex Schapiro 2026-09-01 19:17:33 +00:00
parent 995ba47e05
commit 24a5a362fb
2 changed files with 17 additions and 1 deletions

View file

@ -444,7 +444,14 @@ def _spend_request_records(stdout: str) -> list[dict[str, Any]]:
records: list[dict[str, Any]] = []
for candidate in _embedded_json_documents((stdout or "").strip()):
items = candidate if isinstance(candidate, list) else [candidate]
records.extend(cast("dict[str, Any]", item) for item in items if isinstance(item, dict))
for item in items:
if not isinstance(item, dict):
continue
record = cast("dict[str, Any]", item)
data = record.get("data")
if isinstance(data, dict):
record = cast("dict[str, Any]", data)
records.append(record)
return records

View file

@ -95,6 +95,15 @@ def test_final_spend_request_status_reads_the_last_poll_line() -> None:
assert billing._final_spend_request_status("") is None
def test_final_spend_request_status_unwraps_chunk_envelopes() -> None:
stdout = (
'{"type":"chunk","data":{"id":"lsrq_9","status":"pending_approval"}}\n'
'{"type":"chunk","data":{"id":"lsrq_9","status":"approved"}}\n'
'{"type":"done","ok":true,"meta":{"command":"spend-request retrieve"}}\n'
)
assert billing._final_spend_request_status(stdout) == "approved"
def test_prepare_link_wallet_skips_login_when_connected(monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.setattr(billing, "_link_wallet_authenticated", lambda _npx: True)
assert billing._prepare_link_wallet(Console(), "npx", as_json=True) is None