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

An app made in the tab forge can be published as a read-only link on the forge, with no login #18219

opened this

Merged 11h 28m ago, live in production

scout/forge:scout/18215-an-app-made-in-the-tab-forge-can-be-publ → main 0 commits fork 3 threads · 3 unresolved

  • Merged. scout/18215-an-app-made-in-the-tab-forge-can-be-publ was merged into main as 7a7184b.

Review

Sign in to review this change.
19 files changed +324 −18
docs/features/tabforge.md +8
@@ -13,3 +13,11 @@ It needs a browser with service workers and the private file system. Without the
1313 The page says, before anything else, where it lives: on this device, in this browser's own storage; it stops when the tab closes; others cannot reach it. Its one primary action opens the tab's home. It is two taps from making a forge: `/forges/new` carries a link, "Or try a forge in this tab", that leads to `/tabforge`.
1414
1515 The page is `src/web/pages/tabforge.ts`; the words are `src/web/tabforge/words.ts`, shared with the terminal. The store itself exists only in a browser tab, which a terminal session cannot reach, so the terminal's twin is the new-forge screen (`src/tui/screens/newforge.ts`): its last row offers the tab forge with the same words and this forge's `/tabforge` address (hidden when the forge has no URL). The terminal's issue list (`src/tui/screens/issues.ts`) shows the forge's issues, not the tab's.
16
17 ## Get a link (#18215)
18
19 An app made in a tab (`/tab`, format `src/tab/blocks.ts`) can be sent to the forge as one read-only link that opens on any device, with no login. The app's page in the tab offers **Get a link** beside its source: a plain form whose hidden field carries the app's JSON, so it works with script off. `POST /tabforge-link` (`src/web/pages/tabforge-link.ts`, logic in `src/tab/share.ts`) checks it is same-origin, reads at most 80 KB, validates it with `decodeApp` (its `LIMITS` apply), stores the decoded app only, never its entries, in `tab_shared`, and answers a 16-character random id as `/tabforge-link/<id>`. A spec that does not decode stores nothing. `GET /tabforge-link/<id>` draws the app read-only (the preview renderer: no forms, no entries), escaped, with the floor's headers; an unknown or malformed id is the forge's one 404.
20
21 The route sits outside `/tabforge/` and `/tab/f/` on purpose: a service worker in either scope would answer for it in a browser that started a tab forge. It is an open door for strangers, so it is limited by rate, not by count: 10 posts a minute per address (the `share` door in `src/http/strangers.ts`), taken before the body is read. Storage is bounded the other way: the forge keeps the newest 5000 links and the oldest go as a new one is made, so a link can stop opening once enough newer ones exist, and no one can fill the table and lock the door. It mints no account and no visitor principal, and there is no way to edit or delete a link yet.
22
23 The terminal's twin is the tab forge's palette entry (`src/tui/screens/tab.ts`): `tabLine()` says the same words (`TAB_LINK` in `src/tab/words.ts`). The terminal cannot hold a tab's app, so it has nothing to send.
src/core/migration-pins/20261204120000-tab-shared-apps.pin added +1
@@ -0,0 +1,1 @@
1 d6377b850365723a9738f328c8a735246aa0e95681b6d34ea8af57d4635a1fc9
src/core/migrations/20261204120000-tab-shared-apps.ts added +12
@@ -0,0 +1,12 @@
1 // An app made in the tab forge, published as a read-only link (#18215): one row per link, the
2 // validated spec as JSON, and the address bucket that sent it so one connection's count is capped.

Non-blocking: the per-connection count this comment describes is gone, so bucket and its index serve nothing now. Remove them (and re-pin) or say what they are kept for.

3 // Additive; no entries are ever stored, only the app.
4 export default `
5 CREATE TABLE tab_shared (
6 id TEXT PRIMARY KEY,
7 spec TEXT NOT NULL,
8 bucket TEXT NOT NULL,
9 created INTEGER NOT NULL
10 );
11 CREATE INDEX tab_shared_bucket ON tab_shared (bucket);
12 `;
src/core/reserved.ts +1
@@ -158,6 +158,7 @@ export const SYSTEM_NAMES: readonly string[] = [
158158 "traces",
159159 "talk",
160160 "tabforge",
161 "tabforge-link",
161162 "peek",
162163 "notes",
163164 "next",
src/generated/marks.ts +15 −13
@@ -204,19 +204,20 @@ import k199 from "../http/marks/support.json";
204204 import k200 from "../http/marks/sw.js.json";
205205 import k201 from "../http/marks/system.json";
206206 import k202 from "../http/marks/tab.json";
207 import k203 from "../http/marks/tabforge.json";
208 import k204 from "../http/marks/talk.json";
209 import k205 from "../http/marks/tell.json";
210 import k206 from "../http/marks/templates.json";
211 import k207 from "../http/marks/templates.json.json";
212 import k208 from "../http/marks/terms.json";
213 import k209 from "../http/marks/theme.json";
214 import k210 from "../http/marks/toolbar-lab.js.json";
215 import k211 from "../http/marks/toolbar-lab.json";
216 import k212 from "../http/marks/traces.json";
217 import k213 from "../http/marks/verify.json";
218 import k214 from "../http/marks/welcome.json";
219 import k215 from "../http/marks/well-known.json";
207 import k203 from "../http/marks/tabforge-link.json";
208 import k204 from "../http/marks/tabforge.json";
209 import k205 from "../http/marks/talk.json";
210 import k206 from "../http/marks/tell.json";
211 import k207 from "../http/marks/templates.json";
212 import k208 from "../http/marks/templates.json.json";
213 import k209 from "../http/marks/terms.json";
214 import k210 from "../http/marks/theme.json";
215 import k211 from "../http/marks/toolbar-lab.js.json";
216 import k212 from "../http/marks/toolbar-lab.json";
217 import k213 from "../http/marks/traces.json";
218 import k214 from "../http/marks/verify.json";
219 import k215 from "../http/marks/welcome.json";
220 import k216 from "../http/marks/well-known.json";
220221
221222 /** Each file of `http/marks/`, parsed, in name order. */
222223 export const MARK_FILES: readonly unknown[] = [
@@ -436,4 +437,5 @@ export const MARK_FILES: readonly unknown[] = [
436437 k213,
437438 k214,
438439 k215,
440 k216,
439441 ];
src/http/lazy_lists.ts +2
@@ -479,6 +479,8 @@ export const DISCOVERY_ROUTES = [
479479 ["GET", "/tab/:name"],
480480 ["GET", "/tabforge/sw.js"],
481481 ["GET", "/tabforge"],
482 ["POST", "/tabforge-link"],
483 ["GET", "/tabforge-link/:id"],
482484 ] as const;
483485
484486 /** `docsRoutes` (`routes/docs.ts`). */
src/http/routes/discovery.ts +5
@@ -14,6 +14,7 @@ import { machineTermAsset, ghosttyWasmAsset, wasmResponse } from "../../web/mach
1414 import { openSearch } from "../../web/opensearch.ts";
1515 import { agentsPage } from "../../web/pages/agents.ts";
1616 import { tabforgePage } from "../../web/pages/tabforge.ts";
17 import { tabLinkMake, tabLinkOpen } from "../../web/pages/tabforge-link.ts";
1718 import { offlinePage } from "../../web/pages/offline.ts";
1819 import { tabPage } from "../../web/pages/tab.ts";
1920 import { tabFile, tabVendor } from "../../web/tab-asset.ts";
@@ -134,4 +135,8 @@ export function discoveryRoutes(router: Router<Handler>): void {
134135 router.add("GET", "/tab/:name", (ctx) => tabFile(ctx.request, ctx.params.name!));
135136 router.add("GET", "/tabforge/sw.js", () => tabforgeWorkerResponse()); // the tab forge's own scope (#17275)
136137 router.add("GET", "/tabforge", tabforgePage); // outside that scope: the page that registers it
138 // An app from a tab as a read-only link (#18215). Outside the tab forge's `/tabforge/` and
139 // `/tab/f/` scopes, so no worker answers it.
140 router.add("POST", "/tabforge-link", tabLinkMake);
141 router.add("GET", "/tabforge-link/:id", tabLinkOpen);
137142 }
src/http/strangers.ts +3 −3
@@ -23,7 +23,7 @@ import { transferGate } from "../git/env.ts";
2323 import { bucketOf, clientBucket } from "./peer.ts";
2424
2525 /** A door a stranger is counted at, each with its own minute. */
26 export type Door = "api" | "git" | "code" | "plan" | "pay";
26 export type Door = "api" | "git" | "code" | "plan" | "pay" | "share";
2727
2828 export interface StrangerLimits {
2929 /** Requests per minute through each door, per client address. */
@@ -72,8 +72,8 @@ export interface StrangerLimits {
7272 }
7373
7474 export const STRANGER_LIMITS: StrangerLimits = {
75 perAddress: { api: 600, git: 60, code: 10, plan: 10, pay: 5 },
76 forge: { api: 6000, git: 600, code: 60, plan: 60, pay: 60 },
75 perAddress: { api: 600, git: 60, code: 10, plan: 10, pay: 5, share: 10 },
76 forge: { api: 6000, git: 600, code: 60, plan: 60, pay: 60, share: 120 },
7777 transfersPerAddress: 4,
7878 transferShare: 0.5,
7979 transferTimeoutMs: 7_200_000,
src/tab/apps.ts +3 −1
@@ -7,7 +7,9 @@ import { esc } from "./escape.ts";
77 import { settle } from "./fill.ts";
88 import type { TabDb, TabReply, TabRequest } from "./forge.ts";
99 import { ROOT, renderApp, type Rec } from "./render.ts";
10 import { linkForm } from "./share.ts";
1011 import { shell } from "./shell.ts";
12 import { TAB_LINK, TAB_LINK_LABEL } from "./words.ts";
1113 import { decodeApp, entryText, SPEC_VERSION, type BlockApp } from "./blocks.ts";
1214
1315 export const SAY_MAX = 300;
@@ -93,7 +95,7 @@ export function handleApps(db: TabDb, req: TabRequest, path: string, now: number
9395 if (req.method === "GET" && parts.length === 1)
9496 return found === null
9597 ? shell(title, `<h1>${esc(title)}</h1><p>This app's spec cannot be read, so it cannot be drawn. It can still be removed.</p>${removeForm(id, title)}`)
96 : shell(found.app.title, `${renderApp(found.app, { appId: id, records: records(db, id), today: dayOf(now) })}<p><a href="${ROOT}/apps/${id}/source">How this app was made</a></p>${removeForm(id, title)}`, 200, false);
98 : shell(found.app.title, `${renderApp(found.app, { appId: id, records: records(db, id), today: dayOf(now) })}<p><a href="${ROOT}/apps/${id}/source">How this app was made</a></p><p class="muted">${esc(TAB_LINK)}</p>${linkForm(found.app, TAB_LINK_LABEL)}${removeForm(id, title)}`, 200, false);
9799 if (req.method === "GET" && parts[1] === "source" && parts.length === 2) return found === null ? notFound() : shell(`${found.app.title}: why`, source(found));
98100 if (req.method !== "POST") return shell("Not allowed", "<p>That is not something this forge does.</p>", 405);
99101 if (parts[1] === "delete" && parts.length === 2) {
src/tab/share.ts added +61
@@ -0,0 +1,61 @@
1 /**
2 * An app made in a tab, sent to the forge as one read-only link (#18215). Plain data in, plain data
3 * out over the two-function `TabDb`: the app is validated by `decodeApp` (so `LIMITS` apply),
4 * stored as the decoded app and nothing else (never its entries), and named by a short unguessable
5 * id. Strangers may call this, so the table is bounded by letting the oldest rows go, never by
6 * refusing a new link: a cap that cannot free would let strangers lock the door for everyone.
7 */
8 import { decodeApp, LIMITS, type BlockApp } from "./blocks.ts";
9 import type { TabDb } from "./forge.ts";
10 import { esc } from "./escape.ts";
11 import { pageOf, renderApp } from "./render.ts";
12
13 /** Where the link is made (POST) and opened (GET, with the id after a slash). */
14 export const SHARE_PATH = "/tabforge-link";
15 /** The most bytes of a form that carries an app: the JSON, percent-encoded, with room. */
16 export const SHARE_BODY_MAX = LIMITS.json * 4;
17 /** Links the forge keeps; past this the oldest go as a new one comes in. */
18 export const KEPT = 5000;
19
20 const ID = /^[A-Za-z0-9_-]{16}$/;
21 export const isShareId = (id: string): boolean => ID.test(id);
22
23 export type Shared = { readonly ok: true; readonly id: string } | { readonly ok: false; readonly status: 413 | 422; readonly why: string };
24
25 const newId = (): string => Buffer.from(crypto.getRandomValues(new Uint8Array(12))).toString("base64url");
26
27 /**
28 * Publish `input` (the app's JSON text) for the connection `bucket`. Stores nothing unless it
29 * decodes; keeps the newest `KEPT` links and lets the older go.
30 */
31 export function shareApp(db: TabDb, input: string, bucket: string, now: number): Shared {
32 if (input.length > LIMITS.json) return { ok: false, status: 413, why: "This app is too large to send." };
33 const decoded = decodeApp(input);
34 if (!decoded.ok) return { ok: false, status: 422, why: decoded.why };
35 const id = newId();
36 db.run("INSERT INTO tab_shared (id, spec, bucket, created) VALUES (?, ?, ?, ?)", [id, JSON.stringify(decoded.app), bucket, now]);
outdated

Permanent cap with no delete or expiry: after 20 links a connection is locked out for good, though the message says 'try again later'. The 5000 total below does the same to everyone. Remove both caps; keep the per-address minute and prune the oldest rows instead. Test it.

37 db.run("DELETE FROM tab_shared WHERE rowid <= (SELECT max(rowid) FROM tab_shared) - ?", [KEPT]);
38 return { ok: true, id };
39 }
40
41 /**
42 * The app behind a link, or null: unknown id, malformed id and an unreadable row are all one
43 * answer.
44 */
45 export function sharedApp(db: TabDb, id: string): BlockApp | null {
46 if (!ID.test(id)) return null;
47 const row = db.all("SELECT spec FROM tab_shared WHERE id = ?", [id])[0];
48 if (row === undefined) return null;
49 const decoded = decodeApp(String(row.spec));
50 return decoded.ok ? decoded.app : null;
51 }
52
53 /** The read-only page: the app drawn as a preview (no forms, no entries), and where to make one. */
54 export const sharedPage = (app: BlockApp): string =>
55 pageOf(app.title, `${renderApp(app, { appId: null, records: [], today: "" })}<p class="muted">A read-only copy of an app made in a forge in a browser tab. <a href="/tab">Make your own</a>.</p>`);
56
57 /**
58 * The form the app's page offers: the app's JSON travels in the form, so it works with script off.
59 */
60 export const linkForm = (app: BlockApp, label: string): string =>
61 `<form method="post" action="${SHARE_PATH}" target="_blank" class="link"><input type="hidden" name="app" value="${esc(JSON.stringify(app))}"><button>${esc(label)}</button></form>`;
src/tab/words.ts +8 −1
@@ -18,6 +18,13 @@ export const TAB_LEFT_OUT = "No git, shell or installs here: those need a real L
1818 /** How an app leaves and enters: one file, checked on the way in. */
1919 export const TAB_MOVE = "An app is one JSON file: download it from the forge's home (with its issues or without) and choose it (or paste it) in another tab forge, which refuses a file that does not fit.";
2020
21 /**
22 * The link an app's page offers beside the file: the button's label and what it does, said the same
23 * everywhere.
24 */
25 export const TAB_LINK_LABEL = "Get a link";
26 export const TAB_LINK = "Get a link: send an app to the forge and get one read-only address that opens it on any device, with no login. Only the app goes, never its entries; anyone with the address can read it, so share it only where you mean to.";
27
2128 /**
2229 * The optional model, said before anything is downloaded. It only fills the app's spec (a title, a
2330 * kind and a few words, checked against a schema); the compiler writes the spec when there is no
@@ -29,4 +36,4 @@ export const TAB_MODEL: readonly string[] = [
2936 ];
3037
3138 /** The terminal's one sentence: the facts and where the page is. */
32 export const tabLine = (): string => `${TAB_FACTS.join(" ")} ${TAB_LEFT_OUT} ${TAB_MOVE} ${TAB_MODEL.join(" ")} Open /tab in a browser to start it and to make an app from a sentence.`;
39 export const tabLine = (): string => `${TAB_FACTS.join(" ")} ${TAB_LEFT_OUT} ${TAB_MOVE} ${TAB_LINK} ${TAB_MODEL.join(" ")} Open /tab in a browser to start it and to make an app from a sentence.`;
test/forge-looks.test.ts +1
@@ -32,6 +32,7 @@ const NOT_A_PAGE: Record<string, string> = {
3232 "/next": "no picture: not in app.looks (its 32 slots are full); the page is covered by test/next-all.test.ts",
3333 "/pricing": "no picture: not in app.looks; the page is covered by test/pricing-order.test.ts",
3434 "/tabforge": "no picture: not in app.looks (its 32 slots are full); the page is covered by test/tabforge-page.test.ts",
35 "/tabforge-link": "no picture: not in app.looks (its 32 slots are full); a POST that stores an app and answers a link, and /tabforge-link/<id> needs a stored app; covered by test/tab-share.test.ts",
3536 "/archive": "no picture: not in app.looks (its 32 slots are full); the page is covered by test/archive-page.test.ts, with a 390 px measure, and test/apps-archived.test.ts",
3637 "/templates": "no picture: not in app.looks; the page is covered by test/templates-page.test.ts",
3738 "/traces": "no picture: not in app.looks (its 32 slots are full); the page is covered by test/traces-list.test.ts",
test/no-polling.test.ts +1
@@ -306,6 +306,7 @@ const NOT_WALKED: Record<string, string> = {
306306 "/talk/dev/:token": "a frame proxied from a running dev cell, not a page; the seed starts none",
307307 "/talk/dev/:token/*path": "a file proxied from a running dev cell, not a page; the seed starts none",
308308 "/infra/end/:act/*path": "the plan of a stop or delete, a page for a cloud resource the seed does not have; the action word is not in the seed",
309 "/tabforge-link/:id": "a shared tab-forge app named by a random id the seed does not hold (test/tab-share.test.ts covers it)",
309310 "/tab/v/:hash/:file": "a content-hashed browser-tab bundle file, JS or wasm, not a page; the hash is one the seed cannot guess",
310311 "/edge/config/:file": "a published config file for the edge, JSON or a key, not a page; the seed publishes none",
311312 "/:owner/-/teams/:team": "needs an organization and a team",
test/security-floor-routes.test.ts +1
@@ -70,6 +70,7 @@ const REPORT = "needs a report an outsider filed; the seed has none";
7070 const SHOT = "needs a pin with a picture kept by refs/shots; the seed pins nothing";
7171 const CART = "the seed pins no build with a cart (test/build-cart.test.ts covers its headers)";
7272 const UNSEEDED: Record<string, string> = {
73 "/tabforge-link/:id": "a shared tab-forge app named by a random id the seed does not hold (test/tab-share.test.ts covers it)",
7374 "/tab/v/:hash/:file": "a vendored file of the browser-tab forge, named by its content hash, which the seed does not hold (test/tab.test.ts covers it)",
7475 "/infra/end/:act/*path": "the plan of a stop or delete for a cloud resource, which the seed does not have (test/cloud-end.test.ts covers it)",
7576 "/games/:box": "a game box, which the seed does not make (test/games.test.ts covers it)",
test/tab-share-door.test.ts added +41
@@ -0,0 +1,41 @@
1 /**
2 * The `share` door guards POST /tabforge-link before the body is read (#18215): the 11th post in a
3 * minute from one address is a 429 and stores nothing, even when the body is not worth parsing.
4 */
5 import { afterAll, beforeAll, expect, test } from "bun:test";
6 import { mkdtemp, rm } from "node:fs/promises";
7 import { tmpdir } from "node:os";
8 import { join } from "node:path";
9 import { createApp, type App } from "../src/app.ts";
10 import { forgeHttp, type ForgeHttp } from "../src/http/server.ts";
11 import { compile } from "../src/tab/compile.ts";
12 import { quietLogs } from "./helpers/globals.ts";
13
14 quietLogs();
15
16 let dir = "";
17 let app: App;
18 let http: ForgeHttp;
19 const count = () => Number((app.db.query("SELECT count(*) AS n FROM tab_shared").get() as { n: number }).n);
20 const send = (body: string) =>
21 http.handle(new Request("http://forge.test/tabforge-link", { method: "POST", body, headers: { "content-type": "application/x-www-form-urlencoded", origin: "http://forge.test" } }));
22
23 beforeAll(async () => {
24 dir = await mkdtemp(join(tmpdir(), "forge-tabshare-door-"));
25 app = createApp({ dataDir: dir, port: 0 });
26 http = forgeHttp(app);
27 });
28 afterAll(async () => {
29 http.close();
30 app.close();
31 await rm(dir, { recursive: true, force: true });
32 });
33
34 test("the 11th post in a minute from one address is 429 and stores nothing", async () => {
35 const body = new URLSearchParams({ app: JSON.stringify(compile("a journal").app) }).toString();
36 for (let i = 0; i < 10; i++) expect((await send(body)).status).toBe(201);
37 expect(count()).toBe(10);
38 expect((await send(body)).status).toBe(429);
39 expect((await send("app=" + "x".repeat(300_000))).status).toBe(429);
40 expect(count()).toBe(10);
41 });
test/tab-share.test.ts added +101
@@ -0,0 +1,101 @@
1 /**
2 * An app from a tab as a read-only link (#18215): validated, stored, drawn escaped with no entries;
3 * what does not decode stores nothing; a cross-origin POST is refused.
4 */
5 import { afterAll, beforeAll, expect, test } from "bun:test";
6 import { mkdtemp, rm } from "node:fs/promises";
7 import { tmpdir } from "node:os";
8 import { join } from "node:path";
9 import { createApp, type App } from "../src/app.ts";
10 import { forgeHttp, type ForgeHttp } from "../src/http/server.ts";
11 import { compile } from "../src/tab/compile.ts";
12 import { handle, migrate, type TabDb } from "../src/tab/forge.ts";
13 import { KEPT, shareApp, sharedApp } from "../src/tab/share.ts";
14 import { TAB_LINK, tabLine } from "../src/tab/words.ts";
15 import { open } from "./support/tab-db.ts";
16 import { quietLogs } from "./helpers/globals.ts";
17
18 quietLogs();
19
20 let dir = "";
21 let app: App;
22 let http: ForgeHttp;
23 const count = () => Number((app.db.query("SELECT count(*) AS n FROM tab_shared").get() as { n: number }).n);
24 const send = (body: string, headers: Record<string, string> = {}) =>
25 http.handle(new Request("http://forge.test/tabforge-link", { method: "POST", body, headers: { "content-type": "application/x-www-form-urlencoded", origin: "http://forge.test", ...headers } }));
26 const form = (json: string) => new URLSearchParams({ app: json }).toString();
27
28 beforeAll(async () => {
29 dir = await mkdtemp(join(tmpdir(), "forge-tabshare-"));
30 app = createApp({ dataDir: dir, port: 0 });
31 http = forgeHttp(app);
32 });
33 afterAll(async () => {
34 http.close();
35 app.close();
36 await rm(dir, { recursive: true, force: true });
37 });
38
39 test("a valid app round-trips to a read-only page: escaped, headers on, no entries", async () => {
40 const made = compile("a shopping list").app;
41 const spec = JSON.stringify({ ...made, title: "<b>Mine</b>", blocks: made.blocks.map((b) => ({ ...b, placeholder: "x", entries: ["secret entry"] })) });
42 const res = await send(form(spec));
43 expect(res.status).toBe(201);
44 const link = /href="(http:\/\/forge\.test\/tabforge-link\/[A-Za-z0-9_-]{16})"/.exec(await res.text())![1]!;
45 const got = await http.handle(new Request(link));
46 expect(got.status).toBe(200);
47 const body = await got.text();
48 expect(body).toContain("&lt;b&gt;Mine&lt;/b&gt;");
49 expect(body).not.toContain("<b>Mine");
50 expect(body).not.toContain("secret entry");
51 expect(body).not.toContain("<form");
52 expect(got.headers.get("x-content-type-options")).toBe("nosniff");
53 expect(got.headers.get("content-security-policy")).toBeTruthy();
54 expect(got.headers.get("referrer-policy")).toBeTruthy();
55 });
56
57 test("a spec decodeApp refuses stores nothing", async () => {
58 const before = count();
59 expect((await send(form("not json"))).status).toBe(422);
60 expect((await send(form(JSON.stringify({ version: 99, blocks: [] })))).status).toBe(422);
61 expect((await send(form(JSON.stringify({ title: "x".repeat(30000) })))).status).toBe(413);
62 expect((await send("app=")).status).toBe(422);
63 expect(count()).toBe(before);
64 });
65
66 test("a cross-origin POST is refused and stores nothing", async () => {
67 const before = count();
68 const res = await send(form(JSON.stringify(compile("a journal").app)), { origin: "http://evil.test" });
69 expect(res.status).toBe(403);
70 expect(count()).toBe(before);
71 });
72
73 test("an unknown or malformed id is the forge's one 404", async () => {
74 const missing = await http.handle(new Request("http://forge.test/tabforge-link/AAAAAAAAAAAAAAAA"));
75 const bad = await http.handle(new Request("http://forge.test/tabforge-link/..%2f"));
76 expect(missing.status).toBe(404);
77 expect(bad.status).toBe(404);
78 });
79
80 test("past KEPT links the oldest go and a new link is still made", () => {
81 const db: TabDb = {
82 run: (sql, bind = []) => void app.db.query(sql).run(...bind),
83 all: (sql, bind = []) => app.db.query(sql).all(...bind) as Record<string, string | number>[],
84 };
85 const json = JSON.stringify(compile("count the laps").app);
86 const first = shareApp(db, json, "bucket-x", 1);
87 for (let i = 0; i < KEPT; i++) expect(shareApp(db, json, "bucket-x", 2 + i).ok).toBe(true);
88 expect(count()).toBe(KEPT);
89 expect(first.ok && sharedApp(db, first.id)).toBeFalsy();
90 });
91
92 test("the app's page offers 'Get a link' and the terminal says the same words", () => {
93 const db = open();
94 migrate(db);
95 handle(db, { method: "POST", path: "/apps", form: { say: "a shopping list" } }, 1);
96 const page = handle(db, { method: "GET", path: "/apps/1", form: {} }, 1).html;
97 expect(page).toContain('action="/tabforge-link"');
98 expect(page).toContain("Get a link");
99 expect(page).toContain(TAB_LINK.replace(/'/g, "&#39;"));
100 expect(tabLine()).toContain(TAB_LINK);
101 });

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

Keyboard shortcuts

Docs