From 24a5a362fbb15b9172c2b51a02d932ddece24feb Mon Sep 17 00:00:00 2001 From: Alex Schapiro Date: Tue, 1 Sep 2026 19:17:33 +0000 Subject: [PATCH] Unwrap chunk envelopes in spend-request poll output --- strix/interface/cloud/billing.py | 9 ++++++++- tests/test_cloud_wallet.py | 9 +++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/strix/interface/cloud/billing.py b/strix/interface/cloud/billing.py index c91a731c..bd139fcb 100644 --- a/strix/interface/cloud/billing.py +++ b/strix/interface/cloud/billing.py @@ -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 diff --git a/tests/test_cloud_wallet.py b/tests/test_cloud_wallet.py index 33b48c86..6efd202f 100644 --- a/tests/test_cloud_wallet.py +++ b/tests/test_cloud_wallet.py @@ -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