elliot-stack 1.0.39 → 1.0.41
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/skills/estack-migrate-claude-session-history/SKILL.md +3 -2
- package/skills/estack-migrate-claude-session-history/scripts/__pycache__/validate-migration.cpython-313.pyc +0 -0
- package/skills/estack-read-claude-session-history/SKILL.md +34 -3
- package/skills/estack-read-claude-session-history/references/modes.md +53 -7
- package/skills/estack-read-claude-session-history/references/recipes.md +7 -1
- package/skills/estack-read-claude-session-history/scripts/__pycache__/read_transcript.cpython-313.pyc +0 -0
- package/skills/estack-read-claude-session-history/scripts/lib/__pycache__/__init__.cpython-313.pyc +0 -0
- package/skills/estack-read-claude-session-history/scripts/lib/__pycache__/parser.cpython-313.pyc +0 -0
- package/skills/estack-read-claude-session-history/scripts/lib/__pycache__/paths.cpython-313.pyc +0 -0
- package/skills/estack-read-claude-session-history/scripts/lib/__pycache__/search.cpython-313.pyc +0 -0
- package/skills/estack-read-claude-session-history/scripts/lib/__pycache__/subagents.cpython-313.pyc +0 -0
- package/skills/estack-read-claude-session-history/scripts/lib/__pycache__/tools.cpython-313.pyc +0 -0
- package/skills/estack-read-claude-session-history/scripts/read_transcript.py +163 -20
- package/skills/estack-migrate-claude-session-history/scripts/test-append-note.js +0 -48
- package/skills/estack-migrate-claude-session-history/scripts/test-validate-migration.py +0 -326
- package/skills/estack-read-claude-session-history/scripts/tests/conftest.py +0 -40
- package/skills/estack-read-claude-session-history/scripts/tests/fixtures/README.md +0 -20
- package/skills/estack-read-claude-session-history/scripts/tests/fixtures/all-noise.jsonl +0 -4
- package/skills/estack-read-claude-session-history/scripts/tests/fixtures/basic-session.jsonl +0 -2
- package/skills/estack-read-claude-session-history/scripts/tests/fixtures/engagement-gaps.jsonl +0 -9
- package/skills/estack-read-claude-session-history/scripts/tests/fixtures/engagement-noise.jsonl +0 -7
- package/skills/estack-read-claude-session-history/scripts/tests/fixtures/engagement-parallel-a.jsonl +0 -3
- package/skills/estack-read-claude-session-history/scripts/tests/fixtures/engagement-parallel-b.jsonl +0 -3
- package/skills/estack-read-claude-session-history/scripts/tests/fixtures/engagement-waiting.jsonl +0 -5
- package/skills/estack-read-claude-session-history/scripts/tests/fixtures/interrupted.jsonl +0 -2
- package/skills/estack-read-claude-session-history/scripts/tests/fixtures/multi-compact.jsonl +0 -8
- package/skills/estack-read-claude-session-history/scripts/tests/fixtures/pending-user.jsonl +0 -2
- package/skills/estack-read-claude-session-history/scripts/tests/fixtures/subagent-no-meta/subagents/agent-aaa.jsonl +0 -2
- package/skills/estack-read-claude-session-history/scripts/tests/fixtures/subagent-no-meta.jsonl +0 -2
- package/skills/estack-read-claude-session-history/scripts/tests/fixtures/subagent-parent/subagents/agent-xyz123.jsonl +0 -2
- package/skills/estack-read-claude-session-history/scripts/tests/fixtures/subagent-parent/subagents/agent-xyz123.meta.json +0 -1
- package/skills/estack-read-claude-session-history/scripts/tests/fixtures/subagent-parent.jsonl +0 -4
- package/skills/estack-read-claude-session-history/scripts/tests/fixtures/time-spread.jsonl +0 -6
- package/skills/estack-read-claude-session-history/scripts/tests/fixtures/timeline-day-test.jsonl +0 -5
- package/skills/estack-read-claude-session-history/scripts/tests/fixtures/tool-usage-parent/subagents/agent-sub1.jsonl +0 -3
- package/skills/estack-read-claude-session-history/scripts/tests/fixtures/tool-usage-parent.jsonl +0 -3
- package/skills/estack-read-claude-session-history/scripts/tests/fixtures/tool-zoo.jsonl +0 -10
- package/skills/estack-read-claude-session-history/scripts/tests/fixtures/truncated.jsonl +0 -3
- package/skills/estack-read-claude-session-history/scripts/tests/fixtures/unicode.jsonl +0 -2
- package/skills/estack-read-claude-session-history/scripts/tests/fixtures/with-advisor.jsonl +0 -3
- package/skills/estack-read-claude-session-history/scripts/tests/fixtures/with-compact.jsonl +0 -5
- package/skills/estack-read-claude-session-history/scripts/tests/fixtures/with-thinking.jsonl +0 -2
- package/skills/estack-read-claude-session-history/scripts/tests/test_backup_roots.py +0 -56
- package/skills/estack-read-claude-session-history/scripts/tests/test_engagement.py +0 -239
- package/skills/estack-read-claude-session-history/scripts/tests/test_json_format.py +0 -201
- package/skills/estack-read-claude-session-history/scripts/tests/test_modes.py +0 -323
- package/skills/estack-read-claude-session-history/scripts/tests/test_parser.py +0 -204
- package/skills/estack-read-claude-session-history/scripts/tests/test_paths.py +0 -133
- package/skills/estack-read-claude-session-history/scripts/tests/test_search.py +0 -94
- package/skills/estack-read-claude-session-history/scripts/tests/test_search_output.py +0 -161
- package/skills/estack-read-claude-session-history/scripts/tests/test_subagents.py +0 -43
- package/skills/estack-read-claude-session-history/scripts/tests/test_timeline.py +0 -179
- package/skills/estack-read-claude-session-history/scripts/tests/test_timezone_and_project.py +0 -225
- package/skills/estack-read-claude-session-history/scripts/tests/test_tools.py +0 -80
|
@@ -1,323 +0,0 @@
|
|
|
1
|
-
"""End-to-end CLI tests via subprocess.run.
|
|
2
|
-
|
|
3
|
-
Exercises mode dispatch + argument parsing. Library-level behavior is
|
|
4
|
-
covered by the unit tests in test_paths/parser/tools/search/subagents.
|
|
5
|
-
"""
|
|
6
|
-
|
|
7
|
-
import json
|
|
8
|
-
import os
|
|
9
|
-
import shutil
|
|
10
|
-
import subprocess
|
|
11
|
-
import sys
|
|
12
|
-
from pathlib import Path
|
|
13
|
-
|
|
14
|
-
import pytest
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
def _run_cli(cli_path, *args, env_overrides=None):
|
|
18
|
-
env = dict(os.environ)
|
|
19
|
-
env["PYTHONIOENCODING"] = "utf-8"
|
|
20
|
-
if env_overrides:
|
|
21
|
-
env.update(env_overrides)
|
|
22
|
-
return subprocess.run(
|
|
23
|
-
[sys.executable, str(cli_path), *args],
|
|
24
|
-
capture_output=True,
|
|
25
|
-
text=True,
|
|
26
|
-
encoding="utf-8",
|
|
27
|
-
env=env,
|
|
28
|
-
)
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
def test_help(cli_path):
|
|
32
|
-
r = _run_cli(cli_path, "--help")
|
|
33
|
-
assert r.returncode == 0
|
|
34
|
-
assert "--mode" in r.stdout
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
def test_last_mode(cli_path, fixtures_dir):
|
|
38
|
-
r = _run_cli(cli_path, "--file", str(fixtures_dir / "basic-session.jsonl"), "--mode", "last")
|
|
39
|
-
assert r.returncode == 0
|
|
40
|
-
assert "Here is help" in r.stdout
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
def test_advisor_mode(cli_path, fixtures_dir):
|
|
44
|
-
r = _run_cli(cli_path, "--file", str(fixtures_dir / "with-advisor.jsonl"), "--mode", "advisor")
|
|
45
|
-
assert r.returncode == 0
|
|
46
|
-
assert "advisor" in r.stdout.lower()
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
def test_pre_compact_mode(cli_path, fixtures_dir):
|
|
50
|
-
r = _run_cli(cli_path, "--file", str(fixtures_dir / "with-compact.jsonl"), "--mode", "pre-compact")
|
|
51
|
-
assert r.returncode == 0
|
|
52
|
-
assert "Pre-compact" in r.stdout or "First answer" in r.stdout
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
def test_debug_mode(cli_path, fixtures_dir):
|
|
56
|
-
r = _run_cli(cli_path, "--file", str(fixtures_dir / "basic-session.jsonl"), "--mode", "debug")
|
|
57
|
-
assert r.returncode == 0
|
|
58
|
-
assert "Entry type distribution" in r.stdout
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
def test_brief_mode(cli_path, fixtures_dir):
|
|
62
|
-
r = _run_cli(cli_path, "--file", str(fixtures_dir / "tool-zoo.jsonl"), "--mode", "brief")
|
|
63
|
-
assert r.returncode == 0
|
|
64
|
-
body = r.stdout
|
|
65
|
-
# 6 lines expected
|
|
66
|
-
assert "intent:" in body
|
|
67
|
-
assert "last:" in body
|
|
68
|
-
assert "edits:" in body
|
|
69
|
-
assert "tools:" in body
|
|
70
|
-
assert "subagents:" in body
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
def test_brief_with_include_subagents(cli_path, fixtures_dir):
|
|
74
|
-
r = _run_cli(
|
|
75
|
-
cli_path, "--file", str(fixtures_dir / "subagent-parent.jsonl"),
|
|
76
|
-
"--mode", "brief", "--include-subagents",
|
|
77
|
-
)
|
|
78
|
-
assert r.returncode == 0
|
|
79
|
-
assert "subagent" in r.stdout.lower()
|
|
80
|
-
assert "Found it" in r.stdout
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
def test_changelog(cli_path, fixtures_dir):
|
|
84
|
-
r = _run_cli(cli_path, "--file", str(fixtures_dir / "tool-zoo.jsonl"), "--mode", "changelog")
|
|
85
|
-
assert r.returncode == 0
|
|
86
|
-
assert "Bash" in r.stdout
|
|
87
|
-
assert "Read" in r.stdout
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
def test_file_edits(cli_path, fixtures_dir):
|
|
91
|
-
r = _run_cli(cli_path, "--file", str(fixtures_dir / "tool-zoo.jsonl"), "--mode", "file-edits")
|
|
92
|
-
assert r.returncode == 0
|
|
93
|
-
assert "foo.py" in r.stdout
|
|
94
|
-
assert "bar.py" in r.stdout
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
def test_tool_calls(cli_path, fixtures_dir):
|
|
98
|
-
r = _run_cli(cli_path, "--file", str(fixtures_dir / "tool-zoo.jsonl"), "--mode", "tool-calls")
|
|
99
|
-
assert r.returncode == 0
|
|
100
|
-
assert "Bash" in r.stdout
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
def test_tool_calls_filter(cli_path, fixtures_dir):
|
|
104
|
-
r = _run_cli(
|
|
105
|
-
cli_path, "--file", str(fixtures_dir / "tool-zoo.jsonl"),
|
|
106
|
-
"--mode", "tool-calls", "--tool", "Bash",
|
|
107
|
-
)
|
|
108
|
-
assert r.returncode == 0
|
|
109
|
-
assert "Bash" in r.stdout
|
|
110
|
-
assert "Glob" not in r.stdout
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
def test_tool_usage_file(cli_path, fixtures_dir):
|
|
114
|
-
r = _run_cli(cli_path, "--file", str(fixtures_dir / "tool-zoo.jsonl"), "--mode", "tool-usage")
|
|
115
|
-
assert r.returncode == 0
|
|
116
|
-
assert "Tool calls" in r.stdout
|
|
117
|
-
assert "Bash" in r.stdout
|
|
118
|
-
assert "Skill" in r.stdout
|
|
119
|
-
# Skill calls are sub-tallied by the actual skill name (input.skill).
|
|
120
|
-
assert "using-superpowers" in r.stdout
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
def test_tool_usage_skill_filter(cli_path, fixtures_dir):
|
|
124
|
-
r = _run_cli(
|
|
125
|
-
cli_path, "--file", str(fixtures_dir / "tool-zoo.jsonl"),
|
|
126
|
-
"--mode", "tool-usage", "--tool", "Skill",
|
|
127
|
-
)
|
|
128
|
-
assert r.returncode == 0
|
|
129
|
-
assert "Skill" in r.stdout
|
|
130
|
-
assert "using-superpowers" in r.stdout
|
|
131
|
-
# Filtering to Skill must drop every other tool.
|
|
132
|
-
assert "Bash" not in r.stdout
|
|
133
|
-
assert "Glob" not in r.stdout
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
def test_tool_usage_json(cli_path, fixtures_dir):
|
|
137
|
-
r = _run_cli(
|
|
138
|
-
cli_path, "--file", str(fixtures_dir / "tool-zoo.jsonl"),
|
|
139
|
-
"--mode", "tool-usage", "--format", "json",
|
|
140
|
-
)
|
|
141
|
-
assert r.returncode == 0
|
|
142
|
-
data = json.loads(r.stdout)
|
|
143
|
-
assert data["total"] == 9
|
|
144
|
-
assert data["sessions"] == 1
|
|
145
|
-
tools = {t["tool"]: t["count"] for t in data["tools"]}
|
|
146
|
-
assert tools["Skill"] == 1
|
|
147
|
-
assert tools["Bash"] == 1
|
|
148
|
-
skills = {s["skill"]: s["count"] for s in data["skills"]}
|
|
149
|
-
assert skills == {"using-superpowers": 1}
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
def test_tool_usage_scope_aggregates(cli_path, fixtures_dir, tmp_path):
|
|
153
|
-
# Two sessions in one project → counts add up across files.
|
|
154
|
-
fake_root = tmp_path / "projects"
|
|
155
|
-
fake_proj = fake_root / "C--fake-proj"
|
|
156
|
-
fake_proj.mkdir(parents=True)
|
|
157
|
-
shutil.copy(fixtures_dir / "tool-zoo.jsonl", fake_proj / "a.jsonl")
|
|
158
|
-
shutil.copy(fixtures_dir / "tool-zoo.jsonl", fake_proj / "b.jsonl")
|
|
159
|
-
r = _run_cli(
|
|
160
|
-
cli_path, "--root", str(fake_root), "--cwd", "C:\\fake\\proj",
|
|
161
|
-
"--mode", "tool-usage", "--format", "json",
|
|
162
|
-
)
|
|
163
|
-
assert r.returncode == 0
|
|
164
|
-
data = json.loads(r.stdout)
|
|
165
|
-
assert data["sessions"] == 2
|
|
166
|
-
assert data["total"] == 18
|
|
167
|
-
skills = {s["skill"]: s["count"] for s in data["skills"]}
|
|
168
|
-
assert skills == {"using-superpowers": 2}
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
def test_tool_usage_missing_file(cli_path, tmp_path):
|
|
172
|
-
r = _run_cli(cli_path, "--file", str(tmp_path / "nope.jsonl"), "--mode", "tool-usage")
|
|
173
|
-
assert r.returncode == 1
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
def test_tool_usage_until_keeps_in_window_calls(cli_path, fixtures_dir, tmp_path):
|
|
177
|
-
# The tool-zoo calls are stamped 2026-05-01T10:00:0x. Copy the fixture, then
|
|
178
|
-
# bump its mtime far past --until. A naive mtime filter would drop the file
|
|
179
|
-
# and report zero; per-call timestamp filtering must still count the calls.
|
|
180
|
-
import os
|
|
181
|
-
fake_root = tmp_path / "projects"
|
|
182
|
-
fake_proj = fake_root / "C--fake-proj"
|
|
183
|
-
fake_proj.mkdir(parents=True)
|
|
184
|
-
target = fake_proj / "a.jsonl"
|
|
185
|
-
shutil.copy(fixtures_dir / "tool-zoo.jsonl", target)
|
|
186
|
-
future = 1_900_000_000 # ~2030, well after the --until bound below
|
|
187
|
-
os.utime(target, (future, future))
|
|
188
|
-
r = _run_cli(
|
|
189
|
-
cli_path, "--root", str(fake_root), "--cwd", "C:\\fake\\proj",
|
|
190
|
-
"--mode", "tool-usage", "--until", "2026-05-02", "--format", "json",
|
|
191
|
-
)
|
|
192
|
-
assert r.returncode == 0
|
|
193
|
-
data = json.loads(r.stdout)
|
|
194
|
-
assert data["total"] == 9, data # all 9 calls are inside the window
|
|
195
|
-
assert data["sessions"] == 1
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
def test_tool_usage_exclude_current_drops_session(cli_path, fixtures_dir, tmp_path):
|
|
199
|
-
fake_root = tmp_path / "projects"
|
|
200
|
-
fake_proj = fake_root / "C--fake-proj"
|
|
201
|
-
fake_proj.mkdir(parents=True)
|
|
202
|
-
shutil.copy(fixtures_dir / "tool-zoo.jsonl", fake_proj / "cur.jsonl")
|
|
203
|
-
shutil.copy(fixtures_dir / "tool-zoo.jsonl", fake_proj / "other.jsonl")
|
|
204
|
-
# Without exclusion: 2 sessions, 18 calls. Excluding "cur" leaves 1 session, 9.
|
|
205
|
-
r = _run_cli(
|
|
206
|
-
cli_path, "--root", str(fake_root), "--cwd", "C:\\fake\\proj",
|
|
207
|
-
"--mode", "tool-usage", "--exclude-current", "--format", "json",
|
|
208
|
-
env_overrides={"CLAUDE_SESSION_ID": "cur"},
|
|
209
|
-
)
|
|
210
|
-
assert r.returncode == 0
|
|
211
|
-
data = json.loads(r.stdout)
|
|
212
|
-
assert data["sessions"] == 1
|
|
213
|
-
assert data["total"] == 9
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
def test_tool_usage_include_subagents(cli_path, fixtures_dir):
|
|
217
|
-
# Parent calls: Skill(commit) + Agent. Subagent calls: Skill(estack-repo-search) + Bash.
|
|
218
|
-
# --include-subagents must fold the subagent's calls in, without counting the
|
|
219
|
-
# subagent as its own session.
|
|
220
|
-
parent = fixtures_dir / "tool-usage-parent.jsonl"
|
|
221
|
-
without = json.loads(_run_cli(
|
|
222
|
-
cli_path, "--file", str(parent), "--mode", "tool-usage", "--format", "json",
|
|
223
|
-
).stdout)
|
|
224
|
-
assert without["total"] == 2
|
|
225
|
-
assert without["sessions"] == 1
|
|
226
|
-
assert {s["skill"] for s in without["skills"]} == {"commit"}
|
|
227
|
-
|
|
228
|
-
with_sub = json.loads(_run_cli(
|
|
229
|
-
cli_path, "--file", str(parent), "--mode", "tool-usage",
|
|
230
|
-
"--include-subagents", "--format", "json",
|
|
231
|
-
).stdout)
|
|
232
|
-
assert with_sub["total"] == 4 # +Skill(estack-repo-search) +Bash
|
|
233
|
-
assert with_sub["sessions"] == 1 # subagent is not a separate session
|
|
234
|
-
assert {s["skill"] for s in with_sub["skills"]} == {"commit", "estack-repo-search"}
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
def test_subagent_list(cli_path, fixtures_dir):
|
|
238
|
-
r = _run_cli(
|
|
239
|
-
cli_path, "--file", str(fixtures_dir / "subagent-parent.jsonl"),
|
|
240
|
-
"--mode", "subagent-list",
|
|
241
|
-
)
|
|
242
|
-
assert r.returncode == 0
|
|
243
|
-
assert "agent-xyz123" in r.stdout
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
def test_subagent_finals(cli_path, fixtures_dir):
|
|
247
|
-
r = _run_cli(
|
|
248
|
-
cli_path, "--file", str(fixtures_dir / "subagent-parent.jsonl"),
|
|
249
|
-
"--mode", "subagent-finals",
|
|
250
|
-
)
|
|
251
|
-
assert r.returncode == 0
|
|
252
|
-
assert "Found it" in r.stdout
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
def test_diff_mode(cli_path, fixtures_dir):
|
|
256
|
-
r = _run_cli(
|
|
257
|
-
cli_path, "--mode", "diff",
|
|
258
|
-
"--file-a", str(fixtures_dir / "basic-session.jsonl"),
|
|
259
|
-
"--file-b", str(fixtures_dir / "with-thinking.jsonl"),
|
|
260
|
-
)
|
|
261
|
-
assert r.returncode == 0
|
|
262
|
-
assert "A>" in r.stdout
|
|
263
|
-
assert "B>" in r.stdout
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
def test_lookup_no_match(cli_path, fixtures_dir, tmp_path):
|
|
267
|
-
# Point --root at an empty dir so lookup definitely misses
|
|
268
|
-
r = _run_cli(cli_path, "--root", str(tmp_path), "--mode", "lookup", "--uuid", "nope")
|
|
269
|
-
assert r.returncode == 1
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
def test_list_legacy_format(cli_path, fixtures_dir, tmp_path):
|
|
273
|
-
# Build a fake project root + cwd that matches encoding
|
|
274
|
-
fake_root = tmp_path / "projects"
|
|
275
|
-
fake_proj = fake_root / "C--fake-proj"
|
|
276
|
-
fake_proj.mkdir(parents=True)
|
|
277
|
-
shutil.copy(fixtures_dir / "basic-session.jsonl", fake_proj / "abc.jsonl")
|
|
278
|
-
r = _run_cli(cli_path, "--root", str(fake_root), "--cwd", "C:\\fake\\proj", "--list")
|
|
279
|
-
assert r.returncode == 0
|
|
280
|
-
assert "abc.jsonl" in r.stdout
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
def test_exclude_current(cli_path, fixtures_dir, tmp_path):
|
|
284
|
-
fake_root = tmp_path / "projects"
|
|
285
|
-
fake_proj = fake_root / "C--fake-proj"
|
|
286
|
-
fake_proj.mkdir(parents=True)
|
|
287
|
-
shutil.copy(fixtures_dir / "basic-session.jsonl", fake_proj / "abc.jsonl")
|
|
288
|
-
shutil.copy(fixtures_dir / "tool-zoo.jsonl", fake_proj / "def.jsonl")
|
|
289
|
-
r = _run_cli(
|
|
290
|
-
cli_path, "--root", str(fake_root), "--cwd", "C:\\fake\\proj",
|
|
291
|
-
"--mode", "list", "--exclude-current",
|
|
292
|
-
env_overrides={"CLAUDE_SESSION_ID": "abc"},
|
|
293
|
-
)
|
|
294
|
-
assert r.returncode == 0
|
|
295
|
-
assert "def" in r.stdout
|
|
296
|
-
assert "abc" not in r.stdout
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
def test_dump_large_file_degrades(cli_path, fixtures_dir, tmp_path):
|
|
300
|
-
# Build a 6MB padded fixture by writing many valid lines
|
|
301
|
-
big = tmp_path / "big.jsonl"
|
|
302
|
-
line = '{"type":"user","timestamp":"2026-05-01T10:00:00Z","message":{"role":"user","content":"'
|
|
303
|
-
pad = "x" * 1000 + '"}}\n'
|
|
304
|
-
with open(big, "w", encoding="utf-8") as f:
|
|
305
|
-
# Each line ~1KB → write ~7000 to hit 6MB+
|
|
306
|
-
for _ in range(7000):
|
|
307
|
-
f.write(line + pad)
|
|
308
|
-
r = _run_cli(cli_path, "--file", str(big), "--mode", "dump")
|
|
309
|
-
assert r.returncode == 0
|
|
310
|
-
assert "degraded" in r.stderr.lower()
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
def test_dump_large_file_force(cli_path, tmp_path):
|
|
314
|
-
big = tmp_path / "big.jsonl"
|
|
315
|
-
line = '{"type":"user","timestamp":"2026-05-01T10:00:00Z","message":{"role":"user","content":"'
|
|
316
|
-
pad = "x" * 1000 + '"}}\n'
|
|
317
|
-
with open(big, "w", encoding="utf-8") as f:
|
|
318
|
-
for _ in range(7000):
|
|
319
|
-
f.write(line + pad)
|
|
320
|
-
r = _run_cli(cli_path, "--file", str(big), "--mode", "dump", "--force-dump")
|
|
321
|
-
assert r.returncode == 0
|
|
322
|
-
# No degrade note when forced
|
|
323
|
-
assert "degraded" not in r.stderr.lower()
|
|
@@ -1,204 +0,0 @@
|
|
|
1
|
-
"""Tests for lib.parser."""
|
|
2
|
-
|
|
3
|
-
import json
|
|
4
|
-
from datetime import datetime, timedelta
|
|
5
|
-
from pathlib import Path
|
|
6
|
-
|
|
7
|
-
import pytest
|
|
8
|
-
|
|
9
|
-
from lib import parser as PR
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
def _load(fixtures_dir, name):
|
|
13
|
-
return PR.parse_lines(fixtures_dir / name)
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
def test_parse_basic(fixtures_dir):
|
|
17
|
-
lines = _load(fixtures_dir, "basic-session.jsonl")
|
|
18
|
-
assert len(lines) == 2
|
|
19
|
-
assert lines[0]["type"] == "user"
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
def test_get_messages_basic(fixtures_dir):
|
|
23
|
-
lines = _load(fixtures_dir, "basic-session.jsonl")
|
|
24
|
-
msgs = PR.get_messages(lines)
|
|
25
|
-
assert len(msgs) == 2
|
|
26
|
-
assert msgs[0]["role"] == "user"
|
|
27
|
-
assert msgs[1]["role"] == "assistant"
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
def test_compact_marker_single(fixtures_dir):
|
|
31
|
-
lines = _load(fixtures_dir, "with-compact.jsonl")
|
|
32
|
-
msgs = PR.get_messages(lines)
|
|
33
|
-
compact = [m for m in msgs if m["is_compact"]]
|
|
34
|
-
assert len(compact) == 1
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
def test_compact_marker_multiple(fixtures_dir):
|
|
38
|
-
lines = _load(fixtures_dir, "multi-compact.jsonl")
|
|
39
|
-
msgs = PR.get_messages(lines)
|
|
40
|
-
compact = [m for m in msgs if m["is_compact"]]
|
|
41
|
-
assert len(compact) == 2
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
def test_compact_marker_absent(fixtures_dir):
|
|
45
|
-
lines = _load(fixtures_dir, "basic-session.jsonl")
|
|
46
|
-
msgs = PR.get_messages(lines)
|
|
47
|
-
assert all(not m["is_compact"] for m in msgs)
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
def test_extract_text_blocks_string():
|
|
51
|
-
assert PR.extract_text_blocks("hello") == ["hello"]
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
def test_extract_text_blocks_empty_string():
|
|
55
|
-
assert PR.extract_text_blocks("") == []
|
|
56
|
-
assert PR.extract_text_blocks(" ") == []
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
def test_extract_text_blocks_array():
|
|
60
|
-
blocks = [{"type": "text", "text": "hi"}, {"type": "tool_use", "name": "X"}]
|
|
61
|
-
assert PR.extract_text_blocks(blocks) == ["hi"]
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
def test_extract_text_blocks_with_thinking():
|
|
65
|
-
blocks = [
|
|
66
|
-
{"type": "thinking", "thinking": "reasoning..."},
|
|
67
|
-
{"type": "text", "text": "answer"},
|
|
68
|
-
]
|
|
69
|
-
out = PR.extract_text_blocks(blocks, include_thinking=True)
|
|
70
|
-
assert any("THINKING" in t for t in out)
|
|
71
|
-
assert "answer" in out
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
def test_extract_text_blocks_with_tool_use():
|
|
75
|
-
blocks = [{"type": "tool_use", "name": "Bash", "input": {"command": "ls"}}]
|
|
76
|
-
out = PR.extract_text_blocks(blocks, include_tool_use=True)
|
|
77
|
-
assert any("TOOL_USE Bash" in t for t in out)
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
def test_extract_advisor():
|
|
81
|
-
blocks = [{"type": "advisor_tool_result", "content": {"text": "advice"}}]
|
|
82
|
-
out = PR.extract_text_blocks(blocks)
|
|
83
|
-
assert any("[ADVISOR]" in t for t in out)
|
|
84
|
-
assert any("advice" in t for t in out)
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
def test_classify_entry_user():
|
|
88
|
-
obj = {"type": "user", "message": {"role": "user", "content": "hi"}}
|
|
89
|
-
assert PR.classify_entry(obj) == "user"
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
def test_classify_entry_compact():
|
|
93
|
-
obj = {
|
|
94
|
-
"type": "user",
|
|
95
|
-
"message": {"role": "user", "content": PR.COMPACT_MARKER + " more"},
|
|
96
|
-
}
|
|
97
|
-
assert PR.classify_entry(obj) == "compact"
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
def test_classify_entry_assistant():
|
|
101
|
-
obj = {"type": "assistant", "message": {"role": "assistant", "content": []}}
|
|
102
|
-
assert PR.classify_entry(obj) == "assistant"
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
def test_classify_entry_noise():
|
|
106
|
-
obj = {"type": "ai-title", "aiTitle": "X"}
|
|
107
|
-
assert PR.classify_entry(obj) == "title"
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
def test_all_noise_fixture_yields_no_messages(fixtures_dir):
|
|
111
|
-
lines = _load(fixtures_dir, "all-noise.jsonl")
|
|
112
|
-
msgs = PR.get_messages(lines)
|
|
113
|
-
assert msgs == []
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
def test_filter_by_role(fixtures_dir):
|
|
117
|
-
lines = _load(fixtures_dir, "basic-session.jsonl")
|
|
118
|
-
msgs = PR.get_messages(lines)
|
|
119
|
-
user_only = PR.filter_by_role(msgs, "user")
|
|
120
|
-
assert all(m["role"] == "user" for m in user_only)
|
|
121
|
-
assert len(user_only) == 1
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
def test_filter_by_time(fixtures_dir):
|
|
125
|
-
lines = _load(fixtures_dir, "time-spread.jsonl")
|
|
126
|
-
msgs = PR.get_messages(lines)
|
|
127
|
-
since = datetime(2026, 5, 1)
|
|
128
|
-
filtered = PR.filter_by_time(msgs, since=since, until=None)
|
|
129
|
-
assert all(
|
|
130
|
-
PR._parse_timestamp(m["timestamp"]).replace(tzinfo=None) >= since
|
|
131
|
-
for m in filtered if m["timestamp"]
|
|
132
|
-
)
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
def test_filter_by_time_until_is_exclusive():
|
|
136
|
-
# Half-open [since, until): a message stamped exactly at `until` is excluded.
|
|
137
|
-
# Derive the bound from the parser so the test is timezone-independent.
|
|
138
|
-
msgs = [{"timestamp": "2026-05-01T10:00:00Z"}]
|
|
139
|
-
at = PR._parse_timestamp(msgs[0]["timestamp"])
|
|
140
|
-
assert PR.filter_by_time(msgs, since=None, until=at) == []
|
|
141
|
-
assert PR.filter_by_time(msgs, since=None, until=at + timedelta(seconds=1)) == msgs
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
def test_truncated_line_dropped(fixtures_dir, capsys):
|
|
145
|
-
# Should not raise, and warning should be on stderr
|
|
146
|
-
lines = _load(fixtures_dir, "truncated.jsonl")
|
|
147
|
-
# 2 valid + 1 truncated = 2 valid records
|
|
148
|
-
assert len(lines) == 2
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
def test_unicode_roundtrip(fixtures_dir):
|
|
152
|
-
lines = _load(fixtures_dir, "unicode.jsonl")
|
|
153
|
-
msgs = PR.get_messages(lines)
|
|
154
|
-
user_text = msgs[0]["texts"][0]
|
|
155
|
-
assert "🌍" in user_text or "你好" in user_text
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
def test_infer_status_clean(fixtures_dir):
|
|
159
|
-
lines = _load(fixtures_dir, "basic-session.jsonl")
|
|
160
|
-
mtime = (fixtures_dir / "basic-session.jsonl").stat().st_mtime
|
|
161
|
-
status = PR.infer_status(lines, mtime, current_session_id=None, session_uuid=None)
|
|
162
|
-
assert status == "clean"
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
def test_infer_status_pending_user(fixtures_dir):
|
|
166
|
-
lines = _load(fixtures_dir, "pending-user.jsonl")
|
|
167
|
-
mtime = (fixtures_dir / "pending-user.jsonl").stat().st_mtime
|
|
168
|
-
status = PR.infer_status(lines, mtime, current_session_id=None, session_uuid=None)
|
|
169
|
-
assert status == "pending-user"
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
def test_infer_status_interrupted(fixtures_dir):
|
|
173
|
-
lines = _load(fixtures_dir, "interrupted.jsonl")
|
|
174
|
-
mtime = (fixtures_dir / "interrupted.jsonl").stat().st_mtime
|
|
175
|
-
status = PR.infer_status(lines, mtime, current_session_id=None, session_uuid=None)
|
|
176
|
-
assert status == "interrupted"
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
def test_infer_status_active(fixtures_dir):
|
|
180
|
-
import time
|
|
181
|
-
# Touch the fixture to make it fresh, then set CLAUDE_SESSION_ID to its stem
|
|
182
|
-
f = fixtures_dir / "basic-session.jsonl"
|
|
183
|
-
mtime = time.time()
|
|
184
|
-
lines = _load(fixtures_dir, "basic-session.jsonl")
|
|
185
|
-
status = PR.infer_status(
|
|
186
|
-
lines, mtime, current_session_id="basic-session", session_uuid="basic-session"
|
|
187
|
-
)
|
|
188
|
-
assert status == "active"
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
def test_session_summary_fields(fixtures_dir):
|
|
192
|
-
s = PR.session_summary(fixtures_dir / "tool-zoo.jsonl")
|
|
193
|
-
assert s["exists"]
|
|
194
|
-
assert s["msg_count"] > 0
|
|
195
|
-
assert "Bash" in s["tool_counts"]
|
|
196
|
-
assert "Read" in s["tool_counts"]
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
def test_parse_lines_cache(fixtures_dir):
|
|
200
|
-
f = fixtures_dir / "basic-session.jsonl"
|
|
201
|
-
a = PR.parse_lines(f)
|
|
202
|
-
b = PR.parse_lines(f)
|
|
203
|
-
# Same object thanks to cache
|
|
204
|
-
assert a is b
|
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
"""Tests for lib.paths."""
|
|
2
|
-
|
|
3
|
-
import os
|
|
4
|
-
from datetime import datetime, timedelta
|
|
5
|
-
from pathlib import Path
|
|
6
|
-
|
|
7
|
-
import pytest
|
|
8
|
-
|
|
9
|
-
from lib import paths as P
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
def test_encode_cwd_basic():
|
|
13
|
-
assert P.encode_cwd("C:\\Users\\foo\\bar") == "C--Users-foo-bar"
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
def test_encode_cwd_spaces():
|
|
17
|
-
assert P.encode_cwd("C:\\Users\\2supe\\Other Claude Code") == "C--Users-2supe-Other-Claude-Code"
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
def test_encode_cwd_mixed_slashes():
|
|
21
|
-
assert P.encode_cwd("C:/Users/foo bar") == "C--Users-foo-bar"
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
def test_decode_project_name_strips_prefix():
|
|
25
|
-
enc = "C--Users-elliot-Other-Claude-Code-Personal-Brand-Project"
|
|
26
|
-
decoded = P.decode_project_name(enc)
|
|
27
|
-
assert "Other" in decoded
|
|
28
|
-
assert "Personal" in decoded
|
|
29
|
-
assert "C--Users" not in decoded
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
def test_decode_project_name_fallback_when_unparseable():
|
|
33
|
-
decoded = P.decode_project_name("totally-weird-thing")
|
|
34
|
-
assert decoded # Non-empty, falls back gracefully
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
def test_resolve_root_live():
|
|
38
|
-
assert P.resolve_root("live").name == "projects"
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
def test_resolve_root_mirror():
|
|
42
|
-
r = P.resolve_root("mirror")
|
|
43
|
-
assert "mirror" in str(r)
|
|
44
|
-
assert r.name == "projects"
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
def test_resolve_root_unknown_relative_raises():
|
|
48
|
-
with pytest.raises(ValueError):
|
|
49
|
-
P.resolve_root("not-a-known-root")
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
def test_resolve_root_absolute_passes_through(tmp_path: Path):
|
|
53
|
-
r = P.resolve_root(str(tmp_path))
|
|
54
|
-
assert r == tmp_path
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
def test_current_session_id_unset(monkeypatch):
|
|
58
|
-
monkeypatch.delenv("CLAUDE_SESSION_ID", raising=False)
|
|
59
|
-
assert P.current_session_id() is None
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
def test_current_session_id_set(monkeypatch):
|
|
63
|
-
monkeypatch.setenv("CLAUDE_SESSION_ID", "abc-123")
|
|
64
|
-
assert P.current_session_id() == "abc-123"
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
def test_parse_timespec_relative():
|
|
68
|
-
now = datetime.now()
|
|
69
|
-
delta = now - P.parse_timespec("1h")
|
|
70
|
-
assert timedelta(seconds=3590) <= delta <= timedelta(seconds=3610)
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
def test_parse_timespec_iso_date():
|
|
74
|
-
assert P.parse_timespec("2026-05-01") == datetime(2026, 5, 1)
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
def test_parse_timespec_yesterday():
|
|
78
|
-
y = P.parse_timespec("yesterday")
|
|
79
|
-
assert y.hour == 0
|
|
80
|
-
assert y.minute == 0
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
def test_parse_timespec_invalid():
|
|
84
|
-
with pytest.raises(ValueError):
|
|
85
|
-
P.parse_timespec("not-a-time")
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
def test_list_transcripts_empty(tmp_path: Path):
|
|
89
|
-
assert P.list_transcripts(tmp_path) == []
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
def test_list_transcripts_excludes_agent_prefix(tmp_path: Path):
|
|
93
|
-
(tmp_path / "real.jsonl").write_text("{}\n")
|
|
94
|
-
(tmp_path / "agent-foo.jsonl").write_text("{}\n")
|
|
95
|
-
files = P.list_transcripts(tmp_path)
|
|
96
|
-
names = [f.name for f in files]
|
|
97
|
-
assert "real.jsonl" in names
|
|
98
|
-
assert "agent-foo.jsonl" not in names
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
def test_list_transcripts_time_filter(tmp_path: Path):
|
|
102
|
-
old = tmp_path / "old.jsonl"
|
|
103
|
-
new = tmp_path / "new.jsonl"
|
|
104
|
-
old.write_text("{}\n")
|
|
105
|
-
new.write_text("{}\n")
|
|
106
|
-
# Backdate old
|
|
107
|
-
past = datetime.now() - timedelta(days=10)
|
|
108
|
-
os.utime(old, (past.timestamp(), past.timestamp()))
|
|
109
|
-
|
|
110
|
-
since = datetime.now() - timedelta(days=5)
|
|
111
|
-
files = P.list_transcripts(tmp_path, since=since)
|
|
112
|
-
assert [f.name for f in files] == ["new.jsonl"]
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
def test_list_projects_empty(tmp_path: Path):
|
|
116
|
-
assert P.list_projects(tmp_path) == []
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
def test_list_subagents_returns_empty_when_no_dir(tmp_path: Path):
|
|
120
|
-
f = tmp_path / "session.jsonl"
|
|
121
|
-
f.write_text("{}\n")
|
|
122
|
-
assert P.list_subagents(f) == []
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
def test_list_subagents_finds_agent_files(tmp_path: Path):
|
|
126
|
-
f = tmp_path / "session.jsonl"
|
|
127
|
-
f.write_text("{}\n")
|
|
128
|
-
sub_dir = tmp_path / "session" / "subagents"
|
|
129
|
-
sub_dir.mkdir(parents=True)
|
|
130
|
-
(sub_dir / "agent-x.jsonl").write_text("{}\n")
|
|
131
|
-
(sub_dir / "agent-y.jsonl").write_text("{}\n")
|
|
132
|
-
subs = P.list_subagents(f)
|
|
133
|
-
assert len(subs) == 2
|