Fence unmanaged lifecycle by snapshot time

Co-authored-by: genichin <4282227+genichin@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2026-09-13 05:54:51 +00:00
committed by GitHub
co-authored by genichin
parent 84d81658a1
commit 8b1de8e26a
5 changed files with 239 additions and 34 deletions
@@ -140,6 +140,49 @@ def test_in_memory_store_preserves_first_seen_when_resolved_symbol_reappears():
assert reopened["state"]["evidence_ref"] is None
def test_in_memory_store_ignores_stale_resolve_after_newer_observation():
store = InMemoryUnmanagedPositionStore()
t1 = datetime(2026, 9, 7, 0, 0, tzinfo=UTC)
t2 = t1 + timedelta(minutes=1)
t3 = t2 + timedelta(minutes=1)
store.observe(instance_key=INSTANCE, symbol="008110", quantity=3, observed_at=t1)
store.observe(instance_key=INSTANCE, symbol="008110", quantity=5, observed_at=t3)
resolved = store.resolve_absent(
instance_key=INSTANCE,
observed_symbols=set(),
observed_at=t2,
)
assert resolved == []
state = store.get_state(instance_key=INSTANCE, symbol="008110")
assert state is not None
assert state["lifecycle_state"] == "active"
assert state["quantity"] == 5
assert store.list_audit(instance_key=INSTANCE, symbol="008110")[-1]["event_type"] == "quantity_changed"
def test_in_memory_store_ignores_stale_observation_after_newer_resolution():
store = InMemoryUnmanagedPositionStore()
t1 = datetime(2026, 9, 7, 0, 0, tzinfo=UTC)
t2 = t1 + timedelta(minutes=1)
t3 = t2 + timedelta(minutes=1)
store.observe(instance_key=INSTANCE, symbol="008110", quantity=3, observed_at=t1)
store.resolve_absent(instance_key=INSTANCE, observed_symbols=set(), observed_at=t3)
stale = store.observe(instance_key=INSTANCE, symbol="008110", quantity=5, observed_at=t2)
assert stale["transition"] == "stale"
state = store.get_state(instance_key=INSTANCE, symbol="008110")
assert state is not None
assert state["lifecycle_state"] == "resolved"
assert state["quantity"] == 3
assert [row["event_type"] for row in store.list_audit(instance_key=INSTANCE, symbol="008110")] == [
"detected",
"resolved",
]
def test_reconcile_core_holdings_suppresses_repeated_unmanaged_alarm_spam():
repo, svc = _wire()
emitter, transport = _make_emitter()