Skip to content

AI-native knowledge base & Evernote/Obsidian alternative with instant sync & native MCP. Free on Cloudflare or self-hosted via Docker.

test(desktop): packaged E2E for note windows in the desktop release build (#739)

Dariusz Koryto663d1dbb2550
diff --git a/.github/workflows/desktop-build.yml b/.github/workflows/desktop-build.yml
index f83c1150..399eb1ca 100644
--- a/.github/workflows/desktop-build.yml
+++ b/.github/workflows/desktop-build.yml
@@ -382,6 +382,16 @@ jobs:
fi
bun run verify:desktop-protocol-e2e -- "release/desktop/$unpacked_directory/EdgeEver.app/Contents/MacOS/EdgeEver"
+ - name: Verify packaged macOS note windows
+ env:
+ EDGE_EVER_DESKTOP_ARCH: ${{ matrix.arch }}
+ run: |
+ unpacked_directory="mac-${{ matrix.arch }}"
+ if [[ "${{ matrix.arch }}" == "x64" ]]; then
+ unpacked_directory="mac"
+ fi
+ bun run verify:desktop-note-window-e2e -- "release/desktop/$unpacked_directory/EdgeEver.app/Contents/MacOS/EdgeEver"
+
- name: Verify desktop installer
env:
EDGE_EVER_DESKTOP_ARCH: ${{ matrix.arch }}
@@ -530,6 +540,9 @@ jobs:
- name: Verify packaged Windows private protocol file flows
run: bun run verify:desktop-protocol-e2e -- release/desktop/win-unpacked/EdgeEver.exe
+ - name: Verify packaged Windows note windows
+ run: bun run verify:desktop-note-window-e2e -- release/desktop/win-unpacked/EdgeEver.exe
+
- name: Verify that Preview executables are unsigned
shell: pwsh
run: |
@@ -724,6 +737,18 @@ jobs:
test -n "$executable"
xvfb-run -a bun run verify:desktop-protocol-e2e -- "$executable"
+ - name: Verify packaged Linux note windows
+ run: |
+ executable=""
+ for candidate in release/desktop/linux-unpacked/EdgeEver release/desktop/linux-unpacked/edgeever; do
+ if [[ -x "$candidate" ]]; then
+ executable="$candidate"
+ break
+ fi
+ done
+ test -n "$executable"
+ xvfb-run -a bun run verify:desktop-note-window-e2e -- "$executable"
+
- name: Create Linux checksum
run: |
version="$(node -p "JSON.parse(require('fs').readFileSync('apps/desktop/package.json', 'utf8')).version")"
diff --git a/docs/changes/2026-10-29-desktop-note-window.md b/docs/changes/2026-10-29-desktop-note-window.md
index 1b1565e2..9c093ab2 100644
--- a/docs/changes/2026-10-29-desktop-note-window.md
+++ b/docs/changes/2026-10-29-desktop-note-window.md
@@ -23,3 +23,7 @@ Implements [Issue #67](https://github.com/tianma-if/edgeever/issues/67). Desktop
## Risk and rollback
The change is desktop-only and adds no data, API or migration change. Main-process IPC that used to accept only the main window now also accepts note windows for the session token, image upload, AI direct requests and renderer error reports; account, instance, data reset and window commands still require the main window. A synchronous IPC handler (`desktop:rich-text-heading-shortcut`) previously returned nothing for other windows, which froze them; it now always answers, and each note window has its own heading-shortcut guard. Sync forwarding goes from the main window through the main process to one note window; only the main window may send it and only a note window may report that it is ready. A sync result that arrives while a note window is still loading is not replayed; the window reads the note from storage when it loads. Electron scenarios were run against the local dev server on macOS only; Windows and Linux are covered by CI unit tests and builds, not by interactive runs. Rollback is a revert; no stored state refers to note windows.
+
+## Packaged E2E
+
+`tests/desktop-note-window.integration.mjs` (`bun run verify:desktop-note-window-e2e -- <packaged executable>`) runs the main scenarios against the packaged app and a test API on a temporary database (`tests/desktop-note-window-api.mjs`, run under Bun; the driver runs under Node because Playwright cannot open its Electron connection from Bun 1.3): moving unsaved edits (A1), focusing the existing window from every entry (A2), note-window IPC limits (A3), saving on close (B1), two windows and links (C1), failed saves before the move and on close (D1, E1; skipped on Windows because pausing storage needs POSIX signals), quitting (F1), deleting (G1), a renderer crash (H1), a note that cannot be shown (H2), a change from another device (I1) and a sync conflict (I2). The desktop release workflow runs it after the packaged first-launch and protocol checks on macOS, Windows and Linux (under `xvfb-run`).
diff --git a/docs/changes/2026-10-29-desktop-note-window.zh-CN.md b/docs/changes/2026-10-29-desktop-note-window.zh-CN.md
index cd4f3e8b..4b4f029b 100644
--- a/docs/changes/2026-10-29-desktop-note-window.zh-CN.md
+++ b/docs/changes/2026-10-29-desktop-note-window.zh-CN.md
@@ -23,3 +23,7 @@
## 风险与回滚
本次改动仅涉及桌面端,没有数据、API 或迁移变化。原先只接受主窗口的主进程 IPC 中,会话令牌、图片上传、AI 直连请求和渲染错误上报现在也接受笔记窗口;账号、实例、数据重置和窗口命令仍只接受主窗口。同步 IPC 处理函数 `desktop:rich-text-heading-shortcut` 以前对其他窗口不返回值,会让窗口卡死;现在总会返回,且每个笔记窗口有独立的标题快捷键守卫。同步转发经由主进程从主窗口发送到单个笔记窗口;只有主窗口可以发送,只有笔记窗口可以回报就绪。笔记窗口仍在加载时到达的同步结果不会重放,窗口加载时会从存储读取笔记。Electron 场景仅在 macOS 上对本地开发服务运行;Windows 与 Linux 由 CI 单元测试和构建覆盖,未做交互验证。回滚方式为 revert;没有持久化状态引用笔记窗口。
+
+## 安装包端到端测试
+
+`tests/desktop-note-window.integration.mjs`(`bun run verify:desktop-note-window-e2e -- <安装包可执行文件>`)使用打包后的应用和测试 API(临时数据库,`tests/desktop-note-window-api.mjs`,在 Bun 下运行;由于 Playwright 无法在 Bun 1.3 下建立 Electron 连接,驱动脚本在 Node 下运行)运行主要场景:带未保存修改移动笔记(A1)、从各入口聚焦已有窗口(A2)、笔记窗口的 IPC 限制(A3)、关闭时保存(B1)、两个窗口与链接(C1)、移动前及关闭时保存失败(D1、E1;暂停存储依赖 POSIX 信号,Windows 上跳过)、退出应用(F1)、删除笔记(G1)、渲染进程崩溃(H1)、无法显示的笔记(H2)、其他设备的修改(I1)以及同步冲突(I2)。桌面端发布工作流在 macOS、Windows 和 Linux(通过 `xvfb-run`)的首次启动与协议检查之后运行该测试。
diff --git a/package.json b/package.json
index d21081f9..54f406a2 100644
--- a/package.json
+++ b/package.json
@@ -73,6 +73,7 @@
"verify:desktop-renderer": "bun scripts/verify-desktop-renderer.mjs",
"verify:renderer-origin-migration": "bun run --cwd apps/desktop verify-origin-migration",
"verify:desktop-cross-version-startup": "bun scripts/verify-desktop-cross-version-startup.mjs",
+ "verify:desktop-note-window-e2e": "node tests/desktop-note-window.integration.mjs",
"verify:desktop-protocol-e2e": "bun scripts/verify-desktop-protocol-e2e.mjs",
"verify:packaged-desktop-startup": "bun scripts/verify-packaged-desktop-startup.mjs",
"verify:desktop-package": "bun scripts/verify-desktop-package.mjs",
diff --git a/scripts/desktop-build-workflow.test.mjs b/scripts/desktop-build-workflow.test.mjs
index 16e9a9dd..640981ba 100644
--- a/scripts/desktop-build-workflow.test.mjs
+++ b/scripts/desktop-build-workflow.test.mjs
@@ -101,6 +101,7 @@ describe("desktop release workflow", () => {
expect(step("Verify packaged macOS cross-version startup")).toContain("verify:desktop-cross-version-startup");
expect(step("Verify packaged macOS first launch")).not.toContain("if: matrix.shared_validation");
expect(step("Verify packaged macOS private protocol file flows")).toContain("verify:desktop-protocol-e2e");
+ expect(step("Verify packaged macOS note windows")).toContain("verify:desktop-note-window-e2e");
});
test("limits the Apple HTTP/3 workaround to hosted Intel packaging", () => {
@@ -138,6 +139,7 @@ describe("desktop release workflow", () => {
expect(workflow).toContain("name: Verify packaged Windows first launch");
expect(workflow).toContain("verify:packaged-desktop-startup");
expect(step("Verify packaged Windows private protocol file flows")).toContain("verify:desktop-protocol-e2e");
+ expect(step("Verify packaged Windows note windows")).toContain("verify:desktop-note-window-e2e");
expect(protocolE2eVerifier).toContain('origin !== "edgeever-app://app"');
expect(protocolE2eVerifier).toContain('fetch("edgeever-staged://" + pending.id)');
expect(protocolE2eVerifier).toContain('const url = "edgeever-resource://resource/${cachedResourceId}"');
@@ -183,6 +185,7 @@ describe("desktop release workflow", () => {
expect(workflow).toContain("name: Verify packaged Linux first launch");
expect(workflow).toContain("xvfb-run -a bun run verify:packaged-desktop-startup");
expect(step("Verify packaged Linux private protocol file flows")).toContain("xvfb-run -a bun run verify:desktop-protocol-e2e");
+ expect(step("Verify packaged Linux note windows")).toContain("xvfb-run -a bun run verify:desktop-note-window-e2e");
expect(workflow).toContain("SHA256SUMS-linux.txt");
expect(workflow).toContain("latest-linux.yml");
expect(workflow).toContain("verify-linux-update-release.mjs");
diff --git a/tests/desktop-note-window-api.mjs b/tests/desktop-note-window-api.mjs
new file mode 100644
index 00000000..7773d3e0
--- /dev/null
+++ b/tests/desktop-note-window-api.mjs
@@ -0,0 +1,35 @@
+// Test API for the packaged note window E2E: a temporary SQLite database
+// behind the real API. Runs under Bun; prints "READY <url>" once it listens
+// and stops when its parent closes stdin.
+import { Database } from "bun:sqlite";
+import { readdir, readFile } from "node:fs/promises";
+import { join } from "node:path";
+import { fetchEdgeEverApp } from "../apps/api/src/index.ts";
+import { createSelfHostedStorageAdapter } from "../apps/api/src/self-hosted-storage-adapter.ts";
+
+const directory = process.argv[2];
+if (!directory) throw new Error("Pass the test data directory as the first argument.");
+
+const database = new Database(join(directory, "test-api.sqlite"));
+for (const name of (await readdir("migrations")).filter((name) => name.endsWith(".sql")).sort()) {
+ database.exec(await readFile(join("migrations", name), "utf8"));
+}
+database.query("INSERT OR IGNORE INTO workspaces(id,name,is_personal) VALUES ('ws_default','Personal',1)").run();
+const environment = {
+ storage: createSelfHostedStorageAdapter(database, join(directory, "resources")),
+ EDGE_EVER_ALLOW_UNAUTHENTICATED: "true",
+ EDGE_EVER_RUNTIME: "self-hosted-bun",
+};
+const server = Bun.serve({ hostname: "127.0.0.1", port: 0,
+ fetch: (request) => fetchEdgeEverApp(request, environment, { waitUntil() {}, passThroughOnException() {} }),
+});
+
+const stop = () => {
+ server.stop(true);
+ database.close();
+ process.exit(0);
+};
+process.stdin.on("end", stop);
+process.stdin.on("close", stop);
+process.stdin.resume();
+console.log(`READY http://127.0.0.1:${server.port}`);
diff --git a/tests/desktop-note-window.integration.mjs b/tests/desktop-note-window.integration.mjs
new file mode 100644
index 00000000..78c5d37f
--- /dev/null
+++ b/tests/desktop-note-window.integration.mjs
@@ -0,0 +1,430 @@
+// Packaged desktop E2E for "open a note in a new window" (#67, #730).
+// Usage: node tests/desktop-note-window.integration.mjs <packaged executable>
+// Starts the test API (tests/desktop-note-window-api.mjs, under Bun) on a
+// temporary SQLite database, launches the packaged app against it and drives
+// the main window and note windows. The driver runs under Node because
+// Playwright cannot open its Electron connection from Bun 1.3.
+import assert from "node:assert/strict";
+import { execFileSync, spawn } from "node:child_process";
+import { desktopMenuCopy } from "../apps/desktop/src/main/desktop-menu.mjs";
+import { _electron as electron, expect } from "@playwright/test";
+import { mkdir, mkdtemp, readdir, readFile, rm, writeFile } from "node:fs/promises";
+import { tmpdir } from "node:os";
+import { join, resolve } from "node:path";
+
+assert.ok(process.argv[2], "Pass the locally built desktop executable as the first argument.");
+const executablePath = resolve(process.argv[2]);
+const only = process.argv[3]?.split(",") ?? null;
+const directory = await mkdtemp(join(tmpdir(), "edgeever-note-window-e2e-"));
+const profile = join(directory, "profile");
+const results = [];
+let application;
+let server;
+let page;
+let note;
+let baseUrl;
+
+// Pausing storage simulates a sidecar that stops answering. Only this test's
+// sidecar is matched, by its data directory.
+const sidecarPids = () => {
+ try {
+ return execFileSync("pgrep", ["-f", `edgeever-sidecar --data-dir ${profile}`]).toString().trim().split("\n").filter(Boolean);
+ } catch {
+ return [];
+ }
+};
+const signalSidecars = (signal) => {
+ for (const pid of sidecarPids()) {
+ try { process.kill(Number(pid), signal); } catch {}
+ }
+};
+
+// Pausing storage relies on POSIX signals; Windows runs the other scenarios.
+const pausesStorage = new Set(["D1", "E1"]);
+// A timed-out scenario keeps running against the shared app, so later steps cannot trust its state.
+let timedOut = false;
+const step = async (name, run) => {
+ if (only && !only.includes(name.split(":")[0])) return;
+ if (timedOut) {
+ console.log(`SKIP ${name} (an earlier scenario timed out)`);
+ return;
+ }
+ if (process.platform === "win32" && pausesStorage.has(name.split(":")[0])) {
+ console.log(`SKIP ${name} (needs POSIX signals)`);
+ return;
+ }
+ const started = Date.now();
+ let timer;
+ try {
+ await Promise.race([
+ run(),
+ new Promise((_, reject) => {
+ timer = setTimeout(() => {
+ timedOut = true;
+ reject(new Error("step timeout"));
+ }, 180_000);
+ }),
+ ]);
+ results.push({ name, ok: true, ms: Date.now() - started });
+ } catch (error) {
+ signalSidecars("SIGCONT");
+ results.push({ name, ok: false, error: String(error?.message || error).split("\n").slice(0, 6).join(" | ") });
+ } finally {
+ clearTimeout(timer);
+ }
+ const result = results.at(-1);
+ console.log(`${result.ok ? "PASS" : "FAIL"} ${name}${result.ok ? ` (${result.ms} ms)` : `: ${result.error}`}`);
+};
+
+const api = async (path, init) => {
+ const response = await fetch(`${baseUrl}${path}`, { ...init, headers: { "Content-Type": "application/json", ...(init?.headers ?? {}) } });
+ if (!response.ok) throw new Error(`${path} ${response.status}`);
+ return response.json();
+};
+let notebookId;
+const createMemo = async (title, contentMarkdown) =>
+ (await api("/api/v1/memos", { method: "POST", body: JSON.stringify({ notebookId, title, contentMarkdown }) })).memo;
+const serverMarkdown = async (id) => (await api(`/api/v1/memos/${id}`)).memo.contentMarkdown;
+// An edit made on another device: through the API with its own edit session.
+const editOnServer = async (id, suffix) => {
+ const { memo } = await api(`/api/v1/memos/${id}`);
+ const { editSession } = await api(`/api/v1/memos/${id}/edit-sessions`, { method: "POST" });
+ await api(`/api/v1/memos/${id}`, { method: "PATCH", body: JSON.stringify({
+ editSessionId: editSession.id,
+ expectedRevision: editSession.baseRevision,
+ expectedContentHash: editSession.baseContentHash,
+ contentMarkdown: `${memo.contentMarkdown}\n\n${suffix}`,
+ }) });
+};
+
+// Hosted Windows runners have a 1024x768 screen, which leaves the window below
+// the 1024px desktop layout; a smaller scale factor gives it the desktop layout.
+const displayArgs = process.platform === "win32" ? ["--force-device-scale-factor=0.75"] : [];
+const launch = async () => {
+ application = await electron.launch({
+ executablePath,
+ args: [`--user-data-dir=${profile}`, ...displayArgs],
+ env: { ...process.env, EDGE_EVER_DISABLE_AUTO_UPDATE: "1" },
+ timeout: 60_000,
+ });
+ // Startup can briefly open a renderer-origin migration window before the main window.
+ const deadline = Date.now() + 60_000;
+ let main;
+ while (Date.now() < deadline && !main) {
+ main = application.windows().find((window) => window.url().startsWith("edgeever-app://app/index.html") && !window.url().includes("noteWindow="));
+ if (!main) await new Promise((resolveWait) => setTimeout(resolveWait, 100));
+ }
+ assert.ok(main, "The packaged main window must open");
+ await main.waitForSelector('[data-edgeever-renderer-ready="true"]', { state: "attached", timeout: 60_000 });
+ await main.evaluate(() => localStorage.setItem("edgeever.locale.preference", "en-US"));
+ await main.reload();
+ await main.waitForSelector('[data-edgeever-renderer-ready="true"]', { state: "attached", timeout: 60_000 });
+ page = main;
+ note = undefined;
+ // Wait until the first sync brought the test notebook into local storage.
+ // The sidecar can still be starting right after the reload.
+ await expect.poll(() => page.evaluate(async (id) => {
+ const { notebooks } = await window.edgeeverDesktop.sidecarRequest("notebook.list");
+ return notebooks.some((notebook) => notebook.id === id);
+ }, notebookId).catch(() => false), { timeout: 60_000 }).toBe(true);
+ // Search covers the selected notebook, and a seeded demo notebook is selected first.
+ await page.getByRole("button", { name: "All notes", exact: true }).click({ timeout: 30_000 }).catch(async (error) => {
+ await reportStartupState();
+ throw error;
+ });
+};
+
+// Print what the main window shows when startup does not reach the notes list.
+const reportStartupState = async () => {
+ const state = await page.evaluate(() => ({
+ size: `${window.innerWidth}x${window.innerHeight}`,
+ locale: document.documentElement.lang,
+ buttons: [...document.querySelectorAll("button")].map((button) => button.getAttribute("aria-label") || button.innerText.trim()).filter(Boolean).slice(0, 40),
+ text: document.body.innerText.slice(0, 1500),
+ })).catch((error) => ({ error: String(error) }));
+ console.log("Main window at startup failure:", JSON.stringify(state, null, 2));
+ if (process.env.EDGE_EVER_E2E_SCREENSHOT) await page.screenshot({ path: process.env.EDGE_EVER_E2E_SCREENSHOT }).catch(() => undefined);
+};
+
+const noteWindowPage = async (memoId, timeout = 20_000) => {
+ const deadline = Date.now() + timeout;
+ while (Date.now() < deadline) {
+ const found = application.windows().find((window) => window.url().includes(`noteWindow=${memoId}`));
+ if (found) return found;
+ await new Promise((resolveWait) => setTimeout(resolveWait, 100));
+ }
+ return null;
+};
+const noteWindowCount = () => application.windows().filter((window) => window.url().includes("noteWindow=")).length;
+const waitForNoteWindowClosed = async (memoId, timeout = 20_000) => {
+ const deadline = Date.now() + timeout;
+ while (Date.now() < deadline) {
+ if (!application.windows().some((window) => window.url().includes(`noteWindow=${memoId}`))) return;
+ await new Promise((resolveWait) => setTimeout(resolveWait, 100));
+ }
+ throw new Error("note window did not close");
+};
+const focusedUrl = () => application.evaluate(({ BrowserWindow }) => BrowserWindow.getFocusedWindow()?.webContents.getURL() ?? null);
+const focusMain = () => application.evaluate(({ BrowserWindow }) => {
+ const main = BrowserWindow.getAllWindows().find((window) => !window.webContents.getURL().includes("noteWindow="));
+ main.show();
+ main.focus();
+});
+const syncNow = () => application.evaluate(({ BrowserWindow }) => {
+ BrowserWindow.getAllWindows().find((window) => !window.webContents.getURL().includes("noteWindow="))
+ .webContents.send("desktop:command", "sync-now");
+});
+const closeWindowLikeUser = (memoId) => application.evaluate(({ BrowserWindow }, id) => {
+ BrowserWindow.getAllWindows().find((window) => window.webContents.getURL().includes(`noteWindow=${id}`))?.close();
+}, memoId);
+// The application menu follows the OS language, not the app language.
+const menuLabels = (key) => ["en-US", "zh-CN", "ja", "pl", "ru"].map((locale) => desktopMenuCopy(locale)[key]).filter(Boolean);
+const clickMenuItem = (key) => application.evaluate(({ Menu }, labels) => {
+ const find = (items) => {
+ for (const item of items) {
+ if (labels.includes(item.label)) return item;
+ const nested = item.submenu && find(item.submenu.items);
+ if (nested) return nested;
+ }
+ return null;
+ };
+ const item = find(Menu.getApplicationMenu().items);
+ if (!item) throw new Error(`menu item ${labels[0]} missing`);
+ item.click();
+}, menuLabels(key));
+
+const noteEditor = () => note.locator(".ProseMirror[contenteditable='true']");
+const mainEditor = () => page.locator(".ProseMirror[contenteditable='true']");
+const typeAtEnd = async (target, editor, text) => {
+ await editor.click();
+ await target.keyboard.press("ControlOrMeta+End");
+ await target.keyboard.type(text);
+};
+const openInMain = async (memo) => {
+ await page.getByPlaceholder("Search notes").first().fill(memo.title);
+ const card = page.locator(`[data-memo-id="${memo.id}"]`).first();
+ await expect(card).toBeVisible({ timeout: 30_000 });
+ await card.locator("button").first().click();
+ await expect(mainEditor()).toContainText(memo.contentMarkdown.split("\n")[0], { timeout: 20_000 });
+ return mainEditor();
+};
+const chooseOpenInNewWindow = async () => {
+ await page.getByRole("button", { name: "More note actions" }).click({ timeout: 15_000 });
+ await page.getByRole("menuitem", { name: "Open in new window" }).click({ timeout: 15_000 });
+};
+const closeNotice = async () => {
+ await page.keyboard.press("Escape");
+ await page.getByRole("button", { name: /OK|Close|Got it/i }).first().click({ timeout: 2_000 }).catch(() => undefined);
+};
+const outboxStatuses = (memoId) => page.evaluate(async (id) => {
+ const { items } = await window.edgeeverDesktop.sidecarRequest("sync.outbox.list", { limit: 200, includeConflicts: true });
+ return items.filter((item) => item.entityId === id).map((item) => item.status);
+}, memoId);
+
+try {
+ server = spawn("bun", ["tests/desktop-note-window-api.mjs", directory], { stdio: ["pipe", "pipe", "inherit"] });
+ baseUrl = await new Promise((resolveUrl, reject) => {
+ let output = "";
+ server.on("error", reject);
+ server.on("exit", (code) => reject(new Error(`test API exited with code ${code}`)));
+ server.stdout.on("data", (chunk) => {
+ output += chunk;
+ const ready = output.match(/READY (\S+)/);
+ if (ready) resolveUrl(ready[1]);
+ });
+ });
+ notebookId = (await api("/api/v1/notebooks", { method: "POST", body: JSON.stringify({ name: "Note windows" }) })).notebook.id;
+ const memoA = await createMemo("Window A", "Alpha body");
+ const memoB = await createMemo("Window B", "Bravo body");
+ const memoC = await createMemo("Window C", "Charlie body");
+ const memoD = await createMemo("Window D", "Delta body");
+ const memoE = await createMemo("Window E", "Echo body");
+
+ await mkdir(profile, { recursive: true });
+ await writeFile(join(profile, "instance-url"), baseUrl);
+ await writeFile(join(profile, "installation-confirmed"), "test");
+ await launch();
+
+ await step("A1: unsaved edits move with the note to its new window", async () => {
+ await typeAtEnd(page, await openInMain(memoA), " typed-before-move");
+ await chooseOpenInNewWindow();
+ note = await noteWindowPage(memoA.id);
+ assert.ok(note, "note window opened");
+ await expect(noteEditor()).toContainText("typed-before-move", { timeout: 20_000 });
+ await expect(page.getByTestId("note-in-separate-window")).toBeVisible();
+ await expect(mainEditor()).toHaveCount(0);
+ assert.equal(noteWindowCount(), 1);
+ });
+
+ await step("A2: opening the note again from any entry focuses the same window", async () => {
+ assert.deepEqual(await page.evaluate((id) => window.edgeeverDesktop.openNoteWindow(id), memoA.id), { opened: false });
+ await focusMain();
+ await clickMenuItem("openNoteWindow");
+ await expect.poll(focusedUrl).toContain(`noteWindow=${memoA.id}`);
+ await focusMain();
+ await page.locator(`[data-memo-id="${memoA.id}"]`).first().locator("button").first().click();
+ await expect.poll(focusedUrl).toContain(`noteWindow=${memoA.id}`);
+ await focusMain();
+ await page.getByRole("button", { name: "Show window" }).click();
+ await expect.poll(focusedUrl).toContain(`noteWindow=${memoA.id}`);
+ assert.equal(noteWindowCount(), 1);
+ });
+
+ await step("A3: a note window cannot open windows, switch accounts or change the instance", async () => {
+ await assert.rejects(note.evaluate((id) => window.edgeeverDesktop.openNoteWindow(id), memoB.id));
+ await assert.rejects(note.evaluate(() => window.edgeeverDesktop.setAccountScope("someone-else")));
+ await assert.rejects(note.evaluate(() => window.edgeeverDesktop.setApiBaseUrl("http://127.0.0.1:1")));
+ assert.equal((await note.evaluate(() => window.edgeeverDesktop.noteWindows())).length, 0);
+ });
+
+ await step("B1: closing the note window saves pending edits and returns the note", async () => {
+ await typeAtEnd(note, noteEditor(), " typed-in-window");
+ await closeWindowLikeUser(memoA.id);
+ await waitForNoteWindowClosed(memoA.id);
+ await expect(page.getByTestId("note-in-separate-window")).toHaveCount(0, { timeout: 10_000 });
+ await expect(mainEditor()).toContainText("typed-in-window", { timeout: 20_000 });
+ await syncNow();
+ await expect.poll(() => serverMarkdown(memoA.id), { timeout: 60_000 }).toContain("typed-in-window");
+ assert.match(await serverMarkdown(memoA.id), /typed-before-move/);
+ });
+
+ await step("C1: two notes can each have their own window, and links open in the main window", async () => {
+ await chooseOpenInNewWindow();
+ note = await noteWindowPage(memoA.id);
+ await expect(noteEditor()).toContainText("typed-in-window", { timeout: 20_000 });
+ assert.equal(await note.evaluate((id) => window.edgeeverDesktop.openMemoInMainWindow(id), memoB.id), true);
+ await expect(mainEditor()).toContainText("Bravo body", { timeout: 20_000 });
+ await chooseOpenInNewWindow();
+ assert.ok(await noteWindowPage(memoB.id));
+ assert.equal(noteWindowCount(), 2);
+ // Closing right after opening must work too.
+ await closeWindowLikeUser(memoB.id);
+ await waitForNoteWindowClosed(memoB.id);
+ assert.equal(noteWindowCount(), 1);
+ });
+
+ await step("D1: if saving before the move fails, the note stays in the main window", async () => {
+ await closeWindowLikeUser(memoA.id);
+ await waitForNoteWindowClosed(memoA.id);
+ const editor = await openInMain(memoA);
+ signalSidecars("SIGSTOP");
+ try {
+ await typeAtEnd(page, editor, " typed-while-storage-down");
+ await chooseOpenInNewWindow();
+ await expect(page.getByText("couldn't be saved, so it stays in this window")).toBeVisible({ timeout: 60_000 });
+ assert.equal(noteWindowCount(), 0);
+ await expect(mainEditor()).toContainText("typed-while-storage-down");
+ } finally {
+ signalSidecars("SIGCONT");
+ }
+ await closeNotice();
+ });
+
+ await step("E1: if saving on close fails, the window stays open; closing again keeps the draft", async () => {
+ await chooseOpenInNewWindow();
+ note = await noteWindowPage(memoA.id, 60_000);
+ await expect(noteEditor()).toContainText("typed-while-storage-down", { timeout: 20_000 });
+ signalSidecars("SIGSTOP");
+ try {
+ await typeAtEnd(note, noteEditor(), " draft-only-edit");
+ await closeWindowLikeUser(memoA.id);
+ await expect(note.getByRole("alert")).toContainText("couldn't be saved", { timeout: 60_000 });
+ assert.equal(noteWindowCount(), 1);
+ await closeWindowLikeUser(memoA.id);
+ await waitForNoteWindowClosed(memoA.id);
+ } finally {
+ signalSidecars("SIGCONT");
+ }
+ await expect(mainEditor()).toContainText("draft-only-edit", { timeout: 30_000 });
+ });
+
+ await step("F1: quitting saves the open note window; windows are not restored", async () => {
+ await chooseOpenInNewWindow();
+ note = await noteWindowPage(memoA.id);
+ await expect(noteEditor()).toContainText("Alpha body", { timeout: 20_000 });
+ await typeAtEnd(note, noteEditor(), " typed-before-quit");
+ await application.evaluate(({ app }) => app.quit());
+ await application.waitForEvent("close", { timeout: 30_000 }).catch(() => undefined);
+ await launch();
+ assert.equal(noteWindowCount(), 0, "note windows are not restored after a restart");
+ await openInMain(memoA);
+ await expect(mainEditor()).toContainText("typed-before-quit", { timeout: 20_000 });
+ });
+
+ await step("G1: deleting the note in its window closes the window", async () => {
+ await chooseOpenInNewWindow();
+ note = await noteWindowPage(memoA.id);
+ await expect(noteEditor()).toBeVisible({ timeout: 20_000 });
+ await note.getByRole("button", { name: "More note actions" }).click({ timeout: 15_000 });
+ await note.getByRole("menuitem", { name: /Move to trash|Delete/ }).first().click({ timeout: 15_000 });
+ await note.getByRole("button", { name: /Move to trash|Delete/ }).last().click({ timeout: 3_000 }).catch(() => undefined);
+ await waitForNoteWindowClosed(memoA.id);
+ await expect(page.locator(`[data-memo-id="${memoA.id}"]`)).toHaveCount(0, { timeout: 30_000 });
+ });
+
+ await step("H1: a crashed note window gives the note back to the main window with a message", async () => {
+ await openInMain(memoD);
+ await chooseOpenInNewWindow();
+ note = await noteWindowPage(memoD.id);
+ await expect(noteEditor()).toContainText("Delta body", { timeout: 20_000 });
+ await application.evaluate(({ BrowserWindow }, id) => {
+ BrowserWindow.getAllWindows().find((window) => window.webContents.getURL().includes(`noteWindow=${id}`)).webContents.forcefullyCrashRenderer();
+ }, memoD.id);
+ await waitForNoteWindowClosed(memoD.id);
+ await expect(page.getByText("closed unexpectedly")).toBeVisible({ timeout: 20_000 });
+ await closeNotice();
+ await expect(page.getByTestId("note-in-separate-window")).toHaveCount(0, { timeout: 10_000 });
+ await expect(mainEditor()).toContainText("Delta body", { timeout: 20_000 });
+ });
+
+ await step("H2: a note the window cannot show is reported and leaves no window", async () => {
+ await assert.rejects(page.evaluate(() => window.edgeeverDesktop.openNoteWindow("memo_does_not_exist")), /note-unavailable/);
+ await waitForNoteWindowClosed("memo_does_not_exist");
+ assert.deepEqual(await page.evaluate(() => window.edgeeverDesktop.noteWindows()), []);
+ });
+
+ await step("I1: a change made on another device reaches the open note window after sync", async () => {
+ await openInMain(memoE);
+ await chooseOpenInNewWindow();
+ note = await noteWindowPage(memoE.id);
+ await expect(noteEditor()).toContainText("Echo body", { timeout: 20_000 });
+ await editOnServer(memoE.id, "remote-edit-one");
+ await syncNow();
+ await expect(noteEditor()).toContainText("remote-edit-one", { timeout: 40_000 });
+ });
+
+ await step("I2: a sync conflict reaches the note window as it reaches the main window", async () => {
+ await editOnServer(memoE.id, "remote-edit-two");
+ // Typing saves locally on the old revision; the main window's sync then conflicts.
+ await typeAtEnd(note, noteEditor(), " local-edit-two");
+ await note.waitForTimeout(4_000);
+ await syncNow();
+ await expect(noteEditor()).toContainText("remote-edit-two", { timeout: 40_000 });
+ await expect.poll(() => outboxStatuses(memoE.id), { timeout: 40_000 }).toContain("conflict");
+ });
+} finally {
+ signalSidecars("SIGCONT");
+ let closeTimer;
+ await Promise.race([
+ application?.close().catch(() => undefined),
+ new Promise((resolveWait) => { closeTimer = setTimeout(resolveWait, 20_000); }),
+ ]);
+ clearTimeout(closeTimer);
+ // Windows keeps the database locked until the API process has exited.
+ if (server && server.exitCode === null) {
+ const exited = new Promise((resolveExit) => server.once("exit", resolveExit));
+ server.stdin.end();
+ let killTimer;
+ await Promise.race([exited, new Promise((resolveWait) => { killTimer = setTimeout(resolveWait, 10_000); })]);
+ clearTimeout(killTimer);
+ if (server.exitCode === null) {
+ server.kill();
+ await exited;
+ }
+ }
+ await rm(directory, { recursive: true, force: true, maxRetries: 5, retryDelay: 500 });
+}
+
+const failed = results.filter((result) => !result.ok);
+console.log(`Packaged note windows: ${results.length - failed.length}/${results.length} scenarios passed.`);
+if (failed.length || !results.length) process.exit(1);