Skip to content

Commit 9a32d19

Browse files
nibarAhmedclaude
andcommitted
Merge remote-tracking branch 'origin/main' into fix/mobile-composer-talkback-order
Co-Authored-By: Claude Opus 5.5 <[email protected]>
2 parents 9f44e42 + dd14848 commit 9a32d19

283 files changed

Lines changed: 8872 additions & 1513 deletions

File tree

Some content is hidden

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

‎apps/desktop/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@t3tools/desktop",
3-
"version": "0.1.4",
3+
"version": "0.1.5",
44
"private": true,
55
"type": "module",
66
"main": "dist-electron/boot.cjs",

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

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as NodeServices from "@effect/platform-node/NodeServices";
22
import { afterEach, beforeEach, expect, it } from "@effect/vitest";
3+
import * as HostProcess from "@t3tools/shared/HostProcess";
34
import * as Effect from "effect/Effect";
45
import * as FileSystem from "effect/FileSystem";
56
import * as Option from "effect/Option";
@@ -135,6 +136,14 @@ it.layer(NodeServices.layer)("DesktopCliCommand", (it) => {
135136
yield* command.uninstall;
136137
expect(yield* fs.readFileString(theirs)).toBe("npm's t3\n");
137138
expect(yield* fs.readLink(path.join(home, "bin", "t3"))).toBe(path.join(home, "gone"));
139+
140+
const launcher = path.join(home, ".t3", "bin", "t3");
141+
yield* fs.writeFileString(launcher, "npm's t3\n");
142+
process.env.PATH = path.dirname(launcher);
143+
expect(yield* command.state).toMatchObject({ onPath: false, shadowedBy: launcher });
144+
expect((yield* Effect.flip(command.install)).message).toContain("Could not set up");
145+
yield* command.uninstall;
146+
expect(yield* fs.readFileString(launcher)).toBe("npm's t3\n");
138147
}).pipe(Effect.scoped),
139148
);
140149

@@ -183,6 +192,67 @@ it.layer(NodeServices.layer)("DesktopCliCommand", (it) => {
183192
}).pipe(Effect.scoped),
184193
);
185194

195+
it.effect.skipIf(HostProcess.Platform.defaultValue() === "win32")(
196+
"skips a t3 directory or a file this user cannot execute",
197+
() =>
198+
Effect.gen(function* () {
199+
const fs = yield* FileSystem.FileSystem;
200+
const path = yield* Path.Path;
201+
const home = yield* fs.makeTempDirectoryScoped();
202+
const folder = path.join(home, "folder");
203+
const plain = path.join(home, "plain");
204+
const shadow = path.join(home, "shadow");
205+
yield* fs.makeDirectory(path.join(folder, "t3"), { recursive: true });
206+
yield* fs.makeDirectory(plain);
207+
yield* fs.writeFileString(path.join(plain, "t3"), "notes\n");
208+
// Root can execute mode 0o601; other users must honor the owner permissions.
209+
yield* fs.chmod(path.join(plain, "t3"), process.getuid?.() === 0 ? 0o600 : 0o601);
210+
yield* fs.makeDirectory(shadow);
211+
yield* fs.writeFileString(path.join(shadow, "t3"), "#!/bin/sh\n", { mode: 0o755 });
212+
process.env.PATH = [folder, plain, shadow, path.join(home, ".local", "bin")].join(":");
213+
214+
const command = yield* commandIn({ home });
215+
expect((yield* command.state).shadowedBy).toBe(path.join(shadow, "t3"));
216+
217+
const error = yield* Effect.flip(command.install);
218+
expect(error.message).toContain(path.join(shadow, "t3"));
219+
220+
yield* fs.remove(shadow, { recursive: true });
221+
expect(yield* command.install).toMatchObject({
222+
onPath: true,
223+
installedPath: path.join(home, ".local", "bin", "t3"),
224+
});
225+
}).pipe(Effect.scoped),
226+
);
227+
228+
it.effect("does not treat its own launcher as another t3 when its folder is first on PATH", () =>
229+
Effect.gen(function* () {
230+
const fs = yield* FileSystem.FileSystem;
231+
const path = yield* Path.Path;
232+
const home = yield* fs.makeTempDirectoryScoped();
233+
const launcher = path.join(home, ".t3", "bin", "t3");
234+
process.env.PATH = [path.dirname(launcher), path.join(home, ".local", "bin")].join(":");
235+
236+
const command = yield* commandIn({ home });
237+
const installed = yield* command.install;
238+
239+
expect(yield* fs.exists(launcher)).toBe(true);
240+
expect(installed).toMatchObject({
241+
onPath: true,
242+
installedPath: path.join(home, ".local", "bin", "t3"),
243+
});
244+
expect(installed.shadowedBy).toBeUndefined();
245+
expect(yield* command.state).toEqual(installed);
246+
247+
const removed = yield* command.uninstall;
248+
expect(removed.installedPath).toBeNull();
249+
expect(removed.onPath).toBe(true);
250+
expect(yield* command.state).toEqual(removed);
251+
expect(yield* fs.exists(installed.installedPath!)).toBe(false);
252+
expect(yield* fs.exists(launcher)).toBe(true);
253+
}).pipe(Effect.scoped),
254+
);
255+
186256
it.effect("leaves the Windows PATH alone when it cannot be read", () =>
187257
Effect.gen(function* () {
188258
const fs = yield* FileSystem.FileSystem;

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

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// @effect-diagnostics-next-line nodeBuiltinImport:off -- FileSystem.access has no execute check.
2+
import * as NodeFSP from "node:fs/promises";
3+
14
import type { DesktopCliCommandState } from "@t3tools/contracts";
25
import * as Context from "effect/Context";
36
import * as Effect from "effect/Effect";
@@ -89,6 +92,19 @@ export const make = Effect.gen(function* () {
8992
Effect.orElseSucceed(() => false),
9093
);
9194

95+
// PATH can reach the regular launcher directly; removal still requires isOurLink.
96+
const runsOurLauncher = Effect.fn("DesktopCliCommand.runsOurLauncher")(
97+
function* (candidate: string) {
98+
if (yield* isOurLink(candidate)) return true;
99+
const [resolved, ours] = yield* Effect.all([fs.realPath(candidate), fs.realPath(launcher)]);
100+
if (resolved !== ours) return false;
101+
const info = yield* fs.stat(candidate);
102+
if (info.type !== "File" || Number(info.size) > 16_384) return false;
103+
return (yield* fs.readFileString(candidate)).includes(DesktopCliShim.MARKER);
104+
},
105+
Effect.orElseSucceed(() => false),
106+
);
107+
92108
const powershell = (env: Record<string, string>) =>
93109
Effect.scoped(
94110
Effect.gen(function* () {
@@ -118,18 +134,27 @@ export const make = Effect.gen(function* () {
118134
Effect.mapError(() => fail("Could not update your PATH.")),
119135
);
120136

137+
const isExecutableFile = Effect.fn("DesktopCliCommand.isExecutableFile")(
138+
function* (target: string) {
139+
if ((yield* fs.stat(target)).type !== "File") return false;
140+
yield* Effect.tryPromise(() => NodeFSP.access(target, NodeFSP.constants.X_OK));
141+
return true;
142+
},
143+
Effect.orElseSucceed(() => false),
144+
);
145+
121146
const firstOnPath = Effect.gen(function* () {
122147
for (const directory of pathEntries(process.env.PATH, ":")) {
123148
const candidate = path.join(directory, "t3");
124-
if (yield* exists(candidate)) return Option.some(candidate);
149+
if (yield* isExecutableFile(candidate)) return Option.some(candidate);
125150
}
126151
return Option.none<string>();
127152
});
128153

129154
const foreignFirstOnPath = Effect.gen(function* () {
130155
if (windows) return Option.none<string>();
131156
const first = yield* firstOnPath;
132-
if (Option.isNone(first) || (yield* isOurLink(first.value))) return Option.none<string>();
157+
if (Option.isNone(first) || (yield* runsOurLauncher(first.value))) return Option.none<string>();
133158
return first;
134159
});
135160

@@ -156,12 +181,17 @@ export const make = Effect.gen(function* () {
156181
const installed = yield* installedAt;
157182
const shadowedBy = yield* foreignFirstOnPath;
158183
const shadow = Option.isSome(shadowedBy) ? { shadowedBy: shadowedBy.value } : {};
159-
if (Option.isNone(installed)) {
160-
return { supported: true, installedPath: null, onPath: false, launcherPath, ...shadow };
161-
}
162184
const first = yield* firstOnPath;
163-
const onPath = windows || (Option.isSome(first) && (yield* isOurLink(first.value)));
164-
return { supported: true, installedPath: installed.value, onPath, launcherPath, ...shadow };
185+
const onPath = windows
186+
? Option.isSome(installed)
187+
: Option.isSome(first) && (yield* runsOurLauncher(first.value));
188+
return {
189+
supported: true,
190+
installedPath: Option.getOrNull(installed),
191+
onPath,
192+
launcherPath,
193+
...shadow,
194+
};
165195
}).pipe(
166196
Effect.orElseSucceed(() => ({
167197
supported: false,

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

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
11
import * as NodeServices from "@effect/platform-node/NodeServices";
22
import { assert, describe, it } from "@effect/vitest";
3+
import * as HostProcess from "@t3tools/shared/HostProcess";
4+
import * as Cause from "effect/Cause";
35
import * as Deferred from "effect/Deferred";
46
import * as Effect from "effect/Effect";
7+
import * as Exit from "effect/Exit";
8+
import * as Fiber from "effect/Fiber";
59
import * as FileSystem from "effect/FileSystem";
610
import * as Layer from "effect/Layer";
711
import * as Option from "effect/Option";
812
import * as Path from "effect/Path";
913
import * as PlatformError from "effect/PlatformError";
1014
import * as Sink from "effect/Sink";
1115
import * as Stream from "effect/Stream";
16+
import * as TestClock from "effect/testing/TestClock";
17+
import * as ChildProcess from "effect/process/ChildProcess";
1218
import * as ChildProcessSpawner from "effect/process/ChildProcessSpawner";
1319

1420
import * as DesktopEnvironment from "./DesktopEnvironment.ts";
@@ -56,6 +62,7 @@ const layerHandler = (
5662
recorded: RecordedRegistration,
5763
input: {
5864
readonly environment?: Record<string, unknown>;
65+
readonly processSpawner?: ChildProcessSpawner.ChildProcessSpawner["Service"];
5966
readonly updateDesktopDatabaseExitCode?: number;
6067
readonly updateDesktopDatabaseStalled?: boolean;
6168
readonly updateDesktopDatabaseStarted?: Deferred.Deferred<void>;
@@ -106,6 +113,7 @@ const layerHandler = (
106113
Layer.succeed(
107114
ChildProcessSpawner.ChildProcessSpawner,
108115
ChildProcessSpawner.make((command) => {
116+
if (input.processSpawner) return input.processSpawner.spawn(command);
109117
const childProcess = command as unknown as {
110118
readonly command: string;
111119
readonly args: ReadonlyArray<string>;
@@ -358,6 +366,69 @@ describe("DesktopLinuxUrlHandler", () => {
358366
assert.deepEqual(writeFailed.commands, []);
359367
});
360368
});
369+
370+
it.effect.skipIf(HostProcess.Platform.defaultValue() !== "linux")(
371+
"continues registration after a timed-out cache helper ignores SIGTERM",
372+
() =>
373+
Effect.gen(function* () {
374+
const realSpawner = yield* ChildProcessSpawner.ChildProcessSpawner;
375+
const nodeExecutable = yield* HostProcess.ExecutablePath;
376+
const recorded = emptyRecording();
377+
const spawned = yield* Deferred.make<ChildProcessSpawner.ChildProcessHandle>();
378+
const ready = yield* Deferred.make<void>();
379+
const processSpawner = ChildProcessSpawner.make((command) =>
380+
Effect.gen(function* () {
381+
if (!ChildProcess.isStandardCommand(command)) {
382+
return yield* Effect.die("expected a single registration command");
383+
}
384+
recorded.commands.push({ command: command.command, args: command.args });
385+
if (command.command !== "update-desktop-database") return mockProcess(0);
386+
const child = yield* realSpawner.spawn(
387+
ChildProcess.make(
388+
nodeExecutable,
389+
[
390+
"-e",
391+
// The watchdog makes the unfixed case exit with a distinguishable code.
392+
"process.on('SIGTERM', () => setTimeout(() => process.exit(99), 5000));" +
393+
"process.stdout.write('ready\\n'); setInterval(() => {}, 2147483647);",
394+
],
395+
{ ...command.options, stdout: "pipe" },
396+
),
397+
);
398+
yield* Deferred.succeed(spawned, child);
399+
yield* Stream.runHead(child.stdout);
400+
yield* Deferred.succeed(ready, undefined);
401+
return child;
402+
}),
403+
);
404+
const registration = yield* runRegister(recorded, { processSpawner }).pipe(
405+
Effect.forkScoped,
406+
);
407+
const child = yield* Deferred.await(spawned);
408+
yield* Effect.addFinalizer(() =>
409+
child.isRunning.pipe(
410+
Effect.flatMap((running) =>
411+
running ? child.kill({ killSignal: "SIGKILL" }) : Effect.void,
412+
),
413+
Effect.ignore,
414+
),
415+
);
416+
yield* Deferred.await(ready);
417+
yield* TestClock.adjust("5 seconds");
418+
yield* Fiber.join(registration);
419+
420+
const exit = yield* Effect.exit(child.exitCode);
421+
if (Exit.isFailure(exit)) {
422+
assert.include(Cause.pretty(exit.cause), "SIGKILL");
423+
} else {
424+
assert.fail(`cache helper exited with ${exit.value} instead of being force-killed`);
425+
}
426+
assert.deepEqual(
427+
recorded.commands.map(({ command }) => command),
428+
["update-desktop-database", "xdg-mime"],
429+
);
430+
}).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),
431+
);
361432
});
362433

363434
interface ThemeIconRun {

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ export const make = Effect.gen(function* () {
174174
stdin: "ignore",
175175
stdout: "ignore",
176176
stderr: "ignore",
177+
forceKillAfter: "1 second",
177178
},
178179
);
179180
const handle = yield* spawner.spawn(command);

‎apps/desktop/src/electron/ElectronProtocol.test.ts‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,39 @@ describe("ElectronProtocol", () => {
130130
}).pipe(Effect.provide(layerProtocol)),
131131
);
132132

133+
it.effect("keeps proxied paths on the configured server", () =>
134+
Effect.gen(function* () {
135+
let handler: ((request: Request) => Promise<Response>) | undefined;
136+
handleMock.mockImplementation((_scheme, nextHandler) => {
137+
handler = nextHandler;
138+
});
139+
netFetchMock.mockImplementation(async () => new Response("ok"));
140+
141+
yield* Effect.scoped(
142+
Effect.gen(function* () {
143+
const protocol = yield* ElectronProtocol.ElectronProtocol;
144+
yield* protocol.registerDesktopProtocol({
145+
scheme: "t3code-dev",
146+
targetOrigin: new URL("http://127.0.0.1:5733/"),
147+
clerkFrontendApiHostname: undefined,
148+
});
149+
yield* Effect.promise(() =>
150+
handler!(new Request("t3code-dev://app//example.com/src/main.tsx?t=1")),
151+
);
152+
yield* Effect.promise(() => handler!(new Request("t3code-dev://app/\\example.com/")));
153+
}),
154+
);
155+
156+
assert.deepEqual(
157+
netFetchMock.mock.calls.map((call) => call[0]),
158+
[
159+
"http://127.0.0.1:5733//example.com/src/main.tsx?t=1",
160+
"http://127.0.0.1:5733//example.com/",
161+
],
162+
);
163+
}).pipe(Effect.provide(layerProtocol)),
164+
);
165+
133166
it.effect("rejects custom protocol requests for another host", () =>
134167
Effect.gen(function* () {
135168
let handler: ((request: Request) => Promise<Response>) | undefined;

‎apps/desktop/src/electron/ElectronProtocol.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,10 @@ const proxyRequest = Effect.fn("desktop.protocol.proxyRequest")(function* (
167167
return new Response(null, { status: 404 });
168168
}
169169

170-
const targetUrl = new URL(`${requestUrl.pathname}${requestUrl.search}`, targetOrigin);
170+
// Assign the path so leading slashes cannot replace the configured host.
171+
const targetUrl = new URL(targetOrigin);
172+
targetUrl.pathname = requestUrl.pathname;
173+
targetUrl.search = requestUrl.search;
171174
const headers = new Headers(request.headers);
172175
const headersToRemove: string[] = [];
173176
for (const name of headers.keys()) {

‎apps/desktop/src/preview/BrowserSession.test.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,11 +280,16 @@ describe("BrowserSession", () => {
280280
assert.isUndefined(sessions.get(partition));
281281

282282
yield* browserSessions.getSession("scope-untouched");
283+
const other = yield* browserSessions.getSession("scope-other");
283284
yield* browserSessions.clearCookies([partition]);
284285

285286
const created = sessions.get(partition);
286287
assert.isDefined(created);
287288
assert.strictEqual(created.clearStorageData.mock.calls.length, 1);
289+
assert.deepStrictEqual(created.clearStorageData.mock.calls[0]?.[0], {
290+
storages: ["cookies", "localstorage", "indexdb", "serviceworkers", "cachestorage"],
291+
});
292+
assert.strictEqual(vi.mocked(other.clearStorageData).mock.calls.length, 0);
288293
}).pipe(Effect.provide(layer)),
289294
);
290295
});

‎apps/desktop/src/preview/BrowserSession.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ export const make = Effect.gen(function* BrowserSessionMake() {
367367
Effect.tryPromise({
368368
try: () =>
369369
browserSession.clearStorageData({
370-
storages: ["cookies", "localstorage", "indexdb", "serviceworkers"],
370+
storages: ["cookies", "localstorage", "indexdb", "serviceworkers", "cachestorage"],
371371
}),
372372
catch: (cause) =>
373373
new BrowserSessionStorageClearError({

0 commit comments

Comments
 (0)