GeezerVison is showing github.com — Merge remote-tracking branch 'origin/main' into pr-33042 · pingdotgg/t3code@20ef152
File treeExpand file treeCollapse file tree Open diff view settings testkit/fixtures/message_steering
packages/provider-cursor/src/server
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: apps/desktop/src/preview/DesktopBrowserHost.test.ts +76Lines changed: 76 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -34,6 +34,8 @@ const command = ( | 34 | 34 | const makeDebuggee = ( | 35 | 35 | options: { | 36 | 36 | readonly deferFocus?: boolean; | | 37 | + /** The guest is still loading its first page. */ | | 38 | + readonly loading?: boolean; | 37 | 39 | readonly refuse?: (method: string, sessionId: string | undefined) => boolean; | 38 | 40 | } = {}, | 39 | 41 | ) => { | @@ -69,10 +71,13 @@ const makeDebuggee = ( | 69 | 71 | sendWaiters.shift()?.(); | 70 | 72 | }), | 71 | 73 | }); | | 74 | + let destroyed = false; | 72 | 75 | const webContents = Object.assign(new NodeEvents.EventEmitter(), { | 73 | 76 | getURL: () => "http://localhost/", | 74 | 77 | getTitle: () => "Page", | 75 | 78 | getUserAgent: () => "Electron", | | 79 | + isLoadingMainFrame: () => options.loading === true, | | 80 | + isDestroyed: () => destroyed, | 76 | 81 | }); | 77 | 82 | return { | 78 | 83 | tab: { | @@ -81,6 +86,12 @@ const makeDebuggee = ( | 81 | 86 | }, | 82 | 87 | emit: (method: string, params: unknown) => emitter.emit("message", {}, method, params, ""), | 83 | 88 | navigate: () => webContents.emit("did-navigate"), | | 89 | + domReady: () => webContents.emit("dom-ready"), | | 90 | + destroy: () => { | | 91 | + destroyed = true; | | 92 | + }, | | 93 | + failLoad: (code: number) => | | 94 | + webContents.emit("did-fail-load", {}, code, "Failed", "http://localhost/", true), | 84 | 95 | /** Ids of the commands the debugger received, in order. */ | 85 | 96 | sent, | 86 | 97 | focusEmulation, | @@ -144,6 +155,71 @@ describe("DesktopBrowserHost", () => { | 144 | 155 | }), | 145 | 156 | ); | 146 | 157 |
| | 158 | + it.effect("announces a guest still loading its first page only once that page is up", () => | | 159 | + Effect.gen(function* () { | | 160 | + const host = yield* DesktopBrowserHost.make; | | 161 | + const loading = makeDebuggee({ loading: true }); | | 162 | + const other = { ...key, tabId: "tab-2" }; | | 163 | + const reader = yield* takeEvents(host, 3).pipe(Effect.forkScoped); | | 164 | + | | 165 | + yield* Effect.yieldNow; | | 166 | + host.attach(key, loading.tab); | | 167 | + host.setShown(key, true); | | 168 | + host.attach(other, makeDebuggee().tab); | | 169 | + loading.domReady(); | | 170 | + | | 171 | + expect(yield* Fiber.join(reader)).toEqual([ | | 172 | + { type: "attached", ...other }, | | 173 | + { type: "attached", ...key }, | | 174 | + { type: "shown", ...key, shown: true }, | | 175 | + ]); | | 176 | + }), | | 177 | + ); | | 178 | + | | 179 | + it.effect( | | 180 | + "keeps a loading guest unannounced across a replaced navigation and a new backend", | | 181 | + () => | | 182 | + Effect.gen(function* () { | | 183 | + const host = yield* DesktopBrowserHost.make; | | 184 | + const loading = makeDebuggee({ loading: true }); | | 185 | + const other = { ...key, tabId: "tab-2" }; | | 186 | + host.attach(key, loading.tab); | | 187 | + loading.failLoad(-3); | | 188 | + const reader = yield* takeEvents(host, 2).pipe(Effect.forkScoped); | | 189 | + | | 190 | + yield* Effect.yieldNow; | | 191 | + host.attach(other, makeDebuggee().tab); | | 192 | + loading.domReady(); | | 193 | + | | 194 | + expect(yield* Fiber.join(reader)).toEqual([ | | 195 | + { type: "attached", ...other }, | | 196 | + { type: "attached", ...key }, | | 197 | + ]); | | 198 | + }), | | 199 | + ); | | 200 | + | | 201 | + it.effect( | | 202 | + "announces a first page that never comes up, but never a tab closed or destroyed first", | | 203 | + () => | | 204 | + Effect.gen(function* () { | | 205 | + const host = yield* DesktopBrowserHost.make; | | 206 | + const closed = { ...key, tabId: "tab-2" }; | | 207 | + const destroyed = { ...key, tabId: "tab-3" }; | | 208 | + const destroyedGuest = makeDebuggee({ loading: true }); | | 209 | + const reader = yield* takeEvents(host, 1).pipe(Effect.forkScoped); | | 210 | + | | 211 | + yield* Effect.yieldNow; | | 212 | + host.attach(closed, makeDebuggee({ loading: true }).tab); | | 213 | + host.detach(closed); | | 214 | + host.attach(destroyed, destroyedGuest.tab); | | 215 | + destroyedGuest.destroy(); | | 216 | + host.attach(key, makeDebuggee({ loading: true }).tab); | | 217 | + yield* TestClock.adjust("5 seconds"); | | 218 | + | | 219 | + expect(yield* Fiber.join(reader)).toEqual([{ type: "attached", ...key }]); | | 220 | + }), | | 221 | + ); | | 222 | + | 147 | 223 | it.effect("re-sends shown to a backend that starts later and when a tab attaches again", () => | 148 | 224 | Effect.gen(function* () { | 149 | 225 | const host = yield* DesktopBrowserHost.make; | |
Collapse file Copy file name to clipboardExpand all lines: apps/desktop/src/preview/DesktopBrowserHost.ts +55-5Lines changed: 55 additions & 5 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 8 | 8 | import * as Context from "effect/Context"; | 9 | 9 | import * as NodePath from "node:path"; | 10 | 10 | import * as Effect from "effect/Effect"; | | 11 | +import * as Fiber from "effect/Fiber"; | 11 | 12 | import * as Layer from "effect/Layer"; | 12 | 13 | import * as Option from "effect/Option"; | 13 | 14 | import * as PubSub from "effect/PubSub"; | @@ -26,6 +27,9 @@ const AGENT_INPUT_COMMAND = | 26 | 27 | const AGENT_INPUT_METHOD = /^(?:Input\.|Page\.navigate$|Runtime\.(?:evaluate|callFunctionOn)$)/; | 27 | 28 | const AGENT_DOWNLOAD_WINDOW_MS = 5_000; | 28 | 29 | const FOCUS_IDLE = "5 seconds"; | | 30 | +/** Well inside the server's 10 s DESKTOP_ATTACH_TIMEOUT, for a first page that never reports it is up. */ | | 31 | +const FIRST_PAGE_TIMEOUT = "5 seconds"; | | 32 | +const ERR_ABORTED = -3; | 29 | 33 |
| 30 | 34 | export interface DesktopBrowserTabKey { | 31 | 35 | readonly threadId: string; | @@ -78,6 +82,8 @@ interface AttachedTab { | 78 | 82 | sessionId: string, | 79 | 83 | ) => void; | 80 | 84 | readonly onNewDocument: () => void; | | 85 | + /** Stops waiting for the first page; set until the tab is announced. */ | | 86 | + stopWaiting: (() => void) | null; | 81 | 87 | } | 82 | 88 |
| 83 | 89 | export class DesktopBrowserHost extends Context.Service< | @@ -413,11 +419,13 @@ export const make = Effect.gen(function* () { | 413 | 419 | const tab = tabs.get(id); | 414 | 420 | if (!tab) return; | 415 | 421 | tabs.delete(id); | | 422 | + const announced = tab.stopWaiting === null; | | 423 | + tab.stopWaiting?.(); | 416 | 424 | tab.relay = null; | 417 | 425 | tab.debuggee.debugger.off("message", tab.onMessage); | 418 | 426 | tab.debuggee.webContents.off("did-navigate", tab.onNewDocument); | 419 | 427 | syncPainting(tab); | 420 | | - emit({ type: "detached", ...key }); | | 428 | + if (announced) emit({ type: "detached", ...key }); | 421 | 429 | }; | 422 | 430 |
| 423 | 431 | const attach = (key: DesktopBrowserTabKey, debuggee: DesktopBrowserTabDebugger) => { | @@ -455,13 +463,53 @@ export const make = Effect.gen(function* () { | 455 | 463 | dropFocusHolds(tab); | 456 | 464 | if (tab.screenshotTurn !== null) nextScreenshot(tab); | 457 | 465 | }, | | 466 | + stopWaiting: null, | 458 | 467 | }; | 459 | 468 | tabs.set(id, tab); | 460 | 469 | debuggee.debugger.on("message", tab.onMessage); | 461 | 470 | debuggee.webContents.on("did-navigate", tab.onNewDocument); | 462 | | - emit({ type: "attached", ...key }); | 463 | | - const shown = shownTabs.get(id); | 464 | | - if (shown !== undefined) emit({ type: "shown", ...key, shown }); | | 471 | + const announce = () => { | | 472 | + emit({ type: "attached", ...key }); | | 473 | + const shown = shownTabs.get(id); | | 474 | + if (shown !== undefined) emit({ type: "shown", ...key, shown }); | | 475 | + }; | | 476 | + if (!debuggee.webContents.isLoadingMainFrame()) { | | 477 | + announce(); | | 478 | + return; | | 479 | + } | | 480 | + // Electron does not pause a guest for the debugger, so Playwright connecting during its first | | 481 | + // commit builds its utility world in the discarded document and every wait on it hangs. | | 482 | + const { webContents } = debuggee; | | 483 | + // ERR_ABORTED is a newer navigation replacing this one, whose commit is still to come. | | 484 | + const onFailLoad = ( | | 485 | + _event: Electron.Event, | | 486 | + code: number, | | 487 | + _description: string, | | 488 | + _url: string, | | 489 | + isMainFrame: boolean, | | 490 | + ) => { | | 491 | + if (isMainFrame && code !== ERR_ABORTED) ready(); | | 492 | + }; | | 493 | + const ready = () => { | | 494 | + if (tab.stopWaiting === null) return; | | 495 | + // The manager's cleanup for a destroyed guest can still be queued behind another tab's attach. | | 496 | + if (webContents.isDestroyed()) return detach(key); | | 497 | + tab.stopWaiting(); | | 498 | + announce(); | | 499 | + }; | | 500 | + const timeout = runFork( | | 501 | + Effect.sleep(FIRST_PAGE_TIMEOUT).pipe(Effect.andThen(Effect.sync(ready))), | | 502 | + ); | | 503 | + tab.stopWaiting = () => { | | 504 | + tab.stopWaiting = null; | | 505 | + webContents.off("dom-ready", ready); | | 506 | + webContents.off("did-stop-loading", ready); | | 507 | + webContents.off("did-fail-load", onFailLoad); | | 508 | + runFork(Fiber.interrupt(timeout)); | | 509 | + }; | | 510 | + webContents.on("dom-ready", ready); | | 511 | + webContents.on("did-stop-loading", ready); | | 512 | + webContents.on("did-fail-load", onFailLoad); | 465 | 513 | }; | 466 | 514 |
| 467 | 515 | const setShown = (key: DesktopBrowserTabKey, shown: boolean | undefined) => { | @@ -472,7 +520,7 @@ export const make = Effect.gen(function* () { | 472 | 520 | } | 473 | 521 | if (shownTabs.get(id) === shown) return; | 474 | 522 | shownTabs.set(id, shown); | 475 | | - if (tabs.has(id)) emit({ type: "shown", ...key, shown }); | | 523 | + if (tabs.get(id)?.stopWaiting === null) emit({ type: "shown", ...key, shown }); | 476 | 524 | }; | 477 | 525 |
| 478 | 526 | const handleCommandLine = (line: string) => | @@ -511,6 +559,8 @@ export const make = Effect.gen(function* () { | 511 | 559 | [...tabs.values()], | 512 | 560 | (tab) => { | 513 | 561 | dropRelay(tab); | | 562 | + // Announced once its first page is up. | | 563 | + if (tab.stopWaiting !== null) return Effect.void; | 514 | 564 | const shown = shownTabs.get(keyOf(tab.key)); | 515 | 565 | return PubSub.publish(outbox, { type: "attached", ...tab.key }).pipe( | 516 | 566 | Effect.andThen( | |
Collapse file Copy file name to clipboardExpand all lines: apps/mobile/src/components/ui/FilePreviewSession.test.tsx +29-2Lines changed: 29 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | import { act, useState } from "react"; | 2 | 2 | import { createRoot } from "react-dom/client"; | 3 | 3 | import { expect, it, vi } from "vite-plus/test"; | 4 | | -import { EnvironmentId, SOURCE_CONTROL_MEDIA_ASSET } from "@t3tools/contracts"; | | 4 | +import { | | 5 | + AssetWorkspaceAssetNotFoundError, | | 6 | + EnvironmentId, | | 7 | + SOURCE_CONTROL_MEDIA_ASSET, | | 8 | + ThreadId, | | 9 | +} from "@t3tools/contracts"; | 5 | 10 |
| 6 | 11 | const harness = vi.hoisted(() => ({ | 7 | | - refreshAssetUrl: vi.fn<(environmentId: string, resource: { url: string }) => Promise<string>>(), | | 12 | + refreshAssetUrl: | | 13 | + vi.fn<(environmentId: string, resource: { url: string }) => Promise<string | null>>(), | 8 | 14 | alert: vi.fn(), | 9 | 15 | previews: [] as unknown[], | 10 | 16 | mounts: 0, | @@ -144,3 +150,24 @@ it("closes the preview when the selected image cannot be resolved", async () => | 144 | 150 | expect(preview.onRequestClose).toHaveBeenCalledOnce(); | 145 | 151 | expect(harness.alert).toHaveBeenCalledOnce(); | 146 | 152 | }); | | 153 | + | | 154 | +it("names the checked path when the server cannot find the file", async () => { | | 155 | + const resource = { | | 156 | + _tag: "media-file" as const, | | 157 | + threadId: ThreadId.make("thread"), | | 158 | + path: "v2/extended/duo-color-3-extended-FINAL.png", | | 159 | + }; | | 160 | + const checkedPath = "/repo/v2/extended/duo-color-3-extended-FINAL.png"; | | 161 | + harness.refreshAssetUrl.mockRejectedValue( | | 162 | + new AssetWorkspaceAssetNotFoundError({ resource, checkedPath }), | | 163 | + ); | | 164 | + const selected: FilePreviewItem = { kind: "image", environmentId, resource }; | | 165 | + await using preview = await openGallery(selected, [selected], false); | | 166 | + | | 167 | + expect(preview.onRequestClose).toHaveBeenCalledOnce(); | | 168 | + expect(harness.alert).toHaveBeenCalledWith( | | 169 | + "Could not open preview", | | 170 | + expect.stringContaining(checkedPath), | | 171 | + ); | | 172 | + expect(harness.alert.mock.calls[0]?.[1]).not.toMatch(/reconnect/i); | | 173 | +}); |
Collapse file Copy file name to clipboardExpand all lines: apps/mobile/src/components/ui/FilePreviewSession.tsx +11-2Lines changed: 11 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +import { AssetWorkspaceAssetNotFoundError } from "@t3tools/contracts"; | 1 | 2 | import * as Schema from "effect/Schema"; | 2 | 3 | import * as Dialog from "./Dialog"; | 3 | 4 | import { useContext, useEffect, useEffectEvent, useState, type ComponentType } from "react"; | @@ -36,6 +37,15 @@ class PreviewResolutionError extends Schema.TaggedError<PreviewResolutionError>( | 36 | 37 | } | 37 | 38 |
| 38 | 39 | const isPreviewResolutionError = Schema.is(PreviewResolutionError); | | 40 | +const isAssetNotFoundError = Schema.is(AssetWorkspaceAssetNotFoundError); | | 41 | + | | 42 | +function remotePreviewFailureMessage(error: unknown): string { | | 43 | + if (!isAssetNotFoundError(error)) { | | 44 | + return "Reconnect to this environment and try again. The file may have been moved or deleted."; | | 45 | + } | | 46 | + const path = error.checkedPath ?? ("path" in error.resource ? error.resource.path : undefined); | | 47 | + return path ? `The file was not found at ${path}.` : error.message; | | 48 | +} | 39 | 49 |
| 40 | 50 | interface ResolvedPreviewUri { | 41 | 51 | readonly uri: string; | @@ -64,8 +74,7 @@ async function resolvePreviewUri( | 64 | 74 | .catch((error: unknown) => { | 65 | 75 | throw new PreviewResolutionError({ | 66 | 76 | cause: error, | 67 | | - fallbackMessage: | 68 | | - "Reconnect to this environment and try again. The file may have been moved or deleted.", | | 77 | + fallbackMessage: remotePreviewFailureMessage(error), | 69 | 78 | }); | 70 | 79 | }); | 71 | 80 | return { uri: url + (item.srcFragment ?? "") }; | |
Collapse file Copy file name to clipboardExpand all lines: apps/mobile/src/components/ui/VideoPreviewModal.tsx +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -50,7 +50,7 @@ function NativeVideoPreview(props: { | 50 | 50 | const resolvePlaybackUrl = useEffectEvent(async (): Promise<string> => { | 51 | 51 | if (source.type !== "media") throw new Error("Could not load this video."); | 52 | 52 | if (!("resource" in source)) return source.uri; | 53 | | - const url = await refreshAssetUrl(source.environmentId, source.resource); | | 53 | + const url = await refreshAssetUrl(source.environmentId, source.resource).catch(() => null); | 54 | 54 | const playbackUrl = mediaVideoPreviewUri(source, url); | 55 | 55 | if (playbackUrl !== null) return playbackUrl; | 56 | 56 | throw new Error( | @@ -61,7 +61,7 @@ function NativeVideoPreview(props: { | 61 | 61 | }); | 62 | 62 | const reauthorize = useEffectEvent(() => { | 63 | 63 | if (source.type === "media" && "resource" in source) { | 64 | | - void refreshAssetUrl(source.environmentId, source.resource); | | 64 | + void refreshAssetUrl(source.environmentId, source.resource).catch(() => {}); | 65 | 65 | } | 66 | 66 | }); | 67 | 67 |
| |
Collapse file Copy file name to clipboardExpand all lines: apps/mobile/src/features/layout/AdaptiveWorkspaceLayout.tsx +10-13Lines changed: 10 additions & 13 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -362,8 +362,8 @@ function AdaptiveWorkspaceLayoutContent( | 362 | 362 | floatingTabs.row, | 363 | 363 | floatingTabsEnabled, | 364 | 364 | ]); | 365 | | - // A floating sidebar brings the rail with it. | 366 | | - const width = viewportWidth - (sidebarFloats ? 0 : navigationRailWidth); | | 365 | + // The rail keeps its room even while the sidebar floats; only the list pane overlays the page. | | 366 | + const width = viewportWidth - navigationRailWidth; | 367 | 367 | // The sidebar stays mounted under a workspace page, so its list is ready on the way back. | 368 | 368 | const shouldRenderPrimarySidebar = layout.usesSplitView; | 369 | 369 | const fileInspector = useMemo( | @@ -721,7 +721,7 @@ function AdaptiveWorkspaceLayoutContent( | 721 | 721 | // panes land. A sliding sidebar uncovers the strip it is about to fill, or covers the content | 722 | 722 | // until it is gone. | 723 | 723 | const contentLeftTarget = sidebarFloats | 724 | | - ? 0 | | 724 | + ? navigationRailWidth | 725 | 725 | : navigationRailWidth + | 726 | 726 | (shouldRenderPrimarySidebar && !workspacePage && panes.primarySidebarVisible | 727 | 727 | ? (layout.listPaneWidth ?? 0) + (layout.listPaneGap ?? 0) | @@ -794,7 +794,9 @@ function AdaptiveWorkspaceLayoutContent( | 794 | 794 | workspacePage, | 795 | 795 | ]); | 796 | 796 | const railAnimatedStyle = useAnimatedStyle(() => ({ width: renderedRailWidth.value })); | 797 | | - const floatingSidebarAnimatedStyle = useAnimatedStyle(() => ({ left: renderedRailWidth.value })); | | 797 | + const floatingSidebarAnimatedStyle = useAnimatedStyle(() => ({ | | 798 | + left: sidebarFloats ? renderedRailWidth.value : 0, | | 799 | + })); | 798 | 800 | const floatingSidebarOpen = sidebarFloats && panes.primarySidebarVisible; | 799 | 801 | // Its own value, so a sidebar that was beside a list doesn't dim the page as it leaves. | 800 | 802 | const scrimOpacity = useSharedValue(0); | @@ -850,7 +852,7 @@ function AdaptiveWorkspaceLayoutContent( | 850 | 852 | Math.max( | 851 | 853 | 0, | 852 | 854 | viewportWidth - | 853 | | - (sidebarFloats ? 0 : renderedRailWidth.value) - | | 855 | + renderedRailWidth.value - | 854 | 856 | (workspacePage || sidebarFloats ? 0 : renderedSidebarWidth.value) - | 855 | 857 | renderedInspectorWidth.value, | 856 | 858 | ), | @@ -974,10 +976,7 @@ function AdaptiveWorkspaceLayoutContent( | 974 | 976 | > | 975 | 977 | <AndroidHingeObserver onChange={handleHingeChange} /> | 976 | 978 | {shouldRenderNavigationRail ? ( | 977 | | - <Animated.View | 978 | | - className={sidebarFloats ? "absolute inset-y-0 left-0" : "shrink self-stretch"} | 979 | | - style={railAnimatedStyle} | 980 | | - /> | | 979 | + <Animated.View className="shrink self-stretch" style={railAnimatedStyle} /> | 981 | 980 | ) : null} | 982 | 981 | {shouldRenderPrimarySidebar && layout.listPaneWidth !== null ? ( | 983 | 982 | <Animated.View | @@ -994,11 +993,9 @@ function AdaptiveWorkspaceLayoutContent( | 994 | 993 | style={[ | 995 | 994 | workspacePage ? { position: "absolute", top: 0, bottom: 0, left: 0 } : null, | 996 | 995 | sidebarFloats | 997 | | - ? [ | 998 | | - { position: "absolute", top: 0, bottom: 0, zIndex: 2, elevation: 8 }, | 999 | | - floatingSidebarAnimatedStyle, | 1000 | | - ] | | 996 | + ? { position: "absolute", top: 0, bottom: 0, zIndex: 2, elevation: 8 } | 1001 | 997 | : null, | | 998 | + floatingSidebarAnimatedStyle, | 1002 | 999 | sidebarAnimatedStyle, | 1003 | 1000 | ]} | 1004 | 1001 | > | |
Collapse file Copy file name to clipboardExpand all lines: apps/mobile/src/lib/attachmentDocument.ts +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -44,7 +44,7 @@ async function readAttachmentText(key: AttachmentTextKey, signal: AbortSignal) { | 44 | 44 | const refreshed = | 45 | 45 | key.environmentId === null | 46 | 46 | ? null | 47 | | - : await refreshAssetUrl(key.environmentId, key.resource, signal); | | 47 | + : await refreshAssetUrl(key.environmentId, key.resource, signal).catch(() => null); | 48 | 48 | if (!refreshed) throw new Error("Reconnect to this environment and try again."); | 49 | 49 | target = refreshed; | 50 | 50 | } | |
|