test: assert structuredContent and cover tool error paths
This commit is contained in:
1 parent
71e05d1258
commit
dcd370b2a0
4 files changed
+187
-3
No files matched your search
@@ -42,6 +42,52 @@ describe(name, () => {
|
||||
const result = await client.callTool({ name, arguments: { query: 'brave browser' } });
|
||||
|
||||
assert.equal(result.isError ?? false, false, JSON.stringify(result.content));
|
||||
assert.ok(Array.isArray(result.content) && result.content.length > 0);
|
||||
assert.deepEqual(result.structuredContent, {
|
||||
grounding: {
|
||||
generic: [
|
||||
{
|
||||
url: 'https://search.brave.com/',
|
||||
title: 'Brave Search',
|
||||
snippets: ['Brave is a privacy-focused browser and search engine.'],
|
||||
},
|
||||
],
|
||||
map: [],
|
||||
},
|
||||
sources: {
|
||||
'https://search.brave.com/': { title: 'Brave Search' },
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe(`${name} (malformed upstream response)`, () => {
|
||||
let client: Client;
|
||||
let close: () => Promise<void>;
|
||||
let restoreFetch: () => void;
|
||||
|
||||
before(async () => {
|
||||
restoreFetch = stubFetch((url) => {
|
||||
if (url.pathname === '/res/v1/llm/context') {
|
||||
// `sources` is required by the output schema; omitting it simulates
|
||||
// an upstream response that fails validation.
|
||||
return {
|
||||
grounding: { generic: [], map: [] },
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
({ client, close } = await connectTestClient());
|
||||
});
|
||||
|
||||
after(async () => {
|
||||
restoreFetch();
|
||||
await close();
|
||||
});
|
||||
|
||||
it('surfaces the validation failure as an error result', async () => {
|
||||
const result = await client.callTool({ name, arguments: { query: 'brave browser' } });
|
||||
|
||||
assert.equal(result.isError, true);
|
||||
assert.ok(JSON.stringify(result.content).includes('sources'), JSON.stringify(result.content));
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user