Files
archie/ui/test/task-logs.test.js
T
sam dc744c0b4f feat(ui): download a task attempt's log, and stop blaming a setting for it
The attempt-log panel offered no way to get a log out of the dashboard, and
its failure copy asserted that task logging was not enabled for the run. The
first is the feature: the panel now links to the download route for the attempt
it is showing, so the browser owns the filename the server sets and streams the
body to disk rather than the client holding a whole log in memory.

The second is the honesty fix. "No log recorded for this attempt" is a fact
about the attempt; "this dashboard cannot read task logs" is a fact about the
deployment, and only the second is worth sending an operator to a setting for.
The panel renders them differently off the response's found/disabled markers.

Rebuilds ui/dist, which is a committed asset.
2026-09-17 12:12:47 +00:00

106 lines
4.4 KiB
JavaScript

import { test } from "node:test";
import assert from "node:assert/strict";
import { render, cleanup } from "@testing-library/preact";
import { TaskLogPanel, taskLogDownloadURL } from "../src/tasks/task-logs.jsx";
function renderPanel(state, opts = {}) {
const { container, unmount } = render(<TaskLogPanel state={state} onRetry={opts.onRetry} taskId={opts.taskId} />);
return { root: container, unmount };
}
test("loading state renders a loading placeholder", () => {
const { root, unmount } = renderPanel(undefined);
assert.match(root.querySelector(".task-log-loading")?.className || "", /task-log-loading/);
assert.match(root.textContent, /Loading/);
unmount();
});
test("fetch failure renders a retry control", () => {
const { root, unmount } = renderPanel(null, { onRetry: () => {} });
assert.match(root.querySelector(".task-log-error")?.className || "", /task-log-error/);
const btn = root.querySelector("button");
assert.ok(btn, "a retry button should render");
assert.equal(btn.textContent, "Retry");
unmount();
});
// The panel used to answer every failed read with "Task logging is optional
// and was not enabled for this run", which was false in a deployment where
// logging is unconditional: the dashboard simply could not read the log. The
// two conditions are now stated differently, and this pins that they stay so.
test("a reader that is absent says the dashboard cannot read logs, not that logging is off", () => {
const { root, unmount } = renderPanel({ disabled: true, entries: [] });
assert.match(root.textContent, /No persisted log/);
assert.doesNotMatch(
root.textContent,
/not enabled for this run/,
"this text blames a configuration setting for a process that simply cannot read logs",
);
unmount();
});
test("an attempt with a reader but no log file is not reported as disabled", () => {
const { root, unmount } = renderPanel({ found: false, entries: [], attempt: 0 });
assert.match(root.textContent, /No log recorded for this attempt/);
assert.doesNotMatch(root.textContent, /was not enabled for this run/);
unmount();
});
test("empty entries render a placeholder distinct from the disabled state", () => {
const { root, unmount } = renderPanel({ disabled: false, found: true, entries: [], attempt: 0 });
assert.match(root.textContent, /Nothing recorded/);
unmount();
});
test("entries render one row per entry with fields visible, surfacing stage/token detail", () => {
const { root, unmount } = renderPanel({
found: true,
entries: [
{
time: "2026-01-01T00:00:00Z",
level: "info",
msg: "stage complete",
fields: { stage: "implement", tokens: 1234, model: "sonnet" },
},
{
time: "2026-01-01T00:01:00Z",
level: "error",
msg: "agent failed",
fields: { iteration: 3 },
},
],
});
const list = root.querySelector(".log-list");
assert.ok(list, "the log list wrapper should render");
assert.equal(list.children.length, 2, "one .log-row per entry");
assert.match(root.textContent, /stage complete/);
assert.match(root.textContent, /implement/);
assert.match(root.textContent, /1234/);
assert.match(root.textContent, /sonnet/);
assert.match(root.textContent, /agent failed/);
assert.match(root.textContent, /iteration/);
unmount();
});
// The download is the feature the panel was missing: an operator who wants the
// log in their own tooling had no way to get it.
test("the download link points at the attempt being shown", () => {
assert.equal(taskLogDownloadURL(42, 3), "/api/tasks/42/logs/download?attempt=3");
// No attempt yet resolved: let the server pick the task's current one.
assert.equal(taskLogDownloadURL(42, null), "/api/tasks/42/logs/download");
});
test("a panel with entries offers the download for that attempt", () => {
const { root, unmount } = renderPanel({ found: true, attempt: 3, entries: [{ level: "info", msg: "hi" }] }, { taskId: 42 });
const link = root.querySelector(".task-log-download");
assert.ok(link, "a download control should render when the attempt has a log");
assert.equal(link.getAttribute("href"), "/api/tasks/42/logs/download?attempt=3");
unmount();
});
test("a panel for an attempt with no log offers no download", () => {
const { root, unmount } = renderPanel({ found: false, attempt: 0, entries: [] }, { taskId: 42 });
assert.equal(root.querySelector(".task-log-download"), null, "there is nothing to download");
unmount();
});