web: artifacts gallery, full-screen viewer and session export link (R8/R9)

Port the Android artifact derivation into a pure, DOM-free src/artifacts.js
(presentedArtifacts with the retired session.md hidden everywhere, grouping by
stage/visit, the header/summary/capture-note wording, kind and size formatting,
viewer paging and sessionExportArtifact) and unit-test it.

Wire it into src/app.js: a run-level artifacts gallery with per-(stage,visit)
groups, per-visit summaries and tiles, a full-screen viewer overlay (paging,
Escape/backdrop close) and the read-only session.html link. Every server string
is set with textContent; captures/ stays untracked.

Captured live against run 430 through test/ui-smoke.mjs:
captures/04-run-430-artifacts.png, 05-artifact-viewer.png,
06-session-export-link.png. PARITY.md marks R8 and R9 done.
This commit is contained in:
2026-10-19 02:38:48 +01:00
parent 4721b8af10
commit 67120947c2
6 changed files with 1191 additions and 23 deletions
+2 -2
View File
@@ -38,8 +38,8 @@ Status legend: `todo` · `partial` (some of it works) · `done` (working + captu
| R5 | Graph tab (per-stage panes, verdicts) | `get_run` | todo |
| R6 | Input / Output field sections per stage | `get_run` | todo |
| R7 | Timeline | `get_run` | todo |
| R8 | Artifacts gallery + full-screen viewer (images inline, others download/open) | `GET /artifacts/…` | todo |
| R9 | Session export link (read-only `session.html`) | `GET /artifacts/…` | todo |
| R8 | Artifacts gallery + full-screen viewer (images inline, others download/open) | `GET /artifacts/…` | done (captured 2026-10-19: `captures/04-run-430-artifacts.png`, `captures/05-artifact-viewer.png`) |
| R9 | Session export link (read-only `session.html`) | `GET /artifacts/…` | done (captured 2026-10-19: `captures/06-session-export-link.png`) |
| R10 | Live run updates: subscribe/unsubscribe + event fold | `subscribe`, `unsubscribe`, `run_event` | todo |
| R11 | Human decision sheet: prompt, options, feedback | `decide_run` | todo |
| R12 | Cancel run | `cancel_run` | todo |
+354 -20
View File
@@ -4,17 +4,30 @@
import { PipelinesClient } from "./client.js";
import { PipelinesRepository } from "./repository.js";
import { validateServerUrl, resolveArtifactUrl } from "./serverUrl.js";
import {
ArtifactKind,
artifactCaptureNotes,
artifactGroups,
artifactKind,
artifactKindLabel,
artifactsHeader,
artifactsSummary,
artifactViewerPositionLabel,
displayVisit,
humanBytes,
pagedArtifacts,
pagedIndex,
presentedArtifacts,
resolvedArtifactUrl,
sessionExportArtifact,
viewerIndexByUrl,
} from "./artifacts.js";
const STORAGE_KEY = "pipelines.web.serverUrl.v2";
/**
* The retired markdown session export. The server no longer writes it, but a run
* recorded before the HTML-only change still lists session.md among its stored
* artifacts. It is dated evidence the operator never sees, so every artifact
* listing hides it rather than showing it beside the session html (mirroring the
* app's presentedArtifacts).
*/
const LEGACY_SESSION_MARKDOWN_ARTIFACT = "session.md";
/** Shown where tiles exist but the configured server URL cannot resolve them. */
const ARTIFACT_SERVER_HINT =
"Set the server URL in Settings to open or copy artifact links.";
/**
* The page is normally served by serve.mjs, which also proxies /connect to the
@@ -342,6 +355,14 @@ function renderRunDetail() {
);
const steps = d.steps ?? [];
const executing = isExecuting(d);
// Run-level artifacts gallery (parity R8). The header is the run summary line
// and the gallery below it draws one group per (stage, visit); all derivation
// lives in artifacts.js so the count can never disagree with the tiles.
pane.append(h("h3", { class: "artifacts-header", text: artifactsHeader(steps, executing) }));
pane.append(renderArtifactGallery(steps));
pane.append(h("h3", { text: `Steps (${steps.length})` }));
if (!steps.length) {
pane.append(h("div", { class: "muted pad", text: "No steps recorded yet." }));
@@ -369,7 +390,8 @@ function renderRunDetail() {
kv("Session", s.session_id || "—"),
s.diagnostic ? kv("Diagnostic", s.diagnostic) : null,
),
renderArtifacts(s),
renderVisitArtifacts(s),
renderSessionExport(s),
),
);
}
@@ -377,21 +399,333 @@ function renderRunDetail() {
return pane;
}
function renderArtifacts(step) {
const artifacts = (step.artifacts ?? []).filter((a) => a.name !== LEGACY_SESSION_MARKDOWN_ARTIFACT);
if (!artifacts.length) return null;
const wrap = h("div", { class: "artifacts" }, h("span", { class: "muted", text: "Artifacts: " }));
for (const a of artifacts) {
const href = resolveArtifactUrl(state.url, a.url);
if (href) {
wrap.append(h("a", { href, target: "_blank", rel: "noreferrer", text: a.name || a.url }));
} else {
wrap.append(h("span", { class: "muted", text: `${a.name || a.url} (no server URL)` }));
}
/** Whether the configured server URL can resolve a server-relative artifact. */
function artifactsResolvable() {
return resolveArtifactUrl(state.url, "/artifacts/0/0/probe") != null;
}
/**
* The run-level gallery: one header per (stage, visit) and one grid of tiles per
* visit, in the gallery order (stages first-appearance, visits by sequence). A
* run with no artifacts shows the header (which already says why) and nothing
* else, so the section is never blank.
*/
function renderArtifactGallery(steps) {
const wrap = h("div", { class: "artifact-gallery" });
const groups = artifactGroups(steps);
if (!groups.length) return wrap;
if (!artifactsResolvable()) {
wrap.append(h("div", { class: "muted artifact-hint", text: ARTIFACT_SERVER_HINT }));
}
const viewable = pagedArtifacts(groups);
const viewerIndexOf = viewerIndexByUrl(groups);
for (const group of groups) {
wrap.append(
h("div", { class: "artifact-group-head", text: `${group.stageKey} · visit ${group.visit}` }),
renderArtifactGrid(group.artifacts, viewable, viewerIndexOf),
);
}
return wrap;
}
/**
* The per-visit artifacts section shown inside one step: the summary line, the
* capture notes, the no-server-URL hint and a headerless grid of that visit's
* tiles (matching the Android ArtifactsSection). Its viewer pages only through
* that visit's media, exactly as the Android section does.
*/
function renderVisitArtifacts(step) {
const wrap = h("div", { class: "artifacts" });
wrap.append(h("div", { class: "artifacts-summary", text: artifactsSummary(step) }));
for (const note of artifactCaptureNotes(step)) {
wrap.append(h("div", { class: "artifacts-note muted", text: note }));
}
const artifacts = presentedArtifacts(step);
if (artifacts.length) {
if (!artifactsResolvable()) {
wrap.append(h("div", { class: "muted artifact-hint", text: ARTIFACT_SERVER_HINT }));
}
const group = { stageKey: step.stage, visit: displayVisit(step, 0), artifacts };
wrap.append(
renderArtifactGrid(artifacts, pagedArtifacts([group]), viewerIndexByUrl([group])),
);
}
return wrap;
}
/** One visit's tiles in a CSS grid. */
function renderArtifactGrid(artifacts, viewable, viewerIndexOf) {
const grid = h("div", { class: "artifact-grid" });
for (const artifact of artifacts) {
grid.append(renderArtifactTile(artifact, viewable, viewerIndexOf));
}
return grid;
}
/**
* One gallery tile: an image thumbnail, a video poster with a play marker (never
* a <video> element or autoplay), or a kind/name/size label. Every server string
* is set as text, never as markup.
*/
function renderArtifactTile(artifact, viewable, viewerIndexOf) {
const resolved = resolvedArtifactUrl(artifact, state.url);
const kind = artifactKind(artifact.content_type, artifact.name);
const media = kind === ArtifactKind.Image || kind === ArtifactKind.Video;
const name = artifact.name || "(unnamed artifact)";
const tile = h("div", { class: "artifact-tile clickable" });
const openViewer = () => {
const at = viewerIndexOf.get(artifact.url);
if (at != null) openArtifactViewer(viewable, at);
};
const openTab = () => {
if (resolved) window.open(resolved, "_blank", "noopener,noreferrer");
};
if (kind === ArtifactKind.Image) {
const img = h("img", { class: "artifact-thumb", alt: name, loading: "lazy" });
if (resolved) img.src = resolved;
tile.append(img);
tile.addEventListener("click", openViewer);
} else if (kind === ArtifactKind.Video) {
tile.append(h("div", { class: "artifact-poster" }, h("span", { class: "artifact-play", text: "▶" })));
tile.append(h("div", { class: "artifact-name", text: name }));
tile.addEventListener("click", openViewer);
} else {
tile.append(
h("div", { class: "artifact-kind", text: artifactKindLabel(kind) }),
h("div", { class: "artifact-name", text: name }),
h("div", { class: "artifact-size", text: humanBytes(artifact.size_bytes) }),
);
tile.addEventListener("click", openTab);
}
tile.append(renderTileActions(resolved, media));
return tile;
}
/** The compact per-tile actions: copy-link (non-media tiles) and share. */
function renderTileActions(resolved, media) {
const actions = h("div", { class: "artifact-actions" });
const stop = (fn) => (event) => {
event.stopPropagation();
fn();
};
if (!media) {
actions.append(
h("button", {
class: "artifact-action",
type: "button",
text: "Copy link",
disabled: !resolved || !canCopyLink(),
onclick: stop(() => copyArtifactLink(resolved)),
}),
);
}
actions.append(
h("button", {
class: "artifact-action",
type: "button",
text: "Share",
disabled: !resolved || !canShare(),
onclick: stop(() => shareArtifact(resolved)),
}),
);
return actions;
}
function canCopyLink() {
return typeof navigator !== "undefined" && Boolean(navigator.clipboard?.writeText);
}
function canShare() {
return typeof navigator !== "undefined" && typeof navigator.share === "function";
}
async function copyArtifactLink(resolved) {
if (!resolved || !canCopyLink()) return;
try {
await navigator.clipboard.writeText(resolved);
} catch {
// Clipboard permission may be denied; the link is still openable.
}
}
async function shareArtifact(resolved) {
if (!resolved || !canShare()) return;
try {
await navigator.share({ url: resolved });
} catch {
// The share chooser may be dismissed.
}
}
/**
* The step's session export: a link opening the read-only session.html in a new
* tab, or the plain notice when the visit exported nothing (parity R9).
*/
function renderSessionExport(step) {
const file = sessionExportArtifact(step);
const wrap = h("div", { class: "session-export" });
if (!file) {
wrap.append(h("span", { class: "muted", text: "No session was exported for this visit." }));
return wrap;
}
const href = resolvedArtifactUrl(file, state.url);
if (href) {
wrap.append(
h("a", {
class: "session-link",
href,
target: "_blank",
rel: "noreferrer",
text: `Open ${file.name || "session.html"}`,
}),
);
} else {
wrap.append(
h("span", { class: "muted", text: "Set the server URL in Settings to open the session." }),
);
}
return wrap;
}
let viewerOverlay = null;
let viewerKeydown = null;
/** Close the full-screen viewer and remove its Escape listener. */
function closeArtifactViewer() {
if (viewerKeydown) {
document.removeEventListener("keydown", viewerKeydown);
viewerKeydown = null;
}
viewerOverlay?.remove();
viewerOverlay = null;
}
/**
* Open the full-screen viewer at `startIndex` into `viewable`, the same ordered
* media list the grid drew. Previous/Next are disabled at the ends and absent for
* a single artifact; Escape and a backdrop click close it. Nothing autoplays: a
* non-image artifact shows a still poster placeholder instead.
*/
function openArtifactViewer(viewable, startIndex) {
closeArtifactViewer();
if (!viewable?.length) return;
let index = pagedIndex(startIndex, 0, viewable.length);
const overlay = h("div", {
class: "artifact-viewer",
role: "dialog",
"aria-modal": "true",
"aria-label": "Artifact viewer",
});
overlay.addEventListener("click", (event) => {
if (event.target === overlay) closeArtifactViewer();
});
const renderViewer = () => {
const artifact = viewable[index] ?? {};
const resolved = resolvedArtifactUrl(artifact, state.url);
const kind = artifactKind(artifact.content_type, artifact.name);
const name = artifact.name || "(unnamed artifact)";
const board = h("div", { class: "viewer-board" });
if (kind === ArtifactKind.Image && resolved) {
board.append(h("img", { class: "viewer-image", src: resolved, alt: name }));
} else {
board.append(
h(
"div",
{ class: "viewer-placeholder" },
h("span", { class: "artifact-play", text: "▶" }),
h("span", { class: "viewer-placeholder-name", text: name }),
),
);
}
const head = h(
"div",
{ class: "viewer-head" },
h("div", { class: "viewer-title", text: name }),
h("div", {
class: "viewer-position muted",
text: artifactViewerPositionLabel(index, viewable.length, artifact.content_type),
}),
);
const actions = h("div", { class: "viewer-actions" });
if (resolved) {
actions.append(
h("button", {
class: "viewer-action",
type: "button",
text: "Open",
onclick: () => window.open(resolved, "_blank", "noopener,noreferrer"),
}),
h("button", {
class: "viewer-action",
type: "button",
text: "Copy link",
disabled: !canCopyLink(),
onclick: () => copyArtifactLink(resolved),
}),
h("button", {
class: "viewer-action",
type: "button",
text: "Share",
disabled: !canShare(),
onclick: () => shareArtifact(resolved),
}),
);
}
actions.append(
h("button", {
class: "viewer-action viewer-close",
type: "button",
text: "Close viewer",
onclick: closeArtifactViewer,
}),
);
const nodes = [head, board];
if (viewable.length > 1) {
nodes.push(
h(
"div",
{ class: "viewer-nav" },
h("button", {
class: "viewer-page",
type: "button",
text: "Previous artifact",
disabled: pagedIndex(index, -1, viewable.length) === index,
onclick: () => {
index = pagedIndex(index, -1, viewable.length);
renderViewer();
},
}),
h("button", {
class: "viewer-page",
type: "button",
text: "Next artifact",
disabled: pagedIndex(index, 1, viewable.length) === index,
onclick: () => {
index = pagedIndex(index, 1, viewable.length);
renderViewer();
},
}),
),
);
}
nodes.push(actions);
overlay.replaceChildren(...nodes);
};
renderViewer();
document.body.append(overlay);
viewerOverlay = overlay;
viewerKeydown = (event) => {
if (event.key === "Escape") closeArtifactViewer();
};
document.addEventListener("keydown", viewerKeydown);
}
function kv(key, value) {
return h(
"div",
+390
View File
@@ -0,0 +1,390 @@
// Pure, DOM-free artifact derivation for the run detail, ported from the Android
// client so the browser says and does exactly the same thing:
// ui/ArtifactGroups.kt presentedArtifacts, runArtifactGroups, artifactsEmptyMessage
// ui/Format.kt artifactsSummary, artifactCaptureNotes, humanBytes, content-type tests
// ui/graph/ArtifactType.kt artifactKind, artifactKindLabel
// ui/graph/Artifacts.kt the gallery's group/visit/tile vocabulary
// ui/graph/ArtifactViewer.kt pagedArtifacts, viewerIndexByUrl, pagedIndex, position label
// ui/graph/SessionExport.kt sessionExportFile
// ui/screens/Timeline.kt the display visit number (control.visit, else position + 1)
// ui/ArtifactType.kt the file-kind classification vocabulary
//
// Nothing here touches the DOM or imports the app: every function is pure so the
// wording, ordering, counting and formatting can be unit-tested without a browser.
// The tile/overlay wiring lives in app.js.
import { resolveArtifactUrl } from "./serverUrl.js";
/**
* The retired markdown session export file name. Nothing writes it any more, but
* a run recorded before the HTML-only change still lists `session.md`: it is
* dated evidence that is never presented, so it is hidden from every artifact
* listing rather than shown beside the session html. Mirrors
* ArtifactGroups.kt LEGACY_SESSION_MARKDOWN_ARTIFACT.
*/
export const LEGACY_SESSION_MARKDOWN_ARTIFACT = "session.md";
/**
* The "capture pending" wording shared by a running visit's summary and the
* run-level empty state, so the two never spell it differently.
*/
export const ARTIFACT_CAPTURE_PENDING = "capture pending";
/**
* What an artifact's file type is, from the app's point of view: the two media
* kinds the gallery previews (image, video) and the file kinds it labels with a
* type glyph. Mirrors graph/ArtifactType.kt ArtifactKind.
*/
export const ArtifactKind = Object.freeze({
Image: "Image",
Video: "Video",
Audio: "Audio",
Pdf: "Pdf",
Json: "Json",
Archive: "Archive",
Spreadsheet: "Spreadsheet",
Log: "Log",
Code: "Code",
Document: "Document",
Other: "Other",
});
const ARCHIVE_EXTENSIONS = new Set([
"zip", "tar", "gz", "tgz", "bz2", "xz", "rar", "7z", "jar", "war",
]);
const ARCHIVE_MIMES = new Set([
"application/zip",
"application/gzip",
"application/x-tar",
"application/x-7z-compressed",
"application/x-rar-compressed",
"application/java-archive",
]);
const SPREADSHEET_EXTENSIONS = new Set(["csv", "tsv", "xls", "xlsx", "ods"]);
const SPREADSHEET_MIMES = new Set([
"text/csv",
"text/tab-separated-values",
"application/vnd.ms-excel",
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
]);
const CODE_EXTENSIONS = new Set([
"kt", "kts", "java", "go", "py", "rb", "php", "rs", "c", "h", "cc", "cpp",
"hpp", "cs", "js", "jsx", "ts", "tsx", "mjs", "cjs", "swift", "scala", "sh",
"bash", "zsh", "fish", "ps1", "sql", "yaml", "yml", "toml", "ini", "xml",
"gradle", "properties", "proto",
]);
const CODE_MIMES = new Set([
"application/xml",
"application/x-yaml",
"application/javascript",
"text/javascript",
"text/x-python",
"text/x-java-source",
"text/x-kotlin",
"application/x-sh",
"application/x-httpd-php",
"application/sql",
]);
const DOCUMENT_EXTENSIONS = new Set([
"txt", "md", "markdown", "rst", "doc", "docx", "odt", "rtf", "html", "htm",
]);
const DOCUMENT_MIMES = new Set([
"application/msword",
"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
"application/rtf",
]);
const KIND_LABELS = Object.freeze({
[ArtifactKind.Image]: "Image",
[ArtifactKind.Video]: "Video",
[ArtifactKind.Audio]: "Audio",
[ArtifactKind.Pdf]: "PDF",
[ArtifactKind.Json]: "JSON",
[ArtifactKind.Archive]: "Archive",
[ArtifactKind.Spreadsheet]: "Spreadsheet",
[ArtifactKind.Log]: "Log",
[ArtifactKind.Code]: "Code",
[ArtifactKind.Document]: "Document",
[ArtifactKind.Other]: "File",
});
/** Whether an artifact's content type is an image the gallery can preview. */
export function isImageContentType(contentType) {
return String(contentType ?? "").startsWith("image/");
}
/**
* Whether an artifact's content type is a video. Videos are shown in the gallery
* as a poster-style tile with a play marker; they are never decoded inline and
* never autoplay.
*/
export function isVideoContentType(contentType) {
return String(contentType ?? "").startsWith("video/");
}
/**
* The artifacts of one visit as the operator sees them: the recorded files with
* the retired markdown session export filtered out. Every artifact listing
* derives from this one function, so a visit never shows a session markdown
* beside the session html and the recorded counts can never disagree with the
* tiles. Duplicate names are kept, not deduped: an artifact's identity is its
* recorded url, not its name. Mirrors ArtifactGroups.kt presentedArtifacts.
*/
export function presentedArtifacts(step) {
return (step?.artifacts ?? []).filter(
(artifact) => artifact?.name !== LEGACY_SESSION_MARKDOWN_ARTIFACT,
);
}
/** How many files the capture excluded for `step` (absent means none). */
export function artifactsSkipped(step) {
return Number(step?.artifacts_skipped ?? 0) || 0;
}
/** How many files the capture omitted for `step` (absent means none). */
export function artifactsTruncated(step) {
return Number(step?.artifacts_truncated ?? 0) || 0;
}
/** The extension of `name` (lowercased), or "" when it carries none. */
function extensionOf(name) {
const text = String(name ?? "");
const dot = text.lastIndexOf(".");
return dot === -1 ? "" : text.slice(dot + 1).toLowerCase();
}
/**
* The gallery kind of an artifact from its `contentType` (server-sniffed, may
* carry parameters) and its `name` (the extension is the fallback when the sniff
* is a generic text/plain or application/octet-stream). Image and video come
* straight from the content type; the rest match the normalised mime first, then
* the name's extension. Pure and total. Mirrors graph/ArtifactType.kt artifactKind.
*/
export function artifactKind(contentType, name) {
if (isImageContentType(contentType)) return ArtifactKind.Image;
if (isVideoContentType(contentType)) return ArtifactKind.Video;
const ct = String(contentType ?? "");
const mime = ct.split(";")[0].trim().toLowerCase();
const ext = extensionOf(name);
if (mime.startsWith("audio/")) return ArtifactKind.Audio;
if (mime === "application/pdf" || ext === "pdf") return ArtifactKind.Pdf;
if (mime.includes("json") || ext === "json") return ArtifactKind.Json;
if (ARCHIVE_MIMES.has(mime) || ARCHIVE_EXTENSIONS.has(ext)) return ArtifactKind.Archive;
if (SPREADSHEET_MIMES.has(mime) || SPREADSHEET_EXTENSIONS.has(ext)) return ArtifactKind.Spreadsheet;
if (ext === "log") return ArtifactKind.Log;
if (mime === "text/html") return ArtifactKind.Document;
if (CODE_MIMES.has(mime) || CODE_EXTENSIONS.has(ext)) return ArtifactKind.Code;
if (mime.startsWith("text/") || DOCUMENT_MIMES.has(mime) || DOCUMENT_EXTENSIONS.has(ext)) {
return ArtifactKind.Document;
}
return ArtifactKind.Other;
}
/**
* The word that names `kind` where the gallery shows its glyph but must also say
* the type in prose (a screen reader cannot read an icon). The same
* classification `artifactKind` draws from, so glyph and word never disagree.
*/
export function artifactKindLabel(kind) {
return KIND_LABELS[kind] ?? "File";
}
/**
* Human-readable byte size, matching Android Format.kt humanBytes (and the TUI):
* whole bytes under 1 KiB, otherwise one decimal with a binary unit
* (KiB/MiB/GiB/TiB/PiB/EiB).
*/
export function humanBytes(size) {
const value = Math.trunc(Number(size) || 0);
const unit = 1024;
if (value < unit) return `${value} B`;
let div = unit;
let exp = 0;
let scaled = Math.trunc(value / unit);
while (scaled >= unit) {
div *= unit;
exp++;
scaled = Math.trunc(scaled / unit);
}
return `${(value / div).toFixed(1)} ${"KMGTPE"[exp]}iB`;
}
/**
* The display visit number for a step at `index` within its stage's ordered
* visits: the recorded control visit when positive, otherwise the position
* within the stage. Mirrors Timeline.kt (`control.visit > 0 ? visit : index + 1`).
*/
export function displayVisit(step, index) {
const visit = step?.control?.visit;
return Number(visit) > 0 ? Number(visit) : index + 1;
}
/**
* Groups a run's artifacts by stage and visit. Stages keep first-appearance
* order and each stage's visits are ordered by sequence, with the display visit
* number above. Only visits that recorded at least one presented artifact
* produce a group, so an empty capture never yields an empty group and an
* artifact-less run yields an empty list. Mirrors ArtifactGroups.kt
* runArtifactGroups + Timeline.kt runTimeline.
*/
export function artifactGroups(steps) {
const list = steps ?? [];
if (list.length === 0) return [];
// groupBy(stage) keeps first-appearance order (a Map preserves insertion
// order); each stage's visits are then ordered by sequence.
const visitsByStage = new Map();
for (const step of list) {
const stage = step?.stage ?? "";
if (!visitsByStage.has(stage)) visitsByStage.set(stage, []);
visitsByStage.get(stage).push(step);
}
const groups = [];
for (const [stageKey, visits] of visitsByStage) {
const ordered = [...visits].sort((a, b) => (a?.sequence ?? 0) - (b?.sequence ?? 0));
ordered.forEach((step, index) => {
const artifacts = presentedArtifacts(step);
if (artifacts.length === 0) return;
groups.push({ stageKey, visit: displayVisit(step, index), artifacts });
});
}
return groups;
}
/**
* The explicit message shown where the run's artifacts gallery would be when
* there are none: while the run is executing it uses the same "capture pending"
* wording as a running visit, otherwise it says plainly that nothing was
* recorded. Mirrors ArtifactGroups.kt artifactsEmptyMessage.
*/
export function artifactsEmptyMessage(executing) {
return executing
? `Artifacts · ${ARTIFACT_CAPTURE_PENDING}`
: "No artifacts recorded for this run.";
}
/**
* The run summary's Artifacts section header: the title, how many artifacts the
* run recorded (the title takes its singular form for exactly one) and
* "partial capture" when any visit excluded or omitted files. It reuses the
* shared empty message, so a run with nothing recorded still gets a
* self-describing header. The recorded count is exactly the number of tiles
* `artifactGroups` yields. Mirrors ArtifactGroups.kt runArtifactsHeader.
*/
export function artifactsHeader(steps, executing) {
const list = steps ?? [];
const recorded = list.reduce((sum, step) => sum + presentedArtifacts(step).length, 0);
if (recorded === 0) return artifactsEmptyMessage(executing);
const partial = list.some((step) => artifactsSkipped(step) > 0 || artifactsTruncated(step) > 0);
let label = `${recorded === 1 ? "Artifact" : "Artifacts"} · ${recorded} recorded`;
if (partial) label += " · partial capture";
return label;
}
/**
* The per-visit artifacts summary label: "capture pending" while the visit runs,
* "not recorded for this visit" for a finished visit with no artifacts,
* otherwise the recorded count plus " · partial capture" when files were
* excluded or omitted. Mirrors Format.kt artifactsSummary.
*/
export function artifactsSummary(step) {
const artifacts = presentedArtifacts(step);
if (artifacts.length === 0) {
const state = step?.status === "running" ? ARTIFACT_CAPTURE_PENDING : "not recorded for this visit";
return `Artifacts · ${state}`;
}
let label = `Artifacts · ${artifacts.length} recorded`;
if (artifactsSkipped(step) > 0 || artifactsTruncated(step) > 0) label += " · partial capture";
return label;
}
/**
* The partial-capture notes, one line per non-zero count and nothing when the
* capture was complete. An empty artifact list yields no notes at all, so the
* notes never accompany the empty-state summary. Mirrors Format.kt
* artifactCaptureNotes.
*/
export function artifactCaptureNotes(step) {
const notes = [];
if (presentedArtifacts(step).length === 0) return notes;
const skipped = artifactsSkipped(step);
const truncated = artifactsTruncated(step);
if (skipped > 0) notes.push(`${skipped} files excluded from artifact capture.`);
if (truncated > 0) notes.push(`${truncated} files omitted by artifact capture limits.`);
return notes;
}
/**
* The media artifacts `groups` hold, in the exact order the gallery draws them
* (group by group, each group's images and videos in recorded order): the
* neighbours the full-screen viewer pages through, so a swipe visits the same
* list the grid showed. Non-media artifacts open externally and are not part of
* it. Mirrors ArtifactViewer.kt pagedArtifacts.
*/
export function pagedArtifacts(groups) {
const viewable = [];
for (const group of groups ?? []) {
for (const artifact of group?.artifacts ?? []) {
const kind = artifactKind(artifact?.content_type, artifact?.name);
if (kind === ArtifactKind.Image || kind === ArtifactKind.Video) viewable.push(artifact);
}
}
return viewable;
}
/**
* Each gallery media artifact's url mapped to its position in `pagedArtifacts`,
* the same ordered list the viewer pages through. The grid's tiles resolve their
* viewer index here, so tile and viewer derive from one source and cannot drift.
* The first occurrence of a url wins. Mirrors ArtifactViewer.kt viewerIndexByUrl.
*/
export function viewerIndexByUrl(groups) {
const indices = new Map();
pagedArtifacts(groups).forEach((artifact, index) => {
if (!indices.has(artifact.url)) indices.set(artifact.url, index);
});
return indices;
}
/**
* The index paging from `current` by `delta` within a list of `count`, clamped
* at both ends so a page never wraps (and an empty list is index 0). The one
* paging rule the viewer's buttons share. Mirrors ArtifactViewer.kt pagedIndex.
*/
export function pagedIndex(current, delta, count) {
if (count <= 0) return 0;
return Math.min(Math.max(current + delta, 0), count - 1);
}
/** The viewer's position label, e.g. `2 of 5 · image/png`. Mirrors ArtifactViewer.kt. */
export function artifactViewerPositionLabel(index, count, contentType) {
const type = String(contentType ?? "").split(";")[0].trim() || "artifact";
return `${index + 1} of ${count} · ${type}`;
}
/**
* The html session export `step` recorded, matched to the visit's recorded
* artifacts by exact name, or null when the visit has no export to open. A visit
* that recorded no export, whose export name is blank, or whose file is missing
* from a truncated listing yields null. Mirrors SessionExport.kt sessionExportFile.
*/
export function sessionExportArtifact(step) {
const html = step?.session_export?.html;
if (typeof html !== "string" || html.trim() === "") return null;
return (step?.artifacts ?? []).find((artifact) => artifact?.name === html) ?? null;
}
/**
* The absolute url a gallery artifact can be opened at, or null when it cannot
* be resolved against the configured server (blank or invalid). The one place a
* gallery artifact url is resolved, so tiles and the viewer never disagree.
* Re-exported here so callers derive tiles from this module alone.
*/
export function resolvedArtifactUrl(artifact, configuredServerUrl) {
return resolveArtifactUrl(configuredServerUrl, artifact?.url);
}
+90 -1
View File
@@ -70,7 +70,10 @@ button.ghost { background: transparent; }
.tab.active { background: var(--surface-2); border-color: var(--border); color: var(--accent); }
.split { display: grid; grid-template-columns: minmax(260px, 380px) 1fr; gap: 16px; padding: 16px; align-items: start; }
@media (max-width: 760px) { .split { grid-template-columns: 1fr; } }
@media (max-width: 760px) {
.split { grid-template-columns: 1fr; }
.artifact-grid { grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); }
}
.list, .detail {
background: var(--surface);
@@ -118,6 +121,92 @@ button.ghost { background: transparent; }
.artifacts { margin-top: 8px; font-size: 12px; }
.artifacts a { color: var(--accent); margin-right: 10px; }
.artifacts-summary { color: var(--accent); }
.artifacts-note { margin-top: 2px; }
.artifact-hint { margin: 4px 0; }
/* Run-level artifacts gallery: group headers + a fitting tile grid. */
.artifacts-header { margin-top: 18px; }
.artifact-gallery { display: grid; gap: 12px; }
.artifact-group-head { color: var(--muted); font-size: 12px; font-weight: 600; margin-top: 4px; }
.artifact-grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
gap: 10px;
}
.artifact-tile {
position: relative;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
gap: 4px;
min-height: 120px;
padding: 10px;
background: var(--surface-2);
border: 1px solid var(--border);
border-radius: 10px;
overflow: hidden;
text-align: center;
}
.artifact-tile.clickable { cursor: pointer; }
.artifact-tile.clickable:hover { border-color: var(--accent); }
.artifact-thumb { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.artifact-poster {
display: flex;
align-items: center;
justify-content: center;
width: 56px;
height: 56px;
border-radius: 50%;
background: rgba(0, 0, 0, 0.45);
}
.artifact-play { font-size: 18px; color: var(--text); }
.artifact-kind { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; }
.artifact-name { font-size: 12px; font-weight: 600; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.artifact-size { color: var(--muted); font-size: 11px; }
.artifact-actions { position: absolute; top: 8px; right: 6px; display: flex; gap: 4px; }
.artifact-action {
padding: 2px 6px;
font-size: 10px;
border-radius: 6px;
background: rgba(14, 21, 19, 0.72);
}
.artifact-action:disabled { opacity: 0.4; cursor: not-allowed; }
/* The per-visit session export link / notice (parity R9). */
.session-export { margin-top: 6px; font-size: 12px; }
.session-link { color: var(--accent); }
/* Full-screen artifact viewer overlay. */
.artifact-viewer {
position: fixed;
inset: 0;
z-index: 20;
display: flex;
flex-direction: column;
gap: 12px;
padding: 20px;
background: rgba(0, 0, 0, 0.86);
}
.viewer-head { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.viewer-title { font-size: 15px; font-weight: 600; }
.viewer-position { font-size: 12px; }
.viewer-board { flex: 1; display: flex; align-items: center; justify-content: center; min-height: 0; }
.viewer-image { max-width: 100%; max-height: 100%; object-fit: contain; }
.viewer-placeholder {
display: flex;
flex-direction: column;
align-items: center;
gap: 12px;
padding: 32px;
color: var(--muted);
}
.viewer-placeholder .artifact-play { font-size: 40px; }
.viewer-nav { display: flex; gap: 8px; justify-content: center; }
.viewer-page:disabled { opacity: 0.4; cursor: not-allowed; }
.viewer-actions { display: flex; gap: 8px; justify-content: flex-end; }
.chip { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 11px; border: 1px solid var(--border); color: var(--muted); }
.chip-running, .chip-queued { color: var(--warn); border-color: var(--warn); }
+297
View File
@@ -0,0 +1,297 @@
// Unit tests for the ported artifact derivation, run with `node --test`.
// Mirrors the cases in android/.../test/.../ArtifactGroupsTest.kt and the
// wording/formatting assertions around Format.kt, graph/ArtifactType.kt,
// graph/ArtifactViewer.kt and graph/SessionExport.kt.
import { test } from "node:test";
import assert from "node:assert/strict";
import {
ArtifactKind,
ARTIFACT_CAPTURE_PENDING,
LEGACY_SESSION_MARKDOWN_ARTIFACT,
artifactCaptureNotes,
artifactGroups,
artifactKind,
artifactKindLabel,
artifactsEmptyMessage,
artifactsHeader,
artifactsSummary,
artifactViewerPositionLabel,
displayVisit,
humanBytes,
pagedArtifacts,
pagedIndex,
presentedArtifacts,
sessionExportArtifact,
viewerIndexByUrl,
} from "../src/artifacts.js";
/** A minimal StageArtifact, named so tests read like the Android fixtures. */
function art(name, { contentType = "", sizeBytes = 0, url } = {}) {
return { name, content_type: contentType, size_bytes: sizeBytes, url: url ?? `/artifacts/1/1/${name}` };
}
/** A minimal RunStep with a recorded control visit and optional artifacts. */
function step(stage, sequence, { visit = 1, status = "completed", artifacts, skipped, truncated, exportHtml } = {}) {
const s = { stage, sequence, status, control: { visit, max_visits: 3 } };
if (artifacts !== undefined) s.artifacts = artifacts;
if (skipped !== undefined) s.artifacts_skipped = skipped;
if (truncated !== undefined) s.artifacts_truncated = truncated;
if (exportHtml !== undefined) s.session_export = { html: exportHtml };
return s;
}
test("presentedArtifacts hides the retired session.md and keeps everything else", () => {
const artifacts = [art("shot.png"), art(LEGACY_SESSION_MARKDOWN_ARTIFACT), art("session.html")];
const presented = presentedArtifacts({ artifacts });
assert.deepEqual(presented.map((a) => a.name), ["shot.png", "session.html"]);
assert.deepEqual(presentedArtifacts({}), []);
assert.deepEqual(presentedArtifacts({ artifacts: [] }), []);
assert.deepEqual(presentedArtifacts(undefined), []);
});
test("session.md is hidden from every listing: groups, header and summary", () => {
const onlyLegacy = [step("planner", 1, { artifacts: [art(LEGACY_SESSION_MARKDOWN_ARTIFACT)] })];
assert.deepEqual(artifactGroups(onlyLegacy), []);
assert.equal(artifactsHeader(onlyLegacy, false), "No artifacts recorded for this run.");
assert.equal(artifactsSummary(onlyLegacy[0]), "Artifacts · not recorded for this visit");
assert.deepEqual(artifactCaptureNotes(onlyLegacy[0]), []);
});
test("groups interleaved steps by stage then visit: [planner·1, planner·2, build·1]", () => {
const steps = [
step("planner", 1, { visit: 1, artifacts: [art("a.png")] }),
step("build", 2, { visit: 1, artifacts: [art("b.png")] }),
step("planner", 3, { visit: 2, artifacts: [art("c.png")] }),
];
const groups = artifactGroups(steps);
assert.deepEqual(
groups.map((g) => `${g.stageKey}·${g.visit}`),
["planner·1", "planner·2", "build·1"],
);
assert.deepEqual(groups[0].artifacts.map((a) => a.name), ["a.png"]);
});
test("duplicate names are kept, not deduped", () => {
const steps = [
step("planner", 1, {
artifacts: [
art("shot.png", { url: "/artifacts/1/1/shot-a.png" }),
art("shot.png", { url: "/artifacts/1/1/shot-b.png" }),
],
}),
];
const groups = artifactGroups(steps);
assert.equal(groups.length, 1);
assert.equal(groups[0].artifacts.length, 2);
assert.deepEqual(groups[0].artifacts.map((a) => a.url), [
"/artifacts/1/1/shot-a.png",
"/artifacts/1/1/shot-b.png",
]);
});
test("empty/null artifact visits and an empty run produce no group", () => {
assert.deepEqual(artifactGroups([]), []);
assert.deepEqual(artifactGroups(undefined), []);
const steps = [
step("planner", 1, {}), // no artifacts key
step("planner", 2, { artifacts: [] }), // empty capture
step("planner", 3, { artifacts: null }),
step("build", 4, { artifacts: [art("only.png")] }),
];
const groups = artifactGroups(steps);
assert.equal(groups.length, 1);
assert.equal(groups[0].stageKey, "build");
assert.equal(groups[0].visit, 1);
});
test("display visit number is control.visit when positive, else the position + 1", () => {
assert.equal(displayVisit(step("s", 1, { visit: 2 }), 0), 2);
assert.equal(displayVisit(step("s", 1, { visit: 0 }), 0), 1);
assert.equal(displayVisit(step("s", 1, { visit: 0 }), 4), 5);
assert.equal(displayVisit({ stage: "s", sequence: 1 }, 2), 3); // no control at all
const steps = [
step("planner", 1, { visit: 0, artifacts: [art("a")] }),
step("planner", 2, { visit: 0, artifacts: [art("b")] }),
];
assert.deepEqual(artifactGroups(steps).map((g) => g.visit), [1, 2]);
});
test("the run header counts exactly the tiles the gallery yields", () => {
const steps = [
step("planner", 1, { artifacts: [art("a.png"), art(LEGACY_SESSION_MARKDOWN_ARTIFACT)] }),
step("build", 2, { artifacts: [art("b.png"), art("c.png"), art("d.png")] }),
];
const tiles = artifactGroups(steps).reduce((n, g) => n + g.artifacts.length, 0);
assert.equal(tiles, 4);
assert.equal(artifactsHeader(steps, false), `Artifacts · ${tiles} recorded`);
assert.equal(artifactsHeader(steps, false), "Artifacts · 4 recorded");
});
test("the run header is singular for exactly one artifact and flags partial capture", () => {
assert.equal(artifactsHeader([step("s", 1, { artifacts: [art("one.png")] })], false), "Artifact · 1 recorded");
assert.equal(
artifactsHeader([step("s", 1, { artifacts: [art("a.png")], skipped: 2 })], false),
"Artifact · 1 recorded · partial capture",
);
assert.equal(
artifactsHeader([step("s", 1, { artifacts: [art("a.png")], truncated: 5 })], false),
"Artifact · 1 recorded · partial capture",
);
});
test("the run header empty wording matches running vs finished", () => {
assert.equal(artifactsHeader([], true), "Artifacts · capture pending");
assert.equal(artifactsHeader([], false), "No artifacts recorded for this run.");
assert.equal(artifactsEmptyMessage(true), `Artifacts · ${ARTIFACT_CAPTURE_PENDING}`);
assert.equal(artifactsEmptyMessage(false), "No artifacts recorded for this run.");
});
test("the per-visit summary uses the exact recorded/pending/not-recorded wording", () => {
assert.equal(
artifactsSummary(step("s", 1, { status: "completed", artifacts: [art("a"), art("b"), art("c")] })),
"Artifacts · 3 recorded",
);
assert.equal(
artifactsSummary(step("s", 1, { artifacts: [art("a")], truncated: 1 })),
"Artifacts · 1 recorded · partial capture",
);
assert.equal(
artifactsSummary(step("s", 1, { status: "running", artifacts: [] })),
"Artifacts · capture pending",
);
assert.equal(
artifactsSummary(step("s", 1, { status: "completed", artifacts: [] })),
"Artifacts · not recorded for this visit",
);
assert.equal(
artifactsSummary(step("s", 1, { status: "completed" })),
"Artifacts · not recorded for this visit",
);
});
test("capture notes use the exact wording and stay silent on an empty capture", () => {
const full = step("s", 1, { artifacts: [art("a")], skipped: 4, truncated: 7 });
assert.deepEqual(artifactCaptureNotes(full), [
"4 files excluded from artifact capture.",
"7 files omitted by artifact capture limits.",
]);
assert.deepEqual(artifactCaptureNotes(step("s", 1, { artifacts: [art("a")], skipped: 2 })), [
"2 files excluded from artifact capture.",
]);
assert.deepEqual(artifactCaptureNotes(step("s", 1, { artifacts: [art("a")] })), []);
assert.deepEqual(artifactCaptureNotes(step("s", 1, { artifacts: [], skipped: 4 })), []);
});
test("artifactKind classifies images, videos and every file kind", () => {
assert.equal(artifactKind("image/png", "shot.png"), ArtifactKind.Image);
assert.equal(artifactKind("video/mp4", "clip.mp4"), ArtifactKind.Video);
assert.equal(artifactKind("audio/mpeg", "sound.mp3"), ArtifactKind.Audio);
assert.equal(artifactKind("application/pdf", "report"), ArtifactKind.Pdf);
assert.equal(artifactKind("application/octet-stream", "data.pdf"), ArtifactKind.Pdf);
assert.equal(artifactKind("application/json", "payload"), ArtifactKind.Json);
assert.equal(artifactKind("text/plain", "config.json"), ArtifactKind.Json);
assert.equal(artifactKind("application/zip", "bundle"), ArtifactKind.Archive);
assert.equal(artifactKind("text/plain", "backup.tar.gz"), ArtifactKind.Archive);
assert.equal(artifactKind("text/csv", "rows"), ArtifactKind.Spreadsheet);
assert.equal(artifactKind("application/octet-stream", "sheet.xlsx"), ArtifactKind.Spreadsheet);
assert.equal(artifactKind("text/plain", "run.log"), ArtifactKind.Log);
assert.equal(artifactKind("application/xml", "layout"), ArtifactKind.Code);
assert.equal(artifactKind("text/plain", "main.go"), ArtifactKind.Code);
assert.equal(artifactKind("text/html; charset=utf-8", "session.html"), ArtifactKind.Document);
assert.equal(artifactKind("text/plain", "notes.txt"), ArtifactKind.Document);
assert.equal(artifactKind("application/octet-stream", "blob.bin"), ArtifactKind.Other);
assert.equal(artifactKind("", ""), ArtifactKind.Other);
});
test("artifactKindLabel names every kind in prose", () => {
assert.equal(artifactKindLabel(ArtifactKind.Image), "Image");
assert.equal(artifactKindLabel(ArtifactKind.Video), "Video");
assert.equal(artifactKindLabel(ArtifactKind.Audio), "Audio");
assert.equal(artifactKindLabel(ArtifactKind.Pdf), "PDF");
assert.equal(artifactKindLabel(ArtifactKind.Json), "JSON");
assert.equal(artifactKindLabel(ArtifactKind.Archive), "Archive");
assert.equal(artifactKindLabel(ArtifactKind.Spreadsheet), "Spreadsheet");
assert.equal(artifactKindLabel(ArtifactKind.Log), "Log");
assert.equal(artifactKindLabel(ArtifactKind.Code), "Code");
assert.equal(artifactKindLabel(ArtifactKind.Document), "Document");
assert.equal(artifactKindLabel(ArtifactKind.Other), "File");
assert.equal(artifactKindLabel("nonsense"), "File");
});
test("humanBytes matches the app's binary formatting", () => {
assert.equal(humanBytes(0), "0 B");
assert.equal(humanBytes(999), "999 B");
assert.equal(humanBytes(1024), "1.0 KiB");
assert.equal(humanBytes(1536), "1.5 KiB");
assert.equal(humanBytes(2 * 1024 * 1024), "2.0 MiB");
assert.equal(humanBytes(3 * 1024 * 1024 * 1024), "3.0 GiB");
});
test("viewer position label trims the subtype and falls back to 'artifact'", () => {
assert.equal(artifactViewerPositionLabel(0, 3, "image/png"), "1 of 3 · image/png");
assert.equal(artifactViewerPositionLabel(1, 3, "image/png; charset=binary"), "2 of 3 · image/png");
assert.equal(artifactViewerPositionLabel(4, 5, ""), "5 of 5 · artifact");
assert.equal(artifactViewerPositionLabel(0, 1, " "), "1 of 1 · artifact");
});
test("pagedArtifacts keeps only images and videos, in gallery order", () => {
const groups = [
{ stageKey: "reviewer", visit: 3, artifacts: [art("session.html", { contentType: "text/html" })] },
{
stageKey: "ui_reviewer",
visit: 2,
artifacts: [
art("shot.png", { contentType: "image/png" }),
art("shot.png.xml", { contentType: "application/xml" }),
art("clip.mp4", { contentType: "video/mp4" }),
art("second.png", { contentType: "image/png" }),
],
},
];
assert.deepEqual(pagedArtifacts(groups).map((a) => a.name), ["shot.png", "clip.mp4", "second.png"]);
assert.deepEqual(pagedArtifacts([]), []);
});
test("viewerIndexByUrl maps each media url to its position, first occurrence wins", () => {
const groups = [
{
stageKey: "s",
visit: 1,
artifacts: [
art("a.png", { contentType: "image/png", url: "/artifacts/1/1/a.png" }),
art("note.txt", { contentType: "text/plain", url: "/artifacts/1/1/note.txt" }),
art("b.png", { contentType: "image/png", url: "/artifacts/1/1/b.png" }),
art("a.png", { contentType: "image/png", url: "/artifacts/1/1/a.png" }),
],
},
];
const index = viewerIndexByUrl(groups);
assert.equal(index.get("/artifacts/1/1/a.png"), 0);
assert.equal(index.get("/artifacts/1/1/b.png"), 1);
assert.equal(index.has("/artifacts/1/1/note.txt"), false);
});
test("pagedIndex clamps at both ends and never wraps", () => {
assert.equal(pagedIndex(0, -1, 3), 0);
assert.equal(pagedIndex(1, -1, 3), 0);
assert.equal(pagedIndex(1, 1, 3), 2);
assert.equal(pagedIndex(2, 1, 3), 2);
assert.equal(pagedIndex(0, 0, 0), 0);
assert.equal(pagedIndex(0, 0, 1), 0);
});
test("sessionExportArtifact matches the export html to a step artifact by name", () => {
const exportStep = step("reviewer", 1, {
artifacts: [art("shot.png"), art("session.html")],
exportHtml: "session.html",
});
assert.equal(sessionExportArtifact(exportStep).name, "session.html");
// No session_export at all.
assert.equal(sessionExportArtifact(step("s", 1, { artifacts: [art("session.html")] })), null);
// Blank html.
assert.equal(sessionExportArtifact(step("s", 1, { artifacts: [art("session.html")], exportHtml: " " })), null);
// Export named but the file is missing from the listing.
assert.equal(sessionExportArtifact(step("s", 1, { artifacts: [art("shot.png")], exportHtml: "session.html" })), null);
assert.equal(sessionExportArtifact(undefined), null);
});
+58
View File
@@ -27,6 +27,13 @@ const out = resolve(
flag(process.argv, "--out", process.env.WEB_UI_OUT ?? join(tmpdir(), "pipelines-web-ui")),
);
// The page must connect through its own proxy (the server rejects a cross-origin
// upgrade), but serve.mjs only proxies /connect — not /artifacts. Point the URL
// field at the real Pipelines server after connecting so artifact tiles and the
// viewer resolve to real files; that is exactly the URL a correctly configured
// page would carry.
const artifactServerUrl = `ws://${pipelines}/connect`;
const shots = [];
let serve = null;
let browser = null;
@@ -86,6 +93,57 @@ try {
await page.waitForSelector(".detail h2", { timeout: 25000 });
shots.push(await page.screenshot(`${out}/03-run-detail.png`));
// Artifact URLs resolve against whatever the URL field holds. Point it at the
// real server (the socket stays on the proxy, see the note above) so the tiles
// and the viewer load real files rather than proxying a path serve.mjs does
// not forward.
step(`opening run 430 and capturing its artifacts gallery`);
await page.fill("#url", artifactServerUrl);
await page.clickText(".list button.row", "#430");
await page.waitForSelector(".artifact-gallery .artifact-tile", { timeout: 25000 });
await page.waitForText("recorded", { timeout: 25000 });
const tileCount = await page.evaluate(
`document.querySelectorAll(".artifact-gallery .artifact-tile").length`,
);
if (!tileCount) throw new Error("run 430 rendered no artifact tiles");
console.log(` run 430 gallery tiles: ${tileCount}`);
await page.rect(".artifacts-header");
shots.push(await page.screenshot(`${out}/04-run-430-artifacts.png`));
step("opening an image artifact in the full-screen viewer");
await page.click(".artifact-tile img");
await page.waitForSelector(".artifact-viewer", { timeout: 15000 });
await page.waitForText("Close viewer", { timeout: 15000 });
const position = await page.evaluate(
`document.querySelector(".viewer-position")?.textContent ?? ""`,
);
console.log(` viewer position: ${position}`);
// Best effort: give the full-resolution image a moment to decode.
await eventually(
() =>
page.evaluate(
`(() => { const i = document.querySelector(".viewer-image"); return !!i && i.complete && i.naturalWidth > 0; })()`,
),
{ timeout: 8000, what: "the viewer image" },
).catch(() => console.log(" (viewer image still loading)"));
shots.push(await page.screenshot(`${out}/05-artifact-viewer.png`));
step("closing the viewer and capturing the session export link (R9)");
await page.click(".viewer-close");
await eventually(
() => page.evaluate(`!document.querySelector(".artifact-viewer")`),
{ timeout: 5000, what: "the viewer to close" },
);
await page.rect(".session-link");
const sessionHref = await page.evaluate(
`document.querySelector(".session-link")?.getAttribute("href") ?? ""`,
);
if (!/session\.html$/.test(sessionHref)) {
throw new Error(`the session export link did not resolve: ${sessionHref}`);
}
console.log(` session export link: ${sessionHref}`);
shots.push(await page.screenshot(`${out}/06-session-export-link.png`));
console.log("\nUI SMOKE PASS");
for (const shot of shots) console.log(` ${shot}`);
} catch (error) {