Files
loki/scripts/test/tab-match.ts
T
Mao NakamotoandClaude Opus 4.8 46d39714c6 fix(control): fuzzy tab matching, stale-backlog purge, actionable launch timeout
The dispatch last-mile was failing on real edges once the runner went live:

- Project keys never matched the names users actually gave their Zellij tabs:
  "revampit" ≠ "revamp-it", so focus/inject/launch threw "tab not found". New
  SSOT findMatchingTab() (src/lib/tab-match.ts) normalizes case + punctuation
  and is used in all three matching sites (terminals/zellij, agent-runtime,
  desktop poller). Existing fuzzy-matched tabs are reused; only a genuinely
  absent tab is created under its canonical name.
- A runner reconnecting after days offline drained a stale command backlog
  against a changed Zellij and failed noisily. purgeStalePendingCommands()
  deletes unclaimed/unexecuted commands older than 20m before claiming.
- launch_agent against a detached session hung to the 6s timeout and surfaced a
  cryptic "spawnSync /bin/sh ETIMEDOUT"; now it says which session is detached
  and to `zellij attach` it.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-17 17:43:24 +02:00

34 lines
1.5 KiB
TypeScript

// Verifies the project-key ↔ zellij-tab fuzzy matcher (src/lib/tab-match.ts).
// Run: npx tsx scripts/test/tab-match.ts
import { normalizeTabKey, findMatchingTab } from "@/lib/tab-match";
let pass = 0;
let fail = 0;
function eq(actual: unknown, expected: unknown, label: string) {
if (actual === expected) { pass++; }
else { fail++; console.error(`✗ ${label}: expected ${JSON.stringify(expected)}, got ${JSON.stringify(actual)}`); }
}
// normalize
eq(normalizeTabKey("revamp-it"), "revampit", "normalize hyphen");
eq(normalizeTabKey("AOZ Housing"), "aozhousing", "normalize space+case");
eq(normalizeTabKey("revamp_it"), "revampit", "normalize underscore");
const tabs = ["revamp-it", "OrangeCat", "Fleetcrown", "Tab #5", "AOZ Housing"];
// hyphen / case / space drift → matches, preserving live casing
eq(findMatchingTab("revampit", tabs), "revamp-it", "revampit → revamp-it");
eq(findMatchingTab("orangecat", tabs), "OrangeCat", "case-insensitive exact");
eq(findMatchingTab("aoz-housing", tabs), "AOZ Housing", "slug → spaced name");
eq(findMatchingTab("fleetcrown", tabs), "Fleetcrown", "lowercase → live casing");
// exact case-insensitive takes precedence over a normalized collision
eq(findMatchingTab("revamp-it", tabs), "revamp-it", "exact wins");
// genuinely absent → null (caller then creates the canonical tab)
eq(findMatchingTab("kivvi", tabs), null, "no match → null");
eq(findMatchingTab("petvity", tabs), null, "no match → null (2)");
console.log(`${pass}/${pass + fail} tab-match cases passed`);
if (fail > 0) process.exit(1);