pi-ext
bugabingas pi extensions
owned by bugabinga
fix(web): quiet duplicate notifications
902e78f5dc75dc19294d2edde54504c971c54ee9
Oliver Jan Krylow <oliver@bugabinga.net> ·
unsigned
Browse filesCompare with HEAD
Changed files (3)
extensions/web/__tests__/web-fetch-contract.test.ts
Modified 25 25 isPrivateOrReservedIp,
26 26 resolveRedirectUrl,
27 27 } from
"../safety";
28 +import { searchWeb }
from "../search";
28 29 import { spawnToText }
from "../spawn";
29 30 import { platformStateDir, projectStoreDir, saveJsonResult }
from "../store";
175 176 expect(result.
content[
0].
text).
toContain(
"converted markdown");
178 - it(
"notifies missing required and optional platform tools on session start",
async ()
=> {
179 + it(
"notifies missing required platform tools only on session start",
async ()
=> {
179 180 const emptyDir
= await mkdtemp(path.
join(
tmpdir(),
"pi-web-empty-bin-"));
180 181 t
= await createTestSession({
181 182 extensionFactories: [webExtension],
184 185 await new Promise((resolve)
=> setTimeout(resolve,
0));
186 187 const notify
= t.events.
uiCallsFor(
"notify");
187 - expect(notify.
map((call)
=> call.args)).
toEqual(
188 + const calls
= notify.
map((call)
=> call.args);
189 + expect(calls).
toEqual(
188 190 expect.
arrayContaining([
189 191 expect.
arrayContaining([expect.
stringContaining(
"pandoc"),
"warning"]),
190 192 expect.
arrayContaining([
191 193 expect.
stringContaining(
"pdftotext"),
198 + expect(calls).not.
toEqual(
199 + expect.
arrayContaining([
194 200 expect.
arrayContaining([expect.
stringContaining(
"identify"),
"info"]),
195 201 expect.
arrayContaining([expect.
stringContaining(
"ffprobe"),
"info"]),
206 + it(
"throws search failures without duplicate notify",
async ()
=> {
207 + globalThis.fetch
= vi.
fn(
208 + async ()
=> new Response(
"no", { status:
503, statusText:
"offline" }),
210 + const notify
= vi.
fn();
219 + ).rejects.
toThrow(
"Search unavailable");
220 + expect(notify).not.
toHaveBeenCalled();
200 223 it(
"line matching returns excerpts instead of full page",
async ()
=> {
201 224 globalThis.fetch
= vi.
fn(
extensions/web/index.ts
Modified 412 412 level:
"warning" as const,
413 413 purpose:
"PDF extraction unavailable",
417 - hint: TOOL_HINTS.identify,
418 - level:
"info" as const,
419 - purpose:
"image metadata will use fallback text",
423 - hint: TOOL_HINTS.ffprobe,
424 - level:
"info" as const,
425 - purpose:
"audio/video metadata will use fallback text",
429 417 async function notifyMissingPlatformTools(
1407 - notify: (message, level)
=> ctx?.ui?.
notify(message, level),
1410 1397 if (
!results
|| results.
length === 0) {
extensions/web/search.ts
Modified 10 10 export type SearchSource = "codex" | "zai" | "minimax" | "ddg";
12 -type Notify = (message
: string, level
: "info")
=> void;
14 12 interface SearchProvider {
15 13 source
: SearchSource;
16 14 label
: "Codex" | "Z.AI" | "MiniMax" | "DDG";
41 39 signal
?: AbortSignal;
42 40 ctx
?: ExtensionContext;
46 43 export interface WebSearchOutcome {
69 66 const summary
= failures
70 67 .
map((failure)
=> `${failure.label}: ${failure.message}`)
72 - options.
notify?.(
`Search unavailable: ${summary}`,
"info");
74 70 throw new AggregateError(
75 71 failures.
map((failure)
=> failure.err),