Skip to content

The agent that grows with you

test(webhook): trim finalization recovery tests to three invariants

teknium1f93892a9ece4
diff --git a/tests/gateway/test_hosted_mux_runtime.py b/tests/gateway/test_hosted_mux_runtime.py
index bc118a324b5..c7389b59f5a 100644
--- a/tests/gateway/test_hosted_mux_runtime.py
+++ b/tests/gateway/test_hosted_mux_runtime.py
@@ -77,29 +77,6 @@ def test_hosted_lifecycle_serves_and_stops_every_authority(mux):
assert all(not s.runtime.status()['running'] for s in services.values())
-def test_native_recovery_checks_webhook_finalization_in_each_owner_scope(mux, monkeypatch):
- from gateway.run_runtime import recover_gateway_native_sessions
- from hermes_constants import get_hermes_home
-
- runner, homes, _, call = mux
- observed = []
-
- async def record_scope(authority):
- observed.append((authority.profile_id, get_hermes_home().resolve()))
- return {}
-
- monkeypatch.setattr(
- "gateway.platforms.webhook_ingress.recover_webhook_finalizations", record_scope
- )
- call(recover_gateway_native_sessions(runner))
-
- assert observed == [
- (authority.profile_id, Path(authority.profile_id).resolve())
- for authority in runner.session_authorities
- ]
- assert {home for _profile, home in observed} == {home.resolve() for home in homes.values()}
-
-
def test_secondary_owner_transport_routes_both_directions_through_mux(mux):
from gateway import hosted_rooms
from gateway.session_authorities import owner_scope
diff --git a/tests/gateway/test_webhook_finalization_recovery.py b/tests/gateway/test_webhook_finalization_recovery.py
index 6d789470b28..9ef6f5c6e0a 100644
--- a/tests/gateway/test_webhook_finalization_recovery.py
+++ b/tests/gateway/test_webhook_finalization_recovery.py
@@ -169,24 +169,3 @@ async def test_duplicate_request_finalizes_settled_webhook_without_reexecution()
assert authority.db.get_session(row["target_session_id"])["end_reason"] == "webhook_complete"
assert scheduled == []
assert len(authority.db._read_all("SELECT * FROM session_admissions")) == 1
-
-
[email protected]("route", [None, {"prompt": "changed {text}", "deliver": "log"}])
-async def test_startup_leaves_settled_webhook_open_when_route_is_missing_or_changed(route):
- async with settled_before_finalizer() as (_client, _body, _headers, _runner, authority, row):
- from gateway.platforms.webhook_ingress import recover_webhook_finalizations
-
- entry = authority.runner.session_store.lookup_by_session_id(row["target_session_id"])
- adapter = authority.runner._adapter_for_source(entry.origin)
- if route is None:
- adapter._routes.pop("fixture")
- else:
- adapter._routes["fixture"] = route
-
- await recover_webhook_finalizations(authority)
-
- saved = authority.db.get_session(row["target_session_id"])
- assert saved["ended_at"] is None
- assert saved["end_reason"] is None
- assert len(authority.db._read_all("SELECT * FROM session_admissions")) == 1
diff --git a/tests/gateway/test_webhook_session_close.py b/tests/gateway/test_webhook_session_close.py
index 3830cd919fb..a8692faed50 100644
--- a/tests/gateway/test_webhook_session_close.py
+++ b/tests/gateway/test_webhook_session_close.py
@@ -46,52 +46,3 @@ async def test_webhook_finalization_is_exact_session_and_generation(tmp_path):
event._webhook_receipt = (authority, newer)
await adapter._end_webhook_session(event, source.chat_id)
assert authority.db.get_session(ref.session_id)['end_reason'] == 'webhook_complete'
-
-
-async def test_old_authority_callback_cannot_mutate_after_replacement(tmp_path):
- runner = GatewayRunner()
- old = await initialize_session_authority(runner, profile_id='default', instance_id='old-owner')
- runner._session_db = old.db
- adapter = WebhookAdapter(PlatformConfig(enabled=True, extra={'secret': 'owned-close-secret'}))
- adapter.gateway_runner = runner
- runner.adapters[Platform.WEBHOOK] = adapter
- runner._wire_adapter_handlers(adapter)
- source = adapter.build_source(chat_id='webhook:close:replacement', user_id='webhook:close', chat_type='webhook')
- ref = old.register(source)
- row = admit_session_input(old.db, epoch=old.epoch, principal_id='fixture',
- session_id=ref.session_id, request_id='settled', payload={'text': 'fixture'})
- claimed = claim_session_input(old.db, epoch=old.epoch, session_id=ref.session_id)
- receipt = old._receipt(settle_session_input(old.db, epoch=old.epoch,
- admission_id=row['admission_id'], generation=claimed['generation'], outcome='completed'))
- replacement = await initialize_session_authority(runner, profile_id='default',
- instance_id='replacement-owner', db=old.db)
- event = MessageEvent(text='fixture', source=source, message_id='settled')
-
- event._webhook_receipt = (old, receipt)
- await adapter._end_webhook_session(event, source.chat_id)
- assert old.db.get_session(ref.session_id)['ended_at'] is None
-
- event._webhook_receipt = (replacement, receipt)
- await adapter._end_webhook_session(event, source.chat_id)
- assert old.db.get_session(ref.session_id)['end_reason'] == 'webhook_complete'
-
-
-async def test_webhook_finalization_is_blocked_by_nonterminal_sibling(tmp_path):
- runner = GatewayRunner()
- authority = await initialize_session_authority(runner, profile_id='default', instance_id='sibling-test')
- source = WebhookAdapter(PlatformConfig(enabled=True, extra={'secret': 'secret'})).build_source(
- chat_id='webhook:close:sibling', user_id='webhook:close', chat_type='webhook')
- ref = authority.register(source)
- first = admit_session_input(authority.db, epoch=authority.epoch, principal_id='fixture',
- session_id=ref.session_id, request_id='first', payload={'text': 'first'})
- claimed = claim_session_input(authority.db, epoch=authority.epoch, session_id=ref.session_id)
- receipt = authority._receipt(settle_session_input(authority.db, epoch=authority.epoch,
- admission_id=first['admission_id'], generation=claimed['generation'], outcome='completed'))
- admit_session_input(authority.db, epoch=authority.epoch, principal_id='fixture',
- session_id=ref.session_id, request_id='second', payload={'text': 'second'})
-
- from gateway.platforms.webhook_ingress import finalize_webhook
- assert finalize_webhook(authority, receipt) is False
- assert authority.db.get_session(ref.session_id)['ended_at'] is None