Pick any line to see why it is the way it is: the commit, the pull request and issue it came from, and what the agent was thinking.
| Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put | 1 | import assert from "node:assert/strict"; |
| 2 | import { test } from "node:test"; | |
| 3 | ||
| 4 | import { type MissingKind, missingKind, notFoundCopy } from "./not-found.ts"; | |
| 5 | ||
| 6 | test("the kind a loader names wins over the address", () => { | |
| 7 | assert.equal(missingKind({ kind: "project" }, "/acme/web/blob/main/x"), "project"); | |
| 8 | assert.equal(missingKind({ kind: "pull" }, "/acme/web/pull/7"), "pull"); | |
| 9 | // Anything else a loader put there is ignored. | |
| 10 | assert.equal(missingKind({ kind: "secret" }, "/acme/web"), "project"); | |
| 11 | assert.equal(missingKind("Issue not found.", "/acme/web/issues/3"), "issue"); | |
| 12 | }); | |
| 13 | ||
| 14 | test("without one, the shape of the address decides", () => { | |
| 15 | const cases: [string, MissingKind][] = [ | |
| 16 | ["/acme", "workspace"], | |
| 17 | ["/acme/web", "project"], | |
| 18 | ["/acme/web/issues/12", "issue"], | |
| 19 | ["/acme/web/pull/12", "pull"], | |
| 20 | ["/acme/web/issues", "page"], | |
| 21 | ["/acme/web/settings", "page"], | |
| 22 | ["/acme/-/billing", "page"], | |
| 23 | ["/u/ada", "person"], | |
| 24 | ["/explore/nothing", "page"], | |
| 25 | ["/", "page"], | |
| 26 | ]; | |
| 27 | for (const [path, kind] of cases) assert.equal(missingKind(null, path), kind, path); | |
| 28 | }); | |
| 29 | ||
| status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas | 30 | const KINDS: MissingKind[] = ["project", "issue", "pull", "workspace", "page"]; |
| Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put | 31 | |
| status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas | 32 | test("signed out: nothing here, which may be private, and sign in if it is yours", () => { |
| 33 | for (const kind of KINDS) { | |
| Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put | 34 | const copy = notFoundCopy(kind, null); |
| status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas | 35 | assert.equal(copy.title, "Nothing here"); |
| 36 | assert.equal(copy.body, "This page doesn't exist, or it's private. Sign in if it's yours."); | |
| Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put | 37 | assert.equal(copy.signIn, true); |
| 38 | assert.equal(copy.signedInAs, null); | |
| 39 | } | |
| 40 | }); | |
| 41 | ||
| 42 | test("signed in: it does not exist or you cannot see it, and who you are", () => { | |
| status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas | 43 | for (const kind of KINDS) { |
| Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put | 44 | const copy = notFoundCopy(kind, "ada"); |
| status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas | 45 | assert.equal(copy.title, "Nothing here"); |
| 46 | assert.equal(copy.body, "This page doesn't exist, or you don't have access to it."); | |
| Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put | 47 | assert.equal(copy.signIn, false); |
| 48 | assert.equal(copy.signedInAs, "ada"); | |
| 49 | } | |
| 50 | }); | |
| 51 | ||
| 52 | test("a missing person is simply no one, signed in or not", () => { | |
| 53 | for (const viewer of [null, "ada"]) { | |
| 54 | const copy = notFoundCopy("person", viewer); | |
| status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas | 55 | assert.equal(copy.body, "No one on g1t goes by that name."); |
| Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put | 56 | assert.equal(copy.signIn, false); |
| 57 | } | |
| 58 | }); | |
| 59 | ||
| 60 | test("the page depends only on the kind and the viewer", () => { | |
| 61 | // The same inputs for a private project and a missing one: the loader | |
| 62 | // throws the same kind, at the same address, so the copy is identical. | |
| 63 | const privateOne = notFoundCopy(missingKind({ kind: "project" }, "/acme/secret"), null); | |
| 64 | const missingOne = notFoundCopy(missingKind({ kind: "project" }, "/acme/secret"), null); | |
| 65 | assert.deepEqual(privateOne, missingOne); | |
| 66 | }); |