Files
archie/e2e/archie-smoke.cjs
samandCopilot 64dfad6d53 feat(runs): add typed results and model aliases (#2043)
Also fix repository-free message.send validation (#2046) and add a single-binary development smoke path (#1977).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-11-18 23:47:35 +11:00

75 lines
3.4 KiB
JavaScript

const assert = require("node:assert/strict");
const { randomUUID } = require("node:crypto");
const { setTimeout: delay } = require("node:timers/promises");
async function main() {
assert.ok(process.env.ARCHIE_SMOKE_URL, "Set ARCHIE_SMOKE_URL to a disposable Archie stack");
const origin = new URL(process.env.ARCHIE_SMOKE_URL);
const token = process.env.ARCHIE_SMOKE_TOKEN;
assert.equal(origin.protocol, "http:");
assert.equal(origin.hostname, "127.0.0.1", "Use a disposable Archie stack on IPv4 loopback");
assert.ok(token, "Set ARCHIE_SMOKE_TOKEN to the disposable stack's admin token");
async function request(path, { method = "GET", body, authenticated = true, status = 200 } = {}) {
const response = await fetch(new URL(path, origin), {
method,
redirect: "error",
signal: AbortSignal.timeout(10_000),
headers: {
...(authenticated && { Authorization: `Bearer ${token}` }),
...(body !== undefined && { "Content-Type": "application/json" }),
},
body: body === undefined ? undefined : JSON.stringify(body),
}).catch((err) => {
throw new Error(`${method} ${path}: could not reach Archie at ${origin.origin}: ${err.cause?.message || err.message}`, { cause: err });
});
assert.equal(response.status, status, `${method} ${path}: expected HTTP ${status}, got ${response.status}`);
return response.json();
}
const ready = await request("/readyz", { authenticated: false });
assert.equal(ready.ready, true, "Archie is not ready");
await request("/api/workflows", { authenticated: false, status: 401 });
const name = `smoke-${randomUUID()}`;
const saved = await request(`/api/workflows/${name}`, {
method: "PUT",
body: { body: `repository: none\nsteps:\n - id: notify\n type: run.notify\n settings: {title: ${name}}\n` },
});
const trigger = { workflow: name, every: "1m" };
try {
await request(`/api/triggers/${name}`, { method: "PUT", body: trigger });
const deadline = Date.now() + 90_000;
let last = "no scheduled run";
while (Date.now() < deadline) {
const recent = await request("/api/runs");
const run = recent.find((row) => row.workflow === name);
if (run) {
last = `run ${run.id}: ${run.state}`;
assert.ok(!["failed", "cancelled"].includes(run.state), `${last}: ${run.error || "no error returned"}`);
if (run.state === "succeeded") {
const trail = await request(`/api/runs/${run.id}`);
assert.equal(trail.run.workflow_version, saved.version, "Run used the wrong workflow version");
assert.equal(trail.origin?.trigger, name, "Run trail is missing the schedule trigger");
assert.ok(trail.origin?.event_id, "Run trail is missing the originating event");
assert.equal(trail.origin.type, "schedule.tick");
const messages = await request("/api/composer/messages");
assert.equal(messages.filter((m) => m.run_id === run.id && m.title === name).length, 1,
"Expected one composer notification linked to the run");
console.log(`Schedule, run trail and composer notification verified for ${run.id}`);
return;
}
}
await delay(1_000);
}
throw new Error(`Timed out waiting for ${name}: ${last}`);
} finally {
await request(`/api/triggers/${name}`, { method: "PUT", body: { ...trigger, disabled: true } });
}
}
main().catch((err) => {
console.error(err.message);
process.exitCode = 1;
});