From 8410e3e42abcb018f74f8bc3253100a7f3f20f53 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Wed, 4 Nov 2026 03:01:59 +0000 Subject: [PATCH 1/4] test(web): reproduce #30577 large pastes with a thread link skip folding A large plain-text paste that contains one thread URL goes inline instead of folding into pasted-text.txt, both when pasted into the composer and when a window paste is routed to the blurred composer. These tests reproduce it. The fake environment now advertises file attachment uploads like a real server does, so the composer can stage a folded paste in browser tests. --- .../src/components/ChatView.browser.test.tsx | 67 +++++++++++++++++++ apps/web/test/fakeEnvironment.ts | 6 +- 2 files changed, 72 insertions(+), 1 deletion(-) diff --git a/apps/web/src/components/ChatView.browser.test.tsx b/apps/web/src/components/ChatView.browser.test.tsx index 96eb837db4d6..6e4f968f9384 100644 --- a/apps/web/src/components/ChatView.browser.test.tsx +++ b/apps/web/src/components/ChatView.browser.test.tsx @@ -1,5 +1,6 @@ import { createMemoryHistory } from "@tanstack/react-router"; import { scopeProjectRef } from "@t3tools/client-runtime/environment"; +import { PASTED_TEXT_ATTACHMENT_THRESHOLD_BYTES } from "@t3tools/client-runtime/text-paste"; import { ThreadId } from "@t3tools/contracts"; import { DEFAULT_CLIENT_SETTINGS } from "@t3tools/contracts/settings"; import type * as Context from "effect/Context"; @@ -65,3 +66,69 @@ it("a new draft does not load its reserved thread before the server lists it", a // A 404 here marks the thread deleted, and the view never loads it once the send creates it. expect(threadRequests).toEqual([]); }); + +const LARGE_LOG_WITH_THREAD_LINK = [ + ...Array.from({ length: 400 }, (_, line) => `2026-11-03T12:00:00Z worker[${line}] retrying job`), + `see https://app.t3.codes/threads/${ENVIRONMENT_ID}/thread-abc for context`, + ...Array.from({ length: 400 }, (_, line) => `2026-11-03T12:00:01Z worker[${line}] job failed`), +].join("\n"); + +async function mountDraftComposer(draftId: DraftId) { + await using stack = new AsyncDisposableStack(); + stack.use(installFakeEnvironment([])); + __setClientSettingsForTests({ + ...DEFAULT_CLIENT_SETTINGS, + onboardingCompletedAt: "2026-01-01T00:00:00.000Z", + }); + useComposerDraftStore + .getState() + .setProjectDraftThreadId(scopeProjectRef(ENVIRONMENT_ID, PROJECT_ID), draftId, { + threadId: ThreadId.make(`thread-${draftId}`), + }); + const router = getRouter(createMemoryHistory({ initialEntries: [`/draft/${draftId}`] })); + await router.load(); + // AppRoot brings its own router. + stack.use(await render(, { router: false })); + await expect.element(page.getByTestId("composer-editor")).toBeVisible(); + await expect.element(page.getByText("render", { exact: true }).first()).toBeVisible(); + return stack.move(); +} + +function pastePlainText(target: EventTarget, text: string) { + const clipboardData = new DataTransfer(); + clipboardData.setData("text/plain", text); + target.dispatchEvent( + new ClipboardEvent("paste", { clipboardData, bubbles: true, cancelable: true }), + ); +} + +async function expectPasteFolded(editor: HTMLElement) { + const attachment = page.getByText("pasted-text.txt"); + // The paste lands either inline in the editor or as an attachment chip. + await vi.waitFor(() => expect(editor.textContent || attachment.query()).toBeTruthy()); + expect(editor.textContent, "the large paste went inline instead of folding").not.toContain( + "worker[399] retrying job", + ); + await expect.element(attachment).toBeVisible(); +} + +it("folds a large composer paste that mentions a thread link into a pasted-text attachment", async () => { + expect(LARGE_LOG_WITH_THREAD_LINK.length).toBeGreaterThan(PASTED_TEXT_ATTACHMENT_THRESHOLD_BYTES); + await using _app = await mountDraftComposer(DraftId.make("draft-30577-composer")); + const editor = page.getByTestId("composer-editor").element() as HTMLElement; + editor.focus(); + + pastePlainText(editor, LARGE_LOG_WITH_THREAD_LINK); + + await expectPasteFolded(editor); +}); + +it("folds a large window paste that mentions a thread link into a pasted-text attachment", async () => { + await using _app = await mountDraftComposer(DraftId.make("draft-30577-window")); + const editor = page.getByTestId("composer-editor").element() as HTMLElement; + editor.blur(); + + pastePlainText(document.body, LARGE_LOG_WITH_THREAD_LINK); + + await expectPasteFolded(editor); +}); diff --git a/apps/web/test/fakeEnvironment.ts b/apps/web/test/fakeEnvironment.ts index 44cd45d127e1..74fb95c0a249 100644 --- a/apps/web/test/fakeEnvironment.ts +++ b/apps/web/test/fakeEnvironment.ts @@ -9,6 +9,7 @@ import { MessageId, ORCHESTRATION_PROTOCOL_VERSION, ORCHESTRATION_V2_WS_METHODS, + PROVIDER_SEND_TURN_MAX_FILE_BYTES, ProjectId, ProviderInstanceId, RunId, @@ -58,7 +59,10 @@ const descriptor = { // A matching version, since a mismatch adds an update banner a typical user never sees. serverVersion: APP_VERSION, orchestrationProtocolVersion: ORCHESTRATION_PROTOCOL_VERSION, - capabilities: { repositoryIdentity: true }, + capabilities: { + repositoryIdentity: true, + fileAttachments: { maxUploadBytes: PROVIDER_SEND_TURN_MAX_FILE_BYTES }, + }, }; const auth = { policy: "loopback-browser", From cdce8a3649d64d40715e1edd05f703e5a5bb9e95 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Wed, 4 Nov 2026 03:06:22 +0000 Subject: [PATCH 2/4] fix(web): large pastes with a thread link fold into an attachment again A large plain-text paste that only mentioned a thread URL stayed inline, because both paste paths skipped folding whenever the clipboard yielded context records, and plain thread links now synthesize records too. Folding is now skipped only when the paste references context copied from T3 (the composer clipboard format or its HTML fragment), so copied chips still import while plain links in a large paste fold like any other text. AI-assisted; verified with the tests and tools listed above. --- apps/web/src/components/chat/ChatComposer.tsx | 4 ++-- .../chat/usePasteToFocusComposer.ts | 4 ++-- .../composerInlineTokenPaste.test.ts | 21 +++++++++++++++++- .../components/composerInlineTokenPaste.ts | 22 +++++++++++++++---- 4 files changed, 42 insertions(+), 9 deletions(-) diff --git a/apps/web/src/components/chat/ChatComposer.tsx b/apps/web/src/components/chat/ChatComposer.tsx index 25b7f5ce6f87..d26bcb4af279 100644 --- a/apps/web/src/components/chat/ChatComposer.tsx +++ b/apps/web/src/components/chat/ChatComposer.tsx @@ -10,7 +10,7 @@ import { import { isLocalEnvironmentDisabled } from "../../localEnvironment"; import { usePrimaryEnvironmentId } from "../../state/environments"; import { useRightPanelStore } from "~/rightPanelStore"; -import { importPastedComposerText, readPastedComposerContext } from "../composerInlineTokenPaste"; +import { importPastedComposerText, pastesCopiedComposerContext } from "../composerInlineTokenPaste"; import { questionAttachmentDraftId, trackOpenQuestionAttachmentDraft, @@ -2573,7 +2573,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps) return; } - if ((readPastedComposerContext(event.clipboardData)?.records.length ?? 0) > 0) return; + if (pastesCopiedComposerContext(event.clipboardData)) return; if (!foldPastedText(plainText, bypassAutoAttachment)) { return; } diff --git a/apps/web/src/components/chat/usePasteToFocusComposer.ts b/apps/web/src/components/chat/usePasteToFocusComposer.ts index 84672cc570c5..c616aa085a89 100644 --- a/apps/web/src/components/chat/usePasteToFocusComposer.ts +++ b/apps/web/src/components/chat/usePasteToFocusComposer.ts @@ -1,5 +1,5 @@ import { pasteTextToFocusComposer, shouldRedirectInputToComposer } from "./composerFocusRedirect"; -import { readPastedComposerContext } from "../composerInlineTokenPaste"; +import { pastesCopiedComposerContext } from "../composerInlineTokenPaste"; import { isPasteAsTextShortcut } from "@t3tools/client-runtime/text-paste"; import { useEffect, useRef } from "react"; import { isMacPlatform } from "../../lib/utils"; @@ -38,7 +38,7 @@ export function usePasteToFocusComposer( const bypassAutoAttachment = Date.now() <= pasteAsTextShortcutUntilRef.current; pasteAsTextShortcutUntilRef.current = 0; if ( - ((readPastedComposerContext(clipboardData)?.records.length ?? 0) === 0 && + (!pastesCopiedComposerContext(clipboardData) && composerRef.current?.pasteTextAtEnd(text, { bypassAutoAttachment })) || composerRef.current?.insertTextAtEnd(text, { clipboardData }) ) { diff --git a/apps/web/src/components/composerInlineTokenPaste.test.ts b/apps/web/src/components/composerInlineTokenPaste.test.ts index 1ab28a5b7ff5..7a2fa63f823e 100644 --- a/apps/web/src/components/composerInlineTokenPaste.test.ts +++ b/apps/web/src/components/composerInlineTokenPaste.test.ts @@ -7,7 +7,7 @@ import { import { threadContextRecord } from "@t3tools/shared/composerContextReferences"; import { describe, expect, it } from "vite-plus/test"; -import { importPastedComposerText } from "./composerInlineTokenPaste"; +import { importPastedComposerText, pastesCopiedComposerContext } from "./composerInlineTokenPaste"; const thread = { environmentId: EnvironmentId.make("env-1"), @@ -57,3 +57,22 @@ describe("importPastedComposerText", () => { ); }); }); + +describe("pastesCopiedComposerContext", () => { + it("counts a copied chip but not a bare thread link", () => { + const target = threadChipCopyTarget(thread, "Fix the login flow"); + expect( + pastesCopiedComposerContext( + clipboard({ + "text/plain": `See ${target.value}`, + [COMPOSER_CONTEXT_CLIPBOARD_MIME]: encodeComposerContextFragment(target.fragment!)!, + }), + ), + ).toBe(true); + expect( + pastesCopiedComposerContext( + clipboard({ "text/plain": "See https://app.t3.codes/threads/env-1/thread-1" }), + ), + ).toBe(false); + }); +}); diff --git a/apps/web/src/components/composerInlineTokenPaste.ts b/apps/web/src/components/composerInlineTokenPaste.ts index 0862f81ee835..aa4b52381865 100644 --- a/apps/web/src/components/composerInlineTokenPaste.ts +++ b/apps/web/src/components/composerInlineTokenPaste.ts @@ -20,14 +20,16 @@ import { readThreadShell } from "~/state/entities"; const threadTitle = (ref: ScopedThreadRef) => readThreadShell(ref)?.title; +const readCopiedComposerContext = (clipboardData: Pick) => + decodeComposerContextFragment(clipboardData.getData(COMPOSER_CONTEXT_CLIPBOARD_MIME)) ?? + decodeComposerContextClipboardHtml(clipboardData.getData("text/html")); + /** Pasted thread links count as context too, so they become chips like a copied chip does. */ -export function readPastedComposerContext( +function readPastedComposerContext( clipboardData: Pick, + decodedFragment = readCopiedComposerContext(clipboardData), ): ComposerContextClipboardFragment | null { const pastedText = clipboardData.getData("text/plain"); - const decodedFragment = - decodeComposerContextFragment(clipboardData.getData(COMPOSER_CONTEXT_CLIPBOARD_MIME)) ?? - decodeComposerContextClipboardHtml(clipboardData.getData("text/html")); const threads = threadLinkContextReferences( pastedText, decodedFragment?.records ?? [], @@ -59,6 +61,18 @@ export function readPastedComposerContext( }; } +/** Whether the paste references context copied from T3, which folding it into a file would drop. */ +export function pastesCopiedComposerContext(clipboardData: Pick): boolean { + const copied = readCopiedComposerContext(clipboardData); + if (copied === null) return false; + const copiedIds = new Set(copied.records.map((record) => record.contextId)); + return ( + readPastedComposerContext(clipboardData, copied)?.records.some((record) => + copiedIds.has(record.contextId), + ) ?? false + ); +} + export function importPastedComposerText( clipboardData: Pick, importContextFragment?: ( From fb3f55de7e8f85b829afefdc987eec66feff0c5d Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Wed, 4 Nov 2026 03:16:37 +0000 Subject: [PATCH 3/4] test(web): an unreferenced copied fragment does not keep a paste inline --- .../src/components/composerInlineTokenPaste.test.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/apps/web/src/components/composerInlineTokenPaste.test.ts b/apps/web/src/components/composerInlineTokenPaste.test.ts index 7a2fa63f823e..db5b4460341d 100644 --- a/apps/web/src/components/composerInlineTokenPaste.test.ts +++ b/apps/web/src/components/composerInlineTokenPaste.test.ts @@ -75,4 +75,16 @@ describe("pastesCopiedComposerContext", () => { ), ).toBe(false); }); + + it("ignores a copied fragment the pasted text does not reference", () => { + const target = threadChipCopyTarget(thread, "Fix the login flow"); + expect( + pastesCopiedComposerContext( + clipboard({ + "text/plain": "See https://app.t3.codes/threads/env-1/thread-2", + [COMPOSER_CONTEXT_CLIPBOARD_MIME]: encodeComposerContextFragment(target.fragment!)!, + }), + ), + ).toBe(false); + }); }); From 62df10440121216108b69aa9ef5955f35b5001c0 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Tue, 10 Nov 2026 23:25:43 +0000 Subject: [PATCH 4/4] test(web): keep one browser case for large pastes with a thread link Co-Authored-By: Claude Opus 5.5 --- .../src/components/ChatView.browser.test.tsx | 71 +++++++------------ 1 file changed, 24 insertions(+), 47 deletions(-) diff --git a/apps/web/src/components/ChatView.browser.test.tsx b/apps/web/src/components/ChatView.browser.test.tsx index 7a1a7b680d83..f4d04196ef73 100644 --- a/apps/web/src/components/ChatView.browser.test.tsx +++ b/apps/web/src/components/ChatView.browser.test.tsx @@ -93,68 +93,45 @@ it("opens the thread actions menu for an older settled thread the shell leaves o .toBeVisible(); }); -const LARGE_LOG_WITH_THREAD_LINK = [ - ...Array.from({ length: 400 }, (_, line) => `2026-11-03T12:00:00Z worker[${line}] retrying job`), - `see https://app.t3.codes/threads/${ENVIRONMENT_ID}/thread-abc for context`, - ...Array.from({ length: 400 }, (_, line) => `2026-11-03T12:00:01Z worker[${line}] job failed`), -].join("\n"); - -async function mountDraftComposer(draftId: DraftId) { - await using stack = new AsyncDisposableStack(); - stack.use(installFakeEnvironment([])); +it("folds a large paste that mentions a thread link into a pasted-text attachment", async () => { + using _environment = installFakeEnvironment([]); __setClientSettingsForTests({ ...DEFAULT_CLIENT_SETTINGS, onboardingCompletedAt: "2026-01-01T00:00:00.000Z", }); + const draftId = DraftId.make("draft-30577"); useComposerDraftStore .getState() .setProjectDraftThreadId(scopeProjectRef(ENVIRONMENT_ID, PROJECT_ID), draftId, { - threadId: ThreadId.make(`thread-${draftId}`), + threadId: ThreadId.make("thread-30577"), }); + const log = [ + ...Array.from( + { length: 400 }, + (_, line) => `2026-11-03T12:00:00Z worker[${line}] retrying job`, + ), + `see https://app.t3.codes/threads/${ENVIRONMENT_ID}/thread-abc for context`, + ...Array.from({ length: 400 }, (_, line) => `2026-11-03T12:00:01Z worker[${line}] job failed`), + ].join("\n"); + expect(log.length).toBeGreaterThan(PASTED_TEXT_ATTACHMENT_THRESHOLD_BYTES); + const router = getRouter(createMemoryHistory({ initialEntries: [`/draft/${draftId}`] })); await router.load(); - // AppRoot brings its own router. - stack.use(await render(, { router: false })); + await using _app = await render(, { + // AppRoot brings its own router. + router: false, + }); await expect.element(page.getByTestId("composer-editor")).toBeVisible(); await expect.element(page.getByText("render", { exact: true }).first()).toBeVisible(); - return stack.move(); -} + const editor = page.getByTestId("composer-editor").element() as HTMLElement; + editor.focus(); -function pastePlainText(target: EventTarget, text: string) { const clipboardData = new DataTransfer(); - clipboardData.setData("text/plain", text); - target.dispatchEvent( + clipboardData.setData("text/plain", log); + editor.dispatchEvent( new ClipboardEvent("paste", { clipboardData, bubbles: true, cancelable: true }), ); -} - -async function expectPasteFolded(editor: HTMLElement) { - const attachment = page.getByText("pasted-text.txt"); - // The paste lands either inline in the editor or as an attachment chip. - await vi.waitFor(() => expect(editor.textContent || attachment.query()).toBeTruthy()); - expect(editor.textContent, "the large paste went inline instead of folding").not.toContain( - "worker[399] retrying job", - ); - await expect.element(attachment).toBeVisible(); -} - -it("folds a large composer paste that mentions a thread link into a pasted-text attachment", async () => { - expect(LARGE_LOG_WITH_THREAD_LINK.length).toBeGreaterThan(PASTED_TEXT_ATTACHMENT_THRESHOLD_BYTES); - await using _app = await mountDraftComposer(DraftId.make("draft-30577-composer")); - const editor = page.getByTestId("composer-editor").element() as HTMLElement; - editor.focus(); - - pastePlainText(editor, LARGE_LOG_WITH_THREAD_LINK); - - await expectPasteFolded(editor); -}); - -it("folds a large window paste that mentions a thread link into a pasted-text attachment", async () => { - await using _app = await mountDraftComposer(DraftId.make("draft-30577-window")); - const editor = page.getByTestId("composer-editor").element() as HTMLElement; - editor.blur(); - - pastePlainText(document.body, LARGE_LOG_WITH_THREAD_LINK); - await expectPasteFolded(editor); + await expect.element(page.getByText("pasted-text.txt")).toBeVisible(); + expect(editor.textContent).not.toContain("worker[399] retrying job"); });