ceulen 0.5.0 → 0.7.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/CHANGELOG.md +317 -12
- package/README.md +87 -91
- package/extensions/lib/advisor-marker.ts +33 -0
- package/extensions/lib/panel.ts +25 -2
- package/extensions/lib/rate.ts +24 -0
- package/extensions/lib/registry.ts +93 -7
- package/extensions/lib/tools.ts +47 -0
- package/extensions/lib/usage-store.ts +33 -0
- package/extensions/modules/advisor/commands/advisor.ts +244 -0
- package/extensions/modules/advisor/configPanel.ts +194 -0
- package/extensions/modules/advisor/index.ts +217 -0
- package/extensions/modules/advisor/lib/config.ts +248 -0
- package/extensions/modules/advisor/lib/emission-guard.ts +153 -0
- package/extensions/modules/advisor/lib/isolated-model.ts +160 -0
- package/extensions/modules/advisor/lib/model-picker.ts +47 -0
- package/extensions/modules/advisor/lib/watcher.ts +286 -0
- package/extensions/modules/advisor/test/compliance.test.ts +125 -0
- package/extensions/modules/advisor/test/config.test.ts +202 -0
- package/extensions/modules/advisor/test/configPanel.test.ts +223 -0
- package/extensions/modules/advisor/test/emission-guard.test.ts +201 -0
- package/extensions/modules/advisor/test/isolated-model.test.ts +311 -0
- package/extensions/modules/advisor/test/model-picker.test.ts +32 -0
- package/extensions/modules/advisor/test/module.test.ts +586 -0
- package/extensions/modules/advisor/test/watcher.test.ts +478 -0
- package/extensions/modules/classifier/configPanel.ts +104 -0
- package/extensions/modules/classifier/index.ts +297 -0
- package/extensions/modules/classifier/lib/settings.ts +95 -0
- package/extensions/modules/classifier/test/classifier.test.ts +475 -0
- package/extensions/modules/composer/index.ts +152 -3
- package/extensions/modules/composer/lib/footer.ts +119 -0
- package/extensions/modules/composer/lib/shapes.ts +265 -26
- package/extensions/modules/composer/test/editor.test.ts +1 -1
- package/extensions/modules/composer/test/footer.test.ts +96 -0
- package/extensions/modules/composer/test/module.test.ts +113 -11
- package/extensions/modules/composer/test/screen.test.ts +29 -1
- package/extensions/modules/composer/test/shapes.test.ts +224 -8
- package/extensions/modules/config/defaultTools.ts +96 -0
- package/extensions/modules/config/index.ts +147 -7
- package/extensions/modules/config/piSettings.ts +254 -69
- package/extensions/modules/config/test/defaultTools.test.ts +122 -0
- package/extensions/modules/config/test/menu.test.ts +64 -0
- package/extensions/modules/config/test/panel.test.ts +38 -23
- package/extensions/modules/config/test/piSettings.test.ts +130 -3
- package/extensions/modules/config/test/renderTools.test.ts +71 -0
- package/extensions/modules/config/test/tools.test.ts +146 -0
- package/extensions/modules/fff/index.ts +2094 -0
- package/extensions/modules/fff/lib/query.ts +129 -0
- package/extensions/modules/fff/test/index.test.ts +607 -0
- package/extensions/modules/fff/test/query.test.ts +71 -0
- package/extensions/modules/munin/configPanel.ts +105 -0
- package/extensions/modules/munin/index.ts +641 -0
- package/extensions/modules/munin/lib/helpers.ts +471 -0
- package/extensions/modules/munin/lib/retry.ts +20 -0
- package/extensions/modules/munin/lib/sdk.ts +218 -0
- package/extensions/modules/munin/test/config.test.ts +168 -0
- package/extensions/modules/munin/test/configPanel.test.ts +161 -0
- package/extensions/modules/munin/test/extension.test.ts +224 -0
- package/extensions/modules/munin/test/helpers.test.ts +523 -0
- package/extensions/modules/munin/test/retry.test.ts +145 -0
- package/extensions/modules/munin/test/stale-protocol.test.ts +554 -0
- package/extensions/modules/plan/configPanel.ts +152 -0
- package/extensions/modules/plan/index.ts +917 -0
- package/extensions/modules/plan/lib/plan-tools.ts +72 -0
- package/extensions/modules/plan/lib/prompt.ts +65 -0
- package/extensions/modules/plan/lib/settings.ts +166 -0
- package/extensions/modules/plan/lib/shell-gate.ts +200 -0
- package/extensions/modules/plan/test/configPanel.test.ts +96 -0
- package/extensions/modules/plan/test/harness.ts +133 -0
- package/extensions/modules/plan/test/module.test.ts +305 -0
- package/extensions/modules/plan/test/settings.test.ts +114 -0
- package/extensions/modules/plan/test/shell-gate.test.ts +103 -0
- package/extensions/modules/ponytail/index.ts +23 -73
- package/extensions/modules/ponytail/lib/config.ts +1 -6
- package/extensions/modules/ponytail/test/extension.test.ts +1 -85
- package/extensions/modules/repair/configPanel.ts +96 -0
- package/extensions/modules/repair/index.ts +414 -0
- package/extensions/modules/repair/lib/auto-bg.ts +333 -0
- package/extensions/modules/repair/lib/edit-repair.ts +155 -0
- package/extensions/modules/repair/lib/editor.ts +251 -0
- package/extensions/modules/repair/lib/guards.ts +34 -0
- package/extensions/modules/repair/lib/input-repair.ts +324 -0
- package/extensions/modules/repair/lib/patch.ts +481 -0
- package/extensions/modules/repair/lib/settings.ts +114 -0
- package/extensions/modules/repair/test/auto-bg.test.ts +405 -0
- package/extensions/modules/repair/test/edit-repair.test.ts +224 -0
- package/extensions/modules/repair/test/editor.test.ts +141 -0
- package/extensions/modules/repair/test/guards.test.ts +64 -0
- package/extensions/modules/repair/test/input-repair.test.ts +231 -0
- package/extensions/modules/repair/test/patch.test.ts +563 -0
- package/extensions/modules/repair/test/settings.test.ts +167 -0
- package/extensions/modules/repair/test/wrapper.test.ts +210 -0
- package/extensions/modules/router/commands/commands.ts +4 -0
- package/extensions/modules/router/lib/client.ts +61 -0
- package/extensions/modules/router/lib/provider.ts +34 -13
- package/extensions/modules/router/lib/systemone.ts +152 -0
- package/extensions/modules/router/test/unit.test.ts +179 -0
- package/extensions/modules/rtk/findFallback.js +68 -0
- package/extensions/modules/rtk/index.ts +248 -0
- package/extensions/modules/rtk/safe-rewrite.js +74 -0
- package/extensions/modules/rtk/test/findFallback.test.js +66 -0
- package/extensions/modules/rtk/test/index.test.js +131 -0
- package/extensions/modules/rtk/test/safe-rewrite.test.js +96 -0
- package/extensions/modules/rtk/version-gate.js +34 -0
- package/extensions/modules/serena/index.ts +629 -0
- package/extensions/modules/serena/lib/detect.ts +73 -0
- package/extensions/modules/serena/lib/env.ts +76 -0
- package/extensions/modules/serena/lib/guidance.ts +26 -0
- package/extensions/modules/serena/lib/normalize.ts +27 -0
- package/extensions/modules/serena/lib/symbol-key.ts +20 -0
- package/extensions/modules/serena/lib/truncate.ts +20 -0
- package/extensions/modules/serena/test/env.test.ts +122 -0
- package/extensions/modules/serena/test/index.test.ts +347 -0
- package/extensions/modules/serena/test/worker.test.ts +562 -0
- package/extensions/modules/serena/worker.ts +858 -0
- package/extensions/modules/steering/configPanel.ts +122 -0
- package/extensions/modules/steering/index.ts +616 -0
- package/extensions/modules/steering/lib/anchor.ts +175 -0
- package/extensions/modules/steering/lib/errors.ts +253 -0
- package/extensions/modules/steering/lib/family.ts +33 -0
- package/extensions/modules/steering/lib/guidance.ts +172 -0
- package/extensions/modules/steering/lib/history.ts +170 -0
- package/extensions/modules/steering/lib/settings.ts +127 -0
- package/extensions/modules/steering/test/anchor-regressions.test.ts +93 -0
- package/extensions/modules/steering/test/anchor-wiring.test.ts +99 -0
- package/extensions/modules/steering/test/anchor.test.ts +160 -0
- package/extensions/modules/steering/test/cache-stats.test.ts +43 -0
- package/extensions/modules/steering/test/errors.test.ts +309 -0
- package/extensions/modules/steering/test/family.test.ts +43 -0
- package/extensions/modules/steering/test/guidance.test.ts +357 -0
- package/extensions/modules/steering/test/harness.ts +93 -0
- package/extensions/modules/steering/test/history.test.ts +118 -0
- package/extensions/modules/steering/test/settings.test.ts +182 -0
- package/extensions/modules/steering/test/status.test.ts +71 -0
- package/extensions/modules/steering/test/toolCall.test.ts +99 -0
- package/extensions/modules/subagent/agents/planner.md +14 -0
- package/extensions/modules/subagent/agents/reviewer.md +42 -0
- package/extensions/modules/subagent/agents/scout.md +47 -0
- package/extensions/modules/subagent/agents/tester.md +12 -0
- package/extensions/modules/subagent/agents/worker.md +18 -0
- package/extensions/modules/subagent/configPanel.ts +219 -0
- package/extensions/modules/subagent/index.ts +2451 -0
- package/extensions/modules/subagent/lib/agents.ts +408 -0
- package/extensions/modules/subagent/lib/background.ts +383 -0
- package/extensions/modules/subagent/lib/herdr.ts +1019 -0
- package/extensions/modules/subagent/lib/history.ts +126 -0
- package/extensions/modules/subagent/lib/model.ts +156 -0
- package/extensions/modules/subagent/lib/render.ts +335 -0
- package/extensions/modules/subagent/lib/result.ts +110 -0
- package/extensions/modules/subagent/lib/roles.ts +296 -0
- package/extensions/modules/subagent/lib/routing.ts +223 -0
- package/extensions/modules/subagent/lib/runner.ts +559 -0
- package/extensions/modules/subagent/lib/schema.ts +21 -0
- package/extensions/modules/subagent/lib/security.ts +752 -0
- package/extensions/modules/subagent/lib/settings.ts +159 -0
- package/extensions/modules/subagent/lib/thread-viewer.ts +319 -0
- package/extensions/modules/subagent/lib/threads.ts +135 -0
- package/extensions/modules/subagent/lib/types.ts +18 -0
- package/extensions/modules/subagent/lib/widget.ts +475 -0
- package/extensions/modules/subagent/test/configPanel.test.ts +132 -0
- package/extensions/modules/subagent/test/herdr-advisor.test.ts +40 -0
- package/extensions/modules/subagent/test/routing.test.ts +350 -0
- package/extensions/modules/subagent/test/widget.test.ts +208 -0
- package/extensions/modules/usage/index.ts +59 -16
- package/extensions/modules/usage/test/genrate.test.ts +70 -0
- package/extensions/modules/usage/test/parsers.test.ts +13 -0
- package/extensions/modules/ux/UPSTREAM +24 -0
- package/extensions/modules/ux/index.ts +393 -0
- package/extensions/modules/ux/lib/audit.ts +562 -0
- package/extensions/modules/ux/lib/config.ts +136 -0
- package/extensions/modules/ux/lib/instructions.ts +77 -0
- package/extensions/modules/ux/test/audit.test.ts +756 -0
- package/extensions/modules/ux/test/extension.test.ts +394 -0
- package/extensions/modules/ux/test/instructions.test.ts +19 -0
- package/extensions/modules/web/configPanel.ts +193 -0
- package/extensions/modules/web/index.ts +978 -0
- package/extensions/modules/web/lib/agy.ts +209 -0
- package/extensions/modules/web/lib/brave.ts +42 -0
- package/extensions/modules/web/lib/cdp.ts +686 -0
- package/extensions/modules/web/lib/chatapi.ts +101 -0
- package/extensions/modules/web/lib/chatgpt.ts +796 -0
- package/extensions/modules/web/lib/chrome.ts +328 -0
- package/extensions/modules/web/lib/config.ts +136 -0
- package/extensions/modules/web/lib/content.ts +99 -0
- package/extensions/modules/web/lib/crawl4ai.ts +172 -0
- package/extensions/modules/web/lib/extract.ts +235 -0
- package/extensions/modules/web/lib/firecrawl.ts +56 -0
- package/extensions/modules/web/lib/format.ts +197 -0
- package/extensions/modules/web/lib/gemini-auth.ts +286 -0
- package/extensions/modules/web/lib/gemini-dr.ts +338 -0
- package/extensions/modules/web/lib/gemini.ts +551 -0
- package/extensions/modules/web/lib/imageapi.ts +559 -0
- package/extensions/modules/web/lib/retry.ts +71 -0
- package/extensions/modules/web/lib/search.ts +237 -0
- package/extensions/modules/web/lib/searxng.ts +69 -0
- package/extensions/modules/web/lib/settings.ts +148 -0
- package/extensions/modules/web/scripts/cdp-smoke.ts +77 -0
- package/extensions/modules/web/scripts/gemini-smoke.ts +107 -0
- package/extensions/modules/web/test/agy.test.ts +383 -0
- package/extensions/modules/web/test/cdp.test.ts +717 -0
- package/extensions/modules/web/test/chat.test.ts +171 -0
- package/extensions/modules/web/test/chatgpt.test.ts +633 -0
- package/extensions/modules/web/test/chrome.test.ts +282 -0
- package/extensions/modules/web/test/config.test.ts +218 -0
- package/extensions/modules/web/test/configPanel.test.ts +132 -0
- package/extensions/modules/web/test/crawl.test.ts +134 -0
- package/extensions/modules/web/test/crawl4ai.test.ts +105 -0
- package/extensions/modules/web/test/extension.test.ts +118 -0
- package/extensions/modules/web/test/extract.test.ts +436 -0
- package/extensions/modules/web/test/fixtures/dr-confirm.bin +12 -0
- package/extensions/modules/web/test/fixtures/dr-plan.bin +20 -0
- package/extensions/modules/web/test/fixtures/interaction.html +31 -0
- package/extensions/modules/web/test/format.test.ts +230 -0
- package/extensions/modules/web/test/gemini-auth.test.ts +465 -0
- package/extensions/modules/web/test/gemini-dr.test.ts +249 -0
- package/extensions/modules/web/test/gemini.test.ts +472 -0
- package/extensions/modules/web/test/hook.test.ts +101 -0
- package/extensions/modules/web/test/image.test.ts +1089 -0
- package/extensions/modules/web/test/retry.test.ts +119 -0
- package/extensions/modules/web/test/screenshot.test.ts +109 -0
- package/extensions/modules/web/test/search.test.ts +210 -0
- package/extensions/modules/web/test/settings.test.ts +165 -0
- package/extensions/modules/web/test/skill.test.ts +72 -0
- package/extensions/modules/web/types.d.ts +3 -0
- package/extensions/modules/web/vendor/package.json +1 -0
- package/extensions/modules/web/vendor/readability/LICENSE.md +13 -0
- package/extensions/modules/web/vendor/readability/Readability-readerable.js +123 -0
- package/extensions/modules/web/vendor/readability/Readability.js +2787 -0
- package/extensions/modules/web/vendor/readability/index.d.ts +64 -0
- package/extensions/modules/web/vendor/readability/index.js +9 -0
- package/extensions/modules/web/vendor/turndown/LICENSE +21 -0
- package/extensions/modules/web/vendor/turndown/turndown.cjs.js +784 -0
- package/extensions/modules/web/vendor/turndown-plugin-gfm/LICENSE +21 -0
- package/extensions/modules/web/vendor/turndown-plugin-gfm/turndown-plugin-gfm.cjs.js +163 -0
- package/extensions/modules/zai/configPanel.ts +151 -0
- package/extensions/modules/zai/index.ts +186 -0
- package/extensions/modules/zai/lib/anthropic.ts +159 -0
- package/extensions/modules/zai/lib/settings.ts +198 -0
- package/extensions/modules/zai/lib/signing.ts +718 -0
- package/extensions/modules/zai/lib/throttle.ts +198 -0
- package/extensions/modules/zai/test/anthropic.test.ts +132 -0
- package/extensions/modules/zai/test/configPanel.test.ts +207 -0
- package/extensions/modules/zai/test/extension.test.ts +249 -0
- package/extensions/modules/zai/test/settings.test.ts +183 -0
- package/extensions/modules/zai/test/signing-wiring.test.ts +108 -0
- package/extensions/modules/zai/test/signing.test.ts +345 -0
- package/extensions/modules/zai/test/throttle.test.ts +329 -0
- package/package.json +19 -4
- package/scripts/validate-themes.mjs +75 -0
- package/skills/munin/SKILL.md +117 -0
- package/skills/ux-capture/SKILL.md +202 -0
- package/skills/ux-design/SKILL.md +279 -0
- package/skills/ux-presets/SKILL.md +484 -0
- package/skills/ux-routing/SKILL.md +46 -0
- package/skills/web/SKILL.md +153 -0
- package/themes/alabaster.json +93 -0
- package/themes/amethyst.json +96 -0
- package/themes/anthracite.json +93 -0
- package/themes/basalt.json +91 -0
- package/themes/birch.json +95 -0
- package/themes/catppuccin-mocha.json +91 -0
- package/themes/dark-abyss.json +91 -0
- package/themes/dark-arctic.json +104 -0
- package/themes/dark-aurora.json +95 -0
- package/themes/dark-catppuccin.json +107 -0
- package/themes/dark-cavern.json +91 -0
- package/themes/dark-celestial.json +106 -0
- package/themes/dark-copper.json +95 -0
- package/themes/dark-cosmos.json +90 -0
- package/themes/dark-cyberpunk.json +102 -0
- package/themes/dark-dracula.json +98 -0
- package/themes/dark-eclipse.json +91 -0
- package/themes/dark-ember.json +95 -0
- package/themes/dark-equinox.json +90 -0
- package/themes/dark-forest.json +96 -0
- package/themes/dark-github.json +105 -0
- package/themes/dark-gruvbox.json +112 -0
- package/themes/dark-lavender.json +95 -0
- package/themes/dark-lunar.json +89 -0
- package/themes/dark-midnight.json +95 -0
- package/themes/dark-monochrome.json +94 -0
- package/themes/dark-monokai.json +98 -0
- package/themes/dark-nebula.json +90 -0
- package/themes/dark-neon-noir.json +100 -0
- package/themes/dark-nord.json +98 -0
- package/themes/dark-ocean.json +101 -0
- package/themes/dark-one.json +100 -0
- package/themes/dark-poimandres.json +115 -0
- package/themes/dark-rainforest.json +91 -0
- package/themes/dark-reef.json +91 -0
- package/themes/dark-retro.json +92 -0
- package/themes/dark-rose-pine.json +96 -0
- package/themes/dark-sakura.json +95 -0
- package/themes/dark-slate.json +95 -0
- package/themes/dark-solarized.json +97 -0
- package/themes/dark-solstice.json +90 -0
- package/themes/dark-starfall.json +91 -0
- package/themes/dark-sunset.json +99 -0
- package/themes/dark-swamp.json +90 -0
- package/themes/dark-synthwave.json +103 -0
- package/themes/dark-taiga.json +91 -0
- package/themes/dark-terminal.json +95 -0
- package/themes/dark-tokyo-night.json +101 -0
- package/themes/dark-tundra.json +91 -0
- package/themes/dark-twilight.json +91 -0
- package/themes/dark-volcanic.json +91 -0
- package/themes/dark.json +80 -0
- package/themes/graphite.json +92 -0
- package/themes/light-arctic.json +107 -0
- package/themes/light-aurora-day.json +91 -0
- package/themes/light-canyon.json +91 -0
- package/themes/light-catppuccin.json +106 -0
- package/themes/light-cirrus.json +90 -0
- package/themes/light-coral.json +95 -0
- package/themes/light-cyberpunk.json +96 -0
- package/themes/light-dawn.json +90 -0
- package/themes/light-dunes.json +91 -0
- package/themes/light-eucalyptus.json +95 -0
- package/themes/light-forest.json +100 -0
- package/themes/light-frost.json +95 -0
- package/themes/light-github.json +115 -0
- package/themes/light-glacier.json +91 -0
- package/themes/light-gruvbox.json +108 -0
- package/themes/light-haze.json +90 -0
- package/themes/light-honeycomb.json +95 -0
- package/themes/light-lagoon.json +91 -0
- package/themes/light-lavender.json +95 -0
- package/themes/light-meadow.json +91 -0
- package/themes/light-mint.json +95 -0
- package/themes/light-monochrome.json +101 -0
- package/themes/light-ocean.json +99 -0
- package/themes/light-one.json +99 -0
- package/themes/light-opal.json +91 -0
- package/themes/light-orchard.json +91 -0
- package/themes/light-paper.json +95 -0
- package/themes/light-poimandres.json +115 -0
- package/themes/light-prism.json +90 -0
- package/themes/light-retro.json +98 -0
- package/themes/light-sand.json +95 -0
- package/themes/light-savanna.json +91 -0
- package/themes/light-solarized.json +102 -0
- package/themes/light-soleil.json +90 -0
- package/themes/light-sunset.json +99 -0
- package/themes/light-synthwave.json +98 -0
- package/themes/light-tokyo-night.json +111 -0
- package/themes/light-wetland.json +91 -0
- package/themes/light-zenith.json +89 -0
- package/themes/light.json +80 -0
- package/themes/limestone.json +94 -0
- package/themes/mahogany.json +97 -0
- package/themes/marble.json +93 -0
- package/themes/mirage.json +79 -0
- package/themes/obsidian.json +91 -0
- package/themes/onyx.json +91 -0
- package/themes/pearl.json +93 -0
- package/themes/porcelain.json +91 -0
- package/themes/quartz.json +96 -0
- package/themes/sandstone.json +95 -0
- package/themes/titanium.json +90 -0
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unit tests for the local Chrome capture engine (lib/chrome.ts).
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { describe, it, beforeEach, afterEach } from "node:test";
|
|
6
|
+
import assert from "node:assert/strict";
|
|
7
|
+
import { chmodSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
|
8
|
+
import { tmpdir } from "node:os";
|
|
9
|
+
import path from "node:path";
|
|
10
|
+
import {
|
|
11
|
+
buildPdfArgs,
|
|
12
|
+
buildScreenshotArgs,
|
|
13
|
+
capturePdf,
|
|
14
|
+
captureScreenshot,
|
|
15
|
+
findChromeBinary,
|
|
16
|
+
isLocalUrl,
|
|
17
|
+
isSsrfBlocked,
|
|
18
|
+
resolveEngine,
|
|
19
|
+
} from "../lib/chrome";
|
|
20
|
+
|
|
21
|
+
// chai-compat helpers (assert-based)
|
|
22
|
+
function includes(haystack: unknown, needle: unknown): boolean {
|
|
23
|
+
if (typeof haystack === "string") return haystack.includes(String(needle));
|
|
24
|
+
if (Array.isArray(haystack)) return (haystack as unknown[]).some((v) => {
|
|
25
|
+
if (typeof v === "string" && typeof needle === "string") return v.includes(needle);
|
|
26
|
+
if (v === needle) return true;
|
|
27
|
+
// chai's to.include on an array does DEEP membership for objects.
|
|
28
|
+
if (v && needle && typeof v === "object" && typeof needle === "object") {
|
|
29
|
+
try { assert.deepStrictEqual(v, needle); return true; } catch { return false; }
|
|
30
|
+
}
|
|
31
|
+
return false;
|
|
32
|
+
});
|
|
33
|
+
// chai's to.include on an OBJECT target: needle's properties are a subset.
|
|
34
|
+
if (haystack && typeof haystack === "object" && needle && typeof needle === "object") {
|
|
35
|
+
return deepIncludes(haystack, needle as Record<string, unknown>);
|
|
36
|
+
}
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
function lengthOf(v: unknown): number {
|
|
40
|
+
if (Array.isArray(v)) return v.length;
|
|
41
|
+
if (typeof v === "string") return v.length;
|
|
42
|
+
if (v && typeof v === "object" && "length" in (v as Record<string, unknown>)) return Number((v as Record<string, unknown>).length);
|
|
43
|
+
if (v && typeof v === "object" && "size" in (v as Record<string, unknown>)) return Number((v as Record<string, unknown>).size);
|
|
44
|
+
throw new Error("lengthOf: value has no length/size");
|
|
45
|
+
}
|
|
46
|
+
/** Deep "includes" — every own key of `part` must exist on `obj` with a
|
|
47
|
+
* deep-equal value (chai's to.deep.include for object subjects). */
|
|
48
|
+
function deepIncludes(obj: unknown, part: Record<string, unknown>): boolean {
|
|
49
|
+
if (Array.isArray(obj)) return includes(obj, part); // deep membership
|
|
50
|
+
if (typeof obj !== "object" || obj === null) return false;
|
|
51
|
+
return Object.entries(part).every(([k, v]) => {
|
|
52
|
+
try { assert.deepStrictEqual((obj as Record<string, unknown>)[k], v); return true; } catch { return false; }
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
describe("isLocalUrl", () => {
|
|
57
|
+
const local = [
|
|
58
|
+
"http://localhost:3000",
|
|
59
|
+
"http://localhost",
|
|
60
|
+
"https://app.localhost:5173",
|
|
61
|
+
"http://127.0.0.1:8080",
|
|
62
|
+
"http://10.1.2.3/",
|
|
63
|
+
"http://172.16.0.1/",
|
|
64
|
+
"http://172.31.255.255/",
|
|
65
|
+
"http://192.168.1.50:4200",
|
|
66
|
+
"http://169.254.1.1/",
|
|
67
|
+
"http://0.0.0.0/",
|
|
68
|
+
"http://[::1]:8080",
|
|
69
|
+
"http://[fd00::1]:3000",
|
|
70
|
+
"http://[fe80::1]:3000",
|
|
71
|
+
"http://[::ffff:127.0.0.1]:8080",
|
|
72
|
+
"http://[::ffff:7f00:1]:8080", // hex form — WHATWG URL canonicalization shape
|
|
73
|
+
"http://[::ffff:169.254.169.254]/",
|
|
74
|
+
"http://[::ffff:10.0.0.5]/",
|
|
75
|
+
"file:///Users/me/project/index.html",
|
|
76
|
+
];
|
|
77
|
+
for (const url of local) {
|
|
78
|
+
it(`local: ${url}`, () => {
|
|
79
|
+
assert.equal(isLocalUrl(url), true);
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const remote = [
|
|
84
|
+
"https://example.com",
|
|
85
|
+
"http://8.8.8.8/",
|
|
86
|
+
"http://172.32.0.1/",
|
|
87
|
+
"http://192.169.1.1/",
|
|
88
|
+
"http://[2001:db8::1]/",
|
|
89
|
+
"https://developer.chrome.com/blog",
|
|
90
|
+
"not a url",
|
|
91
|
+
];
|
|
92
|
+
for (const url of remote) {
|
|
93
|
+
it(`remote: ${url}`, () => {
|
|
94
|
+
assert.equal(isLocalUrl(url), false);
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
describe("resolveEngine", () => {
|
|
100
|
+
it("auto routes localhost to local", () => {
|
|
101
|
+
assert.equal(resolveEngine("auto", "http://localhost:3000"), "local");
|
|
102
|
+
assert.equal(resolveEngine(undefined, "http://127.0.0.1:8080"), "local");
|
|
103
|
+
assert.equal(resolveEngine(undefined, "file:///tmp/x.html"), "local");
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it("auto routes public URLs to daemon", () => {
|
|
107
|
+
assert.equal(resolveEngine("auto", "https://example.com"), "daemon");
|
|
108
|
+
assert.equal(resolveEngine(undefined, "https://example.com"), "daemon");
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
it("explicit engine wins over URL class", () => {
|
|
112
|
+
assert.equal(resolveEngine("local", "https://example.com"), "local");
|
|
113
|
+
assert.equal(resolveEngine("daemon", "http://localhost:3000"), "daemon");
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
describe("isSsrfBlocked", () => {
|
|
118
|
+
it("matches daemon SSRF rejections", () => {
|
|
119
|
+
assert.equal(isSsrfBlocked(new Error("URL blocked (SSRF protection)")), true);
|
|
120
|
+
assert.equal(isSsrfBlocked(new Error("request failed: SSRF protection triggered")), true);
|
|
121
|
+
assert.equal(isSsrfBlocked(new Error("connection refused")), false);
|
|
122
|
+
assert.equal(isSsrfBlocked("URL blocked by policy"), true);
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
describe("buildScreenshotArgs", () => {
|
|
127
|
+
const base = {
|
|
128
|
+
chromePath: "/usr/bin/chrome",
|
|
129
|
+
outPath: "/tmp/out.png",
|
|
130
|
+
userDataDir: "/tmp/profile",
|
|
131
|
+
url: "http://localhost:3000",
|
|
132
|
+
width: 1280,
|
|
133
|
+
height: 800,
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
it("builds headless screenshot command with defaults", () => {
|
|
137
|
+
const args = buildScreenshotArgs(base);
|
|
138
|
+
assert.equal(args[0], "/usr/bin/chrome");
|
|
139
|
+
assert.ok(includes(args, "--headless"));
|
|
140
|
+
assert.ok(includes(args, "--window-size=1280,800"));
|
|
141
|
+
assert.ok(includes(args, "--screenshot=/tmp/out.png"));
|
|
142
|
+
assert.ok(includes(args, "--user-data-dir=/tmp/profile"));
|
|
143
|
+
assert.equal(args[args.length - 1], "http://localhost:3000");
|
|
144
|
+
assert.ok(!includes(args.join(" "), "virtual-time-budget"));
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
it("fullPage uses the tall-window ceiling", () => {
|
|
148
|
+
const args = buildScreenshotArgs({ ...base, fullPage: true });
|
|
149
|
+
assert.ok(includes(args, "--window-size=1280,8000"));
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
it("waitForSec maps to virtual-time-budget", () => {
|
|
153
|
+
const args = buildScreenshotArgs({ ...base, waitForSec: 2.5 });
|
|
154
|
+
assert.ok(includes(args, "--virtual-time-budget=2500"));
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
it("reducedMotion forces the prefers-reduced-motion flag", () => {
|
|
158
|
+
assert.ok(!includes(buildScreenshotArgs({ ...base }), "--force-prefers-reduced-motion"));
|
|
159
|
+
assert.ok(includes(buildScreenshotArgs({ ...base, reducedMotion: true }), "--force-prefers-reduced-motion"));
|
|
160
|
+
});
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
describe("buildPdfArgs", () => {
|
|
164
|
+
it("builds print-to-pdf command without headers", () => {
|
|
165
|
+
const args = buildPdfArgs({
|
|
166
|
+
chromePath: "/usr/bin/chrome",
|
|
167
|
+
outPath: "/tmp/out.pdf",
|
|
168
|
+
userDataDir: "/tmp/profile",
|
|
169
|
+
url: "http://localhost:3000",
|
|
170
|
+
});
|
|
171
|
+
assert.ok(includes(args, "--print-to-pdf=/tmp/out.pdf"));
|
|
172
|
+
assert.ok(includes(args, "--no-pdf-header-footer"));
|
|
173
|
+
assert.ok(!includes(args, "--force-prefers-reduced-motion"));
|
|
174
|
+
assert.equal(args[args.length - 1], "http://localhost:3000");
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
it("reducedMotion forces the prefers-reduced-motion flag", () => {
|
|
178
|
+
const args = buildPdfArgs({
|
|
179
|
+
chromePath: "/usr/bin/chrome",
|
|
180
|
+
outPath: "/tmp/out.pdf",
|
|
181
|
+
userDataDir: "/tmp/profile",
|
|
182
|
+
url: "http://localhost:3000",
|
|
183
|
+
reducedMotion: true,
|
|
184
|
+
});
|
|
185
|
+
assert.ok(includes(args, "--force-prefers-reduced-motion"));
|
|
186
|
+
});
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
describe("findChromeBinary", () => {
|
|
190
|
+
it("prefers CHROME_PATH when it exists", () => {
|
|
191
|
+
const fake = process.argv[0]; // some path that definitely exists
|
|
192
|
+
process.env.CHROME_PATH = fake;
|
|
193
|
+
try {
|
|
194
|
+
assert.equal(findChromeBinary(), fake);
|
|
195
|
+
} finally {
|
|
196
|
+
delete process.env.CHROME_PATH;
|
|
197
|
+
}
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
it("falls through when CHROME_PATH does not exist", () => {
|
|
201
|
+
process.env.CHROME_PATH = "/nonexistent/chrome-binary-xyz";
|
|
202
|
+
try {
|
|
203
|
+
// On a dev machine with Chrome installed this finds the real binary;
|
|
204
|
+
// in CI it returns null. Either way it must not return the bad path.
|
|
205
|
+
const found = findChromeBinary();
|
|
206
|
+
assert.notEqual(found, "/nonexistent/chrome-binary-xyz");
|
|
207
|
+
} finally {
|
|
208
|
+
delete process.env.CHROME_PATH;
|
|
209
|
+
}
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
it("returns a string or null", () => {
|
|
213
|
+
const found = findChromeBinary();
|
|
214
|
+
assert.equal(found === null || typeof found === "string", true);
|
|
215
|
+
});
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
describe("capture URL trust boundary", () => {
|
|
219
|
+
it("rejects switch-like URLs before any spawn", async () => {
|
|
220
|
+
try {
|
|
221
|
+
await captureScreenshot({ url: "--proxy-server=http://evil", timeoutMs: 500 });
|
|
222
|
+
assert.fail("should have thrown");
|
|
223
|
+
} catch (err: any) {
|
|
224
|
+
assert.ok(includes(err.message, "Invalid capture URL"));
|
|
225
|
+
assert.ok(!includes(err.message, "Chrome"));
|
|
226
|
+
}
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
it("rejects non-http/file schemes for PDF too", async () => {
|
|
230
|
+
try {
|
|
231
|
+
await capturePdf({ url: "chrome://settings", timeoutMs: 500 });
|
|
232
|
+
assert.fail("should have thrown");
|
|
233
|
+
} catch (err: any) {
|
|
234
|
+
assert.ok(includes(err.message, "Invalid capture URL"));
|
|
235
|
+
}
|
|
236
|
+
});
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
describe("runChrome via stub binary", () => {
|
|
240
|
+
const PAYLOAD = "FAKEPNGDATA";
|
|
241
|
+
let dir: string;
|
|
242
|
+
|
|
243
|
+
const writeStub = (body: string): string => {
|
|
244
|
+
const p = path.join(dir, `stub-${Math.random().toString(36).slice(2)}.sh`);
|
|
245
|
+
writeFileSync(p, `#!/bin/sh\n${body}\n`);
|
|
246
|
+
chmodSync(p, 0o755);
|
|
247
|
+
return p;
|
|
248
|
+
};
|
|
249
|
+
|
|
250
|
+
// Stub contract: writes the --screenshot= target, then (optionally) hangs.
|
|
251
|
+
const writeAndMaybeHang = (hang: boolean): string =>
|
|
252
|
+
writeStub(
|
|
253
|
+
`for a in "$@"; do case "$a" in --screenshot=*) out="\${a#--screenshot=}" ;; esac; done\n` +
|
|
254
|
+
`printf '${PAYLOAD}' > "$out"\n` +
|
|
255
|
+
(hang ? "sleep 30\n" : ""),
|
|
256
|
+
);
|
|
257
|
+
|
|
258
|
+
beforeEach(() => {
|
|
259
|
+
dir = mkdtempSync(path.join(tmpdir(), "pi-web-chrome-test-"));
|
|
260
|
+
});
|
|
261
|
+
|
|
262
|
+
afterEach(() => {
|
|
263
|
+
delete process.env.CHROME_PATH;
|
|
264
|
+
rmSync(dir, { recursive: true, force: true });
|
|
265
|
+
});
|
|
266
|
+
|
|
267
|
+
it("resolves via the file-stability poll even when the binary never exits", async () => {
|
|
268
|
+
process.env.CHROME_PATH = writeAndMaybeHang(true); // writes, then sleeps forever
|
|
269
|
+
const cap = await captureScreenshot({ url: "http://localhost:9/x", timeoutMs: 10_000 });
|
|
270
|
+
assert.equal(cap.base64, Buffer.from(PAYLOAD).toString("base64"));
|
|
271
|
+
});
|
|
272
|
+
|
|
273
|
+
it("rejects on timeout when no output file appears", async () => {
|
|
274
|
+
process.env.CHROME_PATH = writeStub("sleep 30"); // never writes
|
|
275
|
+
try {
|
|
276
|
+
await captureScreenshot({ url: "http://localhost:9/x", timeoutMs: 700 });
|
|
277
|
+
assert.fail("should have timed out");
|
|
278
|
+
} catch (err: any) {
|
|
279
|
+
assert.ok(includes(err.message, "timed out"));
|
|
280
|
+
}
|
|
281
|
+
});
|
|
282
|
+
});
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unit tests for pi-web config module.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { describe, it, beforeEach, afterEach } from "node:test";
|
|
6
|
+
import assert from "node:assert/strict";
|
|
7
|
+
import { createRequire } from "node:module";
|
|
8
|
+
import {
|
|
9
|
+
findEnvValue,
|
|
10
|
+
normalizeSearxngBaseUrl,
|
|
11
|
+
normalizeFirecrawlBaseUrl,
|
|
12
|
+
normalizeCrawl4aiApiUrl,
|
|
13
|
+
loadCrawl4aiConfig,
|
|
14
|
+
DEFAULT_SEARXNG_BASE_URL,
|
|
15
|
+
DEFAULT_CRAWL4AI_API_URL,
|
|
16
|
+
HOSTED_FIRECRAWL_BASE_URL,
|
|
17
|
+
} from "../lib/config";
|
|
18
|
+
|
|
19
|
+
// The web settings layer reads the agent-dir settings.json — isolate it so a
|
|
20
|
+
// host `web` section (real timeouts/keys) never leaks into these unit tests.
|
|
21
|
+
process.env.PI_CODING_AGENT_DIR = "/nonexistent-pi-agent-dir-for-web-tests";
|
|
22
|
+
|
|
23
|
+
// chai-compat helpers (assert-based)
|
|
24
|
+
function includes(haystack: unknown, needle: unknown): boolean {
|
|
25
|
+
if (typeof haystack === "string") return haystack.includes(String(needle));
|
|
26
|
+
if (Array.isArray(haystack)) return (haystack as unknown[]).some((v) => {
|
|
27
|
+
if (typeof v === "string" && typeof needle === "string") return v.includes(needle);
|
|
28
|
+
if (v === needle) return true;
|
|
29
|
+
// chai's to.include on an array does DEEP membership for objects.
|
|
30
|
+
if (v && needle && typeof v === "object" && typeof needle === "object") {
|
|
31
|
+
try { assert.deepStrictEqual(v, needle); return true; } catch { return false; }
|
|
32
|
+
}
|
|
33
|
+
return false;
|
|
34
|
+
});
|
|
35
|
+
// chai's to.include on an OBJECT target: needle's properties are a subset.
|
|
36
|
+
if (haystack && typeof haystack === "object" && needle && typeof needle === "object") {
|
|
37
|
+
return deepIncludes(haystack, needle as Record<string, unknown>);
|
|
38
|
+
}
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
function lengthOf(v: unknown): number {
|
|
42
|
+
if (Array.isArray(v)) return v.length;
|
|
43
|
+
if (typeof v === "string") return v.length;
|
|
44
|
+
if (v && typeof v === "object" && "length" in (v as Record<string, unknown>)) return Number((v as Record<string, unknown>).length);
|
|
45
|
+
if (v && typeof v === "object" && "size" in (v as Record<string, unknown>)) return Number((v as Record<string, unknown>).size);
|
|
46
|
+
throw new Error("lengthOf: value has no length/size");
|
|
47
|
+
}
|
|
48
|
+
/** Deep "includes" — every own key of `part` must exist on `obj` with a
|
|
49
|
+
* deep-equal value (chai's to.deep.include for object subjects). */
|
|
50
|
+
function deepIncludes(obj: unknown, part: Record<string, unknown>): boolean {
|
|
51
|
+
if (Array.isArray(obj)) return includes(obj, part); // deep membership
|
|
52
|
+
if (typeof obj !== "object" || obj === null) return false;
|
|
53
|
+
return Object.entries(part).every(([k, v]) => {
|
|
54
|
+
try { assert.deepStrictEqual((obj as Record<string, unknown>)[k], v); return true; } catch { return false; }
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
describe("normalizeSearxngBaseUrl", () => {
|
|
59
|
+
it("returns default when nothing provided", () => {
|
|
60
|
+
assert.equal(normalizeSearxngBaseUrl(), DEFAULT_SEARXNG_BASE_URL);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it("preserves full URL with scheme", () => {
|
|
64
|
+
assert.equal(normalizeSearxngBaseUrl("https://search.example.com"),
|
|
65
|
+
"https://search.example.com",
|
|
66
|
+
);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it("adds http for localhost", () => {
|
|
70
|
+
assert.equal(normalizeSearxngBaseUrl("localhost:8888"),
|
|
71
|
+
"http://localhost:8888",
|
|
72
|
+
);
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it("adds http for private IP", () => {
|
|
76
|
+
assert.equal(normalizeSearxngBaseUrl("192.168.1.1:8888"),
|
|
77
|
+
"http://192.168.1.1:8888",
|
|
78
|
+
);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it("adds https for public hostname", () => {
|
|
82
|
+
assert.equal(normalizeSearxngBaseUrl("search.example.com"),
|
|
83
|
+
"https://search.example.com",
|
|
84
|
+
);
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it("removes trailing slashes", () => {
|
|
88
|
+
assert.equal(normalizeSearxngBaseUrl("http://localhost:8888/"),
|
|
89
|
+
"http://localhost:8888",
|
|
90
|
+
);
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
describe("normalizeFirecrawlBaseUrl", () => {
|
|
95
|
+
it("returns hosted default when nothing provided", () => {
|
|
96
|
+
assert.equal(normalizeFirecrawlBaseUrl(), HOSTED_FIRECRAWL_BASE_URL);
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it("appends /v2 if no version segment", () => {
|
|
100
|
+
assert.equal(normalizeFirecrawlBaseUrl("http://localhost:3002"), "http://localhost:3002/v2");
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
it("preserves existing version segment", () => {
|
|
104
|
+
assert.equal(normalizeFirecrawlBaseUrl("http://localhost:3002/v1"), "http://localhost:3002/v1");
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it("removes trailing slash before appending version", () => {
|
|
108
|
+
assert.equal(normalizeFirecrawlBaseUrl("http://localhost:3002/"), "http://localhost:3002/v2");
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
describe("findEnvValue", () => {
|
|
113
|
+
it("reads from process.env first", () => {
|
|
114
|
+
process.env.TEST_PI_WEB_VAR = "from_process";
|
|
115
|
+
try {
|
|
116
|
+
const result = findEnvValue("TEST_PI_WEB_VAR", "/tmp", false);
|
|
117
|
+
assert.equal(result.value, "from_process");
|
|
118
|
+
assert.equal(result.source, "env");
|
|
119
|
+
} finally {
|
|
120
|
+
delete process.env.TEST_PI_WEB_VAR;
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
it("returns undefined when not found", () => {
|
|
125
|
+
const result = findEnvValue("THIS_VAR_DOES_NOT_EXIST_12345", "/tmp", false);
|
|
126
|
+
assert.equal(result.value, undefined);
|
|
127
|
+
assert.equal(result.source, "");
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
describe("normalizeCrawl4aiApiUrl", () => {
|
|
132
|
+
it("returns default when nothing provided", () => {
|
|
133
|
+
assert.equal(normalizeCrawl4aiApiUrl(), DEFAULT_CRAWL4AI_API_URL);
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
it("preserves full URL with scheme", () => {
|
|
137
|
+
assert.equal(normalizeCrawl4aiApiUrl("https://crawl.example.com"),
|
|
138
|
+
"https://crawl.example.com",
|
|
139
|
+
);
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
it("adds http for private IP", () => {
|
|
143
|
+
assert.equal(normalizeCrawl4aiApiUrl("172.30.55.22:11235"),
|
|
144
|
+
"http://172.30.55.22:11235",
|
|
145
|
+
);
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
it("adds https for public hostname", () => {
|
|
149
|
+
assert.equal(normalizeCrawl4aiApiUrl("crawl.example.com"),
|
|
150
|
+
"https://crawl.example.com",
|
|
151
|
+
);
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
it("removes trailing slashes", () => {
|
|
155
|
+
assert.equal(normalizeCrawl4aiApiUrl("http://localhost:11235/"),
|
|
156
|
+
"http://localhost:11235",
|
|
157
|
+
);
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
it("does not append /v2 like Firecrawl", () => {
|
|
161
|
+
assert.equal(normalizeCrawl4aiApiUrl("http://localhost:11235"),
|
|
162
|
+
"http://localhost:11235",
|
|
163
|
+
);
|
|
164
|
+
});
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
describe("loadCrawl4aiConfig", () => {
|
|
168
|
+
it("returns default config from defaults", () => {
|
|
169
|
+
// Hermetic: findEnvValue reads process.env AND piConfigDirs() (~/.pi/agent/.env)
|
|
170
|
+
// even with includeCwd=false, so point PI_CODING_AGENT_DIR at an empty dir
|
|
171
|
+
// and clear the ambient var — the default-assertion must not inherit either.
|
|
172
|
+
const _require = createRequire(import.meta.url);
|
|
173
|
+
const { mkdtempSync } = _require("node:fs");
|
|
174
|
+
const { tmpdir } = _require("node:os");
|
|
175
|
+
const { join } = _require("node:path");
|
|
176
|
+
const emptyDir = mkdtempSync(join(tmpdir(), "pi-web-cfg-"));
|
|
177
|
+
const savedDir = process.env.PI_CODING_AGENT_DIR;
|
|
178
|
+
const savedUrl = process.env.CRAWL4AI_API_URL;
|
|
179
|
+
delete process.env.CRAWL4AI_API_URL;
|
|
180
|
+
process.env.PI_CODING_AGENT_DIR = emptyDir;
|
|
181
|
+
try {
|
|
182
|
+
const config = loadCrawl4aiConfig({}, "/tmp", false);
|
|
183
|
+
assert.equal(config.baseUrl, DEFAULT_CRAWL4AI_API_URL);
|
|
184
|
+
assert.equal(config.timeoutMs, 60000);
|
|
185
|
+
} finally {
|
|
186
|
+
if (savedDir !== undefined) process.env.PI_CODING_AGENT_DIR = savedDir;
|
|
187
|
+
else delete process.env.PI_CODING_AGENT_DIR;
|
|
188
|
+
if (savedUrl !== undefined) process.env.CRAWL4AI_API_URL = savedUrl;
|
|
189
|
+
}
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
it("accepts explicit API URL from params", () => {
|
|
193
|
+
const config = loadCrawl4aiConfig(
|
|
194
|
+
{ crawl4ai_api_url: "http://custom:12345" },
|
|
195
|
+
"/tmp",
|
|
196
|
+
false,
|
|
197
|
+
);
|
|
198
|
+
assert.equal(config.baseUrl, "http://custom:12345");
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
it("accepts explicit API token from params", () => {
|
|
202
|
+
const config = loadCrawl4aiConfig(
|
|
203
|
+
{ crawl4ai_api_token: "my-token" },
|
|
204
|
+
"/tmp",
|
|
205
|
+
false,
|
|
206
|
+
);
|
|
207
|
+
assert.equal(config.apiToken, "my-token");
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
it("reads timeout from params", () => {
|
|
211
|
+
const config = loadCrawl4aiConfig({ timeout_ms: 30000 }, "/tmp", false);
|
|
212
|
+
assert.equal(config.timeoutMs, 30000);
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
it("throws on invalid timeout", () => {
|
|
216
|
+
assert.throws(() => loadCrawl4aiConfig({ timeout_ms: 500 }, "/tmp", false));
|
|
217
|
+
});
|
|
218
|
+
});
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
// web's /config contribution: 16 rows over a `web.`-prefixed key set, masked
|
|
2
|
+
// secrets, save that writes only changed fields to the global settings.json.
|
|
3
|
+
|
|
4
|
+
import { describe, it } from "node:test";
|
|
5
|
+
import assert from "node:assert/strict";
|
|
6
|
+
import fs from "node:fs";
|
|
7
|
+
import os from "node:os";
|
|
8
|
+
import path from "node:path";
|
|
9
|
+
|
|
10
|
+
import { buildWebGroups, readWebRowValues, webConfig } from "../configPanel";
|
|
11
|
+
import { writeWebSection } from "../lib/settings";
|
|
12
|
+
|
|
13
|
+
function tmpAgentDir(): string {
|
|
14
|
+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), "web-panel-"));
|
|
15
|
+
process.env.PI_CODING_AGENT_DIR = dir;
|
|
16
|
+
return dir;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function withEnv(key: string, value: string | undefined, fn: () => void): void {
|
|
20
|
+
const old = process.env[key];
|
|
21
|
+
if (value === undefined) delete process.env[key];
|
|
22
|
+
else process.env[key] = value;
|
|
23
|
+
try {
|
|
24
|
+
fn();
|
|
25
|
+
} finally {
|
|
26
|
+
if (old === undefined) delete process.env[key];
|
|
27
|
+
else process.env[key] = old;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
describe("web configPanel", () => {
|
|
32
|
+
it("16 rows, all keys web.-prefixed, secrets masked", () => {
|
|
33
|
+
const groups = buildWebGroups({});
|
|
34
|
+
assert.equal(groups.length, 1);
|
|
35
|
+
assert.equal(groups[0]!.label, "Web");
|
|
36
|
+
assert.equal(groups[0]!.tab, "Tools");
|
|
37
|
+
assert.equal(groups[0]!.icon, "🌍");
|
|
38
|
+
const rows = groups[0]!.rows;
|
|
39
|
+
assert.equal(rows.length, 16);
|
|
40
|
+
for (const r of rows) assert.ok(r.key.startsWith("web."), r.key);
|
|
41
|
+
const masked = rows.filter((r) => r.mask);
|
|
42
|
+
assert.equal(masked.length, 7);
|
|
43
|
+
for (const r of masked) assert.ok(/key|token|cookie/i.test(r.label), `secret row: ${r.label}`);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it("readWebRowValues: env wins, settings fallback, empty default", () => {
|
|
47
|
+
const dir = tmpAgentDir();
|
|
48
|
+
try {
|
|
49
|
+
withEnv("BRAVE_API_KEY", "env-key", () => {
|
|
50
|
+
writeWebSection({ "brave.apiKey": "settings-key", "chat.apiKey": "chat-key" }, path.join(dir, "settings.json"));
|
|
51
|
+
const values = readWebRowValues("/nonexistent-project", false);
|
|
52
|
+
assert.deepEqual(values["brave.apiKey"], { value: "env-key", source: "env" });
|
|
53
|
+
assert.deepEqual(values["chat.apiKey"], { value: "chat-key", source: "global settings" });
|
|
54
|
+
assert.deepEqual(values["gemini.proxy"], { value: "", source: "default" });
|
|
55
|
+
});
|
|
56
|
+
} finally {
|
|
57
|
+
fs.rmSync(dir, { recursive: true, force: true });
|
|
58
|
+
delete process.env.PI_CODING_AGENT_DIR;
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it("timeout rows are a CLOSED SET so an invalid value can't brick a tool", () => {
|
|
63
|
+
// Live-found regression: a free-text 30 (ms) makes load*Config throw
|
|
64
|
+
// ("must be an integer >= 1000"), disabling every Firecrawl/Crawl4AI tool.
|
|
65
|
+
const groups = buildWebGroups({});
|
|
66
|
+
for (const key of ["web.firecrawl.timeoutMs", "web.crawl4ai.timeoutMs"]) {
|
|
67
|
+
const row = groups[0]!.rows.find((r) => r.key === key)!;
|
|
68
|
+
const opts = row.menu?.() ?? [];
|
|
69
|
+
assert.ok(opts.length >= 4, `${key} offers timed options`);
|
|
70
|
+
for (const o of opts) assert.ok(Number(o.value) >= 1000, `${key} option ${o.value} >= 1000ms`);
|
|
71
|
+
assert.ok(opts.some((o) => o.value === "60000"), `${key} includes the 60s default`);
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it("rows mutate the working copy; set() accepts numbers for number rows", () => {
|
|
76
|
+
const groups = buildWebGroups({ "firecrawl.timeoutMs": "60000" });
|
|
77
|
+
const row = groups[0]!.rows.find((r) => r.key === "web.firecrawl.timeoutMs")!;
|
|
78
|
+
assert.equal(row.kind, "number");
|
|
79
|
+
row.set(30000);
|
|
80
|
+
assert.equal(row.value, 30000);
|
|
81
|
+
const secret = groups[0]!.rows.find((r) => r.key === "web.brave.apiKey")!;
|
|
82
|
+
secret.set("typed");
|
|
83
|
+
assert.equal(secret.value, "typed");
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
it("save no-ops unless a web.* key was edited", async () => {
|
|
87
|
+
const dir = tmpAgentDir();
|
|
88
|
+
try {
|
|
89
|
+
const cfg = webConfig();
|
|
90
|
+
const notifications: string[] = [];
|
|
91
|
+
const ctx = { cwd: "/nonexistent", ui: { notify: (m: string) => notifications.push(m) }, isProjectTrusted: () => false } as never;
|
|
92
|
+
await cfg.save(new Set(["munin.apiKey"]), ctx);
|
|
93
|
+
assert.equal(notifications.length, 0);
|
|
94
|
+
assert.ok(!fs.existsSync(path.join(dir, "settings.json")));
|
|
95
|
+
} finally {
|
|
96
|
+
fs.rmSync(dir, { recursive: true, force: true });
|
|
97
|
+
delete process.env.PI_CODING_AGENT_DIR;
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
it("save writes ONLY changed fields and discloses env overrides", async () => {
|
|
102
|
+
const dir = tmpAgentDir();
|
|
103
|
+
const old = process.env.BRAVE_API_KEY;
|
|
104
|
+
process.env.BRAVE_API_KEY = "still-from-env";
|
|
105
|
+
try {
|
|
106
|
+
// Working copy built from effective values: env value shown for brave.
|
|
107
|
+
const cfg = webConfig();
|
|
108
|
+
const groups = cfg.groups();
|
|
109
|
+
const brave = groups[0]!.rows.find((r) => r.key === "web.brave.apiKey")!;
|
|
110
|
+
assert.equal(brave.value, "still-from-env");
|
|
111
|
+
// User changes two rows (one env-backed, one plain).
|
|
112
|
+
brave.set("panel-key");
|
|
113
|
+
const timeout = groups[0]!.rows.find((r) => r.key === "web.crawl4ai.timeoutMs")!;
|
|
114
|
+
timeout.set(45000);
|
|
115
|
+
const notifications: string[] = [];
|
|
116
|
+
const ctx = { cwd: "/nonexistent", ui: { notify: (m: string) => notifications.push(m) }, isProjectTrusted: () => false } as never;
|
|
117
|
+
await cfg.save(new Set(["web.brave.apiKey", "web.crawl4ai.timeoutMs"]), ctx);
|
|
118
|
+
const raw = JSON.parse(fs.readFileSync(path.join(dir, "settings.json"), "utf8"));
|
|
119
|
+
assert.equal(raw.web["brave.apiKey"], "panel-key");
|
|
120
|
+
assert.equal(raw.web["crawl4ai.timeoutMs"], 45000);
|
|
121
|
+
assert.equal(Object.keys(raw.web).length, 2, "only changed keys written");
|
|
122
|
+
const note = notifications.join(" ");
|
|
123
|
+
assert.ok(note.includes("settings.json"), note);
|
|
124
|
+
assert.ok(note.includes("BRAVE_API_KEY"), "env override disclosed");
|
|
125
|
+
} finally {
|
|
126
|
+
if (old === undefined) delete process.env.BRAVE_API_KEY;
|
|
127
|
+
else process.env.BRAVE_API_KEY = old;
|
|
128
|
+
fs.rmSync(dir, { recursive: true, force: true });
|
|
129
|
+
delete process.env.PI_CODING_AGENT_DIR;
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
});
|