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.
This commit is contained in:
2026-10-16 22:21:43 +01:00
669 changed files with 7205 additions and 276 deletions
+163
View File
@@ -0,0 +1,163 @@
// Client transport tests against a fake WebSocket: id matching, serialization,
// error replies, timeouts and the not-connected guard. No server required.
import { test } from "node:test";
import assert from "node:assert/strict";
import { PipelinesClient, ProtocolError, NotConnectedError } from "../src/client.js";
import { validateServerUrl } from "../src/serverUrl.js";
const VALID = validateServerUrl("ws://host:8080/connect");
class FakeWebSocket {
static instances = [];
constructor(url) {
this.url = url;
this.sent = [];
this.closed = null;
this.onopen = null;
this.onmessage = null;
this.onclose = null;
this.onerror = null;
/** @type {((frame: any) => any | undefined) | null} */
this.reply = null;
FakeWebSocket.instances.push(this);
}
send(data) {
const frame = JSON.parse(data);
this.sent.push(frame);
const response = this.reply?.(frame);
if (response !== undefined) {
this.onmessage?.({ data: JSON.stringify(response) });
}
}
close(code, reason) {
this.closed = { code, reason };
this.onclose?.({ code, reason });
}
// test hooks
open() {
this.onopen?.({});
}
push(obj) {
this.onmessage?.({ data: JSON.stringify(obj) });
}
drop(code = 1006) {
this.onclose?.({ code, reason: "test" });
}
}
/** Let the client's serialized call chain run to the point where it has sent. */
const flush = () => new Promise((resolve) => setImmediate(resolve));
function freshClient(options = {}) {
FakeWebSocket.instances = [];
return new PipelinesClient({ WebSocketImpl: FakeWebSocket, ...options });
}
function connectedClient(options = {}) {
const client = freshClient(options);
client.connect(VALID);
const ws = FakeWebSocket.instances.at(-1);
ws.open();
return { client, ws };
}
test("a call before connect is rejected as not connected", async () => {
const client = freshClient();
await assert.rejects(() => client.call({ type: "ping" }), NotConnectedError);
});
test("a call sends a JSON frame with a generated id and resolves the matching reply", async () => {
const { client, ws } = connectedClient();
ws.reply = (frame) => ({ id: frame.id, type: "pong" });
const reply = await client.call({ type: "ping" });
assert.equal(reply.type, "pong");
assert.equal(ws.sent.length, 1);
assert.equal(ws.sent[0].type, "ping");
assert.match(ws.sent[0].id, /^web-\d+$/);
});
test("an error reply surfaces the server text as a ProtocolError", async () => {
const { client, ws } = connectedClient();
ws.reply = (frame) => ({ id: frame.id, type: "error", error: "nope" });
await assert.rejects(() => client.call({ type: "get_run" }), ProtocolError);
});
test("an unsolicited envelope with no matching id is dropped, not misattributed", async () => {
const { client, ws } = connectedClient();
ws.reply = undefined;
const pending = client.call({ type: "ping" });
let settled = false;
pending.then(() => (settled = true), () => (settled = true));
await flush();
ws.push({ type: "pipelines", pipelines: [] }); // no id
await flush();
assert.equal(settled, false);
const frame = ws.sent.at(-1);
ws.push({ id: frame.id, type: "pong" });
assert.equal((await pending).type, "pong");
});
test("a malformed frame is ignored and does not reject a pending call", async () => {
const { client, ws } = connectedClient();
const pending = client.call({ type: "ping" });
await flush();
ws.onmessage?.({ data: "{not json" });
const frame = ws.sent.at(-1);
ws.push({ id: frame.id, type: "pong" });
assert.equal((await pending).type, "pong");
});
test("a missing reply times out with a clear error", async () => {
const { client } = connectedClient({ requestTimeoutMs: 20 });
await assert.rejects(() => client.call({ type: "ping" }), /timed out after 20ms/);
});
test("concurrent calls are serialized in submission order", async () => {
const { client, ws } = connectedClient();
const order = [];
ws.reply = (frame) => {
order.push(frame.type);
return { id: frame.id, type: "ok" };
};
await Promise.all([client.call({ type: "a" }), client.call({ type: "b" })]);
assert.deepEqual(order, ["a", "b"]);
});
test("the state flow reports connecting then connected", async () => {
const seen = [];
const client = freshClient();
client.addEventListener("state", (e) => seen.push(e.detail.kind));
client.connect(VALID);
FakeWebSocket.instances.at(-1).open();
assert.deepEqual(seen, ["connecting", "connected"]);
});
test("an unexpected close fails pending calls and schedules a reconnect", async () => {
const { client, ws } = connectedClient({ backoffBaseMs: 1, backoffMaxMs: 5 });
const pending = client.call({ type: "ping" }); // never answered
await flush(); // let the call reach the socket before it is dropped
ws.drop(1006);
await assert.rejects(() => pending, /Connection closed/);
assert.equal(client.state.kind, "disconnected");
assert.equal(client.state.retrying, true);
client.disconnect(); // stop the reconnect timer before the test ends
});
test("disconnect goes idle and does not schedule a reconnect", () => {
const { client, ws } = connectedClient();
client.disconnect();
assert.equal(client.state.kind, "idle");
assert.equal(client.state.retrying, false);
assert.deepEqual(ws.closed, { code: 1000, reason: "client closing" });
});
+85
View File
@@ -0,0 +1,85 @@
// 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);
});
+102
View File
@@ -0,0 +1,102 @@
// Live end-to-end smoke test: drives the *real* client (src/client.js) against a
// running Pipelines server. Opt-in, because it needs a server:
//
// PIPELINES_WS_URL=ws://127.0.0.1:8080/connect node test/smoke.mjs
//
// Uses Node's built-in global WebSocket and fetch (Node >= 22). Exits non-zero
// on the first failed assertion so it is usable in a check.
import assert from "node:assert/strict";
import { PipelinesClient } from "../src/client.js";
import { PipelinesRepository } from "../src/repository.js";
import { validateServerUrl, resolveArtifactUrl } from "../src/serverUrl.js";
const raw = process.env.PIPELINES_WS_URL ?? process.argv[2] ?? "";
if (!raw) {
console.error("PIPELINES_WS_URL is required, e.g. ws://127.0.0.1:8080/connect");
process.exit(2);
}
const validated = validateServerUrl(raw);
if (!validated.valid) {
console.error(`invalid server URL: ${validated.message}`);
process.exit(2);
}
const client = new PipelinesClient();
const repo = new PipelinesRepository(client);
const checks = [];
const pass = (name) => {
checks.push(name);
console.log(` ok ${name}`);
};
try {
await connectWithTimeout(client, validated, 5000);
pass("websocket connected");
const pong = await repo.ping();
assert.equal(pong.type, "pong");
pass("ping -> pong");
const pipelines = await repo.listPipelines();
assert.ok(Array.isArray(pipelines));
pass(`list_pipelines -> ${pipelines.length} pipeline(s)`);
const { runs, usage } = await repo.listRuns();
assert.ok(Array.isArray(runs));
pass(`list_runs -> ${runs.length} run(s), usage.total=${usage?.total ?? "n/a"}`);
if (pipelines.length) {
const detail = await repo.getPipeline(pipelines[0].id, pipelines[0].version);
assert.equal(detail.id, pipelines[0].id);
assert.ok(Array.isArray(detail.graph?.stages));
pass(`get_pipeline #${detail.id} -> ${detail.graph.stages.length} stage(s)`);
} else {
console.log(" -- no pipelines; skipped get_pipeline");
}
if (runs.length) {
const run = await repo.getRun(runs[0].id);
assert.equal(run.id, runs[0].id);
assert.ok(Array.isArray(run.steps));
pass(`get_run #${run.id} -> status=${run.status} steps=${run.steps.length}`);
const artifact = run.steps.flatMap((s) => s.artifacts ?? []).find((a) => a.url);
if (artifact) {
const url = resolveArtifactUrl(raw, artifact.url);
assert.ok(url?.startsWith("http"));
const res = await fetch(url, { method: "HEAD" });
pass(`artifact HEAD ${url} -> ${res.status} ${res.headers.get("content-type") ?? ""}`.trim());
assert.ok(res.ok, `artifact HEAD was ${res.status}`);
} else {
console.log(" -- newest run has no artifacts; skipped artifact fetch");
}
} else {
console.log(" -- no runs; skipped get_run");
}
console.log(`\nSMOKE PASS (${checks.length} checks) against ${validated.wsUrl}`);
client.disconnect();
process.exit(0);
} catch (err) {
console.error(`\nSMOKE FAIL: ${err?.message ?? err}`);
console.error(`against ${validated.wsUrl}`);
client.disconnect();
process.exit(1);
}
function connectWithTimeout(c, validatedUrl, ms) {
return new Promise((resolve, reject) => {
const timer = setTimeout(() => reject(new Error(`connect timed out after ${ms}ms`)), ms);
const onState = (event) => {
if (event.detail.kind === "connected") {
clearTimeout(timer);
c.removeEventListener("state", onState);
resolve();
}
};
c.addEventListener("state", onState);
c.connect(validatedUrl);
});
}