Skip to content

The agent that grows with you

test(gateway): cover session-scoped /diff session and project skills (currently failing)

yoniebans0aba87e21771
diff --git a/tests/gateway/test_session_busy_controls.py b/tests/gateway/test_session_busy_controls.py
index 7b1d4f3501a..1f4e5d37c66 100644
--- a/tests/gateway/test_session_busy_controls.py
+++ b/tests/gateway/test_session_busy_controls.py
@@ -55,7 +55,7 @@ class CorrectionModel(BaseHTTPRequestHandler):
@contextmanager
-def owner(tmp_path):
+def owner(tmp_path, config=None):
root = Path(__file__).resolve().parents[2]
home, user = tmp_path / 'state', tmp_path / 'user'
home.mkdir(mode=0o700)
@@ -69,7 +69,7 @@ def owner(tmp_path):
(home / 'config.yaml').write_text(json.dumps({
'gateway': {'multiplex_profiles': False}, 'display': {'busy_input_mode': 'steer'},
'model': {'provider': 'custom', 'default': 'controls-fixture', 'base_url': url},
- 'auxiliary': {'title_generation': {'enabled': False}},
+ 'auxiliary': {'title_generation': {'enabled': False}}, **(config or {}),
}))
env = child_env()
env.update(HOME=str(user), USERPROFILE=str(user), HERMES_HOME=str(home), PYTHONPATH=str(root),
diff --git a/tests/gateway/test_session_commands_session_scope.py b/tests/gateway/test_session_commands_session_scope.py
new file mode 100644
index 00000000000..51b7d4bd032
--- /dev/null
+++ b/tests/gateway/test_session_commands_session_scope.py
@@ -0,0 +1,67 @@
+"""Slash commands and discovery on a local session resolve against THAT session: ``/diff session``
+through ``slash.exec`` follows its frozen checkpoint policy (``--checkpoints`` on a profile that leaves
+them off), and its repo's trusted project skills complete, list and dispatch (#134889 TUI-20, TUI-7)."""
+import asyncio
+import subprocess
+
+import pytest
+
+from tests.gateway.fixtures.local_recovery_probe import rpc, websocket
+from tests.gateway.test_session_busy_controls import owner
+from tests.gateway.test_session_tui_ops import _checkpoint, _git_rpc
+
+
+def _repo_with_skill(path):
+ skill = path / '.hermes' / 'skills' / 'repo-probe'
+ skill.mkdir(parents=True)
+ (skill / 'SKILL.md').write_text('---\nname: repo-probe\ndescription: Project skill fixture\n---\n# Repo probe\n')
+ (path / 'a.txt').write_text('original\n')
+ subprocess.run(['git', 'init', '-q', str(path)], check=True)
+ return path
+
+
+def test_slash_diff_session_follows_the_sessions_checkpoint_policy(tmp_path):
+ with owner(tmp_path) as (home, _peer, desc):
+ work = tmp_path / 'work'
+ work.mkdir()
+ (work / 'a.txt').write_text('original\n')
+
+ async def probe():
+ async with websocket(home, desc) as ws:
+ sid = (await rpc(ws, 'session.create', request_id='cp', source='tui', toolsets=[],
+ cwd=str(work), checkpoints=True))['result']['session_id']
+ plain = (await rpc(ws, 'session.create', request_id='plain', source='tui', toolsets=[],
+ cwd=str(work)))['result']['session_id']
+ await asyncio.to_thread(_checkpoint, home, work, 'before write_file')
+ (work / 'a.txt').write_text('edited\n')
+ diff = (await _git_rpc(ws, 'slash.exec', session_id=sid, command='diff session'))['result']
+ assert 'a.txt' in diff['output'] and '+edited' in diff['output'], diff
+ # The profile leaves checkpoints off: a session launched without the flag still says so.
+ off = (await _git_rpc(ws, 'slash.exec', session_id=plain, command='diff session'))['result']
+ assert 'a.txt' not in off['output'], off
+ asyncio.run(probe())
+
+
+def test_project_skills_follow_the_sessions_repo_in_discovery_and_dispatch(tmp_path):
+ repo = _repo_with_skill(tmp_path / 'repo')
+ with owner(tmp_path, {'skills': {'trusted_project_dirs': [str(repo)]}}) as (home, _peer, desc):
+ async def probe():
+ async with websocket(home, desc) as ws:
+ sid = (await rpc(ws, 'session.create', request_id='repo', source='tui', toolsets=[],
+ cwd=str(repo)))['result']['session_id']
+ other = (await rpc(ws, 'session.create', request_id='elsewhere', source='tui', toolsets=[],
+ cwd=str(tmp_path)))['result']['session_id']
+ catalog = await rpc(ws, 'commands.catalog', session_id=sid)
+ assert '/repo-probe' in catalog.get('result', {}).get('skills', {}), catalog
+ items = (await rpc(ws, 'complete.slash', session_id=sid, text='/repo-pr'))['result']['items']
+ assert any(item['text'].lstrip('/').startswith('repo-probe') for item in items), items
+ directive = (await rpc(ws, 'slash.exec', session_id=sid, command='repo-probe hello'))
+ assert directive.get('result', {}).get('type') == 'skill', directive
+ # A session in another directory never sees the repo's skill.
+ foreign = (await rpc(ws, 'commands.catalog', session_id=other))['result']
+ assert '/repo-probe' not in foreign['skills'], foreign['skills']
+ refused = await rpc(ws, 'slash.exec', session_id=other, command='repo-probe hello')
+ assert refused['error']['message'] == 'unsupported_command', refused
+ asyncio.run(probe())