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

Looks of `/` at phone and desktop width, signed out, are on file from the preview's own looks #12241

Merged opened this

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

Merged

scout/forge:scout/11313-looks-of-at-phone-and-desktop-width-sign → main 3 commits fork 2 threads · 2 unresolved

  • Merged. scout/11313-looks-of-at-phone-and-desktop-width-sign was merged into main as b2c98db.

Review

Sign in to review this change.
4 files changed +50 −6
src/looks/service.ts +4 −2
@@ -524,8 +524,10 @@ export function startLooks(app: App, options: LooksOptions): LooksHandle {
524524 const asNobody = (kind: LookKind, page: string): boolean =>
525525 !sealed &&
526526 !(kind !== "thumb" && ownerPages.has(page)) &&
527 !ownerLooks.some((l) => l.page === page && l.kind === kind) &&
528 (everyone || (kind === "thumb" && record.access === "public"));
527 !ownerLooks.some((l) => l.page === page && l.kind === kind && l.as !== "nobody") &&
528 (everyone ||
529 ownerLooks.some((l) => l.page === page && l.as === "nobody") ||
530 (kind === "thumb" && record.access === "public"));
529531 const owner = getUserById(app.db, repo.ownerId);
530532 const asOwner: GrantWho | undefined =
531533 owner === undefined
src/spawn/preview-looks.ts +15 −3
@@ -158,11 +158,18 @@ export const PREVIEW_NEWCOMER = "preview-newcomer";
158158 export const PREVIEW_NEWCOMER_ORG = "preview-newcomer-forge";
159159 export const PREVIEW_NEWCOMER_PAGE = "/?as=newcomer";
160160
161 /**
162 * `/` as a stranger sees it (#11313). The home is a signed-in page for the owner, so
163 * `/` itself is taken as the owner; this page is the same route with a query it ignores,
164 * taken with no session at all, so its phone and desktop pictures are the signed-out home.
165 */
166 export const PREVIEW_SIGNED_OUT_PAGE = "/?as=signedout";
167
161168 export interface OwnerLook {
162169 readonly page: string;
163170 readonly kind: LookKind;
164 /** Taken as the newcomer, not the preview admin. */
165 readonly as?: "newcomer";
171 /** Taken as the newcomer, not the preview admin, or as nobody: no session at all. */
172 readonly as?: "newcomer" | "nobody";
166173 }
167174
168175 /** The named list: each page at desk and phone, taken as the owner. */
@@ -190,6 +197,7 @@ export const PREVIEW_OWNER_LOOKS: readonly OwnerLook[] = [
190197 PREVIEW_RESILIENCE_PAGE,
191198 PREVIEW_SEARCH_PAGE,
192199 PREVIEW_NEWCOMER_PAGE,
200 PREVIEW_SIGNED_OUT_PAGE,
193201 PREVIEW_MACHINES_PAGE,
194202 PREVIEW_DISK_OPEN_LOOK,
195203 ...PREVIEW_SETTINGS_PAGES,
@@ -197,7 +205,11 @@ export const PREVIEW_OWNER_LOOKS: readonly OwnerLook[] = [
197205 "/forges",
198206 ].flatMap((page) =>
199207 (["desktop", "phone"] as const).map((kind): OwnerLook =>
200 page === PREVIEW_NEWCOMER_PAGE ? { page, kind, as: "newcomer" } : { page, kind },
208 page === PREVIEW_NEWCOMER_PAGE
209 ? { page, kind, as: "newcomer" }
210 : page === PREVIEW_SIGNED_OUT_PAGE
211 ? { page, kind, as: "nobody" }
212 : { page, kind },
201213 ),
202214 );
203215
test/forge-looks.test.ts +16
@@ -14,6 +14,7 @@ import { createApp, type App } from "../src/app.ts";
1414 import { createToken } from "../src/core/tokens.ts";
1515 import { createUser } from "../src/core/users.ts";
1616 import { buildRouter, serve, type Servers } from "../src/http/server.ts";
17 import { PREVIEW_OWNER_LOOKS, PREVIEW_SIGNED_OUT_PAGE } from "../src/spawn/preview-looks.ts";
1718 import { quietLogs } from "./helpers/globals.ts";
1819
1920 quietLogs();
@@ -150,6 +151,21 @@ test("app.looks stays within 24 paths, each once", () => {
150151 expect(new Set(looks).size).toBe(looks.length);
151152 });
152153
154 test("`/` signed out is its own look at phone and desktop, taken with no session (#11313)", async () => {
155 // `/` is in looksAsOwner, so the service takes it as the owner; the signed-out home
156 // is a page of its own whose looks the service takes as nobody.
157 const { looks, looksAsOwner } = manifest();
158 expect(looks).toContain("/");
159 expect(looksAsOwner).toContain("/");
160 for (const kind of ["phone", "desktop"] as const) {
161 expect(PREVIEW_OWNER_LOOKS).toContainEqual({ page: PREVIEW_SIGNED_OUT_PAGE, kind, as: "nobody" });
outdated

This restates the constant and would still pass if the looks service stopped taking / signed out. Assert the behaviour, not the literal.

162 expect(PREVIEW_OWNER_LOOKS).toContainEqual({ page: "/", kind });
163 }
164 const res = await fetch(`${servers.url}${PREVIEW_SIGNED_OUT_PAGE}`, { redirect: "manual" });
165 expect(res.status).toBe(200);
166 expect(await res.text()).toContain("Start my forge");
167 });
168
153169 test("a look below the top level is the preview seed's, taken as the owner", () => {
154170 const { looks, looksAsOwner } = manifest();
155171 for (const p of looks.filter((p) => !isTopLevel(p))) {
test/looks-owner.test.ts +15 −1
@@ -45,7 +45,7 @@ import {
4545 seedPreview,
4646 } from "../src/spawn/preview-seed.ts";
4747 import { PREVIEW_CONFIG_FILES } from "../src/spawn/preview-config.ts";
48 import { ownerLooksFor, PREVIEW_FORKS, PREVIEW_HELD_THEMES, PREVIEW_ITERATIONS_PAGE } from "../src/spawn/preview-looks.ts";
48 import { ownerLooksFor, PREVIEW_FORKS, PREVIEW_HELD_THEMES, PREVIEW_ITERATIONS_PAGE, PREVIEW_SIGNED_OUT_PAGE } from "../src/spawn/preview-looks.ts";
4949 import { iterationsOf } from "../src/core/iterations.ts";
5050 import { localSource } from "../src/view/local.ts";
5151 import { isFormConfig, parseConfig } from "../src/web/render/config-format.ts";
@@ -516,6 +516,20 @@ describe("looks of a public app", () => {
516516 // The thumb is what a stranger sees, still.
517517 expect(rows.find((l) => l.page === page && l.kind === "thumb")?.takenAs).toBe("nobody");
518518 }
519 // `/` signed out (#11313): its own page, phone and desktop, with no session in the grant.
520 for (const [kind, width] of [["desktop", 1280], ["phone", 390]] as const) {
521 expect(rows.find((l) => l.page === PREVIEW_SIGNED_OUT_PAGE && l.kind === kind)?.takenAs).toBe("nobody");
522 const call = calls.find(
523 (c) =>
524 c.url.includes(`forge--${opened.value.number}.`) &&
525 new URL(c.url).searchParams.get("to") === PREVIEW_SIGNED_OUT_PAGE &&
526 c.width === width &&
527 c.dark !== true,
528 );
529 expect(call).toBeDefined();
530 const grant = readGrant(dataDir, new URL(call!.url).searchParams.get("t") ?? "", { app: record, env });
531 expect(grant?.who).toBeUndefined();
532 }
519533 }, 120_000);
520534
521535 test("production of the forge, and a preview of any other repository, add none", () => {

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs