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

No new terminal screen for a thing that has a web page: a rule test lists today's screens and the list can only shrink #18519

opened this

Merged 4h 5m ago, live in production

scout/forge:scout/18518-no-new-terminal-screen-for-a-thing-that → main 0 commits fork

  • Merged. scout/18518-no-new-terminal-screen-for-a-thing-that was merged into main as 8a9f7de.

Review

Sign in to review this change.
3 files changed +195 −0
test/screen-page-pairs.json added +3
@@ -0,0 +1,3 @@
1 {
2 "proposeupstream": "offer-upstream"
3 }
test/screens-with-pages.json added +130
@@ -0,0 +1,130 @@
1 [
2 "abstractions",
3 "access",
4 "advisories",
5 "agents",
6 "allocation",
7 "api",
8 "app_templates",
9 "appflags",
10 "appreleases",
11 "appsecrets",
12 "audit",
13 "bets",
14 "billing",
15 "bills",
16 "boards",
17 "bottleneck",
18 "bring",
19 "builds",
20 "capacity",
21 "chain",
22 "changelog",
23 "chapters",
24 "cloud",
25 "cloud_end",
26 "cloudtree",
27 "cockpit",
28 "commits",
29 "confirms",
30 "conflicts",
31 "connections",
32 "contribute",
33 "crew",
34 "crewdevices",
35 "data",
36 "dataset",
37 "display",
38 "displays",
39 "economics",
40 "events",
41 "family",
42 "features",
43 "fileholds",
44 "findings",
45 "flags",
46 "fleet",
47 "fleetgraph",
48 "flow",
49 "flow_cpu",
50 "flows",
51 "flowsall",
52 "forge_it",
53 "forgename",
54 "forgeready",
55 "forges",
56 "forkflows",
57 "games",
58 "gifts",
59 "grants",
60 "hooks",
61 "identities",
62 "infra",
63 "inventory",
64 "issues",
65 "iterations",
66 "knobs",
67 "labels",
68 "lapsed",
69 "largefiles",
70 "machines",
71 "maintenance",
72 "migrate",
73 "model",
74 "newforge",
75 "next",
76 "notes",
77 "packs",
78 "passkeys",
79 "payments",
80 "people",
81 "pinned",
82 "pricing",
83 "prompts",
84 "proposal_tokens",
85 "proposeupstream",
86 "pull",
87 "readgrants",
88 "refs",
89 "registry_gallery",
90 "releases",
91 "repo",
92 "reports",
93 "resilience",
94 "returns",
95 "review",
96 "roadmap",
97 "runners",
98 "runs",
99 "scrapes",
100 "secrets",
101 "security_public",
102 "series",
103 "sources",
104 "space",
105 "spend",
106 "startforge",
107 "statement",
108 "status",
109 "subscriptions",
110 "support",
111 "system",
112 "tab",
113 "teams",
114 "telemetry",
115 "template",
116 "templates",
117 "terms",
118 "thread",
119 "trace",
120 "traces",
121 "traffic",
122 "trusted",
123 "usage",
124 "variants",
125 "visitor_bring",
126 "wallet",
127 "waves",
128 "week",
129 "whocan"
130 ]
test/terminal-screens-rule.test.ts added +62
@@ -0,0 +1,62 @@
1 /**
2 * The rule (P18): no new terminal screen for a thing that has a web page. Each file in
3 * src/tui/screens is a screen; it is paired with a page in src/web/pages by the same name
4 * (case, `-` and `_` ignored) or by an explicit entry in test/screen-page-pairs.json. A
5 * paired screen must be on test/screens-with-pages.json, today's frozen list; the list
6 * only shrinks.
7 */
8 import { expect, test } from "bun:test";
9 import { existsSync, readdirSync, readFileSync } from "node:fs";
10 import { join } from "node:path";
11
12 const ROOT = join(import.meta.dir, "..");
13 const SCREENS = join(ROOT, "src", "tui", "screens");
14 const PAGES = join(ROOT, "src", "web", "pages");
15 const read = (n: string) => JSON.parse(readFileSync(join(import.meta.dir, n), "utf8"));
16
17 const frozen: string[] = read("screens-with-pages.json");
18 const explicit: Record<string, string> = read("screen-page-pairs.json");
19
20 const squash = (f: string) => f.replace(/\.ts$/, "").replace(/[-_]/g, "").toLowerCase();
21 const stem = (f: string) => f.replace(/\.ts$/, "");
22
23 /** Pairs screen name -> page file name, for every screen that has a page. */
24 export function pairs(screens: string[], pages: string[], extra: Record<string, string>): Record<string, string> {
25 const byName = new Map(pages.map((p) => [squash(p), p]));
26 const out: Record<string, string> = {};
27 for (const s of screens) {
28 const page = extra[stem(s)] ? `${extra[stem(s)]}.ts` : byName.get(squash(s));
29 if (page) out[stem(s)] = page;
30 }
31 return out;
32 }
33
34 const screens = readdirSync(SCREENS).filter((f) => f.endsWith(".ts"));
35 const pages = readdirSync(PAGES).filter((f) => f.endsWith(".ts"));
36 const paired = pairs(screens, pages, explicit);
37
38 test("a terminal screen for a thing with a web page is not new: build the web page instead", () => {
39 const fresh = Object.entries(paired).filter(([s]) => !frozen.includes(s));
40 expect(
41 fresh.map(([s, p]) => `src/tui/screens/${s}.ts`),
42 `These screens have a web page already (${fresh.map(([, p]) => `src/web/pages/${p}`).join(", ")}). ` +
43 `Build the web page instead of a new terminal screen; do not add the screen to test/screens-with-pages.json.`,
44 ).toEqual([]);
45 });
46
47 test("every name on the frozen list is still a screen with a page, so the list only shrinks", () => {
48 const gone = frozen.filter((s) => !paired[s]);
49 expect(gone, `Delete these from test/screens-with-pages.json, the screen or its page is gone: ${gone.join(", ")}`).toEqual([]);
50 expect(frozen, "keep the list sorted and free of repeats").toEqual([...new Set(frozen)].sort());
51 });
52
53 test("every explicit pair names a screen and a page that exist", () => {
54 for (const [s, p] of Object.entries(explicit)) {
55 expect(existsSync(join(SCREENS, `${s}.ts`)), `no screen ${s}`).toBe(true);
56 expect(existsSync(join(PAGES, `${p}.ts`)), `no page ${p}`).toBe(true);
57 }
58 });
59
60 test("the pairing reads same names and explicit entries, and nothing else", () => {
61 expect(pairs(["a_b.ts", "c.ts", "d.ts"], ["a-b.ts", "x.ts"], { d: "x" })).toEqual({ a_b: "a-b.ts", d: "x.ts" });
62 });

Search
↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs