@asterxsk/kiln 0.4.0 → 0.4.2
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/README.md +155 -155
- package/agent/AGENTS.md +67 -67
- package/agent/README.md +5 -5
- package/agent/extensions/ask-user/index.ts +418 -418
- package/agent/extensions/ask-user/install.ps1 +27 -27
- package/agent/extensions/ask-user/install.sh +24 -24
- package/agent/extensions/ask-user/package-lock.json +769 -769
- package/agent/extensions/ask-user/package.json +19 -19
- package/agent/extensions/ask-user/prompt.ts +45 -45
- package/agent/extensions/ask-user/tsconfig.json +7 -7
- package/agent/extensions/background-terminals/docs/implementation-guide.md +942 -942
- package/agent/extensions/background-terminals/index.ts +627 -627
- package/agent/extensions/background-terminals/install.ps1 +27 -27
- package/agent/extensions/background-terminals/install.sh +24 -24
- package/agent/extensions/background-terminals/manager.test.ts +735 -735
- package/agent/extensions/background-terminals/output.test.ts +109 -109
- package/agent/extensions/background-terminals/package-lock.json +769 -769
- package/agent/extensions/background-terminals/package.json +17 -17
- package/agent/extensions/background-terminals/prompt.test.ts +125 -125
- package/agent/extensions/background-terminals/ps.test.ts +82 -82
- package/agent/extensions/background-terminals/result-delivery.test.ts +44 -44
- package/agent/extensions/background-terminals/src/domain.ts +87 -87
- package/agent/extensions/background-terminals/src/manager.ts +907 -907
- package/agent/extensions/background-terminals/src/output.ts +84 -84
- package/agent/extensions/background-terminals/src/prompt.ts +142 -142
- package/agent/extensions/background-terminals/src/result-delivery.ts +27 -27
- package/agent/extensions/background-terminals/src/runtime.ts +36 -36
- package/agent/extensions/background-terminals/src/ui/output-view.ts +79 -79
- package/agent/extensions/background-terminals/src/ui/ps.ts +621 -621
- package/agent/extensions/background-terminals/tsconfig.json +7 -7
- package/agent/extensions/destructive/README.md +31 -31
- package/agent/extensions/destructive/index.ts +88 -88
- package/agent/extensions/destructive/install.ps1 +27 -27
- package/agent/extensions/destructive/install.sh +24 -24
- package/agent/extensions/file-search/index.spec.ts +443 -443
- package/agent/extensions/file-search/index.ts +459 -459
- package/agent/extensions/file-search/install.ps1 +27 -27
- package/agent/extensions/file-search/install.sh +24 -24
- package/agent/extensions/file-search/package-lock.json +2253 -2253
- package/agent/extensions/file-search/package.json +23 -23
- package/agent/extensions/file-search/src/args.ts +122 -122
- package/agent/extensions/file-search/src/binaries.ts +422 -422
- package/agent/extensions/file-search/src/output.ts +126 -126
- package/agent/extensions/file-search/src/process.ts +146 -146
- package/agent/extensions/file-search/src/prompt.ts +52 -52
- package/agent/extensions/file-search/tsconfig.json +7 -7
- package/agent/extensions/goal/README.md +50 -50
- package/agent/extensions/goal/index.ts +155 -155
- package/agent/extensions/goal/install.ps1 +27 -27
- package/agent/extensions/goal/install.sh +24 -24
- package/agent/extensions/kiln-update/README.md +38 -25
- package/agent/extensions/kiln-update/index.ts +177 -99
- package/agent/extensions/modelconf/PLAN.md +915 -915
- package/agent/extensions/modelconf/README.md +66 -66
- package/agent/extensions/modelconf/index.ts +296 -296
- package/agent/extensions/modelconf/install.ps1 +27 -27
- package/agent/extensions/modelconf/install.sh +24 -24
- package/agent/extensions/modelconf/package-lock.json +1809 -1809
- package/agent/extensions/modelconf/package.json +13 -13
- package/agent/extensions/modelconf/src/fuzzy.ts +26 -26
- package/agent/extensions/modelconf/src/glob.ts +13 -13
- package/agent/extensions/modelconf/src/persistence.test.ts +46 -46
- package/agent/extensions/modelconf/src/persistence.ts +164 -164
- package/agent/extensions/modelconf/src/ui/ModelConfView.test.ts +75 -75
- package/agent/extensions/modelconf/src/ui/ModelConfView.ts +1101 -1101
- package/agent/extensions/modelconf/tsconfig.json +15 -15
- package/agent/extensions/pi-web-access/CHANGELOG.md +690 -690
- package/agent/extensions/pi-web-access/LICENSE +21 -21
- package/agent/extensions/pi-web-access/README.md +470 -470
- package/agent/extensions/pi-web-access/SECURITY.md +5 -5
- package/agent/extensions/pi-web-access/activity.ts +101 -101
- package/agent/extensions/pi-web-access/auth-fetch.ts +148 -148
- package/agent/extensions/pi-web-access/brightdata-unlocker.ts +272 -272
- package/agent/extensions/pi-web-access/chrome-cookies.ts +669 -669
- package/agent/extensions/pi-web-access/content-find.ts +139 -139
- package/agent/extensions/pi-web-access/credential-source.ts +191 -191
- package/agent/extensions/pi-web-access/data-uri-sanitize.ts +406 -406
- package/agent/extensions/pi-web-access/datalab-pdf-extract.ts +568 -568
- package/agent/extensions/pi-web-access/declared-web-links.ts +173 -173
- package/agent/extensions/pi-web-access/evidence/CONTRACT-EVIDENCE.md +496 -496
- package/agent/extensions/pi-web-access/evidence/contract-probe.mjs +140 -140
- package/agent/extensions/pi-web-access/exa.ts +526 -526
- package/agent/extensions/pi-web-access/extract.ts +1196 -1196
- package/agent/extensions/pi-web-access/feature-config.ts +29 -29
- package/agent/extensions/pi-web-access/fetch-params.ts +111 -111
- package/agent/extensions/pi-web-access/gemini-adc.ts +298 -298
- package/agent/extensions/pi-web-access/gemini-api.ts +353 -353
- package/agent/extensions/pi-web-access/gemini-pdf-extract.ts +108 -108
- package/agent/extensions/pi-web-access/gemini-search.ts +21 -21
- package/agent/extensions/pi-web-access/gemini-url-context.ts +128 -128
- package/agent/extensions/pi-web-access/gemini-web-config.ts +101 -101
- package/agent/extensions/pi-web-access/gemini-web.ts +487 -487
- package/agent/extensions/pi-web-access/github-api.ts +197 -197
- package/agent/extensions/pi-web-access/github-extract.ts +746 -746
- package/agent/extensions/pi-web-access/github-issue-pr.ts +700 -700
- package/agent/extensions/pi-web-access/index.ts +1737 -1737
- package/agent/extensions/pi-web-access/package-lock.json +5808 -5808
- package/agent/extensions/pi-web-access/package.json +64 -64
- package/agent/extensions/pi-web-access/page-query.ts +96 -96
- package/agent/extensions/pi-web-access/pdf-extract.ts +409 -409
- package/agent/extensions/pi-web-access/promise-try.d.ts +7 -7
- package/agent/extensions/pi-web-access/query-rewrite.ts +51 -51
- package/agent/extensions/pi-web-access/render-search-error.ts +170 -170
- package/agent/extensions/pi-web-access/rsc-extract.ts +338 -338
- package/agent/extensions/pi-web-access/search-types.ts +20 -20
- package/agent/extensions/pi-web-access/source-check.ts +282 -282
- package/agent/extensions/pi-web-access/ssrf-protection.ts +526 -526
- package/agent/extensions/pi-web-access/storage.ts +521 -521
- package/agent/extensions/pi-web-access/summary-model-scope.ts +125 -125
- package/agent/extensions/pi-web-access/test/auth-fetch.test.mjs +208 -208
- package/agent/extensions/pi-web-access/test/brightdata-unlocker.test.mjs +840 -840
- package/agent/extensions/pi-web-access/test/chrome-cookie-extraction.test.mjs +441 -441
- package/agent/extensions/pi-web-access/test/config-path.test.mjs +283 -283
- package/agent/extensions/pi-web-access/test/content-find.test.mjs +25 -25
- package/agent/extensions/pi-web-access/test/credential-source.test.mjs +118 -118
- package/agent/extensions/pi-web-access/test/data-uri-sanitize.test.mjs +210 -210
- package/agent/extensions/pi-web-access/test/datalab-pdf-extract.test.mjs +552 -552
- package/agent/extensions/pi-web-access/test/declared-web-links.test.mjs +212 -212
- package/agent/extensions/pi-web-access/test/fetch-answer-storage.test.mjs +40 -40
- package/agent/extensions/pi-web-access/test/fetch-cache-storage.test.mjs +334 -334
- package/agent/extensions/pi-web-access/test/fetch-content-domain-policy.test.mjs +95 -95
- package/agent/extensions/pi-web-access/test/fetch-modes.test.mjs +53 -53
- package/agent/extensions/pi-web-access/test/fetch-not-found-guidance.test.mjs +92 -92
- package/agent/extensions/pi-web-access/test/fetch-params.test.mjs +86 -86
- package/agent/extensions/pi-web-access/test/fetch-render-call.test.mjs +34 -34
- package/agent/extensions/pi-web-access/test/fetch-routing.test.mjs +173 -173
- package/agent/extensions/pi-web-access/test/gemini-adc-auth.test.mjs +257 -257
- package/agent/extensions/pi-web-access/test/gemini-api-transport.test.mjs +170 -170
- package/agent/extensions/pi-web-access/test/gemini-pdf-extract.test.mjs +133 -133
- package/agent/extensions/pi-web-access/test/gemini-web-cookie-opt-in.test.mjs +178 -178
- package/agent/extensions/pi-web-access/test/gemini-web-header-overflow.test.mjs +148 -148
- package/agent/extensions/pi-web-access/test/get-search-content.test.mjs +223 -223
- package/agent/extensions/pi-web-access/test/github-extract.test.mjs +378 -378
- package/agent/extensions/pi-web-access/test/github-issue-pr.test.mjs +565 -565
- package/agent/extensions/pi-web-access/test/inline-content-config.test.mjs +99 -99
- package/agent/extensions/pi-web-access/test/lazy-extract-load.test.mjs +118 -118
- package/agent/extensions/pi-web-access/test/local-video-oversize.test.mjs +52 -52
- package/agent/extensions/pi-web-access/test/package-typebox-dependency.test.mjs +50 -50
- package/agent/extensions/pi-web-access/test/page-query.test.mjs +51 -51
- package/agent/extensions/pi-web-access/test/pdf-config.test.mjs +140 -140
- package/agent/extensions/pi-web-access/test/pdf-extract.test.mjs +500 -500
- package/agent/extensions/pi-web-access/test/proxy-transport.test.mjs +286 -286
- package/agent/extensions/pi-web-access/test/query-rewrite.test.mjs +52 -52
- package/agent/extensions/pi-web-access/test/rsc-fallback.test.mjs +102 -102
- package/agent/extensions/pi-web-access/test/search-error-render.test.mjs +152 -152
- package/agent/extensions/pi-web-access/test/search-providers.test.mjs +274 -274
- package/agent/extensions/pi-web-access/test/source-check.test.mjs +179 -179
- package/agent/extensions/pi-web-access/test/ssrf-allow-ranges-config.test.mjs +205 -205
- package/agent/extensions/pi-web-access/test/ssrf-protection.test.mjs +456 -456
- package/agent/extensions/pi-web-access/test/summary-model-scope.test.mjs +106 -106
- package/agent/extensions/pi-web-access/test/tool-registration-config.test.mjs +182 -182
- package/agent/extensions/pi-web-access/test/web-search-answer-render.test.mjs +66 -66
- package/agent/extensions/pi-web-access/test/youtube-extract-errors.test.mjs +64 -64
- package/agent/extensions/pi-web-access/tsconfig.json +11 -11
- package/agent/extensions/pi-web-access/utils.ts +451 -451
- package/agent/extensions/pi-web-access/video-extract.ts +392 -392
- package/agent/extensions/pi-web-access/youtube-extract.ts +328 -328
- package/agent/extensions/shared/activity-status.ts +31 -31
- package/agent/extensions/shared/child-session.test.ts +270 -270
- package/agent/extensions/shared/child-session.ts +148 -148
- package/agent/extensions/shared/context-utilization.test.ts +48 -48
- package/agent/extensions/shared/context-utilization.ts +47 -47
- package/agent/extensions/shared/dashboard-state.ts +99 -99
- package/agent/extensions/shared/install.ps1 +27 -27
- package/agent/extensions/shared/install.sh +24 -24
- package/agent/extensions/shared/tool-call-timeout.test.ts +117 -117
- package/agent/extensions/shared/tool-call-timeout.ts +104 -104
- package/agent/extensions/skillsconf/README.md +74 -74
- package/agent/extensions/skillsconf/index.ts +92 -92
- package/agent/extensions/skillsconf/install.ps1 +27 -27
- package/agent/extensions/skillsconf/install.sh +24 -24
- package/agent/extensions/skillsconf/package-lock.json +1809 -1809
- package/agent/extensions/skillsconf/package.json +18 -18
- package/agent/extensions/skillsconf/src/delete-skill.test.ts +64 -64
- package/agent/extensions/skillsconf/src/delete-skill.ts +45 -45
- package/agent/extensions/skillsconf/src/filter.test.ts +80 -80
- package/agent/extensions/skillsconf/src/filter.ts +74 -74
- package/agent/extensions/skillsconf/src/fuzzy.ts +26 -26
- package/agent/extensions/skillsconf/src/persistence.test.ts +72 -72
- package/agent/extensions/skillsconf/src/persistence.ts +169 -169
- package/agent/extensions/skillsconf/src/ui/SkillConfView.test.ts +337 -337
- package/agent/extensions/skillsconf/src/ui/SkillConfView.ts +758 -758
- package/agent/extensions/skillsconf/src/ui/text-input.ts +91 -91
- package/agent/extensions/skillsconf/src/ui/tui-helpers.ts +144 -144
- package/agent/extensions/skillsconf/tsconfig.json +15 -15
- package/agent/extensions/statusline/index.ts +273 -282
- package/agent/extensions/statusline/install.ps1 +27 -27
- package/agent/extensions/statusline/install.sh +24 -24
- package/agent/extensions/subagents/by-the-way.test.ts +29 -29
- package/agent/extensions/subagents/claude.test.ts +119 -119
- package/agent/extensions/subagents/codex.test.ts +102 -102
- package/agent/extensions/subagents/context-usage.test.ts +107 -107
- package/agent/extensions/subagents/docs/design-plan.md +568 -568
- package/agent/extensions/subagents/docs/effect-v4-extension-guide.md +354 -354
- package/agent/extensions/subagents/docs/effect-v4-notes.md +571 -571
- package/agent/extensions/subagents/index.ts +779 -779
- package/agent/extensions/subagents/install.ps1 +27 -27
- package/agent/extensions/subagents/install.sh +24 -24
- package/agent/extensions/subagents/manager.test.ts +276 -276
- package/agent/extensions/subagents/package-lock.json +2244 -2244
- package/agent/extensions/subagents/package.json +19 -19
- package/agent/extensions/subagents/result-delivery.test.ts +27 -27
- package/agent/extensions/subagents/src/backend.ts +73 -73
- package/agent/extensions/subagents/src/backends/claude.ts +701 -701
- package/agent/extensions/subagents/src/backends/codex.ts +1060 -1060
- package/agent/extensions/subagents/src/backends/pi.ts +575 -575
- package/agent/extensions/subagents/src/backends/stub.ts +300 -300
- package/agent/extensions/subagents/src/by-the-way.ts +21 -21
- package/agent/extensions/subagents/src/domain.ts +253 -253
- package/agent/extensions/subagents/src/format.ts +74 -74
- package/agent/extensions/subagents/src/manager.ts +736 -736
- package/agent/extensions/subagents/src/prompt.ts +92 -92
- package/agent/extensions/subagents/src/result-delivery.ts +20 -20
- package/agent/extensions/subagents/src/runtime.ts +53 -53
- package/agent/extensions/subagents/src/ui/takeover.ts +583 -583
- package/agent/extensions/subagents/src/ui/transcript.ts +201 -201
- package/agent/extensions/subagents/takeover.test.ts +29 -29
- package/agent/extensions/subagents/tsconfig.json +7 -7
- package/agent/extensions/todo/AGENTS.md +38 -38
- package/agent/extensions/todo/LICENSE +21 -21
- package/agent/extensions/todo/config.ts +55 -55
- package/agent/extensions/todo/index.ts +151 -151
- package/agent/extensions/todo/install.ps1 +27 -27
- package/agent/extensions/todo/install.sh +24 -24
- package/agent/extensions/todo/locales/de.json +17 -17
- package/agent/extensions/todo/locales/en.json +15 -15
- package/agent/extensions/todo/locales/es.json +17 -17
- package/agent/extensions/todo/locales/fr.json +17 -17
- package/agent/extensions/todo/locales/pt-BR.json +17 -17
- package/agent/extensions/todo/locales/pt.json +17 -17
- package/agent/extensions/todo/locales/ru.json +17 -17
- package/agent/extensions/todo/locales/uk.json +17 -17
- package/agent/extensions/todo/locales/zh.json +17 -17
- package/agent/extensions/todo/package-lock.json +3358 -3358
- package/agent/extensions/todo/package.json +67 -67
- package/agent/extensions/todo/state/i18n-bridge.ts +64 -64
- package/agent/extensions/todo/state/invariants.ts +20 -20
- package/agent/extensions/todo/state/replay.ts +38 -38
- package/agent/extensions/todo/state/selectors.ts +107 -107
- package/agent/extensions/todo/state/state-reducer.ts +326 -326
- package/agent/extensions/todo/state/state.ts +18 -18
- package/agent/extensions/todo/state/store.ts +82 -82
- package/agent/extensions/todo/state/task-graph.ts +57 -57
- package/agent/extensions/todo/todo-overlay.ts +200 -200
- package/agent/extensions/todo/todo.ts +155 -155
- package/agent/extensions/todo/tool/response-envelope.ts +109 -109
- package/agent/extensions/todo/tool/types.ts +206 -206
- package/agent/extensions/todo/view/format.ts +177 -177
- package/agent/extensions/trim-context/README.md +54 -54
- package/agent/extensions/trim-context/index.ts +487 -487
- package/agent/extensions/trim-context/install.ps1 +27 -27
- package/agent/extensions/trim-context/install.sh +24 -24
- package/agent/keybindings.json +7 -7
- package/agent/version.txt +1 -1
- package/bin/kiln.js +20 -13
- package/package.json +1 -1
- package/agent/extensions/taste/index.ts +0 -443
- package/agent/extensions/taste/install.ps1 +0 -27
- package/agent/extensions/taste/install.sh +0 -24
|
@@ -1,52 +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
|
-
});
|
|
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
|
+
});
|
|
@@ -1,102 +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
|
-
});
|
|
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
|
+
});
|
|
@@ -1,152 +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
|
-
});
|
|
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
|
+
});
|