Skip to content

Commit 770c360

Browse files
Merge remote-tracking branch 'origin/main' into L71-18392
2 parents 03e0705 + 4af6618 commit 770c360

208 files changed

Lines changed: 8841 additions & 1154 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/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/ipc/DesktopIpcHandlers.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,11 @@ export const installDesktopIpcHandlers = Effect.fn("desktop.ipc.installHandlers"
166166
yield* ipc.handle(installCliCommand);
167167
yield* ipc.handle(uninstallCliCommand);
168168
for (const previewMethod of PreviewIpc.methods) {
169-
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);
170174
}
171175
yield* ipc.handle(PreviewIpc.listBrowserImportSources);
172176
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

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { PreviewCaptureFailure } from "@t3tools/contracts";
2+
import * as Cause from "effect/Cause";
3+
import type { PreviewManagerError } from "./Manager.ts";
4+
5+
/** Classify before Electron replaces a rejected IPC Error with its message. */
6+
export function normalizeCaptureFailure(
7+
error: PreviewManagerError,
8+
stage: PreviewCaptureFailure["stage"],
9+
): PreviewCaptureFailure {
10+
let reason: PreviewCaptureFailure["reason"] = "capture-failed";
11+
switch (error._tag) {
12+
case "PreviewTabNotFoundError":
13+
case "PreviewWebContentsNotFoundError":
14+
case "PreviewMainWindowClosedError":
15+
reason = "renderer-unavailable";
16+
break;
17+
case "PreviewWebviewNotInitializedError":
18+
case "PreviewRecordingCaptureUnavailableError":
19+
reason = "capture-unavailable";
20+
break;
21+
case "PreviewRecordingArmConflictError":
22+
reason = "recording-conflict";
23+
break;
24+
case "PreviewOperationError":
25+
if (error.operation === "captureScreenshot.capturePage") {
26+
stage = "capture-page";
27+
if (
28+
error.cause instanceof Error &&
29+
error.cause.message === "Current display surface not available for capture"
30+
) {
31+
reason = "capture-unavailable";
32+
}
33+
}
34+
if (Cause.isTimeoutError(error.cause)) reason = "capture-timeout";
35+
break;
36+
}
37+
return new PreviewCaptureFailure({ reason, stage });
38+
}

‎apps/desktop/src/wsl/DesktopWslBackend.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ export const layer = Layer.effect(
136136
Ref.set(
137137
preflightErrorRef,
138138
Option.some(
139-
"Another T3 Code server is using this distro's T3 home. Stop it, or pair with it instead.",
139+
"Another T3 Code server is using this distro's T3 home, or an older background service is set up for it. Stop that server or pair with it, or try `t3 update` in the distro. If the older launcher cannot update, run `t3 service uninstall` and optionally reinstall with `t3 service install` from a current CLI in the distro. Use `npx t3@latest` if `t3` is missing or outdated, and pass `--base-dir` with the service's T3 home to each command.",
140140
),
141141
),
142142
),

‎apps/mobile/src/features/agent-awareness/agentLiveActivity.ios.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import AgentActivity, { type AgentActivityProps } from "../../widgets/AgentActivity";
22

3+
export function dismissEndedAgentLiveActivities() {
4+
AgentActivity.dismissEnded();
5+
}
6+
37
export function getAgentLiveActivities() {
48
return AgentActivity.getInstances();
59
}

‎apps/mobile/src/features/agent-awareness/agentLiveActivity.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import type { LiveActivity } from "expo-widgets";
22
import type { AgentActivityProps } from "../../widgets/AgentActivity";
33

4+
export function dismissEndedAgentLiveActivities(): void {}
5+
46
export function getAgentLiveActivities(): Array<LiveActivity<AgentActivityProps>> {
57
return [];
68
}

‎apps/mobile/src/features/agent-awareness/remoteRegistration.test.ts‎

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ vi.mock("./androidNotifications", () => ({
5858

5959
const secureStore = vi.hoisted(() => new Map<string, string>());
6060
const widgetMocks = vi.hoisted(() => ({
61+
dismissEnded: vi.fn(),
6162
getInstances: vi.fn(() => []),
6263
start: vi.fn(() => ({})),
6364
}));
@@ -98,6 +99,7 @@ vi.mock("expo-widgets", () => ({
9899
}));
99100

100101
vi.mock("./agentLiveActivity", () => ({
102+
dismissEndedAgentLiveActivities: widgetMocks.dismissEnded,
101103
getAgentLiveActivities: widgetMocks.getInstances,
102104
startAgentLiveActivity: widgetMocks.start,
103105
}));
@@ -271,6 +273,7 @@ describe("makeRelayDeviceRegistrationRequest", () => {
271273
widgetMocks.getInstances.mockReset();
272274
widgetMocks.getInstances.mockReturnValue([]);
273275
widgetMocks.start.mockClear();
276+
widgetMocks.dismissEnded.mockReset();
274277
environmentConfigsMock.configs.clear();
275278
});
276279

@@ -621,6 +624,75 @@ describe("makeRelayDeviceRegistrationRequest", () => {
621624
},
622625
);
623626

627+
it.effect("dismisses ended Live Activities when the idle app returns to the foreground", () => {
628+
setAgentAwarenessRelayTokenProvider(() => Promise.resolve("clerk-token-user-a"));
629+
630+
return Effect.gen(function* () {
631+
yield* runBackgroundOperations();
632+
widgetMocks.dismissEnded.mockClear();
633+
634+
for (const listener of appStateMock.listeners) listener("background");
635+
yield* runBackgroundOperations();
636+
expect(widgetMocks.dismissEnded).not.toHaveBeenCalled();
637+
638+
for (const listener of appStateMock.listeners) listener("active");
639+
yield* runBackgroundOperations();
640+
641+
expect(widgetMocks.dismissEnded).toHaveBeenCalledOnce();
642+
expect(widgetMocks.start).not.toHaveBeenCalled();
643+
}).pipe(Effect.provide(layerRelayTest));
644+
});
645+
646+
it.effect("still registers the active card when ended-card cleanup throws", () => {
647+
const registrations: unknown[] = [];
648+
vi.stubGlobal("fetch", async (input: RequestInfo | URL, init?: RequestInit) => {
649+
const request = new Request(input, init);
650+
if (request.url.endsWith("/v1/client/dpop-token")) {
651+
return Response.json({
652+
access_token: "relay-dpop-token",
653+
issued_token_type: "urn:ietf:params:oauth:token-type:access_token",
654+
token_type: "DPoP",
655+
expires_in: 300,
656+
scope: "mobile:registration",
657+
});
658+
}
659+
if (request.url.endsWith("/v1/mobile/live-activities")) {
660+
registrations.push(await request.json());
661+
}
662+
return Response.json({ ok: true });
663+
});
664+
Constants.expoConfig!.extra = { relay: { url: "https://relay.example.test/" } };
665+
setAgentAwarenessRelayTokenProvider(() => Promise.resolve("clerk-token-user-a"));
666+
const activity = {
667+
getId: () => "activity-1",
668+
getPushToken: vi.fn(() => Promise.resolve("activity-token")),
669+
addPushTokenListener: vi.fn(),
670+
end: vi.fn(),
671+
};
672+
673+
return Effect.gen(function* () {
674+
yield* runBackgroundOperations();
675+
widgetMocks.dismissEnded.mockReset();
676+
widgetMocks.dismissEnded.mockImplementation(() => {
677+
throw new Error("Cannot find function dismissEnded");
678+
});
679+
widgetMocks.getInstances.mockReturnValue([activity] as never);
680+
681+
for (const listener of appStateMock.listeners) listener("active");
682+
yield* runBackgroundOperations();
683+
684+
expect(widgetMocks.dismissEnded).toHaveBeenCalledOnce();
685+
expect(registrations).toEqual([
686+
{ deviceId: "device-1", activityPushToken: "activity-token" },
687+
]);
688+
expect(activity.end).not.toHaveBeenCalled();
689+
expect(widgetMocks.start).not.toHaveBeenCalled();
690+
}).pipe(
691+
Effect.provideService(FetchHttpClient.Fetch, globalThis.fetch),
692+
Effect.provide(layerRelayTest),
693+
);
694+
});
695+
624696
it("ends local Live Activities and stops foreground reconciliation on cloud sign-out", () => {
625697
const end = vi.fn(() => Promise.resolve());
626698
const activity = {
@@ -636,6 +708,7 @@ describe("makeRelayDeviceRegistrationRequest", () => {
636708
setAgentAwarenessRelayTokenProvider(null);
637709

638710
expect(end).toHaveBeenCalledWith("immediate");
711+
expect(widgetMocks.dismissEnded).toHaveBeenCalled();
639712
expect(appStateMock.listeners).toHaveLength(0);
640713
});
641714

0 commit comments

Comments
 (0)