-
Notifications
You must be signed in to change notification settings - Fork 3.2k
feat(web): preview workspace images from chat and diffs #3259
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
StiensWout
wants to merge
12
commits into
pingdotgg:main
Choose a base branch
from
StiensWout:fix/workspace-image-preview
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
9d4abcb
Preview workspace image files
StiensWout 0a79553
Add markdown preview failure fallback
StiensWout 64464dc
Clarify markdown preview fallback toast
StiensWout 3e14a9a
Retrigger service conventions check
juliusmarminge 93c06ab
Ignore superseded image preview requests
juliusmarminge 78581ed
Share preview request ordering across surfaces
juliusmarminge 49a9c25
fix(web): structure preview asset URL failures
juliusmarminge 881936d
Structure browser preview availability errors
juliusmarminge 0078748
fix(web): preserve markdown preview fallback
juliusmarminge 66c94ff
Merge branch 'main' into fix/workspace-image-preview
StiensWout 0fa2ec2
Merge upstream main into fix/workspace-image-preview
StiensWout 17612cc
Address image preview review feedback
StiensWout File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,134 @@ | ||
| import type { AtomCommandResult } from "@t3tools/client-runtime/state/runtime"; | ||
| import type { PreviewSessionSnapshot, ScopedThreadRef } from "@t3tools/contracts"; | ||
| import * as Cause from "effect/Cause"; | ||
| import { AsyncResult } from "effect/unstable/reactivity"; | ||
| import { afterEach, beforeEach, describe, expect, it, vi } from "vite-plus/test"; | ||
|
|
||
| import { readThreadPreviewState, resetPreviewStateForTests } from "~/previewStateStore"; | ||
| import { selectThreadRightPanelState, useRightPanelStore } from "~/rightPanelStore"; | ||
|
|
||
| import { | ||
| BrowserPreviewUnavailableError, | ||
| isBrowserPreviewAssetUrlInvalidError, | ||
| type OpenPreviewMutation, | ||
| openFileInPreview, | ||
| openUrlInPreview, | ||
| } from "./openFileInPreview"; | ||
|
|
||
| const threadRef = { | ||
| environmentId: "environment-1" as ScopedThreadRef["environmentId"], | ||
| threadId: "thread-1" as ScopedThreadRef["threadId"], | ||
| }; | ||
|
|
||
| const snapshot = (tabId: string, url: string): PreviewSessionSnapshot => ({ | ||
| threadId: threadRef.threadId, | ||
| tabId, | ||
| navStatus: { _tag: "Success", url, title: "" }, | ||
| canGoBack: false, | ||
| canGoForward: false, | ||
| updatedAt: "2026-06-21T00:00:00.000Z", | ||
| }); | ||
|
|
||
| beforeEach(() => { | ||
| resetPreviewStateForTests(); | ||
| useRightPanelStore.setState({ byThreadKey: {} }); | ||
| }); | ||
|
|
||
| afterEach(() => vi.unstubAllGlobals()); | ||
|
|
||
| describe("openFileInPreview", () => { | ||
| it("reports an unavailable runtime with thread context", async () => { | ||
| vi.stubGlobal("window", {}); | ||
|
|
||
| const result = await openFileInPreview({ | ||
| threadRef, | ||
| filePath: "docs/report.pdf", | ||
| httpBaseUrl: "https://environment.test", | ||
| createAssetUrl: vi.fn(), | ||
| openPreview: vi.fn(), | ||
| }); | ||
| const error = result._tag === "Failure" ? Cause.squash(result.cause) : undefined; | ||
|
|
||
| expect(error).toEqual( | ||
| new BrowserPreviewUnavailableError({ | ||
| environmentId: "environment-1", | ||
| threadId: "thread-1", | ||
| }), | ||
| ); | ||
| expect(error).toMatchObject({ | ||
| message: "The integrated browser is unavailable in this runtime.", | ||
| }); | ||
| }); | ||
|
|
||
| it("reports invalid asset URLs with safe context and the exact parser cause", async () => { | ||
| vi.stubGlobal("window", { desktopBridge: { preview: {} } }); | ||
| const parserCause = new TypeError("invalid URL"); | ||
| const InvalidUrl = vi.fn(function InvalidUrl() { | ||
| throw parserCause; | ||
| }); | ||
| vi.stubGlobal("URL", InvalidUrl); | ||
| const openPreview = vi.fn(); | ||
| const httpBaseUrl = "not a URL"; | ||
| const relativeUrl = "/api/assets/signed-secret-token/docs/report.pdf"; | ||
| const expiresAt = Date.now(); | ||
|
|
||
| const result = await openFileInPreview({ | ||
| threadRef, | ||
| filePath: "docs/report.pdf", | ||
| httpBaseUrl, | ||
| createAssetUrl: async () => AsyncResult.success({ relativeUrl, expiresAt }), | ||
| openPreview, | ||
| }); | ||
| const error = result._tag === "Failure" ? Cause.squash(result.cause) : undefined; | ||
|
|
||
| expect(isBrowserPreviewAssetUrlInvalidError(error)).toBe(true); | ||
| if (!isBrowserPreviewAssetUrlInvalidError(error)) { | ||
| throw new Error("Expected BrowserPreviewAssetUrlInvalidError"); | ||
| } | ||
| expect(error).toMatchObject({ | ||
| environmentId: "environment-1", | ||
| threadId: "thread-1", | ||
| filePath: "docs/report.pdf", | ||
| httpBaseUrlLength: httpBaseUrl.length, | ||
| relativeUrlLength: relativeUrl.length, | ||
| expiresAt, | ||
| }); | ||
| expect(error.cause).toBe(parserCause); | ||
| expect(error.message).toBe("The environment returned an invalid asset URL."); | ||
| expect(error).not.toHaveProperty("httpBaseUrl"); | ||
| expect(error).not.toHaveProperty("relativeUrl"); | ||
| expect(JSON.stringify(error)).not.toContain("signed-secret-token"); | ||
| expect(openPreview).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it("does not apply an older preview response after another caller starts a newer request", async () => { | ||
| const firstSnapshot = snapshot("tab-1", "https://assets.test/first.png"); | ||
| const secondSnapshot = snapshot("tab-2", "https://assets.test/second.png"); | ||
| let resolveFirst!: (result: AtomCommandResult<PreviewSessionSnapshot, never>) => void; | ||
| const openPreview: OpenPreviewMutation<never> = ({ input }) => | ||
| input.url === "https://assets.test/first.png" | ||
| ? new Promise<AtomCommandResult<PreviewSessionSnapshot, never>>((resolve) => { | ||
| resolveFirst = resolve; | ||
| }) | ||
| : Promise.resolve(AsyncResult.success(secondSnapshot)); | ||
|
|
||
| const firstRequest = openUrlInPreview({ | ||
| threadRef, | ||
| url: "https://assets.test/first.png", | ||
| openPreview, | ||
| }); | ||
|
|
||
| await openUrlInPreview({ | ||
| threadRef, | ||
| url: "https://assets.test/second.png", | ||
| openPreview, | ||
| }); | ||
| resolveFirst(AsyncResult.success(firstSnapshot)); | ||
| await firstRequest; | ||
|
|
||
| expect(readThreadPreviewState(threadRef).snapshot).toEqual(secondSnapshot); | ||
| expect( | ||
| selectThreadRightPanelState(useRightPanelStore.getState().byThreadKey, threadRef).surfaces, | ||
| ).toEqual([{ id: "browser:tab-2", kind: "preview", resourceId: "tab-2" }]); | ||
| }); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.