@asterxsk/kiln 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +170 -0
- package/agent/AGENTS.md +67 -0
- package/agent/README.md +5 -0
- package/agent/extensions/AGENTS.md +68 -0
- package/agent/extensions/ask-user/index.ts +418 -0
- package/agent/extensions/ask-user/install.ps1 +23 -0
- package/agent/extensions/ask-user/install.sh +21 -0
- package/agent/extensions/ask-user/package-lock.json +769 -0
- package/agent/extensions/ask-user/package.json +19 -0
- package/agent/extensions/ask-user/prompt.ts +45 -0
- package/agent/extensions/ask-user/tsconfig.json +7 -0
- package/agent/extensions/background-terminals/docs/implementation-guide.md +942 -0
- package/agent/extensions/background-terminals/index.ts +627 -0
- package/agent/extensions/background-terminals/install.ps1 +23 -0
- package/agent/extensions/background-terminals/install.sh +21 -0
- package/agent/extensions/background-terminals/manager.test.ts +735 -0
- package/agent/extensions/background-terminals/output.test.ts +109 -0
- package/agent/extensions/background-terminals/package-lock.json +769 -0
- package/agent/extensions/background-terminals/package.json +17 -0
- package/agent/extensions/background-terminals/prompt.test.ts +125 -0
- package/agent/extensions/background-terminals/ps.test.ts +82 -0
- package/agent/extensions/background-terminals/result-delivery.test.ts +44 -0
- package/agent/extensions/background-terminals/src/domain.ts +87 -0
- package/agent/extensions/background-terminals/src/manager.ts +907 -0
- package/agent/extensions/background-terminals/src/output.ts +84 -0
- package/agent/extensions/background-terminals/src/prompt.ts +142 -0
- package/agent/extensions/background-terminals/src/result-delivery.ts +27 -0
- package/agent/extensions/background-terminals/src/runtime.ts +36 -0
- package/agent/extensions/background-terminals/src/ui/output-view.ts +79 -0
- package/agent/extensions/background-terminals/src/ui/ps.ts +621 -0
- package/agent/extensions/background-terminals/tsconfig.json +7 -0
- package/agent/extensions/destructive/README.md +31 -0
- package/agent/extensions/destructive/index.ts +88 -0
- package/agent/extensions/destructive/install.ps1 +23 -0
- package/agent/extensions/destructive/install.sh +21 -0
- package/agent/extensions/file-search/index.spec.ts +443 -0
- package/agent/extensions/file-search/index.ts +459 -0
- package/agent/extensions/file-search/install.ps1 +23 -0
- package/agent/extensions/file-search/install.sh +21 -0
- package/agent/extensions/file-search/package-lock.json +2253 -0
- package/agent/extensions/file-search/package.json +23 -0
- package/agent/extensions/file-search/src/args.ts +122 -0
- package/agent/extensions/file-search/src/binaries.ts +422 -0
- package/agent/extensions/file-search/src/output.ts +126 -0
- package/agent/extensions/file-search/src/process.ts +146 -0
- package/agent/extensions/file-search/src/prompt.ts +52 -0
- package/agent/extensions/file-search/tsconfig.json +7 -0
- package/agent/extensions/goal/README.md +50 -0
- package/agent/extensions/goal/index.ts +155 -0
- package/agent/extensions/goal/install.ps1 +23 -0
- package/agent/extensions/goal/install.sh +21 -0
- package/agent/extensions/modelconf/PLAN.md +915 -0
- package/agent/extensions/modelconf/README.md +66 -0
- package/agent/extensions/modelconf/index.ts +296 -0
- package/agent/extensions/modelconf/install.ps1 +23 -0
- package/agent/extensions/modelconf/install.sh +21 -0
- package/agent/extensions/modelconf/package-lock.json +1809 -0
- package/agent/extensions/modelconf/package.json +13 -0
- package/agent/extensions/modelconf/src/fuzzy.ts +26 -0
- package/agent/extensions/modelconf/src/glob.ts +13 -0
- package/agent/extensions/modelconf/src/persistence.test.ts +46 -0
- package/agent/extensions/modelconf/src/persistence.ts +164 -0
- package/agent/extensions/modelconf/src/ui/ModelConfView.test.ts +75 -0
- package/agent/extensions/modelconf/src/ui/ModelConfView.ts +1101 -0
- package/agent/extensions/modelconf/tsconfig.json +15 -0
- package/agent/extensions/pi-web-access/CHANGELOG.md +690 -0
- package/agent/extensions/pi-web-access/LICENSE +21 -0
- package/agent/extensions/pi-web-access/README.md +470 -0
- package/agent/extensions/pi-web-access/SECURITY.md +5 -0
- package/agent/extensions/pi-web-access/activity.ts +101 -0
- package/agent/extensions/pi-web-access/auth-fetch.ts +148 -0
- package/agent/extensions/pi-web-access/banner.png +0 -0
- package/agent/extensions/pi-web-access/brightdata-unlocker.ts +272 -0
- package/agent/extensions/pi-web-access/chrome-cookies.ts +669 -0
- package/agent/extensions/pi-web-access/content-find.ts +139 -0
- package/agent/extensions/pi-web-access/credential-source.ts +191 -0
- package/agent/extensions/pi-web-access/data-uri-sanitize.ts +406 -0
- package/agent/extensions/pi-web-access/datalab-pdf-extract.ts +568 -0
- package/agent/extensions/pi-web-access/declared-web-links.ts +173 -0
- package/agent/extensions/pi-web-access/evidence/CONTRACT-EVIDENCE.md +496 -0
- package/agent/extensions/pi-web-access/evidence/contract-probe.mjs +140 -0
- package/agent/extensions/pi-web-access/exa.ts +526 -0
- package/agent/extensions/pi-web-access/extract.ts +1196 -0
- package/agent/extensions/pi-web-access/feature-config.ts +29 -0
- package/agent/extensions/pi-web-access/fetch-params.ts +111 -0
- package/agent/extensions/pi-web-access/gemini-adc.ts +298 -0
- package/agent/extensions/pi-web-access/gemini-api.ts +353 -0
- package/agent/extensions/pi-web-access/gemini-pdf-extract.ts +108 -0
- package/agent/extensions/pi-web-access/gemini-search.ts +21 -0
- package/agent/extensions/pi-web-access/gemini-url-context.ts +128 -0
- package/agent/extensions/pi-web-access/gemini-web-config.ts +101 -0
- package/agent/extensions/pi-web-access/gemini-web.ts +487 -0
- package/agent/extensions/pi-web-access/github-api.ts +197 -0
- package/agent/extensions/pi-web-access/github-extract.ts +746 -0
- package/agent/extensions/pi-web-access/github-issue-pr.ts +700 -0
- package/agent/extensions/pi-web-access/index.ts +1737 -0
- package/agent/extensions/pi-web-access/package-lock.json +5808 -0
- package/agent/extensions/pi-web-access/package.json +64 -0
- package/agent/extensions/pi-web-access/page-query.ts +96 -0
- package/agent/extensions/pi-web-access/pdf-extract.ts +409 -0
- package/agent/extensions/pi-web-access/pi-web-fetch-demo.mp4 +0 -0
- package/agent/extensions/pi-web-access/promise-try.d.ts +7 -0
- package/agent/extensions/pi-web-access/query-rewrite.ts +51 -0
- package/agent/extensions/pi-web-access/render-search-error.ts +170 -0
- package/agent/extensions/pi-web-access/rsc-extract.ts +338 -0
- package/agent/extensions/pi-web-access/search-types.ts +20 -0
- package/agent/extensions/pi-web-access/source-check.ts +282 -0
- package/agent/extensions/pi-web-access/ssrf-protection.ts +526 -0
- package/agent/extensions/pi-web-access/storage.ts +521 -0
- package/agent/extensions/pi-web-access/summary-model-scope.ts +125 -0
- package/agent/extensions/pi-web-access/test/auth-fetch.test.mjs +208 -0
- package/agent/extensions/pi-web-access/test/brightdata-unlocker.test.mjs +840 -0
- package/agent/extensions/pi-web-access/test/chrome-cookie-extraction.test.mjs +441 -0
- package/agent/extensions/pi-web-access/test/config-path.test.mjs +283 -0
- package/agent/extensions/pi-web-access/test/content-find.test.mjs +25 -0
- package/agent/extensions/pi-web-access/test/credential-source.test.mjs +118 -0
- package/agent/extensions/pi-web-access/test/data-uri-sanitize.test.mjs +210 -0
- package/agent/extensions/pi-web-access/test/datalab-pdf-extract.test.mjs +552 -0
- package/agent/extensions/pi-web-access/test/declared-web-links.test.mjs +212 -0
- package/agent/extensions/pi-web-access/test/fetch-answer-storage.test.mjs +40 -0
- package/agent/extensions/pi-web-access/test/fetch-cache-storage.test.mjs +334 -0
- package/agent/extensions/pi-web-access/test/fetch-content-domain-policy.test.mjs +95 -0
- package/agent/extensions/pi-web-access/test/fetch-modes.test.mjs +53 -0
- package/agent/extensions/pi-web-access/test/fetch-not-found-guidance.test.mjs +92 -0
- package/agent/extensions/pi-web-access/test/fetch-params.test.mjs +86 -0
- package/agent/extensions/pi-web-access/test/fetch-render-call.test.mjs +34 -0
- package/agent/extensions/pi-web-access/test/fetch-routing.test.mjs +173 -0
- package/agent/extensions/pi-web-access/test/gemini-adc-auth.test.mjs +257 -0
- package/agent/extensions/pi-web-access/test/gemini-api-transport.test.mjs +170 -0
- package/agent/extensions/pi-web-access/test/gemini-pdf-extract.test.mjs +133 -0
- package/agent/extensions/pi-web-access/test/gemini-web-cookie-opt-in.test.mjs +178 -0
- package/agent/extensions/pi-web-access/test/gemini-web-header-overflow.test.mjs +148 -0
- package/agent/extensions/pi-web-access/test/get-search-content.test.mjs +223 -0
- package/agent/extensions/pi-web-access/test/github-extract.test.mjs +378 -0
- package/agent/extensions/pi-web-access/test/github-issue-pr.test.mjs +565 -0
- package/agent/extensions/pi-web-access/test/inline-content-config.test.mjs +99 -0
- package/agent/extensions/pi-web-access/test/lazy-extract-load.test.mjs +118 -0
- package/agent/extensions/pi-web-access/test/local-video-oversize.test.mjs +52 -0
- package/agent/extensions/pi-web-access/test/package-typebox-dependency.test.mjs +50 -0
- package/agent/extensions/pi-web-access/test/page-query.test.mjs +51 -0
- package/agent/extensions/pi-web-access/test/pdf-config.test.mjs +140 -0
- package/agent/extensions/pi-web-access/test/pdf-extract.test.mjs +500 -0
- package/agent/extensions/pi-web-access/test/proxy-transport.test.mjs +286 -0
- package/agent/extensions/pi-web-access/test/query-rewrite.test.mjs +52 -0
- package/agent/extensions/pi-web-access/test/rsc-fallback.test.mjs +102 -0
- package/agent/extensions/pi-web-access/test/search-error-render.test.mjs +152 -0
- package/agent/extensions/pi-web-access/test/search-providers.test.mjs +274 -0
- package/agent/extensions/pi-web-access/test/source-check.test.mjs +179 -0
- package/agent/extensions/pi-web-access/test/ssrf-allow-ranges-config.test.mjs +205 -0
- package/agent/extensions/pi-web-access/test/ssrf-protection.test.mjs +456 -0
- package/agent/extensions/pi-web-access/test/summary-model-scope.test.mjs +106 -0
- package/agent/extensions/pi-web-access/test/tool-registration-config.test.mjs +182 -0
- package/agent/extensions/pi-web-access/test/web-search-answer-render.test.mjs +66 -0
- package/agent/extensions/pi-web-access/test/youtube-extract-errors.test.mjs +64 -0
- package/agent/extensions/pi-web-access/tsconfig.json +11 -0
- package/agent/extensions/pi-web-access/utils.ts +451 -0
- package/agent/extensions/pi-web-access/video-extract.ts +392 -0
- package/agent/extensions/pi-web-access/youtube-extract.ts +328 -0
- package/agent/extensions/shared/activity-status.ts +31 -0
- package/agent/extensions/shared/child-session.test.ts +270 -0
- package/agent/extensions/shared/child-session.ts +148 -0
- package/agent/extensions/shared/context-utilization.test.ts +48 -0
- package/agent/extensions/shared/context-utilization.ts +47 -0
- package/agent/extensions/shared/dashboard-state.ts +99 -0
- package/agent/extensions/shared/install.ps1 +23 -0
- package/agent/extensions/shared/install.sh +21 -0
- package/agent/extensions/shared/tool-call-timeout.test.ts +117 -0
- package/agent/extensions/shared/tool-call-timeout.ts +104 -0
- package/agent/extensions/skillsconf/README.md +74 -0
- package/agent/extensions/skillsconf/index.ts +92 -0
- package/agent/extensions/skillsconf/install.ps1 +23 -0
- package/agent/extensions/skillsconf/install.sh +21 -0
- package/agent/extensions/skillsconf/package-lock.json +1809 -0
- package/agent/extensions/skillsconf/package.json +18 -0
- package/agent/extensions/skillsconf/src/delete-skill.test.ts +64 -0
- package/agent/extensions/skillsconf/src/delete-skill.ts +45 -0
- package/agent/extensions/skillsconf/src/filter.test.ts +80 -0
- package/agent/extensions/skillsconf/src/filter.ts +74 -0
- package/agent/extensions/skillsconf/src/fuzzy.ts +26 -0
- package/agent/extensions/skillsconf/src/persistence.test.ts +72 -0
- package/agent/extensions/skillsconf/src/persistence.ts +169 -0
- package/agent/extensions/skillsconf/src/ui/SkillConfView.test.ts +337 -0
- package/agent/extensions/skillsconf/src/ui/SkillConfView.ts +758 -0
- package/agent/extensions/skillsconf/src/ui/text-input.ts +91 -0
- package/agent/extensions/skillsconf/src/ui/tui-helpers.ts +144 -0
- package/agent/extensions/skillsconf/tsconfig.json +15 -0
- package/agent/extensions/status line/index.ts +282 -0
- package/agent/extensions/status line/install.ps1 +23 -0
- package/agent/extensions/status line/install.sh +21 -0
- package/agent/extensions/subagents/by-the-way.test.ts +29 -0
- package/agent/extensions/subagents/claude.test.ts +119 -0
- package/agent/extensions/subagents/codex.test.ts +102 -0
- package/agent/extensions/subagents/context-usage.test.ts +107 -0
- package/agent/extensions/subagents/docs/design-plan.md +568 -0
- package/agent/extensions/subagents/docs/effect-v4-extension-guide.md +354 -0
- package/agent/extensions/subagents/docs/effect-v4-notes.md +571 -0
- package/agent/extensions/subagents/index.ts +779 -0
- package/agent/extensions/subagents/install.ps1 +23 -0
- package/agent/extensions/subagents/install.sh +21 -0
- package/agent/extensions/subagents/manager.test.ts +276 -0
- package/agent/extensions/subagents/package-lock.json +2244 -0
- package/agent/extensions/subagents/package.json +19 -0
- package/agent/extensions/subagents/result-delivery.test.ts +27 -0
- package/agent/extensions/subagents/src/backend.ts +73 -0
- package/agent/extensions/subagents/src/backends/claude.ts +701 -0
- package/agent/extensions/subagents/src/backends/codex.ts +1060 -0
- package/agent/extensions/subagents/src/backends/pi.ts +575 -0
- package/agent/extensions/subagents/src/backends/stub.ts +300 -0
- package/agent/extensions/subagents/src/by-the-way.ts +21 -0
- package/agent/extensions/subagents/src/domain.ts +253 -0
- package/agent/extensions/subagents/src/format.ts +74 -0
- package/agent/extensions/subagents/src/manager.ts +736 -0
- package/agent/extensions/subagents/src/prompt.ts +92 -0
- package/agent/extensions/subagents/src/result-delivery.ts +20 -0
- package/agent/extensions/subagents/src/runtime.ts +53 -0
- package/agent/extensions/subagents/src/ui/takeover.ts +583 -0
- package/agent/extensions/subagents/src/ui/transcript.ts +201 -0
- package/agent/extensions/subagents/takeover.test.ts +29 -0
- package/agent/extensions/subagents/tsconfig.json +7 -0
- package/agent/extensions/taste/index.ts +443 -0
- package/agent/extensions/taste/install.ps1 +23 -0
- package/agent/extensions/taste/install.sh +21 -0
- package/agent/extensions/todo/AGENTS.md +38 -0
- package/agent/extensions/todo/LICENSE +21 -0
- package/agent/extensions/todo/config.ts +55 -0
- package/agent/extensions/todo/index.ts +151 -0
- package/agent/extensions/todo/install.ps1 +23 -0
- package/agent/extensions/todo/install.sh +21 -0
- package/agent/extensions/todo/locales/de.json +17 -0
- package/agent/extensions/todo/locales/en.json +15 -0
- package/agent/extensions/todo/locales/es.json +17 -0
- package/agent/extensions/todo/locales/fr.json +17 -0
- package/agent/extensions/todo/locales/pt-BR.json +17 -0
- package/agent/extensions/todo/locales/pt.json +17 -0
- package/agent/extensions/todo/locales/ru.json +17 -0
- package/agent/extensions/todo/locales/uk.json +17 -0
- package/agent/extensions/todo/locales/zh.json +17 -0
- package/agent/extensions/todo/package-lock.json +3358 -0
- package/agent/extensions/todo/package.json +67 -0
- package/agent/extensions/todo/state/i18n-bridge.ts +64 -0
- package/agent/extensions/todo/state/invariants.ts +20 -0
- package/agent/extensions/todo/state/replay.ts +38 -0
- package/agent/extensions/todo/state/selectors.ts +107 -0
- package/agent/extensions/todo/state/state-reducer.ts +326 -0
- package/agent/extensions/todo/state/state.ts +18 -0
- package/agent/extensions/todo/state/store.ts +82 -0
- package/agent/extensions/todo/state/task-graph.ts +57 -0
- package/agent/extensions/todo/todo-overlay.ts +200 -0
- package/agent/extensions/todo/todo.ts +155 -0
- package/agent/extensions/todo/tool/response-envelope.ts +109 -0
- package/agent/extensions/todo/tool/types.ts +206 -0
- package/agent/extensions/todo/verify-ref-system.js +0 -0
- package/agent/extensions/todo/view/format.ts +177 -0
- package/agent/extensions/trim-context/README.md +54 -0
- package/agent/extensions/trim-context/index.ts +487 -0
- package/agent/extensions/trim-context/install.ps1 +23 -0
- package/agent/extensions/trim-context/install.sh +21 -0
- package/agent/install.ps1 +527 -0
- package/agent/install.sh +511 -0
- package/agent/keybindings.json +7 -0
- package/bin/kiln.js +359 -0
- package/package.json +21 -0
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { mkdtemp, readFile, rm, writeFile, chmod } from "node:fs/promises";
|
|
3
|
+
import { tmpdir } from "node:os";
|
|
4
|
+
import { delimiter, join } from "node:path";
|
|
5
|
+
import { test } from "node:test";
|
|
6
|
+
|
|
7
|
+
import initializeExtension from "../index.ts";
|
|
8
|
+
import { getActiveProxy, installGlobalProxyFetch, runWithProxy } from "../utils.ts";
|
|
9
|
+
|
|
10
|
+
const originalFetch = globalThis.fetch;
|
|
11
|
+
const originalPath = process.env.PATH;
|
|
12
|
+
const originalAgentDir = process.env.PI_CODING_AGENT_DIR;
|
|
13
|
+
const originalNoProxy = process.env.NO_PROXY;
|
|
14
|
+
const originalNoProxyLower = process.env.no_proxy;
|
|
15
|
+
|
|
16
|
+
// Fake shebang executables cannot run on Windows: extensionless scripts are not
|
|
17
|
+
// resolvable/spawnable via CreateProcess, and `.cmd` shims are refused by
|
|
18
|
+
// child_process without `shell: true` (post CVE-2024-27980 hardening). Tests
|
|
19
|
+
// below that depend on the fake curl's canned responses skip there; they still
|
|
20
|
+
// run on POSIX CI. Behavior-only proxy tests are unaffected and keep running.
|
|
21
|
+
const SKIP_FAKE_CURL = process.platform === "win32"
|
|
22
|
+
? "requires a runnable fake curl executable (unavailable on Windows)"
|
|
23
|
+
: false;
|
|
24
|
+
|
|
25
|
+
async function withFakeCurl(t, routes, fn) {
|
|
26
|
+
const dir = await mkdtemp(join(tmpdir(), "pi-proxy-test-"));
|
|
27
|
+
const logPath = join(dir, "curl-args.jsonl");
|
|
28
|
+
const curlPath = join(dir, "curl");
|
|
29
|
+
await writeFile(curlPath, `#!/usr/bin/env node
|
|
30
|
+
const fs = require("node:fs");
|
|
31
|
+
const routes = JSON.parse(process.env.PI_PROXY_TEST_ROUTES);
|
|
32
|
+
const args = process.argv.slice(2);
|
|
33
|
+
fs.appendFileSync(process.env.PI_PROXY_TEST_LOG, JSON.stringify(args) + "\\n");
|
|
34
|
+
function valueAfter(flag) {
|
|
35
|
+
const index = args.indexOf(flag);
|
|
36
|
+
return index === -1 ? null : args[index + 1];
|
|
37
|
+
}
|
|
38
|
+
const url = args[args.length - 1];
|
|
39
|
+
const route = routes[url];
|
|
40
|
+
if (!route) throw new Error("unexpected url " + url);
|
|
41
|
+
fs.writeFileSync(valueAfter("-D"), "HTTP/1.1 " + route.status + " " + route.statusText + "\\r\\n" + (route.location ? "Location: " + route.location + "\\r\\n" : "") + "\\r\\n");
|
|
42
|
+
fs.writeFileSync(valueAfter("--output"), route.body || "");
|
|
43
|
+
process.stdout.write(JSON.stringify({ url_effective: url, num_redirects: 0 }));
|
|
44
|
+
`);
|
|
45
|
+
await chmod(curlPath, 0o755);
|
|
46
|
+
if (process.platform === "win32") {
|
|
47
|
+
// Windows CreateProcess resolves executables via PATHEXT, so the
|
|
48
|
+
// extensionless shebang script above is invisible to spawn("curl").
|
|
49
|
+
// A curl.cmd shim in the same directory makes the fake win resolution.
|
|
50
|
+
await writeFile(join(dir, "curl.cmd"), `@echo off\r\nnode "%~dp0curl" %*\r\n`);
|
|
51
|
+
}
|
|
52
|
+
process.env.PATH = `${dir}${delimiter}${originalPath ?? ""}`;
|
|
53
|
+
process.env.PI_PROXY_TEST_LOG = logPath;
|
|
54
|
+
process.env.PI_PROXY_TEST_ROUTES = JSON.stringify(routes);
|
|
55
|
+
process.env.NO_PROXY = "";
|
|
56
|
+
process.env.no_proxy = "";
|
|
57
|
+
globalThis.fetch = originalFetch;
|
|
58
|
+
installGlobalProxyFetch();
|
|
59
|
+
t.after(async () => {
|
|
60
|
+
globalThis.fetch = originalFetch;
|
|
61
|
+
if (originalPath === undefined) delete process.env.PATH;
|
|
62
|
+
else process.env.PATH = originalPath;
|
|
63
|
+
if (originalNoProxy === undefined) delete process.env.NO_PROXY;
|
|
64
|
+
else process.env.NO_PROXY = originalNoProxy;
|
|
65
|
+
if (originalNoProxyLower === undefined) delete process.env.no_proxy;
|
|
66
|
+
else process.env.no_proxy = originalNoProxyLower;
|
|
67
|
+
delete process.env.PI_PROXY_TEST_LOG;
|
|
68
|
+
delete process.env.PI_PROXY_TEST_ROUTES;
|
|
69
|
+
await rm(dir, { recursive: true, force: true });
|
|
70
|
+
});
|
|
71
|
+
const result = await fn(logPath);
|
|
72
|
+
return result;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
async function readCurlCalls(logPath) {
|
|
76
|
+
return (await readFile(logPath, "utf8"))
|
|
77
|
+
.trim()
|
|
78
|
+
.split("\n")
|
|
79
|
+
.filter(Boolean)
|
|
80
|
+
.map((line) => JSON.parse(line));
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function headerValues(args) {
|
|
84
|
+
const values = [];
|
|
85
|
+
for (let index = 0; index < args.length; index++) {
|
|
86
|
+
if (args[index] === "-H") values.push(args[index + 1]);
|
|
87
|
+
}
|
|
88
|
+
return values;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function registerSourceCheck() {
|
|
92
|
+
const tools = [];
|
|
93
|
+
initializeExtension({
|
|
94
|
+
registerTool(tool) { tools.push(tool); },
|
|
95
|
+
registerCommand() {},
|
|
96
|
+
registerShortcut() {},
|
|
97
|
+
on() {},
|
|
98
|
+
appendEntry() {},
|
|
99
|
+
});
|
|
100
|
+
return tools.find((tool) => tool.name === "source_check");
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function registerFetchContent() {
|
|
104
|
+
const tools = [];
|
|
105
|
+
initializeExtension({
|
|
106
|
+
registerTool(tool) { tools.push(tool); },
|
|
107
|
+
registerCommand() {},
|
|
108
|
+
registerShortcut() {},
|
|
109
|
+
on() {},
|
|
110
|
+
appendEntry() {},
|
|
111
|
+
});
|
|
112
|
+
return tools.find((tool) => tool.name === "fetch_content");
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function proxyArg(args) {
|
|
116
|
+
const index = args.indexOf("-x");
|
|
117
|
+
return index === -1 ? undefined : args[index + 1];
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
test("proxy curl redirects strip caller headers across origins", { skip: SKIP_FAKE_CURL }, async (t) => {
|
|
121
|
+
await withFakeCurl(t, {
|
|
122
|
+
"https://origin.example/start": { status: 302, statusText: "Found", location: "https://other.example/final" },
|
|
123
|
+
"https://other.example/final": { status: 200, statusText: "OK", body: "ok" },
|
|
124
|
+
}, async (logPath) => {
|
|
125
|
+
const response = await runWithProxy("http://proxy.example:8080", () => fetch("https://origin.example/start", {
|
|
126
|
+
headers: {
|
|
127
|
+
Authorization: "Bearer secret",
|
|
128
|
+
Cookie: "session=secret",
|
|
129
|
+
"X-Api-Key": "secret",
|
|
130
|
+
Accept: "text/html",
|
|
131
|
+
},
|
|
132
|
+
}));
|
|
133
|
+
|
|
134
|
+
assert.equal(await response.text(), "ok");
|
|
135
|
+
assert.equal(response.url, "https://other.example/final");
|
|
136
|
+
assert.equal(response.redirected, true);
|
|
137
|
+
const calls = await readCurlCalls(logPath);
|
|
138
|
+
assert.equal(calls.length, 2);
|
|
139
|
+
assert.ok(headerValues(calls[0]).some((header) => /^authorization:/i.test(header)));
|
|
140
|
+
assert.deepEqual(headerValues(calls[1]), []);
|
|
141
|
+
assert.ok(calls.every((args) => !args.includes("--location")));
|
|
142
|
+
});
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
test("omitted proxy uses global config while empty string forces direct access", async (t) => {
|
|
146
|
+
const dir = await mkdtemp(join(tmpdir(), "pi-proxy-config-test-"));
|
|
147
|
+
await writeFile(join(dir, "web-search.json"), JSON.stringify({ proxy: "http://global-proxy.example:8080" }));
|
|
148
|
+
process.env.PI_CODING_AGENT_DIR = dir;
|
|
149
|
+
t.after(async () => {
|
|
150
|
+
if (originalAgentDir === undefined) delete process.env.PI_CODING_AGENT_DIR;
|
|
151
|
+
else process.env.PI_CODING_AGENT_DIR = originalAgentDir;
|
|
152
|
+
await rm(dir, { recursive: true, force: true });
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
assert.equal(runWithProxy(undefined, () => getActiveProxy()), "http://global-proxy.example:8080/");
|
|
156
|
+
assert.equal(runWithProxy("", () => getActiveProxy()), null);
|
|
157
|
+
assert.equal(runWithProxy("http://call-proxy.example:8080", () => getActiveProxy()), "http://call-proxy.example:8080/");
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
test("invalid configured proxy fails closed instead of direct fetching", async (t) => {
|
|
161
|
+
const dir = await mkdtemp(join(tmpdir(), "pi-proxy-invalid-config-test-"));
|
|
162
|
+
await writeFile(join(dir, "web-search.json"), JSON.stringify({ proxy: "socks5://proxy.example:1080" }));
|
|
163
|
+
process.env.PI_CODING_AGENT_DIR = dir;
|
|
164
|
+
t.after(async () => {
|
|
165
|
+
if (originalAgentDir === undefined) delete process.env.PI_CODING_AGENT_DIR;
|
|
166
|
+
else process.env.PI_CODING_AGENT_DIR = originalAgentDir;
|
|
167
|
+
await rm(dir, { recursive: true, force: true });
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
assert.throws(() => getActiveProxy(), /proxy.*must use the http:\/\/ or https:\/\/ scheme/);
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
test("proxy transport does not spawn curl for pre-aborted requests", async (t) => {
|
|
174
|
+
await withFakeCurl(t, {
|
|
175
|
+
"https://origin.example/abort": { status: 200, statusText: "OK", body: "late" },
|
|
176
|
+
}, async (logPath) => {
|
|
177
|
+
const controller = new AbortController();
|
|
178
|
+
controller.abort();
|
|
179
|
+
|
|
180
|
+
await assert.rejects(
|
|
181
|
+
runWithProxy("http://proxy.example:8080", () => fetch("https://origin.example/abort", { signal: controller.signal })),
|
|
182
|
+
/error.*abort/i,
|
|
183
|
+
);
|
|
184
|
+
await assert.rejects(readFile(logPath, "utf8"), /ENOENT/);
|
|
185
|
+
});
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
test("proxy transport errors redact proxy credentials", async (t) => {
|
|
189
|
+
await withFakeCurl(t, {}, async () => {
|
|
190
|
+
await assert.rejects(
|
|
191
|
+
runWithProxy("http://user:secret@proxy.example:8080", () => fetch("https://origin.example/missing")),
|
|
192
|
+
(error) => {
|
|
193
|
+
assert.match(error.message, /http:\/\/redacted:redacted@proxy\.example:8080\//);
|
|
194
|
+
assert.doesNotMatch(error.message, /user:secret/);
|
|
195
|
+
return true;
|
|
196
|
+
},
|
|
197
|
+
);
|
|
198
|
+
});
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
test("proxy curl redirects keep caller headers on the same origin", { skip: SKIP_FAKE_CURL }, async (t) => {
|
|
202
|
+
await withFakeCurl(t, {
|
|
203
|
+
"https://origin.example/start": { status: 302, statusText: "Found", location: "/final" },
|
|
204
|
+
"https://origin.example/final": { status: 200, statusText: "OK", body: "ok" },
|
|
205
|
+
}, async (logPath) => {
|
|
206
|
+
await runWithProxy("http://proxy.example:8080", () => fetch("https://origin.example/start", {
|
|
207
|
+
headers: { Authorization: "Bearer secret" },
|
|
208
|
+
}));
|
|
209
|
+
|
|
210
|
+
const calls = await readCurlCalls(logPath);
|
|
211
|
+
assert.equal(calls.length, 2);
|
|
212
|
+
assert.ok(headerValues(calls[1]).some((header) => /^authorization:/i.test(header)));
|
|
213
|
+
});
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
test("proxy curl keeps manual redirects as redirect responses", { skip: SKIP_FAKE_CURL }, async (t) => {
|
|
217
|
+
await withFakeCurl(t, {
|
|
218
|
+
"https://origin.example/start": { status: 302, statusText: "Found", location: "https://other.example/final" },
|
|
219
|
+
}, async (logPath) => {
|
|
220
|
+
const response = await runWithProxy("http://proxy.example:8080", () => fetch("https://origin.example/start", { redirect: "manual" }));
|
|
221
|
+
|
|
222
|
+
assert.equal(response.status, 302);
|
|
223
|
+
assert.equal(response.headers.get("location"), "https://other.example/final");
|
|
224
|
+
assert.equal((await readCurlCalls(logPath)).length, 1);
|
|
225
|
+
});
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
test("source_check fetchContent uses the explicit proxy for result pages", { skip: SKIP_FAKE_CURL }, async (t) => {
|
|
229
|
+
const previousKey = process.env.EXA_API_KEY;
|
|
230
|
+
process.env.EXA_API_KEY = "source-check-proxy-test-key";
|
|
231
|
+
t.after(() => {
|
|
232
|
+
if (previousKey === undefined) delete process.env.EXA_API_KEY;
|
|
233
|
+
else process.env.EXA_API_KEY = previousKey;
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
await withFakeCurl(t, {
|
|
237
|
+
"https://api.exa.ai/answer": {
|
|
238
|
+
status: 200,
|
|
239
|
+
statusText: "OK",
|
|
240
|
+
body: JSON.stringify({
|
|
241
|
+
answer: "The API docs are available.",
|
|
242
|
+
citations: [{ title: "API docs", url: "https://example.com/api" }],
|
|
243
|
+
}),
|
|
244
|
+
},
|
|
245
|
+
"https://example.com/api": { status: 200, statusText: "OK", body: "<html><title>API docs</title><body>The API docs are available.</body></html>" },
|
|
246
|
+
}, async (logPath) => {
|
|
247
|
+
const tool = registerSourceCheck();
|
|
248
|
+
assert.ok(tool);
|
|
249
|
+
const response = await tool.execute("call", {
|
|
250
|
+
claim: "API docs",
|
|
251
|
+
fetchContent: true,
|
|
252
|
+
proxy: "http://call-proxy.example:8080",
|
|
253
|
+
}, undefined, undefined, { modelRegistry: {} });
|
|
254
|
+
|
|
255
|
+
assert.equal(response.details.sourceCount, 1);
|
|
256
|
+
const calls = await readCurlCalls(logPath);
|
|
257
|
+
const apiCall = calls.find((args) => args.at(-1) === "https://api.exa.ai/answer");
|
|
258
|
+
const pageCall = calls.find((args) => args.at(-1) === "https://example.com/api");
|
|
259
|
+
assert.ok(apiCall);
|
|
260
|
+
assert.ok(pageCall);
|
|
261
|
+
assert.ok(["http://call-proxy.example:8080", "http://call-proxy.example:8080/"].includes(proxyArg(apiCall)));
|
|
262
|
+
assert.ok(["http://call-proxy.example:8080", "http://call-proxy.example:8080/"].includes(proxyArg(pageCall)));
|
|
263
|
+
});
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
test("fetch_content passes the explicit proxy through queued extraction", { skip: SKIP_FAKE_CURL }, async (t) => {
|
|
267
|
+
await withFakeCurl(t, {
|
|
268
|
+
"https://example.com/page": {
|
|
269
|
+
status: 200,
|
|
270
|
+
statusText: "OK",
|
|
271
|
+
body: "<html><title>Proxy page</title><body>Fetched through the requested proxy.</body></html>",
|
|
272
|
+
},
|
|
273
|
+
}, async (logPath) => {
|
|
274
|
+
const tool = registerFetchContent();
|
|
275
|
+
assert.ok(tool);
|
|
276
|
+
const response = await tool.execute("call", {
|
|
277
|
+
url: "https://example.com/page",
|
|
278
|
+
proxy: "http://call-proxy.example:8080",
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
assert.equal(response.details.successful, 1);
|
|
282
|
+
const pageCall = (await readCurlCalls(logPath)).find((args) => args.at(-1) === "https://example.com/page");
|
|
283
|
+
assert.ok(pageCall);
|
|
284
|
+
assert.ok(["http://call-proxy.example:8080", "http://call-proxy.example:8080/"].includes(proxyArg(pageCall)));
|
|
285
|
+
});
|
|
286
|
+
});
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { after, test } from "node:test";
|
|
3
|
+
import { mkdtemp, rm } from "node:fs/promises";
|
|
4
|
+
import { tmpdir } from "node:os";
|
|
5
|
+
import { join } from "node:path";
|
|
6
|
+
|
|
7
|
+
const previousAgentDir = process.env.PI_CODING_AGENT_DIR;
|
|
8
|
+
const agentDir = await mkdtemp(join(tmpdir(), "pi-query-rewrite-"));
|
|
9
|
+
process.env.PI_CODING_AGENT_DIR = agentDir;
|
|
10
|
+
after(async () => {
|
|
11
|
+
if (previousAgentDir === undefined) delete process.env.PI_CODING_AGENT_DIR;
|
|
12
|
+
else process.env.PI_CODING_AGENT_DIR = previousAgentDir;
|
|
13
|
+
await rm(agentDir, { recursive: true, force: true });
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
const { rewriteSearchQuery } = await import("../query-rewrite.ts");
|
|
17
|
+
|
|
18
|
+
test("rewriteSearchQuery uses the registered provider runtime", async () => {
|
|
19
|
+
const model = {
|
|
20
|
+
api: "custom-rewrite-api",
|
|
21
|
+
provider: "anthropic",
|
|
22
|
+
id: "claude-haiku-4-5",
|
|
23
|
+
input: ["text"],
|
|
24
|
+
};
|
|
25
|
+
let request;
|
|
26
|
+
const signal = new AbortController().signal;
|
|
27
|
+
const result = await rewriteSearchQuery(
|
|
28
|
+
"http status codes",
|
|
29
|
+
{
|
|
30
|
+
modelRegistry: {
|
|
31
|
+
find: () => model,
|
|
32
|
+
getAvailable: () => [model],
|
|
33
|
+
getApiKeyAndHeaders: async () => ({ ok: true, apiKey: "test-key" }),
|
|
34
|
+
complete: async (calledModel, context, options) => {
|
|
35
|
+
request = { model: calledModel, context, options };
|
|
36
|
+
return {
|
|
37
|
+
stopReason: "stop",
|
|
38
|
+
content: [{ type: "text", text: "HTTP status code semantics RFC 9110" }],
|
|
39
|
+
};
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
cwd: process.cwd(),
|
|
43
|
+
isProjectTrusted: () => false,
|
|
44
|
+
},
|
|
45
|
+
signal,
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
assert.equal(result, "HTTP status code semantics RFC 9110");
|
|
49
|
+
assert.equal(request.model, model);
|
|
50
|
+
assert.equal(request.options.signal, signal);
|
|
51
|
+
assert.match(request.context.messages[0].content[0].text, /Query: http status codes/);
|
|
52
|
+
});
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { readFileSync } from "node:fs";
|
|
3
|
+
import { test } from "node:test";
|
|
4
|
+
|
|
5
|
+
import { extractContent } from "../extract.ts";
|
|
6
|
+
|
|
7
|
+
const indexSrc = readFileSync(new URL("../index.ts", import.meta.url), "utf8");
|
|
8
|
+
const lookup = async () => [{ address: "93.184.216.34", family: 4 }];
|
|
9
|
+
const originalFetch = globalThis.fetch;
|
|
10
|
+
|
|
11
|
+
test("weak Readability output falls back to useful RSC content", async (t) => {
|
|
12
|
+
t.after(() => { globalThis.fetch = originalFetch; });
|
|
13
|
+
const article = "RSC article content survives the loading shell. ".repeat(20);
|
|
14
|
+
const payload = `23:${JSON.stringify(["$", "article", null, { children: ["$", "p", null, { children: article }] }])}\n`;
|
|
15
|
+
globalThis.fetch = async () => new Response(
|
|
16
|
+
`<!doctype html><html><head><title>RSC article</title></head><body><article>Loading...</article><script>self.__next_f.push([1,${JSON.stringify(payload)}])</script></body></html>`,
|
|
17
|
+
{
|
|
18
|
+
status: 200,
|
|
19
|
+
headers: {
|
|
20
|
+
"content-type": "text/html",
|
|
21
|
+
link: '</openapi.json>; rel="service-desc"',
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
const result = await extractContent("https://example.com/rsc", undefined, { lookup });
|
|
27
|
+
assert.equal(result.error, null);
|
|
28
|
+
assert.equal(result.title, "RSC article");
|
|
29
|
+
assert.match(result.content, /RSC article content survives the loading shell/);
|
|
30
|
+
assert.match(result.content, /https:\/\/example\.com\/openapi\.json/);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
test("null Readability output falls back to local Defuddle extraction", async (t) => {
|
|
34
|
+
t.after(() => { globalThis.fetch = originalFetch; });
|
|
35
|
+
let fetchCalls = 0;
|
|
36
|
+
const article = "Useful local Defuddle fallback content with enough detail. ".repeat(20);
|
|
37
|
+
globalThis.fetch = async () => {
|
|
38
|
+
fetchCalls += 1;
|
|
39
|
+
if (fetchCalls > 1) throw new Error("Defuddle attempted a hidden network request");
|
|
40
|
+
return new Response(
|
|
41
|
+
`<!doctype html><html><head><title>Defuddle article</title></head><body><aside><main>${article}</main></aside></body></html>`,
|
|
42
|
+
{
|
|
43
|
+
status: 200,
|
|
44
|
+
headers: {
|
|
45
|
+
"content-type": "text/html",
|
|
46
|
+
link: '</openapi.json>; rel="service-desc"',
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
);
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
const result = await extractContent("https://example.com/defuddle-null", undefined, { lookup });
|
|
53
|
+
assert.equal(fetchCalls, 1);
|
|
54
|
+
assert.equal(result.error, null);
|
|
55
|
+
assert.equal(result.title, "Defuddle article");
|
|
56
|
+
assert.match(result.content, /Useful local Defuddle fallback content/);
|
|
57
|
+
assert.match(result.content, /https:\/\/example\.com\/openapi\.json/);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
test("short Readability output falls back to useful Defuddle content", async (t) => {
|
|
61
|
+
t.after(() => { globalThis.fetch = originalFetch; });
|
|
62
|
+
const article = "Useful Defuddle content after the short Readability article. ".repeat(20);
|
|
63
|
+
globalThis.fetch = async () => new Response(
|
|
64
|
+
`<!doctype html><html><head><title>Short article fallback</title></head><body><article>Loading...</article><aside><main>${article}</main></aside></body></html>`,
|
|
65
|
+
{ status: 200, headers: { "content-type": "text/html" } },
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
const result = await extractContent("https://example.com/defuddle-short", undefined, { lookup });
|
|
69
|
+
assert.equal(result.error, null);
|
|
70
|
+
assert.equal(result.title, "Short article fallback");
|
|
71
|
+
assert.match(result.content, /Useful Defuddle content after the short Readability article/);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
test("short non-RSC pages remain incomplete", async (t) => {
|
|
75
|
+
t.after(() => { globalThis.fetch = originalFetch; });
|
|
76
|
+
globalThis.fetch = async () => new Response(
|
|
77
|
+
"<!doctype html><html><head><title>Short</title></head><body><article>Loading...</article></body></html>",
|
|
78
|
+
{ status: 200, headers: { "content-type": "text/html" } },
|
|
79
|
+
);
|
|
80
|
+
|
|
81
|
+
const result = await extractContent("https://example.com/short", undefined, { lookup });
|
|
82
|
+
assert.notEqual(result.error, null);
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
test("short RSC payloads remain incomplete", async (t) => {
|
|
86
|
+
t.after(() => { globalThis.fetch = originalFetch; });
|
|
87
|
+
const payload = `23:${JSON.stringify(["$", "article", null, { children: "Short RSC content" }])}\n`;
|
|
88
|
+
globalThis.fetch = async () => new Response(
|
|
89
|
+
`<!doctype html><html><head><title>Short RSC</title></head><body><script>self.__next_f.push([1,${JSON.stringify(payload)}])</script></body></html>`,
|
|
90
|
+
{ status: 200, headers: { "content-type": "text/html" } },
|
|
91
|
+
);
|
|
92
|
+
|
|
93
|
+
const result = await extractContent("https://example.com/short-rsc", undefined, { lookup });
|
|
94
|
+
assert.notEqual(result.error, null);
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
test("background fetch notification distinguishes full, partial, and failed content", () => {
|
|
98
|
+
assert.match(indexSrc, /ok === fetched\.length\r?\n\s*\? "Full page content now available\."/);
|
|
99
|
+
assert.match(indexSrc, /ok > 0\r?\n\s*\? "Partial page content now available\."/);
|
|
100
|
+
assert.match(indexSrc, /"No page content was fetched\. Stored fetch diagnostics are available\."/);
|
|
101
|
+
assert.match(indexSrc, /Content fetched for \$\{ok\}\/\$\{fetched\.length\} URLs \[\$\{fetchId\}\]\. \$\{availability\}/);
|
|
102
|
+
});
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
// Repro + guard for the web_search Ctrl+O error-path dead-end (ronin fix).
|
|
2
|
+
//
|
|
3
|
+
// BEFORE the fix, web_search renderResult early-returned a SINGLE line on the
|
|
4
|
+
// error/cancel path (before the collapsed/expanded branch), so Ctrl+O flipped
|
|
5
|
+
// `expanded` with zero visible effect and discarded the partial results. This
|
|
6
|
+
// test pins the new behavior: the error/cancel path produces a rich, EXPANDABLE
|
|
7
|
+
// plan (>1 line, with diagnostics + a "ctrl+o to expand" hint), routed through
|
|
8
|
+
// the dep-free buildSearchErrorPlan() that index.ts.renderResult delegates to.
|
|
9
|
+
//
|
|
10
|
+
// Runner: node --test (matches the package's existing .test.mjs convention).
|
|
11
|
+
// Node >= 22.6 imports the .ts source directly (no build step).
|
|
12
|
+
|
|
13
|
+
import assert from "node:assert/strict";
|
|
14
|
+
import { readFileSync } from "node:fs";
|
|
15
|
+
import { fileURLToPath } from "node:url";
|
|
16
|
+
import { test } from "node:test";
|
|
17
|
+
|
|
18
|
+
import { buildSearchErrorPlan } from "../render-search-error.ts";
|
|
19
|
+
|
|
20
|
+
// --- fixture: a stale cancel with partial results, mirroring the user's report
|
|
21
|
+
// ("Search curation cancelled (stale)" with 2/3 queries done, one errored,
|
|
22
|
+
// browser never connected). ---
|
|
23
|
+
const staleCancel = {
|
|
24
|
+
error: "Search curation cancelled (stale).",
|
|
25
|
+
cancelled: true,
|
|
26
|
+
cancelReason: "stale",
|
|
27
|
+
browserConnected: false,
|
|
28
|
+
lastHeartbeatAgeMs: 31200,
|
|
29
|
+
queryCount: 3,
|
|
30
|
+
cancelledQueries: [
|
|
31
|
+
{ query: "z.ai API usage endpoint coding plan credits", provider: "perplexity", error: null, resultCount: 5 },
|
|
32
|
+
{ query: "z.ai GLM coding plan API key usage limits", provider: "perplexity", error: "Connection error", resultCount: 0 },
|
|
33
|
+
],
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
test("cancel/error path is NOT a dead-end single line: expanded plan has >1 line", () => {
|
|
37
|
+
const plan = buildSearchErrorPlan(staleCancel);
|
|
38
|
+
assert.notEqual(plan, null, "a cancelled result must produce a plan, not null");
|
|
39
|
+
const expanded = plan.expanded.join("\n");
|
|
40
|
+
// The dead-end was exactly ONE line. Pin that the expanded view is rich.
|
|
41
|
+
assert.ok(plan.expanded.length > 1, `expanded must be >1 line, got ${plan.expanded.length}`);
|
|
42
|
+
assert.match(expanded, /Search curation cancelled \(stale\)/);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
test("expanded plan surfaces the diagnostics that were previously discarded", () => {
|
|
46
|
+
const plan = buildSearchErrorPlan(staleCancel);
|
|
47
|
+
const expanded = plan.expanded.join("\n");
|
|
48
|
+
// cancel reason
|
|
49
|
+
assert.match(expanded, /cancel reason\s*:\s*stale/);
|
|
50
|
+
// browser state — the #1 stale cause, previously invisible
|
|
51
|
+
assert.match(expanded, /browser\s*:\s*never connected/);
|
|
52
|
+
// query progress (2 of 3 done)
|
|
53
|
+
assert.match(expanded, /queries started\s*:\s*3/);
|
|
54
|
+
assert.match(expanded, /queries done\s*:\s*2/);
|
|
55
|
+
// per-query results: the completed one (with source count) AND the errored one
|
|
56
|
+
assert.match(expanded, /z\.ai API usage endpoint/);
|
|
57
|
+
assert.match(expanded, /5 sources/);
|
|
58
|
+
assert.match(expanded, /\[err\]/);
|
|
59
|
+
assert.match(expanded, /Connection error/);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
test("collapsed view is a short summary WITH a ctrl+o expand hint (Ctrl+O now does something)", () => {
|
|
63
|
+
const plan = buildSearchErrorPlan(staleCancel);
|
|
64
|
+
// collapsed preview summarizes progress + browser state
|
|
65
|
+
const collapsed = plan.collapsed.join("\n");
|
|
66
|
+
assert.match(collapsed, /2\/3 queries completed/);
|
|
67
|
+
assert.match(collapsed, /browser never connected/);
|
|
68
|
+
// THE fix signal: an expand hint exists (the old single-line return had none,
|
|
69
|
+
// so Ctrl+O did nothing). Mutation: dropping the hint fails here.
|
|
70
|
+
assert.equal(typeof plan.expandHint, "string");
|
|
71
|
+
assert.match(plan.expandHint, /ctrl\+o to expand/i, "expand hint must mention ctrl+o");
|
|
72
|
+
// and the hint correctly counts the hidden lines
|
|
73
|
+
assert.match(plan.expandHint, /\d+ more lines/);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
test("plain (non-cancel) error stays a clean single line — no diagnostic noise", () => {
|
|
77
|
+
// A bare argument error has nothing to diagnose; it must NOT sprout fake
|
|
78
|
+
// "browser: unknown" diagnostics. Guards the gating logic in the module.
|
|
79
|
+
const plan = buildSearchErrorPlan({ error: "No query provided" });
|
|
80
|
+
assert.notEqual(plan, null);
|
|
81
|
+
assert.equal(plan.expanded.length, 1, "plain error must be a single line");
|
|
82
|
+
assert.equal(plan.collapsed.length, 0);
|
|
83
|
+
assert.equal(plan.expandHint, null, "plain error must have no expand hint");
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
// --- other tools (fetch_content / get_search_content): the same
|
|
87
|
+
// dead-end exists in their renderResults; they now reuse buildSearchErrorPlan via
|
|
88
|
+
// extraLines. These pin that non-cancel errors with detail become expandable
|
|
89
|
+
// WITHOUT provider/browser diagnostics (which are web_search-only). ---
|
|
90
|
+
|
|
91
|
+
test("fetch_content-style error (extras, no cancel) is expandable without browser diagnostics", () => {
|
|
92
|
+
const plan = buildSearchErrorPlan({
|
|
93
|
+
error: "Failed to fetch: https://example.com/x (404)",
|
|
94
|
+
extraLines: ["urls: 1/2 succeeded", "response id: resp_abc", " \u25b8 https://example.com/x"],
|
|
95
|
+
});
|
|
96
|
+
assert.notEqual(plan, null);
|
|
97
|
+
const expanded = plan.expanded.join("\n");
|
|
98
|
+
assert.ok(plan.expanded.length > 1);
|
|
99
|
+
assert.match(expanded, /urls: 1\/2 succeeded/);
|
|
100
|
+
assert.match(expanded, /resp_abc/);
|
|
101
|
+
// MUST NOT show provider/browser diagnostics for a non-cancel error.
|
|
102
|
+
assert.doesNotMatch(expanded, /browser|cancel reason|queries started/);
|
|
103
|
+
assert.equal(typeof plan.expandHint, "string");
|
|
104
|
+
assert.match(plan.expandHint, /ctrl\+o to expand/i);
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
test("non-search error with extras shows detail without browser diagnostics", () => {
|
|
108
|
+
const plan = buildSearchErrorPlan({
|
|
109
|
+
error: "Exa search failed: connection reset",
|
|
110
|
+
extraLines: ["query: how to use p-limit concurrency"],
|
|
111
|
+
});
|
|
112
|
+
assert.notEqual(plan, null);
|
|
113
|
+
assert.match(plan.expanded.join("\n"), /query: how to use p-limit concurrency/);
|
|
114
|
+
assert.doesNotMatch(plan.expanded.join("\n"), /browser/);
|
|
115
|
+
assert.equal(typeof plan.expandHint, "string");
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
test("error with NO extras and NO cancel stays single-line", () => {
|
|
119
|
+
// e.g. fetch_content with no url — nothing to diagnose.
|
|
120
|
+
const plan = buildSearchErrorPlan({ error: "Some transient error" });
|
|
121
|
+
assert.notEqual(plan, null);
|
|
122
|
+
assert.equal(plan.expanded.length, 1);
|
|
123
|
+
assert.equal(plan.expandHint, null);
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
test("non-error result yields null so the caller falls through to the success renderer", () => {
|
|
127
|
+
assert.equal(buildSearchErrorPlan({ queryCount: 3, totalResults: 9 }), null);
|
|
128
|
+
assert.equal(buildSearchErrorPlan(undefined), null);
|
|
129
|
+
assert.equal(buildSearchErrorPlan(null), null);
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
// --- source-contract guard: index.ts web_search renderResult must DELEGATE to
|
|
133
|
+
// buildSearchErrorPlan on the error path (mutation-proof against reverting the
|
|
134
|
+
// integration back to the dead-end single-line return). ---
|
|
135
|
+
const indexPath = fileURLToPath(new URL("../index.ts", import.meta.url));
|
|
136
|
+
const indexSrc = readFileSync(indexPath, "utf8");
|
|
137
|
+
|
|
138
|
+
test("index.ts imports buildSearchErrorPlan and wires it into the web_search error path", () => {
|
|
139
|
+
assert.match(indexSrc, /import \{ buildSearchErrorPlan, type SearchErrorDetails, type SearchErrorPlan \} from "\.\/render-search-error\.ts";/);
|
|
140
|
+
// The web_search renderResult error branch must call buildSearchErrorPlan.
|
|
141
|
+
// (Mutation: reverting renderResult to `return new Text(error...)` drops this.)
|
|
142
|
+
assert.match(indexSrc, /buildSearchErrorPlan\(details as SearchErrorDetails\)/);
|
|
143
|
+
assert.match(indexSrc, /cancelledQueries/);
|
|
144
|
+
// the 2 other tools must also delegate to buildSearchErrorPlan (mutation-proof:
|
|
145
|
+
// reverting any of them to the bare single-line drops its buildSearchErrorPlan call).
|
|
146
|
+
// Count call sites: web_search + fetch_content + get_search_content = 3.
|
|
147
|
+
const callSiteCount = (indexSrc.match(/const plan = buildSearchErrorPlan\(/g) || []).length;
|
|
148
|
+
assert.equal(callSiteCount, 3, `expected 3 buildSearchErrorPlan call sites, got ${callSiteCount}`);
|
|
149
|
+
// renderSearchErrorPlan shared renderer is used by all 3.
|
|
150
|
+
const renderCount = (indexSrc.match(/return renderSearchErrorPlan\(plan, expanded, theme\)/g) || []).length;
|
|
151
|
+
assert.equal(renderCount, 3, `expected 3 renderSearchErrorPlan returns, got ${renderCount}`);
|
|
152
|
+
});
|