Skip to content

Commit dff8238

Browse files
committed
test: create unit and synthetic replay test
1 parent 4994d4a commit dff8238

3 files changed

Lines changed: 381 additions & 0 deletions

File tree

Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
{
2+
"actions": [],
3+
"extmarks": [
4+
[
5+
1,
6+
1,
7+
0,
8+
{
9+
"ns_id": 3,
10+
"priority": 10,
11+
"right_gravity": true,
12+
"virt_text": [
13+
[
14+
"▌󰭻 ",
15+
"OpencodeMessageRoleUser"
16+
],
17+
[
18+
" "
19+
],
20+
[
21+
"USER",
22+
"OpencodeMessageRoleUser"
23+
],
24+
[
25+
"",
26+
"OpencodeHint"
27+
],
28+
[
29+
" [msg_0000000000001]",
30+
"OpencodeHint"
31+
]
32+
],
33+
"virt_text_hide": false,
34+
"virt_text_pos": "win_col",
35+
"virt_text_repeat_linebreak": false,
36+
"virt_text_win_col": -3
37+
}
38+
],
39+
[
40+
2,
41+
1,
42+
0,
43+
{
44+
"ns_id": 3,
45+
"priority": 9,
46+
"right_gravity": true,
47+
"virt_text": [
48+
[
49+
" 2023-11-14 22:13:20",
50+
"OpencodeHint"
51+
]
52+
],
53+
"virt_text_hide": false,
54+
"virt_text_pos": "right_align",
55+
"virt_text_repeat_linebreak": false
56+
}
57+
],
58+
[
59+
3,
60+
2,
61+
0,
62+
{
63+
"ns_id": 3,
64+
"priority": 4096,
65+
"right_gravity": true,
66+
"virt_text": [
67+
[
68+
"",
69+
"OpencodeMessageRoleUser"
70+
]
71+
],
72+
"virt_text_hide": false,
73+
"virt_text_pos": "win_col",
74+
"virt_text_repeat_linebreak": true,
75+
"virt_text_win_col": -3
76+
}
77+
],
78+
[
79+
4,
80+
3,
81+
0,
82+
{
83+
"ns_id": 3,
84+
"priority": 4096,
85+
"right_gravity": true,
86+
"virt_text": [
87+
[
88+
"",
89+
"OpencodeMessageRoleUser"
90+
]
91+
],
92+
"virt_text_hide": false,
93+
"virt_text_pos": "win_col",
94+
"virt_text_repeat_linebreak": true,
95+
"virt_text_win_col": -3
96+
}
97+
],
98+
[
99+
5,
100+
6,
101+
0,
102+
{
103+
"ns_id": 3,
104+
"priority": 10,
105+
"right_gravity": true,
106+
"virt_text": [
107+
[
108+
"",
109+
"OpencodeMessageRoleAssistant"
110+
],
111+
[
112+
" "
113+
],
114+
[
115+
"BUILD",
116+
"OpencodeMessageRoleAssistant"
117+
],
118+
[
119+
" claude-sonnet-4-5",
120+
"OpencodeHint"
121+
],
122+
[
123+
" [msg_0000000000002]",
124+
"OpencodeHint"
125+
]
126+
],
127+
"virt_text_hide": false,
128+
"virt_text_pos": "win_col",
129+
"virt_text_repeat_linebreak": false,
130+
"virt_text_win_col": -3
131+
}
132+
],
133+
[
134+
6,
135+
6,
136+
0,
137+
{
138+
"ns_id": 3,
139+
"priority": 9,
140+
"right_gravity": true,
141+
"virt_text": [
142+
[
143+
" 2023-11-14 22:13:21",
144+
"OpencodeHint"
145+
]
146+
],
147+
"virt_text_hide": false,
148+
"virt_text_pos": "right_align",
149+
"virt_text_repeat_linebreak": false
150+
}
151+
]
152+
],
153+
"lines": [
154+
"----",
155+
"",
156+
"",
157+
"Can you help me fix this bug?",
158+
"",
159+
"----",
160+
"",
161+
"",
162+
"Sure, I can help with that.",
163+
"",
164+
""
165+
],
166+
"timestamp": 1773091221
167+
}
168+
Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
[
2+
{
3+
"type": "message.updated",
4+
"properties": {
5+
"info": {
6+
"id": "msg_0000000000001",
7+
"sessionID": "ses_0000000000001",
8+
"role": "user",
9+
"agent": "build",
10+
"time": { "created": 1700000000000 },
11+
"model": { "providerID": "anthropic", "modelID": "claude-sonnet-4-5" }
12+
}
13+
}
14+
},
15+
{
16+
"type": "message.part.updated",
17+
"properties": {
18+
"part": {
19+
"id": "prt_0000000000001",
20+
"messageID": "msg_0000000000001",
21+
"sessionID": "ses_0000000000001",
22+
"type": "text",
23+
"text": "Can you help me fix this bug?"
24+
}
25+
}
26+
},
27+
{
28+
"type": "session.updated",
29+
"properties": {
30+
"info": {
31+
"id": "ses_0000000000001",
32+
"title": "Bug fix session",
33+
"time": { "created": 1700000000000, "updated": 1700000001000 }
34+
}
35+
}
36+
},
37+
{
38+
"type": "session.status",
39+
"properties": {
40+
"sessionID": "ses_0000000000001",
41+
"status": { "type": "busy" }
42+
}
43+
},
44+
{
45+
"type": "message.updated",
46+
"properties": {
47+
"info": {
48+
"id": "msg_0000000000002",
49+
"sessionID": "ses_0000000000001",
50+
"role": "assistant",
51+
"agent": "build",
52+
"mode": "build",
53+
"providerID": "anthropic",
54+
"modelID": "claude-sonnet-4-5",
55+
"parentID": "msg_0000000000001",
56+
"time": { "created": 1700000001000 },
57+
"cost": 0,
58+
"tokens": { "input": 0, "output": 0, "reasoning": 0, "cache": { "read": 0, "write": 0 } }
59+
}
60+
}
61+
},
62+
{
63+
"type": "session.status",
64+
"properties": {
65+
"sessionID": "ses_0000000000001",
66+
"status": {
67+
"type": "retry",
68+
"message": "Provider is overloaded",
69+
"attempt": 1,
70+
"next": 1700000011000
71+
}
72+
}
73+
},
74+
{
75+
"type": "session.status",
76+
"properties": {
77+
"sessionID": "ses_0000000000001",
78+
"status": { "type": "busy" }
79+
}
80+
},
81+
{
82+
"type": "session.status",
83+
"properties": {
84+
"sessionID": "ses_0000000000001",
85+
"status": {
86+
"type": "retry",
87+
"message": "Provider is overloaded",
88+
"attempt": 2,
89+
"next": 1700000021000
90+
}
91+
}
92+
},
93+
{
94+
"type": "session.status",
95+
"properties": {
96+
"sessionID": "ses_0000000000001",
97+
"status": { "type": "busy" }
98+
}
99+
},
100+
{
101+
"type": "session.status",
102+
"properties": {
103+
"sessionID": "ses_0000000000001",
104+
"status": {
105+
"type": "retry",
106+
"message": "Provider is overloaded",
107+
"attempt": 3,
108+
"next": 1700000041000
109+
}
110+
}
111+
},
112+
{
113+
"type": "session.status",
114+
"properties": {
115+
"sessionID": "ses_0000000000001",
116+
"status": { "type": "busy" }
117+
}
118+
},
119+
{
120+
"type": "message.part.updated",
121+
"properties": {
122+
"part": {
123+
"id": "prt_0000000000002",
124+
"messageID": "msg_0000000000002",
125+
"sessionID": "ses_0000000000001",
126+
"type": "text",
127+
"text": "Sure, I can help with that."
128+
}
129+
}
130+
},
131+
{
132+
"type": "message.updated",
133+
"properties": {
134+
"info": {
135+
"id": "msg_0000000000002",
136+
"sessionID": "ses_0000000000001",
137+
"role": "assistant",
138+
"agent": "build",
139+
"mode": "build",
140+
"providerID": "anthropic",
141+
"modelID": "claude-sonnet-4-5",
142+
"parentID": "msg_0000000000001",
143+
"time": { "created": 1700000001000, "completed": 1700000050000 },
144+
"cost": 0,
145+
"tokens": { "input": 100, "output": 20, "reasoning": 0, "cache": { "read": 0, "write": 0 } }
146+
}
147+
}
148+
},
149+
{
150+
"type": "session.status",
151+
"properties": {
152+
"sessionID": "ses_0000000000001",
153+
"status": { "type": "idle" }
154+
}
155+
}
156+
]
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
local state = require('opencode.state')
2+
local loading_animation = require('opencode.ui.loading_animation')
3+
4+
describe('loading_animation status text', function()
5+
local original_time
6+
7+
before_each(function()
8+
original_time = os.time
9+
loading_animation._animation.status_data = nil
10+
state.active_session = nil
11+
end)
12+
13+
after_each(function()
14+
os.time = original_time
15+
loading_animation._animation.status_data = nil
16+
state.active_session = nil
17+
end)
18+
19+
it('renders busy as thinking text', function()
20+
local text = loading_animation._format_status_text({ type = 'busy' })
21+
assert.are.equal('Thinking... ', text)
22+
end)
23+
24+
it('counts down retry seconds dynamically', function()
25+
loading_animation._animation.status_data = {
26+
type = 'retry',
27+
message = 'Provider is overloaded',
28+
attempt = 2,
29+
next = 1018000,
30+
}
31+
32+
os.time = function()
33+
return 1000
34+
end
35+
local first = loading_animation._get_display_text()
36+
37+
os.time = function()
38+
return 1005
39+
end
40+
local second = loading_animation._get_display_text()
41+
42+
assert.is_truthy(first:find('in 18s', 1, true))
43+
assert.is_truthy(second:find('in 13s', 1, true))
44+
end)
45+
46+
it('ignores status updates for non-active sessions', function()
47+
state.active_session = { id = 'ses_active' }
48+
loading_animation._animation.status_data = nil
49+
50+
loading_animation.on_session_status({
51+
sessionID = 'ses_other',
52+
status = { type = 'retry', message = 'Provider is overloaded' },
53+
})
54+
55+
assert.is_nil(loading_animation._animation.status_data)
56+
end)
57+
end)

0 commit comments

Comments
 (0)