feat(blocks): split one arm of an A/B test with a nested test (parent/child)
Why
The plp-optimizer A/B test has to split our arm, not the traffic in thirds: 50% control (the store's PLP), and our 50% split into 25% internal test A and 25% internal test B. The analytics has to say both things cleanly: us against the control, and A against B.
v8's tests have two arms each, and a multi-way test is several tests. Two independent tests (plp-optimizer: 50, plp-optimizer-b: 50) give the right shares, but plp-optimizer-b is also on for a quarter of the control, who never see B. Anyone reading it without the right filter mixes control visitors into the A/B comparison, with no error anywhere.
What changes
- A test within a test. A name written
<parent>/<child>, where<parent>is a test of the sameexperimentsblock, is drawn only among<parent>'s visitors and is off outside it:{ "__resolveType": "split-traffic", "plp-optimizer": 50, "plp-optimizer/b": 50 }- The child keeps its own roll (
plp-optimizer/b:id), so ramping the parent to 80 gives 20/40/40 and keeps everyone already in A or B where they were. - The parent is the nearest
/-prefix that is a test of the block (a/b/cfalls back toawithouta/b). A/in a name whose prefix is no test changes nothing, so existing names behave as before. - Given or not: a child switched on in a preview, or forged in an assignments map, stays off while its parent is off. A preview shows B with both switched on, A with the parent alone.
- The child keeps its own roll (
- Where the rule lives:
src/v8/nested.ts(internal), applied byassign(so the browser gives the same answer as the server), the built-insplit-traffic(after the client's overrides) and the analytics client. - Analytics:
startAnalytics({ experiments })sends a child only while its parent is on. A control visitor's events carry{ "plp-optimizer": "off" }; ours carryplp-optimizerandplp-optimizer/b. Soplp-optimizercompares us with the control, andplp-optimizer/bcompares B with A with no filter. Onlyclient.tschanges, notruntime/orshared/: the standalone tag's bundles are untouched, and no decocms/analytics PR is needed. - Nothing else moves: the content type is still
Record<string, number>, so the Studio form,deco check, thex-deco-assignmentsheader,assignmentsKeyand the__testpreview link carry the child as one more test. - Studio: the
split-trafficdescription mentionsparent/child; the examples'schema.gen.jsonare regenerated (one line each). - Docs in the repo:
deco-variants(a "test within a test" section with the PLP slot's nestedmultivariate, and "Reading the results" updated forstartAnalytics) andCLAUDE.md.
Tests
experiments.test.ts: over 100,000 ids, the split is 50/25/25; nobody outside the parent has the child; inside it, the child is its own roll; ramping the parent keeps A and B even and moves nobody between arms; nesting at any depth, to the nearest prefix that is a test; a/without a parent test changes nothing.__conformance__/experiments.test.ts:- exp-14: one slot serves control, A and B, and what it shows always matches the map;
- exp-15: a child given on stays off while its parent is off, given, decided or forged;
- exp-16: a preview with both switched on shows B, the parent alone shows A.
analytics/client.test.ts: theexpof each of the three arms.
bun run check passes, and bun run test passes (3400 tests). The Biome warnings left are on main too.
Before merging
- Docs site: the
/next/*page onsplit-trafficneeds the same rule, since exp-14 to exp-16 encode it. It also needs the PO's ok, since it extends "two arms per test". - Not here: a true N-arm test (
"plp-optimizer": { "control": 50, "a": 25, "b": 25 }with one label per arm inexp). That would touch the assignments type, the header, the cache key, the bindings' parsing, the preview, the Studio form anddeco check. More internal arms are possible here by chaining (plp-optimizer/b: 66,plp-optimizer/b/c: 50), not with siblings, which overlap.
š¤ Generated with Claude Code
Summary by cubic
Adds nested A/B tests: a test named <parent>/<child> is drawn only among <parent>'s visitors, so one test can split its own arm. { "plp-optimizer": 50, "plp-optimizer/b": 50 } gives 50% control, 25% A, 25% B; two independent tests previously put plp-optimizer-b on a quarter of the control too, mixing control visitors into the A/B comparison.
- The child keeps its own roll, so ramping the parent to 80 gives 20/40/40 and keeps everyone already in A or B where they were; a preview switching on the parent alone shows the visitor's own arm of the child.
- A child switched on in a preview, or forged in an assignments map, stays off while its parent is off. The parent is the nearest
/-prefix that is a test of the same block; a/in a name whose prefix is no test changes nothing. deco checkwarns on each name it reads as nested, so a name saved earlier with a/doesn't change meaning silently.- The rule lives in
src/v8/nested.ts, applied byassign, the built-insplit-traffic, and the analytics client, which sends a child only while its parent is on soplp-optimizercompares us with the control andplp-optimizer/bcompares B with A without filtering. - The content type, header, cache key, and Studio form are unchanged; docs and generated schemas are updated, and conformance tests exp-14 to exp-19 cover the new behavior, including that
__testpreview links keep the child name's/on drafts and releases.