Skip to content

Commit 8fc72da

Browse files
juliusmarmingeJulius Marminge
andauthored
revert: fourteen unverified desktop fixes from the takeover campaign (pingdotgg#22222)
Co-authored-by: Julius Marminge <[email protected]>
1 parent 2d11196 commit 8fc72da

49 files changed

Lines changed: 416 additions & 2579 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎apps/desktop/src/app/DesktopApp.ts‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,7 @@ export const stopAllPoolInstances = Effect.fn("desktop.app.stopAllPoolInstances"
153153
const instances = yield* pool.list;
154154
yield* Effect.forEach(
155155
instances,
156-
// Exceeds the backend's 30s graceful termination and output drain budget.
157-
(instance) => instance.stop({ timeout: Duration.seconds(45) }),
156+
(instance) => instance.stop({ timeout: Duration.seconds(5) }),
158157
{ concurrency: "unbounded" },
159158
);
160159
},
@@ -240,7 +239,9 @@ const bootstrap = Effect.gen(function* () {
240239
}
241240

242241
if (!(yield* Ref.get(state.quitting))) {
243-
yield* desktopWindow.showConnectingSplash;
242+
if (settings.wslOnly === true && settings.wslBackendEnabled === true) {
243+
yield* desktopWindow.showConnectingSplash;
244+
}
244245
yield* primaryBackend.start;
245246
yield* logBootstrapInfo("bootstrap backend start requested");
246247
yield* appActivation.start.pipe(

‎apps/desktop/src/app/DesktopClerk.test.ts‎

Lines changed: 2 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// @effect-diagnostics nodeBuiltinImport:off globalFetchInEffect:off - Hosted handoff test uses a real localhost listener without an OpenAI account.
22
import * as NodeHttp from "node:http";
3-
import * as NodePath from "node:path";
4-
import * as PlatformNodePath from "@effect/platform-node/NodePath";
3+
import * as NodePath from "@effect/platform-node/NodePath";
54
import { codexAuthHandoffUrl, readCodexAuthDelivery } from "@t3tools/shared/codexAuthHandoff";
65
import { EnvironmentId, ProviderInstanceId } from "@t3tools/contracts";
76
import * as HostProcess from "@t3tools/shared/HostProcess";
@@ -60,15 +59,11 @@ const layerDesktopClerk = (
6059
copyText: () => Effect.void,
6160
},
6261
listeners = new Map<string, (...args: unknown[]) => void>(),
63-
isPackaged = false,
6462
) => {
6563
const environment = DesktopEnvironment.DesktopEnvironment.of({
6664
stateDir: "/tmp/t3-state",
6765
isDevelopment,
6866
appDataDirectory: "/tmp/app-data",
69-
isPackaged,
70-
dirname: platform === "win32" ? String.raw`C:\T3 Code\dist-electron` : "/tmp/dist-electron",
71-
path: platform === "win32" ? NodePath.win32 : NodePath.posix,
7267
platform,
7368
} as unknown as DesktopEnvironment.DesktopEnvironment["Service"]);
7469

@@ -100,7 +95,7 @@ const layerDesktopClerk = (
10095
return DesktopClerk.layer.pipe(
10196
Layer.provide(
10297
Layer.mergeAll(
103-
PlatformNodePath.layerPosix,
98+
NodePath.layerPosix,
10499
Layer.succeed(DesktopEnvironment.DesktopEnvironment, environment),
105100
Layer.succeed(ElectronApp.ElectronApp, electronApp),
106101
Layer.succeed(ElectronShell.ElectronShell, shell),
@@ -117,67 +112,6 @@ describe("DesktopClerk", () => {
117112
storageMock.mockReset();
118113
});
119114

120-
it.effect.each([
121-
{ platform: "win32", isPackaged: false, isDevelopment: false, registers: true },
122-
{ platform: "win32", isPackaged: false, isDevelopment: true, registers: false },
123-
{ platform: "win32", isPackaged: true, isDevelopment: false, registers: false },
124-
{ platform: "darwin", isPackaged: false, isDevelopment: false, registers: false },
125-
{ platform: "linux", isPackaged: false, isDevelopment: false, registers: false },
126-
] as const)(
127-
"registers an entry point only for unpackaged non-development Windows ($platform, packaged=$isPackaged, development=$isDevelopment)",
128-
({ platform, isPackaged, isDevelopment, registers }) => {
129-
const events: string[] = [];
130-
storageMock.mockReturnValue(storageAdapter);
131-
createClerkBridgeMock.mockImplementation(() => {
132-
events.push("bridge");
133-
return { cleanup: vi.fn() };
134-
});
135-
const setAsDefaultProtocolClient = vi.fn(() =>
136-
Effect.sync(() => {
137-
events.push("register");
138-
return true;
139-
}),
140-
);
141-
const electronApp = {
142-
on: () => Effect.void,
143-
setAsDefaultProtocolClient,
144-
} as unknown as ElectronApp.ElectronApp["Service"];
145-
146-
return Effect.gen(function* () {
147-
const clerk = yield* DesktopClerk.DesktopClerk;
148-
yield* clerk.configure;
149-
150-
assert.deepEqual(
151-
setAsDefaultProtocolClient.mock.calls,
152-
registers
153-
? [["t3code", process.execPath, [String.raw`C:\T3 Code\dist-electron\main.cjs`]]]
154-
: [],
155-
);
156-
assert.deepEqual(events, registers ? ["bridge", "register"] : ["bridge"]);
157-
}).pipe(
158-
Effect.scoped,
159-
Effect.provide(
160-
layerDesktopClerk(
161-
isDevelopment,
162-
[],
163-
platform,
164-
undefined,
165-
undefined,
166-
undefined,
167-
isPackaged,
168-
),
169-
),
170-
Effect.provideService(ElectronApp.ElectronApp, electronApp),
171-
Effect.provideService(
172-
ElectronWindow.ElectronWindow,
173-
{} as ElectronWindow.ElectronWindow["Service"],
174-
),
175-
Effect.provideService(DesktopWebLinks.DesktopWebLinks, ignoreWebLinks),
176-
Effect.provideService(HostProcess.Arguments, ["electron"]),
177-
);
178-
},
179-
);
180-
181115
it.effect("acquires and releases the SDK bridge with the layer", () => {
182116
const cleanup = vi.fn();
183117
const events: string[] = [];

‎apps/desktop/src/app/DesktopClerk.ts‎

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -151,20 +151,6 @@ export const make = Effect.gen(function* () {
151151
const context = yield* Effect.context<ElectronWindow.ElectronWindow>();
152152
const runPromise = Effect.runPromiseWith(context);
153153

154-
// Clerk's bare scheme registration omits the app entry on unpackaged Windows.
155-
// Development callbacks also need dev server environment this command cannot restore.
156-
if (
157-
!environment.isPackaged &&
158-
!environment.isDevelopment &&
159-
environment.platform === "win32"
160-
) {
161-
yield* electronApp.setAsDefaultProtocolClient(
162-
ElectronProtocol.getDesktopScheme(environment.isDevelopment),
163-
process.execPath,
164-
[environment.path.join(environment.dirname, "main.cjs")],
165-
);
166-
}
167-
168154
const startProviderAuthHandoff = (value: string | undefined) => {
169155
if (!value) return false;
170156
const request = readCodexAuthHandoff(value, environment.isDevelopment);

‎apps/desktop/src/app/DesktopLifecycle.test.ts‎

Lines changed: 9 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
1-
// @effect-diagnostics-next-line nodeBuiltinImport:off - A real Node process verifies OS signal ownership outside Effect's process runtime.
2-
import * as NodeChildProcess from "node:child_process";
3-
import * as NodeReadline from "node:readline";
4-
import * as NodeURL from "node:url";
5-
61
import { assert, describe, it } from "@effect/vitest";
7-
import * as HostProcess from "@t3tools/shared/HostProcess";
82
import * as Deferred from "effect/Deferred";
93
import * as Effect from "effect/Effect";
10-
import * as Fiber from "effect/Fiber";
114
import * as Layer from "effect/Layer";
125
import * as Ref from "effect/Ref";
136

@@ -110,67 +103,6 @@ function layerDesktopWindow(
110103
}
111104

112105
describe("DesktopLifecycle", () => {
113-
it.skipIf(HostProcess.Platform.defaultValue() === "win32")(
114-
"leaves SIGTERM to the lifecycle until its graceful shutdown completes",
115-
async ({ onTestFinished }) => {
116-
const runner = new URL("./DesktopRuntime.ts", import.meta.url).href;
117-
const child = NodeChildProcess.spawn(
118-
process.execPath,
119-
[
120-
"--experimental-strip-types",
121-
"--input-type=module",
122-
"-e",
123-
`
124-
import * as Effect from 'effect/Effect';
125-
import * as Deferred from 'effect/Deferred';
126-
import { runMain } from ${JSON.stringify(runner)};
127-
process.stdin.resume();
128-
let released = false;
129-
runMain(Effect.scoped(Effect.gen(function* () {
130-
const done = yield* Deferred.make();
131-
yield* Effect.addFinalizer(() => Effect.sync(() => console.log(released ? 'CLEANED' : 'PREMATURE')));
132-
process.once('SIGTERM', () => {
133-
console.log('STOPPING');
134-
process.stdin.once('data', () => {
135-
released = true;
136-
void Effect.runPromise(Deferred.succeed(done, undefined)).then(() => process.stdin.destroy());
137-
});
138-
});
139-
console.log('READY');
140-
yield* Deferred.await(done);
141-
})));
142-
`,
143-
],
144-
{
145-
cwd: NodeURL.fileURLToPath(new URL("../../", import.meta.url)),
146-
stdio: ["pipe", "pipe", "pipe"],
147-
},
148-
);
149-
const exited = new Promise<readonly [number | null, string | null]>((resolve, reject) => {
150-
child.once("exit", (code, signal) => resolve([code, signal]));
151-
child.once("error", reject);
152-
});
153-
const lines: string[] = [];
154-
let stderr = "";
155-
child.stderr.on("data", (chunk) => {
156-
stderr += chunk;
157-
});
158-
onTestFinished(async () => {
159-
if (child.exitCode === null && child.signalCode === null) {
160-
child.kill("SIGKILL");
161-
await exited;
162-
}
163-
});
164-
for await (const line of NodeReadline.createInterface({ input: child.stdout })) {
165-
lines.push(line);
166-
if (line === "READY") child.kill("SIGTERM");
167-
if (line === "STOPPING") child.stdin.write("finish");
168-
}
169-
assert.deepEqual(await exited, [0, null], stderr);
170-
assert.deepEqual(lines, ["READY", "STOPPING", "CLEANED"]);
171-
},
172-
);
173-
174106
it.effect.each(["darwin", "win32", "linux"] satisfies ReadonlyArray<NodeJS.Platform>)(
175107
"lets the updater's quit event proceed on %s",
176108
(platform) => {
@@ -226,18 +158,12 @@ describe("DesktopLifecycle", () => {
226158
},
227159
);
228160

229-
it.effect("destroys windows and retains signal ownership until backend shutdown completes", () =>
161+
it.effect("destroys windows before waiting for backend shutdown", () =>
230162
Effect.gen(function* () {
231163
const appListeners = new Map<string, (...args: readonly unknown[]) => void>();
232164
const shutdownRequested = yield* Deferred.make<void>();
233165
const allowShutdown = yield* Deferred.make<void>();
234166
const quitRequested = yield* Deferred.make<void>();
235-
const backendStopping = yield* Deferred.make<void>();
236-
const finishBackendShutdown = yield* Deferred.make<void>();
237-
const originalSignals = {
238-
SIGINT: process.listeners("SIGINT"),
239-
SIGTERM: process.listeners("SIGTERM"),
240-
};
241167
const events: string[] = [];
242168

243169
const quit = Effect.sync(() => {
@@ -278,47 +204,20 @@ describe("DesktopLifecycle", () => {
278204
yield* Effect.scoped(
279205
Effect.gen(function* () {
280206
const lifecycle = yield* DesktopLifecycle.DesktopLifecycle;
281-
const shutdown = yield* DesktopShutdown.DesktopShutdown;
282-
const program = yield* Effect.scoped(
283-
Effect.gen(function* () {
284-
yield* Effect.addFinalizer(() =>
285-
Deferred.succeed(backendStopping, undefined).pipe(
286-
Effect.andThen(Deferred.await(finishBackendShutdown)),
287-
Effect.andThen(shutdown.markComplete),
288-
),
289-
);
290-
yield* lifecycle.register;
291-
const event = { preventDefault: () => undefined } as Electron.Event;
292-
appListeners.get("before-quit")?.(event);
293-
yield* shutdown.awaitRequest;
294-
}),
295-
).pipe(Effect.forkScoped);
296-
297-
yield* Deferred.await(backendStopping);
298-
yield* Effect.addFinalizer(() =>
299-
Deferred.succeed(finishBackendShutdown, undefined).pipe(Effect.asVoid),
300-
);
207+
yield* lifecycle.register;
301208

302-
for (const signal of ["SIGINT", "SIGTERM"] as const) {
303-
const listeners = process
304-
.listeners(signal)
305-
.filter((listener) => !originalSignals[signal].includes(listener));
306-
assert.lengthOf(listeners, 1, `${signal} must remain owned during backend cleanup`);
307-
listeners[0]?.(signal);
308-
}
309-
assert.deepEqual(events, ["flush", "destroy", "request"]);
310-
assert.equal(appListeners.size, 0, "Electron listeners still follow the program scope");
311-
assert.isFalse(yield* shutdown.isComplete);
209+
const event = { preventDefault: () => undefined } as Electron.Event;
210+
appListeners.get("before-quit")?.(event);
312211

313-
yield* Deferred.succeed(finishBackendShutdown, undefined);
314-
yield* Fiber.join(program);
212+
yield* Deferred.await(shutdownRequested);
213+
const eventsBeforeCleanup = [...events];
214+
yield* Deferred.succeed(allowShutdown, undefined);
315215
yield* Deferred.await(quitRequested);
216+
217+
assert.deepEqual(eventsBeforeCleanup, ["flush", "destroy", "request"]);
316218
assert.deepEqual(events, ["flush", "destroy", "request", "quit"]);
317219
}),
318220
).pipe(Effect.provide(layer));
319-
320-
assert.deepEqual(process.listeners("SIGINT"), originalSignals.SIGINT);
321-
assert.deepEqual(process.listeners("SIGTERM"), originalSignals.SIGTERM);
322221
}),
323222
);
324223

0 commit comments

Comments
 (0)