Some checks failed
build-packages / resolve bundled mosh-client (push) Has been cancelled
build-packages / resolve bundled et-client (push) Has been cancelled
build-packages / build-macos (push) Has been cancelled
build-packages / build-windows (push) Has been cancelled
build-packages / build-linux-x64 (push) Has been cancelled
build-packages / build-linux-arm64 (push) Has been cancelled
build-packages / release (push) Has been cancelled
build-packages / update Nix release metadata (push) Has been cancelled
build-packages / bump homebrew tap (push) Has been cancelled
test / lint-and-test (push) Has been cancelled
AI automation / Route event (push) Has been cancelled
AI automation / Hand reopened issue to maintainers (push) Has been cancelled
AI automation / Clean source issue state (push) Has been cancelled
AI automation / Reconcile handoffs (push) Has been cancelled
AI automation / Classify issue (push) Has been cancelled
AI automation / Claude Code smoke (push) Has been cancelled
AI automation / Review issue follow-up (push) Has been cancelled
AI automation / Publish issue follow-up (push) Has been cancelled
AI automation / Implement with Claude Code (push) Has been cancelled
AI automation / Publish implement PR (push) Has been cancelled
AI automation / Continue queued issue comments (push) Has been cancelled
AI automation / Codex review loop (push) Has been cancelled
AI automation / Publish Codex fix (push) Has been cancelled
AI automation / Clear Codex dispatch marker (push) Has been cancelled
AI automation / Own PR re-request Codex (push) Has been cancelled
AI automation / External PR re-request Codex (push) Has been cancelled
AI automation / Poll Codex reaction / retry (push) Has been cancelled
build-et-binaries / build-linux-x64 (push) Has been cancelled
build-et-binaries / build-linux-arm64 (push) Has been cancelled
build-et-binaries / build-macos-universal (push) Has been cancelled
build-et-binaries / build-windows-x64 (push) Has been cancelled
build-et-binaries / release (push) Has been cancelled
163 lines
5.8 KiB
TypeScript
163 lines
5.8 KiB
TypeScript
import test from "node:test";
|
|
import assert from "node:assert/strict";
|
|
|
|
import type { TmuxManageAction } from "../../domain/systemManager/types.ts";
|
|
import { runConfirmedTmuxDetachAction } from "./TmuxSessionCard.tsx";
|
|
import { runTmuxSessionAction, scheduleDeferredTerminalFocus } from "./tmuxActionFocus.ts";
|
|
|
|
test("tmux detach action requests terminal focus after a successful action", async () => {
|
|
const calls: string[] = [];
|
|
const action: TmuxManageAction = { action: "detachSession", sessionName: "work" };
|
|
const timeouts: Array<{ delay: number; callback: () => void }> = [];
|
|
const originalSetTimeout = globalThis.setTimeout;
|
|
const originalRequestAnimationFrame = globalThis.requestAnimationFrame;
|
|
|
|
globalThis.requestAnimationFrame = ((callback: FrameRequestCallback) => {
|
|
callback(0);
|
|
return 1;
|
|
}) as typeof globalThis.requestAnimationFrame;
|
|
globalThis.setTimeout = ((callback: () => void, delay?: number) => {
|
|
timeouts.push({ delay: delay ?? 0, callback });
|
|
return timeouts.length;
|
|
}) as typeof globalThis.setTimeout;
|
|
|
|
try {
|
|
const result = await runTmuxSessionAction({
|
|
sessionId: "session-1",
|
|
action,
|
|
tmuxAction: async (payload) => {
|
|
assert.deepEqual(payload, { sessionId: "session-1", ...action });
|
|
calls.push("tmuxAction");
|
|
return { success: true };
|
|
},
|
|
onSessionsChanged: async () => {
|
|
calls.push("sessionsChanged");
|
|
},
|
|
onRequestTerminalFocus: () => {
|
|
calls.push("focus");
|
|
},
|
|
});
|
|
|
|
assert.deepEqual(result, { success: true });
|
|
assert.deepEqual(calls, ["tmuxAction", "sessionsChanged"]);
|
|
assert.deepEqual(timeouts.map(({ delay }) => delay), [0, 50, 150]);
|
|
for (const { callback } of timeouts) callback();
|
|
assert.deepEqual(calls, ["tmuxAction", "sessionsChanged", "focus", "focus", "focus"]);
|
|
} finally {
|
|
globalThis.setTimeout = originalSetTimeout;
|
|
globalThis.requestAnimationFrame = originalRequestAnimationFrame;
|
|
}
|
|
});
|
|
|
|
test("scheduleDeferredTerminalFocus runs the callback on deferred timers", () => {
|
|
const calls: string[] = [];
|
|
const timeouts: Array<{ delay: number; callback: () => void }> = [];
|
|
const originalSetTimeout = globalThis.setTimeout;
|
|
const originalRequestAnimationFrame = globalThis.requestAnimationFrame;
|
|
|
|
globalThis.requestAnimationFrame = ((callback: FrameRequestCallback) => {
|
|
callback(0);
|
|
return 1;
|
|
}) as typeof globalThis.requestAnimationFrame;
|
|
globalThis.setTimeout = ((callback: () => void, delay?: number) => {
|
|
timeouts.push({ delay: delay ?? 0, callback });
|
|
return timeouts.length;
|
|
}) as typeof globalThis.setTimeout;
|
|
|
|
try {
|
|
scheduleDeferredTerminalFocus(() => calls.push("focus"));
|
|
assert.deepEqual(timeouts.map(({ delay }) => delay), [0, 50, 150]);
|
|
for (const { callback } of timeouts) callback();
|
|
assert.deepEqual(calls, ["focus", "focus", "focus"]);
|
|
} finally {
|
|
globalThis.setTimeout = originalSetTimeout;
|
|
globalThis.requestAnimationFrame = originalRequestAnimationFrame;
|
|
}
|
|
});
|
|
|
|
test("tmux detach confirmation runs the action path that requests terminal focus", async () => {
|
|
const calls: string[] = [];
|
|
const timeouts: Array<{ delay: number; callback: () => void }> = [];
|
|
const originalSetTimeout = globalThis.setTimeout;
|
|
const originalRequestAnimationFrame = globalThis.requestAnimationFrame;
|
|
|
|
globalThis.requestAnimationFrame = ((callback: FrameRequestCallback) => {
|
|
callback(0);
|
|
return 1;
|
|
}) as typeof globalThis.requestAnimationFrame;
|
|
globalThis.setTimeout = ((callback: () => void, delay?: number) => {
|
|
timeouts.push({ delay: delay ?? 0, callback });
|
|
return timeouts.length;
|
|
}) as typeof globalThis.setTimeout;
|
|
|
|
try {
|
|
const handled = await runConfirmedTmuxDetachAction({
|
|
sessionName: "work",
|
|
confirmMessage: "detach work?",
|
|
confirm: (message) => {
|
|
calls.push(`confirm:${message}`);
|
|
return true;
|
|
},
|
|
runAction: (action) => runTmuxSessionAction({
|
|
sessionId: "session-1",
|
|
action,
|
|
tmuxAction: async () => {
|
|
calls.push("tmuxAction");
|
|
return { success: true };
|
|
},
|
|
onSessionsChanged: async () => {
|
|
calls.push("sessionsChanged");
|
|
},
|
|
onRequestTerminalFocus: () => {
|
|
calls.push("focus");
|
|
},
|
|
}).then(() => undefined),
|
|
});
|
|
|
|
assert.equal(handled, true);
|
|
assert.deepEqual(calls, ["confirm:detach work?", "tmuxAction", "sessionsChanged"]);
|
|
for (const { callback } of timeouts) callback();
|
|
assert.deepEqual(calls, ["confirm:detach work?", "tmuxAction", "sessionsChanged", "focus", "focus", "focus"]);
|
|
} finally {
|
|
globalThis.setTimeout = originalSetTimeout;
|
|
globalThis.requestAnimationFrame = originalRequestAnimationFrame;
|
|
}
|
|
});
|
|
|
|
test("tmux detach action does not request terminal focus when the action fails", async () => {
|
|
const calls: string[] = [];
|
|
|
|
const result = await runTmuxSessionAction({
|
|
sessionId: "session-1",
|
|
action: { action: "detachSession", sessionName: "work" },
|
|
tmuxAction: async () => ({ success: false, error: "failed" }),
|
|
onSessionsChanged: async () => {
|
|
calls.push("sessionsChanged");
|
|
},
|
|
onRequestTerminalFocus: () => {
|
|
calls.push("focus");
|
|
},
|
|
});
|
|
|
|
assert.deepEqual(result, { success: false, error: "failed" });
|
|
assert.deepEqual(calls, []);
|
|
});
|
|
|
|
test("tmux non-detach actions do not request terminal focus after success", async () => {
|
|
const calls: string[] = [];
|
|
|
|
await runTmuxSessionAction({
|
|
sessionId: "session-1",
|
|
action: { action: "renameSession", sessionName: "work", newName: "renamed" },
|
|
tmuxAction: async () => ({ success: true }),
|
|
onSessionsChanged: async () => {
|
|
calls.push("sessionsChanged");
|
|
},
|
|
onRequestTerminalFocus: () => {
|
|
calls.push("focus");
|
|
},
|
|
});
|
|
|
|
assert.deepEqual(calls, ["sessionsChanged"]);
|
|
});
|