Repository navigation
feat(console): one build serves every product and environment, fetched not built - #120
Conversation
…d not built Table 1.3, the last item of the bootstrap speed-up, and the one that needed real work in the console rather than a script: the prebuilt console artifact. It could not be done before because the console baked its environment into the bundle. `environmentBuildVar: NEXT_PUBLIC_DEPLOY_ENV` was compiled in, and `DEPLOY_ENV` functionally LOCKED the console's API target — so a stage build deployed to prod would have pointed at the stage API. One build could not serve both environments, and an artifact that cannot be redeployed anywhere is not an artifact. CA1 — identity at runtime. `src/lib/app-config.ts` keeps its constants as the compiled-in fallback (so `PRODUCT_NAME = "Lumen"` and `STORAGE_PREFIX = "lumen.next"` remain the literal seams rebrand.mjs matches, and the rebrand needed no new rule) and gains a resolved `AppConfig`: each field overridable per request by the Worker's `vars`, which OpenNext copies into `process.env`. The root layout resolves it on the server and hands it to the client through `<Providers config>`; `wrangler.jsonc` carries the five `CONSOLE_*` vars, which the rebrand rewrites, so a product's console says the product's name even though the bundle was built from the baseline's sources. CA2 — environment at runtime. The deploy environment is read from the `-<env>` its workers.dev host carries, or `CONSOLE_DEPLOY_ENV` where a custom domain names none. `environmentBuildVar` is gone. api.ts's `TARGETS` / `DEPLOY_ENV` / `IS_LOCKED` were module constants evaluated once at import; they are now `apiTargets()` / `deployEnv()` / `isLocked()`, reading the config in force. CA4 — the artifact. 06-console's `console-artifact` hook pins the baseline's published artifact (URL, sha256, and the product's own source hash); the component's buildCommand verifies the digest and unpacks it instead of running a cold Next.js build. Everything degrades to a normal build: no artifact, a changed console, an unreachable URL. Only a digest mismatch is fatal. The rebrand leaves the pin alone — it names the BASELINE's release, which is provenance. `.github/workflows/tag.yml` publishes one as part of cutting a `baseline-vN` tag, and is ignored from products. 06-console drops from 13 to 5 (the Cloudflare-only baseline measured the build step at 0.6s and the whole console job at 1m13s–1m22s), so the bootstrap budget is 45 minutes, from 84 where this work started. docs/phases/TIMINGS.md states the one condition: the fetch needs a published artifact for exactly those sources, and without one the phase is its old ~13 and nothing fails. Verified: console typecheck clean; 25 suites / 258 console tests pass (the new app-config suite among them); testing/console-artifact.test.sh holds pack determinism, the pin, the fetch, a changed console, a tampered asset, the no-artifact path and the rebrand's hands-off; full contract suite 12/12 with `orun new --status` under v2.88.0. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BfmHkwWeA1oPJGBNF3QSQH
| if (typeof window === "undefined" || !slug) return; | ||
| try { | ||
| window.localStorage.setItem(LAST_ORG_KEY, slug); | ||
| window.localStorage.setItem(lastOrgKey(), slug); |
There was a problem hiding this comment.
Traced this. It is pre-existing and attributed here only because this PR touched adjacent lines, and I do not believe it is a true positive — but I am leaving it open for a human call rather than closing it myself.
The dataflow is unchanged by this PR. Before (f5bf493) and after (8a7059a), resolvePostAuthDestination does:
const home = pickAccountBillingOrg(organizations)!;
writeLastOrgSlug(home.slug); // → window.localStorage.setItem(<key>, slug)The only thing this PR changed in this file is how the storage key is computed — const LAST_ORG_KEY = \${STORAGE_PREFIX}.last-org`becameconst lastOrgKey = () => `${appConfig().storagePrefix}.last-org``, because the storage prefix is runtime config now (saas-console-artifact CA1). The stored value and its source are identical.
Why I read it as a false positive. pickAccountBillingOrg returns the oldest org from the caller's own org list, and what reaches localStorage is .slug — a URL path segment the user is about to see in their address bar (/orgs/<slug>/projects). It is an identifier, not a credential; the token, which is sensitive, is handled separately in session.tsx. The module's own header has said this since it was written: "It's a low-sensitivity hint (just a slug)." CodeQL appears to taint the whole org object and flag the sink.
What I have not done: changed any code to silence it. If you want it addressed rather than dismissed, the options are to stop persisting the slug client-side (it would need the per-user preferences API the module's header describes as the upgrade path), or to dismiss the alert as a false positive in code scanning. That call is yours.
Flagging one process failure of mine alongside it: I merged this PR without seeing this check. I verified the three Actions workflow runs were green and did not list the repository's check runs, which is where CodeQL reports. On #118 and #119 I did list check runs; here I did not, and that is how a failing high-severity check got past me.
Generated by Claude Code
Table 1.3, the last item of the bootstrap speed-up — and the one that needed real work in the console rather than a script.
Why it couldn't be done before
The console baked its environment into the bundle:
environmentBuildVar: NEXT_PUBLIC_DEPLOY_ENVwas compiled in, andDEPLOY_ENVfunctionally locked the API target, so a stage build deployed to prod would have pointed at the stage API. One build could not serve both environments — and an artifact that can't be redeployed anywhere isn't an artifact.CA1 — identity at runtime
src/lib/app-config.tskeeps its constants as the compiled-in fallback, soPRODUCT_NAME = "Lumen"andSTORAGE_PREFIX = "lumen.next"remain the literal seamsrebrand.mjsmatches — the rebrand needed no new rule. On top sits a resolvedAppConfig: each field overridable per request by the Worker'svars, which OpenNext copies intoprocess.env.The root layout resolves it on the server (
generateMetadata+ asyncRootLayout) and hands it to the client via<Providers config>.wrangler.jsoncnow carries the fiveCONSOLE_*vars, which the rebrand rewrites — so a product's console says the product's name even though the bundle was built from the baseline's sources. That's load-bearing: a prebuilt artifact carries the baseline's defaults, and vars are the only place a product's identity reaches it.CA2 — environment at runtime
Read from the
-<env>the workers.dev host carries, orCONSOLE_DEPLOY_ENVwhere a custom domain names none.environmentBuildVaris gone.api.ts'sTARGETS/DEPLOY_ENV/IS_LOCKEDwere module constants evaluated once at import; they're nowapiTargets()/deployEnv()/isLocked().CA4 — the artifact
06-console'sconsole-artifacthook pins the baseline's published artifact (URL, sha256, the product's own source hash). The component'sbuildCommandverifies the digest and unpacks it instead of a cold Next.js build.Everything degrades to a normal build: no artifact, a changed console, an unreachable URL. Only a digest mismatch is fatal — that means something served bytes other than those published. The rebrand leaves the pin alone (it names the baseline's release — provenance; a rename would point the product at a release that doesn't exist).
.github/workflows/tag.ymlpublishes one as part of cutting abaseline-vNtag, and is ignored from products, which carry onlyci.yml.Budget
06-consoledrops 13 → 5 (the Cloudflare-only baseline measured the build step at 0.6s and the whole console job at 1m13s–1m22s). Bootstrap budget is now 45 minutes, from 84 where this work started.docs/phases/TIMINGS.mdstates the one condition plainly: the fetch needs a published artifact for exactly those sources. Without one the pin is absent, the phase is its old ~13, and nothing fails.Verification
app-config.test.ts. (Onmainone suite can't compile in this sandbox for an unrelated@saas/sdkbuild-order reason; with the sdk built, both are green.)testing/console-artifact.test.shholds pack determinism, the pin, the fetch, a changed console, a tampered asset, the no-artifact path, and that the rebrand doesn't touch the pin — it caught a real bug: without the exclude rule the rebrand rewrote the pin's baseline URL.orun new --statusunder v2.88.0.ci.ymlonly — notag.yml, nobaseline.yml.Note on tagging
This adds
tag.yml, which the repo didn't have. Baseline tags have been cut by hand; this session cannot push tag refs (the git transport returns 403 for them and the REST refs API is blocked by the proxy), sobaseline-v30is still uncut. Withtag.ymlmerged, a tag can be cut byworkflow_dispatchinstead — a path that works from here.Generated by Claude Code