fix: ruff format test_hooks_cli.py and test_knowledge_graph.py
This commit is contained in:
+40
-25
@@ -42,29 +42,43 @@ def _write_transcript(path: Path, entries: list[dict]):
|
|||||||
|
|
||||||
def test_count_human_messages_basic(tmp_path):
|
def test_count_human_messages_basic(tmp_path):
|
||||||
transcript = tmp_path / "t.jsonl"
|
transcript = tmp_path / "t.jsonl"
|
||||||
_write_transcript(transcript, [
|
_write_transcript(
|
||||||
{"message": {"role": "user", "content": "hello"}},
|
transcript,
|
||||||
{"message": {"role": "assistant", "content": "hi"}},
|
[
|
||||||
{"message": {"role": "user", "content": "bye"}},
|
{"message": {"role": "user", "content": "hello"}},
|
||||||
])
|
{"message": {"role": "assistant", "content": "hi"}},
|
||||||
|
{"message": {"role": "user", "content": "bye"}},
|
||||||
|
],
|
||||||
|
)
|
||||||
assert _count_human_messages(str(transcript)) == 2
|
assert _count_human_messages(str(transcript)) == 2
|
||||||
|
|
||||||
|
|
||||||
def test_count_skips_command_messages(tmp_path):
|
def test_count_skips_command_messages(tmp_path):
|
||||||
transcript = tmp_path / "t.jsonl"
|
transcript = tmp_path / "t.jsonl"
|
||||||
_write_transcript(transcript, [
|
_write_transcript(
|
||||||
{"message": {"role": "user", "content": "<command-message>status</command-message>"}},
|
transcript,
|
||||||
{"message": {"role": "user", "content": "real question"}},
|
[
|
||||||
])
|
{"message": {"role": "user", "content": "<command-message>status</command-message>"}},
|
||||||
|
{"message": {"role": "user", "content": "real question"}},
|
||||||
|
],
|
||||||
|
)
|
||||||
assert _count_human_messages(str(transcript)) == 1
|
assert _count_human_messages(str(transcript)) == 1
|
||||||
|
|
||||||
|
|
||||||
def test_count_handles_list_content(tmp_path):
|
def test_count_handles_list_content(tmp_path):
|
||||||
transcript = tmp_path / "t.jsonl"
|
transcript = tmp_path / "t.jsonl"
|
||||||
_write_transcript(transcript, [
|
_write_transcript(
|
||||||
{"message": {"role": "user", "content": [{"type": "text", "text": "hello"}]}},
|
transcript,
|
||||||
{"message": {"role": "user", "content": [{"type": "text", "text": "<command-message>x</command-message>"}]}},
|
[
|
||||||
])
|
{"message": {"role": "user", "content": [{"type": "text", "text": "hello"}]}},
|
||||||
|
{
|
||||||
|
"message": {
|
||||||
|
"role": "user",
|
||||||
|
"content": [{"type": "text", "text": "<command-message>x</command-message>"}],
|
||||||
|
}
|
||||||
|
},
|
||||||
|
],
|
||||||
|
)
|
||||||
assert _count_human_messages(str(transcript)) == 1
|
assert _count_human_messages(str(transcript)) == 1
|
||||||
|
|
||||||
|
|
||||||
@@ -90,6 +104,7 @@ def test_count_malformed_json_lines(tmp_path):
|
|||||||
def _capture_hook_output(hook_fn, data, harness="claude-code", state_dir=None):
|
def _capture_hook_output(hook_fn, data, harness="claude-code", state_dir=None):
|
||||||
"""Run a hook and capture its JSON stdout output."""
|
"""Run a hook and capture its JSON stdout output."""
|
||||||
import io
|
import io
|
||||||
|
|
||||||
buf = io.StringIO()
|
buf = io.StringIO()
|
||||||
patches = [patch("mempalace.hooks_cli._output", side_effect=lambda d: buf.write(json.dumps(d)))]
|
patches = [patch("mempalace.hooks_cli._output", side_effect=lambda d: buf.write(json.dumps(d)))]
|
||||||
if state_dir:
|
if state_dir:
|
||||||
@@ -123,10 +138,10 @@ def test_stop_hook_passthrough_when_active_string(tmp_path):
|
|||||||
|
|
||||||
def test_stop_hook_passthrough_below_interval(tmp_path):
|
def test_stop_hook_passthrough_below_interval(tmp_path):
|
||||||
transcript = tmp_path / "t.jsonl"
|
transcript = tmp_path / "t.jsonl"
|
||||||
_write_transcript(transcript, [
|
_write_transcript(
|
||||||
{"message": {"role": "user", "content": f"msg {i}"}}
|
transcript,
|
||||||
for i in range(SAVE_INTERVAL - 1)
|
[{"message": {"role": "user", "content": f"msg {i}"}} for i in range(SAVE_INTERVAL - 1)],
|
||||||
])
|
)
|
||||||
result = _capture_hook_output(
|
result = _capture_hook_output(
|
||||||
hook_stop,
|
hook_stop,
|
||||||
{"session_id": "test", "stop_hook_active": False, "transcript_path": str(transcript)},
|
{"session_id": "test", "stop_hook_active": False, "transcript_path": str(transcript)},
|
||||||
@@ -137,10 +152,10 @@ def test_stop_hook_passthrough_below_interval(tmp_path):
|
|||||||
|
|
||||||
def test_stop_hook_blocks_at_interval(tmp_path):
|
def test_stop_hook_blocks_at_interval(tmp_path):
|
||||||
transcript = tmp_path / "t.jsonl"
|
transcript = tmp_path / "t.jsonl"
|
||||||
_write_transcript(transcript, [
|
_write_transcript(
|
||||||
{"message": {"role": "user", "content": f"msg {i}"}}
|
transcript,
|
||||||
for i in range(SAVE_INTERVAL)
|
[{"message": {"role": "user", "content": f"msg {i}"}} for i in range(SAVE_INTERVAL)],
|
||||||
])
|
)
|
||||||
result = _capture_hook_output(
|
result = _capture_hook_output(
|
||||||
hook_stop,
|
hook_stop,
|
||||||
{"session_id": "test", "stop_hook_active": False, "transcript_path": str(transcript)},
|
{"session_id": "test", "stop_hook_active": False, "transcript_path": str(transcript)},
|
||||||
@@ -152,10 +167,10 @@ def test_stop_hook_blocks_at_interval(tmp_path):
|
|||||||
|
|
||||||
def test_stop_hook_tracks_save_point(tmp_path):
|
def test_stop_hook_tracks_save_point(tmp_path):
|
||||||
transcript = tmp_path / "t.jsonl"
|
transcript = tmp_path / "t.jsonl"
|
||||||
_write_transcript(transcript, [
|
_write_transcript(
|
||||||
{"message": {"role": "user", "content": f"msg {i}"}}
|
transcript,
|
||||||
for i in range(SAVE_INTERVAL)
|
[{"message": {"role": "user", "content": f"msg {i}"}} for i in range(SAVE_INTERVAL)],
|
||||||
])
|
)
|
||||||
data = {"session_id": "test", "stop_hook_active": False, "transcript_path": str(transcript)}
|
data = {"session_id": "test", "stop_hook_active": False, "transcript_path": str(transcript)}
|
||||||
|
|
||||||
# First call blocks
|
# First call blocks
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ timeline, stats, and edge cases (duplicate triples, ID collisions).
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class TestEntityOperations:
|
class TestEntityOperations:
|
||||||
def test_add_entity(self, kg):
|
def test_add_entity(self, kg):
|
||||||
eid = kg.add_entity("Alice", entity_type="person")
|
eid = kg.add_entity("Alice", entity_type="person")
|
||||||
@@ -125,6 +124,7 @@ class TestWALMode:
|
|||||||
conn.close()
|
conn.close()
|
||||||
assert mode == "wal"
|
assert mode == "wal"
|
||||||
|
|
||||||
|
|
||||||
class TestStats:
|
class TestStats:
|
||||||
def test_stats_empty(self, kg):
|
def test_stats_empty(self, kg):
|
||||||
stats = kg.stats()
|
stats = kg.stats()
|
||||||
|
|||||||
Reference in New Issue
Block a user