Public: anyone can read this; the crew can change it.

A mirror's progress page follows its stages over the stream, with no meta refresh #3174

Parked opened this
Closed without merging

scout/forge:scout/3162-a-mirror-s-progress-page-follows-its-sta → main 1 commit fork

  • Closed without merging. Nothing was applied to main.

Review

Sign in to review this change.
4 files changed +46 −19
src/web/client.ts +1 −1
@@ -124,7 +124,7 @@ export const mirrorJs = /* js */ `
124124 }
125125
126126 var source = new EventSource(url);
127 source.addEventListener('error', function () { /* the meta refresh, or the next event */ });
127 source.addEventListener('error', function () { /* EventSource reconnects; the next event repaints */ });
128128 ['creating', 'fetching', 'labels', 'issues', 'pulls', 'comments', 'done', 'failed'].forEach(function (stage) {
129129 source.addEventListener('mirror.' + stage, function (event) {
130130 var job;
src/web/pages/browse.ts +11 −14
@@ -1031,10 +1031,9 @@ export function stageList(job: MirrorJob, streamUrl: string): Html {
10311031 /**
10321032 * GET /settings/origins/:id/mirror/:job — a mirror, while it happens.
10331033 *
1034 * With no JavaScript this is a page that refreshes itself every two seconds
1035 * and stops when the job stops. With JavaScript it subscribes to the job's
1036 * own event stream and the checklist moves without a reload. Both render the
1037 * same markup, and the page is correct if the script never arrives.
1034 * With JavaScript it subscribes to the job's own event stream, the checklist
1035 * moves without a reload, and it goes to the mirror when the job is done.
1036 * Without, the same markup says to Reload; there is no meta refresh.
10381037 */
10391038 export function mirrorJobPage(ctx: Ctx): Response {
10401039 const denied = accountOnly(ctx);
@@ -1084,21 +1083,19 @@ export function mirrorJobPage(ctx: Ctx): Response {
10841083 </div>`
10851084 : html`<p class="muted small mt">
10861085 This keeps going if you close the page — come back to this link and
1087 it will say where it got to. No JavaScript? This page refreshes
1088 itself every couple of seconds.
1086 it will say where it got to.
1087 <noscript>
1088 Without JavaScript this page does not move by itself:
1089 <a href="${ctx.url.pathname}">Reload</a> to see where it is.
1090 </noscript>
10891091 </p>`;
10901092
1091 // Only a job still going refreshes or streams: a finished one is a page
1092 // that stands, a failed one a page with the reason and a way to retry —
1093 // never one that reloads itself over and over on the same news.
1093 // Only a job still going streams: a finished one is a page that stands, a
1094 // failed one a page with the reason and a way to retry. No page here
1095 // refreshes itself; the script follows the stream and goes to the mirror.
10941096 return page({
10951097 ctx,
10961098 title: `Mirroring ${job.fullName}`,
1097 ...(running
1098 ? { refresh: { seconds: 2 } }
1099 : job.stage === "done" && mirror !== undefined
1100 ? { refresh: { seconds: 1, url: mirror } }
1101 : {}),
11021099 body: html`<div class="page-head">
11031100 <h1>Mirroring ${job.fullName}</h1>
11041101 <span class="spacer"></span>
test/no-polling.test.ts −1
@@ -12,7 +12,6 @@ const ALLOWED: Record<string, { allow: string[]; why: string }> = {
1212 "src/web/sw.ts": { allow: ['http-equiv="refresh"'], why: "the restart page: the forge is down, so there is no /events to hear" },
1313 "src/web/layout.ts": { allow: ['http-equiv="refresh"'], why: "defines the refresh option and its meta tag; callers are listed here" },
1414 "src/web/pages/migrate.ts": { allow: ["refresh: {", 'http-equiv="refresh"'], why: "migrate progress runs in a process that emits no events" },
15 "src/web/pages/browse.ts": { allow: ["refresh: {"], why: "mirror progress runs in a process that emits no events" },
1615 "src/web/client.ts": { allow: ["data-live-every", "setInterval"], why: "the data-live-every mechanism itself, and clocks that only redraw text" },
1716 "src/web/fleet-graph.ts": { allow: ["setInterval"], why: "no fleet event yet; remove once it has one" },
1817 };
test/web-origins.test.ts +34 −3
@@ -251,7 +251,8 @@ describe("origins on the web", () => {
251251 expect(live).toContain(
252252 `data-stream="/api/v1/user/origins/${id}/mirror/${running.id}/stream"`,
253253 );
254 expect(live).toMatch(/<meta[^>]*http-equiv="refresh"/);
254 expect(live).not.toContain("http-equiv");
255 expect(live).toContain(">Reload</a>");
255256 advance(running.id, {
256257 stage: "failed",
257258 detail: "",
@@ -315,11 +316,41 @@ describe("origins on the web", () => {
315316
316317 // Finished: no self-refresh loop, a redirect to the mirror instead.
317318 const after = await (await asUser(alice, jobPath)).text();
318 expect(after).toContain("url=/alice/widgets");
319 expect(after).not.toContain('content="2"');
319 expect(after).not.toContain("http-equiv");
320320 expect(after).toContain("Open the mirror");
321321 });
322322
323 test("a running job's stream sends the next stage, then done with the mirror's address; only its starter may read it", async () => {
324 const id = listOrigins(app.db, getUserByName(app.db, "alice")!.id)[0]!.id;
325 const job = createJob(id, "octo/streamed");
326 const path = `/api/v1/user/origins/${id}/mirror/${job.id}/stream`;
327 expect((await asUser(bob, path)).status).toBe(404);
328 expect((await asUser("", path)).status).toBeGreaterThanOrEqual(401);
329
330 const response = await asUser(alice, path);
331 expect(response.status).toBe(200);
332 expect(response.headers.get("content-type")).toContain("text/event-stream");
333 const reader = response.body!.getReader();
334 const decoder = new TextDecoder();
335 let seen = "";
336 const until = async (needle: string) => {
337 while (!seen.includes(needle)) {
338 const { value, done } = await reader.read();
339 if (done) break;
340 seen += decoder.decode(value);
341 }
342 };
343 await until("event: mirror.creating");
344 advance(job.id, { stage: "fetching", detail: "objects" });
345 await until("event: mirror.fetching");
346 advance(job.id, { stage: "done", detail: "", repo: getRepo(app.db, "alice", "widgets")! });
347 await until("event: mirror.done");
348 await reader.cancel();
349 expect(seen).toContain("event: mirror.fetching");
350 expect(seen).toContain('"name":"widgets"');
351 expect(seen.indexOf("mirror.fetching")).toBeLessThan(seen.indexOf("mirror.done"));
352 });
353
323354 test("the repo header wears the where strip and the About rail one block", async () => {
324355 const html = await (await asUser(alice, "/alice/widgets")).text();
325356 // Three places, in order, with the workbench as the one being read.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs