Skip to content

Commit 287a955

Browse files
committed
Fix: ruff format hooks_cli and test file
1 parent b33fd80 commit 287a955

2 files changed

Lines changed: 9 additions & 31 deletions

File tree

mempalace/hooks_cli.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,7 @@ def _count_human_messages(transcript_path: str) -> int:
6868
):
6969
continue
7070
text = " ".join(
71-
b.get("text", "")
72-
for b in content if isinstance(b, dict)
71+
b.get("text", "") for b in content if isinstance(b, dict)
7372
)
7473
if "<command-message>" in text:
7574
continue
@@ -164,9 +163,7 @@ def hook_stop(data: dict, harness: str):
164163

165164
since_last = exchange_count - last_save
166165

167-
_log(
168-
f"Session {session_id}: {exchange_count} exchanges, {since_last} since last save"
169-
)
166+
_log(f"Session {session_id}: {exchange_count} exchanges, {since_last} since last save")
170167

171168
if since_last >= SAVE_INTERVAL and exchange_count > 0:
172169
# Update last save point

tests/test_hooks_cli.py

Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,7 @@ def test_count_handles_list_content(tmp_path):
9191
{
9292
"message": {
9393
"role": "user",
94-
"content": [
95-
{"type": "text", "text": "<command-message>x</command-message>"}
96-
],
94+
"content": [{"type": "text", "text": "<command-message>x</command-message>"}],
9795
}
9896
},
9997
],
@@ -221,10 +219,7 @@ def test_stop_hook_passthrough_below_interval(tmp_path):
221219
transcript = tmp_path / "t.jsonl"
222220
_write_transcript(
223221
transcript,
224-
[
225-
{"message": {"role": "user", "content": f"msg {i}"}}
226-
for i in range(SAVE_INTERVAL - 1)
227-
],
222+
[{"message": {"role": "user", "content": f"msg {i}"}} for i in range(SAVE_INTERVAL - 1)],
228223
)
229224
result = _capture_hook_output(
230225
hook_stop,
@@ -242,10 +237,7 @@ def test_stop_hook_blocks_at_interval(tmp_path):
242237
transcript = tmp_path / "t.jsonl"
243238
_write_transcript(
244239
transcript,
245-
[
246-
{"message": {"role": "user", "content": f"msg {i}"}}
247-
for i in range(SAVE_INTERVAL)
248-
],
240+
[{"message": {"role": "user", "content": f"msg {i}"}} for i in range(SAVE_INTERVAL)],
249241
)
250242
result = _capture_hook_output(
251243
hook_stop,
@@ -264,10 +256,7 @@ def test_stop_hook_tracks_save_point(tmp_path):
264256
transcript = tmp_path / "t.jsonl"
265257
_write_transcript(
266258
transcript,
267-
[
268-
{"message": {"role": "user", "content": f"msg {i}"}}
269-
for i in range(SAVE_INTERVAL)
270-
],
259+
[{"message": {"role": "user", "content": f"msg {i}"}} for i in range(SAVE_INTERVAL)],
271260
)
272261
data = {
273262
"session_id": "test",
@@ -355,9 +344,7 @@ def test_maybe_auto_ingest_oserror(tmp_path):
355344
mempal_dir.mkdir()
356345
with patch.dict("os.environ", {"MEMPAL_DIR": str(mempal_dir)}):
357346
with patch("mempalace.hooks_cli.STATE_DIR", tmp_path):
358-
with patch(
359-
"mempalace.hooks_cli.subprocess.Popen", side_effect=OSError("fail")
360-
):
347+
with patch("mempalace.hooks_cli.subprocess.Popen", side_effect=OSError("fail")):
361348
_maybe_auto_ingest() # should not raise
362349

363350

@@ -392,10 +379,7 @@ def test_stop_hook_oserror_on_last_save_read(tmp_path):
392379
transcript = tmp_path / "t.jsonl"
393380
_write_transcript(
394381
transcript,
395-
[
396-
{"message": {"role": "user", "content": f"msg {i}"}}
397-
for i in range(SAVE_INTERVAL)
398-
],
382+
[{"message": {"role": "user", "content": f"msg {i}"}} for i in range(SAVE_INTERVAL)],
399383
)
400384
# Write invalid content to last save file
401385
(tmp_path / "test_last_save").write_text("not_a_number")
@@ -416,10 +400,7 @@ def test_stop_hook_oserror_on_write(tmp_path):
416400
transcript = tmp_path / "t.jsonl"
417401
_write_transcript(
418402
transcript,
419-
[
420-
{"message": {"role": "user", "content": f"msg {i}"}}
421-
for i in range(SAVE_INTERVAL)
422-
],
403+
[{"message": {"role": "user", "content": f"msg {i}"}} for i in range(SAVE_INTERVAL)],
423404
)
424405

425406
def bad_write_text(*args, **kwargs):

0 commit comments

Comments
 (0)