Files
looper/e2e/test_rapid_key_mash.ts
2026-06-06 17:46:52 +00:00

72 lines
2.3 KiB
TypeScript

import { setupTest, startEngine, startClientInTmux, openCmdFifo, writeFifoCommand, wait, tmuxSendKeys, tmuxCapturePane, teardownTest } from './test_utils';
export async function testRapidKeyMashConsistency(): Promise<void> {
console.log("\nTest: RAPID KEY MASH CONSISTENCY (burst of 10 keys, verify pane)");
setupTest();
const engine = await startEngine();
await startClientInTmux();
openCmdFifo();
await wait(500);
// Add channels up to column 5
for (let i = 1; i <= 5; i++) {
writeFifoCommand("add");
await wait(100);
}
const ITERATIONS = 20;
for (let iter = 0; iter < ITERATIONS; iter++) {
const seed = iter * 7;
let keys = "";
for (let k = 0; k < 10; k++) {
const dir = (seed + k) % 4;
switch (dir) {
case 0: keys += "l"; break;
case 1: keys += "h"; break;
case 2: keys += "j"; break;
case 3: keys += "k"; break;
}
}
keys += "t"; // record
tmuxSendKeys("looper", "0", keys);
await wait(500);
// Capture pane
const pane = tmuxCapturePane("looper", "0");
// 1. Selected line must be present
const selMatch = pane.match(/Selected: Grid \d+, Row (\d+), Col (\d+)/);
if (!selMatch) {
console.log(` FAIL at iteration ${iter}: No selected line in pane`);
console.log(" Pane:\n" + pane.slice(0, 500));
engine.kill(); teardownTest();
throw new Error("Selected line missing after burst");
}
const row = parseInt(selMatch[1]);
const col = parseInt(selMatch[2]);
if (row < 0 || row > 7 || col < 0 || col > 7) {
console.log(` FAIL at iteration ${iter}: selected (${row},${col}) out of bounds`);
engine.kill(); teardownTest();
throw new Error("Selected cell out of bounds after burst");
}
// 2. At least one 'R' must appear in the pane
const hasR = pane.includes("R");
if (!hasR) {
console.log(` FAIL at iteration ${iter}: No 'R' found after burst`);
console.log(" Pane:\n" + pane.slice(0, 1000));
engine.kill(); teardownTest();
throw new Error("No 'R' indicator after rapid key mash");
}
// 3. Toggle back to idle for next iteration
tmuxSendKeys("looper", "0", "t");
await wait(300);
}
console.log(" PASS: Rapid key mash consistency maintained over " + ITERATIONS + " iterations");
engine.kill();
teardownTest();
}