docs: document web runtime tests · openclaw/openclaw@0e427e6
steipete
·
2026-06-05
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +// web_fetch visibility tests cover hidden HTML and invisible Unicode stripping |
| 2 | +// before extracted content reaches the model. |
1 | 3 | import { describe, expect, it } from "vitest"; |
2 | 4 | import { sanitizeHtml, stripInvisibleUnicode } from "./web-fetch-visibility.js"; |
3 | 5 | |
@@ -196,6 +198,8 @@ describe("sanitizeHtml", () => {
|
196 | 198 | }); |
197 | 199 | |
198 | 200 | it("drops nested hidden same-name elements without leaking trailing hidden text", async () => { |
| 201 | +// Malformed hidden regions are prompt-injection territory; nested tags must |
| 202 | +// not leak trailing hidden text after the inner close tag. |
199 | 203 | const html = "<p>Visible</p><div hidden><div>Nested hidden</div>Still hidden</div><p>Shown</p>"; |
200 | 204 | const result = await sanitizeHtml(html); |
201 | 205 | expect(result).toContain("Visible"); |
@@ -237,6 +241,8 @@ describe("stripInvisibleUnicode", () => {
|
237 | 241 | }); |
238 | 242 | |
239 | 243 | it("strips directional overrides (LRO, RLO, PDF, etc.)", () => { |
| 244 | +// Directional controls can make visible text render differently from the |
| 245 | +// byte sequence the model sees. |
240 | 246 | const text = "\u202AHello\u202E"; |
241 | 247 | expect(stripInvisibleUnicode(text)).toBe("Hello"); |
242 | 248 | }); |
|
| Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +// web_fetch SSRF tests cover URL, DNS, redirect, and proxy policy enforcement |
| 2 | +// before network requests reach fetch or provider fallbacks. |
1 | 3 | import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; |
2 | 4 | import * as ssrf from "../../infra/net/ssrf.js"; |
3 | 5 | import { type FetchMock, withFetchPreconnect } from "../../test-utils/fetch-mock.js"; |
@@ -139,6 +141,8 @@ describe("web_fetch SSRF protection", () => {
|
139 | 141 | }); |
140 | 142 | |
141 | 143 | it("blocks redirects to private hosts", async () => { |
| 144 | +// Redirect targets are new network destinations and must be re-checked |
| 145 | +// against the same SSRF policy as the original URL. |
142 | 146 | lookupMock.mockResolvedValue([{ address: "93.184.216.34", family: 4 }]); |
143 | 147 | |
144 | 148 | const fetchSpy = setMockFetch().mockResolvedValueOnce( |
@@ -163,6 +167,8 @@ describe("web_fetch SSRF protection", () => {
|
163 | 167 | }); |
164 | 168 | |
165 | 169 | it("allows RFC2544 benchmark-range URLs only when web_fetch ssrfPolicy opts in", async () => { |
| 170 | +// Benchmark ranges are fake-IP infrastructure in some deployments, but |
| 171 | +// remain denied unless the web_fetch config opts in. |
166 | 172 | const url = "http://198.18.0.153/file"; |
167 | 173 | lookupMock.mockResolvedValue([{ address: "198.18.0.153", family: 4 }]); |
168 | 174 | |
|
| Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +// Web search credential tests cover precedence between configured credentials, |
| 2 | +// SecretRefs, and ambient environment fallbacks. |
1 | 3 | import { describe, expect, it } from "vitest"; |
2 | 4 | import { withEnv } from "../../test-utils/env.js"; |
3 | 5 | import { resolveWebSearchProviderCredential } from "./web-search-provider-credentials.js"; |
@@ -32,6 +34,8 @@ describe("resolveWebSearchProviderCredential", () => {
|
32 | 34 | }); |
33 | 35 | |
34 | 36 | it("does not override missing env SecretRefs with ambient env fallback", () => { |
| 37 | +// An explicit SecretRef means "use this credential"; falling back to a |
| 38 | +// different env var can silently route requests through the wrong account. |
35 | 39 | withEnv( |
36 | 40 | { TEST_WEB_SEARCH_REF_KEY: undefined, TEST_WEB_SEARCH_KEY: "ambient-test-value" }, |
37 | 41 | () => { |
|
| Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +// web_search late-binding tests cover runtime config and provider metadata |
| 2 | +// selection at execution time. |
1 | 3 | import { beforeEach, describe, expect, it, vi } from "vitest"; |
2 | 4 | import { createWebSearchTool } from "./web-search.js"; |
3 | 5 | |
@@ -136,6 +138,8 @@ describe("web_search late-bound runtime fallback", () => {
|
136 | 138 | }); |
137 | 139 | |
138 | 140 | it("prefers active runtime metadata over options.runtimeWebSearch when present", async () => { |
| 141 | +// Active runtime metadata reflects the newest credential snapshot; fallback |
| 142 | +// options only cover tools created before that state exists. |
139 | 143 | mocks.getActiveRuntimeWebToolsMetadata.mockReturnValue({ |
140 | 144 | search: { |
141 | 145 | selectedProvider: "perplexity", |
@@ -161,6 +165,8 @@ describe("web_search late-bound runtime fallback", () => {
|
161 | 165 | }); |
162 | 166 | |
163 | 167 | it("honors late-bound disabled search config at execute time", async () => { |
| 168 | +// A long-lived tool must still observe an operator disabling web_search |
| 169 | +// before the next call is dispatched. |
164 | 170 | mocks.getActiveSecretsRuntimeConfigSnapshot.mockReturnValue({ |
165 | 171 | config: { tools: { web: { search: { enabled: false } } } }, |
166 | 172 | }); |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。