|
1 | 1 | local assert = require('luassert') |
| 2 | +local stub = require('luassert.stub') |
2 | 3 |
|
3 | 4 | describe('opencode.commands.handlers', function() |
4 | 5 | local tracked_modules = { |
@@ -110,6 +111,64 @@ describe('opencode.commands.handlers', function() |
110 | 111 | }, err) |
111 | 112 | end) |
112 | 113 |
|
| 114 | + it('returns actionable invalid subcommand errors for agent/session/diff handlers', function() |
| 115 | + local agent = require('opencode.commands.handlers.agent') |
| 116 | + local session = require('opencode.commands.handlers.session') |
| 117 | + local diff = require('opencode.commands.handlers.diff') |
| 118 | + |
| 119 | + local ok_agent, err_agent = pcall(agent.command_defs.agent.execute, { 'unknown' }) |
| 120 | + local ok_session, err_session = pcall(session.command_defs.session.execute, { 'unknown' }) |
| 121 | + local ok_diff, err_diff = pcall(diff.command_defs.diff.execute, { 'unknown' }) |
| 122 | + |
| 123 | + assert.is_false(ok_agent) |
| 124 | + assert.same({ |
| 125 | + code = 'invalid_arguments', |
| 126 | + message = 'Invalid agent subcommand. Use: ' .. table.concat(agent.command_defs.agent.completions, ', '), |
| 127 | + }, err_agent) |
| 128 | + |
| 129 | + assert.is_false(ok_session) |
| 130 | + assert.same({ |
| 131 | + code = 'invalid_arguments', |
| 132 | + message = 'Invalid session subcommand. Use: ' .. table.concat(session.command_defs.session.completions, ', '), |
| 133 | + }, err_session) |
| 134 | + |
| 135 | + assert.is_false(ok_diff) |
| 136 | + assert.same({ |
| 137 | + code = 'invalid_arguments', |
| 138 | + message = 'Invalid diff subcommand. Use: ' .. table.concat(diff.command_defs.diff.completions, ', '), |
| 139 | + }, err_diff) |
| 140 | + end) |
| 141 | + |
| 142 | + it('keeps help rendering stable in narrow output windows', function() |
| 143 | + local surface = require('opencode.commands.handlers.surface') |
| 144 | + local window = require('opencode.commands.handlers.window') |
| 145 | + local state = require('opencode.state') |
| 146 | + local ui = require('opencode.ui.ui') |
| 147 | + |
| 148 | + local open_input_stub = stub(window.actions, 'open_input') |
| 149 | + local is_visible_stub = stub(state.ui, 'is_visible').returns(true) |
| 150 | + local set_route_stub = stub(state.ui, 'set_display_route') |
| 151 | + local render_lines_stub = stub(ui, 'render_lines') |
| 152 | + local width_stub = stub(vim.api, 'nvim_win_get_width').returns(20) |
| 153 | + |
| 154 | + local original_windows = state.store.get('windows') |
| 155 | + local test_windows = vim.deepcopy(original_windows or {}) |
| 156 | + test_windows.output_win = 1 |
| 157 | + state.store.set_raw('windows', test_windows) |
| 158 | + |
| 159 | + local ok = pcall(surface.actions.help) |
| 160 | + |
| 161 | + state.store.set_raw('windows', original_windows) |
| 162 | + open_input_stub:revert() |
| 163 | + is_visible_stub:revert() |
| 164 | + set_route_stub:revert() |
| 165 | + render_lines_stub:revert() |
| 166 | + width_stub:revert() |
| 167 | + |
| 168 | + assert.is_true(ok) |
| 169 | + assert.stub(render_lines_stub).was_called() |
| 170 | + end) |
| 171 | + |
113 | 172 | it('keeps command semantic routing in diff revert handler (session target -> nil snapshot)', function() |
114 | 173 | local called = {} |
115 | 174 | local diff = require('opencode.commands.handlers.diff') |
|
0 commit comments