Open History to see the last commit
1import assert from "node:assert/strict";
2import { readFile } from "node:fs/promises";
3import test from "node:test";
4
5const read = (path) => readFile(new URL(`../${path}`, import.meta.url), "utf8");
6
7test("Windows persistence retry policy is centralized and bounded", async () => {
8 const [helper, sharedPackage] = await Promise.all([
9 read("packages/shared/src/windowsFileRetry.ts"),
10 read("packages/shared/package.json"),
11 ]);
12 assert.match(helper, /WINDOWS_FILE_RETRY_DELAYS/);
13 assert.match(helper, /Busy/);
14 assert.match(helper, /PermissionDenied/);
15 assert.match(helper, /WouldBlock/);
16 assert.match(helper, /EPERM/);
17 assert.match(helper, /platform !== "win32"/);
18 assert.match(sharedPackage, /"\.\/windowsFileRetry"/);
19});
20
21test("desktop and server persistence routes through the Windows retry policy", async () => {
22 const files = await Promise.all([
23 read("apps/desktop/src/settings/DesktopAppSettings.ts"),
24 read("apps/desktop/src/settings/DesktopClientSettings.ts"),
25 read("apps/desktop/src/settings/DesktopSavedEnvironments.ts"),
26 read("apps/desktop/src/app/DesktopConnectionCatalogStore.ts"),
27 read("apps/desktop/src/app/DesktopObservability.ts"),
28 read("apps/server/src/atomicWrite.ts"),
29 read("apps/server/src/auth/ServerSecretStore.ts"),
30 read("apps/server/src/serverRuntimeState.ts"),
31 ]);
32 for (const source of files) {
33 assert.match(source, /retryWindowsFileSystemOperation/);
34 }
35 assert.match(files[4], /fileSystem\.writeFile\(input\.filePath, chunk, \{ flag: "a" \}\)/);
36 assert.match(files[5], /fs\.rename\(tempPath, input\.filePath\)/);
37});
38
39test("resume recovery probes before restarting and re-resolves WSL state", async () => {
40 const [manager, recovery, app, main] = await Promise.all([
41 read("apps/desktop/src/backend/DesktopBackendManager.ts"),
42 read("apps/desktop/src/app/DesktopPowerRecovery.ts"),
43 read("apps/desktop/src/app/DesktopApp.ts"),
44 read("apps/desktop/src/main.ts"),
45 ]);
46 assert.match(manager, /readonly probeReady/);
47 assert.match(manager, /waitForHttpReady\(/);
48 assert.match(recovery, /onSimpleEvent\("suspend"/);
49 assert.match(recovery, /onSimpleEvent\("resume"/);
50 assert.match(recovery, /RESUME_SETTLE_DELAY/);
51 assert.match(recovery, /generationRef/);
52 assert.match(recovery, /recoveryMutex/);
53 assert.match(recovery, /instance\.probeReady/);
54 assert.match(recovery, /instance\.stop/);
55 assert.match(recovery, /instance\.start/);
56 assert.match(recovery, /wslBackend\.reconcile/);
57 assert.match(recovery, /environment\.platform !== "win32"/);
58 assert.match(app, /yield\* electronApp\.whenReady[\s\S]*yield\* powerRecovery\.register/);
59 assert.match(main, /DesktopPowerRecovery\.layer/);
60});
61
62test("Windows CI exercises a real exclusive file handle", async () => {
63 const [ci, lockTest] = await Promise.all([
64 read(".github/workflows/ci.yml"),
65 read("scripts/windows-persistence-lock.test.mjs"),
66 ]);
67 assert.match(ci, /windows-persistence-lock\.test\.mjs/);
68 assert.match(lockTest, /FileShare\]::None/);
69 assert.match(lockTest, /T3-persist|t3-persist/);
70 assert.match(lockTest, /attempts > 1/);
71});