fix: reconcile KIS correction order chains
This commit is contained in:
@@ -104,6 +104,58 @@ def test_full_external_cancel_returns_slot_to_holding():
|
||||
assert r.rolled_back == 1
|
||||
|
||||
|
||||
def test_unresolved_poll_observability_is_sanitized_and_deduplicated(caplog):
|
||||
broker = ProgrammableBroker()
|
||||
repo, _svc, intents, execution, _ledger, _writer = _wire(broker)
|
||||
sid = _buy_to_holding(intents, execution)
|
||||
assert sid is not None
|
||||
intents.submit_sell(SellIntent(intent_id="s-poll-observe", slot_id=sid))
|
||||
samples = iter([
|
||||
("correction_child_present_unresolved", 10),
|
||||
("correction_child_present_unresolved", 10),
|
||||
("correction_child_present_unresolved", 61),
|
||||
("correction_child_present_unresolved", 61),
|
||||
("parent_identity_mismatch", 61),
|
||||
])
|
||||
|
||||
def unresolved(side):
|
||||
del side
|
||||
reason, age = next(samples)
|
||||
return FillStatus(
|
||||
state="unknown",
|
||||
raw={
|
||||
"poll_performed": True,
|
||||
"poll_count": broker.polls,
|
||||
"stuck_duration_sec": age,
|
||||
"last_result_reason": reason,
|
||||
"backoff_sec": 15.0,
|
||||
"raw_payload": {"authorization": "secret-token"},
|
||||
"broker_order_id": "sensitive-order-id",
|
||||
},
|
||||
)
|
||||
|
||||
broker.responder = unresolved
|
||||
with caplog.at_level(logging.INFO):
|
||||
for _ in range(5):
|
||||
execution.run_once()
|
||||
|
||||
observations = [
|
||||
record for record in caplog.records
|
||||
if getattr(record, "event", None) == "order_poll"
|
||||
]
|
||||
warnings = [
|
||||
record for record in caplog.records
|
||||
if getattr(record, "event", None) == "order_poll_unresolved"
|
||||
]
|
||||
assert len(observations) == 5
|
||||
assert len(warnings) == 3 # first, long-duration threshold, reason change
|
||||
assert observations[-1].poll_count == 6
|
||||
assert observations[-1].stuck_duration_sec == 61
|
||||
assert observations[-1].result_reason == "parent_identity_mismatch"
|
||||
assert "secret-token" not in caplog.text
|
||||
assert "sensitive-order-id" not in caplog.text
|
||||
|
||||
|
||||
def test_partial_fill_then_cancel_records_and_keeps_remainder():
|
||||
broker = ProgrammableBroker()
|
||||
repo, svc, intents, execution, ledger, writer = _wire(broker)
|
||||
|
||||
Reference in New Issue
Block a user