@milesroxas/design-hub 0.10.0 → 0.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (131) hide show
  1. package/README.md +13 -11
  2. package/core/files.test.ts +76 -0
  3. package/core/files.ts +131 -0
  4. package/core/prototype.test.ts +124 -7
  5. package/core/prototype.ts +133 -24
  6. package/core/review/model.ts +119 -2
  7. package/core/review/policy.test.ts +79 -22
  8. package/core/review/policy.ts +36 -8
  9. package/core/review/service.test.ts +1464 -340
  10. package/core/review/service.ts +777 -191
  11. package/core/review/store.test.ts +91 -0
  12. package/core/review/store.ts +143 -33
  13. package/dist/core/files.d.ts +39 -0
  14. package/dist/core/files.js +107 -0
  15. package/dist/core/prototype.d.ts +61 -12
  16. package/dist/core/prototype.js +105 -26
  17. package/dist/core/review/model.d.ts +76 -2
  18. package/dist/core/review/model.js +76 -1
  19. package/dist/core/review/policy.d.ts +11 -4
  20. package/dist/core/review/policy.js +14 -2
  21. package/dist/core/review/service.d.ts +197 -45
  22. package/dist/core/review/service.js +702 -192
  23. package/dist/core/review/store.d.ts +84 -31
  24. package/dist/core/review/store.js +66 -33
  25. package/dist/scripts/bootstrap.d.ts +4 -34
  26. package/dist/scripts/bootstrap.js +9 -244
  27. package/dist/scripts/cli.js +6 -0
  28. package/dist/scripts/client.d.ts +45 -0
  29. package/dist/scripts/client.js +320 -0
  30. package/dist/scripts/commands.js +6 -0
  31. package/dist/scripts/comments.d.ts +8 -26
  32. package/dist/scripts/comments.js +27 -14
  33. package/dist/scripts/lib/builds.d.ts +40 -0
  34. package/dist/scripts/lib/builds.js +198 -0
  35. package/dist/scripts/lib/cli.js +3 -1
  36. package/dist/scripts/lib/deploy.d.ts +6 -90
  37. package/dist/scripts/lib/deploy.js +24 -137
  38. package/dist/scripts/lib/dns.d.ts +49 -0
  39. package/dist/scripts/lib/dns.js +141 -0
  40. package/dist/scripts/lib/fake-host.d.ts +168 -0
  41. package/dist/scripts/lib/fake-host.js +244 -0
  42. package/dist/scripts/lib/host.d.ts +87 -0
  43. package/dist/scripts/lib/host.js +362 -0
  44. package/dist/scripts/lib/linked.d.ts +51 -0
  45. package/dist/scripts/lib/linked.js +124 -0
  46. package/dist/scripts/lib/names.d.ts +35 -0
  47. package/dist/scripts/lib/names.js +77 -0
  48. package/dist/scripts/lib/review.d.ts +23 -2
  49. package/dist/scripts/lib/review.js +32 -15
  50. package/dist/scripts/lib/studio-deps.d.ts +35 -0
  51. package/dist/scripts/lib/studio-deps.js +79 -0
  52. package/dist/scripts/lib/studios.d.ts +70 -0
  53. package/dist/scripts/lib/studios.js +187 -0
  54. package/dist/scripts/lib/update.d.ts +33 -0
  55. package/dist/scripts/lib/update.js +40 -0
  56. package/dist/scripts/lib/vercel.d.ts +1 -23
  57. package/dist/scripts/lib/vercel.js +6 -81
  58. package/dist/scripts/people.d.ts +7 -11
  59. package/dist/scripts/people.js +51 -46
  60. package/dist/scripts/preflight.d.ts +8 -1
  61. package/dist/scripts/preflight.js +36 -19
  62. package/dist/scripts/project.d.ts +86 -0
  63. package/dist/scripts/project.js +141 -0
  64. package/dist/scripts/share.d.ts +105 -30
  65. package/dist/scripts/share.js +82 -154
  66. package/dist/scripts/skills.d.ts +18 -2
  67. package/dist/scripts/skills.js +22 -3
  68. package/dist/scripts/studio.d.ts +75 -0
  69. package/dist/scripts/studio.js +401 -0
  70. package/dist/scripts/upgrade.d.ts +10 -2
  71. package/dist/scripts/upgrade.js +44 -14
  72. package/dist/server/api.d.ts +22 -11
  73. package/dist/server/api.js +114 -46
  74. package/dist/server/blob.d.ts +10 -0
  75. package/dist/server/blob.js +53 -0
  76. package/dist/server/checks.js +2 -2
  77. package/dist/server/dev.js +4 -4
  78. package/dist/server/env.d.ts +2 -0
  79. package/dist/server/env.js +9 -0
  80. package/dist/server/fake-upstash.js +52 -3
  81. package/dist/server/hosts.d.ts +11 -0
  82. package/dist/server/hosts.js +31 -0
  83. package/dist/server/local.d.ts +7 -1
  84. package/dist/server/local.js +10 -1
  85. package/dist/server/mark.d.ts +41 -0
  86. package/dist/server/mark.js +111 -0
  87. package/dist/server/session.d.ts +17 -9
  88. package/dist/server/session.js +22 -45
  89. package/dist/server/upstash.js +20 -0
  90. package/dist/vercel/files.d.ts +11 -0
  91. package/dist/vercel/files.js +68 -0
  92. package/dist/vercel/index.d.ts +4 -3
  93. package/dist/vercel/index.js +12 -8
  94. package/dist/vercel/proxy.d.ts +69 -4
  95. package/dist/vercel/proxy.js +171 -107
  96. package/dist/vite/plugin.d.ts +24 -1
  97. package/dist/vite/plugin.js +46 -2
  98. package/kit/dials.tsx +2 -2
  99. package/package.json +2 -1
  100. package/shell/Guide.tsx +11 -5
  101. package/shell/Index.tsx +32 -10
  102. package/shell/Notice.tsx +1 -1
  103. package/shell/controls.ts +1 -1
  104. package/shell/hub.ts +5 -1
  105. package/shell/main.tsx +18 -3
  106. package/shell/review/Review.tsx +2 -2
  107. package/shell/review/ThreadCard.tsx +5 -5
  108. package/shell/review/client.ts +28 -11
  109. package/shell/review/view.test.ts +19 -0
  110. package/shell/review/view.ts +25 -0
  111. package/shell/shell.css +4 -0
  112. package/shell/studio/ClientHub.tsx +98 -0
  113. package/shell/studio/hub.css +48 -0
  114. package/shell/studio/index.html +14 -0
  115. package/shell/studio/main.tsx +17 -0
  116. package/skills/miles-deploy/SKILL.md +120 -65
  117. package/skills/miles-design-hub/SKILL.md +11 -9
  118. package/skills/miles-review/SKILL.md +5 -7
  119. package/skills/miles-worktrees/SKILL.md +3 -3
  120. package/templates/conductor/settings.toml +1 -1
  121. package/templates/studio/.env.example +9 -0
  122. package/templates/studio/.vercelignore +5 -0
  123. package/templates/studio/README.md +84 -0
  124. package/templates/studio/_gitignore +7 -0
  125. package/templates/studio/api/files.ts +4 -0
  126. package/templates/studio/api/review.ts +4 -0
  127. package/templates/studio/build.mjs +4 -0
  128. package/templates/studio/package.json +16 -0
  129. package/templates/studio/proxy.ts +4 -0
  130. package/templates/studio/studio.json +9 -0
  131. package/templates/studio/vercel.json +27 -0
package/README.md CHANGED
@@ -10,9 +10,9 @@ design-hub guide <feature> # its walkthrough, docs/sprints/<feature>/guid
10
10
  design-hub commands # every command, with its flags, as JSON
11
11
  ```
12
12
 
13
- Inside the package, from the inside out: `core/` is the pure kernel (README states, the catalog, fixture sets, checks, the Jev client, the review domain); `kit/` the materials prototypes import; `shell/` the browser hub; `server/` the Node side (the review API, signed sessions, the stores, env and paths); `vite/` the plugin that turns a project into a Vite app; `vercel/` the deployed entries; `scripts/` the CLI; `templates/` what `new` copies; `skills/` what `skills` installs. `AGENTS.md` here holds the layers and their rules.
13
+ Inside the package, from the inside out: `core/` is the pure kernel (README states, the catalog, fixture sets, checks, the Jev client, the review domain); `kit/` the materials prototypes import; `shell/` the browser hub; `server/` the Node side (the review API, signed sessions, the stores, env and paths); `vite/` the plugin that turns a project into a Vite app; `vercel/` the studio site's entries; `scripts/` the CLI; `templates/` what `new` copies; `skills/` what `skills` installs. `AGENTS.md` here holds the layers and their rules.
14
14
 
15
- How a project becomes an app: `design-hub dev` runs Vite with the package's `shell/` as the root and the project as the content. `vite/registry.ts` writes `virtual:design-hub/registry` from the project's `prototypes/` and `docs/sprints/`; `vite/kit.ts` resolves `@kit/<name>` to the project's `kit/<name>` first and the package's second. The sections below describe the hub's own interface and the deployed site; they are the reference for changing the package, not for using it.
15
+ How a project becomes an app: `design-hub dev` runs Vite with the package's `shell/` as the root and the project as the content. `vite/registry.ts` writes `virtual:design-hub/registry` from the project's `prototypes/` and `docs/sprints/`; `vite/kit.ts` resolves `@kit/<name>` to the project's `kit/<name>` first and the package's second. The sections below describe the hub's own interface and the studio site; they are the reference for changing the package, not for using it.
16
16
 
17
17
  ## The index
18
18
 
@@ -70,27 +70,29 @@ A speculation rule in `shell/index.html` prefetches a prototype's page when its
70
70
 
71
71
  `/guide/<feature>/` is `docs/sprints/<feature>/guide.md`, rendered for reviewers who have a sign-in link but not the repo; `/guide/` alone opens the only guide, or lists them. The registry plugin lists the guides, so a new feature's walkthrough appears the moment the file exists (`design-hub guide <feature>` starts one from `templates/guide.md`). The Markdown stays the one source: a Vite plugin (`vite/markdown.ts`, the `?doc` import) compiles it at build time with `marked`, so nothing is parsed in the browser. It turns the first H1 into the title, every H2 and H3 into the contents rail, each image into a figure with its pixel size (no layout shift, lazy below the first), and `> [!NOTE]` quotes into callouts. A paragraph that starts `Controls → …` renders as a click path. Links to other Markdown files lose their href, since nothing serves them. The page reads at 16px on a 680px measure; screenshots and tables take the full 960px column, because a 1440px shot at 680px is unreadable. Two raw values: a screenshot wears a 1px inset outline at 10% (black on light, white on dark) and a callout a 6% ring (8% on dark), alphas rather than tokens because they composite on any surface the page is set on. The slug `guide` is the hub's (`design-hub new guide` refuses it). The page's **Open the prototype** button goes to the feature's sprint prototype, and every prototype of the feature answers with **Open the walkthrough** as the last row of Controls, under every group, in a new tab, so a reviewer reads and clicks side by side. Above it, on every prototype, **All prototypes** goes back to `/` in the same tab. A sheet inside the product was rejected: it would be modal over the thing under review, and testing aids never sit in the product chrome.
72
72
 
73
- ## Deploying, and signing in
73
+ ## The studio site, and signing in
74
74
 
75
- `miles-deploy` owns the steps; this is what they rest on. `design-hub signin` starts `vercel login`'s device sign-in in the background and returns its link, so the user clicks instead of typing. `design-hub bootstrap --vercel <project>` links the project, connects it to the `origin` repo when Vercel can reach it, turns Vercel Authentication off and sets the env. `design-hub share` runs the pre-flight, then deploys: a push of a clean production branch when the project is connected to the repo (following the build for that commit), else `vercel deploy --prod`; then it requests the production URL as a signed-out browser and fails unless the sign-in page answers with `noindex` and a link no store holds answers 404, which proves the review store is wired (503 means there is none, so nobody could sign in). Every path on the deployed site sits behind the gate, enforced on the server by Vercel Routing Middleware (`vercel/proxy.ts`, exported as `createProxy` and default-exported by the project's one-line `proxy.ts`, which `vercel.json` names as `proxy.entrypoint`). A client-side gate was rejected because the bundle and the state behind it would still download.
75
+ `miles-deploy` owns the steps; this is what they rest on. A project has no deployment of its own. A **studio** is one site on one hosting account, with one database (Upstash for Redis), one private file store (Vercel Blob), one `GATE_SECRET` and one apex domain, that serves every client of the studio; two studios share none of these. Its folder, made by `design-hub studio create` from `templates/studio/`, is thin like a project: one-line `proxy.ts`, `api/review.ts` and `api/files.ts` from `./vercel`, a `vercel.json`, a `studio.json` (id, slug, apex, team, DNS; no secret) and a gitignored `.env`. A machine finds its studios by slug in `~/.design-hub/studios.json`. `design-hub signin` starts `vercel login`'s device sign-in in the background and returns its link, so the user clicks instead of typing.
76
76
 
77
- Every person is named, and signs in with a one-time link that Studio makes in the review panel's People tab or with `design-hub people add`.
77
+ A client's address is `<client>.<apex>` (or a codename under the apex, `client add --host`), and a project is `/<project>/` below it. `design-hub project link` writes `.design-hub/studio.json` in the project (studio, its id, client, project; committed). `design-hub share` builds the project with base `/<project>/`, uploads `dist/` under `c/<client>/<project>/<build>/` in the file store with a new random build id, checks every file is there, and only then points the project's record at that build, so a half-finished upload is never served; the live build and the two before it are kept. Every path on every client's host sits behind the gate, enforced on the server by Vercel Routing Middleware (`createStudioProxy` in `vercel/proxy.ts`, which the studio's `vercel.json` names as `proxy.entrypoint`). The host names the client, from one store lookup kept a minute per instance; a host no client has is the plain 404 before anything else is read. The files function and the review function run the gate's checks again themselves, in the order host, session, project, so neither trusts anything the gate set. A client-side gate was rejected because the bundle and the state behind it would still download.
78
+
79
+ Every person is named, and signs in with a one-time link that Studio makes in the review panel's People tab, with `design-hub people add` in a linked project, or, for a client's first person and the owner, with `design-hub client add`. A link signs in on its client's host only.
78
80
 
79
81
  - **A link works once.** `GET /invite/<token>` shows who it is for and a Continue button, and uses nothing up, since mail and chat previews open links too. Continue is a same-origin `POST` that uses the link up, sets the session cookie and goes to `/`. The use is atomic: the store's delete is the claim, so of two requests with one link only the one whose delete removed it signs in. A used, expired or unknown link answers 404, as does a link for someone revoked or past their access end. An unused link lasts 14 days. The store keeps only a hash of each token (32 random bytes), so a read of the store signs nobody in.
80
82
  - **A second device gets a second link** (`design-hub people link <id>`), and the first stays signed in. **Sign out everywhere** (`people sign-out <id>`) bumps the person's epoch, drops their unused links and returns one new link. **Revoke** ends their access everywhere.
81
83
  - **What a stale write cannot undo.** A person is a profile (name, team, kind, access end), written read-modify-write, plus two records only revoke and sign out everywhere touch: the revocation, written once and never cleared, and the epoch, raised only by `HINCRBY`. So a profile change that started before a revoke or a sign out everywhere and lands after it never clears the revocation or lowers the epoch, and two sign outs everywhere at once raise it twice.
82
- - **Access lasts the engagement.** Each person has an access end: 3 months, 6 months, or open-ended. The project default (`people access --access <length>`, or `bootstrap --review --access`) applies to a new Client and is 3 months when unset; a new Studio person is open-ended, and Studio can set one person's length from the People tab or `people access <id>`.
83
- - **The session** is one cookie, `__Host-hub_person`: `HttpOnly`, `Secure`, `SameSite=Lax`, signed with HMAC-SHA256 over the person, their epoch, their kind (Studio or Client), an expiry, `checkedAt` (when the store last said yes) and the review store's URL, which is signed but never written into the token, so two projects that share a `GATE_SECRET` never accept each other's cookies, and versioned (`p4`), so a cookie from an older release never verifies. The one exception is `p3`, the version before the kind: a valid one still passes, read as stale, so the next request asks the store and re-issues it as `p4`, and nobody is signed out by the upgrade. It lasts to the access end, at most 400 days, the longest a browser keeps one. For `CHECK_SECONDS` (5 minutes) after `checkedAt` any request passes on the signature. After that the next request, of any kind, asks the store: a current person passes with a fresh cookie whose expiry follows their current access end; a revoked, signed-out-everywhere or ended person gets 401 and the cookie cleared. The request's own headers never decide whether the store is asked, since the client chooses them. A store that fails answers 503 with `Retry-After`, and leaves the cookie, so an outage signs nobody out; the review panel reads `Retry-After` as try again, and a 503 without it as a site with no store. The API function answers the same way in JSON. The sign-in POST also refuses a store failure with 503, and a link is checked before it is used up, so a failure never burns one.
84
+ - **Access lasts the engagement.** Each person has an access end: 3 months, 6 months, or open-ended. A new Client gets their client's default (`client access <client>`), else the studio's (`client access` with no client), else 3 months; a new Studio person is open-ended, and Studio can set one person's length from the People tab or `people access <id>`.
85
+ - **The session** is one cookie, `__Host-hub_person`: `HttpOnly`, `Secure`, `SameSite=Lax`, host-only. Its token is `p5.<id>.<epoch>.<kind>.<client>.<expires>.<checkedAt>.<sig>`, signed with HMAC-SHA256 over all of those and over two things it never carries: the review store's URL, so two studios that share a `GATE_SECRET` never accept each other's cookies, and when the client was added, so a slug archived and added again accepts no token from before. A token verifies only on its own client's host, a Studio person's too. Any other version never verifies. It lasts to the access end, at most 400 days, the longest a browser keeps one. For `CHECK_SECONDS` (5 minutes) after `checkedAt` any request passes on the signature. After that the next request, of any kind, asks the store: a current person passes with a fresh cookie whose expiry follows their current access end; a revoked, signed-out-everywhere or ended person gets 401 and the cookie cleared. The request's own headers never decide whether the store is asked, since the client chooses them. A store that fails answers 503 with `Retry-After`, and leaves the cookie, so an outage signs nobody out; the review panel reads `Retry-After` as try again. The API function answers the same way in JSON. The sign-in POST also refuses a store failure with 503, and a link is checked before it is used up, so a failure never burns one. The hub reads any 401, the gate's plain text or the API's JSON, as signed out.
84
86
  - **The link page** sends `Referrer-Policy: same-origin`, so Continue's POST carries a real `Origin` (with `no-referrer` a browser sends `Origin: null`, trusted only beside `Sec-Fetch-Site`, which older Safari does not send). Every other gate response sends `no-referrer`.
85
- - **Internal prototypes.** Everything built from `prototypes/<slug>/` (its README, code, CSS, fixtures, lazy chunks and images) lands under `/_p/<slug>/`, its entry at `/_p/<slug>/entry.js`, and Studio's list of every slug at `/_p/all.js`; the shared bundle in `/assets/` names no prototype's folder (`vite/registry.ts`, `vite/boundary.ts`, `vite/settle.ts`; the build fails if a file breaks that). The exception is the walkthroughs: their compiled text and every feature's name sit in `/assets/` and reach every signed-in person, so a walkthrough must not name or describe internal work until that is built. A built file is owned by where its content comes from, never by who reads it, and each source is recorded as the file is written (`vite/settle.ts`): a stylesheet's CSS modules, an asset's original files, a worker's output; a file with no record and no fixed name fails the build. Nothing a prototype owns is inlined by the size limit, and nothing under `prototypes/` is ever the hub's: a file directly there, or in a folder without a README, is refused (shared code belongs in `kit/`). Any import or `new URL` (`?inline` included) into a prototype its importer does not own is refused in dev and in a build. Every stylesheet is read for reaches inside Vite's postcss run (`vite/css-boundary.ts`), each reference followed as a path and through Vite's own resolvers (aliases and package paths included); Sass, Less and Stylus are refused in prototypes and the project's `kit/`, since their imports resolve inside the preprocessor; and every worker bundle refuses a module under `prototypes/` and resolves `@kit/*`. After the bundle is settled the build reads what it wrote (`vite/leaks.ts`): a file outside `/_p/<slug>/` that holds a whole file of `prototypes/<slug>/` (its bytes, a base64 or SVG data URI of it anywhere in the file, or, for a file the build read, its whole text as a string in a script; 40 bytes or more) fails the build, unless the reader's owner has a source with the same content. It is a backstop for whole-file inlining: no part of a file (a line, a rule) is looked for. Vite is pinned to 8.3 (`~8.3.5`) because the boundary leans on its internals; `vite/build.test.ts` is what to run on a Vite upgrade. A file a prototype owns lives in its folder; the hub's and the kit's live in `/assets/` and are never copied into a prototype's folder; the same bytes from several owners become one copy per owner, each named from its owner's source. A file that reads what another prototype owns, or a hub or kit file that reads what a prototype owns, fails the build, naming both. A prototype that reaches into another (an import, a CSS `@import` or `url()`, a `new URL`) or starts a web worker fails the build. A Client asking for a prototype's page (`/<slug>/`) or anything under `/_p/<slug>/` gets 404 unless that prototype is client-facing, asked of the store on every such request; `/_p/all.js` is always 404 to a Client, and an internal prototype and one that does not exist answer byte for byte the same. A path that could mean more than one file (a `.` or `..` segment, a backslash, an empty segment, a `%` left after decoding, or one that does not decode) gets the same 404, as does any first segment that is not `/`, the hub's own (`assets`, `api`, `guide`, `_gate`, `index.html`, `favicon.svg`), `_p` or a prototype slug. A Client's comments on a prototype that is not client-facing answer as if it had none. Studio passes on the cookie's kind with no store read. `/`, `/assets/*`, `/guide/*` and `/api/*` pass as before. `guide`, `api` and `assets` are never a prototype's slug (`core/prototype.ts`).
87
+ - **Internal prototypes.** Everything built from `prototypes/<slug>/` (its README, code, CSS, fixtures, lazy chunks and images) lands under `/_p/<slug>/`, its entry at `/_p/<slug>/entry.js`, and Studio's list of every slug at `/_p/all.js`; the shared bundle in `/assets/` names no prototype's folder (`vite/registry.ts`, `vite/boundary.ts`, `vite/settle.ts`; the build fails if a file breaks that). The exception is the walkthroughs: their compiled text and every feature's name sit in `/assets/` and reach every signed-in person, so a walkthrough must not name or describe internal work until that is built. A built file is owned by where its content comes from, never by who reads it, and each source is recorded as the file is written (`vite/settle.ts`): a stylesheet's CSS modules, an asset's original files, a worker's output; a file with no record and no fixed name fails the build. Nothing a prototype owns is inlined by the size limit, and nothing under `prototypes/` is ever the hub's: a file directly there, or in a folder without a README, is refused (shared code belongs in `kit/`). Any import or `new URL` (`?inline` included) into a prototype its importer does not own is refused in dev and in a build. Every stylesheet is read for reaches inside Vite's postcss run (`vite/css-boundary.ts`), each reference followed as a path and through Vite's own resolvers (aliases and package paths included); Sass, Less and Stylus are refused in prototypes and the project's `kit/`, since their imports resolve inside the preprocessor; and every worker bundle refuses a module under `prototypes/` and resolves `@kit/*`. After the bundle is settled the build reads what it wrote (`vite/leaks.ts`): a file outside `/_p/<slug>/` that holds a whole file of `prototypes/<slug>/` (its bytes, a base64 or SVG data URI of it anywhere in the file, or, for a file the build read, its whole text as a string in a script; 40 bytes or more) fails the build, unless the reader's owner has a source with the same content. It is a backstop for whole-file inlining: no part of a file (a line, a rule) is looked for. Vite is pinned to 8.3 (`~8.3.5`) because the boundary leans on its internals; `vite/build.test.ts` is what to run on a Vite upgrade. A file a prototype owns lives in its folder; the hub's and the kit's live in `/assets/` and are never copied into a prototype's folder; the same bytes from several owners become one copy per owner, each named from its owner's source. A file that reads what another prototype owns, or a hub or kit file that reads what a prototype owns, fails the build, naming both. A prototype that reaches into another (an import, a CSS `@import` or `url()`, a `new URL`) or starts a web worker fails the build. A Client asking for a prototype's page (`/<project>/<slug>/`) or anything under `/<project>/_p/<slug>/` gets 404 unless that prototype is client-facing, asked of the store on every such request; `/<project>/_p/all.js` is always 404 to a Client, and an internal prototype and one that does not exist answer byte for byte the same. Below a project, any first segment that is not the hub's own (`assets`, `api`, `guide`, `_gate`, `index.html`, `favicon.svg`), `_p` or a prototype slug gets the same 404. A path that could mean more than one file (a `.` or `..` segment, a backslash, a control character, an empty segment, a `%` left after decoding, or one that does not decode) goes nowhere for anyone, Studio included. Another client's project, and a project with no build, are the same 404, its review API too. A Client's comments on a prototype that is not client-facing answer as if it had none. Studio passes on the cookie's kind with no audience read. The client's hub at `/` and a project's `/assets/*`, `/guide/*` and review API pass on the session alone. `invite`, `api`, `_gate`, `_p`, `assets`, `guide`, `index.html` and `favicon.svg` are never a prototype's slug (`RESERVED` in `core/prototype.ts`).
86
88
  - **Signed out**, a page gets the sign-in page (401). It has no form: it says to open the link the studio sent, that each link signs in one device and then stops working, and to ask the studio for a new one for another device. Anything else gets a plain-text 401, an anonymous `POST` included.
87
89
 
88
- The middleware reads one environment variable, set in the Vercel project for Production and Preview and never committed (`.env.example` names it): `GATE_SECRET`, at least 32 random characters that sign the session cookie. With it missing the gate answers 503 on every path, so a misconfigured deploy never serves the prototypes open. People and links live in the review store, so a site without it has a gate nobody can pass. The gate pages ship a hash-based Content Security Policy with no `unsafe-inline` and no script, plus `font-src 'self'` and `img-src 'self'`, and send no referrer. They wear the hub's neutral look in Geist, so two files pass the gate without a session: `/_gate/geist.woff2` (the latin subset, emitted by `vite/plugin.ts` at that fixed path) and `/favicon.svg`. Nothing else does. Every response carries `X-Robots-Tag: noindex`, so no search engine lists the site. The pages' title is the `siteName` the project's `proxy.ts` passes to `createProxy`. Under `design-hub dev` there is no gate; `/_gate/` previews the sign-in page, `?page=link` a link's page and `?page=used` a used one.
90
+ The studio site reads its env from the Vercel project, never committed: `GATE_SECRET`, at least 32 random characters that sign the session cookie, and the database's and file store's credentials, which `studio create` sets and copies into the studio folder's `.env` (`templates/studio/.env.example` names them). With the secret or the database missing, every host answers 503 "This site is not set up yet.", which names no command, studio or client, so a misconfigured site never serves anything open. The gate pages ship a hash-based Content Security Policy with no `unsafe-inline` and no script, plus `font-src 'self'` and `img-src 'self'`, and send no referrer. They wear the hub's neutral look in Geist, so two files pass the gate without a session: `/_gate/geist.woff2` (the latin subset, emitted at that fixed path) and `/favicon.svg`. Nothing else does. Every response carries `X-Robots-Tag: noindex`, so no search engine lists the site. The signed-out page names no client. Under `design-hub dev` there is no gate; `/_gate/` previews the sign-in page, `?page=link` a link's page and `?page=used` a used one.
89
91
 
90
92
  ## Comments and people
91
93
 
92
94
  Every signed-in person can comment as themselves. The People tab lists each person with their team, kind and when their access ends, and says how links behave where Studio shares them.
93
95
 
94
- The panel (`shell/review/`) mounts on every prototype page in its own React root, so a prototype that throws never takes it down. A comment carries the prototype, the URL, every dial panel's values (`snapshotDials`), and the element it was pinned to as a selector path with an offset; Show state reopens the URL and sets the dials back. Pins draw over their elements and below the Controls panel. The API is one endpoint, `/api/review` (`server/api.ts`, reached on Vercel through the project's one-line `api/review.ts`, which also bundles the project's `checks.json` so triage runs on its thresholds): queries by GET, commands by POST with a JSON body, same-origin only. The rules (who may delete, what a valid comment is) live once, in `core/review/`, behind a small storage port: Upstash Redis over REST when deployed, a file in `.design-hub/review.json` under `design-hub dev`, where whoever runs the server is a local Studio person.
96
+ The panel (`shell/review/`) mounts on every prototype page in its own React root, so a prototype that throws never takes it down. A comment carries the prototype, the URL, every dial panel's values (`snapshotDials`), and the element it was pinned to as a selector path with an offset; Show state reopens the URL and sets the dials back. Pins draw over their elements and below the Controls panel. The API is one endpoint, `<project>/api/review` (`server/api.ts`, reached on a studio site through its one-line `api/review.ts`, scoped by the host's client and the project the path names): queries by GET, commands by POST with a JSON body, same-origin only. The rules (who may delete, what a valid comment is, which client a person may act in) live once, in `core/review/`, behind a small storage port: the studio's Upstash Redis over REST, or a file in `.design-hub/review.json` under `design-hub dev`, where whoever runs the server is a local Studio person in one fixed scope. Every key is built by one function from a scope, under the prefix `hub4:`: the studio's (`studio:people`, `clients`, `hosts`, …), a client's (`c:<client>:people`, `:links`, `:projects`, …) and a project's (`c:<client>:p:<project>:comments:<prototype>`, …), so no op reaches another client's records.
95
97
 
96
- `design-hub dev` serves the prototypes open, with the review panel on the local store. The gate is covered by `pnpm test` (`vercel/proxy.test.ts`, against an in-memory Upstash); `vercel dev` in a project runs it for real.
98
+ `design-hub dev` serves the prototypes open, with the review panel on the local store. The gate and the studio's functions are covered by `pnpm test` (`vercel/proxy.test.ts`, against an in-memory Upstash and file store).
@@ -0,0 +1,76 @@
1
+ import assert from 'node:assert/strict';
2
+ import { test } from 'node:test';
3
+ import { buildPrefix, clientPrefix, filePath, isBuildId, memoryFiles, typeOf } from './files.ts';
4
+
5
+ const A = { client: 'acme', project: 'rebrand' };
6
+ const BUILD = 'k3f9q2x7m1z8c4v6';
7
+
8
+ test('a file’s path is its client’s, its project’s and its build’s, from checked parts only', () => {
9
+ assert.equal(buildPrefix(A, BUILD), `c/acme/rebrand/${BUILD}/`);
10
+ // A client's own folder ends in a slash, so it never takes in acme-co's.
11
+ assert.equal(clientPrefix('acme'), 'c/acme/');
12
+ assert.ok(buildPrefix(A, BUILD).startsWith(clientPrefix('acme')));
13
+ assert.equal(filePath(A, BUILD, ['_p', 'plan', 'entry.js']), `c/acme/rebrand/${BUILD}/_p/plan/entry.js`);
14
+ assert.equal(filePath(A, BUILD, ['caf é.png']), `c/acme/rebrand/${BUILD}/caf é.png`);
15
+ // The names a build emits: hashed, dotted, dashed and underscored, and what a person names an image.
16
+ for (const name of [
17
+ 'Notice-B7Z_eR-a.css',
18
+ 'sample-social-BhnQuwv-.js',
19
+ 'geist-latin-wght-normal-BgDaEnEv.woff2',
20
+ 'logo@2x.png',
21
+ 'Q&A (v2), final+1.png',
22
+ ])
23
+ assert.equal(filePath(A, BUILD, ['assets', name]), `c/acme/rebrand/${BUILD}/assets/${name}`);
24
+ const bad: [string, () => string][] = [
25
+ ['a client that is reserved', () => buildPrefix({ client: 'studio', project: 'rebrand' }, BUILD)],
26
+ ['a client folder for a reserved name', () => clientPrefix('www')],
27
+ ['a client folder for no slug', () => clientPrefix('')],
28
+ ['a client folder with a slash', () => clientPrefix('acme/../bravo')],
29
+ ['no project', () => buildPrefix({ client: 'acme' }, BUILD)],
30
+ ['a project with a slash', () => buildPrefix({ client: 'acme', project: 'a/b' }, BUILD)],
31
+ ['a short build', () => buildPrefix(A, 'b1')],
32
+ ['a build with a slash', () => buildPrefix(A, `${BUILD}/x`)],
33
+ ['no file', () => filePath(A, BUILD, [])],
34
+ ['a .. segment', () => filePath(A, BUILD, ['..', 'other', 'x.js'])],
35
+ ['an empty segment', () => filePath(A, BUILD, ['assets', '', 'x.js'])],
36
+ ['a slash in a segment', () => filePath(A, BUILD, ['a/../../b'])],
37
+ ['a backslash', () => filePath(A, BUILD, ['a\\\\b'])],
38
+ ['a tab a URL parser drops', () => filePath(A, BUILD, ['.\t.', 'other', 'x.js'])],
39
+ ['a newline', () => filePath(A, BUILD, ['.\n.', 'x.js'])],
40
+ ['a carriage return', () => filePath(A, BUILD, ['.\r.', 'x.js'])],
41
+ ['a ? that cuts the URL', () => filePath(A, BUILD, ['x.js?y'])],
42
+ ['a # that cuts the URL', () => filePath(A, BUILD, ['x.js#y'])],
43
+ ['a % left in a name', () => filePath(A, BUILD, ['%2e%2e', 'x.js'])],
44
+ ['a space at an end', () => filePath(A, BUILD, ['x.js '])],
45
+ ];
46
+ for (const [what, build] of bad) assert.throws(build, /Not a file path/, what);
47
+ assert.equal(isBuildId(BUILD), true);
48
+ for (const id of ['', 'b1', 'A'.repeat(16), 'a'.repeat(65), 7])
49
+ assert.equal(isBuildId(id), false, String(id));
50
+ });
51
+
52
+ test('a file is stored with the type its name says', () => {
53
+ assert.equal(typeOf('index.html'), 'text/html; charset=utf-8');
54
+ assert.equal(typeOf('_p/x/entry.js'), 'text/javascript; charset=utf-8');
55
+ assert.equal(typeOf('_gate/geist.WOFF2'), 'font/woff2');
56
+ assert.equal(typeOf('assets/brand.ttf'), 'font/ttf');
57
+ assert.equal(typeOf('assets/brand.otf'), 'font/otf');
58
+ assert.equal(typeOf('assets/brief.pdf'), 'application/pdf');
59
+ assert.equal(typeOf('sitemap.xml'), 'application/xml');
60
+ assert.equal(typeOf('site.webmanifest'), 'application/manifest+json');
61
+ assert.equal(typeOf('LICENSE'), 'application/octet-stream');
62
+ assert.equal(typeOf('x.constructor'), 'application/octet-stream');
63
+ });
64
+
65
+ test('the in-memory store keeps what is put, never overwrites, and lists by prefix', async () => {
66
+ const files = memoryFiles();
67
+ const bytes = new TextEncoder().encode('hello');
68
+ await files.put('c/acme/a/1', bytes, 'text/plain');
69
+ await files.put('c/acme-co/a/1', bytes, 'text/plain');
70
+ await assert.rejects(files.put('c/acme/a/1', bytes, 'text/plain'), /never overwritten/);
71
+ assert.deepEqual(await files.get('c/acme/a/1'), { body: bytes, type: 'text/plain' });
72
+ assert.equal(await files.get('c/acme/a/2'), null);
73
+ assert.deepEqual(await files.list('c/acme/'), ['c/acme/a/1']);
74
+ await files.remove(['c/acme/a/1', 'c/acme/none']);
75
+ assert.deepEqual(await files.list('c/'), ['c/acme-co/a/1']);
76
+ });
package/core/files.ts ADDED
@@ -0,0 +1,131 @@
1
+ // The files port: where a studio keeps every project's builds. A build is
2
+ // uploaded under `c/<client>/<project>/<build>/…`, and the studio site serves
3
+ // the one the project's record points at (`Project.build`). Production is a
4
+ // private Vercel Blob store (server/blob.ts); tests use the in-memory store
5
+ // below. Every path is built here, from checked parts, so no request can name
6
+ // a file outside its own client and project.
7
+ import { isClientSlug, isProjectSlug, isSegment } from './prototype.ts';
8
+ import type { Scope } from './review/model.ts';
9
+
10
+ /** A file's bytes as the store hands them, and the type it was stored with. */
11
+ export type StoredFile = { body: ReadableStream<Uint8Array> | Bytes; type: string };
12
+ type Bytes = Uint8Array<ArrayBuffer>;
13
+
14
+ export interface Files {
15
+ /** Writes a file that is not there yet. A build's paths are never overwritten. */
16
+ put(path: string, body: Bytes, type: string): Promise<void>;
17
+ /** The file and its type, or null when there is none. */
18
+ get(path: string): Promise<StoredFile | null>;
19
+ /** Every path that starts with `prefix`. A scope's prefix ends in `/`, so `c/acme/` never lists `c/acme-co/`. */
20
+ list(prefix: string): Promise<string[]>;
21
+ /** Removes these paths; one that is not there is no error. */
22
+ remove(paths: string[]): Promise<void>;
23
+ }
24
+
25
+ /**
26
+ * A build's id: random, lower-case letters and digits, and never used twice
27
+ * for the life of the store, so a path never comes back with other bytes.
28
+ */
29
+ const BUILD_ID = /^[a-z0-9]{16,64}$/;
30
+ export const isBuildId = (v: unknown): v is string => typeof v === 'string' && BUILD_ID.test(v);
31
+
32
+ function checked(ok: boolean, what: string, v: unknown): void {
33
+ // A bad part is a bug in the caller, never input to answer: fail closed before any store call.
34
+ if (!ok) throw new Error(`Not a file path: ${what} is ${JSON.stringify(v)}.`);
35
+ }
36
+
37
+ /** A file inside a build, as a list of path segments, each one `isSegment`: the rule the studio gate reads a path by. */
38
+ const isFile = (segments: readonly string[]) => segments.length > 0 && segments.every(isSegment);
39
+
40
+ /**
41
+ * Removes every file under a prefix, in the store's batches of 1,000, and
42
+ * says how many there were. Takes a prefix one of the functions below built,
43
+ * so it never reaches past its scope.
44
+ */
45
+ export async function clearPrefix(files: Files, prefix: string): Promise<number> {
46
+ const paths = await files.list(prefix);
47
+ await removeAll(files, paths);
48
+ return paths.length;
49
+ }
50
+
51
+ /** Removes these paths, in the store's batches of 1,000. */
52
+ export async function removeAll(files: Files, paths: string[]): Promise<void> {
53
+ for (let i = 0; i < paths.length; i += 1000) await files.remove(paths.slice(i, i + 1000));
54
+ }
55
+
56
+ /** Every file of one client, every project and build: what archiving the client removes. Ends in `/`. */
57
+ export function clientPrefix(client: string): string {
58
+ checked(isClientSlug(client), 'client', client);
59
+ return `c/${client}/`;
60
+ }
61
+
62
+ /** Every build of one project, ending in `/`, so `c/acme/rebrand/` never lists `c/acme/rebrand-2/`. */
63
+ export function projectPrefix(scope: Scope): string {
64
+ checked(isClientSlug(scope.client), 'client', scope.client);
65
+ checked(isProjectSlug(scope.project), 'project', scope.project);
66
+ return `c/${scope.client}/${scope.project}/`;
67
+ }
68
+
69
+ /** The folder of one build of a project, ending in `/`. */
70
+ export function buildPrefix(scope: Scope, build: string): string {
71
+ const prefix = projectPrefix(scope);
72
+ checked(isBuildId(build), 'build', build);
73
+ return `${prefix}${build}/`;
74
+ }
75
+
76
+ /** One file of one build: `c/<client>/<project>/<build>/<file>`, with `file` given as its segments. */
77
+ export function filePath(scope: Scope, build: string, file: readonly string[]): string {
78
+ checked(isFile(file), 'file', file);
79
+ return `${buildPrefix(scope, build)}${file.join('/')}`;
80
+ }
81
+
82
+ const TYPES: Record<string, string> = {
83
+ html: 'text/html; charset=utf-8',
84
+ js: 'text/javascript; charset=utf-8',
85
+ mjs: 'text/javascript; charset=utf-8',
86
+ css: 'text/css; charset=utf-8',
87
+ json: 'application/json',
88
+ webmanifest: 'application/manifest+json',
89
+ map: 'application/json',
90
+ md: 'text/markdown; charset=utf-8',
91
+ txt: 'text/plain; charset=utf-8',
92
+ xml: 'application/xml',
93
+ pdf: 'application/pdf',
94
+ svg: 'image/svg+xml',
95
+ png: 'image/png',
96
+ jpg: 'image/jpeg',
97
+ jpeg: 'image/jpeg',
98
+ gif: 'image/gif',
99
+ webp: 'image/webp',
100
+ avif: 'image/avif',
101
+ ico: 'image/x-icon',
102
+ woff2: 'font/woff2',
103
+ woff: 'font/woff',
104
+ ttf: 'font/ttf',
105
+ otf: 'font/otf',
106
+ mp4: 'video/mp4',
107
+ webm: 'video/webm',
108
+ wasm: 'application/wasm',
109
+ };
110
+
111
+ /** The type a built file is stored with, from its extension. */
112
+ export function typeOf(path: string): string {
113
+ const ext = path.match(/\.([a-z0-9]+)$/i)?.[1]?.toLowerCase() ?? '';
114
+ return Object.hasOwn(TYPES, ext) ? TYPES[ext] : 'application/octet-stream';
115
+ }
116
+
117
+ /** The files port in memory, for tests and for a studio run on one machine. */
118
+ export function memoryFiles(): Files {
119
+ const files = new Map<string, StoredFile>();
120
+ return {
121
+ put: async (path, body, type) => {
122
+ if (files.has(path)) throw new Error(`${path} exists; a build's paths are never overwritten.`);
123
+ files.set(path, { body, type });
124
+ },
125
+ get: async (path) => files.get(path) ?? null,
126
+ list: async (prefix) => [...files.keys()].filter((p) => p.startsWith(prefix)).sort(),
127
+ remove: async (paths) => {
128
+ for (const p of paths) files.delete(p);
129
+ },
130
+ };
131
+ }
@@ -1,18 +1,45 @@
1
1
  import assert from 'node:assert/strict';
2
2
  import { test } from 'node:test';
3
- import { ALL_FILE, entryFile, isPrototypeSlug, probeEntry, prototypeOfPath, RESERVED } from './prototype.ts';
3
+ import {
4
+ ALL_FILE,
5
+ entryFile,
6
+ hostName,
7
+ isClientSlug,
8
+ isProjectSlug,
9
+ isPrototypeSlug,
10
+ probeEntry,
11
+ RESERVED,
12
+ RESERVED_CLIENTS,
13
+ routeOf,
14
+ } from './prototype.ts';
4
15
 
5
- test('a prototype slug is kebab-case and never one of the hub’s own paths', () => {
6
- assert.deepEqual([...RESERVED], ['guide', 'api', 'assets']);
7
- for (const reserved of RESERVED) assert.equal(isPrototypeSlug(reserved), false);
16
+ test('a prototype or project slug is kebab-case and never a first segment the gate answers', () => {
17
+ assert.deepEqual(
18
+ [...RESERVED],
19
+ ['invite', 'api', '_gate', '_p', 'assets', 'guide', 'index.html', 'favicon.svg'],
20
+ );
21
+ for (const reserved of RESERVED) {
22
+ assert.equal(isPrototypeSlug(reserved), false, reserved);
23
+ assert.equal(isProjectSlug(reserved), false, reserved);
24
+ }
8
25
  assert.equal(isPrototypeSlug('sample-list'), true);
26
+ assert.equal(isProjectSlug('rebrand'), true);
9
27
  for (const bad of ['_p', 'Sample', 'a_b', '', 'a.js', 'a/b', null, 3])
10
28
  assert.equal(isPrototypeSlug(bad), false);
11
29
  assert.equal(entryFile('sample-list'), '_p/sample-list/entry.js');
12
30
  assert.equal(ALL_FILE, '_p/all.js');
13
31
  });
14
32
 
15
- test('a path names its prototype, or none for the hub’s own', () => {
33
+ test('a client slug is kebab-case and never the studio’s own host names', () => {
34
+ assert.deepEqual([...RESERVED_CLIENTS], ['studio', 'www', 'api']);
35
+ for (const reserved of RESERVED_CLIENTS) assert.equal(isClientSlug(reserved), false, reserved);
36
+ assert.equal(isClientSlug('acme'), true);
37
+ // A prototype's reserved names are no concern of a host's.
38
+ assert.equal(isClientSlug('guide'), true);
39
+ for (const bad of ['Acme', 'a_b', 'a:b', '', 'a.b', null, 3]) assert.equal(isClientSlug(bad), false);
40
+ });
41
+
42
+ test("below a project, a path names its prototype, null for the hub’s own, or '' for nothing a Client may have", () => {
16
43
  const cases: [string, string | null][] = [
17
44
  ['/', null],
18
45
  ['/assets/index-abc.js', null],
@@ -22,7 +49,8 @@ test('a path names its prototype, or none for the hub’s own', () => {
22
49
  ['/_gate/geist.woff2', null],
23
50
  ['/index.html', null],
24
51
  ['/robots.txt', ''],
25
- ['/invite/short', 'invite'],
52
+ // A link path the gate does not answer is no prototype's and no hub path: refused to a Client.
53
+ ['/invite/short', ''],
26
54
  ['/Sample-List/', ''],
27
55
  ['/_p;x/secret/entry.js', ''],
28
56
  ['/_p./secret/entry.js', ''],
@@ -60,7 +88,7 @@ test('a path names its prototype, or none for the hub’s own', () => {
60
88
  ['/%73ample-list/', 'sample-list'],
61
89
  ['/%E0%A4%A/', ''],
62
90
  ];
63
- for (const [path, owner] of cases) assert.equal(prototypeOfPath(path), owner, path);
91
+ for (const [path, owner] of cases) assert.equal(ownerBelow(path), owner, path);
64
92
  });
65
93
 
66
94
  test('an entry is there on a JavaScript 200, not there on a 404 or the host’s page, and an error otherwise', async () => {
@@ -81,3 +109,92 @@ test('an entry is there on a JavaScript 200, not there on a 404 or the host’s
81
109
  await assert.rejects(probeEntry('/_p/a/entry.js', answer(status)), new RegExp(`answered ${status}`));
82
110
  assert.deepEqual(asked[0], ['/_p/a/entry.js', { method: 'HEAD', credentials: 'same-origin' }]);
83
111
  });
112
+
113
+ test('a host is a lookup key: lower case, no port, no trailing dot, or none at all', () => {
114
+ assert.equal(hostName('Acme.Studio.test:443'), 'acme.studio.test');
115
+ assert.equal(hostName('acme.studio.test.'), 'acme.studio.test');
116
+ for (const host of ['', 'localhost', 'a b.test', 'acme..test', 'acme.test/x', `${'a'.repeat(250)}.test`])
117
+ assert.equal(hostName(host), '', host);
118
+ });
119
+
120
+ const H = 'acme.studio.test';
121
+ const route = (path: string) => {
122
+ const { host, ...where } = routeOf(H, path);
123
+ assert.equal(host, H);
124
+ return where;
125
+ };
126
+
127
+ /** What a path below project `rebrand` belongs to: a prototype, the hub (null), or '' when it goes nowhere. */
128
+ function ownerBelow(path: string): string | null {
129
+ const where = route(`/rebrand${path}`);
130
+ if (where.kind === 'file') return where.prototype;
131
+ return where.kind === 'api' ? null : '';
132
+ }
133
+
134
+ test('a studio path goes to the link, the gate’s assets, the client’s hub, a function, or a project', () => {
135
+ const token = 'a'.repeat(43);
136
+ assert.deepEqual(route(`/invite/${token}`), { kind: 'link', token });
137
+ assert.deepEqual(route(`/invite/${token}/`), { kind: 'link', token });
138
+ for (const path of ['/_gate/geist.woff2', '/favicon.svg']) assert.deepEqual(route(path), { kind: 'asset' });
139
+ for (const path of ['/', '/index.html', '/assets/hub-x.js', '/_gate/other.woff2'])
140
+ assert.deepEqual(route(path), { kind: 'hub' }, path);
141
+ for (const path of ['/api/review', '/api/files'])
142
+ assert.deepEqual(route(path), { kind: 'api', project: null }, path);
143
+ assert.deepEqual(route('/rebrand/api/review'), { kind: 'api', project: 'rebrand' });
144
+ assert.deepEqual(route('/rebrand/'), { kind: 'file', project: 'rebrand', file: [], prototype: null });
145
+ assert.deepEqual(route('/rebrand'), { kind: 'file', project: 'rebrand', file: [], prototype: null });
146
+ assert.deepEqual(route('/rebrand/assets/index-x.js'), {
147
+ kind: 'file',
148
+ project: 'rebrand',
149
+ file: ['assets', 'index-x.js'],
150
+ prototype: null,
151
+ });
152
+ assert.deepEqual(route('/rebrand/_p/plan/entry.js'), {
153
+ kind: 'file',
154
+ project: 'rebrand',
155
+ file: ['_p', 'plan', 'entry.js'],
156
+ prototype: 'plan',
157
+ });
158
+ assert.deepEqual(route('/rebrand/plan/'), {
159
+ kind: 'file',
160
+ project: 'rebrand',
161
+ file: ['plan'],
162
+ prototype: 'plan',
163
+ });
164
+ assert.deepEqual(route('/rebrand/_p/all.js').kind, 'file');
165
+ assert.equal((route('/rebrand/_p/all.js') as { prototype: string }).prototype, 'all.js');
166
+ assert.equal((route('/rebrand/caf%C3%A9.png') as { file: string[] }).file[0], 'café.png');
167
+ });
168
+
169
+ test('anything else on a studio host goes nowhere: odd paths, the reserved names, and any host that is no name', () => {
170
+ for (const path of [
171
+ '/invite/short',
172
+ '/invite/',
173
+ '/guide/x/',
174
+ '/_p/plan/entry.js',
175
+ '/api/other',
176
+ '/api/review/x',
177
+ '/rebrand/api/files',
178
+ '/rebrand/api/review/x',
179
+ '/Rebrand/',
180
+ '/robots.txt',
181
+ '/rebrand/..%2fother/x.js',
182
+ '/rebrand//x.js',
183
+ '/rebrand/%255Fp/x',
184
+ '/rebrand%5cx',
185
+ '/%E0%A4%A/',
186
+ '/rebrand/assets/.%09./_p/all.js',
187
+ '/rebrand/assets/.%0A./_p/x/entry.js',
188
+ '/rebrand/assets/.%0D./x.js',
189
+ '/rebrand/assets/x.js%3Fy',
190
+ '/rebrand/assets/x.js%23y',
191
+ '/rebrand/assets/%20x.js',
192
+ '/rebrand/assets/x.js%20',
193
+ '/rebrand/assets/x%E2%80%AE.js',
194
+ ])
195
+ assert.deepEqual(route(path), { kind: 'none' }, path);
196
+ // A path that could mean more than one file is refused below a project too, so its prototype is ''.
197
+ assert.equal((route('/rebrand/_P/plan/x.js') as { prototype: string }).prototype, '');
198
+ for (const host of ['', 'localhost', 'a b'])
199
+ assert.deepEqual(routeOf(host, '/rebrand/'), { host: '', kind: 'none' }, host);
200
+ });