Skip to content

Commit 7766f43

Browse files
committed
test(extension): exercise larger page batches and shared budgets
1 parent e89400f commit 7766f43

2 files changed

Lines changed: 39 additions & 11 deletions

File tree

‎apps/sim/lib/mothership/chat/process-contents.test.ts‎

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -714,17 +714,42 @@ describe('processContextsServer - browser and terminal selections', () => {
714714
}
715715
)
716716

717-
it('refuses more than three page snapshots before resolving context', async () => {
717+
it('delivers ten short page snapshots without dropping their sources', async () => {
718+
const snapshots = Array.from({ length: 10 }, (_, index) => ({
719+
...snapshot,
720+
id: `11111111-1111-4111-8111-11111111111${index}`,
721+
url: `https://example.com/page-${index}`,
722+
text: `Source ${index}`,
723+
}))
724+
const result = await processContextsServer(
725+
snapshots.map((page, index) => ({
726+
kind: 'browser_page' as const,
727+
label: `Page (${index + 1})`,
728+
snapshot: page,
729+
})),
730+
'user-1'
731+
)
732+
expect(result).toHaveLength(10)
733+
for (const [index, context] of result.entries()) {
734+
const payload = context.content.split('\n').find((line) => line.startsWith('{'))
735+
expect(payload && JSON.parse(payload)).toEqual(snapshots[index])
736+
}
737+
})
738+
739+
it.each([
740+
{ name: 'combined text', text: 'x'.repeat(37_501) },
741+
{ name: 'combined serialized bytes', text: '\u0000'.repeat(18_751) },
742+
])('refuses an oversized page batch before resolving context: $name', async ({ text }) => {
718743
await expect(
719744
processContextsServer(
720745
Array.from({ length: 4 }, (_, index) => ({
721746
kind: 'browser_page' as const,
722747
label: `Page ${index}`,
723-
snapshot: { ...snapshot, id: `11111111-1111-4111-8111-11111111111${index}` },
748+
snapshot: { ...snapshot, text, id: `11111111-1111-4111-8111-11111111111${index}` },
724749
})),
725750
'user-1'
726751
)
727-
).rejects.toThrow('At most 3 page snapshots')
752+
).rejects.toThrow('These pages contain too much text')
728753
})
729754

730755
it('points every browser and terminal mention at its exact tab', async () => {

‎apps/sim/scripts/test-browser-extension-e2e.ts‎

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -891,7 +891,7 @@ try {
891891
}
892892
}
893893
await checkNavigation(
894-
'Capture, preview, removal, and the three-page cap use the real composer',
894+
'Capture, preview, and removal support ten pages in the real composer',
895895
async () => {
896896
await capture()
897897
await expect(attachments()).toHaveCount(1)
@@ -1007,13 +1007,16 @@ try {
10071007
await focusBarrier.dispose()
10081008
await focusObserver.dispose()
10091009
}
1010-
await capture()
1011-
await capture()
1012-
await capture()
1013-
await expect(attachments()).toHaveCount(3)
1014-
await expect(frame().getByRole('alert').filter({ hasText: 'Remove a page' })).toBeVisible()
1015-
await screenshot('page-limit')
1016-
await attachments().first().getByRole('button', { name: 'Remove page context' }).click()
1010+
for (let count = 2; count <= 10; count++) {
1011+
await capture()
1012+
await expect(attachments()).toHaveCount(count)
1013+
}
1014+
await expect(frame().getByRole('alert').filter({ hasText: 'Remove a page' })).toHaveCount(0)
1015+
await screenshot('many-pages')
1016+
for (let count = 10; count > 2; count--) {
1017+
await attachments().first().getByRole('button', { name: 'Remove page context' }).click()
1018+
await expect(attachments()).toHaveCount(count - 1)
1019+
}
10171020
await expect(attachments()).toHaveCount(2)
10181021
const stored = await frame().evaluate(() => JSON.stringify(localStorage))
10191022
assert(

0 commit comments

Comments
 (0)