aboutsummaryrefslogtreecommitdiff
path: root/test/cdp/endpoint-test.ts
diff options
context:
space:
mode:
Diffstat (limited to 'test/cdp/endpoint-test.ts')
-rw-r--r--test/cdp/endpoint-test.ts60
1 files changed, 59 insertions, 1 deletions
diff --git a/test/cdp/endpoint-test.ts b/test/cdp/endpoint-test.ts
index d4b696f..57d6088 100644
--- a/test/cdp/endpoint-test.ts
+++ b/test/cdp/endpoint-test.ts
@@ -9,7 +9,12 @@
*
* Run: npx tsx test/cdp/endpoint-test.ts
*/
-import { DEFAULT_REMOTE_CDP, describeCdpTarget, resolveCdpTarget } from "../../src/cdp/endpoint";
+import {
+ DEFAULT_REMOTE_CDP,
+ describeCdpTarget,
+ isValidTargetValue,
+ resolveCdpTarget,
+} from "../../src/cdp/endpoint";
let passed = 0;
let failed = 0;
@@ -92,6 +97,59 @@ function main(): void {
check(describeCdpTarget(resolveCdpTarget(env("local"))).includes("own browser"), "E8: local is described plainly");
}
+ // E9: the stored choice (/browser-target) sits between env and the default.
+ {
+ const t = resolveCdpTarget({}, "local");
+ check(t.kind === "local" && t.source === "stored", "E9: a stored value is used when the env is unset");
+
+ const r = resolveCdpTarget({}, "10.2.3.4:9224");
+ check(r.kind === "remote" && r.source === "stored", "E9: a stored host:port resolves as a remote target");
+ }
+
+ // E10: the environment wins, so a one-off `BU_CDP_HTTP=… pi` is never
+ // silently overridden by a setting made days ago.
+ {
+ const t = resolveCdpTarget(env("local"), "10.2.3.4:9224");
+ check(t.kind === "local" && t.source === "env", "E10: env beats the stored value");
+
+ const r = resolveCdpTarget(env("10.9.9.9:1234"), "local");
+ check(r.kind === "remote" && r.host === "10.9.9.9" && r.source === "env", "E10: an env endpoint beats stored local");
+ }
+
+ // E11: clearing the stored value falls back to the built-in default rather
+ // than to local — clearing is "use the usual browser", not "go local".
+ {
+ const t = resolveCdpTarget({}, null);
+ check(t.kind === "remote" && t.source === "default", "E11: no stored value falls back to the default");
+ const blank = resolveCdpTarget({}, " ");
+ check(blank.kind === "remote" && blank.source === "default", "E11: a blank stored value is treated as cleared");
+ }
+
+ // E12: a corrupt stored value must be reported against the right source, or
+ // the operator goes hunting through their shell config for an env var that
+ // was never set.
+ {
+ const t = resolveCdpTarget({}, "garbage");
+ check(t.kind === "invalid" && t.source === "stored", "E12: a bad stored value is blamed on /browser-target");
+ if (t.kind === "invalid") {
+ check(describeCdpTarget(t).includes("/browser-target"), "E12: the description names the stored source");
+ }
+ const e = resolveCdpTarget(env("garbage"), null);
+ check(e.kind === "invalid" && e.source === "env", "E12: a bad env value is blamed on BU_CDP_HTTP");
+ }
+
+ // E13: the values /browser-target accepts must match what resolution can
+ // actually use, or the command would happily store something unusable.
+ {
+ for (const good of ["local", "off", "1.2.3.4:9222", "castle.local:9223"]) {
+ check(isValidTargetValue(good), `E13: "${good}" is accepted by the command`);
+ }
+ for (const bad of ["", " ", "garbage", "host:", "host:99999"]) {
+ check(!isValidTargetValue(bad), `E13: "${bad}" is rejected by the command`);
+ }
+ check(!isValidTargetValue("default"), "E13: \"default\" is handled as clear, not stored verbatim");
+ }
+
console.log(`\n${passed} passed, ${failed} failed`);
if (failed > 0) process.exit(1);
}