fix(manual-ledger): harden schema init race and sanitize error responses

Co-authored-by: genichin <4282227+genichin@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2026-09-09 11:38:32 +00:00
committed by GitHub
co-authored by genichin
parent 78e347703e
commit a36b451a3d
5 changed files with 103 additions and 4 deletions
+25
View File
@@ -386,6 +386,31 @@ def test_insufficient_cash_rejected_as_409() -> None:
assert resp.status_code == 409
assert resp.json()["detail"]["code"] == "INSUFFICIENT_CASH"
assert resp.json()["detail"]["message"] == "Insufficient cash balance"
def test_manual_ledger_conflict_message_is_sanitized() -> None:
repo = _FakeRepo(_portfolio())
client = _make_client(repo)
secret = "SENTINEL_SECRET_TOKEN_12345"
def _raise_secret(*args: Any, **kwargs: Any) -> LedgerEntry:
raise ValueError(f"synthetic backend failure: {secret}")
repo.record_manual_ledger = _raise_secret # type: ignore[method-assign]
resp = client.post(
f"/v1/portfolios/{_PORTFOLIO_ID}/ledger/manual",
json={"action": "DIVIDEND", "amount": 1, "executed_at": "2026-09-01"},
headers=_auth(),
)
assert resp.status_code == 422
detail = resp.json()["detail"]
assert detail["code"] == "MANUAL_LEDGER_CONFLICT"
assert detail["message"] == "Manual ledger request could not be processed"
assert secret not in resp.text
def test_manual_history_returns_total_value_after() -> None: