33
44local M = {}
55
6+ function M .replay_setup ()
7+ local config = require (' opencode.config' )
8+ local config_file = require (' opencode.config_file' )
9+ local state = require (' opencode.state' )
10+ local ui = require (' opencode.ui.ui' )
11+ local renderer = require (' opencode.ui.renderer' )
12+
13+ local empty_promise = require (' opencode.promise' ).new ():resolve (nil )
14+ config_file .config_promise = empty_promise
15+ config_file .project_promise = empty_promise
16+ config_file .providers_promise = empty_promise
17+
18+ state .windows = ui .create_windows ()
19+
20+ -- we don't change any changes on session
21+ renderer ._cleanup_subscriptions ()
22+ renderer .reset ()
23+
24+ if not config .config then
25+ config .config = vim .deepcopy (config .defaults )
26+ end
27+ end
28+
629-- Create a temporary file with content
730function M .create_temp_file (content )
831 local tmp_file = vim .fn .tempname ()
932 local file = io.open (tmp_file , ' w' )
33+
34+ if not file then
35+ return nil
36+ end
37+
1038 file :write (content or ' Test file content' )
1139 file :close ()
1240 return tmp_file
2654-- Close a buffer
2755function M .close_buffer (bufnr )
2856 if bufnr and vim .api .nvim_buf_is_valid (bufnr ) then
29- pcall (vim .cmd , ' bdelete! ' .. bufnr )
57+ pcall (vim .api . nvim_command , ' bdelete! ' .. bufnr )
3058 end
3159end
3260
@@ -42,17 +70,18 @@ function M.reset_editor()
4270 for _ , bufnr in ipairs (vim .api .nvim_list_bufs ()) do
4371 -- Skip non-existing or invalid buffers
4472 if vim .api .nvim_buf_is_valid (bufnr ) then
45- pcall (vim .cmd , ' bdelete! ' .. bufnr )
73+ pcall (vim .api . nvim_command , ' bdelete! ' .. bufnr )
4674 end
4775 end
4876 -- Reset any other editor state as needed
49- pcall (vim .cmd , ' silent! %bwipeout!' )
77+ pcall (vim .api . nvim_command , ' silent! %bwipeout!' )
5078end
5179
5280-- Mock input function
5381function M .mock_input (return_value )
5482 local original_input = vim .fn .input
55- vim .fn .input = function (...)
83+ --- @diagnostic disable-next-line : duplicate-set-field
84+ vim .fn .input = function (_ )
5685 return return_value
5786 end
5887 return function ()
@@ -65,6 +94,7 @@ function M.mock_notify()
6594 local notifications = {}
6695 local original_notify = vim .notify
6796
97+ --- @diagnostic disable-next-line : duplicate-set-field
6898 vim .notify = function (msg , level , opts )
6999 table.insert (notifications , {
70100 msg = msg ,
@@ -90,6 +120,7 @@ function M.mock_time_ago()
90120 local util = require (' opencode.util' )
91121 local original_time_ago = util .time_ago
92122
123+ --- @diagnostic disable-next-line : duplicate-set-field
93124 util .time_ago = function (timestamp )
94125 if timestamp > 1e12 then
95126 timestamp = math.floor (timestamp / 1000 )
0 commit comments