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

Home shows the app a first ask made, ahead of the forge's own code #13784

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

trevato/claim-journey-home-apps → main 1 commit

  • Merged. trevato/claim-journey-home-apps was merged into main as cc8b5bb.

Review

Sign in to review this change.
3 files changed +43 −8
src/core/client-apps.ts +14 −6
@@ -10,7 +10,7 @@ import { ago } from "../feed/rank.ts";
1010 import { appsRuntime, envsFor } from "../apps/runtime.ts";
1111 import { appsForRepos } from "./apps.ts";
1212 import { spawnedRepos } from "./next-steps.ts";
13 import { withoutArchived, type Repo } from "./repos.ts";
13 import { listReposOwnedBy, withoutArchived, type Repo } from "./repos.ts";
1414 import type { User } from "./users.ts";
1515
1616 export interface ClientApp {
@@ -23,12 +23,17 @@ export interface ClientApp {
2323 readonly live: string | undefined;
2424 }
2525
26 /** The apps `user` can see on a spawned forge, each with its agent counts; archived ones are put away, not shown. */
26 /**
27 * The apps `user` can see on a spawned forge, each with its agent counts; archived ones are put
28 * away, not shown. Their own come first (a first ask makes one under their name), then the forge's.
29 */
2730 export async function clientAppRows(
2831 app: App,
2932 user: User,
3033 ): Promise<readonly ClientApp[]> {
31 const repos = withoutArchived(await spawnedRepos(app, user));
34 const own = listReposOwnedBy(app.db, user.id);
35 const mine = new Set(own.map((r) => r.id));
36 const repos = withoutArchived([...own, ...(await spawnedRepos(app, user)).filter((r) => !mine.has(r.id))]);
3237 if (repos.length === 0) return [];
3338 const rows = app.db
3439 .query<{ repo_id: string; state: string; n: number }, string[]>(
@@ -47,9 +52,9 @@ export async function clientAppRows(
4752 return up ? runtime.urlFor(record, "production") : undefined;
4853 };
4954 return repos.map((repo) => {
50 const own = rows.filter((r) => r.repo_id === repo.id);
55 const runs = rows.filter((r) => r.repo_id === repo.id);
5156 const n = (state: string): number =>
52 own.find((r) => r.state === state)?.n ?? 0;
57 runs.find((r) => r.state === state)?.n ?? 0;
5358 return { repo, working: n("running"), queued: n("queued"), live: liveOf(repo) };
5459 });
5560 }
@@ -135,7 +140,10 @@ export function doingLine(doing: ClientDoing | undefined): string {
135140 return title === "" ? "" : `Working on: ${title}`;
136141 }
137142
138 /** `Finished 3 days ago: Fix the menu`, or "" for an app with nothing finished; both doors word it so. */
143 /**
144 * `Finished 3 days ago: Fix the menu`, or "" for an app with nothing finished; both doors word it
145 * so.
146 */
139147 export function finishedLine(finished: ClientFinished | undefined, now: number): string {
140148 const title = finished === undefined ? "" : cutTitle(finished.title);
141149 if (finished === undefined || title === "") return "";
src/web/studio/client_home.ts +4 −2
@@ -48,9 +48,11 @@ export async function clientApps(ctx: Ctx, user: User): Promise<Html> {
4848 variant: "outline",
4949 })
5050 : null;
51 // The running app, by the way the apps page opens it; an app that is not up offers nothing.
51 // The running app, by the way the apps page opens it; an app that is not up offers nothing,
52 // and neither does the forge's own code, whose address is the page the person is on.
53 const here = (ctx.app.config.url ?? new URL(ctx.request.url).origin).replace(/\/$/, "");
5254 const open =
53 live === undefined
55 live === undefined || live.replace(/\/$/, "") === here
5456 ? null
5557 : btn("Open", { href: `${repoBase(repo)}/app/production/open`, variant: "outline" });
5658 return html`<li class="client-app">
test/client-home.test.ts +25
@@ -264,6 +264,13 @@ describe("a client's first screen", () => {
264264 expect(up).toContain(">Open<");
265265 expect(up).toContain('href="/marias/bakery"');
266266 expect(runtime.urlFor(record, "production")).toStartWith("https://");
267
268 // The forge's own code answers at the address of this very page: an Open there would only
269 // load the page again, so it is not offered.
270 const here = { ...ctx, request: new Request(runtime.urlFor(record, "production")) } as unknown as Ctx;
271 const same = String(await clientApps(here, maria));
272 expect(same).not.toContain("/app/production/open");
273 expect(same).toContain('href="/marias/bakery"');
267274 for (const shown of [up, down])
268275 for (const word of ["deploy", "process", "port"])
269276 expect(text(shown)).not.toMatch(new RegExp(`\\b${word}`, "i"));
@@ -458,6 +465,24 @@ describe("a client's first screen", () => {
458465 app.stop();
459466 });
460467
468 test("an app made under the person's own name is on the first screen, ahead of the forge's", async () => {
469 const maria = getUserByName(child.db, "maria")!;
470 // What a first ask from the home makes: an app of maria's, not of the organisation's.
471 const made = await createRepo(child, maria, { name: "countdown" });
472 if (!made.ok) throw new Error(JSON.stringify(made.error));
473 try {
474 const names = (await clientAppRows(child, maria)).map((r) => `${r.repo.ownerName}/${r.repo.name}`);
475 expect(names[0]).toBe("maria/countdown");
476 expect(names).toContain("marias/bakery");
477 const home = main(await page(owner));
478 const apps = home.slice(home.indexOf('id="client-apps"'));
479 expect(apps).toContain('href="/maria/countdown"');
480 expect(apps.indexOf('href="/maria/countdown"')).toBeLessThan(apps.indexOf('href="/marias/bakery"'));
481 } finally {
482 expect(moveArchived(child.db, made.value.id, true)).toBe(true);
483 }
484 });
485
461486 test("an archived app leaves the first screen and comes back when woken", async () => {
462487 const maria = getUserByName(child.db, "maria")!;
463488 const second = await createRepo(child, maria, { name: "cafe", owner: "marias" });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs