@@ -42,29 +42,43 @@ def _write_transcript(path: Path, entries: list[dict]):
4242
4343def test_count_human_messages_basic (tmp_path ):
4444 transcript = tmp_path / "t.jsonl"
45- _write_transcript (transcript , [
46- {"message" : {"role" : "user" , "content" : "hello" }},
47- {"message" : {"role" : "assistant" , "content" : "hi" }},
48- {"message" : {"role" : "user" , "content" : "bye" }},
49- ])
45+ _write_transcript (
46+ transcript ,
47+ [
48+ {"message" : {"role" : "user" , "content" : "hello" }},
49+ {"message" : {"role" : "assistant" , "content" : "hi" }},
50+ {"message" : {"role" : "user" , "content" : "bye" }},
51+ ],
52+ )
5053 assert _count_human_messages (str (transcript )) == 2
5154
5255
5356def test_count_skips_command_messages (tmp_path ):
5457 transcript = tmp_path / "t.jsonl"
55- _write_transcript (transcript , [
56- {"message" : {"role" : "user" , "content" : "<command-message>status</command-message>" }},
57- {"message" : {"role" : "user" , "content" : "real question" }},
58- ])
58+ _write_transcript (
59+ transcript ,
60+ [
61+ {"message" : {"role" : "user" , "content" : "<command-message>status</command-message>" }},
62+ {"message" : {"role" : "user" , "content" : "real question" }},
63+ ],
64+ )
5965 assert _count_human_messages (str (transcript )) == 1
6066
6167
6268def test_count_handles_list_content (tmp_path ):
6369 transcript = tmp_path / "t.jsonl"
64- _write_transcript (transcript , [
65- {"message" : {"role" : "user" , "content" : [{"type" : "text" , "text" : "hello" }]}},
66- {"message" : {"role" : "user" , "content" : [{"type" : "text" , "text" : "<command-message>x</command-message>" }]}},
67- ])
70+ _write_transcript (
71+ transcript ,
72+ [
73+ {"message" : {"role" : "user" , "content" : [{"type" : "text" , "text" : "hello" }]}},
74+ {
75+ "message" : {
76+ "role" : "user" ,
77+ "content" : [{"type" : "text" , "text" : "<command-message>x</command-message>" }],
78+ }
79+ },
80+ ],
81+ )
6882 assert _count_human_messages (str (transcript )) == 1
6983
7084
@@ -90,6 +104,7 @@ def test_count_malformed_json_lines(tmp_path):
90104def _capture_hook_output (hook_fn , data , harness = "claude-code" , state_dir = None ):
91105 """Run a hook and capture its JSON stdout output."""
92106 import io
107+
93108 buf = io .StringIO ()
94109 patches = [patch ("mempalace.hooks_cli._output" , side_effect = lambda d : buf .write (json .dumps (d )))]
95110 if state_dir :
@@ -123,10 +138,10 @@ def test_stop_hook_passthrough_when_active_string(tmp_path):
123138
124139def test_stop_hook_passthrough_below_interval (tmp_path ):
125140 transcript = tmp_path / "t.jsonl"
126- _write_transcript (transcript , [
127- { "message" : { "role" : "user" , "content" : f"msg { i } " }}
128- for i in range (SAVE_INTERVAL - 1 )
129- ] )
141+ _write_transcript (
142+ transcript ,
143+ [{ "message" : { "role" : "user" , "content" : f"msg { i } " }} for i in range (SAVE_INTERVAL - 1 )],
144+ )
130145 result = _capture_hook_output (
131146 hook_stop ,
132147 {"session_id" : "test" , "stop_hook_active" : False , "transcript_path" : str (transcript )},
@@ -137,10 +152,10 @@ def test_stop_hook_passthrough_below_interval(tmp_path):
137152
138153def test_stop_hook_blocks_at_interval (tmp_path ):
139154 transcript = tmp_path / "t.jsonl"
140- _write_transcript (transcript , [
141- { "message" : { "role" : "user" , "content" : f"msg { i } " }}
142- for i in range (SAVE_INTERVAL )
143- ] )
155+ _write_transcript (
156+ transcript ,
157+ [{ "message" : { "role" : "user" , "content" : f"msg { i } " }} for i in range (SAVE_INTERVAL )],
158+ )
144159 result = _capture_hook_output (
145160 hook_stop ,
146161 {"session_id" : "test" , "stop_hook_active" : False , "transcript_path" : str (transcript )},
@@ -152,10 +167,10 @@ def test_stop_hook_blocks_at_interval(tmp_path):
152167
153168def test_stop_hook_tracks_save_point (tmp_path ):
154169 transcript = tmp_path / "t.jsonl"
155- _write_transcript (transcript , [
156- { "message" : { "role" : "user" , "content" : f"msg { i } " }}
157- for i in range (SAVE_INTERVAL )
158- ] )
170+ _write_transcript (
171+ transcript ,
172+ [{ "message" : { "role" : "user" , "content" : f"msg { i } " }} for i in range (SAVE_INTERVAL )],
173+ )
159174 data = {"session_id" : "test" , "stop_hook_active" : False , "transcript_path" : str (transcript )}
160175
161176 # First call blocks
0 commit comments