From 5291db5c3f29604856fc8843cea36727678e6ba0 Mon Sep 17 00:00:00 2001 From: Mariana Martinho Date: Wed, 16 Sep 2026 23:11:10 +0000 Subject: [PATCH 1/6] fix(models): answer the switch question when the run answers it first Ben's three non-blocking findings from today's catalogue PRs. The workspace dialog asks about a run in flight. If that run ended while the dialog was open, the dialog kept asking and offered to cancel something that was already over; the switch the reader asked for now goes through on its own. At 320px a card of a fixed 18rem left no part of the next one showing, so a strip that scrolls looked like a single card. The card takes four fifths of the row instead, up to the same 18rem. The example width is held by the mobile spec at both counts, where a browser lays it out, and `CopyTextButton`'s class assertions go with the test-only id they read. --- apps/website/e2e/workshop.spec.ts | 36 +++++++++++++++++++ .../copy-text-button/CopyTextButton.test.ts | 28 --------------- .../ui/copy-text-button/CopyTextButton.vue | 6 +--- .../components/workshop/ExamplesTab.test.ts | 25 ------------- .../src/components/workshop/ExamplesTab.vue | 7 ++-- .../components/workshop/HeaderAccount.test.ts | 34 ++++++++++++++++++ .../src/components/workshop/HeaderAccount.vue | 10 ++++++ 7 files changed, 86 insertions(+), 60 deletions(-) delete mode 100644 apps/website/src/components/ui/copy-text-button/CopyTextButton.test.ts diff --git a/apps/website/e2e/workshop.spec.ts b/apps/website/e2e/workshop.spec.ts index 268c858bbea..b08bd7864db 100644 --- a/apps/website/e2e/workshop.spec.ts +++ b/apps/website/e2e/workshop.spec.ts @@ -638,6 +638,42 @@ test.describe('Model playground', () => { .poll(() => list.evaluate((el) => el.scrollWidth > el.clientWidth)) .toBe(true) }) + + // 320px is the narrowest phone the site supports, and it is where a fixed + // card width ran the next sample off the screen: a strip that scrolls with + // nothing showing past its edge reads as a single card. + test('the next sample shows past the edge at 320px @mobile', async ({ + page + }) => { + const width = 320 + await page.setViewportSize({ width, height: 720 }) + await page.goto('/models/krea--krea-2-medium-turbo--generate-images/') + const cards = page.getByTestId('example-card') + await expect(cards).toHaveCount(3) + + await expect + .poll(async () => (await cards.nth(1).boundingBox())?.x ?? width) + .toBeLessThan(width - 24) + }) + + test('a lone sample takes the phone row @mobile', async ({ page }) => { + await page.goto('/models/bfl--flux-2-pro--generate-images/') + const cards = page.getByTestId('example-card') + await expect(cards).toHaveCount(1) + + // The strip runs edge to edge behind a gutter of 24px on each side. + const list = page.getByTestId('examples-tab').locator('ul') + await expect + .poll(async () => { + const [listBox, cardBox] = await Promise.all([ + list.boundingBox(), + cards.first().boundingBox() + ]) + if (!listBox || !cardBox) return false + return Math.abs(cardBox.width - (listBox.width - 48)) < 2 + }) + .toBe(true) + }) }) test.describe('Filter sheet @mobile', () => { diff --git a/apps/website/src/components/ui/copy-text-button/CopyTextButton.test.ts b/apps/website/src/components/ui/copy-text-button/CopyTextButton.test.ts deleted file mode 100644 index 604a04f4fad..00000000000 --- a/apps/website/src/components/ui/copy-text-button/CopyTextButton.test.ts +++ /dev/null @@ -1,28 +0,0 @@ -import { render, screen } from '@testing-library/vue' -import { describe, expect, it } from 'vitest' - -import CopyTextButton from './CopyTextButton.vue' - -function renderIcon(iconClass?: string) { - render(CopyTextButton, { - props: { - value: 'req-1', - label: 'Copy request ID', - copiedLabel: 'Copied', - iconClass - } - }) - return screen.getByTestId('copy-text-icon') -} - -describe('CopyTextButton', () => { - it('sizes its icon for the button it is, when nobody asks for anything else', () => { - expect(renderIcon()).toHaveClass('size-5') - }) - - it("takes the caller's size in place of its own, not beside it", () => { - const icon = renderIcon('size-3.5') - expect(icon).toHaveClass('size-3.5') - expect(icon).not.toHaveClass('size-5') - }) -}) diff --git a/apps/website/src/components/ui/copy-text-button/CopyTextButton.vue b/apps/website/src/components/ui/copy-text-button/CopyTextButton.vue index d95a00e3201..41b3b7a7952 100644 --- a/apps/website/src/components/ui/copy-text-button/CopyTextButton.vue +++ b/apps/website/src/components/ui/copy-text-button/CopyTextButton.vue @@ -41,11 +41,7 @@ const { copy, copied } = useClipboard({ copiedDuring: 2000 }) " @click="void copy(value)" > - + {{ copiedLabel }} diff --git a/apps/website/src/components/workshop/ExamplesTab.test.ts b/apps/website/src/components/workshop/ExamplesTab.test.ts index a21ee2512d9..de73b27d9b3 100644 --- a/apps/website/src/components/workshop/ExamplesTab.test.ts +++ b/apps/website/src/components/workshop/ExamplesTab.test.ts @@ -22,28 +22,3 @@ it('keeps the audio transport separate from the preset action', async () => { await user.click(preset) expect(emitted().open).toEqual([[example]]) }) - -// happy-dom lays nothing out, so the width can only be read off the class here. -// That it comes out to a judgeable size on a real phone is the @mobile spec in -// e2e/workshop.spec.ts; this pins which of the two widths each case picks. -it.for([ - [1, 'w-full'], - [3, 'w-72'] -] as const)('gives %i sample(s) the %s phone width', ([count, width]) => { - render(ExamplesTab, { - props: { - examples: Array.from({ length: count }, (_, index) => ({ - id: `sample-${index}`, - title: `Sample ${index}`, - specs: [], - values: {}, - outputUrl: `https://assets.example/sample-${index}.png`, - mediaKind: 'image' as const - })) - } - }) - - const items = screen.getAllByTestId('example-item') - expect(items).toHaveLength(count) - expect(items.every((item) => item.className.includes(width))).toBe(true) -}) diff --git a/apps/website/src/components/workshop/ExamplesTab.vue b/apps/website/src/components/workshop/ExamplesTab.vue index 35d314c8795..19108ce135e 100644 --- a/apps/website/src/components/workshop/ExamplesTab.vue +++ b/apps/website/src/components/workshop/ExamplesTab.vue @@ -27,8 +27,11 @@ const samplesOnly = computed( ) // A sample exists to be judged, and on a phone it was 144px wide: an 81px // preview of a generated image decides nothing. A lone sample takes the row, -// and several leave the next one peeking so the strip still reads as one. -const phoneWidth = computed(() => (examples.length === 1 ? 'w-full' : 'w-72')) +// and several take four fifths of it, so the next one peeks in at every width +// the phone layout covers, up to the 18rem past which a card gains nothing. +const phoneWidth = computed(() => + examples.length === 1 ? 'w-full' : 'w-4/5 max-w-72' +) const desktopGridColumns = computed(() => examples.length === 3 ? 'sm:grid-cols-[repeat(auto-fit,minmax(14rem,1fr))]' diff --git a/apps/website/src/components/workshop/HeaderAccount.test.ts b/apps/website/src/components/workshop/HeaderAccount.test.ts index c0f1b65d602..c45bbef6482 100644 --- a/apps/website/src/components/workshop/HeaderAccount.test.ts +++ b/apps/website/src/components/workshop/HeaderAccount.test.ts @@ -520,6 +520,40 @@ describe('HeaderAccount workspace switcher', () => { ) }) + it('carries the switch through when the run ends under the dialog', async () => { + signIn() + const cancel = vi.fn() + reportWorkshopRun(cancel) + onTestFinished(() => reportWorkshopRun(undefined)) + vi.stubGlobal( + 'fetch', + vi + .fn() + .mockResolvedValue( + new Response(JSON.stringify(listing), { status: 200 }) + ) + ) + const user = userEvent.setup() + render(HeaderAccount) + + await openSwitcher(user) + await user.click(await screen.findByTestId('account-workspace-team-1')) + expect(await screen.findByTestId('run-leave-dialog')).toBeTruthy() + + reportWorkshopRun(undefined) + + await waitFor(() => + expect(h.remint).toHaveBeenCalledWith(undefined, { + workspaceId: 'team-1', + preserveCredentialOnTransientFailure: true + }) + ) + expect(cancel).not.toHaveBeenCalled() + await waitFor(() => + expect(screen.queryByTestId('run-leave-dialog')).toBeNull() + ) + }) + it('switches by reminting for the picked workspace', async () => { signIn() vi.stubGlobal( diff --git a/apps/website/src/components/workshop/HeaderAccount.vue b/apps/website/src/components/workshop/HeaderAccount.vue index edf0cf49596..0f4a13b59e0 100644 --- a/apps/website/src/components/workshop/HeaderAccount.vue +++ b/apps/website/src/components/workshop/HeaderAccount.vue @@ -175,6 +175,16 @@ function confirmSwitch() { void switchWorkspace(workspaceId, { runAlreadyCancelled: true }) } +// The question only exists because a run would be thrown away. A run that ends +// on its own answers it: there is nothing left to cancel, so the switch the +// reader already asked for goes through and the dialog closes with it. +watch(workshopRunInFlight, (inFlight) => { + if (inFlight) return + const workspaceId = switchPending.value + switchPending.value = undefined + if (workspaceId) void switchWorkspace(workspaceId) +}) + async function applySwitch( workspaceId: string, previous: ActiveWorkshopSession From 928cb242f4de2cb8518d91e128ab1a7a367ae40e Mon Sep 17 00:00:00 2001 From: Mariana Martinho Date: Wed, 16 Sep 2026 23:22:16 +0000 Subject: [PATCH 2/6] fix(models): keep the example cap to the phone strip The cap belongs to the strip that scrolls. Unprefixed it also held the desktop grid, where the cards stretch to fill the row, so the last one stopped meeting its right edge. --- apps/website/src/components/workshop/ExamplesTab.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/website/src/components/workshop/ExamplesTab.vue b/apps/website/src/components/workshop/ExamplesTab.vue index 19108ce135e..6fe5486db1c 100644 --- a/apps/website/src/components/workshop/ExamplesTab.vue +++ b/apps/website/src/components/workshop/ExamplesTab.vue @@ -30,7 +30,7 @@ const samplesOnly = computed( // and several take four fifths of it, so the next one peeks in at every width // the phone layout covers, up to the 18rem past which a card gains nothing. const phoneWidth = computed(() => - examples.length === 1 ? 'w-full' : 'w-4/5 max-w-72' + examples.length === 1 ? 'w-full' : 'w-4/5 max-sm:max-w-72' ) const desktopGridColumns = computed(() => examples.length === 3 From ae6c4b69b6bbd64cbe8e38887122d34425ea7aff Mon Sep 17 00:00:00 2001 From: Mariana Martinho Date: Wed, 16 Sep 2026 23:42:37 +0000 Subject: [PATCH 3/6] test(models): hold the switch that a finished run lets through The browser case the unit test could only approximate: the run is held until the dialog is up, then ends on its own, and the workspace it was blocking becomes the current one. Fails against a header without the watcher. The sign-in, the run and the menu are shared with the case that was already here. --- .../e2e/workshop-workspace-switch.spec.ts | 95 +++++++++++++++---- 1 file changed, 77 insertions(+), 18 deletions(-) diff --git a/apps/website/e2e/workshop-workspace-switch.spec.ts b/apps/website/e2e/workshop-workspace-switch.spec.ts index a5d69bf9902..a5ca6f91261 100644 --- a/apps/website/e2e/workshop-workspace-switch.spec.ts +++ b/apps/website/e2e/workshop-workspace-switch.spec.ts @@ -1,3 +1,4 @@ +import type { Page } from '@playwright/test' import { expect } from '@playwright/test' import type { @@ -31,10 +32,7 @@ const WORKSPACES: ListWorkspacesResponse = { const TEAM = WORKSPACES.workspaces[1] -test('switching workspace during a run asks before it throws the run away', async ({ - page, - modelsAccount -}) => { +async function mockWorkspaces(page: Page) { await page.route('**/api/workspaces', (route) => route.fulfill({ status: 200, @@ -63,34 +61,56 @@ test('switching workspace during a run asks before it throws the run away', asyn } satisfies ExchangeTokenResponse) }) }) - // The run never answers, so it is still going when the workspace changes. - await page.route('**/v2/models/**', () => {}) +} +async function signIn( + page: Page, + account: { email: string; password: string } +) { await page.goto('/login/') await page.getByRole('button', { name: 'Use email instead' }).click() - await page.getByLabel('Email').fill(modelsAccount.email) - await page - .getByLabel('Password', { exact: true }) - .fill(modelsAccount.password) + await page.getByLabel('Email').fill(account.email) + await page.getByLabel('Password', { exact: true }).fill(account.password) await page.getByRole('button', { name: 'Sign in', exact: true }).click() await expect(page).toHaveURL('/') +} +async function startRun(page: Page) { await page.goto(MODEL_PATH) await page.getByTestId('field-prompt').fill('A teapot') await page.getByTestId('run-button').click() const output = page.getByTestId('playground-output') await expect(output).toHaveAttribute('data-state', 'running') + return output +} - const account = page +function accountMenu(page: Page) { + const trigger = page .getByTestId('desktop-nav-cta') .getByTestId('header-account') - const otherWorkspace = async () => { - await account.click() - await page.getByTestId('account-workspace').click() - await page.getByTestId('account-workspace-ws-team').click() + return { + open: () => trigger.click(), + pickTeam: async () => { + await trigger.click() + await page.getByTestId('account-workspace').click() + await page.getByTestId(`account-workspace-${TEAM.id}`).click() + } } +} + +test('switching workspace during a run asks before it throws the run away', async ({ + page, + modelsAccount +}) => { + await mockWorkspaces(page) + // The run never answers, so it is still going when the workspace changes. + await page.route('**/v2/models/**', () => {}) - await otherWorkspace() + await signIn(page, modelsAccount) + const output = await startRun(page) + const menu = accountMenu(page) + + await menu.pickTeam() const dialog = page.getByTestId('run-leave-dialog') await expect(dialog).toBeVisible() @@ -98,11 +118,50 @@ test('switching workspace during a run asks before it throws the run away', asyn await expect(dialog).toBeHidden() await expect(output).toHaveAttribute('data-state', 'running') - await otherWorkspace() + await menu.pickTeam() await page.getByTestId('run-leave-confirm').click() await expect(output).toHaveAttribute('data-state', 'cancelled') - await account.click() + await menu.open() + await expect(page.getByTestId('account-workspace-current')).toContainText( + TEAM.name + ) +}) + +test('a run that ends under the question answers it', async ({ + page, + modelsAccount +}) => { + await mockWorkspaces(page) + // The run is held until the dialog is up, then it ends on its own. + let land = () => {} + const held = new Promise((resolve) => { + land = resolve + }) + await page.route('**/v2/models/**', async (route) => { + await held + await route.fulfill({ + status: 503, + headers: { 'X-Comfy-Error-Type': 'provider_error' }, + contentType: 'application/json', + body: JSON.stringify({ detail: 'Temporary provider error' }) + }) + }) + + await signIn(page, modelsAccount) + const output = await startRun(page) + const menu = accountMenu(page) + + await menu.pickTeam() + const dialog = page.getByTestId('run-leave-dialog') + await expect(dialog).toBeVisible() + + land() + + await expect(output).toHaveAttribute('data-state', 'failed') + await expect(dialog).toBeHidden() + + await menu.open() await expect(page.getByTestId('account-workspace-current')).toContainText( TEAM.name ) From d8ae964d90f309fb7b5ff353b5406959e36c9a0c Mon Sep 17 00:00:00 2001 From: Mariana Martinho Date: Wed, 16 Sep 2026 23:46:09 +0000 Subject: [PATCH 4/6] test(models): hold the next sample to crossing the phone edge Its left edge being inside the viewport is met by a card that fits whole, which is the strip reading as one card again. It has to run past the edge as well. --- apps/website/e2e/workshop.spec.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/apps/website/e2e/workshop.spec.ts b/apps/website/e2e/workshop.spec.ts index b08bd7864db..3f2dfffc1e7 100644 --- a/apps/website/e2e/workshop.spec.ts +++ b/apps/website/e2e/workshop.spec.ts @@ -652,8 +652,14 @@ test.describe('Model playground', () => { await expect(cards).toHaveCount(3) await expect - .poll(async () => (await cards.nth(1).boundingBox())?.x ?? width) - .toBeLessThan(width - 24) + .poll(async () => { + const box = await cards.nth(1).boundingBox() + if (!box) return false + // Far enough in to be seen, and still running off the edge: a card + // that fitted whole would say the strip ends there. + return box.x < width - 24 && box.x + box.width > width + }) + .toBe(true) }) test('a lone sample takes the phone row @mobile', async ({ page }) => { From 0bd4d6fd28904225c25b67127425173f343ea084 Mon Sep 17 00:00:00 2001 From: benjcooley Date: Thu, 17 Sep 2026 10:50:20 -0700 Subject: [PATCH 5/6] fix(models): discard stale pending workspace switches --- .../components/workshop/HeaderAccount.test.ts | 42 +++++++++++++++ .../src/components/workshop/HeaderAccount.vue | 54 +++++++++++++++---- 2 files changed, 85 insertions(+), 11 deletions(-) diff --git a/apps/website/src/components/workshop/HeaderAccount.test.ts b/apps/website/src/components/workshop/HeaderAccount.test.ts index c45bbef6482..6a5c4df9b2d 100644 --- a/apps/website/src/components/workshop/HeaderAccount.test.ts +++ b/apps/website/src/components/workshop/HeaderAccount.test.ts @@ -554,6 +554,48 @@ describe('HeaderAccount workspace switcher', () => { ) }) + it('drops a pending switch when the authenticated session changes', async () => { + signIn() + const cancel = vi.fn() + reportWorkshopRun(cancel) + onTestFinished(() => reportWorkshopRun(undefined)) + vi.stubGlobal( + 'fetch', + vi + .fn() + .mockResolvedValue( + new Response(JSON.stringify(listing), { status: 200 }) + ) + ) + const user = userEvent.setup() + render(HeaderAccount) + + await openSwitcher(user) + await user.click(await screen.findByTestId('account-workspace-team-1')) + expect(await screen.findByTestId('run-leave-dialog')).toBeTruthy() + + const replacement = { + token: 'other-jwt', + uid: 'user-2', + workspace: { id: 'other', name: 'Other', type: 'personal' as const }, + role: 'owner' + } + h.user!.value = { + uid: 'user-2', + email: 'other@b.co', + displayName: 'Other' + } + h.session!.value = replacement + reportWorkshopRun(undefined) + + await waitFor(() => + expect(screen.queryByTestId('run-leave-dialog')).toBeNull() + ) + expect(h.remint).not.toHaveBeenCalled() + expect(cancel).not.toHaveBeenCalled() + expect(h.session!.value).toEqual(replacement) + }) + it('switches by reminting for the picked workspace', async () => { signIn() vi.stubGlobal( diff --git a/apps/website/src/components/workshop/HeaderAccount.vue b/apps/website/src/components/workshop/HeaderAccount.vue index 0f4a13b59e0..7e76e2f6564 100644 --- a/apps/website/src/components/workshop/HeaderAccount.vue +++ b/apps/website/src/components/workshop/HeaderAccount.vue @@ -165,25 +165,53 @@ async function restorePreviousWorkspace( // A run belongs to the workspace that is paying for it, so switching ends it. // The playground guards every way off the page; this is the way off the // workspace, and it has to ask the same question before it takes the credits. -const switchPending = ref() +type PendingWorkspaceSwitch = { + targetWorkspaceId: string + sourceUid: string + sourceWorkspaceId: string +} + +const switchPending = ref() + +function pendingSwitchStillOwnsSession( + pending: PendingWorkspaceSwitch +): boolean { + const current = session.value + return ( + current?.uid === pending.sourceUid && + current.workspace.id === pending.sourceWorkspaceId + ) +} function confirmSwitch() { - const workspaceId = switchPending.value + const pending = switchPending.value switchPending.value = undefined - if (!workspaceId) return + if (!pending || !pendingSwitchStillOwnsSession(pending)) return cancelWorkshopRun() - void switchWorkspace(workspaceId, { runAlreadyCancelled: true }) + void switchWorkspace(pending.targetWorkspaceId, { + runAlreadyCancelled: true + }) } // The question only exists because a run would be thrown away. A run that ends // on its own answers it: there is nothing left to cancel, so the switch the // reader already asked for goes through and the dialog closes with it. -watch(workshopRunInFlight, (inFlight) => { - if (inFlight) return - const workspaceId = switchPending.value - switchPending.value = undefined - if (workspaceId) void switchWorkspace(workspaceId) -}) +watch( + [ + workshopRunInFlight, + () => session.value?.uid, + () => session.value?.workspace.id + ], + ([inFlight]) => { + const pending = switchPending.value + if (!pending) return + if (inFlight && pendingSwitchStillOwnsSession(pending)) return + + const shouldContinue = pendingSwitchStillOwnsSession(pending) + switchPending.value = undefined + if (shouldContinue) void switchWorkspace(pending.targetWorkspaceId) + } +) async function applySwitch( workspaceId: string, @@ -225,7 +253,11 @@ async function switchWorkspace( return } if (workshopRunInFlight.value && !options?.runAlreadyCancelled) { - switchPending.value = workspaceId + switchPending.value = { + targetWorkspaceId: workspaceId, + sourceUid: previous.uid, + sourceWorkspaceId: previous.workspace.id + } return } await applySwitch(workspaceId, previous) From 08047e3ed70c1f8653d2c6dcb07deab586d479c4 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 17 Sep 2026 17:58:00 +0000 Subject: [PATCH 6/6] test(models): hold the workspace arm of the stale-switch guard The guard compares uid and workspace, and ModelDetail cancels the run from two separate watchers, one per field. The existing case moves the uid, so a guard narrowed to uid alone still passes it. This moves only the workspace and keeps the reader signed in, which is the arm where a stale answer would overwrite the newer workspace: with the guard narrowed that way, the uid case passes and this one fails. --- .../components/workshop/HeaderAccount.test.ts | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/apps/website/src/components/workshop/HeaderAccount.test.ts b/apps/website/src/components/workshop/HeaderAccount.test.ts index 6a5c4df9b2d..5ec653be405 100644 --- a/apps/website/src/components/workshop/HeaderAccount.test.ts +++ b/apps/website/src/components/workshop/HeaderAccount.test.ts @@ -596,6 +596,47 @@ describe('HeaderAccount workspace switcher', () => { expect(h.session!.value).toEqual(replacement) }) + // The other arm of the same scope check: the reader stays signed in, and only + // the workspace moves under the dialog. ModelDetail watches uid and workspace + // separately, and this is the arm where a stale answer would overwrite the + // newer workspace rather than reach for another account's. + it('drops a pending switch when only the workspace changes', async () => { + signIn() + const cancel = vi.fn() + reportWorkshopRun(cancel) + onTestFinished(() => reportWorkshopRun(undefined)) + vi.stubGlobal( + 'fetch', + vi + .fn() + .mockResolvedValue( + new Response(JSON.stringify(listing), { status: 200 }) + ) + ) + const user = userEvent.setup() + render(HeaderAccount) + + await openSwitcher(user) + await user.click(await screen.findByTestId('account-workspace-team-1')) + expect(await screen.findByTestId('run-leave-dialog')).toBeTruthy() + + const moved = { + token: 'jwt', + uid: 'user-1', + workspace: { id: 'team-2', name: 'Other team', type: 'team' as const }, + role: 'owner' + } + h.session!.value = moved + reportWorkshopRun(undefined) + + await waitFor(() => + expect(screen.queryByTestId('run-leave-dialog')).toBeNull() + ) + expect(h.remint).not.toHaveBeenCalled() + expect(cancel).not.toHaveBeenCalled() + expect(h.session!.value).toEqual(moved) + }) + it('switches by reminting for the picked workspace', async () => { signIn() vi.stubGlobal(