diff --git a/tests/fixtures/inbox-presence.ts b/tests/fixtures/inbox-presence.ts index 7f41273..c915026 100644 --- a/tests/fixtures/inbox-presence.ts +++ b/tests/fixtures/inbox-presence.ts @@ -158,9 +158,28 @@ try { streamAbort.abort() await streamReader.cancel().catch(() => undefined) await Promise.allSettled(extraStreams.map(response => response.body?.cancel())) - const reopened = await openStream(AbortSignal.timeout(5000)) - assert.equal(reopened.status, 200) - await reopened.body?.cancel() + // Client cancellation can complete before the server processes the disconnect. + // Keep the replacement streams open so the test accounts for all four slots. + const reopened: Response[] = [] + const streamCount = extraStreams.length + 1 + const reconnectDeadline = performance.now() + 5000 + const reconnectSignal = AbortSignal.timeout(5000) + try { + while (reopened.length < streamCount && performance.now() < reconnectDeadline) { + const response = await openStream(reconnectSignal) + if (response.status === 429) { + assert.equal((await response.json()).error.code, 'typing_stream_limit') + await Bun.sleep(25) + continue + } + assert.equal(response.status, 200) + reopened.push(response) + } + assert.equal(reopened.length, streamCount, 'all cancelled typing streams release their slots') + } + finally { + await Promise.allSettled(reopened.map(response => response.body?.cancel())) + } const agentStatus = (sequence: number, path = presence) => http(path, teammate.token, payload(otherTab, sequence, 'viewing')) const whileComposing = await agentStatus(3) assert.equal(whileComposing.data.customerTyping, true) diff --git a/tests/fixtures/team-browser.ts b/tests/fixtures/team-browser.ts index a266423..0ddb8d3 100644 --- a/tests/fixtures/team-browser.ts +++ b/tests/fixtures/team-browser.ts @@ -12,7 +12,7 @@ import { injectGlobalAutoImports } from '@stacksjs/server' import { route } from '@stacksjs/router' import { Storage } from '@stacksjs/storage' import { generateStaticSite } from '@stacksjs/stx/ssg' -import { launch, navigate, waitFor, closeSharedBrowsers } from '@stacksjs/testing/browser' +import { click as clickReady, launch, navigate, waitFor, closeSharedBrowsers } from '@stacksjs/testing/browser' import { insert, one, query } from '../../app/Support/database' import { seedNewerImportRuns } from './import-history' @@ -214,12 +214,19 @@ try { const editManual = async (name: string) => { await evaluate(`Array.from(document.querySelectorAll('tr')).find(row=>row.querySelector('td')?.textContent === ${JSON.stringify(name)})?.querySelector('button').click()`); await waitFor(() => evaluate(`document.querySelector('#edit-inbox-active') !== null`), 15000, { label: 'Inbox edit form' }) } await editManual('Manual review'); await input('#edit-inbox-name', 'Manual review paused'); await evaluate(`document.querySelector('#edit-inbox-active').click()`); await click('Save inbox settings'); await text('Inbox settings saved.') check(!Boolean((await one('SELECT active FROM support_team_inboxes WHERE id = ?', [manual.id]))!.active), 'owner can deactivate an inbox without changing the active default') - await editManual('Manual review paused'); await evaluate(`document.querySelector('#edit-inbox-active').click()`); await click('Save inbox settings'); await waitFor(async () => Boolean((await one('SELECT active FROM support_team_inboxes WHERE id = ?', [manual.id]))!.active), 15000, { label: 'Inbox reactivated' }) + await editManual('Manual review paused') + await evaluate(`document.querySelector('#edit-inbox-active').click()`) + await clickReady(cdp, { selector: 'button', text: 'Save inbox settings' }) + await text('Inbox settings saved.') + await waitFor(async () => Boolean((await one('SELECT active FROM support_team_inboxes WHERE id = ?', [manual.id]))!.active), 15000, { label: 'Inbox reactivated' }) check(Boolean((await one('SELECT is_default FROM support_team_inboxes WHERE id = ?', [inbox.id]))!.is_default), 'inactive inbox recovery preserves the other project default') const emptyTeam = (await one('SELECT id FROM support_teams WHERE workspace_id = ? AND name = ?', [workspace.id, 'Browser-created team']))! - await input('#support-team', String(emptyTeam.id)); await click('Disable team and release assignments'); await text('Team disabled.') + await input('#support-team', String(emptyTeam.id)) + await clickReady(cdp, { selector: 'button', text: 'Disable team and release assignments' }) + await text('Team disabled.') check(!Boolean((await one('SELECT active FROM support_teams WHERE id = ?', [emptyTeam.id]))!.active), 'owner deactivates an empty team through the actual native action') - await click('Reactivate team'); await text('Team reactivated.') + await clickReady(cdp, { selector: 'button', text: 'Reactivate team' }) + await text('Team reactivated.') check(Boolean((await one('SELECT active FROM support_teams WHERE id = ?', [emptyTeam.id]))!.active), 'inactive team has an actionable reactivation path') await mkdir(artifacts, { recursive: true }); const settingsImage = await cdp.send('Page.captureScreenshot', { format: 'png', captureBeyondViewport: true }); await Bun.write(resolve(artifacts, 'team-settings.png'), Buffer.from(settingsImage.data, 'base64')) // Remove the owner again so later capacity behavior has one eligible agent.