fix(ledger): split dividend response schema and harden decimal tests

Co-authored-by: genichin <4282227+genichin@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2026-09-09 13:21:24 +00:00
committed by GitHub
co-authored by genichin
parent d3601d32dc
commit e261a41b7f
4 changed files with 120 additions and 37 deletions
@@ -292,7 +292,7 @@ def test_dividend_precision_and_reversal_round_trip_on_real_postgres(
assert dividend.price == 0.00000001
assert dividend.tax_amount == 0.00000001
assert str(dividend.tax_amount_decimal) == "0.00000001"
assert dividend.tax_amount_decimal == Decimal("0.00000001")
assert dividend.profit_buffer_after == 0.00000001
with repo._connect().cursor() as cur:
cur.execute(
@@ -330,7 +330,7 @@ def test_dividend_tax_omitted_persists_zero_on_real_postgres(
note="tax-omitted",
)
assert dividend.tax_amount == 0.0
assert str(dividend.tax_amount_decimal) == "0E-8"
assert dividend.tax_amount_decimal == Decimal("0.00000000")
with repo._connect().cursor() as cur:
cur.execute("SELECT tax_amount::text FROM portfolio_ledger WHERE ledger_entry_id = %s", (dividend.ledger_entry_id,))
assert cur.fetchone()[0] == "0.00000000"
@@ -431,7 +431,7 @@ def test_large_invest_and_large_dividend_tax_metadata_are_accepted_when_snapshot
note="large-tax-metadata",
)
assert dividend.tax_amount == 50000000.0
assert str(dividend.tax_amount_decimal) == "50000000.00000000"
assert dividend.tax_amount_decimal == Decimal("50000000.00000000")
repo.close()
@@ -458,8 +458,8 @@ def test_dividend_tax_alias_prone_decimals_round_trip_distinctly_on_real_postgre
executed_at=datetime(2026, 9, 2, 0, 0, 0, tzinfo=UTC),
note="alias-tax-2",
)
assert str(first.tax_amount_decimal) == "90000000.00000001"
assert str(second.tax_amount_decimal) == "90000000.00000002"
assert first.tax_amount_decimal == Decimal("90000000.00000001")
assert second.tax_amount_decimal == Decimal("90000000.00000002")
repo.close()
+6 -3
View File
@@ -981,9 +981,12 @@ def test_unified_ledger_openapi_contains_nullable_amount() -> None:
response = client.get("/openapi.json")
assert response.status_code == 200
schemas = response.json()["components"]["schemas"]
assert "amount" in schemas["LedgerHistoryItem"]["properties"]
amount_schema = schemas["ManualLedgerResponse"]["properties"]["amount"]
assert any(option.get("type") == "number" for option in amount_schema.get("anyOf", []))
manual_amount_types = {option.get("type") for option in schemas["ManualLedgerResponse"]["properties"]["amount"]["anyOf"]}
assert manual_amount_types == {"number", "null"}
assert schemas["DividendManualLedgerResponse"]["properties"]["amount"]["type"] == "string"
history_amount_types = {option.get("type") for option in schemas["LedgerHistoryItem"]["properties"]["amount"]["anyOf"]}
assert history_amount_types == {"number", "null"}
assert schemas["DividendLedgerHistoryItem"]["properties"]["amount"]["type"] == "string"
def test_reversal_rejects_fee_tax_and_missing_target() -> None: