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,717 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unit tests for the CDP interaction engine (lib/cdp.ts).
|
|
3
|
+
*
|
|
4
|
+
* Pure helpers are tested directly; runInteraction runs end-to-end against a
|
|
5
|
+
* fake CDP server over a fake websocket (CHROME_PATH points at a stub that
|
|
6
|
+
* writes DevToolsActivePort and hangs) — no real Chrome, no network.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { describe, it, beforeEach, afterEach } from "node:test";
|
|
10
|
+
import assert from "node:assert/strict";
|
|
11
|
+
import { chmodSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
|
12
|
+
import { tmpdir } from "node:os";
|
|
13
|
+
import path from "node:path";
|
|
14
|
+
|
|
15
|
+
import {
|
|
16
|
+
buildPressEvents,
|
|
17
|
+
CdpConnection,
|
|
18
|
+
readDevToolsPortFile,
|
|
19
|
+
runInteraction,
|
|
20
|
+
unwrapEvaluate,
|
|
21
|
+
validateSteps,
|
|
22
|
+
waitForLoad,
|
|
23
|
+
type StepOutcome,
|
|
24
|
+
type WsLike,
|
|
25
|
+
} from "../lib/cdp";
|
|
26
|
+
|
|
27
|
+
// chai-compat helpers (assert-based)
|
|
28
|
+
function includes(haystack: unknown, needle: unknown): boolean {
|
|
29
|
+
if (typeof haystack === "string") return haystack.includes(String(needle));
|
|
30
|
+
if (Array.isArray(haystack)) return (haystack as unknown[]).some((v) => {
|
|
31
|
+
if (typeof v === "string" && typeof needle === "string") return v.includes(needle);
|
|
32
|
+
if (v === needle) return true;
|
|
33
|
+
// chai's to.include on an array does DEEP membership for objects.
|
|
34
|
+
if (v && needle && typeof v === "object" && typeof needle === "object") {
|
|
35
|
+
try { assert.deepStrictEqual(v, needle); return true; } catch { return false; }
|
|
36
|
+
}
|
|
37
|
+
return false;
|
|
38
|
+
});
|
|
39
|
+
// chai's to.include on an OBJECT target: needle's properties are a subset.
|
|
40
|
+
if (haystack && typeof haystack === "object" && needle && typeof needle === "object") {
|
|
41
|
+
return deepIncludes(haystack, needle as Record<string, unknown>);
|
|
42
|
+
}
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
function lengthOf(v: unknown): number {
|
|
46
|
+
if (Array.isArray(v)) return v.length;
|
|
47
|
+
if (typeof v === "string") return v.length;
|
|
48
|
+
if (v && typeof v === "object" && "length" in (v as Record<string, unknown>)) return Number((v as Record<string, unknown>).length);
|
|
49
|
+
if (v && typeof v === "object" && "size" in (v as Record<string, unknown>)) return Number((v as Record<string, unknown>).size);
|
|
50
|
+
throw new Error("lengthOf: value has no length/size");
|
|
51
|
+
}
|
|
52
|
+
/** Deep "includes" — every own key of `part` must exist on `obj` with a
|
|
53
|
+
* deep-equal value (chai's to.deep.include for object subjects). */
|
|
54
|
+
function deepIncludes(obj: unknown, part: Record<string, unknown>): boolean {
|
|
55
|
+
if (Array.isArray(obj)) return includes(obj, part); // deep membership
|
|
56
|
+
if (typeof obj !== "object" || obj === null) return false;
|
|
57
|
+
return Object.entries(part).every(([k, v]) => {
|
|
58
|
+
try { assert.deepStrictEqual((obj as Record<string, unknown>)[k], v); return true; } catch { return false; }
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// ── Fake websocket that speaks just enough CDP for the tests ─────────────
|
|
63
|
+
|
|
64
|
+
class FakeWs implements WsLike {
|
|
65
|
+
sent: Array<Record<string, any>> = [];
|
|
66
|
+
onSend: ((frame: Record<string, any>) => void) | null = null;
|
|
67
|
+
private listeners = new Map<string, Array<(ev?: { data?: unknown }) => void>>();
|
|
68
|
+
|
|
69
|
+
addEventListener(type: string, fn: (ev?: { data?: unknown }) => void) {
|
|
70
|
+
if (!this.listeners.has(type)) this.listeners.set(type, []);
|
|
71
|
+
this.listeners.get(type)!.push(fn);
|
|
72
|
+
// A real websocket emits "open" once connected — fake it immediately.
|
|
73
|
+
if (type === "open") queueMicrotask(() => this.emit("open"));
|
|
74
|
+
}
|
|
75
|
+
removeEventListener(type: string, fn: (ev?: { data?: unknown }) => void) {
|
|
76
|
+
this.listeners.set(type, (this.listeners.get(type) ?? []).filter((f) => f !== fn));
|
|
77
|
+
}
|
|
78
|
+
send(data: string) {
|
|
79
|
+
const frame = JSON.parse(data);
|
|
80
|
+
this.sent.push(frame);
|
|
81
|
+
if (this.onSend) queueMicrotask(() => this.onSend!(frame));
|
|
82
|
+
}
|
|
83
|
+
close() {
|
|
84
|
+
this.emit("close");
|
|
85
|
+
}
|
|
86
|
+
emit(type: string, ev?: { data?: unknown }) {
|
|
87
|
+
for (const fn of this.listeners.get(type) ?? []) fn(ev);
|
|
88
|
+
}
|
|
89
|
+
reply(id: number, result: Record<string, unknown>) {
|
|
90
|
+
this.emit("message", { data: JSON.stringify({ id, result }) });
|
|
91
|
+
}
|
|
92
|
+
replyError(id: number, message: string) {
|
|
93
|
+
this.emit("message", { data: JSON.stringify({ id, error: { message } }) });
|
|
94
|
+
}
|
|
95
|
+
event(method: string, params: Record<string, unknown>, sessionId?: string) {
|
|
96
|
+
this.emit("message", { data: JSON.stringify({ method, params, sessionId }) });
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** Wire a FakeWs with canned CDP responses for a standard successful run. */
|
|
101
|
+
function fakeCdpServer(ws: FakeWs) {
|
|
102
|
+
ws.onSend = (frame) => {
|
|
103
|
+
const { method, id, params } = frame;
|
|
104
|
+
if (method === "Target.createTarget") ws.reply(id, { targetId: "t1" });
|
|
105
|
+
else if (method === "Target.attachToTarget") ws.reply(id, { sessionId: "s1" });
|
|
106
|
+
else if (method === "Page.navigate") {
|
|
107
|
+
ws.reply(id, { frameId: "f1" });
|
|
108
|
+
// Real Chrome fires frameNavigated for the initial main-frame navigation.
|
|
109
|
+
ws.event("Page.frameNavigated", { frame: { url: "http://localhost:3000/" } }, "s1");
|
|
110
|
+
ws.event("Page.loadEventFired", {}, "s1");
|
|
111
|
+
} else if (method === "Runtime.evaluate") {
|
|
112
|
+
const expr = String((params as any)?.expression ?? "");
|
|
113
|
+
if (expr.includes("getBoundingClientRect")) {
|
|
114
|
+
ws.reply(id, { result: { type: "object", value: { x: 100, y: 50 } } });
|
|
115
|
+
} else if (expr.includes("scrollWidth")) {
|
|
116
|
+
ws.reply(id, { result: { type: "string", value: JSON.stringify({ scrollWidth: 390, innerWidth: 390 }) } });
|
|
117
|
+
} else {
|
|
118
|
+
ws.reply(id, { result: { type: "number", value: 2 } });
|
|
119
|
+
}
|
|
120
|
+
} else if (method === "Page.captureScreenshot") {
|
|
121
|
+
ws.reply(id, { data: "UklGRh==" });
|
|
122
|
+
} else {
|
|
123
|
+
ws.reply(id, {});
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
const rejectMsg = async (p: Promise<unknown>): Promise<string> => {
|
|
129
|
+
try {
|
|
130
|
+
await p;
|
|
131
|
+
} catch (err) {
|
|
132
|
+
return String((err as Error).message);
|
|
133
|
+
}
|
|
134
|
+
throw new Error("expected promise to reject");
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
// ── Pure helpers ─────────────────────────────────────────────────────────
|
|
138
|
+
|
|
139
|
+
describe("readDevToolsPortFile", () => {
|
|
140
|
+
let dir: string;
|
|
141
|
+
beforeEach(() => {
|
|
142
|
+
dir = mkdtempSync(path.join(tmpdir(), "pi-web-cdp-test-"));
|
|
143
|
+
});
|
|
144
|
+
afterEach(() => rmSync(dir, { recursive: true, force: true }));
|
|
145
|
+
|
|
146
|
+
it("parses port + ws path", () => {
|
|
147
|
+
writeFileSync(path.join(dir, "DevToolsActivePort"), "9222\n/devtools/browser/abc");
|
|
148
|
+
assert.deepEqual(readDevToolsPortFile(dir), { port: 9222, wsPath: "/devtools/browser/abc" });
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
it("returns null when the file is missing", () => {
|
|
152
|
+
assert.equal(readDevToolsPortFile(dir), null);
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
it("returns null on garbage (file can exist before Chrome fills it)", () => {
|
|
156
|
+
writeFileSync(path.join(dir, "DevToolsActivePort"), "");
|
|
157
|
+
assert.equal(readDevToolsPortFile(dir), null);
|
|
158
|
+
writeFileSync(path.join(dir, "DevToolsActivePort"), "not-a-port\n/x");
|
|
159
|
+
assert.equal(readDevToolsPortFile(dir), null);
|
|
160
|
+
});
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
describe("unwrapEvaluate", () => {
|
|
164
|
+
it("unwraps the nested {result:{result:{value}}} shape", () => {
|
|
165
|
+
assert.equal(unwrapEvaluate({ result: { type: "number", value: 42 } }), 42);
|
|
166
|
+
assert.equal(unwrapEvaluate({ result: { type: "string", value: "copied" } }), "copied");
|
|
167
|
+
assert.equal(unwrapEvaluate({ result: { type: "undefined" } }), undefined);
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
it("surfaces exceptionDetails loudly instead of returning undefined", () => {
|
|
171
|
+
let err: any;
|
|
172
|
+
try {
|
|
173
|
+
unwrapEvaluate({
|
|
174
|
+
result: { type: "object" },
|
|
175
|
+
exceptionDetails: { text: "Uncaught", exception: { description: "ReferenceError: x is not defined" } },
|
|
176
|
+
});
|
|
177
|
+
} catch (e) {
|
|
178
|
+
err = e;
|
|
179
|
+
}
|
|
180
|
+
assert.ok(err);
|
|
181
|
+
assert.ok(includes(String(err.message), "x is not defined"));
|
|
182
|
+
});
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
describe("buildPressEvents", () => {
|
|
186
|
+
it("maps Enter to keyDown(+text)/keyUp with the right virtual key code", () => {
|
|
187
|
+
const { down, up } = buildPressEvents("Enter");
|
|
188
|
+
assert.ok(includes(down, { type: "keyDown", code: "Enter", windowsVirtualKeyCode: 13, text: "\r" }));
|
|
189
|
+
assert.ok(includes(up, { type: "keyUp", code: "Enter", windowsVirtualKeyCode: 13 }));
|
|
190
|
+
assert.ok(((up) as any)?.hasOwnProperty?.("text") !== true);
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
it("single characters carry their text; special keys use rawKeyDown", () => {
|
|
194
|
+
const a = buildPressEvents("a");
|
|
195
|
+
assert.ok(includes(a.down, { type: "keyDown", text: "a", windowsVirtualKeyCode: 65 }));
|
|
196
|
+
const tab = buildPressEvents("Tab");
|
|
197
|
+
assert.ok(includes(tab.down, { type: "rawKeyDown", windowsVirtualKeyCode: 9 }));
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
it("digits map to Digit codes so e.code gates fire", () => {
|
|
201
|
+
const one = buildPressEvents("1");
|
|
202
|
+
assert.ok(includes(one.down, { code: "Digit1", windowsVirtualKeyCode: 49, text: "1" }));
|
|
203
|
+
assert.ok(includes(buildPressEvents("a").down, { code: "KeyA" }));
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
it("rejects unknown multi-character keys", () => {
|
|
207
|
+
assert.throws(() => buildPressEvents("CapsLock"), /unsupported key/);
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
it('"Space" alias produces identical events to " "', () => {
|
|
211
|
+
assert.deepEqual(buildPressEvents("Space"), buildPressEvents(" "));
|
|
212
|
+
});
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
describe("validateSteps", () => {
|
|
216
|
+
it("accepts well-formed steps", () => {
|
|
217
|
+
validateSteps([
|
|
218
|
+
{ click: "#btn" },
|
|
219
|
+
{ type: { selector: "#name", text: "hi" } },
|
|
220
|
+
{ press: "Enter" },
|
|
221
|
+
{ evaluate: "1+1", label: "sum" },
|
|
222
|
+
{ wait_for: "#done" },
|
|
223
|
+
{ wait_for: 250 },
|
|
224
|
+
{ dialog: "accept" },
|
|
225
|
+
{ dialog: "dismiss" },
|
|
226
|
+
{ screenshot: true },
|
|
227
|
+
]);
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
it("rejects zero or unknown action keys", () => {
|
|
231
|
+
assert.throws(() => validateSteps([{}] as any), /steps\[0\] must have exactly one action key/);
|
|
232
|
+
assert.throws(() => validateSteps([{ scroll: "#a" } as any]), /steps\[0\] must have exactly one action key/);
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
it("auto-splits multi-action steps into sequential steps, order preserved", () => {
|
|
236
|
+
const steps = [{ click: "#a", press: "Enter" }] as any[];
|
|
237
|
+
const split = validateSteps(steps);
|
|
238
|
+
assert.strictEqual(split, 1);
|
|
239
|
+
assert.deepStrictEqual(steps, [{ click: "#a" }, { press: "Enter" }]);
|
|
240
|
+
const mixed = [{ click: "#x", screenshot: true, wait_for: "#y" }] as any[];
|
|
241
|
+
assert.strictEqual(validateSteps(mixed), 1);
|
|
242
|
+
assert.deepStrictEqual(mixed, [{ click: "#x" }, { screenshot: true }, { wait_for: "#y" }]);
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
it("still rejects multi-action steps that also carry an unknown key", () => {
|
|
246
|
+
assert.throws(() => validateSteps([{ click: "#a", scroll: "#b" } as any]), /steps\[0\] must have exactly one action key/);
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
it("rejects malformed payloads", () => {
|
|
250
|
+
assert.throws(() => validateSteps([{ click: 5 } as any]), /selector string/);
|
|
251
|
+
assert.throws(() => validateSteps([{ type: { text: "x" } } as any]), /selector, text/);
|
|
252
|
+
assert.throws(() => validateSteps([{ wait_for: true } as any]), /selector string or a millisecond number/);
|
|
253
|
+
assert.throws(() => validateSteps([{ dialog: "maybe" } as any]), /"accept" or "dismiss"/);
|
|
254
|
+
});
|
|
255
|
+
});
|
|
256
|
+
|
|
257
|
+
describe("CdpConnection over a fake websocket", () => {
|
|
258
|
+
it("matches responses to requests by id and dispatches events to listeners", async () => {
|
|
259
|
+
const ws = new FakeWs();
|
|
260
|
+
const conn = await CdpConnection.connect("ws://fake", () => ws);
|
|
261
|
+
|
|
262
|
+
const events: any[] = [];
|
|
263
|
+
conn.on("Page.loadEventFired", (params, sid) => events.push({ params, sid }));
|
|
264
|
+
|
|
265
|
+
const p1 = conn.send("Target.createTarget", { url: "about:blank" });
|
|
266
|
+
const p2 = conn.send("Page.navigate", { url: "http://x/" }, "s1");
|
|
267
|
+
ws.reply(1, { targetId: "t1" });
|
|
268
|
+
ws.reply(2, { frameId: "f1" });
|
|
269
|
+
assert.deepEqual(await p1, { targetId: "t1" });
|
|
270
|
+
assert.deepEqual(await p2, { frameId: "f1" });
|
|
271
|
+
assert.ok(includes(ws.sent[0], { method: "Target.createTarget" }));
|
|
272
|
+
assert.ok(deepIncludes(ws.sent[1], { method: "Page.navigate", sessionId: "s1" }));
|
|
273
|
+
|
|
274
|
+
ws.event("Page.loadEventFired", { frameId: "f1" }, "s1");
|
|
275
|
+
assert.equal(lengthOf(events), 1);
|
|
276
|
+
assert.equal(events[0].sid, "s1");
|
|
277
|
+
|
|
278
|
+
const p3 = conn.send("Runtime.evaluate");
|
|
279
|
+
ws.replyError(3, "Bad params");
|
|
280
|
+
assert.match(String(await rejectMsg(p3)), /Bad params/);
|
|
281
|
+
|
|
282
|
+
const p4 = conn.send("Runtime.evaluate");
|
|
283
|
+
ws.close();
|
|
284
|
+
assert.match(String(await rejectMsg(p4)), /closed/);
|
|
285
|
+
});
|
|
286
|
+
|
|
287
|
+
it("waitForLoad: orphaned timer rejection is pre-handled (pi-crash regression 2026-09-20)", async () => {
|
|
288
|
+
const ws = new FakeWs();
|
|
289
|
+
const conn = await CdpConnection.connect("ws://fake", () => ws);
|
|
290
|
+
const unhandled: unknown[] = [];
|
|
291
|
+
const onUnhandled = (e: unknown) => unhandled.push(e);
|
|
292
|
+
process.on("unhandledRejection", onUnhandled);
|
|
293
|
+
// Deliberately not awaited — simulates Page.navigate rejecting first so the
|
|
294
|
+
// caller skips `await loaded`; the 20ms timer then rejects with no consumer.
|
|
295
|
+
const loaded = waitForLoad(conn, "s1", 20);
|
|
296
|
+
try {
|
|
297
|
+
await new Promise((r) => setTimeout(r, 60));
|
|
298
|
+
assert.deepEqual(unhandled, []); // unpatched: contains the timeout Error
|
|
299
|
+
} finally {
|
|
300
|
+
process.off("unhandledRejection", onUnhandled);
|
|
301
|
+
}
|
|
302
|
+
// Normal path intact: awaiting still throws (timeout still surfaces).
|
|
303
|
+
assert.match(String(await rejectMsg(loaded)), /Navigation timed out after 0\.02s/);
|
|
304
|
+
});
|
|
305
|
+
});
|
|
306
|
+
|
|
307
|
+
// ── runInteraction end-to-end against the fake CDP server ────────────────
|
|
308
|
+
|
|
309
|
+
describe("runInteraction (fake CDP server)", () => {
|
|
310
|
+
let dir: string;
|
|
311
|
+
let originalChromePath: string | undefined;
|
|
312
|
+
|
|
313
|
+
beforeEach(() => {
|
|
314
|
+
dir = mkdtempSync(path.join(tmpdir(), "pi-web-cdp-run-"));
|
|
315
|
+
originalChromePath = process.env.CHROME_PATH;
|
|
316
|
+
// Stub Chrome: publish DevToolsActivePort into the profile dir, then hang.
|
|
317
|
+
const stub = path.join(dir, "stub-chrome.sh");
|
|
318
|
+
writeFileSync(
|
|
319
|
+
stub,
|
|
320
|
+
`#!/bin/sh\nfor a in "$@"; do case "$a" in --user-data-dir=*) prof="\${a#--user-data-dir=}" ;; esac; done\n` +
|
|
321
|
+
`mkdir -p "$prof"\nprintf '9222\\n/devtools/browser/fake' > "$prof/DevToolsActivePort"\nsleep 30\n`,
|
|
322
|
+
);
|
|
323
|
+
chmodSync(stub, 0o755);
|
|
324
|
+
process.env.CHROME_PATH = stub;
|
|
325
|
+
});
|
|
326
|
+
|
|
327
|
+
afterEach(() => {
|
|
328
|
+
if (originalChromePath === undefined) delete process.env.CHROME_PATH;
|
|
329
|
+
else process.env.CHROME_PATH = originalChromePath;
|
|
330
|
+
rmSync(dir, { recursive: true, force: true });
|
|
331
|
+
});
|
|
332
|
+
|
|
333
|
+
it("runs the full lifecycle: launch, emulate, navigate, click, evaluate, probe, screenshot", async () => {
|
|
334
|
+
const ws = new FakeWs();
|
|
335
|
+
fakeCdpServer(ws);
|
|
336
|
+
const result = await runInteraction({
|
|
337
|
+
url: "http://localhost:3000/",
|
|
338
|
+
steps: [{ click: "#btn" }, { evaluate: "1+1", label: "sum" }],
|
|
339
|
+
viewport: { width: 390, height: 844 },
|
|
340
|
+
reducedMotion: true,
|
|
341
|
+
grant: ["clipboard-read"],
|
|
342
|
+
wsFactory: () => ws,
|
|
343
|
+
});
|
|
344
|
+
|
|
345
|
+
assert.deepEqual(result.outcomes.map((o) => o.ok), [true, true]);
|
|
346
|
+
assert.equal(result.outcomes[1].value, 2);
|
|
347
|
+
assert.equal(result.screenshot, "UklGRh==");
|
|
348
|
+
assert.deepEqual(result.probe, { scrollWidth: 390, innerWidth: 390 });
|
|
349
|
+
// The initial main-frame navigation must NOT be reported as a step navigation.
|
|
350
|
+
assert.equal(result.navigatedTo, undefined);
|
|
351
|
+
|
|
352
|
+
const methods = ws.sent.map((f) => f.method);
|
|
353
|
+
// Emulation before navigation (honest viewport, no entrance-animation blanks)
|
|
354
|
+
assert.ok((methods.indexOf("Emulation.setDeviceMetricsOverride")) < (methods.indexOf("Page.navigate")));
|
|
355
|
+
assert.ok((methods.indexOf("Emulation.setEmulatedMedia")) < (methods.indexOf("Page.navigate")));
|
|
356
|
+
assert.ok(includes(ws.sent.find((f) => f.method === "Emulation.setDeviceMetricsOverride")?.params, {
|
|
357
|
+
width: 390,
|
|
358
|
+
height: 844,
|
|
359
|
+
}));
|
|
360
|
+
// Trusted click at the element center over the page session
|
|
361
|
+
const pressed = ws.sent.filter((f) => f.method === "Input.dispatchMouseEvent");
|
|
362
|
+
assert.deepEqual(pressed.map((f) => f.params.type), ["mousePressed", "mouseReleased"]);
|
|
363
|
+
assert.ok(includes(pressed[0].params, { x: 100, y: 50, button: "left" }));
|
|
364
|
+
assert.equal(pressed[0].sessionId, "s1");
|
|
365
|
+
// Permissions granted at browser level (no sessionId), aliased to CDP names
|
|
366
|
+
assert.deepEqual(ws.sent.find((f) => f.method === "Browser.grantPermissions")?.params, {
|
|
367
|
+
permissions: ["clipboardReadWrite"],
|
|
368
|
+
});
|
|
369
|
+
// No screenshot step → exactly one automatic final capture
|
|
370
|
+
assert.equal(lengthOf(ws.sent.filter((f) => f.method === "Page.captureScreenshot")), 1);
|
|
371
|
+
});
|
|
372
|
+
|
|
373
|
+
it("resolves with outcomes + screenshot intact and an empty probe when the probe evaluate fails", async () => {
|
|
374
|
+
const ws = new FakeWs();
|
|
375
|
+
fakeCdpServer(ws);
|
|
376
|
+
const realOnSend = ws.onSend!;
|
|
377
|
+
ws.onSend = (frame) => {
|
|
378
|
+
// Probe evaluate (identified by its scrollWidth expression) throws.
|
|
379
|
+
if (frame.method === "Runtime.evaluate" && String(frame.params?.expression ?? "").includes("scrollWidth")) {
|
|
380
|
+
return ws.reply(frame.id, {
|
|
381
|
+
result: { type: "object" },
|
|
382
|
+
exceptionDetails: { text: "Uncaught", exception: { description: "Error: target crashed" } },
|
|
383
|
+
});
|
|
384
|
+
}
|
|
385
|
+
realOnSend(frame);
|
|
386
|
+
};
|
|
387
|
+
const result = await runInteraction({
|
|
388
|
+
url: "http://localhost:3000/",
|
|
389
|
+
steps: [{ evaluate: "1+1" }],
|
|
390
|
+
wsFactory: () => ws,
|
|
391
|
+
});
|
|
392
|
+
assert.deepEqual(result.outcomes.map((o) => o.ok), [true]);
|
|
393
|
+
assert.equal(result.screenshot, "UklGRh==");
|
|
394
|
+
assert.deepEqual(result.probe, {});
|
|
395
|
+
});
|
|
396
|
+
|
|
397
|
+
it("fails a click on a hidden (zero-size) element instead of clicking at (0,0)", async () => {
|
|
398
|
+
const ws = new FakeWs();
|
|
399
|
+
ws.onSend = (frame) => {
|
|
400
|
+
const { method, id, params } = frame;
|
|
401
|
+
if (method === "Target.createTarget") return ws.reply(id, { targetId: "t1" });
|
|
402
|
+
if (method === "Target.attachToTarget") return ws.reply(id, { sessionId: "s1" });
|
|
403
|
+
if (method === "Page.navigate") {
|
|
404
|
+
ws.reply(id, {});
|
|
405
|
+
ws.event("Page.loadEventFired", {}, "s1");
|
|
406
|
+
return;
|
|
407
|
+
}
|
|
408
|
+
if (method === "Runtime.evaluate" && String(params?.expression ?? "").includes("getBoundingClientRect")) {
|
|
409
|
+
// The visibility-check expression turns a 0x0 rect into the sentinel.
|
|
410
|
+
return ws.reply(id, { result: { type: "object", value: { hidden: true } } });
|
|
411
|
+
}
|
|
412
|
+
ws.reply(id, {});
|
|
413
|
+
};
|
|
414
|
+
const result = await runInteraction({ url: "http://localhost:3000/", steps: [{ click: "#hidden" }], wsFactory: () => ws });
|
|
415
|
+
assert.equal(result.outcomes[0].ok, false);
|
|
416
|
+
assert.match(String(result.outcomes[0].error), /not visible/);
|
|
417
|
+
assert.equal(lengthOf(ws.sent.filter((f) => f.method === "Input.dispatchMouseEvent")), 0);
|
|
418
|
+
});
|
|
419
|
+
|
|
420
|
+
it("treats {screenshot:false} as a declined capture (dropped; auto-final still runs)", async () => {
|
|
421
|
+
const ws = new FakeWs();
|
|
422
|
+
fakeCdpServer(ws);
|
|
423
|
+
const result = await runInteraction({
|
|
424
|
+
url: "http://localhost:3000/",
|
|
425
|
+
steps: [{ screenshot: false } as any],
|
|
426
|
+
wsFactory: () => ws,
|
|
427
|
+
});
|
|
428
|
+
assert.equal(lengthOf(result.outcomes), 0);
|
|
429
|
+
assert.equal(result.screenshot, "UklGRh==");
|
|
430
|
+
assert.equal(lengthOf(ws.sent.filter((f) => f.method === "Page.captureScreenshot")), 1);
|
|
431
|
+
});
|
|
432
|
+
|
|
433
|
+
it("distinguishes a missing element from a non-focusable one on type steps", async () => {
|
|
434
|
+
const run = async (evalValue: unknown): Promise<StepOutcome> => {
|
|
435
|
+
const ws = new FakeWs();
|
|
436
|
+
ws.onSend = (frame) => {
|
|
437
|
+
const { method, id, params } = frame;
|
|
438
|
+
if (method === "Target.createTarget") return ws.reply(id, { targetId: "t1" });
|
|
439
|
+
if (method === "Target.attachToTarget") return ws.reply(id, { sessionId: "s1" });
|
|
440
|
+
if (method === "Page.navigate") {
|
|
441
|
+
ws.reply(id, {});
|
|
442
|
+
ws.event("Page.loadEventFired", {}, "s1");
|
|
443
|
+
return;
|
|
444
|
+
}
|
|
445
|
+
if (method === "Runtime.evaluate" && String(params?.expression ?? "").includes("focus")) {
|
|
446
|
+
return ws.reply(id, { result: { type: "object", value: evalValue } });
|
|
447
|
+
}
|
|
448
|
+
ws.reply(id, {});
|
|
449
|
+
};
|
|
450
|
+
const r = await runInteraction({ url: "http://localhost:3000/", steps: [{ type: { selector: "#x", text: "hi" } }], wsFactory: () => ws });
|
|
451
|
+
return r.outcomes[0];
|
|
452
|
+
};
|
|
453
|
+
const missing = await run({ missing: true });
|
|
454
|
+
assert.equal(missing.ok, false);
|
|
455
|
+
assert.match(String(missing.error), /no element matches/);
|
|
456
|
+
const notFocusable = await run({ focused: false });
|
|
457
|
+
assert.equal(notFocusable.ok, false);
|
|
458
|
+
assert.match(String(notFocusable.error), /not focusable/);
|
|
459
|
+
});
|
|
460
|
+
|
|
461
|
+
it("fails fast on a broken step and says why", async () => {
|
|
462
|
+
const ws = new FakeWs();
|
|
463
|
+
ws.onSend = (frame) => {
|
|
464
|
+
const { method, id, params } = frame;
|
|
465
|
+
if (method === "Target.createTarget") return ws.reply(id, { targetId: "t1" });
|
|
466
|
+
if (method === "Target.attachToTarget") return ws.reply(id, { sessionId: "s1" });
|
|
467
|
+
if (method === "Page.navigate") {
|
|
468
|
+
ws.reply(id, {});
|
|
469
|
+
ws.event("Page.loadEventFired", {}, "s1");
|
|
470
|
+
return;
|
|
471
|
+
}
|
|
472
|
+
if (method === "Runtime.evaluate") {
|
|
473
|
+
// click's rect lookup → element missing
|
|
474
|
+
return ws.reply(id, { result: { type: "object", value: null } });
|
|
475
|
+
}
|
|
476
|
+
ws.reply(id, {});
|
|
477
|
+
};
|
|
478
|
+
const result = await runInteraction({
|
|
479
|
+
url: "http://localhost:3000/",
|
|
480
|
+
steps: [{ click: "#missing" }, { evaluate: "1+1" }],
|
|
481
|
+
wsFactory: () => ws,
|
|
482
|
+
});
|
|
483
|
+
assert.equal(result.outcomes[0].ok, false);
|
|
484
|
+
assert.match(String(result.outcomes[0].error), /no element matches #missing/);
|
|
485
|
+
assert.equal(lengthOf(result.outcomes), 1); // stopped, later steps not run
|
|
486
|
+
});
|
|
487
|
+
|
|
488
|
+
it("maps the flattened wait_ms schema field onto wait_for", async () => {
|
|
489
|
+
const ws = new FakeWs();
|
|
490
|
+
fakeCdpServer(ws);
|
|
491
|
+
const result = await runInteraction({
|
|
492
|
+
url: "http://localhost:3000/",
|
|
493
|
+
steps: [{ wait_ms: 10 } as any],
|
|
494
|
+
wsFactory: () => ws,
|
|
495
|
+
});
|
|
496
|
+
assert.deepEqual(result.outcomes.map((o) => o.ok), [true]);
|
|
497
|
+
assert.match(String(result.outcomes[0].label), /wait_for 10/);
|
|
498
|
+
});
|
|
499
|
+
|
|
500
|
+
it("aliases friendly permission names to CDP names and annotates mid-step navigation", async () => {
|
|
501
|
+
const ws = new FakeWs();
|
|
502
|
+
ws.onSend = (frame) => {
|
|
503
|
+
const { method, id, params } = frame;
|
|
504
|
+
if (method === "Target.createTarget") return ws.reply(id, { targetId: "t1" });
|
|
505
|
+
if (method === "Target.attachToTarget") return ws.reply(id, { sessionId: "s1" });
|
|
506
|
+
if (method === "Page.navigate") {
|
|
507
|
+
ws.reply(id, {});
|
|
508
|
+
ws.event("Page.loadEventFired", {}, "s1");
|
|
509
|
+
return;
|
|
510
|
+
}
|
|
511
|
+
if (method === "Browser.grantPermissions") {
|
|
512
|
+
// Capture what actually went over the wire, then ack.
|
|
513
|
+
(ws as any).grantReceived = (params as any).permissions;
|
|
514
|
+
return ws.reply(id, {});
|
|
515
|
+
}
|
|
516
|
+
if (method === "Runtime.evaluate" && String(params?.expression ?? "").includes("1+1")) {
|
|
517
|
+
// The step's evaluate triggers a navigation (form-submit style):
|
|
518
|
+
// first an IFRAME navigates (must be ignored), then the main frame.
|
|
519
|
+
ws.event("Page.frameNavigated", { frame: { url: "http://cdn.example.com/ad", parentId: "f-parent" } }, "s1");
|
|
520
|
+
ws.event("Page.frameNavigated", { frame: { url: "http://localhost:3000/submitted" } }, "s1");
|
|
521
|
+
}
|
|
522
|
+
ws.reply(id, {});
|
|
523
|
+
};
|
|
524
|
+
const result = await runInteraction({
|
|
525
|
+
url: "http://localhost:3000/",
|
|
526
|
+
steps: [{ evaluate: "1+1" }],
|
|
527
|
+
grant: ["clipboard-read", "clipboard-write"],
|
|
528
|
+
wsFactory: () => ws,
|
|
529
|
+
});
|
|
530
|
+
assert.deepEqual((ws as any).grantReceived, ["clipboardReadWrite", "clipboardSanitizedWrite"]);
|
|
531
|
+
assert.equal(result.navigatedTo, "http://localhost:3000/submitted"); // not the iframe URL
|
|
532
|
+
});
|
|
533
|
+
|
|
534
|
+
it("ignores iframe/subframe navigations entirely (no false ⚠)", async () => {
|
|
535
|
+
const ws = new FakeWs();
|
|
536
|
+
ws.onSend = (frame) => {
|
|
537
|
+
const { method, id, params } = frame;
|
|
538
|
+
if (method === "Target.createTarget") return ws.reply(id, { targetId: "t1" });
|
|
539
|
+
if (method === "Target.attachToTarget") return ws.reply(id, { sessionId: "s1" });
|
|
540
|
+
if (method === "Page.navigate") {
|
|
541
|
+
ws.reply(id, {});
|
|
542
|
+
ws.event("Page.loadEventFired", {}, "s1");
|
|
543
|
+
return;
|
|
544
|
+
}
|
|
545
|
+
if (method === "Runtime.evaluate" && String(params?.expression ?? "").includes("scrollWidth")) {
|
|
546
|
+
// An ad iframe refreshes during the probe — subframe, has parentId.
|
|
547
|
+
ws.event("Page.frameNavigated", { frame: { url: "http://cdn.example.com/ad", parentId: "f-parent" } }, "s1");
|
|
548
|
+
}
|
|
549
|
+
ws.reply(id, {});
|
|
550
|
+
};
|
|
551
|
+
const result = await runInteraction({ url: "http://localhost:3000/", steps: [{ evaluate: "1+1" }], wsFactory: () => ws });
|
|
552
|
+
assert.equal(result.navigatedTo, undefined);
|
|
553
|
+
});
|
|
554
|
+
|
|
555
|
+
it("rejects switch-like URLs before launching Chrome", async () => {
|
|
556
|
+
let err: any;
|
|
557
|
+
try {
|
|
558
|
+
await runInteraction({ url: "--remote-debugging-port=9222", wsFactory: () => new FakeWs() });
|
|
559
|
+
} catch (e) {
|
|
560
|
+
err = e;
|
|
561
|
+
}
|
|
562
|
+
assert.ok(err);
|
|
563
|
+
assert.ok(includes(String(err.message), "Invalid capture URL"));
|
|
564
|
+
});
|
|
565
|
+
|
|
566
|
+
it("auto-dismisses a native confirm() opened by a click and reports it on the step", async () => {
|
|
567
|
+
const ws = new FakeWs();
|
|
568
|
+
ws.onSend = (frame) => {
|
|
569
|
+
const { method, id, params } = frame;
|
|
570
|
+
if (method === "Target.createTarget") return ws.reply(id, { targetId: "t1" });
|
|
571
|
+
if (method === "Target.attachToTarget") return ws.reply(id, { sessionId: "s1" });
|
|
572
|
+
if (method === "Page.navigate") {
|
|
573
|
+
ws.reply(id, {});
|
|
574
|
+
ws.event("Page.loadEventFired", {}, "s1");
|
|
575
|
+
return;
|
|
576
|
+
}
|
|
577
|
+
if (method === "Runtime.evaluate" && String(params?.expression ?? "").includes("getBoundingClientRect")) {
|
|
578
|
+
// The click's rect lookup: element found at (100, 50).
|
|
579
|
+
return ws.reply(id, { result: { type: "object", value: { x: 100, y: 50 } } });
|
|
580
|
+
}
|
|
581
|
+
if (method === "Input.dispatchMouseEvent" && params?.type === "mouseReleased") {
|
|
582
|
+
// Real Chrome: the page's onclick called confirm() — renderer blocks until answered.
|
|
583
|
+
ws.event("Page.javascriptDialogOpening", { type: "confirm", message: "Delete this opportunity?" }, "s1");
|
|
584
|
+
return ws.reply(id, {});
|
|
585
|
+
}
|
|
586
|
+
ws.reply(id, {});
|
|
587
|
+
};
|
|
588
|
+
const result = await runInteraction({
|
|
589
|
+
url: "http://localhost:3000/",
|
|
590
|
+
steps: [{ click: "#delete" }, { evaluate: "1+1", label: "after" }],
|
|
591
|
+
wsFactory: () => ws,
|
|
592
|
+
});
|
|
593
|
+
// Safe default: dismissed (destructive stays blocked)…
|
|
594
|
+
const answer = ws.sent.find((f) => f.method === "Page.handleJavaScriptDialog");
|
|
595
|
+
assert.ok(deepIncludes(answer?.params, { accept: false }));
|
|
596
|
+
// …reported on the step and at run level, and the run continued past it.
|
|
597
|
+
assert.deepEqual(result.outcomes[0].dialogs, ['confirm("Delete this opportunity?") → dismissed']);
|
|
598
|
+
assert.deepEqual(result.dialogs, ['confirm("Delete this opportunity?") → dismissed']);
|
|
599
|
+
assert.equal(result.outcomes[1].ok, true);
|
|
600
|
+
});
|
|
601
|
+
|
|
602
|
+
it("answers a dialog with the armed {dialog} step and reverts to dismiss after one consumption", async () => {
|
|
603
|
+
const accepts: boolean[] = [];
|
|
604
|
+
const ws = new FakeWs();
|
|
605
|
+
ws.onSend = (frame) => {
|
|
606
|
+
const { method, id, params } = frame;
|
|
607
|
+
if (method === "Target.createTarget") return ws.reply(id, { targetId: "t1" });
|
|
608
|
+
if (method === "Target.attachToTarget") return ws.reply(id, { sessionId: "s1" });
|
|
609
|
+
if (method === "Page.navigate") {
|
|
610
|
+
ws.reply(id, {});
|
|
611
|
+
ws.event("Page.loadEventFired", {}, "s1");
|
|
612
|
+
return;
|
|
613
|
+
}
|
|
614
|
+
if (method === "Input.dispatchMouseEvent" && params?.type === "mouseReleased") {
|
|
615
|
+
ws.event("Page.javascriptDialogOpening", { type: "confirm", message: "Delete?" }, "s1");
|
|
616
|
+
return ws.reply(id, {});
|
|
617
|
+
}
|
|
618
|
+
if (method === "Runtime.evaluate" && String(params?.expression ?? "").includes("getBoundingClientRect")) {
|
|
619
|
+
return ws.reply(id, { result: { type: "object", value: { x: 100, y: 50 } } });
|
|
620
|
+
}
|
|
621
|
+
if (method === "Runtime.evaluate" && String(params?.expression ?? "").includes("openAnother")) {
|
|
622
|
+
ws.event("Page.javascriptDialogOpening", { type: "confirm", message: "Again?" }, "s1");
|
|
623
|
+
return ws.reply(id, { result: { type: "number", value: 1 } });
|
|
624
|
+
}
|
|
625
|
+
if (method === "Page.handleJavaScriptDialog") {
|
|
626
|
+
accepts.push(Boolean((params as any).accept));
|
|
627
|
+
return ws.reply(id, {});
|
|
628
|
+
}
|
|
629
|
+
ws.reply(id, {});
|
|
630
|
+
};
|
|
631
|
+
const result = await runInteraction({
|
|
632
|
+
url: "http://localhost:3000/",
|
|
633
|
+
steps: [
|
|
634
|
+
{ dialog: "accept" },
|
|
635
|
+
{ click: "#delete" },
|
|
636
|
+
{ evaluate: "window.openAnother()", label: "second" },
|
|
637
|
+
] as any,
|
|
638
|
+
wsFactory: () => ws,
|
|
639
|
+
});
|
|
640
|
+
// Armed accept consumed by the first dialog; the second falls back to dismiss.
|
|
641
|
+
assert.deepEqual(accepts, [true, false]);
|
|
642
|
+
assert.equal(result.outcomes[0].label, "dialog accept");
|
|
643
|
+
assert.deepEqual(result.dialogs, ['confirm("Delete?") → accepted', 'confirm("Again?") → dismissed']);
|
|
644
|
+
});
|
|
645
|
+
|
|
646
|
+
it("fails a step that exceeds the per-step timeout instead of hanging the run", async () => {
|
|
647
|
+
const ws = new FakeWs();
|
|
648
|
+
let wedged = false;
|
|
649
|
+
ws.onSend = (frame) => {
|
|
650
|
+
const { method, id, params } = frame;
|
|
651
|
+
if (method === "Target.createTarget") return ws.reply(id, { targetId: "t1" });
|
|
652
|
+
if (method === "Target.attachToTarget") return ws.reply(id, { sessionId: "s1" });
|
|
653
|
+
if (method === "Page.navigate") {
|
|
654
|
+
ws.reply(id, {});
|
|
655
|
+
ws.event("Page.loadEventFired", {}, "s1");
|
|
656
|
+
return;
|
|
657
|
+
}
|
|
658
|
+
// Simulate a fully wedged renderer (dialog race / hung evaluate): the
|
|
659
|
+
// blocked step AND every post-loop frame (overflow probe, auto-final
|
|
660
|
+
// screenshot) never answer — runInteraction must still resolve.
|
|
661
|
+
if (method === "Runtime.evaluate" && String(params?.expression ?? "") === "blocked") wedged = true;
|
|
662
|
+
if (wedged && (method === "Runtime.evaluate" || method === "Page.captureScreenshot")) return;
|
|
663
|
+
ws.reply(id, {});
|
|
664
|
+
};
|
|
665
|
+
const result = await runInteraction({
|
|
666
|
+
url: "http://localhost:3000/",
|
|
667
|
+
steps: [{ evaluate: "1+1" }, { evaluate: "blocked" }, { evaluate: "1+2" }],
|
|
668
|
+
stepTimeoutMs: 150,
|
|
669
|
+
wsFactory: () => ws,
|
|
670
|
+
});
|
|
671
|
+
assert.equal(lengthOf(result.outcomes), 2); // stopped at the timed-out step
|
|
672
|
+
assert.equal(result.outcomes[0].ok, true);
|
|
673
|
+
assert.equal(result.outcomes[1].ok, false);
|
|
674
|
+
assert.match(String(result.outcomes[1].error), /timed out after/);
|
|
675
|
+
// Bounded probe + auto-final: the run resolves promptly with outcomes
|
|
676
|
+
// intact, an empty probe, and no PNG (instead of hanging forever).
|
|
677
|
+
assert.deepEqual(result.probe, {});
|
|
678
|
+
assert.equal(result.screenshot, undefined);
|
|
679
|
+
});
|
|
680
|
+
|
|
681
|
+
it("expires an unconsumed {dialog} arm at the next step boundary", async () => {
|
|
682
|
+
const accepts: boolean[] = [];
|
|
683
|
+
const ws = new FakeWs();
|
|
684
|
+
ws.onSend = (frame) => {
|
|
685
|
+
const { method, id, params } = frame;
|
|
686
|
+
if (method === "Target.createTarget") return ws.reply(id, { targetId: "t1" });
|
|
687
|
+
if (method === "Target.attachToTarget") return ws.reply(id, { sessionId: "s1" });
|
|
688
|
+
if (method === "Page.navigate") {
|
|
689
|
+
ws.reply(id, {});
|
|
690
|
+
ws.event("Page.loadEventFired", {}, "s1");
|
|
691
|
+
return;
|
|
692
|
+
}
|
|
693
|
+
if (method === "Runtime.evaluate" && String(params?.expression ?? "").includes("openAnother")) {
|
|
694
|
+
// An UNRELATED dialog steps after the armed click never happened —
|
|
695
|
+
// the arm must have expired, so this falls back to dismiss.
|
|
696
|
+
ws.event("Page.javascriptDialogOpening", { type: "beforeunload", message: "Leave?" }, "s1");
|
|
697
|
+
return ws.reply(id, { result: { type: "number", value: 1 } });
|
|
698
|
+
}
|
|
699
|
+
if (method === "Page.handleJavaScriptDialog") {
|
|
700
|
+
accepts.push(Boolean((params as any).accept));
|
|
701
|
+
return ws.reply(id, {});
|
|
702
|
+
}
|
|
703
|
+
ws.reply(id, {});
|
|
704
|
+
};
|
|
705
|
+
const result = await runInteraction({
|
|
706
|
+
url: "http://localhost:3000/",
|
|
707
|
+
steps: [
|
|
708
|
+
{ dialog: "accept" },
|
|
709
|
+
{ evaluate: "1+1", label: "no dialog here" },
|
|
710
|
+
{ evaluate: "window.openAnother()", label: "unrelated dialog" },
|
|
711
|
+
] as any,
|
|
712
|
+
wsFactory: () => ws,
|
|
713
|
+
});
|
|
714
|
+
assert.deepEqual(accepts, [false]); // NOT accepted
|
|
715
|
+
assert.deepEqual(result.dialogs, ['beforeunload("Leave?") → dismissed']);
|
|
716
|
+
});
|
|
717
|
+
});
|