test: assert structuredContent and cover tool error paths

This commit is contained in:
Sampson committed 2026-08-11 13:24:52 -05:00
1 parent 71e05d1258
commit dcd370b2a0
4 files changed
+187 -3

No files matched your search

+83
View File
@@ -46,3 +46,86 @@ describe(name, () => {
assert.ok(Array.isArray(result.content) && result.content.length > 0);
});
});
describe(`${name} (no locations, web fallback available)`, () => {
let client: Client;
let close: () => Promise<void>;
let restoreFetch: () => void;
before(async () => {
restoreFetch = stubFetch((url) => {
if (url.pathname === '/res/v1/web/search') {
return {
type: 'search',
web: {
results: [
{
url: 'https://example.com/cafe',
title: 'Local Cafe',
description: 'A nice cafe.',
extra_snippets: [],
},
],
},
};
}
});
({ client, close } = await connectTestClient());
});
after(async () => {
restoreFetch();
await close();
});
it('falls back to formatted web results', async () => {
const result = await client.callTool({
name,
arguments: { query: 'coffee shops in san francisco' },
});
assert.equal(result.isError ?? false, false, JSON.stringify(result.content));
const content = result.content as { text: string }[];
assert.equal(content.length, 2);
assert.match(content[0].text, /Falling back to general web search/);
assert.match(content[1].text, /Local Cafe/);
});
});
describe(`${name} (no locations, no web results)`, () => {
let client: Client;
let close: () => Promise<void>;
let restoreFetch: () => void;
before(async () => {
restoreFetch = stubFetch((url) => {
if (url.pathname === '/res/v1/web/search') {
return { type: 'search' };
}
});
({ client, close } = await connectTestClient());
});
after(async () => {
restoreFetch();
await close();
});
it('reports that no location data was found', async () => {
const result = await client.callTool({
name,
arguments: { query: 'coffee shops in san francisco' },
});
assert.equal(result.isError ?? false, false, JSON.stringify(result.content));
assert.deepEqual(result.content, [
{
type: 'text',
text: "No location data was returned. User's plan does not support local search, or the query may be unclear.",
},
]);
});
});