§22 M3 frontend: /p/<project>/ routing, runtime branding, directory, 308s (v0.35.0)

Implements the M3-frontend slice of the §22 multi-project track, per
docs/superpowers/specs/2026-06-03-m3-frontend-design.md (design merged in
#10). Completes the runtime-config cut 0.33.0 (M3-backend Plan A) began.

Frontend:
- DeploymentProvider boots GET /api/deployment → {name, tagline,
  defaultProjectId, projects}; brandTitle() neutral 'RFC' pre-fetch fallback.
- /p/:projectId/* routing with generic /e/<slug> segment. ProjectLayout
  fetches /api/projects/:id, applies per-project theme (reset on switch),
  provides ProjectContext, guards the corpus (served only for the default;
  others get NotServedPlaceholder — decouples this slice from Plan B).
- Directory at / (2+ projects) with N=1 redirect into the single project;
  ProjectSwitcher in deployment chrome; entry-noun by project type.
- VITE_APP_NAME hard cut: removed from vite.config + index.html; the 6 brand
  reads now use deployment.name via context; static <title>RFC</title> + JS
  document.title. Internal /rfc·/proposals links → /p/<project>/e|proposals
  via lib/entryPaths.

Backend:
- GET /api/deployment returns default_project_id (the guard contract).
- Server-side 308s: /rfc/<slug>, /rfc/<slug>/pr/<n>, /proposals/<n> →
  /p/<default>/… . nginx (testing + prod) routes /rfc/ and /proposals/ to
  the backend.

Tests: 3 new backend redirect/deployment tests (438 pass); Vitest unit for
DeploymentProvider, ProjectLayout (theme/guard/404), Directory (11 pass);
clean build with no VITE_APP_NAME. Playwright e2e deferred until Tier-1 seeds
a registry (see CHANGELOG 0.35.0 step 5).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Ben Stull
2026-06-04 05:58:59 -07:00
parent 0252e40527
commit 999c4b65ef
39 changed files with 798 additions and 99 deletions
+8 -32
View File
@@ -1,40 +1,16 @@
import { defineConfig, loadEnv } from 'vite'
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
// In dev, the frontend runs on Vite's port and proxies the API
// (and /auth/*, /api/webhooks/*) to the FastAPI process.
// (and /auth/*) to the FastAPI process.
//
// VITE_APP_NAME is the user-visible name of this deployment — used in
// the browser tab title, the header brand, and the landing page H1.
// The framework intentionally ships no default: every deployment must
// supply its own name via `frontend/.env` so a fresh build never ships
// the wrong brand. See `frontend/.env.example`.
export default defineConfig(({ mode }) => {
const env = loadEnv(mode, process.cwd(), '')
const appName = env.VITE_APP_NAME
if (!appName || !appName.trim()) {
throw new Error(
'VITE_APP_NAME is required but not set. Copy frontend/.env.example to ' +
'frontend/.env and set VITE_APP_NAME=... before building. The framework ' +
'ships no default on purpose — each deployment names itself.'
)
}
// §22.9 (M3): the deployment name is NO LONGER a build-time value. It comes
// from GET /api/deployment at runtime (see src/context/DeploymentProvider.jsx),
// so a build needs no VITE_APP_NAME — the same bundle serves any deployment.
// The old build-time `throw` + `%VITE_APP_NAME%` HTML injection are removed.
export default defineConfig(() => {
return {
plugins: [
react(),
// Build-time HTML token substitution: `%VITE_APP_NAME%` inside
// `index.html` becomes the configured name. Vite already does this
// for env vars referenced as `%VITE_*%` in HTML, but we wire it
// explicitly so the failure mode (token left in title) is loud.
{
name: 'inject-app-name',
transformIndexHtml(html) {
return html.replace(/%VITE_APP_NAME%/g, appName)
},
},
],
plugins: [react()],
server: {
port: 5173,
proxy: {