fix(execution): bind parent row to request identity before child evaluation; add parent mismatch and race tests

Co-authored-by: genichin <4282227+genichin@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2026-09-01 13:21:20 +00:00
committed by GitHub
co-authored by genichin
parent 65df10542b
commit 584e08eb36
3 changed files with 245 additions and 15 deletions
+118
View File
@@ -391,3 +391,121 @@ def test_ambiguous_multiple_child_cancel_rows_return_unknown(monkeypatch):
assert fs.state == "unknown", f"expected unknown (ambiguous children), got {fs.state}"
raw = fs.raw if isinstance(fs.raw, dict) else {}
assert raw.get("reason") == "child_cancel_ambiguous"
# ── Regression: parent row identity mismatch with request ────────────────────
def test_parent_row_wrong_branch_returns_unknown(monkeypatch):
"""Parent row with wrong ord_gno_brno (branch) relative to broker_order_id → unknown."""
parent = {
"odno": ODNO,
"orgn_odno": "",
"ord_qty": "10",
"tot_ccld_qty": "0",
"avg_prvs": "0",
"cncl_yn": "",
"rjct_qty": "0",
"ord_dt": "20260901",
"ord_gno_brno": "99999", # wrong branch — request has 06010
"pdno": "225190",
}
monkeypatch.setattr(
kis_mod.httpx, "get", _fake_get({"rt_cd": "0", "output1": [parent]})
)
# broker_order_id encodes branch 06010, but row has 99999
fs = _broker().poll_fill(
f"06010:{ODNO}", side="buy", symbol="225190", order_date="20260901"
)
assert fs.state == "unknown", f"expected unknown (wrong parent branch), got {fs.state}"
raw = fs.raw if isinstance(fs.raw, dict) else {}
assert "mismatch" in raw.get("reason", "")
def test_parent_row_wrong_date_returns_unknown(monkeypatch):
"""Parent row with wrong ord_dt relative to order_date arg → unknown."""
parent = {
"odno": ODNO,
"orgn_odno": "",
"ord_qty": "10",
"tot_ccld_qty": "0",
"avg_prvs": "0",
"cncl_yn": "",
"rjct_qty": "0",
"ord_dt": "20260831", # wrong date — request has 20260901
"ord_gno_brno": "06010",
"pdno": "225190",
}
monkeypatch.setattr(
kis_mod.httpx, "get", _fake_get({"rt_cd": "0", "output1": [parent]})
)
fs = _broker().poll_fill(
f"06010:{ODNO}", side="buy", symbol="225190", order_date="20260901"
)
assert fs.state == "unknown", f"expected unknown (wrong parent date), got {fs.state}"
raw = fs.raw if isinstance(fs.raw, dict) else {}
assert "mismatch" in raw.get("reason", "")
def test_parent_row_wrong_symbol_returns_unknown(monkeypatch):
"""Parent row with wrong pdno (symbol) relative to symbol arg → unknown."""
parent = {
"odno": ODNO,
"orgn_odno": "",
"ord_qty": "10",
"tot_ccld_qty": "0",
"avg_prvs": "0",
"cncl_yn": "",
"rjct_qty": "0",
"ord_dt": "20260901",
"ord_gno_brno": "06010",
"pdno": "000660", # wrong symbol — request has 225190
}
monkeypatch.setattr(
kis_mod.httpx, "get", _fake_get({"rt_cd": "0", "output1": [parent]})
)
fs = _broker().poll_fill(
f"06010:{ODNO}", side="buy", symbol="225190", order_date="20260901"
)
assert fs.state == "unknown", f"expected unknown (wrong parent symbol), got {fs.state}"
raw = fs.raw if isinstance(fs.raw, dict) else {}
assert "mismatch" in raw.get("reason", "")
def test_correction_child_wrong_identity_is_not_treated_as_correction(monkeypatch):
"""Correction child with wrong branch/date/symbol must not trigger correction_child_present_unresolved."""
parent = {
"odno": ODNO,
"orgn_odno": "",
"ord_qty": "10",
"tot_ccld_qty": "0",
"avg_prvs": "0",
"cncl_yn": "",
"rjct_qty": "0",
"ord_dt": "20260901",
"ord_gno_brno": "06010",
"pdno": "225190",
}
unrelated_correction = {
"odno": "0000199990",
"orgn_odno": ODNO,
"ord_qty": "10",
"tot_ccld_qty": "0",
"avg_prvs": "0",
"cncl_yn": "N",
"rjct_qty": "0",
"ord_dt": "20260831", # different date → not related to our request
"ord_gno_brno": "99999", # different branch
"pdno": "000660", # different symbol
}
monkeypatch.setattr(
kis_mod.httpx,
"get",
_fake_get({"rt_cd": "0", "output1": [parent, unrelated_correction]}),
)
fs = _broker().poll_fill(
f"06010:{ODNO}", side="buy", symbol="225190", order_date="20260901"
)
# Unrelated correction must not cause correction_child_present_unresolved
assert fs.state == "accepted", f"expected accepted (unrelated correction), got {fs.state}"
raw = fs.raw if isinstance(fs.raw, dict) else {}
assert raw.get("reason") != "correction_child_present_unresolved"