Files
pipelines/web/test/serverUrl.test.mjs
T
alan bd09c55c47 Merge lane-go: titles, verdicts, human stage, line result format, stale-client guard
Integrates nine commits of reviewed work from the lane-go branch after the
automated resolver failed on this merge five times (each attempt dying on the
malformed-result defect whose fix is contained in this same merge).

Integration decisions:
- Search: kept main's shipped design (Store.Search + SearchResponse.Results) and
  dropped lane-go's parallel, older attempt (an unused Message.Matches field, an
  absent runs.search, and two partial TUI plumbing blocks). lane-go itself did not
  compile: protocol.SearchMatch was undefined and model.go referenced searchNav,
  requestSearch and applyRunNav, which exist nowhere. Those partial TUI blocks are
  removed; the queued TUI omni-search item will implement the surface properly on
  main's design.
- Both sides' additions are kept where they are independent: run titles and
  provenance, the human decision stage and its CLI/TUI surface, the derived stage
  verdict, the stale-client guard, the line-oriented result format, and main's
  search command.
- The search key's help label is now "/ omni search"; the two tests asserting the
  old label are updated rather than the label reverted.
- docs/cli.md and the packaged operations reference carry both sides' text.

Verified: go build ./... , go vet ./... and the full go test ./... suite pass.
2026-10-16 22:21:43 +01:00

86 lines
3.5 KiB
JavaScript

// Unit tests for the ported ServerUrl validation, run with `node --test`.
// Mirrors the cases in android/.../test/.../ServerUrlTest.kt.
import { test } from "node:test";
import assert from "node:assert/strict";
import { validateServerUrl, resolveArtifactUrl, ServerUrlKind } from "../src/serverUrl.js";
import { Protocol, resolveTarget, isTerminal } from "../src/protocol.js";
test("defaults a bare host to /connect over ws", () => {
const v = validateServerUrl("ws://192.168.1.20:8081");
assert.equal(v.valid, true);
assert.equal(v.wsUrl, "ws://192.168.1.20:8081/connect");
assert.equal(v.httpUrl, "http://192.168.1.20:8081/connect");
assert.equal(v.host, "192.168.1.20");
assert.equal(v.port, 8081);
assert.equal(v.secure, false);
});
test("treats a lone / as the default endpoint path", () => {
const v = validateServerUrl("ws://host:1234/");
assert.equal(v.valid, true);
assert.equal(v.wsUrl, "ws://host:1234/connect");
});
test("wss maps to https and defaults the port to 443", () => {
const v = validateServerUrl("wss://example.test/connect");
assert.equal(v.valid, true);
assert.equal(v.secure, true);
assert.equal(v.port, 443);
assert.equal(v.httpUrl, "https://example.test/connect");
});
test("rejects empty, non-ws schemes, userinfo and fragments", () => {
assert.equal(validateServerUrl("").kind, ServerUrlKind.EMPTY);
assert.equal(validateServerUrl(" ").kind, ServerUrlKind.EMPTY);
assert.equal(validateServerUrl("http://host:8080/connect").kind, ServerUrlKind.UNSUPPORTED_SCHEME);
assert.equal(validateServerUrl("ftp://host").kind, ServerUrlKind.UNSUPPORTED_SCHEME);
assert.equal(validateServerUrl("ws://user:pass@host:8080/connect").kind, ServerUrlKind.USER_INFO);
assert.equal(validateServerUrl("ws://host:8080/connect#frag").kind, ServerUrlKind.FRAGMENT);
});
test("rejects malformed and hostless input", () => {
assert.equal(validateServerUrl("not a url").kind, ServerUrlKind.MALFORMED);
const hostless = validateServerUrl("ws://");
assert.ok(hostless.kind === ServerUrlKind.MALFORMED || hostless.kind === ServerUrlKind.MISSING_HOST);
assert.equal(hostless.valid, false);
});
test("preserves a query string", () => {
const v = validateServerUrl("ws://host:8080/connect?token=abc");
assert.equal(v.valid, true);
assert.equal(v.wsUrl, "ws://host:8080/connect?token=abc");
});
test("resolveArtifactUrl maps ws to http and drops /connect", () => {
assert.equal(
resolveArtifactUrl("ws://10.0.0.249:8080/connect", "/artifacts/55/4/shot.png"),
"http://10.0.0.249:8080/artifacts/55/4/shot.png",
);
});
test("resolveArtifactUrl uses https and omits the default port for wss", () => {
assert.equal(
resolveArtifactUrl("wss://example.test/connect", "artifacts/1/1/a.png"),
"https://example.test/artifacts/1/1/a.png",
);
});
test("resolveArtifactUrl returns an absolute url unchanged and null when unconfigured", () => {
assert.equal(
resolveArtifactUrl("ws://host:8080/connect", "https://cdn.test/a.png"),
"https://cdn.test/a.png",
);
assert.equal(resolveArtifactUrl("", "/artifacts/1/1/a.png"), null);
assert.equal(resolveArtifactUrl("ws://host:8080/connect", " "), null);
});
test("protocol target resolution mirrors the server shorthand", () => {
assert.equal(resolveTarget("error", "#"), Protocol.FAILURE_END);
assert.equal(resolveTarget("success", "#"), Protocol.SUCCESS_END);
assert.equal(resolveTarget("error", "cleanup"), "cleanup");
assert.equal(isTerminal("#success"), true);
assert.equal(isTerminal("#failure"), true);
assert.equal(isTerminal("cleanup"), false);
});