Merge branch 'main' into theme

This commit is contained in:
2026-10-19 21:35:07 +01:00
11 changed files with 695 additions and 48 deletions
+83 -3
View File
@@ -19,6 +19,8 @@ import {
artifactViewerPositionLabel,
displayVisit,
humanBytes,
isMarkdownArtifact,
isViewerArtifact,
pagedArtifacts,
pagedIndex,
presentedArtifacts,
@@ -253,7 +255,83 @@ test("pagedArtifacts keeps only images and videos, in gallery order", () => {
assert.deepEqual(pagedArtifacts([]), []);
});
test("viewerIndexByUrl maps each media url to its position, first occurrence wins", () => {
test("isMarkdownArtifact accepts markdown/text content types and md/txt names", () => {
for (const [contentType, name] of [
["text/markdown", "plan"],
["text/markdown; charset=utf-8", "plan"],
["text/plain", "notes"],
["application/octet-stream", "input.md"],
["", "memory.markdown"],
["", "output.txt"],
["text/html", "report.md"],
["text/plain", "run.log"],
]) {
assert.equal(isMarkdownArtifact(contentType, name), true, `${contentType} ${name}`);
}
for (const [contentType, name] of [
["text/html", "session.html"],
["text/csv", "rows.csv"],
["application/json", "payload.json"],
["text/x-python", "main.py"],
["application/xml", "shot.png.xml"],
["", ""],
[undefined, undefined],
]) {
assert.equal(isMarkdownArtifact(contentType, name), false, `${contentType} ${name}`);
}
});
test("isViewerArtifact includes media and markdown but not code, logs or other files", () => {
for (const [contentType, name] of [
["image/png", "shot.png"],
["video/mp4", "clip.mp4"],
["text/markdown", "input.md"],
["text/plain", "memory.txt"],
["", "output.md"],
]) {
assert.equal(isViewerArtifact(contentType, name), true, `${contentType} ${name}`);
}
for (const [contentType, name] of [
["text/html", "session.html"],
["text/csv", "rows.csv"],
["application/json", "payload.json"],
["text/x-python", "main.py"],
["text/plain", "run.log"],
["application/octet-stream", "blob.bin"],
["", ""],
]) {
assert.equal(isViewerArtifact(contentType, name), false, `${contentType} ${name}`);
}
});
test("pagedArtifacts keeps images, videos and markdown in gallery order", () => {
const groups = [
{ stageKey: "reviewer", visit: 1, artifacts: [art("session.html", { contentType: "text/html" })] },
{
stageKey: "implementer",
visit: 2,
artifacts: [
art("input.md", { contentType: "text/markdown" }),
art("run.log", { contentType: "text/plain" }),
art("shot.png", { contentType: "image/png" }),
art("main.py", { contentType: "text/x-python" }),
art("clip.mp4", { contentType: "video/mp4" }),
art("memory.txt", { contentType: "text/plain" }),
art("rows.csv", { contentType: "text/csv" }),
art("output.md", { contentType: "application/octet-stream" }),
],
},
];
assert.deepEqual(pagedArtifacts(groups).map((a) => a.name), [
"input.md",
"shot.png",
"clip.mp4",
"memory.txt",
"output.md",
]);
});
test("viewerIndexByUrl maps each viewer-selectable url, first occurrence wins", () => {
const groups = [
{
stageKey: "s",
@@ -263,13 +341,15 @@ test("viewerIndexByUrl maps each media url to its position, first occurrence win
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" }),
art("session.html", { contentType: "text/html", url: "/artifacts/1/1/session.html" }),
],
},
];
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);
assert.equal(index.get("/artifacts/1/1/note.txt"), 1);
assert.equal(index.get("/artifacts/1/1/b.png"), 2);
assert.equal(index.has("/artifacts/1/1/session.html"), false);
});
test("pagedIndex clamps at both ends and never wraps", () => {
+7
View File
@@ -0,0 +1,7 @@
# Turn input
Plan the next small change.
```sh
go test ./...
```
+3
View File
@@ -0,0 +1,3 @@
# Memory
The previous turn landed the artifact viewer.
+6
View File
@@ -0,0 +1,6 @@
# Output
The change is ready for review.
- viewer renders markdown
- keyboard paging works
Binary file not shown.

After

Width:  |  Height:  |  Size: 68 B

+307 -10
View File
@@ -15,6 +15,9 @@
// real runs and chat session. The default run never sends a `submit`: the live
// server's pipeline list is never mutated.
//
// `--viewer` drives ONLY R8's deterministic markdown/text viewer fixture (no
// dependency on the operator's current run history) and captures 44–48.
//
// `--decide` drives ONLY R11's live human-decision flow: it reuses an existing
// entry-stage human pipeline or submits one uniquely named create-only
// definition, starts two throwaway runs in fresh temp workspaces, and presses
@@ -82,14 +85,16 @@ const scratch = process.argv.includes("--scratch");
const notifyOnly = process.argv.includes("--notify");
// Focused R11 evidence only; the one explicit mode allowed to submit a pipeline.
const decideOnly = process.argv.includes("--decide");
// Focused R8 evidence only: the deterministic markdown viewer fixture, with no
// dependency on the operator's current run history.
const viewerOnly = process.argv.includes("--viewer");
// 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 pipelineUrl = artifactServerUrl;
// Artifact URLs resolve against the configured server. Point them at the page's
// own proxy origin (serve.mjs forwards /artifacts/ and /connect), so the viewer's
// markdown fetch and the image/video tiles are same-origin exactly as they are
// in a correctly configured deployment.
const artifactServerUrl = `ws://127.0.0.1:${port}/connect`;
const pipelineUrl = `ws://${pipelines}/connect`;
const shots = [];
let serve = null;
@@ -1670,6 +1675,292 @@ async function runNotificationChecks() {
);
}
// --- R8: the markdown-first artifact viewer --------------------------------
// A deterministic synthetic run served by the page's own static origin. The run
// is injected over the real get_run command (never a new protocol field): its
// ordinary artifacts include the stage-turn names and a small media+markdown
// list, so the gallery, the viewer, keyboard paging, the backdrop and the honest
// failure path are exercised without depending on whatever history the operator
// currently has (the live fixture may be wiped between runs).
const VIEWER_FIXTURE_RUN_ID = 990001;
function viewerFixtureRun() {
const fixture = (name, contentType, url) => ({
name,
content_type: contentType,
size_bytes: 96,
url,
});
return {
id: VIEWER_FIXTURE_RUN_ID,
pipeline_id: 1,
version: 1,
name: "Viewer fixture",
title: "Markdown viewer fixture",
status: "succeeded",
executing: false,
outcome: "success",
current_stage: "",
content_hash: "viewerfixture",
created_at: "2026-10-19T20:00:00Z",
finished_at: "2026-10-19T20:01:00Z",
completed_steps: 1,
diagnostic: "",
resource_wait: null,
input: { prompt: "Render the stage turn." },
output: { result: "ready" },
graph: {
stages: [
{ key: "implementer", type: "model", edges: { success: "#success" }, prompt: "Render." },
],
},
steps: [
{
sequence: 1,
stage: "implementer",
status: "completed",
outcome: "success",
target: "#success",
diagnostic: "",
session_id: "",
agent_active: false,
control: { visit: 1, max_visits: 1 },
started_at: "2026-10-19T20:00:00Z",
finished_at: "2026-10-19T20:01:00Z",
input: { prompt: "Render the stage turn." },
output: { result: "ready" },
artifacts: [
fixture("input.md", "text/markdown; charset=utf-8", "/test/fixtures/artifacts/input.md"),
fixture("shot.png", "image/png", "/test/fixtures/artifacts/shot.png"),
fixture("memory.md", "text/plain; charset=utf-8", "/test/fixtures/artifacts/memory.md"),
fixture("output.md", "text/markdown; charset=utf-8", "/test/fixtures/artifacts/output.md"),
// Deliberately absent from the static origin: the viewer must show the
// honest fetch failure, not an empty or invented document.
fixture("missing.txt", "text/plain; charset=utf-8", "/test/fixtures/artifacts/missing.txt"),
],
},
],
};
}
/** The visible gallery tiles' stable metadata and document marking. */
async function viewerTiles(scope) {
return page.evaluate(`[...document.querySelectorAll(${JSON.stringify(scope)} + " .artifact-tile")].map((tile) => ({
name: tile.getAttribute("data-artifact-name") ?? "",
kind: tile.getAttribute("data-artifact-kind") ?? "",
label: tile.querySelector(".artifact-kind")?.textContent ?? "",
glyph: !!tile.querySelector(".artifact-doc-glyph"),
}))`);
}
async function runMarkdownViewerChecks() {
step("R8: the deterministic markdown/text stage-turn fixture run");
const fixture = viewerFixtureRun();
// This init script only answers get_run for the fixture id: every other frame
// (the socket, the real list, the operator's own data) still goes to the server.
await page.addInitScript(`(() => {
window.__viewerFixtureRun = ${JSON.stringify(fixture)};
window.__pipelinesIntercept = (frame) => (
frame.type === "get_run" && frame.run_id === ${VIEWER_FIXTURE_RUN_ID}
? { id: frame.id, type: "run_detail", run_detail: window.__viewerFixtureRun }
: null
);
})()`);
await openDeepLink(`/runs/${VIEWER_FIXTURE_RUN_ID}`);
await page.waitForSelector("#detailTitle", { timeout: 20000 });
await eventually(
() =>
page.evaluate(
`document.querySelector(".run-detail .run-identity")?.textContent?.startsWith("run ${VIEWER_FIXTURE_RUN_ID} ") ?? false`,
),
{ timeout: 20000, what: "the markdown fixture run detail to load" },
);
step("R8: the run gallery shows input.md, memory.md and output.md as Documents");
await page.clickText(".run-detail .section-toggle", "Artifacts");
await page.waitForSelector('.run-detail .artifact-gallery .artifact-tile[data-artifact-name="input.md"]', {
timeout: 15000,
});
const runTiles = await viewerTiles(".run-detail .artifact-gallery");
for (const name of ["input.md", "memory.md", "output.md"]) {
const tile = runTiles.find((entry) => entry.name === name);
if (!tile) throw new Error(`the run gallery is missing ${name}: ${JSON.stringify(runTiles)}`);
if (tile.kind !== "Document" || tile.label !== "Document" || !tile.glyph) {
throw new Error(`${name} is not presented as a Document: ${JSON.stringify(tile)}`);
}
}
const runImage = runTiles.find((entry) => entry.name === "shot.png");
if (!runImage || runImage.kind !== "Image" || runImage.glyph) {
throw new Error(`shot.png is not presented as media: ${JSON.stringify(runImage)}`);
}
console.log(` run gallery: ${runTiles.map((tile) => `${tile.name} (${tile.label})`).join(", ")}`);
await shot("44-viewer-turn-documents.png");
step("R8: the per-visit gallery presents the same turn documents");
await clickDetailTab("Timeline");
await page.click('.detail .timeline-row[data-stage-key="implementer"]');
await page.waitForSelector(".stage-pane", { timeout: 15000 });
await page.clickText(".stage-pane .section-toggle", "Artifacts");
await page.waitForSelector('.stage-pane .artifact-tile[data-artifact-name="input.md"]', { timeout: 15000 });
const visitTiles = await viewerTiles(".stage-pane");
for (const name of ["input.md", "memory.md", "output.md"]) {
const tile = visitTiles.find((entry) => entry.name === name);
if (!tile || tile.kind !== "Document" || tile.label !== "Document" || !tile.glyph) {
throw new Error(`the visit gallery does not present ${name} as a Document: ${JSON.stringify(tile)}`);
}
}
console.log(` visit gallery: ${visitTiles.map((tile) => tile.name).join(", ")}`);
step("R8: opening input.md renders the fetched markdown in the viewer");
await page.click('.stage-pane .artifact-tile[data-artifact-name="input.md"]');
await page.waitForSelector(".artifact-viewer .viewer-panel", { timeout: 15000 });
await page.waitForSelector(".viewer-markdown h3.md-heading", { timeout: 15000 });
const rendered = await page.evaluate(`(() => {
const viewer = document.querySelector(".artifact-viewer");
const heading = viewer?.querySelector(".viewer-markdown h3.md-heading");
const code = viewer?.querySelector(".viewer-markdown .md-code-block pre code");
const fetched = performance.getEntriesByType("resource").map((entry) => entry.name)
.filter((name) => name.endsWith("/test/fixtures/artifacts/input.md"));
return {
heading: heading?.textContent ?? "",
code: code?.textContent ?? "",
fetched: fetched.length,
position: viewer?.querySelector(".viewer-position")?.textContent ?? "",
title: viewer?.querySelector(".viewer-title")?.textContent ?? "",
prevDisabled: viewer?.querySelector('.viewer-page[data-viewer-focus="prev"]')?.disabled ?? null,
nextDisabled: viewer?.querySelector('.viewer-page[data-viewer-focus="next"]')?.disabled ?? null,
hasPanel: !!viewer?.querySelector(".viewer-panel"),
};
})()`);
if (rendered.heading !== "Turn input" || !rendered.code.includes("go test ./...")) {
throw new Error(`the markdown did not render through the page renderer: ${JSON.stringify(rendered)}`);
}
if (!rendered.hasPanel || rendered.title !== "input.md" || !rendered.position.startsWith("1 of 5")) {
throw new Error(`the viewer head/position is wrong: ${JSON.stringify(rendered)}`);
}
if (rendered.fetched < 1) {
throw new Error(`the viewer did not fetch the resolved artifact url: ${JSON.stringify(rendered)}`);
}
if (rendered.prevDisabled !== true || rendered.nextDisabled !== false) {
throw new Error(`the first artifact's paging state is wrong: ${JSON.stringify(rendered)}`);
}
console.log(
` rendered "${rendered.heading}" with fenced code (${rendered.code.trim().split("\n")[0]}); ${rendered.position}`,
);
await shot("45-viewer-markdown-rendered.png");
step("R8: ArrowRight advances to the next artifact, ArrowLeft returns");
await page.evaluate(
`document.activeElement?.dispatchEvent(new KeyboardEvent("keydown", { key: "ArrowRight", bubbles: true, cancelable: true }))`,
);
await eventually(
() =>
page.evaluate(
`document.querySelector(".artifact-viewer .viewer-position")?.textContent?.startsWith("2 of 5") ?? false`,
),
{ timeout: 10000, what: "ArrowRight to advance the viewer" },
);
const advanced = await page.evaluate(`(() => {
const viewer = document.querySelector(".artifact-viewer");
const image = viewer?.querySelector(".viewer-image");
return {
title: viewer?.querySelector(".viewer-title")?.textContent ?? "",
position: viewer?.querySelector(".viewer-position")?.textContent ?? "",
imageLoaded: !!image && image.complete && image.naturalWidth > 0,
};
})()`);
if (advanced.title !== "shot.png" || !advanced.imageLoaded) {
throw new Error(`ArrowRight did not land on the image artifact: ${JSON.stringify(advanced)}`);
}
console.log(` ArrowRight -> ${advanced.title} (${advanced.position})`);
await shot("46-viewer-markdown-next.png");
await page.evaluate(
`document.activeElement?.dispatchEvent(new KeyboardEvent("keydown", { key: "ArrowLeft", bubbles: true, cancelable: true }))`,
);
await eventually(
() =>
page.evaluate(
`document.querySelector(".artifact-viewer .viewer-position")?.textContent?.startsWith("1 of 5") ?? false`,
),
{ timeout: 10000, what: "ArrowLeft to return the viewer" },
);
const returned = await page.evaluate(
`document.querySelector(".artifact-viewer .viewer-title")?.textContent ?? ""`,
);
if (returned !== "input.md") throw new Error(`ArrowLeft returned to ${returned}, not input.md`);
console.log(" ArrowLeft -> input.md");
step("R8: the last artifact disables Next and a failed fetch is honest");
await page.evaluate(`(() => {
for (let i = 0; i < 20; i += 1) {
const next = document.querySelector('.viewer-page[data-viewer-focus="next"]');
if (!next || next.disabled) break;
next.click();
}
})()`);
await page.waitForSelector(".artifact-viewer .viewer-error-message", { timeout: 15000 });
const failure = await page.evaluate(`(() => {
const viewer = document.querySelector(".artifact-viewer");
const external = viewer?.querySelector(".viewer-external");
return {
title: viewer?.querySelector(".viewer-title")?.textContent ?? "",
message: viewer?.querySelector(".viewer-error-message")?.textContent ?? "",
externalText: external?.textContent ?? "",
externalHref: external?.getAttribute("href") ?? "",
nextDisabled: viewer?.querySelector('.viewer-page[data-viewer-focus="next"]')?.disabled ?? null,
};
})()`);
if (failure.title !== "missing.txt" || failure.message.trim() === "") {
throw new Error(`the failed fetch did not show an honest message: ${JSON.stringify(failure)}`);
}
if (
failure.externalText !== "Open missing.txt externally" ||
!failure.externalHref.endsWith("/test/fixtures/artifacts/missing.txt")
) {
throw new Error(`the external fallback is wrong: ${JSON.stringify(failure)}`);
}
if (failure.nextDisabled !== true) throw new Error("Next is not disabled on the last artifact");
console.log(` failure: ${failure.message.trim()} · ${failure.externalText}`);
await shot("47-viewer-markdown-failure.png");
step("R8: a click inside the panel keeps the viewer open; the backdrop closes it");
await page.evaluate(`document.querySelector('.viewer-page[data-viewer-focus="prev"]').click()`);
await page.evaluate(`document.querySelector('.viewer-page[data-viewer-focus="prev"]').click()`);
await page.evaluate(`document.querySelector('.viewer-page[data-viewer-focus="prev"]').click()`);
await page.evaluate(`document.querySelector('.viewer-page[data-viewer-focus="prev"]').click()`);
await eventually(
() =>
page.evaluate(
`document.querySelector(".artifact-viewer .viewer-title")?.textContent === "input.md"`,
),
{ timeout: 10000, what: "the viewer to return to input.md" },
);
await page.evaluate(`document.querySelector(".artifact-viewer .viewer-title")?.click()`);
if (!(await page.evaluate(`!!document.querySelector(".artifact-viewer")`))) {
throw new Error("a click inside the viewer panel closed it");
}
const closedByBackdrop = await page.evaluate(`(() => {
const overlay = document.querySelector(".artifact-viewer");
if (!overlay) return false;
const rect = overlay.getBoundingClientRect();
const target = document.elementFromPoint(rect.left + 3, rect.top + 3);
if (!target) return false;
target.dispatchEvent(new MouseEvent("click", { bubbles: true, cancelable: true }));
return true;
})()`);
if (!closedByBackdrop) throw new Error("the backdrop had no point to click");
await eventually(() => page.evaluate(`!document.querySelector(".artifact-viewer")`), {
timeout: 10000,
what: "the backdrop click to close the viewer",
});
console.log(" a panel click kept the viewer open; the dimmed backdrop closed it");
await shot("48-viewer-markdown-backdrop-closed.png");
// Drop the fixture intercept so later documents (the shell pass) talk only to
// the real server; the init script is removed by navigating away from here.
await page.evaluate(`(() => { window.__pipelinesIntercept = null; return true; })()`);
}
try {
await mkdir(out, { recursive: true });
@@ -1862,6 +2153,10 @@ try {
await runNotificationChecks();
console.log("\nUI SMOKE PASS");
for (const shot of shots) console.log(` ${shot}`);
} else if (viewerOnly) {
await runMarkdownViewerChecks();
console.log("\nUI SMOKE PASS");
for (const shot of shots) console.log(` ${shot}`);
} else if (!scratch) {
const pipelineCount = await page.evaluate(
`document.querySelectorAll("#pipelineRows button.row").length`,
@@ -2549,9 +2844,9 @@ try {
shots.push(await page.screenshot(`${out}/19-template-source.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.
// page's own proxy origin so tiles and the viewer load real files same-origin:
// serve.mjs forwards /artifacts/ to the Pipelines server (the socket stays on
// that same proxy too).
step("returning to Runs and opening run 430 (Summary tab)");
await clickDestination("Settings");
await page.waitForSelector("#settingsServerUrl", { timeout: 15000 });
@@ -7693,6 +7988,8 @@ try {
);
console.log(` cleanup: /close closed the New-marker throwaway ${newMarkerId}`);
await runMarkdownViewerChecks();
await runShellChecks();
console.log("\nUI SMOKE PASS");