Repository navigation
feat(site/src): open open_preview results in the right panel - #32441
DanielleMaywood wants to merge 1 commit into
Conversation
5272318 to
f206137
Compare
f206137 to
de09426
Compare
|
/coder-agents-review |
|
Chat: Review posted | View chat Review history
deep-review v0.13.1 | Round 10 | Last posted: Round 10, 36 findings (12 P3, 15 P4, 9 Nit), COMMENT. Review Finding inventoryFinding inventory, PR #32441Findings
Contested and acknowledgedCRF-5 (P4, rightPanelTabs.ts:169) - getMatchingAgentOrFirst fallback never applies for preview tabs
CRF-16 (Nit, OpenPreviewTool.tsx:16) - Bare 80/2048 literals copy Go constants
CRF-15 (P4, PreviewPanel.tsx:13) - PreviewPanel vs PortPreviewPanel naming hides that both show ports
CRF-18 (Nit, rightPanelTabs.ts:74) - Tab field
|
| Reviewer | Focus |
|---|---|
| Bisky | tests |
| Chopper | ops/errors |
| Churn-guard | change verification |
| Ging | language modernization |
| Gon | naming |
| Hisoka | edge cases |
| Killua | perf |
| Kite | change integrity |
| Knov | contracts |
| Knuckle | SQL |
| Komugi | flake/determinism |
| Kurapika | security |
| Law | decomposition |
| Leorio | docs |
| Luffy | product |
| Mafu-san | process |
| Mafuuu | contracts |
| Melody | dispatch/pairing |
| Meruem | structural |
| Nami | frontend |
| Netero | mechanical checks |
| Pariston | premise testing |
| Pen-botter | product gaps |
| Razor | verification |
| Robin | duplication |
| Ryosuke | Go arch |
| Takumi | concurrency |
| Zoro | shape |
🤖 Managed by Coder Agents.
There was a problem hiding this comment.
This PR adds the Agents UI for open_preview results: a tool row with an Open preview button, and a right-panel tab that signs in and frames the preview in a CSP wrapper. 8 P3, 7 P4, 5 Nit.
The PR description says "see the routing PR", and no PR in the stack list is the routing PR. Name its number.
Out of scope (needs a ticket or explicit acceptance by a human):
coderd/x/chatd/chattool/openpreview.go:166: the tool returns success for a workspace the chat owner does not own. Sign-in rejects that workspace, so the model tells the user a preview is ready that cannot open.coderd/workspaceapps/preview.go:108,coderd/workspaceapps.go:146: each sign-in creates anapplication_connectAPI key with session lifetime that is never revoked, and an expired sign-in token is rejected even when the request has a valid preview session cookie. Every frame reload adds a key.agent/agentpreview/preview.go:69: file preview IDs exist only in agent memory, so preview links and tabs return 404 after an agent restart untilopen_previewruns again.coderd/previews.go:69: sign-in issues a token for a file preview slug without checking that the agent has published that ID, so the failure appears inside the frame instead of as a sign-in error.coderd/x/chatd/chattool/openpreview.go:138:checkURLPathlimits the path in bytes but its error says "characters", so a model with a long non-ASCII path cannot tell why it failed.
🤖 This review was automatically generated with Coder Agents.
| export const parseOpenPreviewResult = ( | ||
| result: unknown, | ||
| ): NewPreviewTab | undefined => { | ||
| const rec = asRecord(result); |
There was a problem hiding this comment.
P3 [CRF-1] parseOpenPreviewResult never reads kind, so the PR description's "parsed strictly by kind" does not hold. (Netero)
A result with no kind, or with kind: "port" and a file slug such as preview--0123abcd, gets an Open preview button. Check that kind is "port" or "file" and matches the slug form, or remove the claim from the description.
🤖
There was a problem hiding this comment.
Verified in 16f0f81d16: the description now says results are parsed by shape, which matches the parser.
🤖
| ); | ||
| }; | ||
|
|
||
| // Mirrors CheckURLPath in coderd/workspaceapps/previewhost/previewhost.go, |
There was a problem hiding this comment.
P3 [CRF-2] CheckURLPath in coderd/workspaceapps/previewhost/previewhost.go does not exist. The rule this code mirrors is checkURLPath in coderd/x/chatd/chattool/openpreview.go:129. (Netero)
A reader who follows this reference to keep the two checks in sync finds nothing to compare. Point the comment at checkURLPath.
🤖
There was a problem hiding this comment.
Verified fixed in 16f0f81d16: the comment and the client url_path check are gone.
🤖
| buildId: chat.build_id, | ||
| agentId: chat.agent_id, | ||
| agentName: workspaceAgent?.name, | ||
| openPreview: openPreviewEnabled ? openPreviewTab : undefined, |
There was a problem hiding this comment.
P3 [CRF-3] No test fails if the Open preview button shows with the open-preview experiment off. (Netero)
Changing this line to openPreview: openPreviewTab, left Tool.test.tsx, AgentChatPage.test.tsx and rightPanelTabs.test.ts passing (60 of 60), because every page test returns ["open-preview"] from /api/v2/experiments. Add a case to the open_preview results block that returns [] and asserts that no Open preview button renders.
🤖
There was a problem hiding this comment.
P3 [CRF-44] "offers no preview while the experiment is off" waits for API.getWorkspace to be called, not for its response to render, so it checks the gate only when the workspace render finishes first. (Komugi)
The button can only appear after the workspace renders, because previewAccess is undefined while workspace is unset. With !openPreviewEnabled || removed, the test fails with the current mock but passes when getWorkspace resolves 150 ms after the call. Before looking for buttons, wait for something rendered from the loaded workspace, or resolve a deferred getWorkspace and wait until the query succeeds.
🤖
There was a problem hiding this comment.
Declined: removing the experiment check from previewAccess fails this test with the mocks the suite uses, so it guards the gate today; you are right that it waits for the workspace request rather than its render, but the workspace mock resolves immediately in every case.
There was a problem hiding this comment.
The defense holds: with the gate removed, 42 of 42 runs (including on a single core) found the button and failed. Closed.
🤖
|
|
||
| const isPreviewSlug = (value: unknown): value is string => | ||
| typeof value === "string" && | ||
| /^preview--([0-9a-f]{8}|[1-9][0-9]{0,4})$/.test(value); |
There was a problem hiding this comment.
P4 [CRF-4] The port branch [1-9][0-9]{0,4} accepts preview--65536 through preview--99999, which appurl.ParsePreviewSlug rejects with strconv.ParseUint(target, 10, 16). (Netero)
Such a result shows a button whose sign-in returns 400. Match the server's range, or remove this copy (see the comment on the duplicated server rules).
🤖
There was a problem hiding this comment.
Verified fixed in 16f0f81d16: the parser checks only the preview-- prefix.
🤖
| return ( | ||
| openPreviewEnabled && | ||
| tab.workspaceId === workspace.id && | ||
| getMatchingAgentOrFirst(workspace, tab.agentName) !== undefined |
There was a problem hiding this comment.
P4 [CRF-5] getMatchingAgentOrFirst falls back to the first agent only for an empty name, and isUserRightPanelTab already rejects preview tabs with an empty agentName, so here and in UserTabPanel.tsx:77 the call only finds an agent by name. (Netero)
A reader has to trace back to isUserRightPanelTab to confirm that a preview tab cannot fall back to an unrelated agent. Use getWorkspaceAgents(workspace).find((agent) => agent.name === tab.agentName) at both call sites.
🤖
There was a problem hiding this comment.
Declined: behavior is the same because preview tabs always carry an agent name; cheap to revisit.
There was a problem hiding this comment.
The defense holds: both ways a preview tab gets an agent name keep it non-empty. Closed.
🤖
| } | ||
| const runes = [...value].length; | ||
| return ( | ||
| runes >= 1 && runes <= 80 && !/[\p{Cc}\p{Cf}\p{Zl}\p{Zp}]/u.test(value) |
There was a problem hiding this comment.
Nit [CRF-16] 80 here and 2048 on line 26 are bare copies of maxPreviewTitleLength and maxURLPathLength in coderd/x/chatd/chattool/openpreview.go. (Gon)
Declare them as named constants, each with a comment that names the Go constant it mirrors.
🤖
There was a problem hiding this comment.
Declined: the 2048 copy is gone in 16f0f81 because sign-in now checks url_path, and the title limit 80 stays inline in its only check.
There was a problem hiding this comment.
The 2048 copy is gone. The 80 remains: if maxPreviewTitleLength in coderd/x/chatd/chattool/openpreview.go is raised, results with longer titles render as a bare title with no button and no reason, and nothing on this line points to the Go constant. Adding "The limit of 80 mirrors maxPreviewTitleLength in coderd/x/chatd/chattool/openpreview.go." to the comment above isPreviewTitle is enough. (Gon)
🤖
There was a problem hiding this comment.
Declined: the title check is deliberately a client copy, since the user decides by title, and the limit only changes together with the tool, so a drift would need a Go change first.
There was a problem hiding this comment.
Still open as a Nit. The reply explains why the client keeps a copy, but not how someone who raises maxPreviewTitleLength in coderd/x/chatd/chattool/openpreview.go finds it: neither side names the other, and results with longer titles would then lose the button with no reason. One clause on the existing comment above isPreviewTitle fixes it: "The limit of 80 mirrors maxPreviewTitleLength in coderd/x/chatd/chattool/openpreview.go." (Gon)
🤖
There was a problem hiding this comment.
Declined: the title check is deliberately a client copy because the user decides by title, and the limit only changes together with the tool, so we are not adding the cross-reference here.
There was a problem hiding this comment.
Accepted. Neither side names the other, so whether that is acceptable is now the author's call. Closed. (Gon)
🤖
| }; | ||
|
|
||
| /** | ||
| * Signs the caller in to a preview. The returned URL carries a short-lived |
There was a problem hiding this comment.
Nit [CRF-17] Several new doc comments open with a sentence that restates the symbol name or the JSX, and AGENTS.md requires comments to be "substantive and concise". (Gon)
Here, keep only "The returned URL carries a short-lived sign-in token." The same applies to previews.ts:5 ("Signs in to a preview for one frame"), PreviewFrame.tsx:24 ("under a header with the preview's host and a reload button"), UserTabPanel.tsx:21 (the list of kinds repeats the exhaustive switch), rightPanelTabs.ts:78, and chatEntities.ts:240.
🤖
There was a problem hiding this comment.
Three of the six locations are unchanged: UserTabPanel.tsx:21 (the list of kinds), rightPanelTabs.ts:78 ("A preview tab before it has an ID."), and chatEntities.ts:240. (Gon)
🤖
There was a problem hiding this comment.
Declined: these are one-line docs on exported symbols, which the repository requires, and each one is accurate.
There was a problem hiding this comment.
The defense holds: AGENTS.md requires docs on exported symbols, and all three are exported. Closed.
🤖
| label: string; | ||
| workspaceId: string; | ||
| agentName: string; | ||
| slug: string; |
There was a problem hiding this comment.
Nit [CRF-18] The tab field slug renames the API's preview_slug, and in a module that also stores workspace app tabs, a bare slug reads as an app slug. (Gon)
Name it previewSlug.
🤖
There was a problem hiding this comment.
Declined: naming preference.
There was a problem hiding this comment.
Declined: slug sits on the preview tab variant only, next to kind: "preview", so TypeScript narrows it before any read and it cannot be confused with an app tab's fields; renaming it touches every preview tab test for no behavior change.
There was a problem hiding this comment.
The defense holds: every read narrows to kind: "preview" first, and workspace app tabs store appId, not slug. Closed.
🤖
| const signInQuery = useQuery( | ||
| previewSignIn({ ...preview, region_id: proxy.proxy?.id }, frameId), | ||
| ); | ||
| const signIn = signInQuery.data; |
There was a problem hiding this comment.
Nit [CRF-19] signIn holds a PreviewSignInResponse, but it reads as a function at signIn && ... and wrapperHTML(signIn, title). (Gon)
Name it signInResponse.
🤖
There was a problem hiding this comment.
Verified fixed in 16f0f81d16.
🤖
| return { user: userEvent.setup(), signIn }; | ||
| }; | ||
|
|
||
| it("opens a result's tab from its row once", async () => { |
There was a problem hiding this comment.
Nit [CRF-20] The test name "opens a result's tab from its row once" does not say that the test clicks twice. (Leorio)
For example: "clicking Open preview twice opens one tab and focuses it".
🤖
There was a problem hiding this comment.
Declined: naming preference.
There was a problem hiding this comment.
Declined: the test name says the result opens its tab once, which is the asserted behavior, and the body's two clicks are the setup; the suggested name describes the same assertion in more words.
There was a problem hiding this comment.
The defense holds: the name states the asserted behavior. Closed.
🤖
de09426 to
0fce80c
Compare
0fce80c to
9f8de93
Compare
9f8de93 to
185a913
Compare
185a913 to
c3d1145
Compare
b0e29c9 to
0d418bd
Compare
There was a problem hiding this comment.
The new push changes code for 14 of the 20 round 1 findings. The panel will check those changes in the next round. Six findings have no code change and no reply, so the review is paused until each one gets a response: a fix in this PR, a linked GitHub issue, or a reply on its thread explaining why it should not change.
site/src/pages/AgentsPage/utils/rightPanelTabs.ts:165(P3): after an agent restart, restored file preview tabs and earlier file preview buttons open a 404 inside the frame, with nothing telling the user to open the preview again.site/src/pages/AgentsPage/utils/rightPanelTabs.ts:169(P4):getMatchingAgentOrFirstis used where only a lookup by name can happen, here and inUserTabPanel.tsx.site/src/pages/AgentsPage/components/RightPanel/PreviewPanel.tsx:13(P4):PreviewPanelalso shows port previews next toPortPreviewPanel, and only the doc comment tells the two apart.site/src/pages/AgentsPage/components/ChatElements/tools/OpenPreviewTool.tsx:16(Nit): the title limit80is a bare copy ofmaxPreviewTitleLength.site/src/pages/AgentsPage/utils/rightPanelTabs.ts:74(Nit): the tab fieldslugrenames the API'spreview_slug.site/src/pages/AgentsPage/AgentChatPage/AgentChatPage.test.tsx(Nit): the test name "opens a result's tab from its row once" does not say that it clicks twice.
🤖 This review was automatically generated with Coder Agents.
|
/coder-agents-review |
There was a problem hiding this comment.
Three of the six findings paused in the last review now have a response the panel can evaluate: the agent-restart 404 (fixed in d156c13, #32438), the getMatchingAgentOrFirst lookup, and the bare title limit. Three still block the review, because each got the same reply, "Declined: naming preference.", which gives no reason specific to that finding:
site/src/pages/AgentsPage/components/RightPanel/PreviewPanel.tsx:13(P4):PreviewPanelalso shows port previews next toPortPreviewPanel, so a reader looking for how port previews render finds the wrong panel.site/src/pages/AgentsPage/utils/rightPanelTabs.ts:74(Nit): the tab fieldslugrenames the API'spreview_slug, and the module also stores workspace app tabs.site/src/pages/AgentsPage/AgentChatPage/AgentChatPage.test.tsx(Nit): the test name "opens a result's tab from its row once" does not say that it clicks twice.
To unblock, reply on each thread with one sentence on why the current name is better for that case, rename it, or link an issue.
The sign-in rewrite pushed in 16f0f81 (sign-in on request from the preview frame) has not been reviewed by the panel yet. The lack of findings on it is not an approval.
🤖 This review was automatically generated with Coder Agents.
|
/coder-agents-review |
There was a problem hiding this comment.
This round reviews 16f0f81, which moves preview sign-in to run only when the preview host reports no session. New findings: 4 P3, 6 P4, 4 Nit.
Twelve earlier findings are verified fixed, and the disputes on the agent lookup, the panel name, the slug field and the test name are closed; each thread has a reply. Three are re-raised on their threads: rows that give no reason when previews are unavailable, the title limit literal, and three unchanged doc comments.
The commit message of 16f0f81 still says saved preview tabs are dropped; the PR description was corrected.
Out of scope (needs a ticket or explicit acceptance by a human):
coderd/previews.go:44: the address endpoint takes and returnsPreviewSignInRequestandPreviewSignInResponsealthough it does not sign in, sogetPreviewAddressreads as a sign-in call.coderd/workspaceapps/preview.go:163: inside the Agents panel, the signed-out page tells the user to reopen the preview from Coder, and its Back to site action is blocked by the wrapper'sframe-src, so the page offers no action that works.coderd/workspaceapps/preview.go:172: the signed-out page posts towindow.topwith theAccessURLorigin, so sign-in never starts when the dashboard is framed or reached through another hostname.coderd/workspaceapps/preview.go: the preview session cookie uses the defaultSameSite, so when the preview host is cross-site with the dashboard the browser does not send it inside the frame and the preview never stays signed in (the #32522 review reproduced this in Chromium).
Notes:
- "opens a result's tab from its row once" and "renames an open preview's tab and reloads it for a newer result" took 5.5 to 5.7 s on a cold Vitest cache against the 5 s default timeout; warm runs took about 1 s.
- When the selected proxy changes, including the automatic latency-based switch on a first page load, an open preview reloads from the new region and loses its page state.
🤖 This review was automatically generated with Coder Agents.
| activateRightPanelTab(tab.id); | ||
| }; | ||
|
|
||
| const previewAccess = |
There was a problem hiding this comment.
P3 [CRF-41] previewAccess offers Open preview in the embedded chat (/agents/:agentId/embed, used by the VS Code extension), where the preview frame can neither load nor sign in. (Melody, Pariston)
The preview CSP is frame-ancestors 'self' <dashboardOrigin> (previewhost.go:120), which every ancestor must match, and the signed-out page posts to window.top (preview.go:172), which is the webview host when the dashboard is framed; so the browser blocks the frame and drops the sign-in message. This follows from the CSP and postMessage rules and was not run in a VS Code webview. isEmbedded (line 249) is not part of previewAccess: when it is true, set an unavailableReason such as "Previews open only in the Coder dashboard."
🤖
There was a problem hiding this comment.
Declined: you are right that the preview CSP lists only the dashboard as a frame ancestor, so a preview opened from the VS Code embed is unlikely to load there, but previews in this experiment target the dashboard and we did not reproduce the embedded case, so the embedded chat is left unchanged in this PR.
There was a problem hiding this comment.
Re-raised with a reproduction. A Playwright Chromium page with three origins (embedder, dashboard, preview host), this PR's wrapper markup, the server's sandbox and the preview CSP from previewhost.go:118-120 rendered the preview and received the sign-in message with the dashboard at the top level, but with the dashboard framed the browser refused the preview response (frame-ancestors) and no message reached the dashboard. In the VS Code extension, Open preview therefore opens the right panel on a blocked frame with no reason, and Reload and reopening repeat it. When useEmbedContext().isEmbedded is true, set previewAccess to { unavailableReason: "Previews open only in the Coder dashboard." }. (Pariston)
🤖
There was a problem hiding this comment.
Declined: thanks for the reproduction. It runs a copy of the markup and CSP on static pages rather than Coder itself, and we already decided not to change the embedded chat in this PR, so we are leaving it as is.
There was a problem hiding this comment.
Not re-raised: there is no new evidence. The R6 reply does not answer the reproduction, which used the server's CSP and sandbox strings and this PR's wrapper markup, and the button this diff adds is shown in the embedded route. With no fix and no ticket, this needs a human decision: file a ticket or accept it explicitly. (Pariston)
🤖
There was a problem hiding this comment.
Confirmed for the experimental release (operator decision, no ticket): previews target the dashboard, and we accept that the embedded chat shows a button whose preview does not load there.
There was a problem hiding this comment.
Recorded as an operator decision for the experimental release.
🤖
| variant="subtle" | ||
| className="ml-auto" | ||
| aria-label="Reload preview" | ||
| onClick={() => setReloadCount((count) => count + 1)} |
There was a problem hiding this comment.
P3 [CRF-42] After the address request fails, Reload preview does nothing. (Nami, Mafuuu)
The button only bumps reloadCount, the key of SignInOnRequestFrame, which is not rendered in the addressQuery.error branch, and the app QueryClient sets retry: false (App.tsx:19). A scratch test where getPreviewAddress rejects once and then resolves left one address call and no frame after clicking Reload. Call addressQuery.refetch() from the button when the address query has failed, and add that case to PreviewFrame.test.tsx.
🤖
There was a problem hiding this comment.
Fixed in 4ac23c2: Reload now refetches a failed address request, with a PreviewFrame test that fails without the refetch.
There was a problem hiding this comment.
Verified fixed in 4ac23c2859; the new test fails without the refetch.
🤖
| event.data !== previewSignInNeeded || | ||
| event.origin !== address.origin || | ||
| event.source !== frameRef.current?.contentWindow?.frames[0] || | ||
| signInRequested.current |
There was a problem hiding this comment.
P3 [CRF-43] When the preview host still reports no session after the one sign-in a mount allows, the second coder-preview-sign-in-needed message is dropped and the panel shows the host's 401 page, which says "Reopen this preview from Coder to sign in again." (Leorio)
That happens when the browser does not keep the preview host's cookie after the sign-in redirect, for example when the preview host is cross-site with the dashboard; Reload then signs in again, mints another key, and lands on the same page. The once-per-mount guard is right, but the user is not told what failed. On a sign-in-needed message after this mount already signed in, show an error in the panel that says the preview host did not keep the sign-in and the browser may be blocking its cookies.
🤖
There was a problem hiding this comment.
There was a problem hiding this comment.
Verified in 5421940: a cross-site wildcard is refused on the address request with a message that names the fix.
🤖
There was a problem hiding this comment.
The defense holds: an HTTP deployment with Secure cookies cannot sign in to the dashboard either, cross-site regions are refused before the frame loads, and an expired session recovers through Reload. Closed. (Chopper)
🤖
| preview && | ||
| previewAccess && | ||
| (preview.workspaceId !== workspaceId || preview.agentName !== agentName) | ||
| ? { unavailableReason: "This preview belongs to a different workspace." } |
There was a problem hiding this comment.
P4 [CRF-40] A result whose agent_name differs from the chat's agent shows "This preview belongs to a different workspace." even when workspace_id matches. (Netero)
Both conditions share one message, and "offers no preview of another workspace or agent to the owner" asserts that text for the agent_name: "other-agent" row. Give the agent mismatch its own reason, for example "This preview belongs to a different agent in this workspace."
🤖
There was a problem hiding this comment.
Declined: the tool takes the agent name from the chat's own workspace agent, so a mismatch inside the same workspace needs a rebuild that renames the agent, and one reason for both cases keeps the row short.
There was a problem hiding this comment.
The defense holds: the tool takes the agent name from the chat's own agent, so this needs a rebuild that renames it. Closed.
🤖
| </div> | ||
| {address ? ( | ||
| <SignInOnRequestFrame | ||
| key={reloadCount} |
There was a problem hiding this comment.
P4 [CRF-45] SignInOnRequestFrame is keyed only on reloadCount, so after a region switch to an address that is still cached, it keeps framing the previous region's sign-in URL. (Knov)
frame = signInMutation.data ?? address prefers the sign-in response for the address it mounted with, while handleMessage compares against the current address.origin. A scratch test with the app's query client settings (region A, switch to B, sign in, switch back to A) left the inner frame on B's URL. Key the component on the address too, for example key={`${reloadCount}:${address.url}`}.
🤖
There was a problem hiding this comment.
Declined: this reproduces at the component level, but the Agents page has no region control and the latency auto-select runs once, so the region can only switch back to a cached one within a mount through a proxy health change, and we are leaving the key as is.
There was a problem hiding this comment.
The panel accepts this: the Agents page renders no ProxyMenu, and the regions query does not refetch during a mount, so the switch back needs no user action to avoid. A human should confirm the acceptance or file a ticket.
🤖
There was a problem hiding this comment.
Confirmed for the experimental release (operator decision, no ticket): the Agents page has no region menu and the regions query does not refetch during a mount, so we are not keying the frame on the address.
There was a problem hiding this comment.
Recorded as an operator decision for the experimental release.
🤖
| !isPreviewTitle(rec.title) || | ||
| typeof rec.workspace_id !== "string" || | ||
| typeof rec.agent_name !== "string" || | ||
| // Sign-in checks the slug and URL path in full, so the parser checks |
There was a problem hiding this comment.
P4 [CRF-49] The comment names sign-in as the check on the slug and URL path, but the request that runs on every mount is the address request, and sign-in may never run. (Gon)
Both handlers validate through resolvePreview (coderd/previews.go), so the removal is safe, but a reader of this comment could conclude that a browser with a live preview session skips the check. For example: "coderd checks the slug and URL path in full on every address and sign-in request, so the parser checks only their shape."
🤖
There was a problem hiding this comment.
Fixed in 4ac23c2: the comment now names every check the slug and path go through.
There was a problem hiding this comment.
Verified fixed in 4ac23c2859: both endpoints go through resolvePreview.
🤖
| // Opening the same result again reloads it too. | ||
| await page.user.click(newerButton); | ||
| await waitFor(() => expect(newerFrame).not.toBeInTheDocument()); | ||
| expect(previewFrame("Docs v2")).toBeInTheDocument(); |
There was a problem hiding this comment.
Nit [CRF-50] expect(previewFrame("Docs v2")).toBeInTheDocument() is a presence assertion, which FE1 (.claude/docs/FRONTEND_PATTERNS.md) rules out in Vitest, and getByTitle already throws when the frame is missing. (Bisky)
Call previewFrame(...) without expect here and at line 994.
🤖
There was a problem hiding this comment.
Fixed in 4ac23c2: the presence assertion now compares frames instead of only checking one exists.
There was a problem hiding this comment.
Verified fixed in 4ac23c2859.
🤖
| expect(newerFrame).not.toBe(firstFrame); | ||
| expect(firstFrame).not.toBeInTheDocument(); | ||
|
|
||
| // Opening the same result again reloads it too. |
There was a problem hiding this comment.
Nit [CRF-51] // Opening the same result again reloads it too. repeats the next two lines. (Gon)
Delete it.
🤖
There was a problem hiding this comment.
Declined: the comment marks where the test moves from the newer result to reopening the same one, which the click alone does not say.
There was a problem hiding this comment.
The defense holds: the comment marks the switch to reopening the same result. Closed.
🤖
| agent: WorkspaceAgent; | ||
| tab: Extract<UserRightPanelTab, { kind: "preview" }>; | ||
| /** Changing it loads the preview again. */ | ||
| reloadCount: number; |
There was a problem hiding this comment.
Nit [CRF-52] reloadCount here counts how often the chat reopened the tab, while reloadCount in PreviewFrame.tsx counts Reload clicks, and both are used as a React key one component apart. (Gon)
Rename the chat-level chain to reopenCount (previewReopenCounts, previewReopenCount).
🤖
There was a problem hiding this comment.
Declined: both counters are React keys that reload the preview when they change, so one name fits both, and the prop doc states what changing it does.
There was a problem hiding this comment.
The defense holds: both counters are only React keys, and no code reads either as a number. Closed.
🤖
| if (signInMutation.isPending) { | ||
| return <PreviewLoading />; | ||
| } | ||
| const frame = signInMutation.data ?? address; |
There was a problem hiding this comment.
Nit [CRF-53] frame holds a PreviewSignInResponse, while frameRef holds the iframe element. (Gon)
Give the response another name, for example target.
🤖
There was a problem hiding this comment.
Declined: frame is the target the iframe loads (its URL, origin and sandbox) and is used only in the next three lines, so the name describes how it is used.
There was a problem hiding this comment.
The defense holds: frame is used only in three attributes of one element. Closed.
🤖
16f0f81 to
4ac23c2
Compare
|
/coder-agents-review |
There was a problem hiding this comment.
This round reviews 4ac23c2, which makes Reload retry a failed address request, adds tests for both failure paths, and rewords two comments. New findings: 1 P4.
Seven round 4 findings are verified fixed, and seven disputes are closed (replies on each thread). Two findings are re-raised on their threads: the embedded VS Code chat still offers a preview that cannot load, which now reproduces in Chromium, and the title limit copy still does not name the Go constant.
Two gaps are accepted in replies without a ticket: rows of a stopped workspace show no reason, and a region switch back to a cached region keeps the old region's frame. The panel agrees with both. A human should confirm that acceptance or file a ticket.
🤖 This review was automatically generated with Coder Agents.
| event.data !== previewSignInNeeded || | ||
| event.origin !== address.origin || | ||
| event.source !== frameRef.current?.contentWindow?.frames[0] || | ||
| signInRequested.current |
There was a problem hiding this comment.
P4 [CRF-66] A coder-preview-sign-in-needed message that arrives after this mount's sign-in succeeded is dropped without telling the user, so the panel stays on the host's 401 page, whose "Reopen this preview from Coder" text sends the user into the same failure. (Chopper)
The cross-site cause is now refused before any frame loads, but any other case where the preview host does not keep the session ends the same way, and each Reload mints another key. PreviewFrame.test.tsx:160-163 ("the signed-in frame asking again changes nothing") checks only that no second call is made. Keep the one sign-in per mount, and when the message arrives after signInMutation.isSuccess, show an error in the panel that says the preview host did not keep the sign-in, with that test expecting the error.
🤖
There was a problem hiding this comment.
Declined: signing in once per mount is deliberate, since script in the preview can post the same message, and the only known way a host loses the new session, a cross-site region, is now refused before the frame loads. For an expired session the host page's advice to reopen is right, because Reload remounts the frame and signs in again.
4ac23c2 to
79c6491
Compare
|
/coder-agents-review |
There was a problem hiding this comment.
This head is a rebase of 4ac23c2 with the same PR diff. New findings: 1 P4.
The title limit and second sign-in message disputes are closed. The operator decisions on stopped-workspace rows and the region-switch frame are recorded.
The embedded VS Code chat still offers Open preview on a frame the browser refuses, with no fix and no ticket. The reviewers have no new evidence and do not re-raise it, so this needs a human decision: file a ticket or accept the gap explicitly, as was done for the two items above.
Notes:
- The rule for which tabs count as the same preview (
agentName,slug,urlPath,AgentChatPageView.tsx:577) is inline in the view, so only the slow page-level tests cover it; a helper next tovalidateUserRightPanelTabscould be tested inrightPanelTabs.test.ts.
🤖 This review was automatically generated with Coder Agents.
| activateRightPanelTab(tab.id); | ||
| }; | ||
|
|
||
| const previewAccess = |
There was a problem hiding this comment.
P4 [CRF-67] previewAccess.open accepts a preview from any workspace or agent, and only OpenPreviewTool keeps foreign previews out, by repeating the match check against a context field (agentName) that exists for that one check. (Meruem)
openPreviewTab appends and selects the tab without checking workspaceId or agentName, while validateUserRightPanelTabs drops a tab that fails either, so a second caller that skips the check persists a hidden tab and selects an ID the tab list omits; each further click adds another, because the lookup searches only validated tabs (inferred from the code, not run). The Desktop action at line 435 already avoids this by offering the action only when the panel can render. Make previewAccess a function of the preview, built in the view, that checks ownership, workspace and agent in one place, and remove agentName from ChatWorkspaceContextValue.
🤖
There was a problem hiding this comment.
Declined: you are right that the match check lives in the tool row rather than in previewAccess, so a future caller could skip it. Today the tool row is the only caller and it checks workspace and agent before opening, so we are keeping the check where the reason text is shown.
There was a problem hiding this comment.
Accepted: today OpenPreviewTool is the only reader of previewAccess outside tests and stories, and it replaces open with the reason before any click. With no ticket, please confirm this as an operator decision. (Meruem)
🤖
There was a problem hiding this comment.
Confirmed for the experimental release (operator decision, no ticket): the workspace and agent match check stays in OpenPreviewTool, the only reader of previewAccess.
79c6491 to
9db4ea5
Compare
|
/coder-agents-review |
There was a problem hiding this comment.
This head is a rebase of 79c6491 with the same PR diff; the base change since then is comment-only in coderd/previews.go. No new findings.
The embedded VS Code chat gap is recorded as an operator decision. The reviewers accept keeping the workspace and agent match check in the tool row, because that row is the only caller today. That leaves a hazard for any future caller of previewAccess.open and has no ticket, so please confirm it as an operator decision on its thread, as was done for the other accepted gaps.
Every other in-scope finding is fixed or closed.
🤖 This review was automatically generated with Coder Agents.
9db4ea5 to
c626616
Compare
|
/coder-agents-review |
There was a problem hiding this comment.
This head is a rebase of 9db4ea5 with the same PR diff; the base change since then is comment-only. No new findings, and every finding from earlier rounds is fixed, closed, or accepted as an operator decision for the experimental release.
The out-of-scope server items listed in earlier reviews (sign-in types reused by the address endpoint, the signed-out page's action and window.top target, key lifetime, the tool reporting success for workspaces the owner does not hold) are not part of this PR and still need tickets or explicit acceptance.
🤖 This review was automatically generated with Coder Agents.
c626616 to
71bab52
Compare
|
/coder-agents-review |
There was a problem hiding this comment.
This head is a rebase of c626616 with the same PR diff. The base change since then is tests and coderd/x/chatd/ARCHITECTURE.md. No new findings. The approval from the previous review still applies, so this review is a comment rather than a second approval.
The base now returns an error from open_preview for a workspace the chat owner does not own, so that out-of-scope item from earlier reviews is resolved. The other out-of-scope server items (sign-in types reused by the address endpoint, the signed-out page's action and window.top target, key lifetime) are not part of this PR and still need tickets or explicit acceptance.
🤖 This review was automatically generated with Coder Agents.
Renders open_preview results in the Agents chat with an Open preview button. The preview tab loads the preview's address in a srcdoc wrapper frame whose CSP allows only that preview's origin. When the preview's signed-out page posts coder-preview-sign-in-needed, the tab signs in through the dashboard endpoint, at most once per mount, and loads the returned URL. With the experiment off, the button is hidden and saved preview tabs are dropped. Co-Authored-By: Claude Opus 5.5 <[email protected]>
71bab52 to
b1c1ead
Compare
|
/coder-agents-review |
There was a problem hiding this comment.
This head is a rebase of 71bab52 with the same PR diff. No new findings. The earlier approval still applies, so this review is a comment rather than another approval.
The base now reads the workspace proxy in previewHostingFor with the caller's context instead of AsSystemRestricted. That does not change what this UI receives: the member role grants site-wide read on workspace proxies, and the dashboard session has no narrower scope. Only a token scoped without workspace_proxy:read now gets the 400 "This region does not serve previews.", which PreviewFrame already shows in its error alert with Reload.
The out-of-scope server items from earlier reviews (sign-in types reused by the address endpoint, the signed-out page's action and window.top target, key lifetime) are not part of this PR and still need tickets or explicit acceptance.
🤖 This review was automatically generated with Coder Agents.
Renders
open_previewresults in the Agents chat. For the workspace owner, the result has an Open preview button. Anyone else sees why they can't open it: only the workspace owner can, or the preview belongs to a different workspace. Nothing opens until the owner clicks.The preview tab asks coderd for the preview's address and loads it inside a
srcdocwrapper frame whose CSP allows only that preview's origin, with the sandbox the server returns. The UI never builds a preview hostname. If the preview host has no session, it tells the dashboard, which signs in once and reloads the frame, so reopening or reloading a preview does not create a new API key. Opening a newer result for the same preview renames its tab and reloads it. Previews open only in the chat's right panel; opening a preview address directly shows an error page (#32439).Results are parsed by shape, the title rule is checked again because the user decides by title, and the server enforces the slug and
url_pathrules. With the experiment disabled, the button is hidden and saved preview tabs are hidden until it is enabled again.A manual pass in Safari 27.2 on macOS against an HTTPS deployment passed on an earlier version of this PR, before sign-in moved to on demand: file and port previews signed in and loaded inside the wrapper, every preview response carried the CSP, and the test page's fetch to the dashboard, top navigation and popup were all blocked. The on-demand sign-in was checked in Chromium and Firefox.
Stack (review bottom-up). Replaces the closed #31282 stack. Security review: coder/security-assessments#437.
🤖 Generated with Claude Code