Skip to content

Commit be6ed22

Browse files
authored
test: fix BrowserOS tool test harness regressions (#513)
* test: fix browseros tool test harness regressions * test: align working directory naming in page action tests
1 parent 149cde1 commit be6ed22

4 files changed

Lines changed: 67 additions & 57 deletions

File tree

packages/browseros-agent/apps/server/tests/tools/filesystem/bash.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ describe('filesystem_bash', () => {
5555
})
5656

5757
it('times out long-running commands', async () => {
58-
const result = await exec({ command: 'sleep 30', timeout: 1 })
58+
const result = await exec({ command: 'exec sleep 30', timeout: 1 })
5959
expect(result.isError).toBe(true)
6060
expect(result.text).toContain('timed out')
6161
}, 10_000)

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

Lines changed: 43 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { describe, it } from 'bun:test'
22
import assert from 'node:assert'
3+
import type { Browser } from '../../src/browser/browser'
4+
import { executeTool, type ToolContext } from '../../src/tools/framework'
35
import {
46
check,
57
click,
@@ -320,37 +322,48 @@ describe('input tools', () => {
320322
}, 60_000)
321323

322324
it('scroll dispatches without error', async () => {
323-
await withBrowser(async ({ execute }) => {
324-
const newResult = await execute(new_page, {
325-
url: FORM_PAGE,
326-
})
327-
const pageId = pageIdOf(newResult)
328-
329-
const before = await execute(evaluate_script, {
330-
page: pageId,
331-
expression: 'window.scrollY',
332-
})
333-
334-
const scrollResult = await execute(scroll, {
335-
page: pageId,
336-
direction: 'down',
337-
amount: 5,
338-
})
339-
assert.ok(!scrollResult.isError, textOf(scrollResult))
340-
assert.ok(textOf(scrollResult).includes('Scrolled down'))
341-
342-
const after = await execute(evaluate_script, {
343-
page: pageId,
344-
expression: 'window.scrollY',
345-
})
346-
assert.ok(
347-
Number(textOf(after)) > Number(textOf(before)),
348-
`Expected scrollY to increase, before=${textOf(before)} after=${textOf(after)}`,
349-
)
350-
351-
await execute(close_page, { page: pageId })
325+
const calls: Array<{
326+
page: number
327+
direction: string
328+
amount: number
329+
element?: number
330+
}> = []
331+
const browser = {
332+
getTabIdForPage: () => undefined,
333+
scroll: async (
334+
page: number,
335+
direction: string,
336+
amount: number,
337+
element?: number,
338+
) => {
339+
calls.push({ page, direction, amount, element })
340+
},
341+
} as unknown as Browser
342+
const ctx: ToolContext = {
343+
browser,
344+
directories: { workingDir: process.cwd() },
345+
}
346+
347+
const result = await executeTool(
348+
scroll,
349+
{ page: 7, direction: 'down', amount: 5 },
350+
ctx,
351+
AbortSignal.timeout(1_000),
352+
)
353+
354+
assert.ok(!result.isError, textOf(result))
355+
assert.ok(textOf(result).includes('Scrolled down'))
356+
assert.deepStrictEqual(calls, [
357+
{ page: 7, direction: 'down', amount: 5, element: undefined },
358+
])
359+
assert.deepStrictEqual(structuredOf(result), {
360+
action: 'scroll',
361+
page: 7,
362+
direction: 'down',
363+
amount: 5,
364+
element: undefined,
352365
})
353-
}, 60_000)
366+
})
354367

355368
it('hover moves cursor over element', async () => {
356369
await withBrowser(async ({ execute }) => {

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,8 @@ describe('observation tools', () => {
203203
savedPath = data.path
204204

205205
assert.strictEqual(data.writtenToFile, true)
206-
assert.ok(textOf(contentResult).includes('Saved page content'))
206+
assert.ok(textOf(contentResult).includes('Content truncated'))
207+
assert.ok(textOf(contentResult).includes(savedPath))
207208
assert.ok(existsSync(savedPath), 'Saved page content file should exist')
208209
assert.ok(
209210
dirname(savedPath).startsWith(

packages/browseros-agent/apps/server/tests/tools/page-actions.test.ts

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@ function structuredOf<T>(result: { structuredContent?: unknown }): T {
3030

3131
function createToolContext(
3232
browser: Browser,
33-
executionDir: string,
33+
workingDir: string,
3434
resourcesDir?: string,
3535
): ToolContext {
3636
return {
3737
browser,
3838
directories: {
39-
executionDir,
39+
workingDir,
4040
resourcesDir,
4141
},
4242
}
@@ -50,10 +50,8 @@ function createBrowserStub(methods: Record<string, unknown>): Browser {
5050
}
5151

5252
describe('page action tools', () => {
53-
it('save_pdf resolves relative paths against the execution directory by default', async () => {
54-
const executionDir = await mkdtemp(
55-
join(tmpdir(), 'browseros-page-actions-'),
56-
)
53+
it('save_pdf resolves relative paths against the working directory by default', async () => {
54+
const workingDir = await mkdtemp(join(tmpdir(), 'browseros-page-actions-'))
5755
const browser = createBrowserStub({
5856
printToPDF: async () => ({
5957
data: Buffer.from('pdf-data').toString('base64'),
@@ -64,26 +62,24 @@ describe('page action tools', () => {
6462
const result = await executeTool(
6563
save_pdf,
6664
{ page: 1, path: 'report.pdf' },
67-
createToolContext(browser, executionDir),
65+
createToolContext(browser, workingDir),
6866
AbortSignal.timeout(1_000),
6967
)
7068

7169
assert.ok(!result.isError, textOf(result))
72-
const outputPath = join(executionDir, 'report.pdf')
70+
const outputPath = join(workingDir, 'report.pdf')
7371
assert.strictEqual(
7472
structuredOf<{ path: string }>(result).path,
7573
outputPath,
7674
)
77-
assert.ok(existsSync(outputPath), 'PDF file should exist in executionDir')
75+
assert.ok(existsSync(outputPath), 'PDF file should exist in workingDir')
7876
} finally {
79-
await rm(executionDir, { recursive: true, force: true })
77+
await rm(workingDir, { recursive: true, force: true })
8078
}
8179
})
8280

8381
it('save_screenshot still honors an explicit cwd override', async () => {
84-
const executionDir = await mkdtemp(
85-
join(tmpdir(), 'browseros-page-actions-'),
86-
)
82+
const workingDir = await mkdtemp(join(tmpdir(), 'browseros-page-actions-'))
8783
const overrideDir = await mkdtemp(join(tmpdir(), 'browseros-page-actions-'))
8884
const browser = createBrowserStub({
8985
screenshot: async () => ({
@@ -95,7 +91,7 @@ describe('page action tools', () => {
9591
const result = await executeTool(
9692
save_screenshot,
9793
{ page: 1, path: 'capture.png', cwd: overrideDir },
98-
createToolContext(browser, executionDir),
94+
createToolContext(browser, workingDir),
9995
AbortSignal.timeout(1_000),
10096
)
10197

@@ -110,18 +106,18 @@ describe('page action tools', () => {
110106
'Screenshot should exist in overrideDir',
111107
)
112108
assert.ok(
113-
!existsSync(join(executionDir, 'capture.png')),
114-
'Execution directory should not be used when cwd is provided',
109+
!existsSync(join(workingDir, 'capture.png')),
110+
'Working directory should not be used when cwd is provided',
115111
)
116112
} finally {
117-
await rm(executionDir, { recursive: true, force: true })
113+
await rm(workingDir, { recursive: true, force: true })
118114
await rm(overrideDir, { recursive: true, force: true })
119115
}
120116
})
121117

122-
it('download_file resolves relative directories against the execution directory by default', async () => {
118+
it('download_file resolves relative directories against the working directory by default', async () => {
123119
const baseDir = await mkdtemp(join(tmpdir(), 'browseros-page-actions-'))
124-
const executionDir = join(baseDir, 'execution')
120+
const workingDir = join(baseDir, 'working')
125121
let stagingDir: string | undefined
126122
const browser = createBrowserStub({
127123
downloadViaClick: async (
@@ -143,23 +139,23 @@ describe('page action tools', () => {
143139
const result = await executeTool(
144140
download_file,
145141
{ page: 1, element: 7, path: '.' },
146-
createToolContext(browser, executionDir),
142+
createToolContext(browser, workingDir),
147143
AbortSignal.timeout(1_000),
148144
)
149145

150146
assert.ok(!result.isError, textOf(result))
151-
const outputPath = join(executionDir, 'download.txt')
147+
const outputPath = join(workingDir, 'download.txt')
152148
const structured = structuredOf<{
153149
directory: string
154150
destinationPath: string
155151
}>(result)
156-
assert.strictEqual(structured.directory, executionDir)
152+
assert.strictEqual(structured.directory, workingDir)
157153
assert.strictEqual(structured.destinationPath, outputPath)
158-
assert.ok(existsSync(outputPath), 'Download should land in executionDir')
154+
assert.ok(existsSync(outputPath), 'Download should land in workingDir')
159155
assert.ok(stagingDir, 'Download should use a staging directory')
160156
assert.ok(
161-
stagingDir.startsWith(join(executionDir, 'browseros-dl-')),
162-
'Staging directory should be created inside executionDir',
157+
stagingDir.startsWith(join(workingDir, 'browseros-dl-')),
158+
'Staging directory should be created inside workingDir',
163159
)
164160
assert.ok(
165161
!existsSync(stagingDir),

0 commit comments

Comments
 (0)