Skip to content

Commit fdb473e

Browse files
authored
Merge branch 'main' into pnpm-global-virtual-store
2 parents d0bdcc0 + 1e3e3a8 commit fdb473e

105 files changed

Lines changed: 2893 additions & 202 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/src/app/DesktopCliCommand.test.ts‎

Lines changed: 34 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";
@@ -183,6 +184,39 @@ it.layer(NodeServices.layer)("DesktopCliCommand", (it) => {
183184
}).pipe(Effect.scoped),
184185
);
185186

187+
it.effect.skipIf(HostProcess.Platform.defaultValue() === "win32")(
188+
"skips a t3 directory or a file this user cannot execute",
189+
() =>
190+
Effect.gen(function* () {
191+
const fs = yield* FileSystem.FileSystem;
192+
const path = yield* Path.Path;
193+
const home = yield* fs.makeTempDirectoryScoped();
194+
const folder = path.join(home, "folder");
195+
const plain = path.join(home, "plain");
196+
const shadow = path.join(home, "shadow");
197+
yield* fs.makeDirectory(path.join(folder, "t3"), { recursive: true });
198+
yield* fs.makeDirectory(plain);
199+
yield* fs.writeFileString(path.join(plain, "t3"), "notes\n");
200+
// Root can execute mode 0o601; other users must honor the owner permissions.
201+
yield* fs.chmod(path.join(plain, "t3"), process.getuid?.() === 0 ? 0o600 : 0o601);
202+
yield* fs.makeDirectory(shadow);
203+
yield* fs.writeFileString(path.join(shadow, "t3"), "#!/bin/sh\n", { mode: 0o755 });
204+
process.env.PATH = [folder, plain, shadow, path.join(home, ".local", "bin")].join(":");
205+
206+
const command = yield* commandIn({ home });
207+
expect((yield* command.state).shadowedBy).toBe(path.join(shadow, "t3"));
208+
209+
const error = yield* Effect.flip(command.install);
210+
expect(error.message).toContain(path.join(shadow, "t3"));
211+
212+
yield* fs.remove(shadow, { recursive: true });
213+
expect(yield* command.install).toMatchObject({
214+
onPath: true,
215+
installedPath: path.join(home, ".local", "bin", "t3"),
216+
});
217+
}).pipe(Effect.scoped),
218+
);
219+
186220
it.effect("leaves the Windows PATH alone when it cannot be read", () =>
187221
Effect.gen(function* () {
188222
const fs = yield* FileSystem.FileSystem;

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

Lines changed: 13 additions & 1 deletion
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";
@@ -118,10 +121,19 @@ export const make = Effect.gen(function* () {
118121
Effect.mapError(() => fail("Could not update your PATH.")),
119122
);
120123

124+
const isExecutableFile = Effect.fn("DesktopCliCommand.isExecutableFile")(
125+
function* (target: string) {
126+
if ((yield* fs.stat(target)).type !== "File") return false;
127+
yield* Effect.tryPromise(() => NodeFSP.access(target, NodeFSP.constants.X_OK));
128+
return true;
129+
},
130+
Effect.orElseSucceed(() => false),
131+
);
132+
121133
const firstOnPath = Effect.gen(function* () {
122134
for (const directory of pathEntries(process.env.PATH, ":")) {
123135
const candidate = path.join(directory, "t3");
124-
if (yield* exists(candidate)) return Option.some(candidate);
136+
if (yield* isExecutableFile(candidate)) return Option.some(candidate);
125137
}
126138
return Option.none<string>();
127139
});

‎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({

‎apps/desktop/src/shell/DesktopShellEnvironment.test.ts‎

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ describe("DesktopShellEnvironment", () => {
149149
};
150150
const commands: ChildProcess.Command[] = [];
151151

152-
yield* runShellEnvironment({
152+
const prepared = yield* runShellEnvironment({
153153
env,
154154
platform: "darwin",
155155
handler: (command) => {
@@ -167,6 +167,7 @@ describe("DesktopShellEnvironment", () => {
167167
assert.equal(env.PATH, "/opt/homebrew/bin:/usr/bin:/Users/test/.local/bin");
168168
assert.equal(env.SSH_AUTH_SOCK, "/tmp/secretive.sock");
169169
assert.equal(env.HOMEBREW_PREFIX, "/opt/homebrew");
170+
assert.isTrue(prepared);
170171
}),
171172
);
172173

@@ -267,7 +268,7 @@ describe("DesktopShellEnvironment", () => {
267268
};
268269
const commands: string[] = [];
269270

270-
yield* runShellEnvironment({
271+
const prepared = yield* runShellEnvironment({
271272
env,
272273
platform: "darwin",
273274
handler: (command) => {
@@ -279,6 +280,19 @@ describe("DesktopShellEnvironment", () => {
279280

280281
assert.deepEqual(commands, ["/opt/homebrew/bin/nu", "/bin/zsh", "/bin/launchctl"]);
281282
assert.equal(env.PATH, "/opt/homebrew/bin:/usr/bin");
283+
assert.isFalse(prepared);
284+
}),
285+
);
286+
287+
it.effect("leaves macOS preparation incomplete when no login shell returns a PATH", () =>
288+
Effect.gen(function* () {
289+
const prepared = yield* runShellEnvironment({
290+
env: { SHELL: "/bin/zsh", PATH: "/usr/bin:/bin:/usr/sbin:/sbin" },
291+
platform: "darwin",
292+
handler: () => "",
293+
});
294+
295+
assert.isFalse(prepared);
282296
}),
283297
);
284298

‎apps/desktop/src/shell/DesktopShellEnvironment.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ const installPosixEnvironment = Effect.fn("desktop.shellEnvironment.installPosix
392392
function* (
393393
config: ShellEnvironmentConfig,
394394
): Effect.fn.Return<
395-
void,
395+
boolean,
396396
never,
397397
ChildProcessSpawner.ChildProcessSpawner | FileSystem.FileSystem
398398
> {
@@ -491,6 +491,8 @@ const installPosixEnvironment = Effect.fn("desktop.shellEnvironment.installPosix
491491
}
492492
}
493493
}
494+
495+
return Option.isSome(trimNonEmpty(shellEnvironment.PATH));
494496
},
495497
);
496498

@@ -505,7 +507,7 @@ const installShellEnvironment = (
505507
return installWindowsEnvironment(config);
506508
}
507509
if (config.platform === "darwin" || config.platform === "linux") {
508-
return installPosixEnvironment(config).pipe(Effect.as(true));
510+
return installPosixEnvironment(config);
509511
}
510512
return Effect.succeed(false);
511513
};

‎apps/mobile/src/features/settings/appearance/components/AppearancePreviews.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export function TerminalAppearancePreview(props: { readonly fontSize: number })
4444
const theme = getMobileTerminalTheme(themeId, scheme);
4545
const lineHeight = Math.round(props.fontSize * 1.6);
4646
const lineStyle = {
47-
fontFamily: "Menlo",
47+
fontFamily: Platform.OS === "android" ? "monospace" : "Menlo",
4848
fontSize: props.fontSize,
4949
lineHeight,
5050
} as const;

‎apps/mobile/src/features/terminal/terminalInput.test.ts‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,38 @@ const ESC = byte(0x1b);
1212
const CTRL_V = byte(0x16);
1313

1414
describe("resolveModifiedTerminalInput", () => {
15+
it.each(["A", "B", "C", "D"])("encodes ctrl+arrow %s with the cursor modifier", (arrow) => {
16+
expect(
17+
resolveModifiedTerminalInput({
18+
data: `${ESC}[${arrow}`,
19+
modifier: "ctrl",
20+
hostPlatform: "linux",
21+
}),
22+
).toEqual({ kind: "write", data: `${ESC}[1;5${arrow}` });
23+
});
24+
25+
it.each(["A", "B", "C", "D"])("encodes meta+arrow %s with the cursor modifier", (arrow) => {
26+
expect(
27+
resolveModifiedTerminalInput({
28+
data: `${ESC}[${arrow}`,
29+
modifier: "meta",
30+
hostPlatform: "linux",
31+
}),
32+
).toEqual({ kind: "write", data: `${ESC}[1;3${arrow}` });
33+
});
34+
35+
it.each(["a", "", ESC, `${ESC}[H`, `${ESC}[1;5D`, `${ESC}[D\n`])(
36+
"preserves non-arrow modifier handling for %j",
37+
(data) => {
38+
expect(
39+
resolveModifiedTerminalInput({ data, modifier: "meta", hostPlatform: "linux" }),
40+
).toEqual({
41+
kind: "write",
42+
data: `${ESC}${data}`,
43+
});
44+
},
45+
);
46+
1547
it("pastes on ctrl+v for windows, linux, and unknown hosts", () => {
1648
for (const hostPlatform of ["windows", "linux", "unknown"] as const) {
1749
expect(resolveModifiedTerminalInput({ data: "v", modifier: "ctrl", hostPlatform })).toEqual({

0 commit comments

Comments
 (0)