~bigbes/lethe

ref: f0f651bfc74681988f56bd610074e1dce6dbee1c lethe/internal/collector/ingest/runner_helpers_test.go -rw-r--r-- 2.1 KiB
f0f651bf — Eugene Blikh feat: add search data layer — adapter, highlight helper, hook, and tests 24 days ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package ingest

import (
	"context"
	"encoding/json"
	"errors"
	"path/filepath"
	"testing"
	"time"

	"sourcecraft.dev/bigbes/lethe/internal/collector/config"
	"sourcecraft.dev/bigbes/lethe/internal/collector/state"
	"sourcecraft.dev/bigbes/lethe/internal/shared/wire"
)

var (
	errParseBoom = errors.New("parse boom")
	errPostBoom  = errors.New("post boom")
)

func turnEvent(seq int64, content string) wire.TurnEvent {
	return wire.TurnEvent{
		Tool:      "claude-code",
		Host:      "test-host",
		SessionID: "session-1",
		TurnID:    content,
		Seq:       seq,
		Role:      "user",
		Timestamp: 123,
		Content:   content,
		SessionMeta: wire.SessionMeta{
			SourceFile: "source.jsonl",
		},
	}
}

func resultJSON(result Result) string {
	data, err := json.Marshal(result)
	if err != nil {
		panic(err)
	}
	return string(data)
}

func testConfig() config.Config {
	return config.Config{
		Host:      "test-host",
		ServerURL: "http://127.0.0.1",
		Outbox:    config.OutboxConfig{MaxBytes: 1024 * 1024},
		HTTP:      config.HTTPConfig{Timeout: 30 * time.Second},
	}
}

func testSource(t *testing.T, tool string, maxLines int, maxBytes int64) config.SourceConfig {
	t.Helper()
	return config.SourceConfig{
		Tool:          tool,
		Path:          t.TempDir(),
		PollInterval:  time.Millisecond,
		BatchMaxLines: maxLines,
		BatchMaxBytes: maxBytes,
	}
}

func openTestStore(t *testing.T, ctx context.Context) *state.Store {
	t.Helper()
	store, err := state.Open(ctx, filepath.Join(t.TempDir(), "state.db"))
	if err != nil {
		t.Fatalf("Open: %v", err)
	}
	t.Cleanup(func() { _ = store.Close() })
	return store
}

func assertOffset(t *testing.T, ctx context.Context, store *state.Store, tool, file string, want int64) {
	t.Helper()
	got, err := store.GetOffset(ctx, tool, file)
	if err != nil {
		t.Fatalf("GetOffset: %v", err)
	}
	if got != want {
		t.Errorf("offset = %d, want %d", got, want)
	}
}

func assertOutboxCount(t *testing.T, ctx context.Context, store *state.Store, want int64) {
	t.Helper()
	st, err := store.Stats(ctx)
	if err != nil {
		t.Fatalf("Stats: %v", err)
	}
	if st.OutboxCount != want {
		t.Errorf("OutboxCount = %d, want %d", st.OutboxCount, want)
	}
}