Skip to content

Commit c7267bd

Browse files
committed
feat: add messagelist test infrastructure and tests
- Add domaintest factories (NewMessage, NewTextBlock, etc.) - Add messagelisttest helper with real SQLite, mock chat client - Add mouse_test.go: selection math tests - Add update_test.go: message dispatch ordering - Add turn_test.go: state machine transitions - Add user_test.go: rendering width contracts - Add tool_test.go: status rendering for all states - Update TESTING.md with real vs mock guidance - Fix: thinking animation not stopping after stream completed - Fix: copy/highlight including border characters
1 parent d31d0af commit c7267bd

32 files changed

Lines changed: 2017 additions & 404 deletions

‎Taskfile.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ tasks:
5353
cmds:
5454
- go generate ./internal/powersync
5555
- go generate ./internal/sqlite
56-
- cp ../control-plane/internal/powersync/schema.sql internal/chat/tools/query_schema.sql
56+
- sed '/^-- Auto-generated/d; /^-- Run .task generate/d' ../control-plane/internal/powersync/schema.sql > internal/chat/tools/query_schema.sql
5757

5858
# ===========================================================================
5959
# Build

‎docs/TESTING.md‎

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Test behavior, not implementation. A good test breaks when something stops worki
44

55
## Three Types of Tests
66

7-
**Unit tests** run fast with no external dependencies. They mock interfaces and test logic in isolation.
7+
**Unit tests** run fast with no external services. Use real local deps (SQLite, theme), mock remote ones (APIs).
88

99
```bash
1010
task test
@@ -47,9 +47,23 @@ func TestSync_Connect(t *testing.T) {
4747
}
4848
```
4949

50+
### Real vs Mock
51+
52+
Use real things when they're cheap. Mock only what's expensive or external.
53+
54+
| Dependency | Strategy | Why |
55+
|------------|----------|-----|
56+
| SQLite | Real — `sqlitetest.OpenBareDB(t)` or `dbtest.OpenTestDB(t)` | Local, fast, tmpdir-based, auto-cleanup |
57+
| Theme | Real — `styles.NewTheme(true)` | Just a struct with colors |
58+
| Logger | Real — `logtest.NewScope(t)` | Writes to `testing.T`, shows on failure |
59+
| Chat API | Mock — `chattest.MockClient{}` | Hits remote server |
60+
| Tool registry | `nil` or partial — `&chattools.Registry{Query: ...}` | Only construct what you're testing |
61+
62+
The rule: if you can construct it in a test without network, credentials, or slow setup, use the real thing. Mocks hide bugs.
63+
5064
### Mock with Structs
5165

52-
Don't use mocking frameworks. Write simple structs:
66+
When you do need mocks, don't use mocking frameworks. Write simple structs:
5367

5468
```go
5569
type mockClient struct {

‎internal/api/datadog_account_service.go‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,11 @@ type DatadogAccountStatus struct {
8585
BrokenServices int
8686
DisabledServices int
8787
InactiveServices int
88-
SavedCount int // Number of log events saved (for progress display)
88+
AnalyzedCount int // Number of log events analyzed (for progress display)
89+
ResolvedCount int // Log events with all policies acted on
90+
CleanCount int // Log events analyzed with no issues
91+
PendingCount int // Log events with policies awaiting action
92+
PendingPolicyCount int // Policies awaiting user action
8993
ReadyForUse bool // Whether the account has enough data to proceed
9094
}
9195

@@ -232,7 +236,11 @@ func (s *DatadogAccountService) GetStatus(ctx context.Context, datadogAccountID
232236
BrokenServices: statusNode.LogBrokenServices,
233237
DisabledServices: statusNode.LogDisabledServices,
234238
InactiveServices: statusNode.LogInactiveServices,
235-
SavedCount: statusNode.LogSavedCount,
239+
AnalyzedCount: statusNode.LogAnalyzedCount,
240+
ResolvedCount: statusNode.LogResolvedCount,
241+
CleanCount: statusNode.LogCleanCount,
242+
PendingCount: statusNode.LogPendingCount,
243+
PendingPolicyCount: statusNode.LogPendingPolicyCount,
236244
ReadyForUse: statusNode.ReadyForUse,
237245
}
238246

‎internal/api/gen/generated.go‎

Lines changed: 70 additions & 23 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎internal/api/gen/queries/datadog_accounts.graphql‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,11 @@ query GetDatadogAccountStatus($id: ID!) {
5151
logBrokenServices
5252
logDisabledServices
5353
logInactiveServices
54-
logSavedCount
54+
logAnalyzedCount
55+
logResolvedCount
56+
logCleanCount
57+
logPendingCount
58+
logPendingPolicyCount
5559
readyForUse
5660
}
5761
}

0 commit comments

Comments
 (0)