Repository navigation
refactor(preview): keep the preview credential out of the embed graph - #218
Conversation
The embedded `<sahaj-atlas>` element shipped the code that spends SahajCloud's live-preview credential, though no host page can open a session. #215 closed the session's writer list to `boot.ts`; this closes the other half. `applyRequestContext` now ends in one named decorator slot instead of a preview branch. `config/live-preview/request.ts` holds the decorator, standalone-only, and `boot.ts` registers it on the line that flips `active` — before the flip, in the same synchronous step, so no request can see an open session with an empty slot. **Moving `LIVE_PREVIEW_HEADER` is the part that makes this real.** `protocol.ts` is in both entry graphs on purpose, so a constant left there keeps the wire name in every host's bundle, and a writer needs nothing else. It lives beside the one decorator that sets it now. A slot, not a list: only one decorator will ever exist, a list would make iteration order an implicit contract, and a named setter keeps "who can spend this credential" a one-hit grep. `Widget.standalone.test.ts` gains three assertions — the graph walk over `request.ts`, a closed importer list for it, and a scan of the widget entry's graph for the header literal, read off the real constant so a rename cannot make it vacuous. Each was driven red at its causing site: the constant back in `protocol.ts`, and `client.ts` importing the decorator directly. The two specs that assert the credential now register the real decorator in setup. Without that they assert an absence and stay green against a seam that never fires; dropping the registration turns all four header assertions red. This trades an impossible failure for a silent one. A standalone session whose registration is dropped previews published content and says nothing — the retargeted specs and the two `/admin` checks stand in for the compiler. Refs #217. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01TecGGqBhAjFnCuoC3eevCH
Review-pass follow-ups on the same change. `Widget.standalone.test.ts` had three near-identical importer scans and grew a fourth. `importersOf` replaces two of them under one `describe.each`, and the module paths are named constants, so `STANDALONE_ONLY` stops being half a source of truth. A `read` helper matches the idiom the other scanning specs already use. Net: one fewer full pass over `src/`. The session-writer docblock still argued from the threat this change removed — that a widget-graph write would send a CMS credential. It cannot any more. The gate is still worth closing, because such a write opens a session on a host page we do not own: inert links, snapped-back navigation, a refused registration. That is now its whole justification, so it says so. One fact — request.ts is standalone-only, and why — was stated in eleven places. Kept where it is load-bearing, cut where it was restatement. No ⚠ line and no breadcrumb was dropped. Refs #217. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01TecGGqBhAjFnCuoC3eevCH
`Widget.standalone.test.ts` proves the widget's `src/` graph does not reach the credential header. This proves it of the bytes a host downloads, which is the claim that actually matters. Neither check subsumes the other, and both failure modes are real. A constant parked in a shared module with no reader is tree-shaken, so it reaches the spec and not the bundle. And the standalone and embed graphs DO share chunks — unlike the loader/embed pair this script already guards — so a decorator moved into one of them would ship while a source-level resolver saw nothing wrong. Rebuilding the pre-#217 state puts the header in `Spinner-*.js`, a chunk both entries import. The literal is duplicated into the script, as `src/loader/literals.ts` is and for the same reason: a gate that imported the string from `src/` would be reading the thing it is checking. The positive arm keeps that honest — if the name stops appearing in the standalone graph, the negative arm has gone vacuous and says so rather than passing. Refs #217. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01TecGGqBhAjFnCuoC3eevCH
Deploying sahajatlas-design with
|
| Latest commit: |
b7072f6
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://6d0af5ff.sahajatlas-design.pages.dev |
| Branch Preview URL: | https://claude-refactor-217-preview.sahajatlas-design.pages.dev |
Deploying sahajatlas with
|
| Latest commit: |
b7072f6
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://0869ae39.sahajatlas.pages.dev |
| Branch Preview URL: | https://claude-refactor-217-preview.sahajatlas.pages.dev |
|
🤖 no session running recent dispatchesWritten by the sydevs dispatcher. Sessions never edit this comment. |
sydevs-bot
left a comment
There was a problem hiding this comment.
🧐 Adversarial review
The diff is the size of its ticket and stays inside it. A one-slot seam is the smallest shape that takes the header name out of the embed graph, and the three alternatives the body dismisses are dismissed correctly. The wire literal is unchanged, so SahajCloud's CORS allowlist and Cache Rule still match, and no request changes — skipping CHANGELOG.md is right.
The body names the real judgement: an impossible failure traded for a silent one. The one line that prevents the silent one is asserted by nothing.
Findings
should-fix—boot.ts:156, the production wiring, is unpinned.consider—check-bundle-size.mjs:373: its stated non-overlap is not the one that holds.consider—Widget.standalone.test.ts:230overclaims.
What was checked
Ticket #217 against all 11 files. Read whole: client.ts, request.ts, boot.ts, protocol.ts, Widget.standalone.test.ts, main(), activateLivePreview. Grepped for the literal and the setter: one definition, one production caller, one activation path.
🤖 Written by the sydevs autonomous loop — see what this is
Generated by Claude Code
`boot.ts` registers the preview decorator on the line before it flips `active`, and nothing read that line. Five activation cases exercised the function without touching the slot, and both retargeted specs register the decorator by hand in setup — so deleting the registration left the whole lane green while a verified reviewer silently previewed published content. Two cases, because the line makes two claims. The first drives a verified activation and then runs `applyRequestContext`: delete the registration and it goes red naming the missing header. The second re-opens the session by hand after a REFUSED token and expects no header, which pins the registration below the `if (!verified)` early return — the decorator's own gate would answer that case whether the slot was filled or not, so the gate is stepped around deliberately. The slot is module state, so it is reset in `beforeEach`. Without that, one case's registration answers the next and both go vacuous. Ordering within the synchronous step stays unasserted: the two statements are adjacent and nothing can interleave between them in-process. What the cases hold is that the registration happens, and that it happens after the verify. Refs #217. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_0127SJVrtgNiRBJWyyH8Y7Rt
The session-writer docblock said a widget-graph write "can no longer send anything" because `request.ts` sits outside that graph. That overclaimed. `client.ts` exports `setPreviewRequestDecorator` and IS in that graph, and the header is a 30-character string anyone can spell — so one module there could fill the slot itself. The slot was empty by absence, not by structure. A closed caller list makes it structural: within the widget graph, only the module DEFINING the setter may name it. The docblock now argues from that list rather than from a reachability the setter does not have. Not covered by the header scan beside it. Driven red with a widget-graph module re-attaching the credential through a header name assembled by `join`: the header scan stays green, and this is the only assertion that fires. Refs #217. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_0127SJVrtgNiRBJWyyH8Y7Rt
The comment justified the embed-graph header scan against `Widget.standalone.test.ts` with "the standalone and embed graphs do share chunks, so a move of the decorator into one of them is invisible to the spec". That is not a gap. Rolldown puts a module in a chunk `embed.js` loads only where `Widget.tsx` reaches it, which is exactly the reachability the spec walks — so stated that way the arm looked redundant. The real non-overlap runs both ways. The spec's resolver follows only our own `.ts`/`.tsx` files, a package specifier resolving to nothing there by design, so a carrier arriving from a dependency reaches the bytes unseen. And `importClosure` here is static, so a carrier behind a dynamic import is absent from these bytes and caught only by the spec, whose walk follows `import()`. The tree-shaking leg was already right and is unchanged. Comment and guide only — no arm changed. The wrong argument is kept as a ⚠ line so it is not re-derived. Refs #217. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_0127SJVrtgNiRBJWyyH8Y7Rt
|
Three adversarial-review threads, all adopted — one commit each, pushed as de3e43f.
Gate green: lint, typecheck, 1567 tests. 🤖 Written by the sydevs autonomous loop — see what this is Generated by Claude Code |
Ardnived
left a comment
There was a problem hiding this comment.
Take a step back and look for ways to radically simplify our approach to this feature in a way that eliminates the amount of code. Look for simpler ways to also smooth out the implementation and make it simple, robust, and easy to understand
…client.ts The seam #217 needs is "the embed graph carries neither the header name nor the code that spends it". A dedicated slot in `client.ts` bought that with a type, a module-level binding, an exported setter, and a second closed list in `Widget.standalone.test.ts` to keep the setter from being called. `livePreview` is already a mutable singleton in both graphs with a closed WRITER list, asserted since before this branch. Moving the decorator onto it as `decorateRequest` reuses both: one list now guards opening a session and spending its credential, and every `Object.assign(livePreview, LIVE_PREVIEW_INACTIVE)` — in production's refusal path and in four specs' teardown — disarms the credential for free instead of needing a paired `setPreviewRequestDecorator(null)`. What that deletes: the `RequestDecorator` export and slot from `client.ts` (its diff against main is now one call line), the setter, the setter's caller-list arm, and six teardown lines. `client.ts` exports nothing new. `request.ts` keeps the header and the decorator, and stays out of the embed graph. `readLivePreviewParams` returns the field null, so capture disarms and only a verified activation arms — the same fail-closed gap capture and activation already had. Refs #217. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01Sp12Sh1UK6sPPdYS3QyyK2
This arm was the one change on this branch beyond #217's acceptance criteria, and it was flagged as such when it landed. Criterion 3 asks for a source-level scan, which `src/Widget.standalone.test.ts` does: it walks the real import graph, static and dynamic, and names the module at fault. What this arm caught that the spec cannot is one case — a carrier arriving from a dependency, invisible to a resolver that follows only our own `.ts`/`.tsx` files. No dependency spells SahajCloud's private header, and the shape that would make one do so is not a shape a size gate should be the first to notice. 54 lines of script plus its own positive control, for that. The AGENTS.md paragraph describing it goes with it, so the gate's description keeps matching the script. Refs #217. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01Sp12Sh1UK6sPPdYS3QyyK2
|
Simplified in two commits for your review.
Net +324/−69 → +253/−70: one fewer file, gate arm and closed list. Declined: merging Both commits revert independently. Gate green: lint, typecheck, 1566 tests, build. Size unmoved at 295.1 / 2.6 / 296.9 KiB. 🤖 Written by the sydevs autonomous loop — see what this is Generated by Claude Code |
Summary
<sahaj-atlas>element no longer carries the code that spends SahajCloud's live-preview credential, nor the header name it spends it under.applyRequestContextends in one nullable call —livePreview.decorateRequest.config/live-preview/request.tsholds the decorator and is standalone-only.Changes
src/config/api/client.ts— the preview branch becomeslivePreview.decorateRequest?.(url, headers), called last. Nothing new is exported.src/config/live-preview/request.ts— new.LIVE_PREVIEW_HEADERand the one decorator that sets it, gate included.src/config/live-preview/protocol.ts— losesLIVE_PREVIEW_HEADER, gains thedecorateRequestfield and the erased type it is declared with. Stays in both graphs:AppandRegistrationFormread the session to select restraints, and a restraint is not the credential.src/config/live-preview/boot.ts— hangs the decorator off the session immediately before flippingactive. Capture sets the field null, so it disarms.src/config/live-preview/boot.test.ts— pins that registration, in both directions.src/Widget.standalone.test.ts— the header scan of the widget graph, each standalone-only module's closed importer list, and the session's closed writer list.docs/rules/data-layer.md,docs/architecture.md,AGENTS.md— the seam, step 6, the layout line.Preview
Branch alias: https://claude-refactor-217-preview.sahajatlas.pages.dev (the latest commit is still deploying). Nothing here is visible: no UI, no route, and no host-observable behaviour changed, so there is nothing to deep-link. Ladle is unaffected.
Contract impact
None. The requests the embedded widget makes are byte-identical, no origin or CSP entry changed, and no attribute was added. Per
CHANGELOG.md's own rule — it records only what a host can observe — this gets no entry anddocs/embedding.mdis unchanged.Test results
pnpm lint && pnpm typecheck && pnpm test:run— 122 files, 1566 testspnpm build(incl.assert:css,assert:maps)pnpm size: ✓ standalone 295.1 / 308, loader 2.6 / 3.5, embed 296.9 / 308 KiB. Identical to a build oforigin/mainmeasured on this machine — all three graphs, to 0.1 KiB, and unmoved by either review pass. The under-budget arm is unmoved.b7072f6:x-sahajcloud-preview-secretappears in exactly one emitted file,assets/main-*.js, whichpnpm sizescores understandaloneand not underembed.Manual verification
Both need a real SahajCloud session — neither is reachable from a spec.
/admin→ Sahaj Atlas → Translations: an unpublished string still renders. This proves the credential still rides the standalone read./admin→ an Event → live preview: a title edit still lands on screen. This proves the populate request still carries the header.Notes for reviewer
The change trades an impossible failure for a silent one, and that is the judgement worth checking. Today the branch cannot fire in a host page because nothing there writes the session. After this, the branch is not in that graph at all — but a standalone session whose registration is dropped previews published content and says nothing. The retargeted specs and the two checks above stand in for the compiler. The ticket's open question (a dev-only warning for an active session with no decorator) is not implemented — it asks for a decision nobody has made, and none of the acceptance criteria need it.
The simplification pass is
ab09890andb7072f6, and each is separately revertable.ab09890moves the decorator onto the session.livePreviewwas already a mutable singleton in both graphs with a closed writer list, asserted before this branch existed. Reusing it deleted a type export, a module binding, a setter, the setter's own closed caller list, and six teardown lines — andclient.ts's diff againstmainis now one call line. One list guards opening a session and spending its credential, and everyObject.assign(livePreview, LIVE_PREVIEW_INACTIVE)disarms the credential for free.The cost, stated plainly:
client.tsnames a live-preview field again, where the slot version was feature-neutral. It importedlivePreviewonmaintoo, so no module enters the embed graph that was not already there — but if the generic slot is worth its extra parts, revert this commit and the rest of the branch stands.b7072f6deletes thepnpm sizearm, which was the one change on this branch beyond the acceptance criteria. Criterion 3 asks for a source-level scan, andWidget.standalone.test.tsis it. The arm's one unique gap was a carrier arriving from a dependency; no dependency spells SahajCloud's private header, and 54 lines of script plus a positive control is a lot to hold that. TheAGENTS.mdparagraph describing it went with it.Dismissed findings, each with a reason:
boot.tsmodule scope instead of insideactivateLivePreview. Simpler, and the decorator self-gates, so it would be safe. Declined: the ticket specifies registration after verification, and it is a second independent condition guarding a credential. Worth overruling me if you disagree — it would delete an ordering rule that exists only as prose.LIVE_PREVIEW_HEADERinfetch.test.tsinstead of spelling the literal. Declined: those four literals are the only place anything pins the wire name to its actual value.Widget.standalone.test.tsreads it off the constant, so importing it here would leave nothing asserting the string SahajCloud's CORS allowlist matches on.Considered and not taken: merging
request.tsintoboot.ts, which would drop a module and inheritboot.ts's pre-existing exclusion from the widget graph. It costs more than it saves.request.tsis a leaf, so three specs and the header scan read the wire name off it without pulling inclient.tsand i18next; viaboot.tseach would needvi.mocklines it does not have today.Out of scope, noticed on the way:
docs/testing.md's "keep the lane under ~5s" is stale — the lane measures 20.1s on this branch, and 22.3s onmain. Not filed as a ticket; it is one number in a doc, and it is here so it is not lost.Detail
Driving each assertion red, at the site that caused it (
docs/testing.md):protocol.tsprotocol.tsrequest.tsrequest.tsunreachable fromWidget.tsxclient.tsimports the decoratorrequest.ts's closed importer listclient.tsapplyRequestContextboot.tsif (!verified)The last two were re-driven on
ab09890's shape, against the session field rather than the slot. The first attempt at the oldpnpm sizeleak arm did not fire: an unusedexport constinprotocol.tsis tree-shaken, so it never reached the bytes. That was the reason both checks existed — the source scan catches a parked constant, the artifact scan catches a shipped one — andb7072f6weighs that one remaining case against the arm's cost.Why a field on the session and not a slot of its own. One decorator will ever exist, so a list would make iteration order an implicit contract for no gain, and
applyRequestContextstays the one place cross-cutting context attaches. Given that, the field is smaller than a slot: it needs no setter and no second guard. A review pass also considered threading the decorator as an argument and splittingclient.tsper entry; the first needs a factory plus a shared instance holder (module-level mutable state again, by a longer path), and the second duplicates auth and locale, the one thingdocs/rules/data-layer.mdinsists exists once.A security review found nothing at confidence ≥ 8 on the slot version. What
ab09890changes about its findings: the gate still fails closed (livePreview.active && livePreview.tokenis unmoved, and the one production write sits afteractivateLivePreview'sif (!verified)early return), andcapturenow writes the field null, so a second token arriving mid-session cannot inherit the first one's decorator. The decorator re-reads the singleton rather than closing over a token, so a never-cleared field is inert. Reachability from the embedded surface is now a property ofrequest.tsalone, sinceclient.tsexports nothing to call.No import cycle.
request.tstakes both the session and the erased type fromprotocol.ts, andclient.tsimports only the session, as it did onmain.Docs swept:
docs/rules/data-layer.md(the seam, plusrequest.tsadded to itspaths:so the rule loads there),docs/architecture.md(step 6), the rootAGENTS.md(thelive-preview/layout line).docs/testing.md,docs/environment.mdanddocs/rules/i18n-and-state.mdmentionapplyRequestContextbut say nothing this change makes stale.Commit order.
c9ec1eeis the change;7b5bbe8folds three near-identical importer scans into one helper and cuts the prose where one fact was stated in eleven places;cc5d10b,8b171c5andde3e43fanswer the adversarial review one thread each;ab09890andb7072f6are the simplification pass above.8b171c5's closed caller list is gone with the setter it guarded, and its finding — a widget-graph write could spell the 30-character header itself — is now carried by the session's writer list.Closes #217
🤖 Written by the sydevs autonomous loop — see what this is