test: add comprehensive Phase 0 test suite — 67 tests, 90.9% coverage
Add parser_test.go (22 tests), search_test.go (9 tests), html_test.go (6 tests),
video_test.go (12 tests), and bench_test.go (4 benchmarks) covering all Phase 0
TODO items:
- ParseTranscript: minimal JSONL, all 7 tool types, errors, truncated/malformed
input, large sessions (1100+ events), nested array/map results, mixed content
- ListSessions: empty dir, single/multi sorted, non-JSONL ignored, modtime fallback
- extractToolInput: all tool types plus nil, invalid JSON, unknown tool fallback
- extractResultContent: string, array, map, and other types
- Search: empty dir, no matches, multi-match, case insensitive, output matching
- RenderHTML: basic, empty, errors, XSS escaping, label types, invalid path
- generateTape/extractCommand: all event types, empty/failed commands, truncation
- Benchmarks: 2.2MB and 11MB ParseTranscript, ListSessions, Search with b.Loop()
go vet ./... clean, go test -race ./... clean.
Co-Authored-By: Virgil <virgil@lethean.io>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-20 05:00:38 +00:00
|
|
|
// SPDX-Licence-Identifier: EUPL-1.2
|
2026-02-20 00:42:11 +00:00
|
|
|
package session
|
|
|
|
|
|
|
|
|
|
import (
|
2026-03-26 15:50:44 +00:00
|
|
|
"path"
|
2026-02-20 00:42:11 +00:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
)
|
|
|
|
|
|
2026-03-26 18:59:53 +00:00
|
|
|
func TestSearch_SearchEmptyDir_Good(t *testing.T) {
|
2026-02-20 00:42:11 +00:00
|
|
|
dir := t.TempDir()
|
|
|
|
|
|
test: add comprehensive Phase 0 test suite — 67 tests, 90.9% coverage
Add parser_test.go (22 tests), search_test.go (9 tests), html_test.go (6 tests),
video_test.go (12 tests), and bench_test.go (4 benchmarks) covering all Phase 0
TODO items:
- ParseTranscript: minimal JSONL, all 7 tool types, errors, truncated/malformed
input, large sessions (1100+ events), nested array/map results, mixed content
- ListSessions: empty dir, single/multi sorted, non-JSONL ignored, modtime fallback
- extractToolInput: all tool types plus nil, invalid JSON, unknown tool fallback
- extractResultContent: string, array, map, and other types
- Search: empty dir, no matches, multi-match, case insensitive, output matching
- RenderHTML: basic, empty, errors, XSS escaping, label types, invalid path
- generateTape/extractCommand: all event types, empty/failed commands, truncation
- Benchmarks: 2.2MB and 11MB ParseTranscript, ListSessions, Search with b.Loop()
go vet ./... clean, go test -race ./... clean.
Co-Authored-By: Virgil <virgil@lethean.io>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-20 05:00:38 +00:00
|
|
|
results, err := Search(dir, "anything")
|
2026-02-20 00:42:11 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
assert.Empty(t, results)
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-26 18:59:53 +00:00
|
|
|
func TestSearch_SearchNoMatches_Good(t *testing.T) {
|
2026-02-20 00:42:11 +00:00
|
|
|
dir := t.TempDir()
|
test: add comprehensive Phase 0 test suite — 67 tests, 90.9% coverage
Add parser_test.go (22 tests), search_test.go (9 tests), html_test.go (6 tests),
video_test.go (12 tests), and bench_test.go (4 benchmarks) covering all Phase 0
TODO items:
- ParseTranscript: minimal JSONL, all 7 tool types, errors, truncated/malformed
input, large sessions (1100+ events), nested array/map results, mixed content
- ListSessions: empty dir, single/multi sorted, non-JSONL ignored, modtime fallback
- extractToolInput: all tool types plus nil, invalid JSON, unknown tool fallback
- extractResultContent: string, array, map, and other types
- Search: empty dir, no matches, multi-match, case insensitive, output matching
- RenderHTML: basic, empty, errors, XSS escaping, label types, invalid path
- generateTape/extractCommand: all event types, empty/failed commands, truncation
- Benchmarks: 2.2MB and 11MB ParseTranscript, ListSessions, Search with b.Loop()
go vet ./... clean, go test -race ./... clean.
Co-Authored-By: Virgil <virgil@lethean.io>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-20 05:00:38 +00:00
|
|
|
writeJSONL(t, dir, "session.jsonl",
|
2026-02-22 21:00:17 +00:00
|
|
|
toolUseEntry(ts(0), "Bash", "tool-1", map[string]any{
|
test: add comprehensive Phase 0 test suite — 67 tests, 90.9% coverage
Add parser_test.go (22 tests), search_test.go (9 tests), html_test.go (6 tests),
video_test.go (12 tests), and bench_test.go (4 benchmarks) covering all Phase 0
TODO items:
- ParseTranscript: minimal JSONL, all 7 tool types, errors, truncated/malformed
input, large sessions (1100+ events), nested array/map results, mixed content
- ListSessions: empty dir, single/multi sorted, non-JSONL ignored, modtime fallback
- extractToolInput: all tool types plus nil, invalid JSON, unknown tool fallback
- extractResultContent: string, array, map, and other types
- Search: empty dir, no matches, multi-match, case insensitive, output matching
- RenderHTML: basic, empty, errors, XSS escaping, label types, invalid path
- generateTape/extractCommand: all event types, empty/failed commands, truncation
- Benchmarks: 2.2MB and 11MB ParseTranscript, ListSessions, Search with b.Loop()
go vet ./... clean, go test -race ./... clean.
Co-Authored-By: Virgil <virgil@lethean.io>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-20 05:00:38 +00:00
|
|
|
"command": "ls -la",
|
|
|
|
|
}),
|
|
|
|
|
toolResultEntry(ts(1), "tool-1", "total 42", false),
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
results, err := Search(dir, "nonexistent-query")
|
2026-02-20 00:42:11 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
assert.Empty(t, results)
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-26 18:59:53 +00:00
|
|
|
func TestSearch_SearchSingleMatch_Good(t *testing.T) {
|
2026-02-20 00:42:11 +00:00
|
|
|
dir := t.TempDir()
|
test: add comprehensive Phase 0 test suite — 67 tests, 90.9% coverage
Add parser_test.go (22 tests), search_test.go (9 tests), html_test.go (6 tests),
video_test.go (12 tests), and bench_test.go (4 benchmarks) covering all Phase 0
TODO items:
- ParseTranscript: minimal JSONL, all 7 tool types, errors, truncated/malformed
input, large sessions (1100+ events), nested array/map results, mixed content
- ListSessions: empty dir, single/multi sorted, non-JSONL ignored, modtime fallback
- extractToolInput: all tool types plus nil, invalid JSON, unknown tool fallback
- extractResultContent: string, array, map, and other types
- Search: empty dir, no matches, multi-match, case insensitive, output matching
- RenderHTML: basic, empty, errors, XSS escaping, label types, invalid path
- generateTape/extractCommand: all event types, empty/failed commands, truncation
- Benchmarks: 2.2MB and 11MB ParseTranscript, ListSessions, Search with b.Loop()
go vet ./... clean, go test -race ./... clean.
Co-Authored-By: Virgil <virgil@lethean.io>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-20 05:00:38 +00:00
|
|
|
writeJSONL(t, dir, "session.jsonl",
|
2026-02-22 21:00:17 +00:00
|
|
|
toolUseEntry(ts(0), "Bash", "tool-1", map[string]any{
|
test: add comprehensive Phase 0 test suite — 67 tests, 90.9% coverage
Add parser_test.go (22 tests), search_test.go (9 tests), html_test.go (6 tests),
video_test.go (12 tests), and bench_test.go (4 benchmarks) covering all Phase 0
TODO items:
- ParseTranscript: minimal JSONL, all 7 tool types, errors, truncated/malformed
input, large sessions (1100+ events), nested array/map results, mixed content
- ListSessions: empty dir, single/multi sorted, non-JSONL ignored, modtime fallback
- extractToolInput: all tool types plus nil, invalid JSON, unknown tool fallback
- extractResultContent: string, array, map, and other types
- Search: empty dir, no matches, multi-match, case insensitive, output matching
- RenderHTML: basic, empty, errors, XSS escaping, label types, invalid path
- generateTape/extractCommand: all event types, empty/failed commands, truncation
- Benchmarks: 2.2MB and 11MB ParseTranscript, ListSessions, Search with b.Loop()
go vet ./... clean, go test -race ./... clean.
Co-Authored-By: Virgil <virgil@lethean.io>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-20 05:00:38 +00:00
|
|
|
"command": "go test ./...",
|
|
|
|
|
}),
|
|
|
|
|
toolResultEntry(ts(1), "tool-1", "PASS ok mypackage 0.5s", false),
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
results, err := Search(dir, "go test")
|
2026-02-20 00:42:11 +00:00
|
|
|
require.NoError(t, err)
|
test: add comprehensive Phase 0 test suite — 67 tests, 90.9% coverage
Add parser_test.go (22 tests), search_test.go (9 tests), html_test.go (6 tests),
video_test.go (12 tests), and bench_test.go (4 benchmarks) covering all Phase 0
TODO items:
- ParseTranscript: minimal JSONL, all 7 tool types, errors, truncated/malformed
input, large sessions (1100+ events), nested array/map results, mixed content
- ListSessions: empty dir, single/multi sorted, non-JSONL ignored, modtime fallback
- extractToolInput: all tool types plus nil, invalid JSON, unknown tool fallback
- extractResultContent: string, array, map, and other types
- Search: empty dir, no matches, multi-match, case insensitive, output matching
- RenderHTML: basic, empty, errors, XSS escaping, label types, invalid path
- generateTape/extractCommand: all event types, empty/failed commands, truncation
- Benchmarks: 2.2MB and 11MB ParseTranscript, ListSessions, Search with b.Loop()
go vet ./... clean, go test -race ./... clean.
Co-Authored-By: Virgil <virgil@lethean.io>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-20 05:00:38 +00:00
|
|
|
require.Len(t, results, 1)
|
|
|
|
|
|
|
|
|
|
assert.Equal(t, "session", results[0].SessionID)
|
|
|
|
|
assert.Equal(t, "Bash", results[0].Tool)
|
|
|
|
|
assert.Contains(t, results[0].Match, "go test")
|
2026-02-20 00:42:11 +00:00
|
|
|
}
|
|
|
|
|
|
2026-03-26 18:59:53 +00:00
|
|
|
func TestSearch_SearchSeqSingleMatch_Good(t *testing.T) {
|
2026-02-23 05:25:33 +00:00
|
|
|
dir := t.TempDir()
|
|
|
|
|
writeJSONL(t, dir, "session.jsonl",
|
|
|
|
|
toolUseEntry(ts(0), "Bash", "tool-1", map[string]any{
|
|
|
|
|
"command": "go test ./...",
|
|
|
|
|
}),
|
|
|
|
|
toolResultEntry(ts(1), "tool-1", "PASS ok mypackage 0.5s", false),
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
var results []SearchResult
|
|
|
|
|
for r := range SearchSeq(dir, "go test") {
|
|
|
|
|
results = append(results, r)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
require.Len(t, results, 1)
|
|
|
|
|
assert.Equal(t, "session", results[0].SessionID)
|
|
|
|
|
assert.Equal(t, "Bash", results[0].Tool)
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-26 18:59:53 +00:00
|
|
|
func TestSearch_SearchMultipleMatches_Good(t *testing.T) {
|
2026-02-20 00:42:11 +00:00
|
|
|
dir := t.TempDir()
|
test: add comprehensive Phase 0 test suite — 67 tests, 90.9% coverage
Add parser_test.go (22 tests), search_test.go (9 tests), html_test.go (6 tests),
video_test.go (12 tests), and bench_test.go (4 benchmarks) covering all Phase 0
TODO items:
- ParseTranscript: minimal JSONL, all 7 tool types, errors, truncated/malformed
input, large sessions (1100+ events), nested array/map results, mixed content
- ListSessions: empty dir, single/multi sorted, non-JSONL ignored, modtime fallback
- extractToolInput: all tool types plus nil, invalid JSON, unknown tool fallback
- extractResultContent: string, array, map, and other types
- Search: empty dir, no matches, multi-match, case insensitive, output matching
- RenderHTML: basic, empty, errors, XSS escaping, label types, invalid path
- generateTape/extractCommand: all event types, empty/failed commands, truncation
- Benchmarks: 2.2MB and 11MB ParseTranscript, ListSessions, Search with b.Loop()
go vet ./... clean, go test -race ./... clean.
Co-Authored-By: Virgil <virgil@lethean.io>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-20 05:00:38 +00:00
|
|
|
writeJSONL(t, dir, "session1.jsonl",
|
2026-02-22 21:00:17 +00:00
|
|
|
toolUseEntry(ts(0), "Bash", "t1", map[string]any{
|
test: add comprehensive Phase 0 test suite — 67 tests, 90.9% coverage
Add parser_test.go (22 tests), search_test.go (9 tests), html_test.go (6 tests),
video_test.go (12 tests), and bench_test.go (4 benchmarks) covering all Phase 0
TODO items:
- ParseTranscript: minimal JSONL, all 7 tool types, errors, truncated/malformed
input, large sessions (1100+ events), nested array/map results, mixed content
- ListSessions: empty dir, single/multi sorted, non-JSONL ignored, modtime fallback
- extractToolInput: all tool types plus nil, invalid JSON, unknown tool fallback
- extractResultContent: string, array, map, and other types
- Search: empty dir, no matches, multi-match, case insensitive, output matching
- RenderHTML: basic, empty, errors, XSS escaping, label types, invalid path
- generateTape/extractCommand: all event types, empty/failed commands, truncation
- Benchmarks: 2.2MB and 11MB ParseTranscript, ListSessions, Search with b.Loop()
go vet ./... clean, go test -race ./... clean.
Co-Authored-By: Virgil <virgil@lethean.io>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-20 05:00:38 +00:00
|
|
|
"command": "go test ./...",
|
|
|
|
|
}),
|
|
|
|
|
toolResultEntry(ts(1), "t1", "PASS", false),
|
2026-02-22 21:00:17 +00:00
|
|
|
toolUseEntry(ts(2), "Bash", "t2", map[string]any{
|
test: add comprehensive Phase 0 test suite — 67 tests, 90.9% coverage
Add parser_test.go (22 tests), search_test.go (9 tests), html_test.go (6 tests),
video_test.go (12 tests), and bench_test.go (4 benchmarks) covering all Phase 0
TODO items:
- ParseTranscript: minimal JSONL, all 7 tool types, errors, truncated/malformed
input, large sessions (1100+ events), nested array/map results, mixed content
- ListSessions: empty dir, single/multi sorted, non-JSONL ignored, modtime fallback
- extractToolInput: all tool types plus nil, invalid JSON, unknown tool fallback
- extractResultContent: string, array, map, and other types
- Search: empty dir, no matches, multi-match, case insensitive, output matching
- RenderHTML: basic, empty, errors, XSS escaping, label types, invalid path
- generateTape/extractCommand: all event types, empty/failed commands, truncation
- Benchmarks: 2.2MB and 11MB ParseTranscript, ListSessions, Search with b.Loop()
go vet ./... clean, go test -race ./... clean.
Co-Authored-By: Virgil <virgil@lethean.io>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-20 05:00:38 +00:00
|
|
|
"command": "go test -race ./...",
|
|
|
|
|
}),
|
|
|
|
|
toolResultEntry(ts(3), "t2", "PASS", false),
|
|
|
|
|
)
|
|
|
|
|
writeJSONL(t, dir, "session2.jsonl",
|
2026-02-22 21:00:17 +00:00
|
|
|
toolUseEntry(ts(0), "Bash", "t3", map[string]any{
|
test: add comprehensive Phase 0 test suite — 67 tests, 90.9% coverage
Add parser_test.go (22 tests), search_test.go (9 tests), html_test.go (6 tests),
video_test.go (12 tests), and bench_test.go (4 benchmarks) covering all Phase 0
TODO items:
- ParseTranscript: minimal JSONL, all 7 tool types, errors, truncated/malformed
input, large sessions (1100+ events), nested array/map results, mixed content
- ListSessions: empty dir, single/multi sorted, non-JSONL ignored, modtime fallback
- extractToolInput: all tool types plus nil, invalid JSON, unknown tool fallback
- extractResultContent: string, array, map, and other types
- Search: empty dir, no matches, multi-match, case insensitive, output matching
- RenderHTML: basic, empty, errors, XSS escaping, label types, invalid path
- generateTape/extractCommand: all event types, empty/failed commands, truncation
- Benchmarks: 2.2MB and 11MB ParseTranscript, ListSessions, Search with b.Loop()
go vet ./... clean, go test -race ./... clean.
Co-Authored-By: Virgil <virgil@lethean.io>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-20 05:00:38 +00:00
|
|
|
"command": "go test -bench=.",
|
|
|
|
|
}),
|
|
|
|
|
toolResultEntry(ts(1), "t3", "PASS", false),
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
results, err := Search(dir, "go test")
|
2026-02-20 00:42:11 +00:00
|
|
|
require.NoError(t, err)
|
test: add comprehensive Phase 0 test suite — 67 tests, 90.9% coverage
Add parser_test.go (22 tests), search_test.go (9 tests), html_test.go (6 tests),
video_test.go (12 tests), and bench_test.go (4 benchmarks) covering all Phase 0
TODO items:
- ParseTranscript: minimal JSONL, all 7 tool types, errors, truncated/malformed
input, large sessions (1100+ events), nested array/map results, mixed content
- ListSessions: empty dir, single/multi sorted, non-JSONL ignored, modtime fallback
- extractToolInput: all tool types plus nil, invalid JSON, unknown tool fallback
- extractResultContent: string, array, map, and other types
- Search: empty dir, no matches, multi-match, case insensitive, output matching
- RenderHTML: basic, empty, errors, XSS escaping, label types, invalid path
- generateTape/extractCommand: all event types, empty/failed commands, truncation
- Benchmarks: 2.2MB and 11MB ParseTranscript, ListSessions, Search with b.Loop()
go vet ./... clean, go test -race ./... clean.
Co-Authored-By: Virgil <virgil@lethean.io>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-20 05:00:38 +00:00
|
|
|
assert.Len(t, results, 3, "should find matches across both sessions")
|
2026-02-20 00:42:11 +00:00
|
|
|
}
|
|
|
|
|
|
2026-03-26 18:59:53 +00:00
|
|
|
func TestSearch_SearchCaseInsensitive_Good(t *testing.T) {
|
2026-02-20 00:42:11 +00:00
|
|
|
dir := t.TempDir()
|
test: add comprehensive Phase 0 test suite — 67 tests, 90.9% coverage
Add parser_test.go (22 tests), search_test.go (9 tests), html_test.go (6 tests),
video_test.go (12 tests), and bench_test.go (4 benchmarks) covering all Phase 0
TODO items:
- ParseTranscript: minimal JSONL, all 7 tool types, errors, truncated/malformed
input, large sessions (1100+ events), nested array/map results, mixed content
- ListSessions: empty dir, single/multi sorted, non-JSONL ignored, modtime fallback
- extractToolInput: all tool types plus nil, invalid JSON, unknown tool fallback
- extractResultContent: string, array, map, and other types
- Search: empty dir, no matches, multi-match, case insensitive, output matching
- RenderHTML: basic, empty, errors, XSS escaping, label types, invalid path
- generateTape/extractCommand: all event types, empty/failed commands, truncation
- Benchmarks: 2.2MB and 11MB ParseTranscript, ListSessions, Search with b.Loop()
go vet ./... clean, go test -race ./... clean.
Co-Authored-By: Virgil <virgil@lethean.io>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-20 05:00:38 +00:00
|
|
|
writeJSONL(t, dir, "session.jsonl",
|
2026-02-22 21:00:17 +00:00
|
|
|
toolUseEntry(ts(0), "Bash", "t1", map[string]any{
|
test: add comprehensive Phase 0 test suite — 67 tests, 90.9% coverage
Add parser_test.go (22 tests), search_test.go (9 tests), html_test.go (6 tests),
video_test.go (12 tests), and bench_test.go (4 benchmarks) covering all Phase 0
TODO items:
- ParseTranscript: minimal JSONL, all 7 tool types, errors, truncated/malformed
input, large sessions (1100+ events), nested array/map results, mixed content
- ListSessions: empty dir, single/multi sorted, non-JSONL ignored, modtime fallback
- extractToolInput: all tool types plus nil, invalid JSON, unknown tool fallback
- extractResultContent: string, array, map, and other types
- Search: empty dir, no matches, multi-match, case insensitive, output matching
- RenderHTML: basic, empty, errors, XSS escaping, label types, invalid path
- generateTape/extractCommand: all event types, empty/failed commands, truncation
- Benchmarks: 2.2MB and 11MB ParseTranscript, ListSessions, Search with b.Loop()
go vet ./... clean, go test -race ./... clean.
Co-Authored-By: Virgil <virgil@lethean.io>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-20 05:00:38 +00:00
|
|
|
"command": "GO TEST ./...",
|
|
|
|
|
}),
|
|
|
|
|
toolResultEntry(ts(1), "t1", "PASS", false),
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
results, err := Search(dir, "go test")
|
2026-02-20 00:42:11 +00:00
|
|
|
require.NoError(t, err)
|
test: add comprehensive Phase 0 test suite — 67 tests, 90.9% coverage
Add parser_test.go (22 tests), search_test.go (9 tests), html_test.go (6 tests),
video_test.go (12 tests), and bench_test.go (4 benchmarks) covering all Phase 0
TODO items:
- ParseTranscript: minimal JSONL, all 7 tool types, errors, truncated/malformed
input, large sessions (1100+ events), nested array/map results, mixed content
- ListSessions: empty dir, single/multi sorted, non-JSONL ignored, modtime fallback
- extractToolInput: all tool types plus nil, invalid JSON, unknown tool fallback
- extractResultContent: string, array, map, and other types
- Search: empty dir, no matches, multi-match, case insensitive, output matching
- RenderHTML: basic, empty, errors, XSS escaping, label types, invalid path
- generateTape/extractCommand: all event types, empty/failed commands, truncation
- Benchmarks: 2.2MB and 11MB ParseTranscript, ListSessions, Search with b.Loop()
go vet ./... clean, go test -race ./... clean.
Co-Authored-By: Virgil <virgil@lethean.io>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-20 05:00:38 +00:00
|
|
|
assert.Len(t, results, 1, "search should be case-insensitive")
|
2026-02-20 00:42:11 +00:00
|
|
|
}
|
|
|
|
|
|
2026-03-26 18:59:53 +00:00
|
|
|
func TestSearch_SearchMatchesInOutput_Good(t *testing.T) {
|
2026-02-20 00:42:11 +00:00
|
|
|
dir := t.TempDir()
|
test: add comprehensive Phase 0 test suite — 67 tests, 90.9% coverage
Add parser_test.go (22 tests), search_test.go (9 tests), html_test.go (6 tests),
video_test.go (12 tests), and bench_test.go (4 benchmarks) covering all Phase 0
TODO items:
- ParseTranscript: minimal JSONL, all 7 tool types, errors, truncated/malformed
input, large sessions (1100+ events), nested array/map results, mixed content
- ListSessions: empty dir, single/multi sorted, non-JSONL ignored, modtime fallback
- extractToolInput: all tool types plus nil, invalid JSON, unknown tool fallback
- extractResultContent: string, array, map, and other types
- Search: empty dir, no matches, multi-match, case insensitive, output matching
- RenderHTML: basic, empty, errors, XSS escaping, label types, invalid path
- generateTape/extractCommand: all event types, empty/failed commands, truncation
- Benchmarks: 2.2MB and 11MB ParseTranscript, ListSessions, Search with b.Loop()
go vet ./... clean, go test -race ./... clean.
Co-Authored-By: Virgil <virgil@lethean.io>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-20 05:00:38 +00:00
|
|
|
writeJSONL(t, dir, "session.jsonl",
|
2026-02-22 21:00:17 +00:00
|
|
|
toolUseEntry(ts(0), "Bash", "t1", map[string]any{
|
test: add comprehensive Phase 0 test suite — 67 tests, 90.9% coverage
Add parser_test.go (22 tests), search_test.go (9 tests), html_test.go (6 tests),
video_test.go (12 tests), and bench_test.go (4 benchmarks) covering all Phase 0
TODO items:
- ParseTranscript: minimal JSONL, all 7 tool types, errors, truncated/malformed
input, large sessions (1100+ events), nested array/map results, mixed content
- ListSessions: empty dir, single/multi sorted, non-JSONL ignored, modtime fallback
- extractToolInput: all tool types plus nil, invalid JSON, unknown tool fallback
- extractResultContent: string, array, map, and other types
- Search: empty dir, no matches, multi-match, case insensitive, output matching
- RenderHTML: basic, empty, errors, XSS escaping, label types, invalid path
- generateTape/extractCommand: all event types, empty/failed commands, truncation
- Benchmarks: 2.2MB and 11MB ParseTranscript, ListSessions, Search with b.Loop()
go vet ./... clean, go test -race ./... clean.
Co-Authored-By: Virgil <virgil@lethean.io>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-20 05:00:38 +00:00
|
|
|
"command": "cat log.txt",
|
|
|
|
|
}),
|
|
|
|
|
toolResultEntry(ts(1), "t1", "ERROR: connection refused to database", false),
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
results, err := Search(dir, "connection refused")
|
2026-02-20 00:42:11 +00:00
|
|
|
require.NoError(t, err)
|
test: add comprehensive Phase 0 test suite — 67 tests, 90.9% coverage
Add parser_test.go (22 tests), search_test.go (9 tests), html_test.go (6 tests),
video_test.go (12 tests), and bench_test.go (4 benchmarks) covering all Phase 0
TODO items:
- ParseTranscript: minimal JSONL, all 7 tool types, errors, truncated/malformed
input, large sessions (1100+ events), nested array/map results, mixed content
- ListSessions: empty dir, single/multi sorted, non-JSONL ignored, modtime fallback
- extractToolInput: all tool types plus nil, invalid JSON, unknown tool fallback
- extractResultContent: string, array, map, and other types
- Search: empty dir, no matches, multi-match, case insensitive, output matching
- RenderHTML: basic, empty, errors, XSS escaping, label types, invalid path
- generateTape/extractCommand: all event types, empty/failed commands, truncation
- Benchmarks: 2.2MB and 11MB ParseTranscript, ListSessions, Search with b.Loop()
go vet ./... clean, go test -race ./... clean.
Co-Authored-By: Virgil <virgil@lethean.io>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-20 05:00:38 +00:00
|
|
|
require.Len(t, results, 1, "should match against output text")
|
|
|
|
|
// Match field should contain the input (command) since it's non-empty
|
|
|
|
|
assert.Contains(t, results[0].Match, "cat log.txt")
|
2026-02-20 00:42:11 +00:00
|
|
|
}
|
|
|
|
|
|
2026-03-26 18:59:53 +00:00
|
|
|
func TestSearch_SearchSkipsNonToolEvents_Good(t *testing.T) {
|
2026-02-20 00:42:11 +00:00
|
|
|
dir := t.TempDir()
|
test: add comprehensive Phase 0 test suite — 67 tests, 90.9% coverage
Add parser_test.go (22 tests), search_test.go (9 tests), html_test.go (6 tests),
video_test.go (12 tests), and bench_test.go (4 benchmarks) covering all Phase 0
TODO items:
- ParseTranscript: minimal JSONL, all 7 tool types, errors, truncated/malformed
input, large sessions (1100+ events), nested array/map results, mixed content
- ListSessions: empty dir, single/multi sorted, non-JSONL ignored, modtime fallback
- extractToolInput: all tool types plus nil, invalid JSON, unknown tool fallback
- extractResultContent: string, array, map, and other types
- Search: empty dir, no matches, multi-match, case insensitive, output matching
- RenderHTML: basic, empty, errors, XSS escaping, label types, invalid path
- generateTape/extractCommand: all event types, empty/failed commands, truncation
- Benchmarks: 2.2MB and 11MB ParseTranscript, ListSessions, Search with b.Loop()
go vet ./... clean, go test -race ./... clean.
Co-Authored-By: Virgil <virgil@lethean.io>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-20 05:00:38 +00:00
|
|
|
writeJSONL(t, dir, "session.jsonl",
|
|
|
|
|
userTextEntry(ts(0), "Please search for something"),
|
|
|
|
|
assistantTextEntry(ts(1), "I will search for something"),
|
|
|
|
|
)
|
2026-02-20 00:42:11 +00:00
|
|
|
|
test: add comprehensive Phase 0 test suite — 67 tests, 90.9% coverage
Add parser_test.go (22 tests), search_test.go (9 tests), html_test.go (6 tests),
video_test.go (12 tests), and bench_test.go (4 benchmarks) covering all Phase 0
TODO items:
- ParseTranscript: minimal JSONL, all 7 tool types, errors, truncated/malformed
input, large sessions (1100+ events), nested array/map results, mixed content
- ListSessions: empty dir, single/multi sorted, non-JSONL ignored, modtime fallback
- extractToolInput: all tool types plus nil, invalid JSON, unknown tool fallback
- extractResultContent: string, array, map, and other types
- Search: empty dir, no matches, multi-match, case insensitive, output matching
- RenderHTML: basic, empty, errors, XSS escaping, label types, invalid path
- generateTape/extractCommand: all event types, empty/failed commands, truncation
- Benchmarks: 2.2MB and 11MB ParseTranscript, ListSessions, Search with b.Loop()
go vet ./... clean, go test -race ./... clean.
Co-Authored-By: Virgil <virgil@lethean.io>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-20 05:00:38 +00:00
|
|
|
// "search" appears in user and assistant text, but Search only checks tool_use events
|
|
|
|
|
results, err := Search(dir, "search")
|
2026-02-20 00:42:11 +00:00
|
|
|
require.NoError(t, err)
|
test: add comprehensive Phase 0 test suite — 67 tests, 90.9% coverage
Add parser_test.go (22 tests), search_test.go (9 tests), html_test.go (6 tests),
video_test.go (12 tests), and bench_test.go (4 benchmarks) covering all Phase 0
TODO items:
- ParseTranscript: minimal JSONL, all 7 tool types, errors, truncated/malformed
input, large sessions (1100+ events), nested array/map results, mixed content
- ListSessions: empty dir, single/multi sorted, non-JSONL ignored, modtime fallback
- extractToolInput: all tool types plus nil, invalid JSON, unknown tool fallback
- extractResultContent: string, array, map, and other types
- Search: empty dir, no matches, multi-match, case insensitive, output matching
- RenderHTML: basic, empty, errors, XSS escaping, label types, invalid path
- generateTape/extractCommand: all event types, empty/failed commands, truncation
- Benchmarks: 2.2MB and 11MB ParseTranscript, ListSessions, Search with b.Loop()
go vet ./... clean, go test -race ./... clean.
Co-Authored-By: Virgil <virgil@lethean.io>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-20 05:00:38 +00:00
|
|
|
assert.Empty(t, results, "should only match tool_use events, not user/assistant text")
|
2026-02-20 00:42:11 +00:00
|
|
|
}
|
|
|
|
|
|
2026-03-26 18:59:53 +00:00
|
|
|
func TestSearch_SearchNonJSONLIgnored_Good(t *testing.T) {
|
2026-02-20 00:42:11 +00:00
|
|
|
dir := t.TempDir()
|
2026-03-26 15:50:44 +00:00
|
|
|
writeResult := hostFS.Write(path.Join(dir, "readme.md"), "go test")
|
|
|
|
|
require.True(t, writeResult.OK)
|
2026-02-20 00:42:11 +00:00
|
|
|
|
test: add comprehensive Phase 0 test suite — 67 tests, 90.9% coverage
Add parser_test.go (22 tests), search_test.go (9 tests), html_test.go (6 tests),
video_test.go (12 tests), and bench_test.go (4 benchmarks) covering all Phase 0
TODO items:
- ParseTranscript: minimal JSONL, all 7 tool types, errors, truncated/malformed
input, large sessions (1100+ events), nested array/map results, mixed content
- ListSessions: empty dir, single/multi sorted, non-JSONL ignored, modtime fallback
- extractToolInput: all tool types plus nil, invalid JSON, unknown tool fallback
- extractResultContent: string, array, map, and other types
- Search: empty dir, no matches, multi-match, case insensitive, output matching
- RenderHTML: basic, empty, errors, XSS escaping, label types, invalid path
- generateTape/extractCommand: all event types, empty/failed commands, truncation
- Benchmarks: 2.2MB and 11MB ParseTranscript, ListSessions, Search with b.Loop()
go vet ./... clean, go test -race ./... clean.
Co-Authored-By: Virgil <virgil@lethean.io>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-20 05:00:38 +00:00
|
|
|
results, err := Search(dir, "go test")
|
2026-02-20 00:42:11 +00:00
|
|
|
require.NoError(t, err)
|
test: add comprehensive Phase 0 test suite — 67 tests, 90.9% coverage
Add parser_test.go (22 tests), search_test.go (9 tests), html_test.go (6 tests),
video_test.go (12 tests), and bench_test.go (4 benchmarks) covering all Phase 0
TODO items:
- ParseTranscript: minimal JSONL, all 7 tool types, errors, truncated/malformed
input, large sessions (1100+ events), nested array/map results, mixed content
- ListSessions: empty dir, single/multi sorted, non-JSONL ignored, modtime fallback
- extractToolInput: all tool types plus nil, invalid JSON, unknown tool fallback
- extractResultContent: string, array, map, and other types
- Search: empty dir, no matches, multi-match, case insensitive, output matching
- RenderHTML: basic, empty, errors, XSS escaping, label types, invalid path
- generateTape/extractCommand: all event types, empty/failed commands, truncation
- Benchmarks: 2.2MB and 11MB ParseTranscript, ListSessions, Search with b.Loop()
go vet ./... clean, go test -race ./... clean.
Co-Authored-By: Virgil <virgil@lethean.io>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-20 05:00:38 +00:00
|
|
|
assert.Empty(t, results, "non-JSONL files should be ignored")
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-26 18:59:53 +00:00
|
|
|
func TestSearch_SearchMalformedSessionSkipped_Bad(t *testing.T) {
|
test: add comprehensive Phase 0 test suite — 67 tests, 90.9% coverage
Add parser_test.go (22 tests), search_test.go (9 tests), html_test.go (6 tests),
video_test.go (12 tests), and bench_test.go (4 benchmarks) covering all Phase 0
TODO items:
- ParseTranscript: minimal JSONL, all 7 tool types, errors, truncated/malformed
input, large sessions (1100+ events), nested array/map results, mixed content
- ListSessions: empty dir, single/multi sorted, non-JSONL ignored, modtime fallback
- extractToolInput: all tool types plus nil, invalid JSON, unknown tool fallback
- extractResultContent: string, array, map, and other types
- Search: empty dir, no matches, multi-match, case insensitive, output matching
- RenderHTML: basic, empty, errors, XSS escaping, label types, invalid path
- generateTape/extractCommand: all event types, empty/failed commands, truncation
- Benchmarks: 2.2MB and 11MB ParseTranscript, ListSessions, Search with b.Loop()
go vet ./... clean, go test -race ./... clean.
Co-Authored-By: Virgil <virgil@lethean.io>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-20 05:00:38 +00:00
|
|
|
dir := t.TempDir()
|
2026-02-20 00:42:11 +00:00
|
|
|
|
test: add comprehensive Phase 0 test suite — 67 tests, 90.9% coverage
Add parser_test.go (22 tests), search_test.go (9 tests), html_test.go (6 tests),
video_test.go (12 tests), and bench_test.go (4 benchmarks) covering all Phase 0
TODO items:
- ParseTranscript: minimal JSONL, all 7 tool types, errors, truncated/malformed
input, large sessions (1100+ events), nested array/map results, mixed content
- ListSessions: empty dir, single/multi sorted, non-JSONL ignored, modtime fallback
- extractToolInput: all tool types plus nil, invalid JSON, unknown tool fallback
- extractResultContent: string, array, map, and other types
- Search: empty dir, no matches, multi-match, case insensitive, output matching
- RenderHTML: basic, empty, errors, XSS escaping, label types, invalid path
- generateTape/extractCommand: all event types, empty/failed commands, truncation
- Benchmarks: 2.2MB and 11MB ParseTranscript, ListSessions, Search with b.Loop()
go vet ./... clean, go test -race ./... clean.
Co-Authored-By: Virgil <virgil@lethean.io>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-20 05:00:38 +00:00
|
|
|
// One broken session and one valid session
|
|
|
|
|
writeJSONL(t, dir, "broken.jsonl",
|
|
|
|
|
`{not valid json at all`,
|
|
|
|
|
)
|
|
|
|
|
writeJSONL(t, dir, "valid.jsonl",
|
2026-02-22 21:00:17 +00:00
|
|
|
toolUseEntry(ts(0), "Bash", "t1", map[string]any{
|
test: add comprehensive Phase 0 test suite — 67 tests, 90.9% coverage
Add parser_test.go (22 tests), search_test.go (9 tests), html_test.go (6 tests),
video_test.go (12 tests), and bench_test.go (4 benchmarks) covering all Phase 0
TODO items:
- ParseTranscript: minimal JSONL, all 7 tool types, errors, truncated/malformed
input, large sessions (1100+ events), nested array/map results, mixed content
- ListSessions: empty dir, single/multi sorted, non-JSONL ignored, modtime fallback
- extractToolInput: all tool types plus nil, invalid JSON, unknown tool fallback
- extractResultContent: string, array, map, and other types
- Search: empty dir, no matches, multi-match, case insensitive, output matching
- RenderHTML: basic, empty, errors, XSS escaping, label types, invalid path
- generateTape/extractCommand: all event types, empty/failed commands, truncation
- Benchmarks: 2.2MB and 11MB ParseTranscript, ListSessions, Search with b.Loop()
go vet ./... clean, go test -race ./... clean.
Co-Authored-By: Virgil <virgil@lethean.io>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-20 05:00:38 +00:00
|
|
|
"command": "go test ./...",
|
|
|
|
|
}),
|
|
|
|
|
toolResultEntry(ts(1), "t1", "PASS", false),
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
results, err := Search(dir, "go test")
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
assert.Len(t, results, 1, "should still find matches in valid sessions")
|
2026-02-20 00:42:11 +00:00
|
|
|
}
|