mirror of
https://github.com/getpaseo/paseo.git
synced 2026-12-04 06:06:26 +00:00
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
876f6d53a8 |
@@ -239,7 +239,7 @@ describe("desktop-settings", () => {
|
||||
expect(persisted.settings.daemon.manageBuiltInDaemon).toBe(false);
|
||||
});
|
||||
|
||||
it("does not rewrite existing settings while reading them", async () => {
|
||||
it("does not rewrite migrated settings while reading them", async () => {
|
||||
const userDataPath = await createTempUserDataDir();
|
||||
directories.add(userDataPath);
|
||||
const raw = JSON.stringify({
|
||||
@@ -253,6 +253,7 @@ describe("desktop-settings", () => {
|
||||
},
|
||||
migrations: {
|
||||
legacyRendererSettingsImported: false,
|
||||
daemonStopOnQuitDefaultApplied: true,
|
||||
},
|
||||
});
|
||||
await writeFile(settingsFilePath(userDataPath), raw);
|
||||
@@ -265,7 +266,7 @@ describe("desktop-settings", () => {
|
||||
expect(persisted).toBe(raw);
|
||||
});
|
||||
|
||||
it("resets the pre-existing keep-running default so the daemon stops with the app", async () => {
|
||||
it("persists the stop-on-quit migration on the first read", async () => {
|
||||
const userDataPath = await createTempUserDataDir();
|
||||
directories.add(userDataPath);
|
||||
await writeFile(
|
||||
@@ -276,7 +277,7 @@ describe("desktop-settings", () => {
|
||||
releaseChannel: "stable",
|
||||
daemon: { manageBuiltInDaemon: true, keepRunningAfterQuit: true },
|
||||
},
|
||||
migrations: { legacyRendererSettingsImported: true },
|
||||
futureSetting: { value: 7 },
|
||||
}),
|
||||
);
|
||||
const store = createDesktopSettingsStore({ userDataPath });
|
||||
@@ -284,6 +285,12 @@ describe("desktop-settings", () => {
|
||||
const settings = await store.get();
|
||||
|
||||
expect(settings.daemon.keepRunningAfterQuit).toBe(false);
|
||||
const persisted = JSON.parse(await readFile(settingsFilePath(userDataPath), "utf8"));
|
||||
expect(persisted).toMatchObject({
|
||||
settings: { daemon: { manageBuiltInDaemon: true, keepRunningAfterQuit: false } },
|
||||
migrations: { daemonStopOnQuitDefaultApplied: true },
|
||||
futureSetting: { value: 7 },
|
||||
});
|
||||
});
|
||||
|
||||
it("keeps an explicit keep-running choice across restarts", async () => {
|
||||
|
||||
@@ -238,12 +238,9 @@ function hasLegacyRendererOwnedPatch(patch: DesktopSettingsPatch): boolean {
|
||||
return patch.releaseChannel !== undefined || patch.daemon?.manageBuiltInDaemon !== undefined;
|
||||
}
|
||||
|
||||
function coerceDocument(input: unknown): PersistedDesktopSettingsDocument {
|
||||
const document = PersistedDocumentSchema.parse(input);
|
||||
if (document.migrations.daemonStopOnQuitDefaultApplied) {
|
||||
return document;
|
||||
}
|
||||
|
||||
function applyDaemonStopOnQuitDefault(
|
||||
document: PersistedDesktopSettingsDocument,
|
||||
): PersistedDesktopSettingsDocument {
|
||||
return {
|
||||
...document,
|
||||
settings: {
|
||||
@@ -283,45 +280,39 @@ export function createDesktopSettingsStore({
|
||||
cachedDocument = document;
|
||||
}
|
||||
|
||||
async function loadDocumentUnlocked(): Promise<PersistedDesktopSettingsDocument> {
|
||||
async function loadDocumentUnlocked({
|
||||
recoverUnreadable = false,
|
||||
} = {}): Promise<PersistedDesktopSettingsDocument> {
|
||||
if (cachedDocument) {
|
||||
return cachedDocument;
|
||||
}
|
||||
|
||||
let raw: string;
|
||||
let document: PersistedDesktopSettingsDocument;
|
||||
try {
|
||||
raw = await readFile(filePath, "utf8");
|
||||
const raw = await readFile(filePath, "utf8");
|
||||
document = PersistedDocumentSchema.parse(JSON.parse(raw));
|
||||
} catch (error) {
|
||||
if (!isNodeError(error) || error.code !== "ENOENT") {
|
||||
if (!recoverUnreadable && (!isNodeError(error) || error.code !== "ENOENT")) {
|
||||
throw error;
|
||||
}
|
||||
const document = buildDefaultDocument();
|
||||
await writeDocument(document);
|
||||
return document;
|
||||
const defaults = buildDefaultDocument();
|
||||
await writeDocument(defaults);
|
||||
return defaults;
|
||||
}
|
||||
const document = coerceDocument(JSON.parse(raw));
|
||||
|
||||
if (!document.migrations.daemonStopOnQuitDefaultApplied) {
|
||||
const migrated = applyDaemonStopOnQuitDefault(document);
|
||||
await writeDocument(migrated);
|
||||
return migrated;
|
||||
}
|
||||
|
||||
cachedDocument = document;
|
||||
return document;
|
||||
}
|
||||
|
||||
async function initializeLegacyRendererMigrationUnlocked(): Promise<PersistedDesktopSettingsDocument> {
|
||||
try {
|
||||
return await loadDocumentUnlocked();
|
||||
} catch {
|
||||
const document = buildDefaultDocument();
|
||||
await writeDocument(document);
|
||||
return document;
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
async get(): Promise<DesktopSettings> {
|
||||
const document = await enqueueOperation(async () => {
|
||||
if (cachedDocument) {
|
||||
return cachedDocument;
|
||||
}
|
||||
return loadDocumentUnlocked();
|
||||
});
|
||||
const document = await enqueueOperation(() => loadDocumentUnlocked());
|
||||
return toDesktopSettings(document.settings);
|
||||
},
|
||||
|
||||
@@ -346,7 +337,7 @@ export function createDesktopSettingsStore({
|
||||
|
||||
async migrateLegacyRendererSettings(legacySettings: unknown): Promise<DesktopSettings> {
|
||||
return enqueueOperation(async () => {
|
||||
const current = await initializeLegacyRendererMigrationUnlocked();
|
||||
const current = await loadDocumentUnlocked({ recoverUnreadable: true });
|
||||
if (current.migrations.legacyRendererSettingsImported) {
|
||||
return toDesktopSettings(current.settings);
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ import {
|
||||
rmSync,
|
||||
writeFileSync,
|
||||
} from "node:fs";
|
||||
import { basename, delimiter, join } from "node:path";
|
||||
import { delimiter, join } from "node:path";
|
||||
import { tmpdir } from "node:os";
|
||||
import pino from "pino";
|
||||
import {
|
||||
@@ -1667,53 +1667,25 @@ async function startManagerWithWorkerProtocol(
|
||||
}
|
||||
}
|
||||
|
||||
// Whether the program still accepts connections on its socket. Unlike its pid, which Windows
|
||||
// hands to another process as soon as the program ends and records without a birth time, the
|
||||
// socket closes with the program and nothing else answers on it.
|
||||
async function programListens(socketPath: string): Promise<boolean> {
|
||||
return await new Promise((resolve) => {
|
||||
const socket = createConnection(socketPath);
|
||||
socket.once("connect", () => {
|
||||
socket.destroy();
|
||||
resolve(true);
|
||||
});
|
||||
socket.once("error", () => resolve(false));
|
||||
});
|
||||
}
|
||||
|
||||
// A terminal running an idle program in a worker that reports `protocolVersion`, left running
|
||||
// after its daemon lets go (stop --keep-terminals). The program listens on `programSocket`.
|
||||
// after its daemon lets go (stop --keep-terminals).
|
||||
async function leaveWorkerWithTerminal(
|
||||
paseoHome: string,
|
||||
protocolVersion: number,
|
||||
): Promise<{
|
||||
terminalId: string;
|
||||
programPid: number;
|
||||
programSocket: string;
|
||||
workerPid: number;
|
||||
cwd: string;
|
||||
}> {
|
||||
): Promise<{ terminalId: string; programPid: number; workerPid: number; cwd: string }> {
|
||||
const cwd = mkdtempSync(join(tmpdir(), "worker-terminal-manager-protocol-"));
|
||||
temporaryDirs.push(cwd);
|
||||
const programSocket =
|
||||
process.platform === "win32"
|
||||
? `\\\\.\\pipe\\paseo-test-program-${basename(cwd)}`
|
||||
: join(cwd, "program.sock");
|
||||
const previous = await startManagerWithWorkerProtocol(paseoHome, protocolVersion);
|
||||
const session = await previous.createTerminal({
|
||||
workspaceId: "ws-protocol",
|
||||
cwd,
|
||||
...nodeTerminalCommand(
|
||||
`require("node:net").createServer().listen(${JSON.stringify(programSocket)}); setInterval(() => {}, 1000);`,
|
||||
),
|
||||
...nodeTerminalCommand("setInterval(() => {}, 1000);"),
|
||||
});
|
||||
await waitForCondition(() => programListens(programSocket), 10000);
|
||||
const [record] = await workerRecords(paseoHome);
|
||||
await previous.detach();
|
||||
return {
|
||||
terminalId: session.id,
|
||||
programPid: (await recordedTerminalPids(paseoHome)).get(session.id)!,
|
||||
programSocket,
|
||||
workerPid: record!.pid,
|
||||
cwd,
|
||||
};
|
||||
@@ -1725,14 +1697,24 @@ it.each([1, 4, 5])(
|
||||
const paseoHome = createTemporaryHome();
|
||||
const old = await leaveWorkerWithTerminal(paseoHome, version);
|
||||
const [record] = await workerRecords(paseoHome);
|
||||
const program = record!.terminals.find((entry) => entry.id === old.terminalId)!;
|
||||
const inspector = createTerminalWorkerProcessInspector();
|
||||
|
||||
manager = await startRealWorkerManager({ paseoHome });
|
||||
|
||||
expect(await readUnconfirmedTerminalCleanup(paseoHome)).toEqual([]);
|
||||
// Startup launches a replacement worker after cleanup. The program's PID may already
|
||||
// belong to another process, so its own socket is what proves it gone.
|
||||
// Startup launches a replacement worker after cleanup. Either old PID may already
|
||||
// belong to another process, so verify that the recorded birth identities are gone.
|
||||
await waitForCondition(() => !isProcessAlive(record!.pid), 10000);
|
||||
await expect.poll(() => programListens(old.programSocket), { timeout: 10000 }).toBe(false);
|
||||
await expect
|
||||
.poll(
|
||||
async () =>
|
||||
!isProcessAlive(program.pid) ||
|
||||
classifyTerminalProgramProcess(program, await inspector.inspect(program.pid)).status ===
|
||||
"unrelated",
|
||||
{ timeout: 10000 },
|
||||
)
|
||||
.toBe(true);
|
||||
expect(manager.getTerminal(old.terminalId)).toBeUndefined();
|
||||
const workers = await workerRecords(paseoHome);
|
||||
expect(workers).toHaveLength(1);
|
||||
|
||||
Reference in New Issue
Block a user