import { expect, tap } from '@git.zone/tstest/tapbundle'; import { createWrappedKvmCommand, parseWrappedKvmCommandOutput, } from '../ts/smartkvm.commandwrappers.js'; tap.test('bash wrapper should contain OCR-friendly markers', async () => { const wrappedCommand = createWrappedKvmCommand('echo hello', 'bash'); expect(wrappedCommand.commandId).toMatch(/^[a-f0-9]{32}$/); expect(wrappedCommand.startMarker).toEqual(`SMARTKVM_START_${wrappedCommand.commandId}`); expect(wrappedCommand.endMarkerPrefix).toEqual(`SMARTKVM_END_${wrappedCommand.commandId}_`); expect(wrappedCommand.textToType).toInclude(wrappedCommand.startMarker); expect(wrappedCommand.textToType).toInclude(wrappedCommand.endMarkerPrefix); expect(wrappedCommand.textToType).toInclude('echo hello'); }); tap.test('powershell wrapper should contain valid markers', async () => { const wrappedCommand = createWrappedKvmCommand('Get-Location', 'powershell'); expect(wrappedCommand.textToType).toInclude(wrappedCommand.startMarker); expect(wrappedCommand.textToType).toInclude(wrappedCommand.endMarkerPrefix); expect(wrappedCommand.textToType).toInclude('try { Get-Location;'); }); tap.test('cmd wrapper should contain valid markers', async () => { const wrappedCommand = createWrappedKvmCommand('dir', 'cmd'); expect(wrappedCommand.textToType).toInclude(`echo ${wrappedCommand.startMarker}`); expect(wrappedCommand.textToType).toInclude(`echo ${wrappedCommand.endMarkerPrefix}%ERRORLEVEL%`); }); tap.test('parser should extract command output and exit code', async () => { const parsedResult = parseWrappedKvmCommandOutput({ commandId: 'abc123', startMarker: 'SMARTKVM_START_abc123', endMarkerPrefix: 'SMARTKVM_END_abc123_', rawText: `something before SMARTKVM_START_abc123 hello world SMARTKVM_END_abc123_0 prompt after`, }); expect(parsedResult.completed).toBeTrue(); expect(parsedResult.exitCode).toEqual(0); expect(parsedResult.combinedText).toEqual('hello world'); }); tap.test('parser should return incomplete result if markers are missing', async () => { const parsedResult = parseWrappedKvmCommandOutput({ commandId: 'abc123', startMarker: 'SMARTKVM_START_abc123', endMarkerPrefix: 'SMARTKVM_END_abc123_', rawText: 'hello world', }); expect(parsedResult.completed).toBeFalse(); expect(parsedResult.combinedText).toEqual('hello world'); }); export default tap.start();