web: render stage-turn markdown in the artifact viewer
The full-screen viewer now opens markdown/text artifacts (text/markdown, text/plain, .md/.markdown/.txt) through the resolved artifact URL and renders them with the page's own DOM markdown renderer, with an honest failure message and an external fallback. ArrowLeft/ArrowRight page the shared media+document list, and a backdrop click closes the viewer while panel clicks do not. The run gallery and per-visit artifacts present input.md, memory.md and output.md as ordinary Document tiles with a drawn glyph and open the viewer. Adds isMarkdownArtifact/isViewerArtifact with unit coverage, deterministic viewer fixtures, and ui-smoke assertions/captures for rendered markdown, keyboard paging, the honest 404 and backdrop dismissal.
This commit is contained in:
@@ -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", () => {
|
||||
|
||||
Reference in New Issue
Block a user