-
Notifications
You must be signed in to change notification settings - Fork 0
[CEL-1364] DEV-only sign-in bypass + devLogin() store helper #15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
d801638
[CEL-1364] DEV-only sign-in bypass + devLogin() store helper
mong-x a34f347
refine(CEL-1364): tree-shaking verification test + unreachable-code c…
mong-x 574f96c
[CEL-1364] Review follow-ups: fail-closed portal guard + untrack deri…
mong-x 5a8e235
[CEL-1364] Review comments: inert test, missing catch, OTP/bypass rac…
mong-x File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,3 @@ | ||
| local/ | ||
| nodes.jsonl | ||
| edges.jsonl |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| import { fileURLToPath } from "node:url"; | ||
| import * as esbuild from "esbuild"; | ||
| import { describe, expect, it } from "vitest"; | ||
|
|
||
| /** | ||
| * CEL-1364 — build-output proof that the DEV-only sign-in bypass leaves | ||
| * production bundles. | ||
| * | ||
| * The behavioural tests in `login-form-dev-bypass.test.tsx` pin the RUNTIME | ||
| * conditional: with `import.meta.env.DEV` stubbed false, nothing renders. That | ||
| * is not the same claim. A refactor that reads the flag through an indirection | ||
| * the bundler cannot fold statically would keep those tests green while | ||
| * shipping the bypass UI to production. | ||
| * | ||
| * So this bundles `login-form.tsx` the way a consumer's Vite production build | ||
| * does — `import.meta.env.DEV` statically defined to `false`, tree-shaking on — | ||
| * and asserts the `DevSignInBypass` markup is absent from the emitted code, | ||
| * while the same bundle built with DEV=true contains it. Building both | ||
| * directions is what stops the assertion going inert if the sentinels drift. | ||
| * | ||
| * esbuild stands in for Rollup here: it applies the same `define` + DCE that | ||
| * makes the elision work, and it is already installed as the transform half of | ||
| * vitest's own toolchain. | ||
| * | ||
| * SCOPE — read before widening. Only the COMPONENT is statically eliminated. | ||
| * `readDevLoginEmail` / `rememberDevLoginEmail` / `DEV_LOGIN_EMAIL_STORAGE_KEY` | ||
| * are called from live function bodies behind runtime `if` guards, so they | ||
| * survive into production bundles as unreachable code. That is a handful of | ||
| * bytes and no behaviour (both are no-ops unless called), but it means the | ||
| * storage-key literal is NOT a valid sentinel for this test. | ||
| */ | ||
|
|
||
| const ROOT = fileURLToPath(new URL("..", import.meta.url)); | ||
|
|
||
| /** Strings that exist only inside `DevSignInBypass`. */ | ||
| const DEV_ONLY_MARKUP = ["Dev sign-in (skip the code)", "Development only"]; | ||
|
|
||
| /** Peers a consumer app supplies; irrelevant to what we are measuring. */ | ||
| const EXTERNALS = [ | ||
| "react", | ||
| "react/jsx-runtime", | ||
| "react-dom", | ||
| "lucide-react", | ||
| "input-otp", | ||
| "clsx", | ||
| "three", | ||
| "@react-three/fiber", | ||
| ]; | ||
|
|
||
| async function bundleLoginForm(dev: boolean): Promise<string> { | ||
| const result = await esbuild.build({ | ||
| entryPoints: [`${ROOT}src/react/login-form.tsx`], | ||
| bundle: true, | ||
| write: false, | ||
| format: "esm", | ||
| treeShaking: true, | ||
| jsx: "automatic", | ||
| define: { | ||
| "import.meta.env.DEV": String(dev), | ||
| "import.meta.env.PROD": String(!dev), | ||
| }, | ||
| external: EXTERNALS, | ||
| }); | ||
|
|
||
| return result.outputFiles[0].text; | ||
| } | ||
|
|
||
| describe("dev sign-in bypass tree-shaking (CEL-1364)", () => { | ||
| it("drops the bypass UI from a production bundle and keeps it in a dev one", async () => { | ||
| const [prod, dev] = await Promise.all([ | ||
| bundleLoginForm(false), | ||
| bundleLoginForm(true), | ||
| ]); | ||
|
|
||
| // Guards against a stale sentinel: if these strings ever stop existing, the | ||
| // production assertion below would pass for the wrong reason. | ||
| for (const marker of DEV_ONLY_MARKUP) { | ||
| expect(dev, `DEV bundle should contain ${JSON.stringify(marker)}`).toContain(marker); | ||
| } | ||
|
|
||
| for (const marker of DEV_ONLY_MARKUP) { | ||
| expect(prod, `PROD bundle must not contain ${JSON.stringify(marker)}`).not.toContain(marker); | ||
| } | ||
| }, 60_000); | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.