The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
test: restore three of #139721's created_source tests
kshitijk4poor2ff6d1582169
diff --git a/tests/gateway/test_resume_latest_local_cli.py b/tests/gateway/test_resume_latest_local_cli.pyindex 3e09adb814b..a51f23ba41e 100644--- a/tests/gateway/test_resume_latest_local_cli.py+++ b/tests/gateway/test_resume_latest_local_cli.py@@ -151,6 +151,35 @@ async def test_reset_copies_the_parent_surface_and_falls_back_to_policy(tmp_pathstore.close_all_db_handles()+async def test_compress_mutation_copies_parent_or_uses_the_policy_surface(tmp_path, monkeypatch):+ """The compress mutation copies the parent's surface. A NULL or ``local`` parent is not a+ surface, so the child falls back to the policy label."""+ from hermes_state_mutation_compress import compress_in_transaction+ from hermes_state_mutation_prepared import local_snapshot++ store, authority, owner = _owner(tmp_path / 'home', monkeypatch)+ try:+ def compress(sid):+ def write(conn):+ snapshot = local_snapshot(authority.db, conn, sid)+ prepared = {'snapshot': snapshot, 'in_place': False,+ 'messages': [{'role': 'user', 'content': 'hi'}]}+ return compress_in_transaction(authority.db, conn, sid, {}, prepared)+ return authority.db._execute_write(write)[1]['target_session_id']++ for parent_created, expected in (('desktop', 'desktop'), (None, 'cli'), ('local', 'cli')):+ created = await _call(owner, 'session.create', request_id=f'compress-{parent_created}',+ source='cli', cwd=str(tmp_path), toolsets=[], model='m')+ sid = created['session_id']+ _set_created(authority.db, sid, parent_created)+ row = authority.db.get_session(compress(sid))+ assert row['created_source'] == expected, (parent_created, row['created_source'])+ finally:+ await owner.close()+ store.close_all_db_handles()++def _listed(db, source, capsys):from argparse import Namespacefrom hermes_cli.sessions_cmd import _cmd_list@@ -158,6 +187,28 @@ def _listed(db, source, capsys):return capsys.readouterr().out[email protected](('surface', 'labels'), [('gui', ('gui', 'desktop')), ('acp', ('acp',))])+async def test_gui_and_acp_list_under_the_policy_label_and_the_agent_surface(+ tmp_path, monkeypatch, capsys, surface, labels):+ """session.create stamps the agent surface (gui is desktop). --source accepts+ either name, before the peer refresh and after the row is stored as local."""+ store, authority, owner = _owner(tmp_path / 'home', monkeypatch)+ try:+ created = await _call(owner, 'session.create', request_id=surface, source=surface,+ cwd=str(tmp_path), toolsets=[], model='m')+ sid = created['session_id']+ for label in labels:+ assert sid in _listed(authority.db, label, capsys), (surface, label, 'before peer')+ live = authority.sessions[sid]+ store._record_gateway_session_peer(sid, live.route, live.source)+ for label in labels:+ assert sid in _listed(authority.db, label, capsys), (surface, label, 'after peer')+ finally:+ await owner.close()+ store.close_all_db_handles()++@pytest.mark.asyncioasync def test_oneshot_keeps_its_own_created_source_and_stays_out_of_cli(tmp_path, monkeypatch, capsys):"""created_source is provenance: a oneshot run is stamped oneshot, not the cli it runs as."""diff --git a/tests/hermes_cli/test_sessions_source_local.py b/tests/hermes_cli/test_sessions_source_local.pyindex b9a167bf75e..d00365bacec 100644--- a/tests/hermes_cli/test_sessions_source_local.py+++ b/tests/hermes_cli/test_sessions_source_local.py@@ -40,3 +40,33 @@ def test_list_includes_a_compression_tip_whose_root_has_no_created_source(tmp_pa_cmd_stats(db, Namespace())assert "cli: 3 sessions" in capsys.readouterr().out # stats counts every segmentdb.close()+++def test_reader_on_a_read_only_store_from_before_the_column_and_the_runtime_tables(tmp_path):+ """A read-only open does not migrate. A store without ``created_source`` still counts its+ source=cli rows, and one without ``session_admissions`` still resolves ``-c`` by messages."""+ from hermes_cli.gateway_session_store import SurfaceLabelReader++ path = tmp_path / "old.db"+ writer = SessionDB(db_path=path)+ writer.create_session("legacy-cli", source="cli")+ writer.append_message("legacy-cli", role="user", content="hi")+ writer.create_session("legacy-stub", source="cli")+ with writer._lock:+ writer._conn.execute("UPDATE sessions SET started_at = started_at + 60 WHERE id = 'legacy-stub'")+ writer._conn.execute("DROP INDEX IF EXISTS idx_sessions_local_created_started")+ writer._conn.execute("ALTER TABLE sessions DROP COLUMN created_source")+ writer._conn.execute("DROP TABLE session_admissions")+ writer._conn.commit()+ writer.close()+ ro = SessionDB(db_path=path, read_only=True)+ try:+ reader = SurfaceLabelReader(ro)+ assert reader.session_count(source="cli") == 2+ assert [row["id"] for row in reader.search_sessions(source="cli", limit=1, skip_launch_stubs=True)] == [+ "legacy-cli"]+ tables = {row[0] for row in ro._conn.execute("SELECT name FROM sqlite_master WHERE type='table'")}+ columns = {row[1] for row in ro._conn.execute("PRAGMA table_info(sessions)")}+ assert "created_source" not in columns and "session_admissions" not in tables+ finally:+ ro.close()