// 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); }); }