aboutsummaryrefslogtreecommitdiff
path: root/scripts/test_hermes_integration_asset.py
blob: f3778214401ee0c535a78a77f8dda7fc56d568fd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import importlib.util
import unittest
from pathlib import Path


ASSET = Path(__file__).parents[1] / "src/integration/assets/hermes/__init__.py"


def load_asset():
    spec = importlib.util.spec_from_file_location("herdr_hermes_integration", ASSET)
    if spec is None or spec.loader is None:
        raise RuntimeError("could not load Hermes integration asset")
    module = importlib.util.module_from_spec(spec)
    spec.loader.exec_module(module)
    return module


class FakeContext:
    def __init__(self):
        self.hooks = {}

    def register_hook(self, name, callback):
        self.hooks[name] = callback


class HermesIntegrationAssetTests(unittest.TestCase):
    def test_reports_only_root_session_identity(self):
        module = load_asset()
        calls = []
        module._send = lambda method, params: calls.append((method, params))
        context = FakeContext()
        module.register(context)

        self.assertEqual(
            set(context.hooks),
            {"on_session_start", "on_session_reset", "pre_llm_call"},
        )

        context.hooks["on_session_start"](session_id="root-1", platform="tui")
        context.hooks["pre_llm_call"](session_id="root-1", platform="tui")
        context.hooks["pre_llm_call"](session_id="child", platform="subagent")
        context.hooks["on_session_reset"](session_id="root-2", platform="tui")
        context.hooks["pre_llm_call"](
            session_id="background", platform="tui"
        )

        self.assertEqual(
            calls,
            [
                (
                    "pane.report_agent_session",
                    {
                        "agent_session_id": "root-1",
                        "session_start_source": "startup",
                    },
                ),
                (
                    "pane.report_agent_session",
                    {
                        "agent_session_id": "root-2",
                        "session_start_source": "new",
                    },
                ),
            ],
        )

    def test_first_turn_recovers_resumed_session_identity(self):
        module = load_asset()
        calls = []
        module._send = lambda method, params: calls.append((method, params))
        context = FakeContext()
        module.register(context)

        context.hooks["pre_llm_call"](session_id="resumed", platform="cli")

        self.assertEqual(
            calls,
            [
                (
                    "pane.report_agent_session",
                    {
                        "agent_session_id": "resumed",
                        "session_start_source": "resume",
                    },
                )
            ],
        )

if __name__ == "__main__":
    unittest.main()