Test files received fixtures by importing them from a sibling test module (`from tests.x.test_y import daemon, owner # noqa: F401`). Every test that then takes the fixture as a parameter is a ruff F811 redefinition, which main's code-health ratchet blocks (it ignores noqa), and it couples test modules to each other. Move each shared fixture to where pytest resolves it by name, scopes unchanged (all function-scoped): - model_peer -> tests/_fixtures/model_peer.py, registered in tests/conftest.py (used by gateway, acp_adapter and hermes_cli tests) - daemon, server_spec -> tests/acp_adapter/conftest.py - owner, api -> tests/gateway/conftest.py - worker -> new tests/hermes_state/conftest.py - test_session_hosted_rpc's `owner` (a different object: hosted-room authority on its own loop) -> tests/gateway/conftest.py as `hosted_owner`, so it does not collide with the API `owner`; its three user files rename the parameter. Conftest fixtures import lazily so the gateway conftest still installs its telegram/discord mocks before any gateway module loads. Plain helpers (viewer, editor, control, policy) stay imported from their modules. Also drop an unused HostedRoomAttachmentStore local in test_hosted_attachment_bridge (F841) while that file is touched. Same tests collected and passing in every touched file. (cherry picked from commit 463102382f8cd9bbc9e0c605be7e1345165efda4)
26 lines
1.2 KiB
Python
26 lines
1.2 KiB
Python
"""Hosted source binding preserves the canonical hidden room identity."""
|
|
import hashlib
|
|
|
|
import pytest
|
|
|
|
from tests.gateway.test_hosted_room_execution_policy import _dispatch, _policy
|
|
from hermes_state_runtime import RuntimeStoreError
|
|
|
|
|
|
def test_hosted_binding_requires_exact_server_dispatch(owner):
|
|
from gateway.session_api import bind_api_session, restore_api_session
|
|
dispatch = _dispatch(_policy()).as_mapping()
|
|
seed = '\0'.join(dispatch[k] for k in ('home_install_id', 'room_id', 'member_id', 'target_profile'))
|
|
sid = 'room_' + hashlib.sha256(seed.encode()).hexdigest()[:32]
|
|
ref = bind_api_session(owner, sid, hosted_dispatch=dispatch)
|
|
row = owner.db.get_session(sid)
|
|
assert row['source'] == 'bot_room' and row['hidden'] == 1 and row['title'] == 'Group: room-1'
|
|
owner.sessions.clear()
|
|
assert restore_api_session(owner, sid) == ref
|
|
owner.sessions.clear()
|
|
with pytest.raises(RuntimeStoreError, match='permission_denied'):
|
|
bind_api_session(owner, sid)
|
|
with pytest.raises(RuntimeStoreError, match='admission_conflict'):
|
|
bind_api_session(owner, 'different-room-id', hosted_dispatch=dispatch)
|
|
assert owner.db.get_session('different-room-id') is None
|