Skip to content

Commit 335f15c

Browse files
committed
test(replay): fix full session replay
The issue is a bit subtle: the event notification about the session changing from nil to an id gets wrapped in vim.schedule but that means it gets delivered after we've loaded the fulls session, which causes us to clear the whole session right after we just loaded it, leaving the output blank. It's possible that we might want to not wrap state notifications in vim.schedule and expect listeners to handle cases where they can't be in a fast context. The primary benefit of that would be guaranteed ordering of events. For example, in this case, the event that the session was set would've been processed before we loaded the session so the issue wouldn't exist.
1 parent 338efa8 commit 335f15c

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

tests/helpers.lua

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,11 @@ function M.replay_setup()
2121
end
2222

2323
state.current_mode = 'build' -- default mode for tests
24-
state.windows = ui.create_windows()
2524

26-
-- we use the event manager to dispatch events
25+
-- we use the event manager to dispatch events, have to setup before ui.create_windows
2726
require('opencode.event_manager').setup()
2827

29-
renderer.setup_subscriptions()
28+
state.windows = ui.create_windows()
3029

3130
renderer.reset()
3231

tests/manual/renderer_replay.lua

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -196,13 +196,14 @@ function M.replay_full_session()
196196
end
197197

198198
state.active_session = helpers.get_session_from_events(M.events, true)
199-
local session_data = helpers.load_session_from_events(M.events)
199+
vim.schedule(function()
200+
local session_data = helpers.load_session_from_events(M.events)
200201

201-
renderer.reset()
202-
renderer._render_full_session_data(session_data)
203-
state.job_count = 0
202+
renderer._render_full_session_data(session_data)
203+
state.job_count = 0
204204

205-
vim.notify('Rendered full session from loaded events', vim.log.levels.INFO)
205+
vim.notify('Rendered full session from loaded events', vim.log.levels.INFO)
206+
end)
206207
return true
207208
end
208209

0 commit comments

Comments
 (0)