Merge branch 'main' into web-runs-home
# Conflicts: # web/src/app.js # web/styles.css
This commit is contained in:
@@ -0,0 +1,106 @@
|
||||
// Repository request-shape tests: the templates catalogue and the validate
|
||||
// command, driven through the real transport against a fake WebSocket so the
|
||||
// exact frames sent (and the error-envelope handling) are proven, not assumed.
|
||||
import { test } from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
|
||||
import { PipelinesClient, ProtocolError } from "../src/client.js";
|
||||
import { PipelinesRepository } from "../src/repository.js";
|
||||
import { validateServerUrl } from "../src/serverUrl.js";
|
||||
|
||||
const VALID = validateServerUrl("ws://host:8080/connect");
|
||||
|
||||
/** The same minimal fake the client tests use (test files are not importable). */
|
||||
class FakeWebSocket {
|
||||
static instances = [];
|
||||
|
||||
constructor(url) {
|
||||
this.url = url;
|
||||
this.sent = [];
|
||||
this.onopen = null;
|
||||
this.onmessage = null;
|
||||
this.onclose = null;
|
||||
this.onerror = 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.onclose?.({ code, reason });
|
||||
}
|
||||
|
||||
open() {
|
||||
this.onopen?.({});
|
||||
}
|
||||
}
|
||||
|
||||
function connected() {
|
||||
FakeWebSocket.instances = [];
|
||||
const client = new PipelinesClient({ WebSocketImpl: FakeWebSocket });
|
||||
const repo = new PipelinesRepository(client);
|
||||
client.connect(VALID);
|
||||
const ws = FakeWebSocket.instances.at(-1);
|
||||
ws.open();
|
||||
return { repo, ws, client };
|
||||
}
|
||||
|
||||
/** The last frame without the client-generated id, for an exact shape assertion. */
|
||||
function lastFrame(ws) {
|
||||
const { id, ...frame } = ws.sent.at(-1);
|
||||
assert.match(id, /^web-\d+$/);
|
||||
return frame;
|
||||
}
|
||||
|
||||
test("listTemplates sends exactly {type:'list_templates'} and returns the catalogue", async () => {
|
||||
const { repo, ws } = connected();
|
||||
ws.reply = (frame) => ({
|
||||
id: frame.id,
|
||||
type: "templates",
|
||||
templates: [{ key: "task", name: "Complete a task" }],
|
||||
});
|
||||
|
||||
const templates = await repo.listTemplates();
|
||||
assert.deepEqual(lastFrame(ws), { type: "list_templates" });
|
||||
assert.equal(templates.length, 1);
|
||||
assert.equal(templates[0].key, "task");
|
||||
});
|
||||
|
||||
test("listTemplates returns [] when the reply carries no templates", async () => {
|
||||
const { repo, ws } = connected();
|
||||
ws.reply = (frame) => ({ id: frame.id, type: "templates" });
|
||||
assert.deepEqual(await repo.listTemplates(), []);
|
||||
});
|
||||
|
||||
test("validate sends exactly {type:'validate', source} and returns response.graph", async () => {
|
||||
const { repo, ws } = connected();
|
||||
const graph = { stages: [{ key: "plan" }] };
|
||||
ws.reply = (frame) => ({ id: frame.id, type: "validated", graph });
|
||||
|
||||
const result = await repo.validate("the source");
|
||||
assert.deepEqual(lastFrame(ws), { type: "validate", source: "the source" });
|
||||
assert.deepEqual(result, graph);
|
||||
});
|
||||
|
||||
test("validate rejects a server error envelope with the server's text", async () => {
|
||||
const { repo, ws } = connected();
|
||||
ws.reply = (frame) => ({ id: frame.id, type: "error", error: "unexpected token" });
|
||||
await assert.rejects(() => repo.validate("bad source"), {
|
||||
name: "ProtocolError",
|
||||
message: "unexpected token",
|
||||
});
|
||||
});
|
||||
|
||||
test("validate throws when the reply has no graph", async () => {
|
||||
const { repo, ws } = connected();
|
||||
ws.reply = (frame) => ({ id: frame.id, type: "validated" });
|
||||
await assert.rejects(() => repo.validate("empty"), ProtocolError);
|
||||
});
|
||||
@@ -0,0 +1,87 @@
|
||||
// Pure Templates helper tests: wording (singular/plural, placeholders), the
|
||||
// card mapping and the stage-summary/graph-note derivations. No DOM, no server.
|
||||
import { test } from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
|
||||
import {
|
||||
effectiveStageType,
|
||||
stageCountText,
|
||||
templateCard,
|
||||
templateDetailName,
|
||||
templateGalleryName,
|
||||
templateGraphNote,
|
||||
templateStageCountLabel,
|
||||
templateStageSummary,
|
||||
TEMPLATE_GRAPH_NOTE,
|
||||
TEMPLATE_NO_STAGES_NOTE,
|
||||
TEMPLATE_UNPARSED_GRAPH_NOTE,
|
||||
TEMPLATE_UNPARSED_SUMMARY_NOTE,
|
||||
} from "../src/templates.js";
|
||||
|
||||
test("stageCountText spells one stage and many stages", () => {
|
||||
assert.equal(stageCountText(1), "1 stage");
|
||||
assert.equal(stageCountText(2), "2 stages");
|
||||
assert.equal(stageCountText(0), "0 stages");
|
||||
});
|
||||
|
||||
test("templateStageCountLabel says unavailable for an unknown count, never zero", () => {
|
||||
assert.equal(templateStageCountLabel(null), "stage count unavailable");
|
||||
assert.equal(templateStageCountLabel(undefined), "stage count unavailable");
|
||||
assert.equal(templateStageCountLabel(1), "1 stage");
|
||||
assert.equal(templateStageCountLabel(3), "3 stages");
|
||||
});
|
||||
|
||||
test("a blank gallery name becomes the unnamed placeholder", () => {
|
||||
assert.equal(templateGalleryName(""), "(unnamed template)");
|
||||
assert.equal(templateGalleryName(" "), "(unnamed template)");
|
||||
assert.equal(templateGalleryName("Review a repository"), "Review a repository");
|
||||
});
|
||||
|
||||
test("a blank detail name falls back to the template key", () => {
|
||||
assert.equal(templateDetailName({ key: "task", name: "" }), "task");
|
||||
assert.equal(templateDetailName({ key: "task", name: " " }), "task");
|
||||
assert.equal(templateDetailName({ key: "task", name: "Complete a task" }), "Complete a task");
|
||||
});
|
||||
|
||||
test("effectiveStageType defaults a blank type to model", () => {
|
||||
assert.equal(effectiveStageType(""), "model");
|
||||
assert.equal(effectiveStageType(null), "model");
|
||||
assert.equal(effectiveStageType(" "), "model");
|
||||
assert.equal(effectiveStageType("human"), "human");
|
||||
});
|
||||
|
||||
test("templateCard takes the stage count from the parsed graph, null when absent", () => {
|
||||
const entry = { key: "task", name: "Complete a task", description: "Do it." };
|
||||
assert.equal(templateCard(entry, null).stageCount, null);
|
||||
assert.equal(templateCard(entry, { stages: [] }).stageCount, 0);
|
||||
assert.equal(templateCard(entry, { stages: [{ key: "a" }, { key: "b" }] }).stageCount, 2);
|
||||
assert.deepEqual(templateCard(entry, null), {
|
||||
key: "task",
|
||||
name: "Complete a task",
|
||||
description: "Do it.",
|
||||
stageCount: null,
|
||||
});
|
||||
});
|
||||
|
||||
test("templateStageSummary distinguishes unparsed, empty and populated", () => {
|
||||
assert.deepEqual(templateStageSummary(null), {
|
||||
note: TEMPLATE_UNPARSED_SUMMARY_NOTE,
|
||||
stages: [],
|
||||
});
|
||||
assert.deepEqual(templateStageSummary({ stages: [] }), {
|
||||
note: TEMPLATE_NO_STAGES_NOTE,
|
||||
stages: [],
|
||||
});
|
||||
|
||||
const summary = templateStageSummary({ stages: [{ key: "plan", type: "" }, { key: "review", type: "human" }] });
|
||||
assert.equal(summary.note, null);
|
||||
assert.deepEqual(summary.stages, [
|
||||
{ key: "plan", type: "model" },
|
||||
{ key: "review", type: "human" },
|
||||
]);
|
||||
});
|
||||
|
||||
test("templateGraphNote picks the unparsed or parsed note", () => {
|
||||
assert.equal(templateGraphNote(null), TEMPLATE_UNPARSED_GRAPH_NOTE);
|
||||
assert.equal(templateGraphNote({ stages: [] }), TEMPLATE_GRAPH_NOTE);
|
||||
});
|
||||
@@ -332,6 +332,24 @@ try {
|
||||
await page.waitForSelector(".detail h2", { timeout: 25000 });
|
||||
await shot("16-run-detail.png");
|
||||
|
||||
step("opening the Templates gallery");
|
||||
await page.clickText("nav.tabs button.tab", "Templates");
|
||||
await page.waitForSelector(".cards button.card", { timeout: 25000 });
|
||||
shots.push(await page.screenshot(`${out}/17-templates-gallery.png`));
|
||||
const templateCount = await page.evaluate(`document.querySelectorAll(".cards button.card").length`);
|
||||
console.log(` templates rendered: ${templateCount}`);
|
||||
|
||||
step("opening a template detail (Summary)");
|
||||
await page.click(".cards button.card");
|
||||
await page.waitForSelector(".detail .tabstrip", { timeout: 25000 });
|
||||
await page.waitForText("Key", { timeout: 25000 });
|
||||
shots.push(await page.screenshot(`${out}/18-template-detail-summary.png`));
|
||||
|
||||
step("opening the template Source tab");
|
||||
await page.clickText(".detail .tabstrip button.minitab", "Source");
|
||||
await page.waitForText("Definition source", { timeout: 25000 });
|
||||
shots.push(await page.screenshot(`${out}/19-template-source.png`));
|
||||
|
||||
console.log("\nUI SMOKE PASS");
|
||||
for (const shot of shots) console.log(` ${shot}`);
|
||||
} catch (error) {
|
||||
|
||||
Reference in New Issue
Block a user