Skip to content

Commit 10ccc62

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 ee140ff commit 10ccc62

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
@@ -391,6 +391,52 @@ describe('opencode.services.session_runtime', function()
391391
mounted_stub:revert()
392392
state.ui.set_windows(nil)
393393
end)
394+
395+
it('restores pending permissions after a full session render', function()
396+
local renderer = require('opencode.ui.renderer')
397+
local permission_window = require('opencode.ui.permission_window')
398+
local events = require('opencode.ui.renderer.events')
399+
400+
state.session.set_active({ id = 'sess1' })
401+
state.ui.set_windows({ output_buf = 1, output_win = 2 })
402+
403+
local mounted_stub = stub(require('opencode.ui.output_window'), 'mounted').returns(true)
404+
local fetch_stub = stub(session, 'get_messages').invokes(function()
405+
return Promise.new():resolve({})
406+
end)
407+
local render_stub = stub(renderer, '_render_full_session_data')
408+
local list_questions_stub = stub(state.api_client, 'list_questions').invokes(function()
409+
return Promise.new():resolve({})
410+
end)
411+
local list_permissions_stub = stub(state.api_client, 'list_permissions').invokes(function()
412+
return Promise.new():resolve({
413+
{
414+
id = 'perm1',
415+
sessionID = 'sess1',
416+
permission = 'bash',
417+
patterns = { 'echo hello' },
418+
},
419+
})
420+
end)
421+
local on_permission_stub = stub(events, 'on_permission_updated')
422+
423+
renderer.render_full_session():wait()
424+
425+
assert.stub(on_permission_stub).was_called_with({
426+
id = 'perm1',
427+
sessionID = 'sess1',
428+
permission = 'bash',
429+
patterns = { 'echo hello' },
430+
})
431+
432+
on_permission_stub:revert()
433+
list_permissions_stub:revert()
434+
list_questions_stub:revert()
435+
render_stub:revert()
436+
fetch_stub:revert()
437+
mounted_stub:revert()
438+
state.ui.set_windows(nil)
439+
end)
394440
end)
395441

396442
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)