Skip to content

Replay your coding agent sessions as a map and a timeline

test(builder): cover Claude Code workflow subagent transcripts

rav4nn9f79e6b1051c
diff --git a/python/tests/test_builder.py b/python/tests/test_builder.py
index 3090604..ad980bf 100644
--- a/python/tests/test_builder.py
+++ b/python/tests/test_builder.py
@@ -227,6 +227,61 @@ def test_acompact_snapshot_is_not_a_subagent_lane(transcript):
assert doc["totals"]["tokens"] == before["totals"]["tokens"]
+def test_workflow_subagent_gets_a_lane_without_leaking_text(transcript):
+ before = sm.build_claude_code_map(transcript)
+ cwd = json.loads(transcript.read_text().splitlines()[0])["cwd"]
+ run = transcript.with_suffix("") / "subagents" / "workflows" / "wf_0a1b2c3d-4e5"
+ run.mkdir(parents=True)
+ (run / "agent-a0f1e2d3c4b5a6978.meta.json").write_text(
+ json.dumps(
+ {"agentType": "workflow-subagent", "description": "SECRET-WF-DESC", "workflowPhase": "SECRET-WF-PHASE"}
+ )
+ )
+ (run / "agent-a0f1e2d3c4b5a6978.jsonl").write_text(
+ _line(
+ type="user",
+ timestamp="2026-09-10T01:00:05Z",
+ cwd=cwd,
+ isSidechain=True,
+ message={"role": "user", "content": "SECRET-WF-PROMPT"},
+ )
+ + _line(
+ type="assistant",
+ timestamp="2026-09-10T01:00:06Z",
+ cwd=cwd,
+ isSidechain=True,
+ message={
+ "id": "w1",
+ "model": "claude-sonnet-5",
+ "usage": {"input_tokens": 11, "output_tokens": 4},
+ "content": [
+ {"type": "tool_use", "id": "wt1", "name": "Bash", "input": {"command": "pytest -q SECRET-WF-ARG"}}
+ ],
+ },
+ )
+ + _line(
+ type="user",
+ timestamp="2026-09-10T01:00:07Z",
+ cwd=cwd,
+ isSidechain=True,
+ message={
+ "role": "user",
+ "content": [{"type": "tool_result", "tool_use_id": "wt1", "content": "SECRET-WF-OUTPUT"}],
+ },
+ )
+ )
+ doc = sm.build_claude_code_map(transcript)
+ (lane,) = [a for a in doc["agents"] if a.get("subagentType") == "workflow-subagent"]
+ assert (lane["parent"], lane["kind"]) == ("main", "subagent")
+ assert [e.get("tool") for e in doc["events"] if e["agent"] == lane["id"] and e["kind"] != "llm"] == ["Bash"]
+ assert doc["totals"]["subagents"] == before["totals"]["subagents"] + 1
+ assert doc["totals"]["requests"] == before["totals"]["requests"] + 1
+ assert doc["totals"]["tokens"] == before["totals"]["tokens"] + 15
+ raw = json.dumps(doc)
+ for secret in ("SECRET-WF-DESC", "SECRET-WF-PHASE", "SECRET-WF-PROMPT", "SECRET-WF-ARG", "SECRET-WF-OUTPUT"):
+ assert secret not in raw
+
+
def test_builder_never_leaks_free_text(transcript):
raw = json.dumps(sm.build_claude_code_map(transcript))
for secret in (
diff --git a/python/tests/test_local_tool.py b/python/tests/test_local_tool.py
index a45a62f..8d76751 100644
--- a/python/tests/test_local_tool.py
+++ b/python/tests/test_local_tool.py
@@ -122,6 +122,52 @@ def test_build_is_incremental_and_redacted(env):
assert doc["repos"][0]["remote"] == "acme/app"
+def test_incremental_build_picks_up_a_new_workflow_subagent(env):
+ stem = "11111111-0000-0000-0000-000000000002"
+ f = _write_claude_session(env["home"], stem, env["repo"])
+ assert pipeline.build_all(agents={"claude-code"}, store=Store(env["sm"])).built == 1
+ run = f.with_suffix("") / "subagents" / "workflows" / "wf_0a1b2c3d-4e5"
+ run.mkdir(parents=True)
+ agent = run / "agent-a0f1e2d3c4b5a6978.jsonl"
+ agent.write_text(
+ _line(type="assistant", timestamp="2026-09-10T02:00:00Z", cwd=str(env["repo"]), sessionId=stem,
+ isSidechain=True,
+ message={"id": "w1", "model": "claude-sonnet-5", "role": "assistant",
+ "usage": {"input_tokens": 10, "output_tokens": 5},
+ "content": [{"type": "tool_use", "id": "w1t", "name": "Read",
+ "input": {"file_path": f"{env['repo']}/src/app.py"}}]})
+ + _line(type="user", timestamp="2026-09-10T02:00:01Z", cwd=str(env["repo"]), sessionId=stem,
+ isSidechain=True,
+ message={"role": "user", "content": [{"type": "tool_result", "tool_use_id": "w1t",
+ "content": "x = 1"}]})
+ )
+ later = f.stat().st_mtime + 60
+ os.utime(agent, (later, later))
+
+ again = pipeline.build_all(agents={"claude-code"}, store=Store(env["sm"]))
+ assert (again.built, again.unchanged) == (1, 0)
+ sid = f"local:claude-code:{stem}"
+ doc = Store(env["sm"]).get(sid)
+ lanes = {a["id"]: a["kind"] for a in doc["agents"]}
+ assert [lanes[e["agent"]] for e in doc["events"] if e.get("tool") == "Read"] == ["main", "subagent"]
+ cand = discover.Candidate(sid, "claude-code", str(f), later)
+ assert discover.source_bytes(cand) == f.stat().st_size + agent.stat().st_size
+
+
[email protected](sys.platform == "win32" or os.geteuid() == 0, reason="needs POSIX permissions")
+def test_unreadable_workflow_folder_fails_only_its_own_session(env):
+ _write_claude_session(env["home"], "11111111-0000-0000-0000-000000000003", env["repo"])
+ f = _write_claude_session(env["home"], "11111111-0000-0000-0000-000000000004", env["repo"])
+ run = f.with_suffix("") / "subagents" / "workflows" / "wf_0a1b2c3d-4e5"
+ run.mkdir(parents=True)
+ run.chmod(0)
+ try:
+ rep = pipeline.build_all(agents={"claude-code"}, store=Store(env["sm"]))
+ finally:
+ run.chmod(0o700)
+ assert (rep.found, rep.built, rep.failed) == (2, 1, 1)
+
+
@pytest.mark.parametrize(
("raw", "want"),
[
@@ -1086,8 +1132,9 @@ def test_hook_text_never_reaches_a_map_the_index_or_an_export(env, monkeypatch,
assert "stop msg" not in raw and "stop cmd" not in raw
assert _HOOK_BLOCK in map_raw and _HOOK_BLOCK not in index_raw
-def test_hook_detail_finds_a_subagent_hook_in_its_own_transcript(hooked):
- sub = hooked.transcript.with_suffix("") / "subagents"
[email protected]("folder", ["subagents", "subagents/workflows/wf_0a1b2c3d-4e5"])
+def test_hook_detail_finds_a_subagent_hook_in_its_own_transcript(hooked, folder):
+ sub = hooked.transcript.with_suffix("") / folder
sub.mkdir(parents=True)
uuid = "55555555-0000-0000-0000-000000000005"
(sub / "agent-abc.jsonl").write_text(_line(type="attachment", uuid=uuid, attachment={