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

map: one canvas for every app #20

Closed opened this
Closed without merging

global-map → main 1 commit

  • Closed without merging. Nothing was applied to main.

Review

Sign in to review this change.
8 files changed +466 −17
docs/PLANNING.md +16 −1
@@ -54,7 +54,22 @@ converging, the bars say whether anything is moving.
5454
5555 The same three lists are data at `GET /api/v1/repos/:owner/:name/map`,
5656 which is what an agent reads before it starts and what a repository in
57 autonomous mode reads to pick the next thing.
57 autonomous mode reads to pick the next thing. Both carry where the crew
58 is: an issue with an agent run in flight is marked _working_ (or _queued_)
59 on the drawing, and listed under `working` in the data.
60
61 ### The global map
62
63 `/map` is every app on one canvas. Each repository the viewer can see that
64 has an open issue or a run in flight is one lane, stacked, headed by its
65 name (a link to its own map), how it runs itself — _off_, _assisted_ or
66 _autonomous_, with today's spend against the ceiling when it is not off —
67 and how many runs are in flight. The lane is the same drawing as the
68 repository's map. Repositories with nothing to draw are left out; a forge
69 with nothing to draw anywhere says so in one sentence. It is reached from
70 the user menu and the command palette, and from the Apps card on either
71 home. `GET /api/v1/map` is the same, one entry per repository, each the
72 repository's map data plus `autonomy`, `spentTodayUsd` and `inFlight`.
5873
5974 ## Planning by the crew
6075
src/http/api.ts +21 −4
@@ -168,13 +168,19 @@ import { assignIssue } from "../actions/issues.ts";
168168 import { steerRepoRun } from "../actions/runs.ts";
169169 import { linkIssue, unlinkIssue } from "../actions/dependencies.ts";
170170 import { dependenciesOf, repoGraph } from "../core/dependencies.ts";
171 import { mapJson } from "../web/pages/map.ts";
171 import { crewMarks, globalMapJson, mapJson } from "../web/pages/map.ts";
172172 import { appsRuntime, type AppsRuntime } from "../apps/runtime.ts";
173173 import { isEnvName } from "../apps/data.ts";
174174 import type { Agent } from "../core/agents.ts";
175175 import { listApps, type AppRecord } from "../core/apps.ts";
176176 import { listAssignedTo } from "../core/issues.ts";
177 import { checksForHead, getRun, isTerminal, type Run } from "../core/runs.ts";
177 import {
178 checksForHead,
179 getRun,
180 isTerminal,
181 listActiveRuns,
182 type Run,
183 } from "../core/runs.ts";
178184 import { resolveOid } from "../git/merge.ts";
179185 import { readRunLog, subscribeRunLog } from "../runs/log.ts";
180186 import { blobForRender, commitLog, listRefs, listTree } from "../git/read.ts";
@@ -1542,12 +1548,23 @@ export function apiRoutes(router: Router<Handler>): void {
15421548 return new Response(null, { status: 204 });
15431549 },
15441550 );
1545 // The map as data: ready now, blocked on, the critical path, every edge.
1551 // The map as data: ready now, blocked on, the critical path, every edge,
1552 // and where the crew is.
15461553 router.add("GET", "/api/v1/repos/:owner/:name/map", (ctx) => {
15471554 const repo = loadRepo(ctx);
15481555 if (!repo) return notFound();
1549 return json(mapJson(repo, repoGraph(ctx.app.db, repo.id)));
1556 return json(
1557 mapJson(
1558 repo,
1559 repoGraph(ctx.app.db, repo.id),
1560 crewMarks(listActiveRuns(ctx.app.db, [repo.id])),
1561 ),
1562 );
15501563 });
1564 // Every repository the caller can see, one entry each: the global map.
1565 router.add("GET", "/api/v1/map", (ctx) =>
1566 json(globalMapJson(ctx.app, ctx.auth.user)),
1567 );
15511568
15521569 router.add(
15531570 "PATCH",
src/http/server.ts +3 −1
@@ -75,7 +75,7 @@ import {
7575 newIssuePage,
7676 newIssueSubmit,
7777 } from "../web/pages/issues.ts";
78 import { mapPage } from "../web/pages/map.ts";
78 import { globalMapPage, mapPage } from "../web/pages/map.ts";
7979 import {
8080 asksSubmit,
8181 modeSubmit,
@@ -364,6 +364,8 @@ export function buildRouter(): Router<Handler> {
364364 router.add("GET", "/apps", appsList);
365365 router.add("GET", "/apps/new", newAppPage);
366366 router.add("POST", "/apps/new", newAppSubmit);
367 // Every app on one canvas; a literal route, so it must sit above /:owner.
368 router.add("GET", "/map", globalMapPage);
367369 router.add("GET", "/runs/:id", runRedirect);
368370 router.add("GET", "/settings", accountPage);
369371 router.add("POST", "/settings", accountUpdate);
src/web/layout.ts +2
@@ -155,6 +155,7 @@ function userMenu(user: User, signOut: MenuItem): Html {
155155 { label: "Your profile", href: `/${user.username}`, icon: "user" },
156156 { label: "Your repositories", href: "/", icon: "repo" },
157157 { label: "Apps", href: "/apps", icon: "rocket" },
158 { label: "Map", href: "/map", icon: "map" },
158159 { separator: true, label: "" },
159160 { label: "Settings", href: "/settings", icon: "settings" },
160161 { label: "Access tokens", href: "/settings/tokens", icon: "key" },
@@ -218,6 +219,7 @@ function helpButton(): Html {
218219 const STATIC_PALETTE: PaletteItem[] = [
219220 { t: "Home", h: "/", c: "Go" },
220221 { t: "Apps", h: "/apps", c: "Go" },
222 { t: "Map", h: "/map", c: "Go" },
221223 { t: "New app", h: "/apps/new", c: "Create" },
222224 { t: "New repository", h: "/new", c: "Create" },
223225 { t: "New organization", h: "/organizations/new", c: "Create" },
src/web/pages/apps.ts +1
@@ -157,6 +157,7 @@ export function appsCard(ctx: Ctx): Html {
157157 const head = html`${icon("rocket")}
158158 <h2>Apps</h2>
159159 <span class="spacer"></span>
160 ${btn("Map", { href: "/map", size: "sm", icon: "map" })}
160161 ${btn("New app", { href: "/apps/new", size: "sm", icon: "plus" })}`;
161162 if (entries.length === 0) {
162163 return card(
src/web/pages/map.ts +185 −11
@@ -8,8 +8,13 @@
88 *
99 * Drawn on the server as SVG, laid out by hand: a plan bigger than the
1010 * few hundred issues this handles is not one a person reads.
11 *
12 * The global map at `/map` is the same drawing once per repository the
13 * viewer can see, stacked: one canvas for every app, and where the crew is
14 * marked on it.
1115 */
1216
17 import type { App } from "../../app.ts";
1318 import {
1419 blockedOn,
1520 criticalPath,
@@ -21,20 +26,24 @@ import {
2126 type Ranked,
2227 } from "../../core/dependencies.ts";
2328 import type { Issue } from "../../core/issues.ts";
24 import type { Repo } from "../../core/repos.ts";
29 import { listReposVisibleTo, type Repo } from "../../core/repos.ts";
30 import { listActiveRuns, type Run, type RunState } from "../../core/runs.ts";
31 import type { User } from "../../core/users.ts";
2532 import type { Ctx } from "../../http/context.ts";
2633 import {
2734 crumbsFor,
2835 loadRepo,
2936 notFoundPage,
37 pageHead,
3038 repoBase,
3139 repoHeader,
3240 repoPalette,
41 signInFirst,
3342 } from "../chrome.ts";
3443 import { html, raw, type Html } from "../html.ts";
3544 import { page } from "../layout.ts";
3645 import { icon } from "../ui.ts";
37 import { autonomyStatus } from "../../crew/autonomy.ts";
46 import { autonomyStatus, type AutonomyStatus } from "../../crew/autonomy.ts";
3847
3948 // ---- layout ----
4049
@@ -163,11 +172,31 @@ function trim(text: string, max = 24): string {
163172 return text.length <= max ? text : `${text.slice(0, max - 1)}…`;
164173 }
165174
175 /**
176 * Where the crew is: each issue with an agent run in flight, by issue id.
177 * A running run outranks a queued one on the same issue. Issue ids are
178 * forge-wide, so one map serves every repository's drawing at once.
179 */
180 export function crewMarks(runs: readonly Run[]): Map<string, RunState> {
181 const marks = new Map<string, RunState>();
182 for (const run of runs)
183 if (run.issueId !== null && marks.get(run.issueId) !== "running")
184 marks.set(run.issueId, run.state);
185 return marks;
186 }
187
188 export interface Emphasis {
189 readonly ready: Set<string>;
190 readonly critical: Set<string>;
191 /** Issues the crew is on right now; see `crewMarks`. */
192 readonly crew: Map<string, RunState>;
193 }
194
166195 export function drawMap(
167196 repo: Repo,
168197 graph: Graph,
169198 placed: Layout,
170 emphasis: { ready: Set<string>; critical: Set<string> },
199 emphasis: Emphasis,
171200 ): Html {
172201 if (placed.nodes.length === 0)
173202 return html`<div class="map-empty">
@@ -206,13 +235,25 @@ export function drawMap(
206235 : "waiting";
207236 const px = x(n.column);
208237 const py = y(n.row);
238 // The crew's marker: the studio's word for the run, and a dot while it
239 // actually runs. Quiet on purpose; the node's colour still says ready.
240 const run = emphasis.crew.get(n.issue.id);
209241 return html`<a
210242 class="map-node"
211243 data-state="${state}"
212244 data-crit="${emphasis.critical.has(n.issue.id) ? "1" : "0"}"
245 ${run ? html`data-run="${run}"` : null}
213246 href="${base}/issues/${n.issue.number}"
214247 >
215248 <rect x="${px}" y="${py}" width="${W}" height="${H}" rx="7" />
249 ${run === "running"
250 ? html`<circle
251 class="map-crew-dot"
252 cx="${px + W - 13}"
253 cy="${py + 13}"
254 r="3.5"
255 />`
256 : null}
216257 <text class="map-title" x="${px + 12}" y="${py + 19}">
217258 ${trim(n.issue.title)}
218259 </text>
@@ -223,6 +264,12 @@ export function drawMap(
223264 : state === "ready"
224265 ? " · ready"
225266 : ""}${n.issue.assigneeName ? ` · ${n.issue.assigneeName}` : ""}
267 ${run
268 ? html` ·
269 <tspan class="map-crew"
270 >${run === "running" ? "working" : "queued"}</tspan
271 >`
272 : null}
226273 </text>
227274 </a>`;
228275 });
@@ -323,6 +370,8 @@ export const mapCss = /* css */ `
323370 .map-node text { font-family: var(--font); pointer-events: none; }
324371 .map-title { font-size: 12.5px; font-weight: 560; fill: var(--fg); }
325372 .map-sub { font-size: 11px; fill: var(--fg-muted, var(--fg)); opacity: .72; }
373 .map-crew { fill: var(--accent); }
374 .map-crew-dot { fill: var(--accent); }
326375 .map-edge { fill: none; stroke: var(--border); stroke-width: 1.4; }
327376 .map-edge-crit { stroke: var(--accent); stroke-width: 2; }
328377 .map-list h2 { font-size: 13px; margin: 0 0 6px; }
@@ -338,8 +387,24 @@ export const mapCss = /* css */ `
338387 .map-legend i.ready { background: color-mix(in srgb, var(--accent) 14%, var(--bg)); border-color: var(--accent); }
339388 .map-legend i.done { background: color-mix(in srgb, var(--merged) 12%, var(--bg)); }
340389 .map-legend i.crit { border: 2px solid var(--accent); background: transparent; }
390 .map-legend i.crew { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); border-color: var(--accent); vertical-align: 0; }
391 .map-lane + .map-lane { margin-top: 28px; }
392 .map-lane-head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; margin: 0 0 8px; }
393 .map-lane-head h2 { font-size: 15px; margin: 0; }
394 .map-lane-head h2 a { color: inherit; }
341395 `;
342396
397 /** The swatches under a drawing: what each colour and mark means. */
398 function legend(): Html {
399 return html`<div class="map-legend">
400 <span><i class="ready"></i>ready now</span>
401 <span><i></i>waiting</span>
402 <span><i class="done"></i>done</span>
403 <span><i class="crit"></i>critical path</span>
404 <span><i class="crew"></i>the crew is on it</span>
405 </div>`;
406 }
407
343408 /** One line on how the repository runs itself, when it does. */
344409 function autonomyLine(ctx: Ctx, repo: Repo): Html | null {
345410 if (repo.autonomy === "off") return null;
@@ -368,6 +433,7 @@ export function mapPage(ctx: Ctx): Response {
368433 const blocked = blockedOn(graph);
369434 const critical = criticalPath(graph);
370435 const placed = layout(graph);
436 const crew = crewMarks(listActiveRuns(ctx.app.db, [repo.id]));
371437 const body = html`${repoHeader(ctx, repo, "map")}
372438 <div class="page-head mt">
373439 <h1>Map</h1>
@@ -382,13 +448,9 @@ export function mapPage(ctx: Ctx): Response {
382448 ${drawMap(repo, graph, placed, {
383449 ready: new Set(ready.map((r) => r.issue.id)),
384450 critical: new Set(critical.map((i) => i.id)),
451 crew,
385452 })}
386 <div class="map-legend">
387 <span><i class="ready"></i>ready now</span>
388 <span><i></i>waiting</span>
389 <span><i class="done"></i>done</span>
390 <span><i class="crit"></i>critical path</span>
391 </div>
453 ${legend()}
392454 </div>
393455 <aside>
394456 ${graph.issues.length === 0
@@ -438,8 +500,15 @@ export function mapPage(ctx: Ctx): Response {
438500 });
439501 }
440502
441 /** The map as data, for the crew and the tick: the same three lists. */
442 export function mapJson(repo: Repo, graph: Graph): Record<string, unknown> {
503 /**
504 * The map as data, for the crew and the tick: the same three lists, and
505 * `working`, the issues the crew is on right now.
506 */
507 export function mapJson(
508 repo: Repo,
509 graph: Graph,
510 crew: Map<string, RunState> = new Map(),
511 ): Record<string, unknown> {
443512 const brief = (i: Issue) => ({
444513 number: i.number,
445514 title: i.title,
@@ -458,6 +527,7 @@ export function mapJson(repo: Repo, graph: Graph): Record<string, unknown> {
458527 waitsFor: r.waitsFor,
459528 })),
460529 critical: criticalPath(graph).map((i) => i.number),
530 working: graph.issues.filter((i) => crew.has(i.id)).map((i) => i.number),
461531 issues: graph.issues.map(brief),
462532 edges: graph.edges.map((e) => {
463533 const a = graph.issues.find((i) => i.id === e.issueId);
@@ -466,3 +536,107 @@ export function mapJson(repo: Repo, graph: Graph): Record<string, unknown> {
466536 }),
467537 };
468538 }
539
540 // ---- every app on one canvas ----
541
542 interface Lane {
543 readonly repo: Repo;
544 readonly graph: Graph;
545 /** Agent runs queued or running here now. */
546 readonly inFlight: number;
547 /** Set when the repository runs itself; `off` has no spend to show. */
548 readonly status: AutonomyStatus | undefined;
549 }
550
551 interface Lanes {
552 readonly lanes: Lane[];
553 readonly crew: Map<string, RunState>;
554 }
555
556 /**
557 * One lane per repository the viewer can see that has something to draw:
558 * an open issue, or a run in flight. The rest are left out rather than
559 * drawn empty, so the page is as long as the work and no longer. One read
560 * for every run in flight; a graph only for the lanes that stay.
561 */
562 export function globalLanes(app: App, viewer: User | undefined): Lanes {
563 const db = app.db;
564 const repos = listReposVisibleTo(db, viewer, { limit: 200 });
565 const runs = listActiveRuns(
566 db,
567 repos.map((r) => r.id),
568 );
569 const inFlight = new Map<string, number>();
570 for (const run of runs)
571 inFlight.set(run.repoId, (inFlight.get(run.repoId) ?? 0) + 1);
572 const lanes: Lane[] = [];
573 for (const repo of repos) {
574 const flying = inFlight.get(repo.id) ?? 0;
575 if ((repo.counts?.openIssues ?? 0) === 0 && flying === 0) continue;
576 lanes.push({
577 repo,
578 graph: repoGraph(db, repo.id),
579 inFlight: flying,
580 status: repo.autonomy === "off" ? undefined : autonomyStatus(app, repo),
581 });
582 }
583 return { lanes, crew: crewMarks(runs) };
584 }
585
586 /** A lane: the repository's name, how it runs itself, and its map. */
587 function laneHtml(lane: Lane, crew: Map<string, RunState>): Html {
588 const { repo, graph, status } = lane;
589 const spend =
590 status === undefined
591 ? ""
592 : ` · $${status.spentTodayUsd.toFixed(2)} of $${status.ceilingUsd.toFixed(0)} today`;
593 const flying =
594 lane.inFlight === 0
595 ? ""
596 : ` · ${lane.inFlight} ${lane.inFlight === 1 ? "run" : "runs"} in flight`;
597 return html`<section class="map-lane">
598 <header class="map-lane-head">
599 <h2>
600 <a href="${repoBase(repo)}/map">${repo.ownerName}/${repo.name}</a>
601 </h2>
602 <span class="muted small">${repo.autonomy}${spend}${flying}</span>
603 </header>
604 ${drawMap(repo, graph, layout(graph), {
605 ready: new Set(readyNow(graph).map((r) => r.issue.id)),
606 critical: new Set(criticalPath(graph).map((i) => i.id)),
607 crew,
608 })}
609 </section>`;
610 }
611
612 /** GET /map — every app the viewer can see, one lane each. */
613 export function globalMapPage(ctx: Ctx): Response {
614 const viewer = ctx.auth.user;
615 if (!viewer) return signInFirst(ctx);
616 const { lanes, crew } = globalLanes(ctx.app, viewer);
617 const body = html`${pageHead("Map", {
618 sub: "Every app you can see, laid out by what waits for what. The left edge of each lane is ready now; a marked issue is where the crew is.",
619 })}
620 ${lanes.length === 0
621 ? html`<p class="muted">
622 Nothing to map: no open issues anywhere you can see, and nobody working.
623 </p>`
624 : html`${lanes.map((lane) => laneHtml(lane, crew))} ${legend()}`}`;
625 return page({ ctx, title: "Map", body, styleCss: mapCss });
626 }
627
628 /** GET /api/v1/map — the lanes as data, one entry per repository. */
629 export function globalMapJson(
630 app: App,
631 viewer: User | undefined,
632 ): Record<string, unknown> {
633 const { lanes, crew } = globalLanes(app, viewer);
634 return {
635 repos: lanes.map((lane) => ({
636 ...mapJson(lane.repo, lane.graph, crew),
637 autonomy: lane.repo.autonomy,
638 spentTodayUsd: lane.status?.spentTodayUsd ?? null,
639 inFlight: lane.inFlight,
640 })),
641 };
642 }
src/web/pages/studio.ts +1
@@ -892,6 +892,7 @@ export async function studioHome(ctx: Ctx, user: User): Promise<Response> {
892892 head: html`${icon("rocket")}
893893 <h2>Your apps</h2>
894894 <span class="spacer"></span>
895 ${btn("Map", { href: "/map", size: "sm", icon: "map" })}
895896 ${btn("New app", { href: "/apps/new", size: "sm", icon: "plus" })}`,
896897 });
897898
test/map.test.ts added +237
@@ -0,0 +1,237 @@
1 /**
2 * The global map: every app a person can see on one canvas, one lane per
3 * repository with something to draw, where the crew is marked on it. A
4 * lane is exactly the repository's own map, so what the per-repo page
5 * says and what `/map` says never disagree.
6 */
7 import { afterAll, beforeAll, describe, expect, test } from "bun:test";
8 import { mkdtemp, rm } from "node:fs/promises";
9 import { tmpdir } from "node:os";
10 import { join } from "node:path";
11 import { createApp, type App } from "../src/app.ts";
12 import { addToCrew, createAgent } from "../src/actions/crew.ts";
13 import { assignIssue, openIssue } from "../src/actions/issues.ts";
14 import { createRepo } from "../src/actions/repos.ts";
15 import { addDependency } from "../src/core/dependencies.ts";
16 import type { Issue } from "../src/core/issues.ts";
17 import type { Repo } from "../src/core/repos.ts";
18 import { claimRun, createRun } from "../src/core/runs.ts";
19 import { createToken } from "../src/core/tokens.ts";
20 import { createUser, getUserByName, type User } from "../src/core/users.ts";
21 import { serve, type Servers } from "../src/http/server.ts";
22
23 describe("the global map", () => {
24 let dataDir: string;
25 let app: App;
26 let servers: Servers;
27 let base: string;
28 let alice: User;
29 let bob: User;
30 let engine: Repo;
31 const engineIssues: Issue[] = [];
32
33 const signIn = async (username: string): Promise<string> =>
34 (
35 (
36 await fetch(`${base}/signin`, {
37 method: "POST",
38 body: new URLSearchParams({
39 username,
40 password: "a-good-passphrase",
41 }),
42 redirect: "manual",
43 })
44 ).headers.get("set-cookie") ?? ""
45 ).split(";")[0]!;
46 const person = async (username: string, admin = false): Promise<User> => {
47 const made = await createUser(app.db, {
48 username,
49 email: `${username}@forge.local`,
50 password: "a-good-passphrase",
51 adminIfFirst: admin,
52 });
53 if (!made.ok) throw new Error(made.error);
54 return made.value;
55 };
56 const repoOf = async (
57 owner: User,
58 name: string,
59 titles: string[],
60 ): Promise<{ repo: Repo; issues: Issue[] }> => {
61 const made = await createRepo(app, owner, { name, visibility: "private" });
62 if (!made.ok) throw new Error(String(made.error));
63 const issues = titles.map((title) => {
64 const opened = openIssue(app, owner, made.value, { title });
65 if (!opened.ok) throw new Error(String(opened.error));
66 return opened.value;
67 });
68 return { repo: made.value, issues };
69 };
70
71 beforeAll(async () => {
72 dataDir = await mkdtemp(join(tmpdir(), "forge-map-"));
73 app = createApp({ dataDir, port: 0 });
74 servers = await serve(app);
75 base = servers.url;
76 alice = await person("alice", true);
77 bob = await person("bob");
78 await person("carol");
79
80 // alice/engine: three issues, 2 waits for 1, and the crew on 1.
81 const made = await repoOf(alice, "engine", [
82 "Extract renderer",
83 "Scene graph",
84 "Write the docs",
85 ]);
86 engine = made.repo;
87 engineIssues.push(...made.issues);
88 expect(
89 addDependency(app.db, engineIssues[1]!, engineIssues[0]!, alice.id).ok,
90 ).toBe(true);
91 const scout = await createAgent(app, alice, { username: "scout" });
92 if (!scout.ok) throw new Error(String(scout.error));
93 expect(addToCrew(app, alice, engine, "scout").ok).toBe(true);
94 const scoutUser = getUserByName(app.db, "scout")!;
95 const assigned = assignIssue(
96 app,
97 alice,
98 engine,
99 engineIssues[0]!,
100 scoutUser,
101 );
102 if (!assigned.ok) throw new Error(String(assigned.error));
103 const run = createRun(app.db, {
104 repoId: engine.id,
105 kind: "agent",
106 issueId: engineIssues[0]!.id,
107 actorId: scoutUser.id,
108 reason: "assigned",
109 });
110 expect(claimRun(app.db, run.id)).toBeDefined();
111
112 // alice/bare: a repository with nothing open and nobody working.
113 await repoOf(alice, "bare", []);
114 // bob/secret: bob's own, which alice cannot see and bob can.
115 await repoOf(bob, "secret", ["Rotate the keys"]);
116 });
117
118 afterAll(async () => {
119 servers.stop();
120 app.close();
121 await rm(dataDir, { recursive: true, force: true });
122 });
123
124 test("a person sees a lane for each repository they can read, and no other", async () => {
125 const cookie = await signIn("alice");
126 const page = await (
127 await fetch(`${base}/map`, {
128 headers: { cookie: `${cookie}; forge_mode=studio` },
129 })
130 ).text();
131 expect(page).toContain("<h1>Map</h1>");
132 expect(page).toContain('href="/alice/engine/map"');
133 expect(page).toContain("Extract renderer");
134 expect(page).toContain("Scene graph");
135 // The lane says how the repository runs itself and what is in flight.
136 expect(page).toContain("off · 1 run in flight");
137 // Where the crew is: the studio's word on the issue, and the dot.
138 expect(page).toContain('data-run="running"');
139 expect(page).toContain(">working</tspan");
140 expect(page).toContain('class="map-crew-dot"');
141 // A repository with nothing to draw is not a lane.
142 expect(page).not.toContain('href="/alice/bare/map"');
143 // The forge's admin reads every repository, so bob's is a lane here …
144 expect(page).toContain('href="/bob/secret/map"');
145
146 // … and bob, who is nobody's admin, sees his own and not alice's.
147 const bobs = await (
148 await fetch(`${base}/map`, { headers: { cookie: await signIn("bob") } })
149 ).text();
150 expect(bobs).toContain('href="/bob/secret/map"');
151 expect(bobs).toContain("Rotate the keys");
152 expect(bobs).not.toContain("alice/engine");
153 expect(bobs).not.toContain("Extract renderer");
154
155 // The per-repo map carries the same marker, so the two never disagree.
156 const own = await (
157 await fetch(`${base}/alice/engine/map`, { headers: { cookie } })
158 ).text();
159 expect(own).toContain('data-run="running"');
160 expect(own).toContain(">working</tspan");
161 });
162
163 test("nothing to draw anywhere is one quiet sentence; a stranger is sent to sign in", async () => {
164 const page = await (
165 await fetch(`${base}/map`, { headers: { cookie: await signIn("carol") } })
166 ).text();
167 expect(page).toContain("Nothing to map");
168 expect(page).not.toContain('class="map-lane"');
169 expect(page).not.toContain("No open issues to map");
170
171 const anonymous = await fetch(`${base}/map`, { redirect: "manual" });
172 expect(anonymous.status).toBe(303);
173 expect(anonymous.headers.get("location")).toContain("/signin");
174 });
175
176 test("the map is reached from the user menu and the palette on both homes", async () => {
177 const cookie = await signIn("alice");
178 for (const mode of ["studio", "dev"]) {
179 const home = await (
180 await fetch(`${base}/`, {
181 headers: { cookie: `${cookie}; forge_mode=${mode}` },
182 })
183 ).text();
184 expect(home).toContain('href="/map"');
185 expect(home).toContain('"t":"Map","h":"/map"');
186 }
187 });
188
189 test("the data has one entry per visible repository, with its issues and where the crew is", async () => {
190 const token = createToken(app.db, alice.id, "test", "rw").token;
191 const res = await fetch(`${base}/api/v1/map`, {
192 headers: { authorization: `Bearer ${token}` },
193 });
194 expect(res.status).toBe(200);
195 const data = (await res.json()) as {
196 repos: {
197 repo: { owner: string; name: string };
198 autonomy: string;
199 spentTodayUsd: number | null;
200 inFlight: number;
201 issues: { number: number; title: string }[];
202 ready: { number: number }[];
203 working: number[];
204 edges: { issue: number; blockedBy: number }[];
205 }[];
206 };
207 const names = data.repos.map((r) => `${r.repo.owner}/${r.repo.name}`);
208 expect(names).toContain("alice/engine");
209 expect(names).toContain("bob/secret");
210 expect(names).not.toContain("alice/bare");
211 const lane = data.repos.find((r) => r.repo.name === "engine")!;
212 expect(lane.issues.map((i) => i.number)).toEqual([1, 2, 3]);
213 expect(lane.ready.map((r) => r.number)).toEqual([1, 3]);
214 expect(lane.edges).toEqual([{ issue: 2, blockedBy: 1 }]);
215 expect(lane.working).toEqual([1]);
216 expect(lane.autonomy).toBe("off");
217 expect(lane.spentTodayUsd).toBeNull();
218 expect(lane.inFlight).toBe(1);
219
220 // The per-repo data says the same about where the crew is.
221 const own = (await (
222 await fetch(`${base}/api/v1/repos/alice/engine/map`, {
223 headers: { authorization: `Bearer ${token}` },
224 })
225 ).json()) as { working: number[] };
226 expect(own.working).toEqual([1]);
227
228 // A stranger's token sees only what a stranger can: nothing private.
229 const bobToken = createToken(app.db, bob.id, "test", "ro").token;
230 const bobs = (await (
231 await fetch(`${base}/api/v1/map`, {
232 headers: { authorization: `Bearer ${bobToken}` },
233 })
234 ).json()) as { repos: { repo: { owner: string } }[] };
235 expect(bobs.repos.map((r) => r.repo.owner)).toEqual(["bob"]);
236 });
237 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs