Skip to content

Commit 679cf7f

Browse files
committed
test: add list_permissions mock and permission restoration test
Add list_permissions to the shared mock API client so tests exercising render_full_session() don't crash on the new restore_pending_permissions code path. Add a dedicated test verifying that pending permissions are fetched and re-queued via on_permission_updated after a session switch.
1 parent ab1f44c commit 679cf7f

2 files changed

Lines changed: 49 additions & 0 deletions

File tree

tests/unit/services_session_runtime_spec.lua

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,52 @@ describe('opencode.services.session_runtime', function()
368368
mounted_stub:revert()
369369
state.ui.set_windows(nil)
370370
end)
371+
372+
it('restores pending permissions after a full session render', function()
373+
local renderer = require('opencode.ui.renderer')
374+
local permission_window = require('opencode.ui.permission_window')
375+
local events = require('opencode.ui.renderer.events')
376+
377+
state.session.set_active({ id = 'sess1' })
378+
state.ui.set_windows({ output_buf = 1, output_win = 2 })
379+
380+
local mounted_stub = stub(require('opencode.ui.output_window'), 'mounted').returns(true)
381+
local fetch_stub = stub(session, 'get_messages').invokes(function()
382+
return Promise.new():resolve({})
383+
end)
384+
local render_stub = stub(renderer, '_render_full_session_data')
385+
local list_questions_stub = stub(state.api_client, 'list_questions').invokes(function()
386+
return Promise.new():resolve({})
387+
end)
388+
local list_permissions_stub = stub(state.api_client, 'list_permissions').invokes(function()
389+
return Promise.new():resolve({
390+
{
391+
id = 'perm1',
392+
sessionID = 'sess1',
393+
permission = 'bash',
394+
patterns = { 'echo hello' },
395+
},
396+
})
397+
end)
398+
local on_permission_stub = stub(events, 'on_permission_updated')
399+
400+
renderer.render_full_session():wait()
401+
402+
assert.stub(on_permission_stub).was_called_with({
403+
id = 'perm1',
404+
sessionID = 'sess1',
405+
permission = 'bash',
406+
patterns = { 'echo hello' },
407+
})
408+
409+
on_permission_stub:revert()
410+
list_permissions_stub:revert()
411+
list_questions_stub:revert()
412+
render_stub:revert()
413+
fetch_stub:revert()
414+
mounted_stub:revert()
415+
state.ui.set_windows(nil)
416+
end)
371417
end)
372418

373419
describe('markdown rendering metadata', function()

tests/unit/services_spec_support.lua

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ function M.mock_api_client()
2424
get_config = function()
2525
return Promise.new():resolve({ model = 'gpt-4' })
2626
end,
27+
list_permissions = function()
28+
return Promise.new():resolve({})
29+
end,
2730
})
2831
end
2932

0 commit comments

Comments
 (0)