Preserve ledger venue provenance (#39)

* feat: preserve ledger venue provenance

* fix: satisfy ledger test lint ratchet

* fix: advance image migration inventory
This commit is contained in:
2026-09-19 19:30:32 +09:00
committed by GitHub
parent 567d662913
commit 996127f215
23 changed files with 768 additions and 35 deletions
+91
View File
@@ -147,6 +147,97 @@ def test_ledger_trade_duplicate_same_payload() -> None:
assert resp.json()["status"] == "duplicate"
def test_ledger_trade_round_trips_and_forwards_venue_provenance() -> None:
settings = _make_settings()
repo = _make_service_repo(
trade=_make_trade(execution_venue="NXT", order_venue="SOR")
)
with _with_repo(repo):
client = _make_client(settings)
resp = client.post(
_NEW_PATH,
json=_trade_payload(execution_venue="NXT", order_venue="SOR"),
headers={"Authorization": "Bearer svc-token"},
)
assert resp.status_code == 201
assert resp.json()["execution_venue"] == "NXT"
assert resp.json()["order_venue"] == "SOR"
assert repo.insert_ledger_trade.call_args.kwargs["execution_venue"] == "NXT"
assert repo.insert_ledger_trade.call_args.kwargs["order_venue"] == "SOR"
def test_ledger_trade_allows_unknown_actual_venue_with_sor_route() -> None:
settings = _make_settings()
repo = _make_service_repo(trade=_make_trade(execution_venue=None, order_venue="SOR"))
with _with_repo(repo):
client = _make_client(settings)
resp = client.post(
_NEW_PATH,
json=_trade_payload(execution_venue=None, order_venue="SOR"),
headers={"Authorization": "Bearer svc-token"},
)
assert resp.status_code == 201
assert resp.json()["execution_venue"] is None
assert resp.json()["order_venue"] == "SOR"
def test_ledger_trade_rejects_sor_as_execution_venue() -> None:
settings = _make_settings()
repo = _make_service_repo()
with _with_repo(repo):
client = _make_client(settings)
resp = client.post(
_NEW_PATH,
json=_trade_payload(execution_venue="SOR", order_venue="SOR"),
headers={"Authorization": "Bearer svc-token"},
)
assert resp.status_code == 422
repo.insert_ledger_trade.assert_not_called()
def test_ledger_trade_rejects_unknown_request_fields() -> None:
settings = _make_settings()
repo = _make_service_repo()
with _with_repo(repo):
client = _make_client(settings)
resp = client.post(
_NEW_PATH,
json=_trade_payload(broker_ordered_at="2026-05-01T09:59:59+09:00"),
headers={"Authorization": "Bearer svc-token"},
)
assert resp.status_code == 422
repo.insert_ledger_trade.assert_not_called()
def test_ledger_trade_openapi_exposes_nullable_venue_enums() -> None:
settings = _make_settings()
repo = _make_service_repo()
with _with_repo(repo):
client = _make_client(settings)
response = client.get("/openapi.json")
assert response.status_code == 200
properties = response.json()["components"]["schemas"]["LedgerTradeRequest"][
"properties"
]
execution_options = properties["execution_venue"]["anyOf"]
order_options = properties["order_venue"]["anyOf"]
assert {tuple(option.get("enum", ())) for option in execution_options} == {
(),
("KRX", "NXT"),
}
assert {tuple(option.get("enum", ())) for option in order_options} == {
(),
("KRX", "NXT", "SOR"),
}
assert {option.get("type") for option in execution_options} == {"string", "null"}
assert {option.get("type") for option in order_options} == {"string", "null"}
# ---------------------------------------------------------------------------
# AC-3: same key + different payload → 409
# ---------------------------------------------------------------------------