import { setupTest, startEngine, startClientInTmux, openCmdFifo, writeFifoCommand, wait, tmuxSendKeys, tmuxCapturePane, waitForPaneText, teardownTest } from './test_utils'; export async function testRecordOnHighRow(): Promise { console.log("\nTest: RECORD ON HIGH ROW (row 5, col 0) – verifies engine & TUI"); setupTest(); const engine = await startEngine(); await startClientInTmux(); openCmdFifo(); await wait(500); // Add a few channels so column 0 is usable for (let i = 1; i <= 3; i++) { writeFifoCommand("add"); await wait(100); } // Navigate to row 5, col 0 tmuxSendKeys("looper", "0", "j"); tmuxSendKeys("looper", "0", "j"); tmuxSendKeys("looper", "0", "j"); tmuxSendKeys("looper", "0", "j"); tmuxSendKeys("looper", "0", "j"); await wait(500); // Verify selection shows row 5 let pane = tmuxCapturePane("looper", "0"); if (!pane.includes("Selected: Grid 0, Row 5, Col 0")) { console.log(" FAIL: Could not navigate to Row 5, Col 0"); engine.kill(); teardownTest(); throw new Error("Navigation to row 5 failed"); } console.log(" PASS: Navigated to Row 5, Col 0"); // Press 't' to start recording tmuxSendKeys("looper", "0", "t"); // Check the TUI pane – wait until it shows 'R' near row 5 const paneWithR = await waitForPaneText("R", 5000); const paneLines = paneWithR.split("\n"); let cell5Line = -1, recordLine = -1; for (let i = 0; i < paneLines.length; i++) { if (paneLines[i].includes(" 5")) cell5Line = i; if (paneLines[i].includes("R")) recordLine = i; } if (cell5Line !== -1 && recordLine !== -1 && Math.abs(recordLine - cell5Line) <= 2) { console.log(" PASS: TUI grid shows 'R' near row 5"); } else { console.log(" FAIL: TUI grid does not show 'R' near row 5"); console.log(" Pane:\n" + paneWithR.slice(0, 1000)); engine.kill(); teardownTest(); throw new Error("TUI indicator missing for row 5"); } engine.kill(); teardownTest(); }