|
| 1 | +import { describe, it, expect, vi, afterEach } from 'vitest'; |
| 2 | +import { z } from 'zod'; |
| 3 | + |
| 4 | +// Import the tool and logic |
| 5 | +import tool, { record_sim_videoLogic } from '../record_sim_video.ts'; |
| 6 | +import { createMockFileSystemExecutor } from '../../../../test-utils/mock-executors.ts'; |
| 7 | + |
| 8 | +const DUMMY_EXECUTOR: any = (async () => ({ success: true })) as any; // CommandExecutor stub |
| 9 | +const VALID_UUID = '00000000-0000-0000-0000-000000000000'; |
| 10 | + |
| 11 | +afterEach(() => { |
| 12 | + vi.restoreAllMocks(); |
| 13 | +}); |
| 14 | + |
| 15 | +describe('record_sim_video tool - validation', () => { |
| 16 | + it('errors when start and stop are both true (mutually exclusive)', async () => { |
| 17 | + const res = await tool.handler({ |
| 18 | + simulatorUuid: VALID_UUID, |
| 19 | + start: true, |
| 20 | + stop: true, |
| 21 | + } as any); |
| 22 | + |
| 23 | + expect(res.isError).toBe(true); |
| 24 | + const text = (res.content?.[0] as any)?.text ?? ''; |
| 25 | + expect(text.toLowerCase()).toContain('mutually exclusive'); |
| 26 | + }); |
| 27 | + |
| 28 | + it('errors when stop=true but outputFile is missing', async () => { |
| 29 | + const res = await tool.handler({ |
| 30 | + simulatorUuid: VALID_UUID, |
| 31 | + stop: true, |
| 32 | + } as any); |
| 33 | + |
| 34 | + expect(res.isError).toBe(true); |
| 35 | + const text = (res.content?.[0] as any)?.text ?? ''; |
| 36 | + expect(text.toLowerCase()).toContain('outputfile is required'); |
| 37 | + }); |
| 38 | +}); |
| 39 | + |
| 40 | +describe('record_sim_video logic - start behavior', () => { |
| 41 | + it('starts with default fps (30) and warns when outputFile is provided on start (ignored)', async () => { |
| 42 | + const video: any = { |
| 43 | + startSimulatorVideoCapture: async () => ({ |
| 44 | + started: true, |
| 45 | + sessionId: 'sess-123', |
| 46 | + }), |
| 47 | + stopSimulatorVideoCapture: async () => ({ |
| 48 | + stopped: false, |
| 49 | + }), |
| 50 | + }; |
| 51 | + |
| 52 | + // DI for AXe helpers: available and version OK |
| 53 | + const axe = { |
| 54 | + areAxeToolsAvailable: () => true, |
| 55 | + isAxeAtLeastVersion: async () => true, |
| 56 | + createAxeNotAvailableResponse: () => ({ |
| 57 | + content: [{ type: 'text', text: 'AXe not available' }], |
| 58 | + isError: true, |
| 59 | + }), |
| 60 | + }; |
| 61 | + |
| 62 | + const fs = createMockFileSystemExecutor(); |
| 63 | + |
| 64 | + const res = await record_sim_videoLogic( |
| 65 | + { |
| 66 | + simulatorUuid: VALID_UUID, |
| 67 | + start: true, |
| 68 | + // fps omitted to hit default 30 |
| 69 | + outputFile: '/tmp/ignored.mp4', // should be ignored with a note |
| 70 | + } as any, |
| 71 | + DUMMY_EXECUTOR, |
| 72 | + axe, |
| 73 | + video, |
| 74 | + fs, |
| 75 | + ); |
| 76 | + |
| 77 | + expect(res.isError).toBe(false); |
| 78 | + const texts = (res.content ?? []).map((c: any) => c.text).join('\n'); |
| 79 | + |
| 80 | + expect(texts).toContain('🎥'); |
| 81 | + expect(texts).toMatch(/30\s*fps/i); |
| 82 | + expect(texts.toLowerCase()).toContain('outputfile is ignored'); |
| 83 | + expect(texts).toContain('Next Steps'); |
| 84 | + expect(texts).toContain('stop: true'); |
| 85 | + expect(texts).toContain('outputFile'); |
| 86 | + }); |
| 87 | +}); |
| 88 | + |
| 89 | +describe('record_sim_video logic - end-to-end stop with rename', () => { |
| 90 | + it('stops, parses stdout path, and renames to outputFile', async () => { |
| 91 | + const video: any = { |
| 92 | + startSimulatorVideoCapture: async () => ({ |
| 93 | + started: true, |
| 94 | + sessionId: 'sess-abc', |
| 95 | + }), |
| 96 | + stopSimulatorVideoCapture: async () => ({ |
| 97 | + stopped: true, |
| 98 | + parsedPath: '/tmp/recorded.mp4', |
| 99 | + stdout: 'Saved to /tmp/recorded.mp4', |
| 100 | + }), |
| 101 | + }; |
| 102 | + |
| 103 | + const fs = createMockFileSystemExecutor(); |
| 104 | + |
| 105 | + const axe = { |
| 106 | + areAxeToolsAvailable: () => true, |
| 107 | + isAxeAtLeastVersion: async () => true, |
| 108 | + createAxeNotAvailableResponse: () => ({ |
| 109 | + content: [{ type: 'text', text: 'AXe not available' }], |
| 110 | + isError: true, |
| 111 | + }), |
| 112 | + }; |
| 113 | + |
| 114 | + // Start (not strictly required for stop path, but included to mimic flow) |
| 115 | + const startRes = await record_sim_videoLogic( |
| 116 | + { |
| 117 | + simulatorUuid: VALID_UUID, |
| 118 | + start: true, |
| 119 | + } as any, |
| 120 | + DUMMY_EXECUTOR, |
| 121 | + axe, |
| 122 | + video, |
| 123 | + fs, |
| 124 | + ); |
| 125 | + expect(startRes.isError).toBe(false); |
| 126 | + |
| 127 | + // Stop and rename |
| 128 | + const outputFile = '/var/videos/final.mp4'; |
| 129 | + const stopRes = await record_sim_videoLogic( |
| 130 | + { |
| 131 | + simulatorUuid: VALID_UUID, |
| 132 | + stop: true, |
| 133 | + outputFile, |
| 134 | + } as any, |
| 135 | + DUMMY_EXECUTOR, |
| 136 | + axe, |
| 137 | + video, |
| 138 | + fs, |
| 139 | + ); |
| 140 | + |
| 141 | + expect(stopRes.isError).toBe(false); |
| 142 | + const texts = (stopRes.content ?? []).map((c: any) => c.text).join('\n'); |
| 143 | + expect(texts).toContain('Original file: /tmp/recorded.mp4'); |
| 144 | + expect(texts).toContain(`Saved to: ${outputFile}`); |
| 145 | + |
| 146 | + // _meta should include final saved path |
| 147 | + expect((stopRes as any)._meta?.outputFile).toBe(outputFile); |
| 148 | + }); |
| 149 | +}); |
| 150 | + |
| 151 | +describe('record_sim_video logic - version gate', () => { |
| 152 | + it('errors when AXe version is below 1.1.0', async () => { |
| 153 | + const axe = { |
| 154 | + areAxeToolsAvailable: () => true, |
| 155 | + isAxeAtLeastVersion: async () => false, |
| 156 | + createAxeNotAvailableResponse: () => ({ |
| 157 | + content: [{ type: 'text', text: 'AXe not available' }], |
| 158 | + isError: true, |
| 159 | + }), |
| 160 | + }; |
| 161 | + |
| 162 | + const video: any = { |
| 163 | + startSimulatorVideoCapture: async () => ({ |
| 164 | + started: true, |
| 165 | + sessionId: 'sess-xyz', |
| 166 | + }), |
| 167 | + stopSimulatorVideoCapture: async () => ({ |
| 168 | + stopped: true, |
| 169 | + }), |
| 170 | + }; |
| 171 | + |
| 172 | + const fs = createMockFileSystemExecutor(); |
| 173 | + |
| 174 | + const res = await record_sim_videoLogic( |
| 175 | + { |
| 176 | + simulatorUuid: VALID_UUID, |
| 177 | + start: true, |
| 178 | + } as any, |
| 179 | + DUMMY_EXECUTOR, |
| 180 | + axe, |
| 181 | + video, |
| 182 | + fs, |
| 183 | + ); |
| 184 | + |
| 185 | + expect(res.isError).toBe(true); |
| 186 | + const text = (res.content?.[0] as any)?.text ?? ''; |
| 187 | + expect(text).toContain('AXe v1.1.0'); |
| 188 | + }); |
| 189 | +}); |
0 commit comments