Skip to content

Commit 4f78d34

Browse files
committed
tighten researcher web integration test
1 parent 4cc0aab commit 4f78d34

1 file changed

Lines changed: 34 additions & 22 deletions

File tree

sdk/src/__tests__/researcher-web.integration.test.ts

Lines changed: 34 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -39,27 +39,28 @@ function extractOutputText(output: AgentOutput): string {
3939
return JSON.stringify(output.value ?? {})
4040
}
4141

42-
return output.value
43-
.map((message) => {
44-
const content = (message as { content?: unknown }).content
45-
if (typeof content === 'string') return content
46-
if (!Array.isArray(content)) return ''
47-
return content
48-
.map((part) => {
49-
if (
50-
part &&
51-
typeof part === 'object' &&
52-
'type' in part &&
53-
part.type === 'text' &&
54-
'text' in part
55-
) {
56-
return String(part.text)
57-
}
58-
return ''
59-
})
60-
.join('')
42+
const assistantText = output.value.flatMap((message) => {
43+
if ((message as { role?: unknown }).role !== 'assistant') return []
44+
45+
const content = (message as { content?: unknown }).content
46+
if (typeof content === 'string') return [content]
47+
if (!Array.isArray(content)) return []
48+
49+
return content.flatMap((part) => {
50+
if (
51+
part &&
52+
typeof part === 'object' &&
53+
'type' in part &&
54+
part.type === 'text' &&
55+
'text' in part
56+
) {
57+
return [String(part.text)]
58+
}
59+
return []
6160
})
62-
.join('\n')
61+
})
62+
63+
return assistantText.join('\n')
6364
}
6465

6566
describe('researcher-web SDK integration', () => {
@@ -95,8 +96,12 @@ describe('researcher-web SDK integration', () => {
9596
handleEvent: (event) => {
9697
events.push(event)
9798
},
98-
prompt:
99-
'Use web search to answer this React docs question. In React 19, which hook returns state, a form action, and an isPending value for form actions? Answer with the exact hook name and one short sentence.',
99+
prompt: [
100+
'Use web search to answer this React docs question.',
101+
'After searching, fetch the most relevant React docs page with run_terminal_command before answering.',
102+
'In React 19, which hook returns state, a form action, and an isPending value for form actions?',
103+
'Answer with the exact hook name and one short sentence.',
104+
].join(' '),
100105
})
101106

102107
const outputText = extractOutputText(result.output)
@@ -111,6 +116,13 @@ describe('researcher-web SDK integration', () => {
111116
event.type === 'tool_call' && event.toolName === 'web_search',
112117
),
113118
).toBe(true)
119+
expect(
120+
events.some(
121+
(event) =>
122+
event.type === 'tool_call' &&
123+
event.toolName === 'run_terminal_command',
124+
),
125+
).toBe(true)
114126
},
115127
DEFAULT_TIMEOUT_MS,
116128
)

0 commit comments

Comments
 (0)