Skip to content

Commit 09f3d19

Browse files
authored
chore: raise snapshot and diff inline thresholds (#1268)
* chore: raise snapshot and diff inline thresholds * fix: address review findings for snapshot diff thresholds * fix: align ci biome version
1 parent 289ac73 commit 09f3d19

5 files changed

Lines changed: 127 additions & 26 deletions

File tree

.github/workflows/code-quality.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
- name: Setup Biome
2727
uses: biomejs/setup-biome@v2
2828
with:
29-
version: 2.4.8
29+
version: 2.5.0
3030

3131
- name: Run Biome
3232
run: biome ci .

packages/browseros-agent/apps/server/src/tools/browser/diff-format.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { SnapshotDiff } from '../../browser/core/snapshot/diff'
22
import { writeTempToolOutputFile } from './output-file'
33
import { wrapUntrusted } from './trust-boundary'
44

5-
const MAX_INLINE_DIFF_WORDS = 2_000
5+
const MAX_INLINE_DIFF_WORDS = 10_000
66
const MAX_SAVE_FAILURE_EXCERPT_CHARS = 4_000
77

88
export interface FormattedDiff {

packages/browseros-agent/apps/server/src/tools/browser/snapshot.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { defineTool, textResult } from './framework'
33
import { writeTempToolOutputFile } from './output-file'
44
import { wrapUntrusted } from './trust-boundary'
55

6-
const LARGE_SNAPSHOT_WORD_THRESHOLD = 5_000
6+
const LARGE_SNAPSHOT_WORD_THRESHOLD = 15_000
77
const LARGE_SNAPSHOT_CHAR_THRESHOLD = 50_000
88

99
function countWords(text: string): number {

packages/browseros-agent/apps/server/tests/tools/browser/framework.test.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ describe('browser tool framework post-actions', () => {
179179
it('writes large diff post-actions to a BrowserOS output file', async () => {
180180
await withBrowserosDir(async () => {
181181
const largeDiff = Array.from(
182-
{ length: 2001 },
182+
{ length: 10001 },
183183
(_, i) => `word-${i}`,
184184
).join(' ')
185185
const postActionTool = defineTool({
@@ -195,7 +195,7 @@ describe('browser tool framework post-actions', () => {
195195
diff: async () => ({
196196
changed: true,
197197
text: largeDiff,
198-
added: 2001,
198+
added: 10001,
199199
removed: 0,
200200
afterUrl: 'https://example.com/large',
201201
}),
@@ -212,18 +212,18 @@ describe('browser tool framework post-actions', () => {
212212

213213
expect(result.isError).toBeFalsy()
214214
expect(text).toContain('[Page 4 diff]')
215-
expect(text).toContain('Diff is 2001 words')
215+
expect(text).toContain('Diff is 10001 words')
216216
expect(savedPath).toBeTruthy()
217-
expect(text).not.toContain('word-2000')
217+
expect(text).not.toContain('word-10000')
218218
expect(text).not.toContain('[UNTRUSTED_PAGE_CONTENT')
219-
expect(readFileSync(savedPath ?? '', 'utf8')).toContain('word-2000')
219+
expect(readFileSync(savedPath ?? '', 'utf8')).toContain('word-10000')
220220
})
221221
})
222222

223223
it('keeps large diff post-actions visible when output file writes fail', async () => {
224224
await withBrowserosFile(async () => {
225225
const largeDiff = Array.from(
226-
{ length: 2001 },
226+
{ length: 10001 },
227227
(_, i) => `word-${i}`,
228228
).join(' ')
229229
const postActionTool = defineTool({
@@ -239,7 +239,7 @@ describe('browser tool framework post-actions', () => {
239239
diff: async () => ({
240240
changed: true,
241241
text: largeDiff,
242-
added: 2001,
242+
added: 10001,
243243
removed: 0,
244244
afterUrl: 'https://example.com/large',
245245
}),
@@ -259,7 +259,7 @@ describe('browser tool framework post-actions', () => {
259259
expect(text).toContain('Showing the first')
260260
expect(text).toContain('[UNTRUSTED_PAGE_CONTENT')
261261
expect(text).toContain('word-0')
262-
expect(text).not.toContain('word-2000')
262+
expect(text).not.toContain('word-10000')
263263
})
264264
})
265265

packages/browseros-agent/apps/server/tests/tools/browser/register.test.ts

Lines changed: 116 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -579,19 +579,76 @@ return 'late'
579579
])
580580
})
581581

582+
it('returns old-threshold-sized direct diffs inline', async () => {
583+
await withBrowserosDir(async () => {
584+
const fake = createFakeServer()
585+
const inlineDiff = Array.from(
586+
{ length: 2001 },
587+
(_, i) => `word-${i}`,
588+
).join(' ')
589+
const session = {
590+
observe: () => ({
591+
diff: async () => ({
592+
changed: true,
593+
text: inlineDiff,
594+
added: 2001,
595+
removed: 0,
596+
afterUrl: 'https://example.com/large',
597+
}),
598+
}),
599+
pages: {
600+
getInfo: () => ({ url: 'https://example.com/large' }),
601+
},
602+
} as unknown as BrowserSession
603+
604+
registerBrowserTools(fake.server as never, session)
605+
606+
const result = await fake.handlers.get('diff')?.({ page: 1 })
607+
608+
expect(result?.isError).toBeFalsy()
609+
const data = result?.structuredContent as
610+
| {
611+
added: number
612+
removed: number
613+
wordCount: number
614+
}
615+
| undefined
616+
expect(data).toMatchObject({
617+
added: 2001,
618+
removed: 0,
619+
})
620+
expect(JSON.stringify(result?.structuredContent)).not.toContain('path')
621+
expect(JSON.stringify(result?.structuredContent)).not.toContain(
622+
'writtenToFile',
623+
)
624+
expect(result?.content).toEqual([
625+
expect.objectContaining({
626+
type: 'text',
627+
text: expect.stringContaining('word-2000'),
628+
}),
629+
])
630+
expect(result?.content).toEqual([
631+
expect.objectContaining({
632+
type: 'text',
633+
text: expect.stringContaining('[UNTRUSTED_PAGE_CONTENT'),
634+
}),
635+
])
636+
})
637+
})
638+
582639
it('writes large direct diffs to a BrowserOS output markdown file', async () => {
583640
await withBrowserosDir(async () => {
584641
const fake = createFakeServer()
585642
const largeDiff = Array.from(
586-
{ length: 2001 },
643+
{ length: 10001 },
587644
(_, i) => `word-${i}`,
588645
).join(' ')
589646
const session = {
590647
observe: () => ({
591648
diff: async () => ({
592649
changed: true,
593650
text: largeDiff,
594-
added: 2001,
651+
added: 10001,
595652
removed: 0,
596653
afterUrl: 'https://example.com/large',
597654
}),
@@ -618,10 +675,10 @@ return 'late'
618675
}
619676
| undefined
620677
expect(data).toMatchObject({
621-
added: 2001,
678+
added: 10001,
622679
removed: 0,
623680
truncated: true,
624-
wordCount: 2001,
681+
wordCount: 10001,
625682
writtenToFile: true,
626683
})
627684
const savedPath = data?.path
@@ -630,7 +687,7 @@ return 'late'
630687
expect(result?.content).toEqual([
631688
expect.objectContaining({
632689
type: 'text',
633-
text: expect.stringContaining('Diff is 2001 words'),
690+
text: expect.stringContaining('Diff is 10001 words'),
634691
}),
635692
])
636693
expect(result?.content).toEqual([
@@ -642,12 +699,12 @@ return 'late'
642699
expect(result?.content).toEqual([
643700
expect.objectContaining({
644701
type: 'text',
645-
text: expect.not.stringContaining('word-2000'),
702+
text: expect.not.stringContaining('word-10000'),
646703
}),
647704
])
648705
const savedContent = readFileSync(savedPath ?? '', 'utf8')
649706
expect(savedContent).toContain('[UNTRUSTED_PAGE_CONTENT')
650-
expect(savedContent).toContain('word-2000')
707+
expect(savedContent).toContain('word-10000')
651708
expect(data?.contentLength).toBe(savedContent.length)
652709
})
653710
})
@@ -728,7 +785,7 @@ return 'late'
728785
await withBrowserosDir(async () => {
729786
const fake = createFakeServer()
730787
const largeSnapshot = Array.from(
731-
{ length: 2001 },
788+
{ length: 10001 },
732789
(_, i) => `destination-${i}`,
733790
).join(' ')
734791
const session = {
@@ -776,7 +833,7 @@ return 'late'
776833
expect.objectContaining({
777834
type: 'text',
778835
text: expect.stringContaining(
779-
'full current snapshot is 2001 words',
836+
'full current snapshot is 10001 words',
780837
),
781838
}),
782839
expect.objectContaining({
@@ -789,7 +846,7 @@ return 'late'
789846
expect.arrayContaining([
790847
expect.objectContaining({
791848
type: 'text',
792-
text: expect.not.stringContaining('destination-2000'),
849+
text: expect.not.stringContaining('destination-10000'),
793850
}),
794851
]),
795852
)
@@ -1126,13 +1183,58 @@ return 'late'
11261183
expect(JSON.stringify(result?.structuredContent)).not.toContain('path')
11271184
})
11281185

1129-
it('writes very large snapshots to a BrowserOS output markdown file', async () => {
1186+
it('returns old-threshold-sized snapshots inline', async () => {
11301187
await withBrowserosDir(async () => {
11311188
const fake = createFakeServer()
1132-
const largeSnapshot = Array.from(
1189+
const inlineSnapshot = Array.from(
11331190
{ length: 5001 },
11341191
(_, i) => `node-${i}`,
11351192
).join(' ')
1193+
const session = {
1194+
observe: () => ({
1195+
snapshot: async () => ({ text: inlineSnapshot }),
1196+
}),
1197+
pages: {
1198+
getInfo: () => ({ url: 'https://example.com/large' }),
1199+
},
1200+
} as unknown as BrowserSession
1201+
registerBrowserTools(fake.server as never, session)
1202+
1203+
const result = await fake.handlers.get('snapshot')?.({ page: 4 })
1204+
1205+
expect(result?.isError).toBeFalsy()
1206+
const data = result?.structuredContent as
1207+
| {
1208+
page: number
1209+
}
1210+
| undefined
1211+
expect(data).toMatchObject({
1212+
page: 4,
1213+
})
1214+
expect(JSON.stringify(result?.structuredContent)).not.toContain('path')
1215+
expect(result?.content).toEqual([
1216+
expect.objectContaining({
1217+
type: 'text',
1218+
text: expect.stringContaining('node-5000'),
1219+
}),
1220+
])
1221+
expect(result?.content).toEqual([
1222+
expect.objectContaining({
1223+
type: 'text',
1224+
text: expect.stringContaining('[UNTRUSTED_PAGE_CONTENT'),
1225+
}),
1226+
])
1227+
})
1228+
})
1229+
1230+
it('writes very large snapshots to a BrowserOS output markdown file', async () => {
1231+
await withBrowserosDir(async () => {
1232+
const fake = createFakeServer()
1233+
const largeSnapshot = [
1234+
...Array.from({ length: 15000 }, () => 'x'),
1235+
'last-node',
1236+
].join(' ')
1237+
expect(largeSnapshot.length).toBeLessThan(50_000)
11361238
const session = {
11371239
observe: () => ({
11381240
snapshot: async () => ({ text: largeSnapshot }),
@@ -1157,7 +1259,7 @@ return 'late'
11571259
| undefined
11581260
expect(data).toMatchObject({
11591261
page: 4,
1160-
wordCount: 5001,
1262+
wordCount: 15001,
11611263
writtenToFile: true,
11621264
})
11631265
const savedPath = data?.path
@@ -1180,8 +1282,7 @@ return 'late'
11801282
const savedContent = readFileSync(savedPath ?? '', 'utf8')
11811283
expect(savedContent).toContain('[UNTRUSTED_PAGE_CONTENT')
11821284
expect(savedContent).toContain('[END_UNTRUSTED_PAGE_CONTENT')
1183-
expect(savedContent).toContain('node-0')
1184-
expect(savedContent).toContain('node-5000')
1285+
expect(savedContent).toContain('last-node')
11851286
expect(data?.contentLength).toBe(savedContent.length)
11861287
})
11871288
})

0 commit comments

Comments
 (0)