import assert from 'node:assert/strict'; import test from 'node:test'; import { nativeTools } from '../src/native-tools.mjs'; test('native commands retain result and canvas identity without echoing workbench state', async () => { const result = {layer: 3, text: '标题', bounds: [0, 0, 100, 20]}; const canvas = {documentId: 7, revision: 5, selectedLayers: [3], activeLayer: 3}; const state = {...canvas, docking: {layers: true}, brush: {size: 10}}; const receipt = {beforeRevision: 4, afterRevision: 5, actualResult: result}; const events = []; const host = { canvas: { nativeCatalog: async () => ({items: [{id: 'type.edit', requiresRevisionLease: true}]}), requestWrite: async revision => ({allowed: true, revision}), nativeCall: async () => ({executed: true, completed: true, changed: true, revision: 5, state, result, receipt}), }, store: {appendEvent: async event => events.push(event)}, }; const call = nativeTools(host, (name, _description, _parameters, execute) => ({name, execute})) .find(tool => tool.name === 'native_call').execute; const edited = await call({method: 'engine.execute', revision: 4, params: {command: 'type.edit', params: {layer: 3, text: '标题'}}}); assert.deepEqual(edited.result, result); assert.equal(edited.revision, 5); assert.deepEqual(JSON.parse(JSON.stringify(edited.state)), canvas); assert.deepEqual(edited.receipt, {beforeRevision: 4, afterRevision: 5}); assert.deepEqual(events[0].receipt, receipt); assert.deepEqual((await call({method: 'ui.inspect', revision: 5, params: {}})).state, state); });