-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathopencode.test.ts
More file actions
87 lines (76 loc) · 2.44 KB
/
Copy pathopencode.test.ts
File metadata and controls
87 lines (76 loc) · 2.44 KB
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
import { describe, it, expect, mock, beforeEach } from 'bun:test';
import { OpencodeOrchestrator } from '../src/opencode.js';
describe('OpencodeOrchestrator', () => {
beforeEach(() => {
mock.clearAllMocks();
});
it('returns auth status from getAuthStatus() without throwing on initialize()', async () => {
const mockClient = {
provider: {
list: mock().mockResolvedValue({
data: {
default: {},
connected: [],
all: [
{
id: 'anthropic',
name: 'Anthropic',
env: ['ANTHROPIC_API_KEY'],
},
],
},
}),
},
} as any;
const mockServer = { close: mock() } as any;
const orchestrator = await OpencodeOrchestrator.initialize(undefined, mockClient, mockServer);
const status = await orchestrator.getAuthStatus();
expect(status.authenticated).toBe(false);
expect(status.connected).toEqual([]);
});
it('times out and aborts if prompt takes too long', async () => {
const abortMock = mock().mockResolvedValue({});
const promptMock = mock().mockImplementation(() => {
return new Promise((_resolve) => {
// Never resolves to simulate a hung provider
});
});
const mockClient = {
provider: {
list: mock().mockResolvedValue({
data: {
default: { model: 'anthropic/claude' },
connected: ['anthropic'],
all: [],
},
}),
},
session: {
create: mock().mockResolvedValue({ data: { id: 'test-session' } }),
prompt: promptMock,
abort: abortMock,
},
event: {
subscribe: mock().mockResolvedValue({ stream: [] }),
},
} as any;
const mockServer = { close: mock() } as any;
const orchestrator = await OpencodeOrchestrator.initialize(undefined, mockClient, mockServer);
const task = {
id: '1',
description: 'Test task',
goal: 'Do nothing',
category: 'test' as const,
systemPrompt: 'You are helpful',
expectedOutputs: [],
writeAllowlist: [],
verification: [],
maxCost: 1,
timeout: 0.1, // 100ms timeout for test
};
const result = await orchestrator.executeTask(task);
expect(result.success).toBe(false);
expect(result.message).toMatch(/Task timed out/);
expect(abortMock).toHaveBeenCalledWith({ path: { id: 'test-session' } });
});
});