Skip to content

test: add unit tests for buildSnapshotContent, buildSnapshotMarkdown, and extractMessageText #252

@claude

Description

@claude

Problem

cmd/precompact_test.go only tests looksLikeFilePath. The three functions that do the real work of building the session snapshot have no unit tests:

  • buildSnapshotContent (cmd/precompact.go:96) — orchestrates transcript parsing, deduplication, and trimming
  • buildSnapshotMarkdown (cmd/precompact.go:176) — formats the final Markdown output
  • extractMessageText (cmd/precompact.go:214) — handles both string and []contentBlock content shapes

These functions contain non-trivial logic (last-5 user messages, last-10 files-in-focus, reverse-deduplication of file paths, Unicode-aware truncation at 200 runes) that is easy to break silently. The recent perf commit f6ad83d streamed the transcript line-by-line but added no new test coverage for this logic.

What to add

Tests in cmd/precompact_test.go covering:

  1. extractMessageText — plain string content returns the string as-is
  2. extractMessageText — structured []interface{} content block array joins text blocks
  3. extractMessageText — non-text blocks (e.g. tool_use) are skipped
  4. buildSnapshotMarkdown — with user messages and files: both sections appear in output
  5. buildSnapshotMarkdown — with no messages and no files: fallback placeholder appears
  6. buildSnapshotContent — given a JSONL fixture with more than 5 user messages, only the last 5 are retained
  7. buildSnapshotContent — file paths mentioned multiple times are deduplicated, keeping only the last occurrence

Files

  • cmd/precompact_test.go (file to extend)
  • cmd/precompact.go:96,176,214 (functions under test)

@claude please implement this

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions