feat: add command context and diagnostics protocol

This commit is contained in:
2026-08-02 02:46:39 -04:00
parent df0053cfe5
commit 4ef1885149
4 changed files with 56 additions and 11 deletions

View File

@@ -39,9 +39,23 @@ test('disabled commands return a reason instead of mutating the document', () =>
const before = facade.getState().document.version
const state = facade.gui.command.getState('pad')
assert.equal(state.status, 'enabled')
facade.selection.clear()
facade.gui.workbench.setActive('Sketcher')
const disabled = facade.gui.command.getState('pad')
assert.equal(disabled.status, 'disabled')
assert.match(disabled.reason || '', /Part Design/)
assert.match(disabled.reason || '', /Part Design|compatible object/)
facade.gui.command.execute({ commandId: 'pad' })
assert.equal(facade.getState().diagnostics.at(-1)?.code, 'COMMAND_DISABLED')
assert.equal(facade.getState().document.version, before)
})
test('command events carry a document-scoped request context', () => {
const facade = createMockFacade()
const events: string[] = []
let requestId = ''
facade.subscribe((event) => { events.push(event.type); if (event.type === 'command.started') requestId = event.context.requestId })
facade.gui.command.execute({ commandId: 'create-sketch' })
assert.ok(events.includes('command.started'))
assert.ok(events.includes('command.completed'))
assert.match(requestId, /^req-/)
})