The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
test(gateway): cover messaging and cron sessions in the stored picker feed (currently failing)
yoniebansbe8f7f16ff2d
diff --git a/tests/gateway/test_stored_picker_routed_sources.py b/tests/gateway/test_stored_picker_routed_sources.pynew file mode 100644index 00000000000..2af3e910978--- /dev/null+++ b/tests/gateway/test_stored_picker_routed_sources.py@@ -0,0 +1,82 @@+"""Regression for TUI-8 (#134889): the native picker's stored feed lists messaging and cron sessions.++Before the shared gateway the picker listed every source except the internal ones (kanban, tool,+oneshot); the stored feed listed only local labels, so a Telegram conversation or a finished cron run+could not be picked from Ink's ``/resume``. Resuming such a row is the cold mount+(``gateway/session_route_recovery.py``); this pins that the listing offers it.+"""+from types import SimpleNamespace++import pytest+++async def _owner(tmp_path, monkeypatch):+ from gateway import run+ from gateway.config import GatewayConfig+ from gateway.session import SessionStore+ from gateway.session_authority import initialize_session_authority++ monkeypatch.setenv('HERMES_HOME', str(tmp_path))+ monkeypatch.setattr(run, '_load_gateway_config', lambda: {'model': {}, 'platform_toolsets': {'cli': []}})+ store = SessionStore(tmp_path / 'sessions', GatewayConfig())+ runner = SimpleNamespace(session_store=store, _session_db=store._db, adapters={}, _draining=False,+ _cached_agent_for=lambda route: None, _restored_source=lambda entry: entry.origin)+ runner._adapter_for_source = lambda source: runner.adapters.get(source.platform)+ authority = await initialize_session_authority(runner, profile_id=str(tmp_path), instance_id='owner')+ authority._schedule = lambda ref: None+ runner.session_authority = authority+ return authority, store._db+++async def _finished_cron_run(authority, db, tmp_path):+ """A cron fire through the owner's own path, then settled the way a finished run books it."""+ from cron import jobs+ from gateway import session_cron+ from hermes_state_runtime import cancel_session_input+ with jobs.use_cron_store(tmp_path / 'cron'):+ job = jobs.create_job(prompt='report', schedule='every 1h', deliver='local', model='m')+ receipt = await session_cron.operation(authority, 'submit', {'job_id': job['id'], 'request_id': 'fire',+ 'extra_prompt': None})+ cancel_session_input(db, epoch=authority.epoch, admission_id=receipt['admission_id'])+ db.end_session(receipt['session_id'], 'cron_complete')+ return receipt['session_id']+++def _messaging_row(db, sid, chat_id, *, profile_name=None):+ import json+ route = f'agent:main:telegram:dm:{chat_id}'+ db.create_session(sid, source='telegram', model='m', user_id='111', profile_name=profile_name)+ db._write_sql('UPDATE sessions SET session_key=?, chat_id=?, chat_type=?, origin_json=? WHERE id=?',+ (route, chat_id, 'dm', json.dumps({'platform': 'telegram', 'chat_id': chat_id, 'chat_type': 'dm',+ 'user_id': '111'}), sid))+ db.append_message(sid, 'user', sid + ' question')+ db.append_message(sid, 'assistant', sid + ' answer')+ db.end_session(sid, 'session_reset')+++async def test_the_stored_feed_lists_messaging_and_cron_sessions_and_hides_internal_ones(tmp_path, monkeypatch):+ from gateway.session_controls import AuthorityConnection++ authority, db = await _owner(tmp_path, monkeypatch)+ _messaging_row(db, 'tg-chat', '111')+ _messaging_row(db, 'tg-other-profile', '112', profile_name='other')+ cron_run = await _finished_cron_run(authority, db, tmp_path)+ for sid, source in [('worker', 'kanban'), ('integration', 'tool'), ('once', 'oneshot')]:+ db.create_session(sid, source=source, model='m')+ db.append_message(sid, 'user', sid + ' question')+ db.end_session(sid, 'completed')+ # The native local transport, as `gateway/run_api.py` admits it (a verified local operator).+ native = AuthorityConnection(authority, object(), {'provider': 'local', 'user_id': 'native',+ 'profile_id': str(tmp_path), 'instance_id': 'owner'},+ operator=True)++ listed = await native.dispatch({'id': 1, 'method': 'session.list', 'params': {'scope': 'stored'}})+ assert 'result' in listed, listed+ ids = {row['id'] for row in listed['result']['sessions']}+ assert {'tg-chat', cron_run} <= ids+ assert not ids & {'worker', 'integration', 'once', 'tg-other-profile'}++ resumed = await native.dispatch({'id': 2, 'method': 'session.resume', 'params': {'session_id': 'tg-chat'}})+ assert 'result' in resumed, resumed+ assert [m['content'] for m in resumed['result']['messages']] == ['tg-chat question', 'tg-chat answer']