|
3 | 3 | import { rm } from "node:fs/promises"; |
4 | 4 | import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; |
5 | 5 | import type { OpenClawConfig } from "../../config/config.js"; |
| 6 | +import { setActiveDegradedSecretOwners } from "../../secrets/runtime-degraded-state.js"; |
6 | 7 | import { wrapExternalContent } from "../../security/external-content.js"; |
7 | 8 | import { withFetchPreconnect } from "../../test-utils/fetch-mock.js"; |
8 | 9 | import { createWebFetchTool } from "./web-fetch.js"; |
@@ -32,13 +33,43 @@ describe("web_fetch provider fallback normalization", () => { |
32 | 33 | resolveWebFetchDefinitionMock.mockReset(); |
33 | 34 | runtimeState.activeSecretsRuntimeSnapshot = null; |
34 | 35 | runtimeState.activeRuntimeWebToolsMetadata = null; |
| 36 | + setActiveDegradedSecretOwners([]); |
35 | 37 | }); |
36 | 38 |
|
37 | 39 | afterEach(() => { |
38 | 40 | global.fetch = priorFetch; |
39 | 41 | vi.restoreAllMocks(); |
40 | 42 | runtimeState.activeSecretsRuntimeSnapshot = null; |
41 | 43 | runtimeState.activeRuntimeWebToolsMetadata = null; |
| 44 | + setActiveDegradedSecretOwners([]); |
| 45 | + }); |
| 46 | + |
| 47 | + it("returns typed unavailability for only the isolated fetch provider", async () => { |
| 48 | + setActiveDegradedSecretOwners([ |
| 49 | + { |
| 50 | + ownerKind: "capability", |
| 51 | + ownerId: "web-fetch:firecrawl", |
| 52 | + state: "unavailable", |
| 53 | + paths: ["plugins.entries.firecrawl.config.webFetch.apiKey"], |
| 54 | + refKeys: ["env:default:MISSING_FIRECRAWL_KEY"], |
| 55 | + reason: "missing test ref", |
| 56 | + }, |
| 57 | + ]); |
| 58 | + const tool = createWebFetchTool({ |
| 59 | + config: { |
| 60 | + tools: { web: { fetch: { provider: "firecrawl" } } }, |
| 61 | + } as OpenClawConfig, |
| 62 | + }); |
| 63 | + |
| 64 | + await expect( |
| 65 | + tool?.execute?.("call-provider-fallback", { url: "https://example.com" }), |
| 66 | + ).rejects.toMatchObject({ |
| 67 | + name: "SecretSurfaceUnavailableError", |
| 68 | + code: "SECRET_SURFACE_UNAVAILABLE", |
| 69 | + ownerKind: "capability", |
| 70 | + ownerId: "web-fetch:firecrawl", |
| 71 | + }); |
| 72 | + expect(resolveWebFetchDefinitionMock).not.toHaveBeenCalled(); |
42 | 73 | }); |
43 | 74 |
|
44 | 75 | it("re-wraps and truncates provider fallback payloads before caching or returning", async () => { |
|
0 commit comments