Files
ai-agent/backend/test_image_note.py
gabrielvidalandClaude Opus 5.5 3ec287a493 refactor(conversations): turn parse.py into a package (pass a: pure moves)
conversations/parse.py (2,449 lines) becomes conversations/parse/:
records (JSONL records, timestamps, clipped blocks, _item), usertext (inbox /
cancel / relay / author / held / slash / skill / image / compact text), tools
(buckets, sub-labels, project / service / worktree / commit evidence,
lifecycle + deploys), errors (API-error kinds, limit resets), usage (delta /
estimate / cost-state helpers), turns (turn-end records), state
(ParserState + parse_conversation, unchanged) and cut (find_cut_line).

Code moved verbatim. The package re-exports every name the module had, and
its __all__ is exactly what `from .parse import *` exported before, so the
`conversations` namespace is identical (checked name by name).

Verified against 57a4d8ee: parse-ab 500 files x 2 modes 0 differing,
--chunked 0 mismatches, pricing-dump identical, test_parse_fixtures OK.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-23 23:34:14 +01:00

54 lines
1.8 KiB
Python

"""Claude Code's image-resize note (conversations/parse/usertext.py `_IMAGE_NOTE_RE`) —
an `isMeta` user record after an image Read — is not a user turn: no bubble,
no count, not searchable. Even right after a typed `/name`, where an `isMeta`
record would otherwise be taken for the skill's prompt."""
import json
import conversations as c
NOTE = ("[Image: original 2048x2048, displayed at 1932x1932. "
"Multiply coordinates by 1.06 to map to original image.]")
def _user(content, ts, **rec):
return {"type": "user", "timestamp": ts, "sessionId": "s1",
"message": {"role": "user", "content": content}, **rec}
def _parse(tmp_path, recs):
p = tmp_path / "s1.jsonl"
p.write_text("".join(json.dumps(r) + "\n" for r in recs))
st = c.ParserState(p, full=True)
for r in recs:
st.feed(r)
return st
def _bubbles(st):
return [it["text"] for it in st.thread if it["role"] == "user" and it["kind"] == "text"]
def test_image_note_is_hidden(tmp_path):
st = _parse(tmp_path, [
_user("look at this screenshot", "2026-10-20T10:00:00Z"),
_user(NOTE, "2026-10-20T10:00:05Z", isMeta=True, turnCompanion=True),
])
assert _bubbles(st) == ["look at this screenshot"]
assert st.user_turns == 1
assert all("Multiply coordinates" not in m["text"] for m in st.search_msgs)
def test_image_note_first_is_not_the_first_prompt(tmp_path):
st = _parse(tmp_path, [
_user(NOTE, "2026-10-20T10:00:00Z", isMeta=True),
_user("the real prompt", "2026-10-20T10:00:05Z"),
])
assert st.first_user == "the real prompt"
def test_quoting_the_note_is_still_a_turn(tmp_path):
text = f"why do I see '{NOTE}' in the chat?"
st = _parse(tmp_path, [_user(text, "2026-10-20T10:00:00Z")])
assert _bubbles(st) == [text]