Skip to content

Commit 5a0b1e8

Browse files
authored
Merge pull request #65 from codervisor/copilot/fix-bug-in-spec-14
Fix workspace upsert constraint mismatch in batch events API
2 parents fef678f + 9f343b6 commit 5a0b1e8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+1297
-938
lines changed

packages/ai/src/__tests__/parsers/copilot.test.ts

Lines changed: 114 additions & 101 deletions
Large diffs are not rendered by default.

packages/ai/src/parsers/base.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,14 @@
77
* Supports four-level hierarchy: Application → Workspace → Session → Turn → Message
88
*/
99

10-
import type { ChatSession, ChatTurn, ChatMessage, Application, Workspace, ParserType } from '../types/index.js';
10+
import type {
11+
ChatSession,
12+
ChatTurn,
13+
ChatMessage,
14+
Application,
15+
Workspace,
16+
ParserType,
17+
} from '../types/index.js';
1118

1219
/**
1320
* Abstract base class for AI assistant parsers

packages/ai/src/parsers/copilot.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,11 @@ export class CopilotParser extends BaseParser {
6767

6868
if (applications.length > 0) {
6969
const totalWorkspaces = applications.reduce((sum, app) => sum + (app.workspaceCount || 0), 0);
70-
console.log(chalk.green(`✓ Found ${applications.length} VS Code installation(s) with ${totalWorkspaces} total workspaces`));
70+
console.log(
71+
chalk.green(
72+
`✓ Found ${applications.length} VS Code installation(s) with ${totalWorkspaces} total workspaces`,
73+
),
74+
);
7175
}
7276

7377
return applications;
@@ -227,7 +231,10 @@ export class CopilotParser extends BaseParser {
227231

228232
return session;
229233
} catch (error) {
230-
console.error(chalk.red(`Error parsing chat session ${sessionId}:`), error instanceof Error ? error.message : String(error));
234+
console.error(
235+
chalk.red(`Error parsing chat session ${sessionId}:`),
236+
error instanceof Error ? error.message : String(error),
237+
);
231238
return null;
232239
}
233240
}

packages/ai/src/types/chat-session.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Hierarchy: Application → Workspace → Chat Session → Chat Turn → Chat Message
44
*/
55

6-
import type { ChatTurn } from "./chat-turn.js";
6+
import type { ChatTurn } from './chat-turn.js';
77

88
// Session-level metadata based on actual Copilot data structure
99
export interface ChatSessionMetadata {

packages/ai/src/types/chat-turn.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
/**
22
* ChatTurn model for grouping related messages in AI Chat processing
33
* Hierarchy: Application → Workspace → Chat Session → Chat Turn → Chat Message
4-
*
4+
*
55
* A ChatTurn represents one complete request-response cycle:
66
* - User makes a request (user message)
77
* - Assistant responds with multiple actions (assistant messages)
88
*/
99

10-
import type { ChatMessage } from "./chat-message.js";
10+
import type { ChatMessage } from './chat-message.js';
1111

1212
// Turn-level metadata based on actual Copilot data structure
1313
export interface ChatTurnMetadata {

packages/ai/tsconfig.json

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,9 @@
99
"incremental": false,
1010
"baseUrl": ".",
1111
"paths": {
12-
"@/*": [
13-
"./src/*"
14-
]
12+
"@/*": ["./src/*"]
1513
}
1614
},
17-
"include": [
18-
"src/**/*"
19-
],
20-
"exclude": [
21-
"node_modules",
22-
"build",
23-
"**/*.test.ts",
24-
"**/*.spec.ts"
25-
]
15+
"include": ["src/**/*"],
16+
"exclude": ["node_modules", "build", "**/*.test.ts", "**/*.spec.ts"]
2617
}

packages/collector/README.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,13 @@ devlog-collector status
6666
### Real-Time Monitoring Only
6767

6868
The collector currently operates in **real-time mode only**. When started:
69+
6970
- ✅ Discovers agent log file locations automatically
7071
- ✅ Watches files for future changes (using fsnotify)
7172
- ❌ Does NOT read existing historical log data
7273

7374
This means:
75+
7476
- Events are captured from the moment the collector starts
7577
- Historical agent activity before collector startup is not captured
7678
- If the collector is stopped, events during downtime are not recovered
@@ -84,14 +86,15 @@ A backfill feature is planned for future releases to address these limitations:
8486
devlog-collector backfill [options]
8587
--agent <name> # Specific agent (copilot, claude, cursor)
8688
--from <date> # Start date for historical collection
87-
--to <date> # End date for historical collection
89+
--to <date> # End date for historical collection
8890
--dry-run # Preview what would be collected
8991

9092
# Or as a startup flag
9193
devlog-collector start --backfill --backfill-days=7
9294
```
9395

9496
**Use cases for historical collection:**
97+
9598
- Initial setup with existing context from past sessions
9699
- Gap recovery after collector downtime or system restarts
97100
- Historical analysis of past AI agent activities
@@ -113,20 +116,20 @@ Example configuration:
113116
"backendUrl": "https://api.devlog.io",
114117
"apiKey": "${DEVLOG_API_KEY}",
115118
"projectId": "my-project",
116-
119+
117120
"collection": {
118121
"batchSize": 100,
119122
"batchInterval": "5s",
120123
"maxRetries": 3,
121124
"retryBackoff": "exponential"
122125
},
123-
126+
124127
"buffer": {
125128
"enabled": true,
126129
"maxSize": 10000,
127130
"dbPath": "~/.devlog/buffer.db"
128131
},
129-
132+
130133
"agents": {
131134
"copilot": {
132135
"enabled": true,
@@ -141,7 +144,7 @@ Example configuration:
141144
"logPath": "auto"
142145
}
143146
},
144-
147+
145148
"logging": {
146149
"level": "info",
147150
"file": "~/.devlog/collector.log"

packages/collector/internal/integration/README.md

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ This directory contains end-to-end integration tests for the Devlog Collector.
55
## Overview
66

77
Integration tests verify that all components work correctly together:
8+
89
- Agent adapters (log parsing)
910
- File system watcher (monitoring)
1011
- HTTP client (batching, retry)
@@ -14,60 +15,72 @@ Integration tests verify that all components work correctly together:
1415
## Test Scenarios
1516

1617
### 1. `TestEndToEnd_CopilotLogParsing`
18+
1719
Verifies the complete flow from Copilot log file to backend API.
1820

1921
**What it tests**:
22+
2023
- Log file parsing with Copilot adapter
2124
- Event extraction and formatting
2225
- HTTP client batching and sending
2326
- Backend API integration
2427
- Data integrity through the pipeline
2528

2629
**Expected behavior**:
30+
2731
- 2 events parsed from sample log
2832
- All events reach backend
2933
- Event metadata preserved (agent ID, type, file path)
3034

3135
### 2. `TestEndToEnd_OfflineBuffering`
36+
3237
Verifies offline buffering when backend is unavailable.
3338

3439
**What it tests**:
40+
3541
- Detection of backend failures
3642
- Automatic buffering to SQLite
3743
- Event persistence across restarts
3844
- Automatic retry when backend recovers
3945
- Buffer cleanup after successful send
4046

4147
**Expected behavior**:
48+
4249
- Events buffered when backend down (503)
4350
- Events retrieved from buffer intact
4451
- Events sent successfully when backend up
4552
- Buffer cleared after send
4653

4754
### 3. `TestEndToEnd_LogRotation`
55+
4856
Verifies handling of log file rotation.
4957

5058
**What it tests**:
59+
5160
- Processing events from initial file
5261
- Detection of file rotation
5362
- Processing events from new file
5463
- No data loss during rotation
5564

5665
**Expected behavior**:
66+
5767
- Events from both files processed
5868
- Rotation handled gracefully
5969
- No duplicate or missed events
6070

6171
### 4. `TestEndToEnd_HighVolume`
72+
6273
Verifies performance with many events.
6374

6475
**What it tests**:
76+
6577
- Parsing 100 events efficiently
6678
- Batching optimization
6779
- Memory management
6880
- Throughput
6981

7082
**Expected behavior**:
83+
7184
- 100/100 events processed (100% success)
7285
- Processing completes in <5 seconds
7386
- No memory leaks
@@ -91,6 +104,7 @@ go test ./internal/integration -short
91104
## Test Environment
92105

93106
Each test creates an isolated environment:
107+
94108
- Temporary directory (auto-cleanup)
95109
- Mock HTTP backend
96110
- Real components (minimal mocking)
@@ -116,7 +130,7 @@ func TestEndToEnd_YourScenario(t *testing.T) {
116130
// Initialize components
117131
registry := adapters.DefaultRegistry("test-project")
118132
adapter := adapters.NewCopilotAdapter("test-project")
119-
133+
120134
// ... rest of setup
121135

122136
// Write test log files
@@ -142,17 +156,20 @@ func TestEndToEnd_YourScenario(t *testing.T) {
142156
## Debugging Failed Tests
143157

144158
### Enable verbose logging
159+
145160
```go
146161
log := logrus.New()
147162
log.SetLevel(logrus.DebugLevel)
148163
```
149164

150165
### Check test output
166+
151167
```bash
152168
go test ./internal/integration -v 2>&1 | tee test.log
153169
```
154170

155171
### Inspect temp files
172+
156173
```go
157174
// Add this to prevent cleanup
158175
tmpDir := t.TempDir()
@@ -163,16 +180,19 @@ t.Logf("Test directory: %s", tmpDir)
163180
## Common Issues
164181

165182
**Events not received by backend**:
183+
166184
- Check batching delay (increase wait time)
167185
- Verify log format matches adapter expectations
168186
- Check mock server handler logic
169187

170188
**Buffer not storing events**:
189+
171190
- Ensure SendSingleEvent used (not SendEvent)
172191
- Verify backend returns failure status
173192
- Check buffer configuration
174193

175194
**Timing issues**:
195+
176196
- Increase sleep durations
177197
- Use polling instead of fixed delays
178198
- Check debounce settings
@@ -189,6 +209,7 @@ For continuous integration:
189209
```
190210
191211
For faster CI (skip slow tests):
212+
192213
```bash
193214
go test ./internal/integration -short
194215
```
@@ -198,7 +219,7 @@ go test ./internal/integration -short
198219
Expected performance on modern hardware:
199220

200221
- Log parsing: ~5,000 events/second
201-
- HTTP batching: ~1,000 events/second
222+
- HTTP batching: ~1,000 events/second
202223
- Buffer operations: <1ms per event
203224
- End-to-end latency: <100ms per event
204225

@@ -211,6 +232,7 @@ Expected performance on modern hardware:
211232
## Support
212233

213234
For issues with integration tests:
235+
214236
1. Check test output for specific failures
215237
2. Enable debug logging
216238
3. Verify component configurations

0 commit comments

Comments
 (0)