[Init] Initial commit - NetMesh terminal manager
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
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
This commit is contained in:
284
electron/bridges/windowManager/terminalPopupWindow.test.cjs
Normal file
284
electron/bridges/windowManager/terminalPopupWindow.test.cjs
Normal file
@@ -0,0 +1,284 @@
|
||||
"use strict";
|
||||
|
||||
const assert = require("node:assert/strict");
|
||||
const test = require("node:test");
|
||||
|
||||
const { createAppContentWindowClosedHandler } = require("../../appWindowLifecycle.cjs");
|
||||
const { createTerminalPopupWindowApi } = require("./terminalPopupWindow.cjs");
|
||||
const { markAttachPopupClosePrepared } = require("../terminalAttachRestore.cjs");
|
||||
|
||||
test("terminal popups participate in the last app-content-window lifecycle", async () => {
|
||||
const appContentWindows = new Set();
|
||||
let quitCalls = 0;
|
||||
const lifecycleHandler = createAppContentWindowClosedHandler({
|
||||
app: { quit() { quitCalls += 1; } },
|
||||
platform: "win32",
|
||||
windowManager: {
|
||||
getAppContentWindows: () => [...appContentWindows],
|
||||
getIsQuitting: () => false,
|
||||
},
|
||||
});
|
||||
let popupWindow;
|
||||
|
||||
class BrowserWindowStub {
|
||||
constructor() {
|
||||
popupWindow = this;
|
||||
this.handlers = new Map();
|
||||
this.webContents = {
|
||||
id: 42,
|
||||
on() {},
|
||||
send() {},
|
||||
setWindowOpenHandler() {},
|
||||
};
|
||||
}
|
||||
|
||||
on(channel, handler) { this.handlers.set(channel, handler); }
|
||||
isDestroyed() { return false; }
|
||||
isVisible() { return true; }
|
||||
loadURL() { return Promise.resolve(); }
|
||||
setBackgroundColor() {}
|
||||
}
|
||||
|
||||
const api = createTerminalPopupWindowApi({
|
||||
mainWindow: null,
|
||||
currentTheme: "light",
|
||||
V8_CACHE_OPTIONS: "bypassHeatCheck",
|
||||
resolveFrontendBackgroundColor() { return "#fff"; },
|
||||
resolveSettingsWindowBounds() { return { x: 10, y: 20 }; },
|
||||
createExternalOnlyWindowOpenHandler() { return {}; },
|
||||
applyWindowOpacityToWindow() {},
|
||||
getDevRendererBaseUrl(url) { return url; },
|
||||
showAndFocusWindow() {},
|
||||
registerAppContentWindow(win) { appContentWindows.add(win); },
|
||||
unregisterAppContentWindow(win) { appContentWindows.delete(win); },
|
||||
notifyAppContentWindowClosed() { lifecycleHandler(); },
|
||||
});
|
||||
|
||||
const result = await api.openTerminalPopupWindow(
|
||||
{
|
||||
BrowserWindow: BrowserWindowStub,
|
||||
nativeTheme: { shouldUseDarkColors: false },
|
||||
shell: {},
|
||||
},
|
||||
{
|
||||
preload: "/tmp/preload.cjs",
|
||||
isDev: false,
|
||||
appIcon: null,
|
||||
isMac: false,
|
||||
electronDir: __dirname,
|
||||
},
|
||||
{ popupId: "popup-1", title: "Terminal" },
|
||||
);
|
||||
|
||||
assert.deepEqual(result, { success: true, popupId: "popup-1" });
|
||||
assert.deepEqual([...appContentWindows], [popupWindow]);
|
||||
await assert.rejects(api.openTerminalPopupWindow(
|
||||
{ BrowserWindow: BrowserWindowStub, nativeTheme: {}, shell: {} },
|
||||
{
|
||||
preload: "/tmp/preload.cjs",
|
||||
isDev: false,
|
||||
appIcon: null,
|
||||
isMac: false,
|
||||
electronDir: __dirname,
|
||||
},
|
||||
{ popupId: "popup-1" },
|
||||
), /already active/);
|
||||
assert.equal(appContentWindows.size, 1);
|
||||
assert.equal(lifecycleHandler(), false);
|
||||
assert.equal(quitCalls, 0);
|
||||
|
||||
popupWindow.handlers.get("closed")?.();
|
||||
assert.deepEqual([...appContentWindows], []);
|
||||
assert.equal(quitCalls, 1);
|
||||
});
|
||||
|
||||
test("a terminal popup that fails to load releases app-content lifecycle state", async () => {
|
||||
const appContentWindows = new Set();
|
||||
let closeNotifications = 0;
|
||||
|
||||
class FailingBrowserWindowStub {
|
||||
constructor() {
|
||||
this.destroyed = false;
|
||||
this.handlers = new Map();
|
||||
this.webContents = {
|
||||
id: 43,
|
||||
on() {},
|
||||
send() {},
|
||||
setWindowOpenHandler() {},
|
||||
};
|
||||
}
|
||||
|
||||
on(channel, handler) { this.handlers.set(channel, handler); }
|
||||
isDestroyed() { return this.destroyed; }
|
||||
loadURL() { return Promise.reject(new Error("renderer unavailable")); }
|
||||
setBackgroundColor() {}
|
||||
destroy() {
|
||||
this.destroyed = true;
|
||||
this.handlers.get("closed")?.();
|
||||
}
|
||||
}
|
||||
|
||||
const api = createTerminalPopupWindowApi({
|
||||
mainWindow: null,
|
||||
currentTheme: "light",
|
||||
V8_CACHE_OPTIONS: "bypassHeatCheck",
|
||||
resolveFrontendBackgroundColor() { return "#fff"; },
|
||||
resolveSettingsWindowBounds() { return {}; },
|
||||
createExternalOnlyWindowOpenHandler() { return {}; },
|
||||
applyWindowOpacityToWindow() {},
|
||||
getDevRendererBaseUrl(url) { return url; },
|
||||
showAndFocusWindow() {},
|
||||
registerAppContentWindow(win) { appContentWindows.add(win); },
|
||||
unregisterAppContentWindow(win) { appContentWindows.delete(win); },
|
||||
notifyAppContentWindowClosed() { closeNotifications += 1; },
|
||||
});
|
||||
|
||||
await assert.rejects(api.openTerminalPopupWindow(
|
||||
{
|
||||
BrowserWindow: FailingBrowserWindowStub,
|
||||
nativeTheme: { shouldUseDarkColors: false },
|
||||
shell: {},
|
||||
},
|
||||
{
|
||||
preload: "/tmp/preload.cjs",
|
||||
isDev: false,
|
||||
appIcon: null,
|
||||
isMac: false,
|
||||
electronDir: __dirname,
|
||||
},
|
||||
{ popupId: "failed-popup" },
|
||||
), /renderer unavailable/);
|
||||
|
||||
assert.deepEqual([...appContentWindows], []);
|
||||
assert.equal(closeNotifications, 1);
|
||||
});
|
||||
|
||||
test("popup close failures cannot leave a ghost app-content window", async () => {
|
||||
const appContentWindows = new Set();
|
||||
let closeNotifications = 0;
|
||||
let popupWindow;
|
||||
|
||||
class CloseFailingBrowserWindowStub {
|
||||
constructor() {
|
||||
popupWindow = this;
|
||||
this.handlers = new Map();
|
||||
this.webContents = {
|
||||
id: 44,
|
||||
on() {},
|
||||
send() {},
|
||||
setWindowOpenHandler() {},
|
||||
};
|
||||
}
|
||||
|
||||
on(channel, handler) { this.handlers.set(channel, handler); }
|
||||
isDestroyed() { return false; }
|
||||
loadURL() { return Promise.resolve(); }
|
||||
setBackgroundColor() {}
|
||||
close() { throw new Error("close failed"); }
|
||||
destroy() { throw new Error("destroy failed"); }
|
||||
}
|
||||
|
||||
const api = createTerminalPopupWindowApi({
|
||||
mainWindow: null,
|
||||
currentTheme: "light",
|
||||
V8_CACHE_OPTIONS: "bypassHeatCheck",
|
||||
resolveFrontendBackgroundColor() { return "#fff"; },
|
||||
resolveSettingsWindowBounds() { return {}; },
|
||||
createExternalOnlyWindowOpenHandler() { return {}; },
|
||||
applyWindowOpacityToWindow() {},
|
||||
getDevRendererBaseUrl(url) { return url; },
|
||||
showAndFocusWindow() {},
|
||||
registerAppContentWindow(win) { appContentWindows.add(win); },
|
||||
unregisterAppContentWindow(win) { appContentWindows.delete(win); },
|
||||
notifyAppContentWindowClosed() { closeNotifications += 1; },
|
||||
});
|
||||
|
||||
await api.openTerminalPopupWindow(
|
||||
{ BrowserWindow: CloseFailingBrowserWindowStub, nativeTheme: {}, shell: {} },
|
||||
{
|
||||
preload: "/tmp/preload.cjs",
|
||||
isDev: false,
|
||||
appIcon: null,
|
||||
isMac: false,
|
||||
electronDir: __dirname,
|
||||
},
|
||||
{ popupId: "close-failure" },
|
||||
);
|
||||
assert.deepEqual([...appContentWindows], [popupWindow]);
|
||||
assert.doesNotThrow(() => api.closeTerminalPopupWindow("close-failure"));
|
||||
assert.deepEqual([...appContentWindows], []);
|
||||
assert.equal(closeNotifications, 1);
|
||||
});
|
||||
|
||||
test("attach popup waits for renderer handoff before closing", async () => {
|
||||
const sent = [];
|
||||
let popupWindow;
|
||||
class AttachBrowserWindowStub {
|
||||
constructor() {
|
||||
popupWindow = this;
|
||||
this.destroyed = false;
|
||||
this.handlers = new Map();
|
||||
this.webContents = {
|
||||
id: 45,
|
||||
on() {},
|
||||
send(channel, payload) { sent.push({ channel, payload }); },
|
||||
setWindowOpenHandler() {},
|
||||
};
|
||||
}
|
||||
on(channel, handler) { this.handlers.set(channel, handler); }
|
||||
isDestroyed() { return this.destroyed; }
|
||||
isVisible() { return true; }
|
||||
loadURL() { return Promise.resolve(); }
|
||||
setBackgroundColor() {}
|
||||
close() {
|
||||
let prevented = false;
|
||||
this.handlers.get("close")?.({ preventDefault() { prevented = true; } });
|
||||
if (!prevented) {
|
||||
this.destroyed = true;
|
||||
this.handlers.get("closed")?.();
|
||||
}
|
||||
}
|
||||
destroy() {
|
||||
this.destroyed = true;
|
||||
this.handlers.get("closed")?.();
|
||||
}
|
||||
}
|
||||
const api = createTerminalPopupWindowApi({
|
||||
mainWindow: null,
|
||||
currentTheme: "light",
|
||||
V8_CACHE_OPTIONS: "bypassHeatCheck",
|
||||
resolveFrontendBackgroundColor() { return "#fff"; },
|
||||
resolveSettingsWindowBounds() { return {}; },
|
||||
createExternalOnlyWindowOpenHandler() { return {}; },
|
||||
applyWindowOpacityToWindow() {},
|
||||
getDevRendererBaseUrl(url) { return url; },
|
||||
showAndFocusWindow() {},
|
||||
registerAppContentWindow() {},
|
||||
unregisterAppContentWindow() {},
|
||||
notifyAppContentWindowClosed() {},
|
||||
});
|
||||
|
||||
await api.openTerminalPopupWindow(
|
||||
{ BrowserWindow: AttachBrowserWindowStub, nativeTheme: {}, shell: {} },
|
||||
{ preload: "/tmp/preload.cjs", isDev: false, appIcon: null, isMac: false, electronDir: __dirname },
|
||||
{
|
||||
popupId: "attach-popup",
|
||||
title: "Attach",
|
||||
attachSessionId: "session-1",
|
||||
sourceSession: { id: "session-1" },
|
||||
},
|
||||
);
|
||||
const config = sent.find((entry) => entry.channel === "netcatty:window:terminalPopupConfig")?.payload;
|
||||
assert.equal(typeof config.attachAuthorization, "string");
|
||||
|
||||
api.closeTerminalPopupWindow("attach-popup");
|
||||
assert.equal(popupWindow.destroyed, false);
|
||||
assert.deepEqual(sent.at(-1), {
|
||||
channel: "netcatty:terminal-popup:prepare-close",
|
||||
payload: { sessionId: "session-1", authorization: config.attachAuthorization },
|
||||
});
|
||||
|
||||
assert.equal(markAttachPopupClosePrepared(config.attachAuthorization, "session-1", 45), true);
|
||||
api.closeTerminalPopupWindow("attach-popup");
|
||||
assert.equal(popupWindow.destroyed, true);
|
||||
});
|
||||
Reference in New Issue
Block a user