Repository navigation
chore: add code quality tooling (Biome + Knip) and apply formatting - #2
Merged
Merged
Conversation
- Add Biome 2.4.6 for linting and formatting - Add Knip for dead code detection - Add scripts: lint, lint:fix, lint:unused, format, format:fix, check - Configure biome.json with recommended rules (noExplicitAny off, noDangerouslySetInnerHtml off for framework needs) - Configure knip.json to detect unused exports Made-with: Cursor
- Auto-format all source files with Biome (import ordering, consistent spacing, trailing commas) - Fix duplicate else-if condition in generate-schema.ts (line 185: nullable string branch was unreachable because the non-nullable string branch above already matched) All checks pass: tsc --noEmit, biome check, knip Made-with: Cursor
There was a problem hiding this comment.
1 issue found across 40 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="src/sdk/instrumentedFetch.ts">
<violation number="1" location="src/sdk/instrumentedFetch.ts:122">
P1: `instrumentFetch` ignores the `originalFetch` argument and always uses `globalThis.fetch`, so custom client fetch behavior is bypassed.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
|
🎉 This PR is included in version 0.16.0 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
hugo-ccabral
added a commit
that referenced
this pull request
Aug 21, 2026
…s) (#494) Rollout **item B** of the PLP ranking experiments design ([`04_engineering/platform/experiments/README.md`](https://github.com/decocms/context/blob/main/04_engineering/platform/experiments/README.md) in `context`). Companion doc PR publishing the signature for item C: decocms/context#683 ## What this does Extracts the sticky-assignment / self-healing re-roll core out of `cms/resolve.ts`'s `evaluateVariantRule` into `sdk/experiments.ts` as `stickyDecide`, so it can be driven by a variant list from **any** source. The CMS multivariate path now calls the same function, so the two assignment paths cannot drift. On top of it, `resolveExperimentVariant` resolves an N-way weighted experiment from control-plane config in KV (frozen contract 1), returning contract 2's `ResolvedVariant`. ## The signature item C consumes ```ts import { resolveExperimentVariant } from "@decocms/blocks/sdk/experiments"; resolveExperimentVariant<P>(experimentKey: string, ctx?: ExperimentContext<P>) : Promise<ResolvedVariant<P> | null> ``` **One argument in a loader.** The KV binding (`EXPERIMENTS_KV`), request hostname, and `deco_segment` cookie all come from the ambient `RequestContext` that `workerEntry.ts` already installs; the KV read is memoised per request, so N loaders cost one `kv.get`. `ctx` exists for tests — `config`, `kv`, `hostname`, `segmentCookie`, `assignments`, `random`, all optional. Every failure mode (binding absent, key unset, malformed document, KV outage) returns `null`, never a thrown request. Callers behave exactly as today on `null`. ## Two things the design assumed were already solved The design's "Key insight #2" claimed the CMS multivariate engine already had N-way weighted variants and a reusable cookie. Reading the code, neither held. Both are solved here; both are corrected in the doc PR. 1. **The CMS engine was never N-way weighted.** It lists N variants each gated by its own *independent boolean* matcher, evaluated first-match-wins — there is no weighted draw over a variant list, and `StoredFlag.value` was a `boolean`. The sticky/re-roll *policy* did extract cleanly; the weighted draw (`pickWeightedVariant`) and the weight-vector fingerprint (`weightsFingerprint`) are net-new. 2. **`deco_segment` could not physically hold a variant id.** `active` / `inactiveDrawn` are boolean buckets. String-valued decisions now ride in an `exp` map — deliberately the shape Deco Analytics consumes, making that migration a read rather than a translation. The map is **omitted when empty**, so cookies stay byte-identical for sites with no experiment (an added empty map would re-issue every visitor's cookie on deploy and, via `segmentCacheToken`, cold-start every edge cache entry). ## The non-obvious fix `persistFlags` ran **before** the section loaders. An experiment is resolved *inside* a loader (that is where item C calls it), so the assignment would never have reached the cookie and every visitor would re-roll on every request. Moved to after the loaders, and it now merges experiment assignments through the same writer — one `deco_segment`, one `Set-Cookie`. Item C would have hit this as "stickiness doesn't work" with no obvious cause. ## Cache safety `segmentCacheToken` folds experiment assignments in on the same footing as boolean flags, so the existing `__abf` cache-key split in `workerEntry.ts` covers them with **no change**. Without that, two visitors on different variants would share cached HTML. There is a test for exactly that. CMS multivariate keeps its own `trafficToPct` fingerprint — swapping it for the experiment weight hash would re-roll every live visitor on the next deploy. ## Tests 26 new tests in `packages/blocks/src/sdk/experiments.test.ts`: - first assignment (fresh visitor, `isFresh`, weight-proportional routing) - stickiness across requests, including adversarial RNG that *would* have drawn the other arm, and legacy fingerprint-less `deco_segment` cookies - **re-roll once then stick** across a 95/5 → 90/10 ramp, asserting the new fingerprint is written so the re-roll cannot repeat - a visitor holding a variant retired mid-flight is re-rolled onto a live arm - cookie coexistence with a CMS boolean flag; cache-key separation - `readExperimentConfig` failure modes **Blocks suite:** baseline on `origin/main` is `27 failed | 667 passed`; with this branch `27 failed | 693 passed`. Same 27 failures, all `this runtime has no URLPattern Web API` (needs Node 24+, environmental). The 2 `workerEntry.test.ts` draft-preview failures also reproduce on clean `origin/main` — both verified by stashing, neither is from this branch. `tsc --noEmit` clean. `biome check` clean on all touched files. ## Not in scope `sdk/abTesting.ts` is untouched — it is a binary migration-period proxy and a dead end for this. Only its `kv.get<T>(key, "json")` shape is borrowed. Nothing in `farmrio-storefront`, `control-plane`, or `ai-farmrio`. 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Introduces a generic sticky variant resolver and an N-way weighted experiment API. Aligns CMS boolean matcher stickiness with experiments and fixes cookie persistence so assignments reach `deco_segment` and stick across requests. - Review notes - Adds `@decocms/blocks/sdk/experiments` export with `stickyDecide` (extracted from `cms/resolve.ts`) and `resolveExperimentVariant(experimentKey, ctx?) -> Promise<ResolvedVariant | null>`. - Moves persistence: `cmsRoute` now writes `deco_segment` after loaders and merges `takeExperimentAssignments()`; prevents per-request re-rolls. - Extends `deco_segment` schema in `sdk/flags.ts` with `exp` map `{ experimentKey: variantId }` (omitted when empty). `segmentCacheToken` includes variant ids; existing analytics remain unchanged. - CMS boolean matcher path now uses `stickyDecide` with its own `trafficToPct` fingerprint; behavior for binary flags is unchanged. - Failure modes (missing `EXPERIMENTS_KV`, unset/malformed config, KV errors) return `null`; callers follow the current path on `null`. - Adds focused tests for first assignment, stickiness, single re-roll on weight changes, retired variants, cookie coexistence, cache-key separation, and config reads. - Rollout - No action for sites without experiments; cookies remain byte-identical. - To run an experiment, call `resolveExperimentVariant` from a loader and branch on `variantId`/`payload`. Do not set cookies; the framework persists assignments. - Ensure `EXPERIMENTS_KV` is bound and serves per-hostname config; changing weights will re-roll each visitor once, then stick. <sup>Written for commit efbcccc. Summary will update on new commits.</sup> <a href="https://cubic.dev/pr/decocms/blocks/pull/494?utm_source=github" target="_blank" rel="noopener noreferrer" data-no-image-dialog="true"><picture><source media="(prefers-color-scheme: dark)" srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img alt="Review in cubic" src="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"></picture></a> <!-- End of auto-generated description by cubic. --> Co-authored-by: hugo-ccabral <[email protected]> Co-authored-by: Claude Opus 5 <[email protected]>
guitavano
added a commit
that referenced
this pull request
Nov 17, 2026
…anStack Start, esbuild) (#832) Closes the open Dependabot alerts in one PR, with the lockfile. The Dependabot PRs (#811, #828, #747) only touch `package.json`, so they all fail `bun install --frozen-lockfile` in CI. | Package | From | To | Alerts | |---|---|---|---| | `react-server-dom-webpack` (tanstack-rsc-smoke) | 19.2.7 | 19.2.9 | #19, critical: RSC RCE, GHSA-xqc2-xf4c-x3h3 | | `react` / `react-dom` (all pinned workspaces) | 19.2.7 | 19.2.9 | peer floor of the above | | `next` (nextjs, compat-v7, nextjs-binding-smoke) | 16.3.8 | 16.4.6 | #10–12, #14, #15, #17, #18, #20–22 | | `@tanstack/react-start` (tanstack, compat-v7, smokes) | 1.168.58 | 1.168.61 | #2–4, #7, #9 | | `@tanstack/react-router` | 1.170.39 | 1.170.42 | the version react-start 1.168.61 pins, so it stays a single copy | | `esbuild` (blocks, tanstack, compat-v7) | ^0.27.3 | ^0.28.2 | #5, #6, #8 (low) | `bun.lock` was regenerated with bun 1.3.5 (the `packageManager`). React dedupes to a single 19.2.9 at the root, with no nested copies. Vite still has its own transitive `[email protected]` (its own range); that is outside our manifests. Supersedes #811, #828 and #747. ### Verified locally (bun 1.3.5, node 24) - `bun install --frozen-lockfile` ✅ - `bun run typecheck` ✅ · `bun run lint` ✅ - `bun x vitest run`: 3388 passed, 0 failed ✅ (includes `tests/release.test.ts`) - `examples/tanstack-worker-smoke`: build + smoke ✅ - `examples/nextjs-binding-smoke`: build + smoke ✅ - `examples/tanstack-rsc-smoke`: build + typecheck ✅ 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Bumps several dependencies to clear open Dependabot security alerts, including a critical RCE in `react-server-dom-webpack` (GHSA-xqc2-xf4c-x3h3). The lockfile was regenerated so `bun install --frozen-lockfile` passes — React dedupes to a single 19.2.9 copy. **Dependencies** - `react`, `react-dom`, and `react-server-dom-webpack` 19.2.7 → 19.2.9 - `next` 16.3.8 → 16.4.6 - `@tanstack/react-start` 1.168.58 → 1.168.61, with `@tanstack/react-router` 1.170.42 - `esbuild` ^0.27.3 → ^0.28.2; Vite's own transitive `[email protected]` is untouched - Typecheck, lint, the full test suite (3388 passed), and the Next.js and TanStack smoke builds all pass <sup>Written for commit 123acc8. Summary will update on new commits.</sup> <a href="https://cubic.dev/pr/decocms/blocks/pull/832?utm_source=github" target="_blank" rel="noopener noreferrer" data-no-image-dialog="true"><picture><source media="(prefers-color-scheme: dark)" srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img alt="View guided diff" src="https://www.cubic.dev/buttons/review-in-cubic-light.svg"></picture></a> <a href="https://www.cubic.dev/action/auto-fix/pr/decocms/blocks/832?returnTo=https%3A%2F%2Fgithub.com%2Fdecocms%2Fblocks%2Fpull%2F832&source=description" target="_blank" rel="noopener noreferrer" data-no-image-dialog="true"><picture><source media="(prefers-color-scheme: dark)" srcset="https://www.cubic.dev/buttons/turn-on-auto-fix-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://www.cubic.dev/buttons/turn-on-auto-fix-light.svg"><img alt="Turn on auto-fix" src="https://www.cubic.dev/buttons/turn-on-auto-fix-light.svg"></picture></a> <!-- End of auto-generated description by cubic. --> Co-authored-by: Claude Opus 5.5 <[email protected]>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
noDangerouslySetInnerHtmloff for LiveControls/inline scripts,noExplicitAnyoff for generic utilities)lint,lint:fix,lint:unused,format,format:fix,check(runs all quality checks)else ifbranch ingenerate-schema.ts— the nullable string condition on line 185 was unreachable because the non-nullable string branch above already matched the same caseAll checks pass:
Test plan
npm run checkpasses (typecheck + lint + knip)npm run buildsucceedsMade with Cursor
Summary by cubic
Add
@biomejs/biomeandknipto standardize code quality and catch dead code, then apply project-wide formatting. Also fixes an unreachable branch in the schema generator.Dependencies
@biomejs/biome2.4.6 for linting/formatting with recommended rules (disablenoDangerouslySetInnerHtml,noExplicitAny,noNonNullAssertion).knipfor detecting unused files/exports/dependencies.Bug Fixes
scripts/generate-schema.ts(nullable string branch was shadowed).Written for commit 624cca1. Summary will update on new commits.