test(desktop): make path fixtures and timeouts host-portable (#9568)
Co-authored-by: Claude Code <[email protected]>
This commit is contained in:
1 parent
5c6c1d67d8
commit
c251e41b5e
6 files changed
+133
-87
No files matched your search
@@ -165,10 +165,14 @@ function registerMacLauncherBundle(appBundlePath) {
|
||||
}
|
||||
}
|
||||
|
||||
// Bundle-internal paths are macOS paths whatever host builds them.
|
||||
export function resolveMacLauncherIconPaths(runtimeDir, development = isDevelopment) {
|
||||
return {
|
||||
sourceIconPath: development ? developmentMacIconPngPath : productionMacIconPngPath,
|
||||
generatedIconPath: NodePath.join(runtimeDir, development ? "icon-dev.icns" : "icon-prod.icns"),
|
||||
generatedIconPath: NodePath.posix.join(
|
||||
runtimeDir,
|
||||
development ? "icon-dev.icns" : "icon-prod.icns",
|
||||
),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -280,12 +284,12 @@ function readJson(path) {
|
||||
}
|
||||
|
||||
export function resolveMacLauncherPaths(appBundlePath, displayName = APP_DISPLAY_NAME) {
|
||||
const executableDir = NodePath.join(appBundlePath, "Contents", "MacOS");
|
||||
const executableDir = NodePath.posix.join(appBundlePath, "Contents", "MacOS");
|
||||
const launcherExecutableName = `${displayName} Launcher`;
|
||||
return {
|
||||
launcherExecutableName,
|
||||
launcherBinaryPath: NodePath.join(executableDir, launcherExecutableName),
|
||||
runtimeElectronBinaryPath: NodePath.join(executableDir, "Electron"),
|
||||
launcherBinaryPath: NodePath.posix.join(executableDir, launcherExecutableName),
|
||||
runtimeElectronBinaryPath: NodePath.posix.join(executableDir, "Electron"),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -84,9 +84,10 @@ describe("electron development launcher", () => {
|
||||
const development = resolveMacLauncherIconPaths("/runtime", true);
|
||||
const production = resolveMacLauncherIconPaths("/runtime", false);
|
||||
|
||||
assert.match(development.sourceIconPath, /assets\/dev\/blueprint-macos-1024\.png$/);
|
||||
// The source icons are real repo paths, joined for the host.
|
||||
assert.match(development.sourceIconPath, /assets[\\/]dev[\\/]blueprint-macos-1024\.png$/);
|
||||
assert.equal(development.generatedIconPath, "/runtime/icon-dev.icns");
|
||||
assert.match(production.sourceIconPath, /assets\/prod\/black-macos-1024\.png$/);
|
||||
assert.match(production.sourceIconPath, /assets[\\/]prod[\\/]black-macos-1024\.png$/);
|
||||
assert.equal(production.generatedIconPath, "/runtime/icon-prod.icns");
|
||||
});
|
||||
});
|
||||
@@ -4,6 +4,7 @@ import { ConnectionCatalogDocument } from "@t3tools/client-runtime/platform";
|
||||
import { EnvironmentId, type PersistedSavedEnvironmentRecord } from "@t3tools/contracts";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as FileSystem from "effect/FileSystem";
|
||||
import * as Path from "effect/Path";
|
||||
import * as Layer from "effect/Layer";
|
||||
import * as Option from "effect/Option";
|
||||
import * as PlatformError from "effect/PlatformError";
|
||||
@@ -226,10 +227,11 @@ describe("DesktopConnectionCatalogStore", () => {
|
||||
it.effect("surfaces malformed catalog documents without deleting them", () =>
|
||||
withStore(
|
||||
Effect.gen(function* () {
|
||||
const path = yield* Path.Path;
|
||||
const environment = yield* DesktopEnvironment.DesktopEnvironment;
|
||||
const fileSystem = yield* FileSystem.FileSystem;
|
||||
const store = yield* DesktopConnectionCatalogStore.DesktopConnectionCatalogStore;
|
||||
const catalogPath = `${environment.stateDir}/connection-catalog.json`;
|
||||
const catalogPath = path.join(environment.stateDir, "connection-catalog.json");
|
||||
yield* fileSystem.makeDirectory(environment.stateDir, { recursive: true });
|
||||
yield* fileSystem.writeFileString(catalogPath, "{not-json");
|
||||
|
||||
@@ -247,6 +249,7 @@ describe("DesktopConnectionCatalogStore", () => {
|
||||
|
||||
it.effect("surfaces catalog filesystem failures instead of treating them as missing", () =>
|
||||
Effect.gen(function* () {
|
||||
const path = yield* Path.Path;
|
||||
const baseFileSystem = yield* FileSystem.FileSystem;
|
||||
const baseDir = yield* baseFileSystem.makeTempDirectoryScoped({
|
||||
prefix: "t3-desktop-connection-catalog-test-",
|
||||
@@ -255,7 +258,7 @@ describe("DesktopConnectionCatalogStore", () => {
|
||||
_tag: "PermissionDenied",
|
||||
module: "FileSystem",
|
||||
method: "readFileString",
|
||||
pathOrDescriptor: `${baseDir}/userdata/connection-catalog.json`,
|
||||
pathOrDescriptor: path.join(baseDir, "userdata", "connection-catalog.json"),
|
||||
});
|
||||
const fileSystemLayer = Layer.succeed(
|
||||
FileSystem.FileSystem,
|
||||
@@ -272,11 +275,11 @@ describe("DesktopConnectionCatalogStore", () => {
|
||||
error,
|
||||
DesktopConnectionCatalogStore.DesktopConnectionCatalogStoreReadError,
|
||||
);
|
||||
assert.equal(error.catalogPath, `${baseDir}/userdata/connection-catalog.json`);
|
||||
assert.equal(error.catalogPath, path.join(baseDir, "userdata", "connection-catalog.json"));
|
||||
assert.strictEqual(error.cause, permissionError);
|
||||
assert.equal(
|
||||
error.message,
|
||||
`Failed to read the desktop connection catalog at ${baseDir}/userdata/connection-catalog.json.`,
|
||||
`Failed to read the desktop connection catalog at ${path.join(baseDir, "userdata", "connection-catalog.json")}.`,
|
||||
);
|
||||
assert.notEqual(error.message, permissionError.message);
|
||||
}).pipe(Effect.provide(NodeServices.layer), Effect.scoped),
|
||||
@@ -285,6 +288,7 @@ describe("DesktopConnectionCatalogStore", () => {
|
||||
it.effect("reports the failed catalog write operation and path", () =>
|
||||
Effect.gen(function* () {
|
||||
const baseFileSystem = yield* FileSystem.FileSystem;
|
||||
const path = yield* Path.Path;
|
||||
const baseDir = yield* baseFileSystem.makeTempDirectoryScoped({
|
||||
prefix: "t3-desktop-connection-catalog-test-",
|
||||
});
|
||||
@@ -292,7 +296,7 @@ describe("DesktopConnectionCatalogStore", () => {
|
||||
_tag: "PermissionDenied",
|
||||
module: "FileSystem",
|
||||
method: "makeDirectory",
|
||||
pathOrDescriptor: `${baseDir}/userdata`,
|
||||
pathOrDescriptor: path.join(baseDir, "userdata"),
|
||||
});
|
||||
const fileSystemLayer = Layer.succeed(
|
||||
FileSystem.FileSystem,
|
||||
@@ -310,11 +314,11 @@ describe("DesktopConnectionCatalogStore", () => {
|
||||
DesktopConnectionCatalogStore.DesktopConnectionCatalogStoreWriteError,
|
||||
);
|
||||
assert.equal(error.operation, "create-directory");
|
||||
assert.equal(error.path, `${baseDir}/userdata`);
|
||||
assert.equal(error.path, path.join(baseDir, "userdata"));
|
||||
assert.strictEqual(error.cause, permissionError);
|
||||
assert.equal(
|
||||
error.message,
|
||||
`Desktop connection catalog write failed during create-directory at ${baseDir}/userdata.`,
|
||||
`Desktop connection catalog write failed during create-directory at ${path.join(baseDir, "userdata")}.`,
|
||||
);
|
||||
assert.notEqual(error.message, permissionError.message);
|
||||
}).pipe(Effect.provide(NodeServices.layer), Effect.scoped),
|
||||
@@ -323,6 +327,7 @@ describe("DesktopConnectionCatalogStore", () => {
|
||||
it.effect("reports the legacy migration stage", () =>
|
||||
withStore(
|
||||
Effect.gen(function* () {
|
||||
const path = yield* Path.Path;
|
||||
const environment = yield* DesktopEnvironment.DesktopEnvironment;
|
||||
const fileSystem = yield* FileSystem.FileSystem;
|
||||
const store = yield* DesktopConnectionCatalogStore.DesktopConnectionCatalogStore;
|
||||
@@ -335,7 +340,7 @@ describe("DesktopConnectionCatalogStore", () => {
|
||||
DesktopConnectionCatalogStore.DesktopConnectionCatalogStoreMigrationError,
|
||||
);
|
||||
assert.equal(error.operation, "read-legacy-registry");
|
||||
assert.equal(error.catalogPath, `${environment.stateDir}/connection-catalog.json`);
|
||||
assert.equal(error.catalogPath, path.join(environment.stateDir, "connection-catalog.json"));
|
||||
assert.instanceOf(
|
||||
error.cause,
|
||||
DesktopSavedEnvironments.DesktopSavedEnvironmentsDocumentDecodeError,
|
||||
@@ -345,7 +350,7 @@ describe("DesktopConnectionCatalogStore", () => {
|
||||
assert.exists(registryError.cause);
|
||||
assert.equal(
|
||||
error.message,
|
||||
`Legacy desktop saved-environment migration failed during read-legacy-registry into ${environment.stateDir}/connection-catalog.json.`,
|
||||
`Legacy desktop saved-environment migration failed during read-legacy-registry into ${path.join(environment.stateDir, "connection-catalog.json")}.`,
|
||||
);
|
||||
assert.notEqual(error.message, registryError.message);
|
||||
}),
|
||||
@@ -355,10 +360,11 @@ describe("DesktopConnectionCatalogStore", () => {
|
||||
it.effect("reports invalid encrypted catalog data without exposing it", () =>
|
||||
withStore(
|
||||
Effect.gen(function* () {
|
||||
const path = yield* Path.Path;
|
||||
const environment = yield* DesktopEnvironment.DesktopEnvironment;
|
||||
const fileSystem = yield* FileSystem.FileSystem;
|
||||
const store = yield* DesktopConnectionCatalogStore.DesktopConnectionCatalogStore;
|
||||
const catalogPath = `${environment.stateDir}/connection-catalog.json`;
|
||||
const catalogPath = path.join(environment.stateDir, "connection-catalog.json");
|
||||
yield* fileSystem.makeDirectory(environment.stateDir, { recursive: true });
|
||||
yield* fileSystem.writeFileString(catalogPath, '{"version":1,"encryptedCatalog":"%%%"}\n');
|
||||
|
||||
@@ -381,6 +387,7 @@ describe("DesktopConnectionCatalogStore", () => {
|
||||
|
||||
it.effect("surfaces a catalog that can no longer be decrypted without deleting it", () =>
|
||||
Effect.gen(function* () {
|
||||
const path = yield* Path.Path;
|
||||
const fileSystem = yield* FileSystem.FileSystem;
|
||||
const baseDir = yield* fileSystem.makeTempDirectoryScoped({
|
||||
prefix: "t3-desktop-connection-catalog-test-",
|
||||
@@ -399,14 +406,14 @@ describe("DesktopConnectionCatalogStore", () => {
|
||||
DesktopConnectionCatalogStore.DesktopConnectionCatalogStoreProtectionError,
|
||||
);
|
||||
assert.equal(error.operation, "decrypt-catalog");
|
||||
assert.equal(error.catalogPath, `${baseDir}/userdata/connection-catalog.json`);
|
||||
assert.equal(error.catalogPath, path.join(baseDir, "userdata", "connection-catalog.json"));
|
||||
assert.instanceOf(error.cause, ElectronSafeStorage.ElectronSafeStorageDecryptError);
|
||||
const decryptError = error.cause as ElectronSafeStorage.ElectronSafeStorageDecryptError;
|
||||
assert.instanceOf(decryptError.cause, Error);
|
||||
assert.equal(decryptError.cause.message, "invalid encrypted catalog");
|
||||
assert.equal(
|
||||
error.message,
|
||||
`Desktop connection catalog protection failed during decrypt-catalog at ${baseDir}/userdata/connection-catalog.json.`,
|
||||
`Desktop connection catalog protection failed during decrypt-catalog at ${path.join(baseDir, "userdata", "connection-catalog.json")}.`,
|
||||
);
|
||||
assert.notEqual(error.message, decryptError.message);
|
||||
yield* Ref.set(failDecrypt, false);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
// @effect-diagnostics nodeBuiltinImport:off - Builds a Chromium-shaped cookie
|
||||
// table with the same native bindings the source reads.
|
||||
import * as NodePath from "node:path";
|
||||
import * as NodeServices from "@effect/platform-node/NodeServices";
|
||||
import { assert, describe, it } from "@effect/vitest";
|
||||
import {
|
||||
@@ -531,7 +532,7 @@ Path=Profiles/wxyz.empty
|
||||
yield* fileSystem.makeDirectory(`${root}/Profiles/wxyz.empty`, { recursive: true });
|
||||
|
||||
assert.deepEqual(yield* listSourceProfiles(firefox, context), [
|
||||
{ directory: "Profiles/abcd.default-release", name: "original" },
|
||||
{ directory: context.path.join("Profiles", "abcd.default-release"), name: "original" },
|
||||
]);
|
||||
}),
|
||||
),
|
||||
@@ -612,10 +613,16 @@ describe("cookieDatabaseCandidatePaths", () => {
|
||||
run(
|
||||
Effect.gen(function* () {
|
||||
const context = yield* withSourceHome();
|
||||
const profile = `${context.home}/Library/Application Support/net.imput.helium/Profile 1`;
|
||||
const profile = context.path.join(
|
||||
context.home,
|
||||
"Library",
|
||||
"Application Support",
|
||||
"net.imput.helium",
|
||||
"Profile 1",
|
||||
);
|
||||
assert.deepEqual(cookieDatabaseCandidatePaths(helium, context, "Profile 1"), [
|
||||
`${profile}/Network/Cookies`,
|
||||
`${profile}/Cookies`,
|
||||
context.path.join(profile, "Network", "Cookies"),
|
||||
context.path.join(profile, "Cookies"),
|
||||
]);
|
||||
}),
|
||||
),
|
||||
@@ -626,7 +633,7 @@ describe("cookieDatabaseCandidatePaths", () => {
|
||||
Effect.gen(function* () {
|
||||
const fileSystem = yield* FileSystem.FileSystem;
|
||||
const context = yield* withSourceHome();
|
||||
const root = helium.userDataDirectory(context);
|
||||
const root = userDataDirectory(context);
|
||||
// Chromium 96+ keeps sessions in Network/; a root Cookies left behind
|
||||
// by the move is stale and must not be the one imported.
|
||||
yield* fileSystem.makeDirectory(`${root}/Default/Network`, { recursive: true });
|
||||
@@ -635,7 +642,7 @@ describe("cookieDatabaseCandidatePaths", () => {
|
||||
|
||||
assert.equal(
|
||||
yield* resolveCookieDatabase(helium, context, "Default"),
|
||||
`${root}/Default/Network/Cookies`,
|
||||
context.path.join(root, "Default", "Network", "Cookies"),
|
||||
);
|
||||
// A fresh install with only the Network/ jar is installed, not hidden.
|
||||
yield* fileSystem.remove(`${root}/Default/Cookies`);
|
||||
@@ -680,8 +687,8 @@ describe("Firefox Snap profiles", () => {
|
||||
Effect.provideService(HostProcessEnvironment, { HOME: home }),
|
||||
Effect.provideService(HostProcessPlatform, "linux"),
|
||||
);
|
||||
const root = `${home}/snap/firefox/common/.mozilla/firefox`;
|
||||
const directory = `${root}/abcd.default`;
|
||||
const root = context.path.join(home, "snap", "firefox", "common", ".mozilla", "firefox");
|
||||
const directory = context.path.join(root, "abcd.default");
|
||||
yield* fileSystem.makeDirectory(directory, { recursive: true });
|
||||
yield* writeFirefoxCookieDatabase(`${directory}/cookies.sqlite`, 2, 1);
|
||||
yield* fileSystem.writeFileString(
|
||||
@@ -695,7 +702,7 @@ describe("Firefox Snap profiles", () => {
|
||||
]);
|
||||
assert.equal(
|
||||
yield* resolveCookieDatabase(firefox, context, directory),
|
||||
`${directory}/cookies.sqlite`,
|
||||
context.path.join(directory, "cookies.sqlite"),
|
||||
);
|
||||
assert.isFalse(yield* isSourceRunning(firefox, context));
|
||||
yield* fileSystem.symlink("foreign-host:+4242", `${directory}/lock`);
|
||||
@@ -720,8 +727,8 @@ describe("Firefox Snap profiles", () => {
|
||||
Effect.provideService(HostProcessEnvironment, { HOME: home }),
|
||||
Effect.provideService(HostProcessPlatform, "linux"),
|
||||
);
|
||||
const native = `${home}/.mozilla/firefox`;
|
||||
const snap = `${home}/snap/firefox/common/.mozilla/firefox`;
|
||||
const native = context.path.join(home, ".mozilla", "firefox");
|
||||
const snap = context.path.join(home, "snap", "firefox", "common", ".mozilla", "firefox");
|
||||
for (const root of [native, snap]) {
|
||||
yield* fileSystem.makeDirectory(`${root}/abcd.default`, { recursive: true });
|
||||
yield* writeFirefoxCookieDatabase(`${root}/abcd.default/cookies.sqlite`, 1, 0);
|
||||
@@ -735,14 +742,14 @@ describe("Firefox Snap profiles", () => {
|
||||
const profiles = yield* listSourceProfiles(firefox, context);
|
||||
assert.deepEqual(
|
||||
profiles.map((profile) => profile.directory),
|
||||
["abcd.default", `${snap}/abcd.default`],
|
||||
["abcd.default", context.path.join(snap, "abcd.default")],
|
||||
);
|
||||
const databases = yield* Effect.forEach(profiles, (profile) =>
|
||||
resolveCookieDatabase(firefox, context, profile.directory),
|
||||
);
|
||||
assert.deepEqual(databases, [
|
||||
`${native}/abcd.default/cookies.sqlite`,
|
||||
`${snap}/abcd.default/cookies.sqlite`,
|
||||
context.path.join(native, "abcd.default", "cookies.sqlite"),
|
||||
context.path.join(snap, "abcd.default", "cookies.sqlite"),
|
||||
]);
|
||||
}),
|
||||
),
|
||||
@@ -752,8 +759,8 @@ describe("Firefox Snap profiles", () => {
|
||||
describe("listSourceProfiles Firefox fallback", () => {
|
||||
const cases = [
|
||||
{ platform: "linux" as const, profileDirectory: "linux.default" },
|
||||
{ platform: "darwin" as const, profileDirectory: "Profiles/macos.default" },
|
||||
{ platform: "win32" as const, profileDirectory: "Profiles/windows.default" },
|
||||
{ platform: "darwin" as const, profileDirectory: NodePath.join("Profiles", "macos.default") },
|
||||
{ platform: "win32" as const, profileDirectory: NodePath.join("Profiles", "windows.default") },
|
||||
];
|
||||
|
||||
for (const { platform, profileDirectory } of cases) {
|
||||
@@ -824,7 +831,11 @@ describe("listSourceProfiles Firefox fallback", () => {
|
||||
|
||||
// Returning the empty declared list would hide the browser entirely.
|
||||
assert.deepEqual(yield* listSourceProfiles(firefox, context), [
|
||||
{ directory: "Profiles/real.default", name: "real.default", cookieCount: 3 },
|
||||
{
|
||||
directory: path.join("Profiles", "real.default"),
|
||||
name: "real.default",
|
||||
cookieCount: 3,
|
||||
},
|
||||
]);
|
||||
assert.isTrue(yield* isSourceInstalled(firefox, context));
|
||||
}),
|
||||
@@ -855,7 +866,11 @@ describe("listSourceProfiles Firefox fallback", () => {
|
||||
);
|
||||
|
||||
assert.deepEqual(yield* listSourceProfiles(firefox, context), [
|
||||
{ directory: "Profiles/declared.default", name: "Declared", cookieCount: 2 },
|
||||
{
|
||||
directory: path.join("Profiles", "declared.default"),
|
||||
name: "Declared",
|
||||
cookieCount: 2,
|
||||
},
|
||||
]);
|
||||
|
||||
yield* fileSystem.remove(path.join(root, "profiles.ini"));
|
||||
@@ -864,8 +879,16 @@ describe("listSourceProfiles Firefox fallback", () => {
|
||||
yield* writeFirefoxCookieDatabase(path.join(fallbackDirectory, "cookies.sqlite"), 1, 4);
|
||||
|
||||
assert.deepEqual(yield* listSourceProfiles(firefox, context), [
|
||||
{ directory: "Profiles/declared.default", name: "declared.default", cookieCount: 2 },
|
||||
{ directory: "Profiles/fallback.default", name: "fallback.default", cookieCount: 1 },
|
||||
{
|
||||
directory: path.join("Profiles", "declared.default"),
|
||||
name: "declared.default",
|
||||
cookieCount: 2,
|
||||
},
|
||||
{
|
||||
directory: path.join("Profiles", "fallback.default"),
|
||||
name: "fallback.default",
|
||||
cookieCount: 1,
|
||||
},
|
||||
]);
|
||||
}),
|
||||
),
|
||||
@@ -928,53 +951,56 @@ describe("isSourceRunning for Firefox", () => {
|
||||
),
|
||||
);
|
||||
|
||||
it.effect("detects a live fcntl lock on .parentlock, as macOS Firefox leaves it", () =>
|
||||
run(
|
||||
Effect.gen(function* () {
|
||||
const fileSystem = yield* FileSystem.FileSystem;
|
||||
const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
|
||||
const home = yield* fileSystem.makeTempDirectoryScoped({ prefix: "t3code-firefox-" });
|
||||
const context = yield* sourcePathContext.pipe(
|
||||
Effect.provideService(HostProcessEnvironment, { HOME: home }),
|
||||
Effect.provideService(HostProcessPlatform, "darwin"),
|
||||
);
|
||||
const root = firefox.userDataDirectory(context)!;
|
||||
const profile = `${root}/Profiles/abcd.default-release`;
|
||||
yield* fileSystem.makeDirectory(profile, { recursive: true });
|
||||
yield* fileSystem.writeFileString(`${profile}/cookies.sqlite`, "db");
|
||||
const parentLock = `${profile}/.parentlock`;
|
||||
yield* fileSystem.writeFileString(parentLock, "");
|
||||
// Holds the lock with python3's fcntl, which does not exist on Windows.
|
||||
it.effect.skipIf(HostProcessPlatform.defaultValue() === "win32")(
|
||||
"detects a live fcntl lock on .parentlock, as macOS Firefox leaves it",
|
||||
() =>
|
||||
run(
|
||||
Effect.gen(function* () {
|
||||
const fileSystem = yield* FileSystem.FileSystem;
|
||||
const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
|
||||
const home = yield* fileSystem.makeTempDirectoryScoped({ prefix: "t3code-firefox-" });
|
||||
const context = yield* sourcePathContext.pipe(
|
||||
Effect.provideService(HostProcessEnvironment, { HOME: home }),
|
||||
Effect.provideService(HostProcessPlatform, "darwin"),
|
||||
);
|
||||
const root = firefox.userDataDirectory(context)!;
|
||||
const profile = `${root}/Profiles/abcd.default-release`;
|
||||
yield* fileSystem.makeDirectory(profile, { recursive: true });
|
||||
yield* fileSystem.writeFileString(`${profile}/cookies.sqlite`, "db");
|
||||
const parentLock = `${profile}/.parentlock`;
|
||||
yield* fileSystem.writeFileString(parentLock, "");
|
||||
|
||||
// Hold the lock from a child the way Firefox does (F_SETLK, write),
|
||||
// and keep it until the scope closes.
|
||||
const holder = yield* spawner.spawn(
|
||||
ChildProcess.make(
|
||||
"python3",
|
||||
[
|
||||
"-c",
|
||||
"import fcntl,os,sys,time\n" +
|
||||
"fd=os.open(sys.argv[1],os.O_WRONLY)\n" +
|
||||
"fcntl.lockf(fd,fcntl.LOCK_EX|fcntl.LOCK_NB)\n" +
|
||||
"print('locked',flush=True)\n" +
|
||||
"time.sleep(30)",
|
||||
parentLock,
|
||||
],
|
||||
{ stdin: "ignore" },
|
||||
),
|
||||
);
|
||||
// Wait for the child to confirm it holds the lock before probing.
|
||||
yield* holder.stdout.pipe(
|
||||
Stream.decodeText(),
|
||||
Stream.splitLines,
|
||||
Stream.filter((line) => line.trim() === "locked"),
|
||||
Stream.take(1),
|
||||
Stream.runDrain,
|
||||
);
|
||||
// Hold the lock from a child the way Firefox does (F_SETLK, write),
|
||||
// and keep it until the scope closes.
|
||||
const holder = yield* spawner.spawn(
|
||||
ChildProcess.make(
|
||||
"python3",
|
||||
[
|
||||
"-c",
|
||||
"import fcntl,os,sys,time\n" +
|
||||
"fd=os.open(sys.argv[1],os.O_WRONLY)\n" +
|
||||
"fcntl.lockf(fd,fcntl.LOCK_EX|fcntl.LOCK_NB)\n" +
|
||||
"print('locked',flush=True)\n" +
|
||||
"time.sleep(30)",
|
||||
parentLock,
|
||||
],
|
||||
{ stdin: "ignore" },
|
||||
),
|
||||
);
|
||||
// Wait for the child to confirm it holds the lock before probing.
|
||||
yield* holder.stdout.pipe(
|
||||
Stream.decodeText(),
|
||||
Stream.splitLines,
|
||||
Stream.filter((line) => line.trim() === "locked"),
|
||||
Stream.take(1),
|
||||
Stream.runDrain,
|
||||
);
|
||||
|
||||
assert.isTrue(yield* isSourceRunning(firefox, context));
|
||||
yield* holder.kill();
|
||||
}),
|
||||
),
|
||||
assert.isTrue(yield* isSourceRunning(firefox, context));
|
||||
yield* holder.kill();
|
||||
}),
|
||||
),
|
||||
);
|
||||
|
||||
it.effect("reads a Firefox lock symlink's pid to tell live from crashed", () =>
|
||||
|
||||
@@ -3,6 +3,7 @@ import { assert, describe, it } from "@effect/vitest";
|
||||
import { EnvironmentId, type PersistedSavedEnvironmentRecord } from "@t3tools/contracts";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as FileSystem from "effect/FileSystem";
|
||||
import * as Path from "effect/Path";
|
||||
import * as Layer from "effect/Layer";
|
||||
import * as Option from "effect/Option";
|
||||
import * as PlatformError from "effect/PlatformError";
|
||||
@@ -400,11 +401,12 @@ describe("DesktopSavedEnvironments", () => {
|
||||
|
||||
it.effect("reports saved environment filesystem reads separately from document decoding", () =>
|
||||
Effect.gen(function* () {
|
||||
const path = yield* Path.Path;
|
||||
const baseFileSystem = yield* FileSystem.FileSystem;
|
||||
const baseDir = yield* baseFileSystem.makeTempDirectoryScoped({
|
||||
prefix: "t3-desktop-saved-environments-test-",
|
||||
});
|
||||
const registryPath = `${baseDir}/userdata/saved-environments.json`;
|
||||
const registryPath = path.join(baseDir, "userdata", "saved-environments.json");
|
||||
const permissionError = PlatformError.systemError({
|
||||
_tag: "PermissionDenied",
|
||||
module: "FileSystem",
|
||||
@@ -433,6 +435,7 @@ describe("DesktopSavedEnvironments", () => {
|
||||
it.effect("reports the failed saved environment write operation and path", () =>
|
||||
Effect.gen(function* () {
|
||||
const baseFileSystem = yield* FileSystem.FileSystem;
|
||||
const path = yield* Path.Path;
|
||||
const baseDir = yield* baseFileSystem.makeTempDirectoryScoped({
|
||||
prefix: "t3-desktop-saved-environments-test-",
|
||||
});
|
||||
@@ -440,7 +443,7 @@ describe("DesktopSavedEnvironments", () => {
|
||||
_tag: "PermissionDenied",
|
||||
module: "FileSystem",
|
||||
method: "makeDirectory",
|
||||
pathOrDescriptor: `${baseDir}/userdata`,
|
||||
pathOrDescriptor: path.join(baseDir, "userdata"),
|
||||
});
|
||||
const fileSystemLayer = Layer.succeed(
|
||||
FileSystem.FileSystem,
|
||||
@@ -456,11 +459,11 @@ describe("DesktopSavedEnvironments", () => {
|
||||
const error = yield* savedEnvironments.setRegistry([savedRegistryRecord]).pipe(Effect.flip);
|
||||
assert.instanceOf(error, DesktopSavedEnvironments.DesktopSavedEnvironmentsWriteError);
|
||||
assert.equal(error.operation, "create-directory");
|
||||
assert.equal(error.path, `${baseDir}/userdata`);
|
||||
assert.equal(error.path, path.join(baseDir, "userdata"));
|
||||
assert.strictEqual(error.cause, permissionError);
|
||||
assert.equal(
|
||||
error.message,
|
||||
`Desktop saved-environment write failed during create-directory at ${baseDir}/userdata.`,
|
||||
`Desktop saved-environment write failed during create-directory at ${path.join(baseDir, "userdata")}.`,
|
||||
);
|
||||
assert.notEqual(error.message, permissionError.message);
|
||||
}).pipe(Effect.provide(NodeServices.layer), Effect.scoped),
|
||||
|
||||
@@ -83,4 +83,9 @@ export default defineConfig({
|
||||
entry: ["src/preview-pip-preload.ts"],
|
||||
},
|
||||
],
|
||||
test: {
|
||||
// The Windows lane runs workspace suites concurrently; filesystem-heavy
|
||||
// desktop integration tests can exceed Vitest's 5 second default there.
|
||||
testTimeout: 15_000,
|
||||
},
|
||||
});
|
||||
Reference in new issue
Block a user