Skip to content

Commit 553378c

Browse files
Merge remote-tracking branch 'origin/main' into l69-19931
2 parents 3b6008c + 8c8e187 commit 553378c

268 files changed

Lines changed: 12554 additions & 1618 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/DesktopApp.ts‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -239,9 +239,7 @@ const bootstrap = Effect.gen(function* () {
239239
}
240240

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

‎apps/desktop/src/backend/DesktopBackendPool.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ export const layer = Layer.effect(
180180
electronDialog
181181
.showErrorBox(
182182
"This T3 home is unavailable",
183-
"Another T3 Code server, such as the background service, is using this data directory. Stop that server and reopen T3 Code, or set a separate T3CODE_HOME and pair with the running server.",
183+
"Another T3 Code server, such as the background service, is using this data directory, or an older background service is set up for it. Stop that server or try `t3 update`. If the older launcher cannot update, run `t3 service uninstall` and optionally reinstall with `t3 service install` from a current CLI. Use `npx t3@latest` if `t3` is missing or outdated, and pass `--base-dir` with the service's T3 home to each command. Then reopen T3 Code. You can also set a separate T3CODE_HOME and pair with the running server.",
184184
)
185185
.pipe(Effect.andThen(electronApp.quit)),
186186
});

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,12 @@ describe("ElectronShell", () => {
7878

7979
const electronShell = yield* ElectronShell.ElectronShell;
8080
const result = yield* electronShell.openExternal(
81-
"vscode://vscode-remote/ssh-remote+example.com/home/user/project",
81+
"vscode://vscode-remote/ssh-remote+user%40example.com/home/user/project",
8282
);
8383

8484
assert.equal(result, true);
8585
assert.deepEqual(openExternalMock.mock.calls, [
86-
["vscode://vscode-remote/ssh-remote+example.com/home/user/project"],
86+
["vscode://vscode-remote/ssh-remote+user%40example.com/home/user/project"],
8787
]);
8888
}).pipe(Effect.provide(ElectronShell.layer)),
8989
);
@@ -94,13 +94,13 @@ describe("ElectronShell", () => {
9494

9595
const electronShell = yield* ElectronShell.ElectronShell;
9696
const results = yield* Effect.all([
97-
electronShell.openExternal("zed://ssh/example.com/home/user/project"),
97+
electronShell.openExternal("zed://ssh/user@example.com/home/user/project"),
9898
electronShell.openExternal("zed://ssh/example.com/"),
9999
]);
100100

101101
assert.deepEqual(results, [true, true]);
102102
assert.deepEqual(openExternalMock.mock.calls, [
103-
["zed://ssh/example.com/home/user/project"],
103+
["zed://ssh/user@example.com/home/user/project"],
104104
["zed://ssh/example.com/"],
105105
]);
106106
}).pipe(Effect.provide(ElectronShell.layer)),
@@ -111,7 +111,7 @@ describe("ElectronShell", () => {
111111
openExternalMock.mockResolvedValue(undefined);
112112

113113
const url =
114-
"jetbrains://gateway/ssh/environment?h=example.com&launchIde=true&ideHint=IU&projectHint=%2Fhome%2Fuser%2Fproject";
114+
"jetbrains://gateway/ssh/environment?h=example.com&launchIde=true&ideHint=IU&projectHint=%2Fhome%2Fuser%2Fproject&u=user";
115115
const electronShell = yield* ElectronShell.ElectronShell;
116116
const result = yield* electronShell.openExternal(url);
117117

@@ -150,7 +150,7 @@ describe("ElectronShell", () => {
150150
electronShell.openExternal(
151151
"vscode://:secret@vscode-remote/ssh-remote+example.com/home/user/project",
152152
),
153-
electronShell.openExternal("zed://ssh/[email protected]/home/user/project"),
153+
electronShell.openExternal("zed://ssh/user:secret@example.com/home/user/project"),
154154
electronShell.openExternal("jetbrains://user@gateway/ssh/environment?h=example.com"),
155155
]);
156156

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ const REMOTE_EDITOR_PROTOCOLS = new Set(
2222
}),
2323
);
2424

25-
// Zed's host sits in the first path segment, so it needs its own userinfo ban.
26-
const ZED_SSH_PATHNAME = /^\/[^/@:]+\/.*$/;
25+
// Zed embeds [user@]host in the path; reject passwords and ports there.
26+
const ZED_SSH_PATHNAME = /^\/(?:[^/@:]+@)?[^/@:]+\/.*$/;
2727

2828
const isRemoteEditorUrl = (url: URL) =>
2929
REMOTE_EDITOR_PROTOCOLS.has(url.protocol) &&

‎apps/desktop/src/ipc/DesktopIpcHandlers.ts‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import {
4040
import {
4141
getAppBranding,
4242
getLocalEnvironmentBootstraps,
43+
readLocalEnvironmentBootstraps,
4344
getLocalEnvironmentBearerToken,
4445
getRelayTelemetryEnabled,
4546
getSystemLocale,
@@ -100,6 +101,7 @@ export const installDesktopIpcHandlers = Effect.fn("desktop.ipc.installHandlers"
100101
yield* ipc.handleSync(getSystemLocale);
101102
yield* ipc.handleSync(getWindowFullscreenState);
102103
yield* ipc.handleSync(getLocalEnvironmentBootstraps);
104+
yield* ipc.handle(readLocalEnvironmentBootstraps);
103105
yield* ipc.handleSync(getLocalEnvironmentEnabled);
104106
yield* ipc.handle(setLocalEnvironmentEnabled);
105107
yield* ipc.handle(getLocalEnvironmentBearerToken);
@@ -164,7 +166,11 @@ export const installDesktopIpcHandlers = Effect.fn("desktop.ipc.installHandlers"
164166
yield* ipc.handle(installCliCommand);
165167
yield* ipc.handle(uninstallCliCommand);
166168
for (const previewMethod of PreviewIpc.methods) {
167-
yield* ipc.handle(previewMethod);
169+
// Explicit types preserve the error/service union of these heterogeneous preview methods.
170+
yield* ipc.handle<
171+
Effect.Error<ReturnType<(typeof PreviewIpc.methods)[number]["handler"]>>,
172+
Effect.Services<ReturnType<(typeof PreviewIpc.methods)[number]["handler"]>>
173+
>(previewMethod);
168174
}
169175
yield* ipc.handle(PreviewIpc.listBrowserImportSources);
170176
yield* ipc.handle(PreviewIpc.importBrowserCookies);

‎apps/desktop/src/ipc/methods/preview.test.ts‎

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
DEFAULT_BROWSER_PROFILE_ID,
44
INCOGNITO_BROWSER_PROFILE_ID,
55
PreviewAutomationStatus,
6+
PreviewCaptureFailure,
67
} from "@t3tools/contracts";
78
import * as Cause from "effect/Cause";
89
import * as Effect from "effect/Effect";
@@ -14,6 +15,8 @@ import { beforeEach, describe, expect, it, vi } from "vite-plus/test";
1415
import * as PreviewManager from "../../preview/Manager.ts";
1516
import * as BrowserImport from "../../preview/BrowserImport/BrowserImport.ts";
1617
import * as PreviewIpc from "./preview.ts";
18+
import * as DesktopIpc from "../DesktopIpc.ts";
19+
import * as DesktopClientSettings from "../../settings/DesktopClientSettings.ts";
1720

1821
const { fromPartition } = vi.hoisted(() => ({
1922
fromPartition: vi.fn(() => {
@@ -33,7 +36,102 @@ vi.mock("electron", () => ({
3336
},
3437
}));
3538

39+
const decodeCaptureFailure = Schema.decodeUnknownEffect(PreviewCaptureFailure);
40+
3641
describe("preview IPC methods", () => {
42+
const invokeCapture = (
43+
method: typeof PreviewIpc.startRecording | typeof PreviewIpc.captureScreenshot,
44+
manager: Partial<PreviewManager.PreviewManager["Service"]>,
45+
) =>
46+
Effect.scoped(
47+
Effect.gen(function* () {
48+
let listener: DesktopIpc.DesktopIpcHandleListener | undefined;
49+
const ipc = DesktopIpc.make({
50+
removeHandler: vi.fn(),
51+
handle: (_channel, registered) => {
52+
listener = registered;
53+
},
54+
removeAllListeners: vi.fn(),
55+
on: vi.fn(),
56+
});
57+
yield* ipc.handle(method);
58+
return yield* Effect.promise(async () =>
59+
structuredClone(await listener!({ sender: { id: 7 } }, { tabId: "capture-tab" })),
60+
);
61+
}).pipe(
62+
Effect.provideService(
63+
PreviewManager.PreviewManager,
64+
manager as PreviewManager.PreviewManager["Service"],
65+
),
66+
Effect.provideService(DesktopClientSettings.DesktopClientSettings, {
67+
get: Effect.succeedNone,
68+
set: () => Effect.void,
69+
}),
70+
),
71+
);
72+
73+
effectIt.effect.each([
74+
{
75+
cause: new Error("Current display surface not available for capture"),
76+
reason: "capture-unavailable",
77+
guidance: ["target tab", "unlocked", "display is on", "window is restored"],
78+
},
79+
{
80+
cause: new Cause.TimeoutError(),
81+
reason: "capture-timeout",
82+
guidance: ["timed out during capture-page"],
83+
},
84+
{
85+
cause: new Error("Current display surface not available for capture: private page data"),
86+
reason: "capture-failed",
87+
guidance: ["Preview capture failed during capture-page"],
88+
},
89+
])(
90+
"transports a safe $reason screenshot diagnostic through registered IPC",
91+
({ cause, reason, guidance }) =>
92+
Effect.gen(function* () {
93+
const result = yield* invokeCapture(PreviewIpc.captureScreenshot, {
94+
captureScreenshot: (tabId) =>
95+
Effect.fail(
96+
new PreviewManager.PreviewOperationError({
97+
operation: "captureScreenshot.capturePage",
98+
tabId,
99+
artifactPath: "/private/capture.png",
100+
cause,
101+
}),
102+
),
103+
});
104+
expect(result).toEqual({
105+
_tag: "PreviewCaptureFailure",
106+
reason,
107+
stage: "capture-page",
108+
});
109+
const failure = yield* decodeCaptureFailure(result);
110+
for (const phrase of guidance) expect(failure.message).toContain(phrase);
111+
}),
112+
);
113+
114+
effectIt.effect("preserves recording arm failures without erasing successful void results", () =>
115+
Effect.gen(function* () {
116+
const result = yield* invokeCapture(PreviewIpc.startRecording, {
117+
startRecording: (tabId) =>
118+
Effect.fail(new PreviewManager.PreviewTabNotFoundError({ tabId })),
119+
});
120+
expect(result).toEqual({
121+
_tag: "PreviewCaptureFailure",
122+
reason: "renderer-unavailable",
123+
stage: "recording-start",
124+
});
125+
const failure = yield* decodeCaptureFailure(result);
126+
expect(failure.message).toContain("Reopen the preview tab");
127+
expect(
128+
yield* invokeCapture(PreviewIpc.startRecording, {
129+
startRecording: () => Effect.void,
130+
}),
131+
).toBeUndefined();
132+
}),
133+
);
134+
37135
beforeEach(() => {
38136
fromPartition.mockClear();
39137
});

‎apps/desktop/src/ipc/methods/preview.ts‎

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
DesktopPreviewTabInputSchema,
2020
DesktopPreviewWebviewConfigSchema,
2121
PreviewAnnotationSubmissionResultSchema,
22+
PreviewCaptureFailure,
2223
DEFAULT_BROWSER_PROFILE_ID,
2324
INCOGNITO_BROWSER_PROFILE_ID,
2425
PreviewForwardedShortcut,
@@ -32,6 +33,7 @@ import * as NodeURL from "node:url";
3233
import * as ElectronWindow from "../../electron/ElectronWindow.ts";
3334
import * as BrowserImport from "../../preview/BrowserImport/BrowserImport.ts";
3435
import * as PreviewManager from "../../preview/Manager.ts";
36+
import { normalizeCaptureFailure } from "../../preview/captureErrors.ts";
3537
import * as DesktopClientSettings from "../../settings/DesktopClientSettings.ts";
3638
import { PREVIEW_WEBVIEW_PREFERENCES } from "../../preview/WebviewPreferences.ts";
3739
import * as IpcChannels from "../channels.ts";
@@ -207,7 +209,8 @@ export const cancelPickElement = tabMethod(
207209
export const startRecording = DesktopIpc.makeIpcMethod({
208210
channel: IpcChannels.PREVIEW_RECORDING_START_CHANNEL,
209211
payload: DesktopPreviewTabInputSchema,
210-
result: Schema.Void,
212+
// Void encodes any value as undefined, so the tagged failure must be tried first.
213+
result: Schema.Union([PreviewCaptureFailure, Schema.Void]),
211214
handler: Effect.fn("desktop.ipc.preview.startRecording")(function* ({ tabId }) {
212215
const manager = yield* PreviewManager.PreviewManager;
213216
const store = yield* DesktopClientSettings.DesktopClientSettings;
@@ -216,7 +219,11 @@ export const startRecording = DesktopIpc.makeIpcMethod({
216219
showKeyPresses: value.browserRecordingShowKeyPresses,
217220
showMousePresses: value.browserRecordingShowMousePresses,
218221
}));
219-
yield* manager.startRecording(tabId, Option.getOrUndefined(options));
222+
return yield* manager
223+
.startRecording(tabId, Option.getOrUndefined(options))
224+
.pipe(
225+
Effect.catch((error) => Effect.succeed(normalizeCaptureFailure(error, "recording-start"))),
226+
);
220227
}),
221228
});
222229
export const stopRecording = tabMethod(
@@ -390,10 +397,12 @@ export const setAnnotationSendEnabled = DesktopIpc.makeIpcMethod({
390397
export const captureScreenshot = DesktopIpc.makeIpcMethod({
391398
channel: IpcChannels.PREVIEW_CAPTURE_SCREENSHOT_CHANNEL,
392399
payload: DesktopPreviewTabInputSchema,
393-
result: DesktopPreviewScreenshotArtifactSchema,
400+
result: Schema.Union([DesktopPreviewScreenshotArtifactSchema, PreviewCaptureFailure]),
394401
handler: Effect.fn("desktop.ipc.preview.captureScreenshot")(function* ({ tabId }) {
395402
const manager = yield* PreviewManager.PreviewManager;
396-
return yield* manager.captureScreenshot(tabId);
403+
return yield* manager
404+
.captureScreenshot(tabId)
405+
.pipe(Effect.catch((error) => Effect.succeed(normalizeCaptureFailure(error, "screenshot"))));
397406
}),
398407
});
399408

‎apps/desktop/src/ipc/methods/window.ts‎

Lines changed: 58 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -99,57 +99,68 @@ export const getWindowFullscreenState = DesktopIpc.makeSyncIpcMethod({
9999
}),
100100
});
101101

102-
export const getLocalEnvironmentBootstraps = DesktopIpc.makeSyncIpcMethod({
103-
channel: IpcChannels.GET_LOCAL_ENVIRONMENT_BOOTSTRAPS_CHANNEL,
104-
result: Schema.Array(DesktopEnvironmentBootstrapSchema),
105-
handler: Effect.fn("desktop.ipc.window.getLocalEnvironmentBootstraps")(function* () {
106-
const pool = yield* DesktopBackendPool.DesktopBackendPool;
107-
const configuration = yield* DesktopBackendConfiguration.DesktopBackendConfiguration;
108-
const instances = yield* pool.list;
109-
const bootstraps: DesktopEnvironmentBootstrap[] = [];
110-
for (const instance of instances) {
111-
const isPrimary = instance.id === PRIMARY_LOCAL_ENVIRONMENT_ID;
112-
const config = yield* instance.currentConfig;
113-
const snapshot = yield* instance.snapshot;
114-
if (Option.isNone(config) || Option.isSome(config.value.preflightFailure)) {
115-
const fatalPreflight =
116-
Option.isSome(config) &&
117-
Option.isSome(config.value.preflightFailure) &&
118-
config.value.preflightFailure.value.fatal;
119-
const stoppedPreflight =
120-
Option.isSome(config) &&
121-
Option.isSome(config.value.preflightFailure) &&
122-
(!snapshot.desiredRunning || !snapshot.restartScheduled);
123-
if (isPrimary || fatalPreflight || stoppedPreflight) continue;
124-
bootstraps.push({
125-
id: instance.id,
126-
label: yield* instance.label,
127-
runningDistro: null,
128-
httpBaseUrl: null,
129-
wsBaseUrl: null,
130-
});
131-
continue;
132-
}
133-
const { bootstrap, httpBaseUrl } = config.value;
134-
const runningDistro = config.value.runningDistro ?? null;
102+
const readLocalEnvironmentBootstrapSnapshot = Effect.fn(
103+
"desktop.ipc.window.getLocalEnvironmentBootstraps",
104+
)(function* () {
105+
const pool = yield* DesktopBackendPool.DesktopBackendPool;
106+
const configuration = yield* DesktopBackendConfiguration.DesktopBackendConfiguration;
107+
const instances = yield* pool.list;
108+
const bootstraps: DesktopEnvironmentBootstrap[] = [];
109+
for (const instance of instances) {
110+
const isPrimary = instance.id === PRIMARY_LOCAL_ENVIRONMENT_ID;
111+
const config = yield* instance.currentConfig;
112+
const snapshot = yield* instance.snapshot;
113+
if (Option.isNone(config) || Option.isSome(config.value.preflightFailure)) {
114+
const fatalPreflight =
115+
Option.isSome(config) &&
116+
Option.isSome(config.value.preflightFailure) &&
117+
config.value.preflightFailure.value.fatal;
118+
const stoppedPreflight =
119+
Option.isSome(config) &&
120+
Option.isSome(config.value.preflightFailure) &&
121+
(!snapshot.desiredRunning || !snapshot.restartScheduled);
122+
if (isPrimary || fatalPreflight || stoppedPreflight) continue;
135123
bootstraps.push({
136124
id: instance.id,
137-
label: runningDistro === null ? yield* instance.label : `WSL (${runningDistro})`,
138-
runningDistro,
139-
httpBaseUrl: httpBaseUrl.href,
140-
wsBaseUrl: toWebSocketBaseUrl(httpBaseUrl),
141-
// A backend launched with the desktop secret accepts whichever token the secret derives
142-
// for the current window, so hand out that one rather than the token frozen into its
143-
// launch config.
144-
...(bootstrap.desktopBootstrapSecret
145-
? { bootstrapToken: yield* configuration.currentBootstrapToken }
146-
: bootstrap.desktopBootstrapToken
147-
? { bootstrapToken: bootstrap.desktopBootstrapToken }
148-
: {}),
125+
label: yield* instance.label,
126+
runningDistro: null,
127+
httpBaseUrl: null,
128+
wsBaseUrl: null,
149129
});
130+
continue;
150131
}
151-
return bootstraps;
152-
}),
132+
const { bootstrap, httpBaseUrl } = config.value;
133+
const runningDistro = config.value.runningDistro ?? null;
134+
bootstraps.push({
135+
id: instance.id,
136+
label: runningDistro === null ? yield* instance.label : `WSL (${runningDistro})`,
137+
runningDistro,
138+
httpBaseUrl: httpBaseUrl.href,
139+
wsBaseUrl: toWebSocketBaseUrl(httpBaseUrl),
140+
// A backend launched with the desktop secret accepts whichever token the secret derives
141+
// for the current window, so hand out that one rather than the token frozen into its
142+
// launch config.
143+
...(bootstrap.desktopBootstrapSecret
144+
? { bootstrapToken: yield* configuration.currentBootstrapToken }
145+
: bootstrap.desktopBootstrapToken
146+
? { bootstrapToken: bootstrap.desktopBootstrapToken }
147+
: {}),
148+
});
149+
}
150+
return bootstraps;
151+
});
152+
153+
export const getLocalEnvironmentBootstraps = DesktopIpc.makeSyncIpcMethod({
154+
channel: IpcChannels.GET_LOCAL_ENVIRONMENT_BOOTSTRAPS_CHANNEL,
155+
result: Schema.Array(DesktopEnvironmentBootstrapSchema),
156+
handler: readLocalEnvironmentBootstrapSnapshot,
157+
});
158+
159+
export const readLocalEnvironmentBootstraps = DesktopIpc.makeIpcMethod({
160+
channel: IpcChannels.GET_LOCAL_ENVIRONMENT_BOOTSTRAPS_CHANNEL,
161+
payload: Schema.Void,
162+
result: Schema.Array(DesktopEnvironmentBootstrapSchema),
163+
handler: readLocalEnvironmentBootstrapSnapshot,
153164
});
154165

155166
function extractWslDistroFromEnvironmentId(envId: string): string | null {

0 commit comments

Comments
 (0)