@delmaredigital/payload-experiments 0.4.0-rc.7 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -15
- package/dist/admin/MetricSourceSelect.js +10 -3
- package/dist/admin/armSelect/armSelect.model.d.ts +1 -1
- package/dist/admin/blocks/BlockPanel.d.ts +1 -0
- package/dist/admin/blocks/BlockPanel.js +75 -29
- package/dist/admin/blocks/model.js +7 -6
- package/dist/admin/copy/blocks.d.ts +14 -11
- package/dist/admin/copy/blocks.js +33 -22
- package/dist/admin/copy/goals.d.ts +15 -8
- package/dist/admin/copy/goals.js +18 -8
- package/dist/admin/copy/newTest.d.ts +10 -7
- package/dist/admin/copy/newTest.js +14 -7
- package/dist/admin/copy/status.d.ts +1 -1
- package/dist/admin/copy/status.js +2 -1
- package/dist/admin/pageCollections.d.ts +1 -0
- package/dist/admin/pageCollections.js +3 -0
- package/dist/admin/placementStatus.model.js +5 -3
- package/dist/admin/status.model.d.ts +1 -0
- package/dist/admin/status.model.js +2 -1
- package/dist/admin/surface/ResultsRoute.js +12 -10
- package/dist/admin/surface/SurfaceShell.d.ts +4 -2
- package/dist/admin/surface/SurfaceShell.js +28 -3
- package/dist/admin/surface/TestRowMenu.d.ts +13 -0
- package/dist/admin/surface/TestRowMenu.js +163 -0
- package/dist/admin/surface/TestsHome.d.ts +4 -3
- package/dist/admin/surface/TestsHome.js +224 -52
- package/dist/admin/surface/TestsSurface.js +2 -1
- package/dist/admin/surface/goals/DeleteGoalDialog.d.ts +7 -0
- package/dist/admin/surface/goals/DeleteGoalDialog.js +42 -0
- package/dist/admin/surface/goals/GoalForm.d.ts +1 -0
- package/dist/admin/surface/goals/GoalForm.js +280 -198
- package/dist/admin/surface/goals/GoalsList.js +102 -33
- package/dist/admin/surface/goals/data.d.ts +2 -0
- package/dist/admin/surface/goals/data.js +9 -0
- package/dist/admin/surface/goals/goals.css +3 -2
- package/dist/admin/surface/goals/goals.model.d.ts +2 -2
- package/dist/admin/surface/goals/goals.model.js +7 -12
- package/dist/admin/surface/home.model.d.ts +15 -8
- package/dist/admin/surface/home.model.js +22 -18
- package/dist/admin/surface/newTest/NewTest.d.ts +3 -3
- package/dist/admin/surface/newTest/NewTest.js +156 -96
- package/dist/admin/surface/newTest/PageWizard.d.ts +4 -1
- package/dist/admin/surface/newTest/PageWizard.js +99 -68
- package/dist/admin/surface/newTest/newTest.css +28 -11
- package/dist/admin/surface/results/ResultsHeader.d.ts +1 -1
- package/dist/admin/surface/results/ResultsHeader.js +98 -66
- package/dist/admin/surface/surface.css +29 -0
- package/dist/admin/surface/test/TestPage.js +46 -38
- package/dist/admin/surface/useXpStepNav.d.ts +11 -0
- package/dist/admin/surface/useXpStepNav.js +14 -0
- package/dist/admin/views/TestsSurfaceClient.js +27 -3
- package/dist/admin/views/buildSurfaceProps.js +18 -66
- package/dist/arms/copy.d.ts +13 -3
- package/dist/arms/copy.js +5 -4
- package/dist/blocks/createExperimentBlock.js +1 -1
- package/dist/blocks/formState.js +2 -2
- package/dist/collections/experiments/armInvariants.js +8 -5
- package/dist/collections/experiments/config.js +8 -3
- package/dist/collections/experiments/deleteGuard.js +2 -2
- package/dist/collections/experiments/lockHook.js +21 -2
- package/dist/collections/experiments/pickSlug.js +2 -0
- package/dist/collections/metrics.js +12 -5
- package/dist/collections/metricsGuards.js +2 -0
- package/dist/collections/serialize.js +8 -6
- package/dist/constants.d.ts +1 -0
- package/dist/constants.js +1 -0
- package/dist/db/adapter.d.ts +9 -1
- package/dist/db/adapter.js +77 -1
- package/dist/db/delete.d.ts +1 -1
- package/dist/db/delete.js +2 -4
- package/dist/db/events.d.ts +9 -0
- package/dist/db/events.js +42 -8
- package/dist/db/executor.d.ts +7 -1
- package/dist/db/executor.js +7 -3
- package/dist/db/pageCopies.d.ts +5 -0
- package/dist/db/pageCopies.js +31 -0
- package/dist/db/results.d.ts +5 -1
- package/dist/db/results.js +21 -5
- package/dist/db/snapshots.d.ts +2 -0
- package/dist/endpoints/deleteImpact.js +2 -1
- package/dist/endpoints/duplicateOriginal.d.ts +38 -0
- package/dist/endpoints/duplicateOriginal.js +414 -0
- package/dist/endpoints/editorSurface.js +1 -1
- package/dist/endpoints/events.js +103 -39
- package/dist/endpoints/index.js +22 -8
- package/dist/endpoints/pages.js +245 -66
- package/dist/endpoints/placementStatus.js +8 -4
- package/dist/endpoints/results.d.ts +1 -1
- package/dist/endpoints/results.js +9 -2
- package/dist/endpoints/routeId.d.ts +2 -2
- package/dist/endpoints/routeId.js +11 -5
- package/dist/endpoints/summary.js +46 -12
- package/dist/endpoints/testVersion.d.ts +2 -0
- package/dist/endpoints/testVersion.js +38 -0
- package/dist/endpoints/transitions.js +41 -29
- package/dist/errors.d.ts +4 -0
- package/dist/errors.js +6 -0
- package/dist/events/request.d.ts +6 -2
- package/dist/events/request.js +35 -8
- package/dist/events/rows.d.ts +1 -1
- package/dist/events/rows.js +24 -8
- package/dist/events/writable.d.ts +9 -0
- package/dist/events/writable.js +13 -0
- package/dist/exports/index.d.ts +1 -1
- package/dist/exports/rsc.d.ts +1 -0
- package/dist/exports/rsc.js +1 -0
- package/dist/goals/fairness.js +2 -2
- package/dist/goals/picker/copy.js +1 -1
- package/dist/goals/sourceLabel.d.ts +2 -0
- package/dist/goals/sourceLabel.js +4 -0
- package/dist/hooks/hostHook.js +6 -2
- package/dist/hooks/pageGuard.js +4 -0
- package/dist/hooks/trackPageCopies.d.ts +11 -0
- package/dist/hooks/trackPageCopies.js +7 -0
- package/dist/labels/arms.d.ts +3 -0
- package/dist/labels/arms.js +8 -0
- package/dist/lib/fetchAllDocs.d.ts +1 -1
- package/dist/manifest/compile.js +8 -5
- package/dist/onInit.js +14 -0
- package/dist/options.d.ts +2 -0
- package/dist/options.js +23 -2
- package/dist/plugin.js +56 -2
- package/dist/proxy/pageNavigation.d.ts +4 -0
- package/dist/proxy/pageNavigation.js +28 -0
- package/dist/proxy/resolve.js +52 -25
- package/dist/puck/editor/ConfigureTestDrawer.d.ts +7 -7
- package/dist/puck/editor/ConfigureTestDrawer.js +40 -29
- package/dist/puck/editor/ExperimentSlotEditor.d.ts +2 -1
- package/dist/puck/editor/ExperimentSlotEditor.js +376 -139
- package/dist/puck/editor/LeftoverVersions.js +17 -32
- package/dist/puck/editor/QuickTestActions.d.ts +6 -3
- package/dist/puck/editor/QuickTestActions.js +55 -33
- package/dist/puck/editor/ResultsReadout.d.ts +4 -1
- package/dist/puck/editor/ResultsReadout.js +28 -15
- package/dist/puck/editor/VersionBuilder.d.ts +17 -4
- package/dist/puck/editor/VersionBuilder.js +175 -112
- package/dist/puck/editor/armWrites.js +2 -2
- package/dist/puck/editor/armsCache.js +1 -3
- package/dist/puck/editor/copy.d.ts +14 -7
- package/dist/puck/editor/copy.js +26 -13
- package/dist/puck/editor/editor.chrome.css +10 -8
- package/dist/puck/editor/editor.css +15 -9
- package/dist/puck/editor/editor.model.d.ts +1 -0
- package/dist/puck/editor/placementsCache.d.ts +4 -0
- package/dist/puck/editor/usePageSaveReadiness.d.ts +6 -0
- package/dist/puck/editor/usePageSaveReadiness.js +31 -0
- package/dist/puck/nestedTestCopy.js +2 -2
- package/dist/puck/slotConfig.d.ts +1 -1
- package/dist/puck/slotConfig.js +1 -1
- package/dist/results/aggregate.d.ts +6 -3
- package/dist/results/aggregate.js +9 -9
- package/dist/results/analyse.d.ts +2 -0
- package/dist/results/analyse.js +2 -2
- package/dist/results/health.d.ts +8 -0
- package/dist/results/health.js +28 -0
- package/dist/results/identityCredit.d.ts +1 -0
- package/dist/results/identityCredit.js +4 -1
- package/dist/results/verdict.d.ts +4 -4
- package/dist/results/verdict.js +15 -11
- package/dist/runtime/cookie.d.ts +10 -2
- package/dist/runtime/cookie.js +38 -6
- package/dist/runtime/cookieOptions.d.ts +6 -0
- package/dist/runtime/cookieOptions.js +14 -0
- package/dist/runtime/proxyRuntime.d.ts +1 -0
- package/dist/runtime/proxyRuntime.js +18 -8
- package/dist/runtime/signing.d.ts +1 -0
- package/dist/runtime/signing.js +5 -0
- package/dist/sanitizeReadinessDetail.d.ts +2 -2
- package/dist/sanitizeReadinessDetail.js +20 -2
- package/dist/server/getAssignments.js +11 -10
- package/dist/server/recordContentChange.d.ts +1 -1
- package/dist/server/recordContentChange.js +11 -2
- package/dist/server/resolveExperimentBlocks.js +2 -4
- package/dist/server/resolveExperimentData.js +2 -5
- package/dist/server/runResults.js +54 -15
- package/dist/server/startExperiment.d.ts +20 -0
- package/dist/server/startExperiment.js +70 -0
- package/dist/server/trackConversion.js +10 -13
- package/dist/testSurface/PreviewLinks.d.ts +2 -1
- package/dist/testSurface/PreviewLinks.js +3 -3
- package/dist/testSurface/actions/DecideDialog.d.ts +10 -4
- package/dist/testSurface/actions/DecideDialog.js +93 -63
- package/dist/testSurface/actions/LifecycleAction.d.ts +17 -0
- package/dist/testSurface/actions/LifecycleAction.js +107 -0
- package/dist/testSurface/actions/MakeContentResult.d.ts +4 -3
- package/dist/testSurface/actions/MakeContentResult.js +10 -2
- package/dist/testSurface/actions/actions.model.d.ts +13 -5
- package/dist/testSurface/actions/actions.model.js +75 -22
- package/dist/testSurface/actions/decide.model.d.ts +1 -0
- package/dist/testSurface/actions/decide.model.js +1 -0
- package/dist/testSurface/allocation.model.js +6 -3
- package/dist/testSurface/api.d.ts +9 -6
- package/dist/testSurface/api.js +43 -23
- package/dist/testSurface/copy/actions.d.ts +37 -14
- package/dist/testSurface/copy/actions.js +40 -17
- package/dist/testSurface/copy/advanced.d.ts +10 -0
- package/dist/testSurface/copy/advanced.js +10 -0
- package/dist/testSurface/copy/arms.d.ts +1 -1
- package/dist/testSurface/copy/arms.js +1 -1
- package/dist/testSurface/copy/audience.d.ts +4 -3
- package/dist/testSurface/copy/audience.js +5 -4
- package/dist/testSurface/copy/common.d.ts +8 -6
- package/dist/testSurface/copy/common.js +8 -6
- package/dist/testSurface/copy/languages.d.ts +1 -0
- package/dist/testSurface/copy/languages.js +1 -0
- package/dist/testSurface/copy/metrics.d.ts +7 -0
- package/dist/testSurface/copy/metrics.js +9 -0
- package/dist/testSurface/copy/pages.d.ts +67 -7
- package/dist/testSurface/copy/pages.js +74 -7
- package/dist/testSurface/copy/readiness.d.ts +20 -7
- package/dist/testSurface/copy/readiness.js +36 -10
- package/dist/testSurface/copy/recommendation.d.ts +1 -22
- package/dist/testSurface/copy/recommendation.js +2 -22
- package/dist/testSurface/copy/results.d.ts +21 -12
- package/dist/testSurface/copy/results.js +24 -13
- package/dist/testSurface/copy/review.d.ts +13 -10
- package/dist/testSurface/copy/review.js +14 -10
- package/dist/testSurface/copy/setting.d.ts +1 -2
- package/dist/testSurface/copy/setting.js +1 -2
- package/dist/testSurface/copy/surface.d.ts +11 -2
- package/dist/testSurface/copy/surface.js +14 -11
- package/dist/testSurface/copy/testPage.d.ts +36 -12
- package/dist/testSurface/copy/testPage.js +53 -16
- package/dist/testSurface/format/date.d.ts +5 -2
- package/dist/testSurface/format/date.js +24 -8
- package/dist/testSurface/format/roundProgress.d.ts +6 -0
- package/dist/testSurface/format/roundProgress.js +15 -0
- package/dist/testSurface/format/useDateFormatter.d.ts +3 -0
- package/dist/testSurface/format/useDateFormatter.js +8 -0
- package/dist/testSurface/labels.d.ts +1 -2
- package/dist/testSurface/labels.js +2 -3
- package/dist/testSurface/lockedNotice.model.d.ts +2 -0
- package/dist/testSurface/lockedNotice.model.js +31 -0
- package/dist/testSurface/readPreflight.d.ts +4 -0
- package/dist/testSurface/readPreflight.js +6 -0
- package/dist/testSurface/readinessRead.d.ts +3 -0
- package/dist/testSurface/readinessRead.js +4 -0
- package/dist/testSurface/results/CiChart.js +2 -1
- package/dist/testSurface/results/DataTable.d.ts +1 -1
- package/dist/testSurface/results/DataTable.js +4 -3
- package/dist/testSurface/results/VerdictHero.d.ts +3 -2
- package/dist/testSurface/results/VerdictHero.js +5 -1
- package/dist/testSurface/results/legacy.d.ts +0 -5
- package/dist/testSurface/results/legacy.js +0 -14
- package/dist/testSurface/results/results.css +2 -2
- package/dist/testSurface/results/results.model.d.ts +9 -4
- package/dist/testSurface/results/results.model.js +31 -23
- package/dist/testSurface/results/snapshot.d.ts +2 -0
- package/dist/testSurface/results/snapshot.js +3 -0
- package/dist/testSurface/surface/contracts.d.ts +13 -1
- package/dist/testSurface/surface/editorPlacement.d.ts +3 -3
- package/dist/testSurface/surface/editorPlacement.js +2 -2
- package/dist/testSurface/surface/pageBlock/pageBlock.model.js +3 -3
- package/dist/testSurface/surface/pageBlock/parts.js +25 -12
- package/dist/testSurface/surface/pagePicker/CopyRoute.d.ts +8 -1
- package/dist/testSurface/surface/pagePicker/CopyRoute.js +243 -22
- package/dist/testSurface/surface/pagePicker/PageCombobox.d.ts +15 -4
- package/dist/testSurface/surface/pagePicker/PageCombobox.js +300 -197
- package/dist/testSurface/surface/pagePicker/pagePicker.css +73 -10
- package/dist/testSurface/surface/pagePicker/pagePicker.model.d.ts +5 -3
- package/dist/testSurface/surface/pagePicker/pagePicker.model.js +17 -2
- package/dist/testSurface/surface/readiness/ActionDialogs.d.ts +9 -5
- package/dist/testSurface/surface/readiness/ActionDialogs.js +241 -230
- package/dist/testSurface/surface/readiness/Banner.d.ts +5 -1
- package/dist/testSurface/surface/readiness/Banner.js +113 -141
- package/dist/testSurface/surface/readiness/SaveStatus.d.ts +8 -4
- package/dist/testSurface/surface/readiness/SaveStatus.js +23 -22
- package/dist/testSurface/surface/readiness/readiness.model.d.ts +20 -6
- package/dist/testSurface/surface/readiness/readiness.model.js +168 -21
- package/dist/testSurface/surface/readiness/useTransition.d.ts +6 -4
- package/dist/testSurface/surface/readiness/useTransition.js +57 -14
- package/dist/testSurface/surface/results/ReleasePages.d.ts +6 -3
- package/dist/testSurface/surface/results/ReleasePages.js +42 -41
- package/dist/testSurface/surface/results/ResultsBody.d.ts +11 -4
- package/dist/testSurface/surface/results/ResultsBody.js +221 -118
- package/dist/testSurface/surface/results/recommendation.model.d.ts +6 -9
- package/dist/testSurface/surface/results/recommendation.model.js +15 -59
- package/dist/testSurface/surface/results/useResults.d.ts +13 -8
- package/dist/testSurface/surface/results/useResults.js +3 -2
- package/dist/testSurface/surface/setting/parts.js +89 -46
- package/dist/testSurface/surface/setting/setting.css +2 -1
- package/dist/testSurface/surface/test/AdvancedSection.js +11 -4
- package/dist/testSurface/surface/test/DeleteTest.d.ts +10 -2
- package/dist/testSurface/surface/test/DeleteTest.js +173 -74
- package/dist/testSurface/surface/test/GoalSection.js +18 -14
- package/dist/testSurface/surface/test/LengthSection.js +24 -13
- package/dist/testSurface/surface/test/PageHoldout.d.ts +1 -1
- package/dist/testSurface/surface/test/PageHoldout.js +11 -8
- package/dist/testSurface/surface/test/ReadinessBar.d.ts +2 -1
- package/dist/testSurface/surface/test/ReadinessBar.js +4 -10
- package/dist/testSurface/surface/test/Section.js +8 -0
- package/dist/testSurface/surface/test/TargetingSection.js +82 -12
- package/dist/testSurface/surface/test/TestSurface.js +73 -37
- package/dist/testSurface/surface/test/VersionsSection.js +141 -91
- package/dist/testSurface/surface/test/fields.d.ts +32 -6
- package/dist/testSurface/surface/test/fields.js +166 -52
- package/dist/testSurface/surface/test/pageParts.js +27 -12
- package/dist/testSurface/surface/test/testPage.css +9 -2
- package/dist/testSurface/surface/test/testPage.model.d.ts +1 -0
- package/dist/testSurface/surface/test/testPage.model.js +6 -0
- package/dist/testSurface/surface/testDocument.model.d.ts +3 -0
- package/dist/testSurface/surface/testDocument.model.js +4 -1
- package/dist/testSurface/surface/useTestDocument.d.ts +21 -5
- package/dist/testSurface/surface/useTestDocument.js +472 -167
- package/dist/testSurface/surface/watchTestDocument.d.ts +15 -0
- package/dist/testSurface/surface/watchTestDocument.js +181 -0
- package/dist/testSurface/surfaceUrls.d.ts +1 -0
- package/dist/testSurface/surfaceUrls.js +4 -0
- package/dist/testSurface/useApi.d.ts +8 -5
- package/dist/testSurface/useOnTestReturn.d.ts +2 -0
- package/dist/testSurface/useOnTestReturn.js +27 -0
- package/dist/testSurface/useReadinessPolling.js +3 -1
- package/dist/transitions/addMetric.d.ts +2 -5
- package/dist/transitions/addMetric.js +5 -1
- package/dist/transitions/allocate.d.ts +2 -2
- package/dist/transitions/allocate.js +3 -1
- package/dist/transitions/archive.d.ts +1 -1
- package/dist/transitions/archive.js +3 -2
- package/dist/transitions/checkStart.d.ts +1 -0
- package/dist/transitions/checkStart.js +17 -6
- package/dist/transitions/decide.d.ts +1 -1
- package/dist/transitions/decide.js +5 -3
- package/dist/transitions/deleteExperiment.d.ts +2 -2
- package/dist/transitions/deleteExperiment.js +17 -7
- package/dist/transitions/kernel.d.ts +4 -0
- package/dist/transitions/kernel.js +9 -4
- package/dist/transitions/makeContent.d.ts +2 -1
- package/dist/transitions/makeContent.js +12 -8
- package/dist/transitions/nestedPlacementNames.d.ts +2 -2
- package/dist/transitions/nestedPlacementNames.js +4 -5
- package/dist/transitions/pageAddress.d.ts +6 -0
- package/dist/transitions/pageAddress.js +71 -0
- package/dist/transitions/pageVersions.d.ts +1 -1
- package/dist/transitions/phaseRecord.d.ts +2 -0
- package/dist/transitions/phaseRecord.js +5 -0
- package/dist/transitions/placementInteractions.d.ts +3 -3
- package/dist/transitions/placementInteractions.js +8 -7
- package/dist/transitions/placements.d.ts +2 -0
- package/dist/transitions/placements.js +5 -5
- package/dist/transitions/preflightData.d.ts +3 -2
- package/dist/transitions/preflightData.js +77 -43
- package/dist/transitions/releaseHoldout.d.ts +2 -1
- package/dist/transitions/releaseHoldout.js +3 -1
- package/dist/transitions/releasePages.d.ts +2 -1
- package/dist/transitions/releasePages.js +3 -1
- package/dist/transitions/resolveCaps.d.ts +2 -4
- package/dist/transitions/start.d.ts +7 -9
- package/dist/transitions/start.js +75 -39
- package/dist/transitions/startReads.d.ts +7 -0
- package/dist/transitions/startReads.js +28 -0
- package/dist/transitions/stop.d.ts +2 -1
- package/dist/transitions/stop.js +3 -2
- package/dist/types/armKey.d.ts +2 -0
- package/dist/types/armKey.js +1 -0
- package/dist/types/contracts.d.ts +17 -4
- package/dist/types/endpoints.d.ts +89 -17
- package/dist/types/endpoints.js +1 -1
- package/dist/types/runtime.d.ts +15 -9
- package/dist/types/snapshot.d.ts +2 -0
- package/dist/types/surface.d.ts +7 -9
- package/dist/ui/ChipsInput.d.ts +8 -1
- package/dist/ui/ChipsInput.js +17 -4
- package/dist/ui/Dialog.d.ts +21 -2
- package/dist/ui/Dialog.js +101 -4
- package/dist/ui/Inputs.js +0 -1
- package/dist/ui/ui.css +5 -1
- package/package.json +2 -2
|
@@ -1,7 +1,10 @@
|
|
|
1
|
+
import { findDraftPageByPath } from './pageAddress.js';
|
|
1
2
|
import { nestedPlacementNames, nameNestedPlacements } from './nestedPlacementNames.js';
|
|
2
3
|
import { placementReader } from '../blocks/placementLocale.js';
|
|
3
|
-
import {
|
|
4
|
+
import { BLOCK_SLOTS } from '../blocks/model.js';
|
|
5
|
+
import { placementLanguageNames, placementLanguages } from '../blocks/placementLanguages.js';
|
|
4
6
|
import { goalContent, OUTSIDE_GOAL } from '../goals/fairness.js';
|
|
7
|
+
import { browserWritableMetric } from '../events/writable.js';
|
|
5
8
|
import { placementInteractions, placementPaths, uniquePlacementDocs } from './placementInteractions.js';
|
|
6
9
|
import { Forbidden, NotFound } from 'payload';
|
|
7
10
|
import { normalisePath } from '../runtime/normalisePath.js';
|
|
@@ -13,17 +16,16 @@ import { checkStart, relationshipId } from './checkStart.js';
|
|
|
13
16
|
import { flagPlacements, scanBlockPlacements } from './placements.js';
|
|
14
17
|
import { routedPageTests } from '../db/pageOccupancy.js';
|
|
15
18
|
import { pooledExecutor, txExecutor } from '../db/executor.js';
|
|
19
|
+
import { findStartDocuments, readStartState } from './startReads.js';
|
|
16
20
|
const failureDetail = (cause)=>{
|
|
17
21
|
const name = cause instanceof Error ? cause.name : undefined;
|
|
18
22
|
return cause instanceof Forbidden || name === 'Forbidden' ? 'forbidden' : cause instanceof NotFound || name === 'NotFound' ? 'not-found' : 'placements-failed';
|
|
19
23
|
};
|
|
20
24
|
/** Read-only inputs shared with Start's pre-transaction checks. Start must re-read
|
|
21
25
|
* the document and lock-sensitive facts inside its transition (CORE-10b).
|
|
22
|
-
*/ export async function
|
|
23
|
-
const found = await req
|
|
26
|
+
*/ export async function readStartInputExperiment(req, experimentId, system = false) {
|
|
27
|
+
const found = await findStartDocuments(req, {
|
|
24
28
|
collection: 'xp-experiments',
|
|
25
|
-
req,
|
|
26
|
-
overrideAccess: false,
|
|
27
29
|
depth: 0,
|
|
28
30
|
limit: 1,
|
|
29
31
|
where: {
|
|
@@ -31,12 +33,15 @@ const failureDetail = (cause)=>{
|
|
|
31
33
|
equals: experimentId
|
|
32
34
|
}
|
|
33
35
|
}
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
|
|
36
|
+
}, system);
|
|
37
|
+
return found.docs[0] ?? null;
|
|
38
|
+
}
|
|
39
|
+
export async function loadStartInputs(req, options, experimentId, system = false) {
|
|
40
|
+
const experiment = await readStartInputExperiment(req, experimentId, system);
|
|
41
|
+
if (!experiment) return null;
|
|
37
42
|
return (await loadStartInputsBatch(req, options, [
|
|
38
43
|
experiment
|
|
39
|
-
])).get(String(experiment.id)) ?? null;
|
|
44
|
+
], false, system)).get(String(experiment.id)) ?? null;
|
|
40
45
|
}
|
|
41
46
|
/** Occupancy from the arms the runtime routes on (frozen rounds), shared by preflight and
|
|
42
47
|
* Start's locked recheck. Raw SQL on the request's transaction when there is one. */ export async function loadPageTestsInUse(req) {
|
|
@@ -74,16 +79,14 @@ const metricIds = (experiment)=>[
|
|
|
74
79
|
].map(relationshipId).filter((id)=>id !== undefined);
|
|
75
80
|
/** Shared, request-scoped reads for summary; a failed row is null in tolerant mode.
|
|
76
81
|
* Preflight/Start use the same builder and retain their throwing read behaviour.
|
|
77
|
-
*/ export async function loadStartInputsBatch(req, options, experiments, tolerateErrors = false) {
|
|
82
|
+
*/ export async function loadStartInputsBatch(req, options, experiments, tolerateErrors = false, system = false) {
|
|
78
83
|
const ids = [
|
|
79
84
|
...new Set(experiments.flatMap(metricIds))
|
|
80
85
|
];
|
|
81
86
|
const metrics = (async ()=>{
|
|
82
87
|
if (!ids.length) return [];
|
|
83
|
-
const result = await req
|
|
88
|
+
const result = await findStartDocuments(req, {
|
|
84
89
|
collection: 'xp-metrics',
|
|
85
|
-
req,
|
|
86
|
-
overrideAccess: false,
|
|
87
90
|
depth: 0,
|
|
88
91
|
pagination: false,
|
|
89
92
|
limit: ids.length,
|
|
@@ -92,7 +95,7 @@ const metricIds = (experiment)=>[
|
|
|
92
95
|
in: ids
|
|
93
96
|
}
|
|
94
97
|
}
|
|
95
|
-
});
|
|
98
|
+
}, system);
|
|
96
99
|
return result.docs;
|
|
97
100
|
})();
|
|
98
101
|
const blockSlugs = new Set(experiments.filter((e)=>e.kind === 'block').map((e)=>e.slug));
|
|
@@ -144,13 +147,14 @@ const metricIds = (experiment)=>[
|
|
|
144
147
|
slugs: blockSlugs,
|
|
145
148
|
compareVersions: true,
|
|
146
149
|
puckCollections: options.puck?.collections ?? [],
|
|
147
|
-
blocksCollections: options.blocks?.collections ?? []
|
|
150
|
+
blocksCollections: options.blocks?.collections ?? [],
|
|
151
|
+
system
|
|
148
152
|
});
|
|
149
153
|
input.placements = (await blocks).get(experiment.slug) ?? [];
|
|
150
154
|
if (input.placements.some((p)=>p.nestedTests?.length)) {
|
|
151
155
|
nestedNames ??= nestedPlacementNames(req, [
|
|
152
156
|
...(await blocks).values()
|
|
153
|
-
].flat());
|
|
157
|
+
].flat(), system);
|
|
154
158
|
input.placements = nameNestedPlacements(input.placements, await nestedNames);
|
|
155
159
|
}
|
|
156
160
|
} catch (cause) {
|
|
@@ -162,12 +166,7 @@ const metricIds = (experiment)=>[
|
|
|
162
166
|
if (point) {
|
|
163
167
|
state ??= (async ()=>{
|
|
164
168
|
try {
|
|
165
|
-
const doc = await req
|
|
166
|
-
slug: 'xp-state',
|
|
167
|
-
req,
|
|
168
|
-
overrideAccess: false,
|
|
169
|
-
depth: 0
|
|
170
|
-
});
|
|
169
|
+
const doc = await readStartState(req, system);
|
|
171
170
|
return doc.flagDefaults;
|
|
172
171
|
} catch (cause) {
|
|
173
172
|
const error = cause;
|
|
@@ -195,10 +194,8 @@ const metricIds = (experiment)=>[
|
|
|
195
194
|
const key = experiment.flagPoint;
|
|
196
195
|
if (!busyPoints.has(key)) busyPoints.set(key, (async ()=>{
|
|
197
196
|
// Two rows suffice to find a peer, including when the batch contains that peer.
|
|
198
|
-
const busy = await req
|
|
197
|
+
const busy = await findStartDocuments(req, {
|
|
199
198
|
collection: 'xp-experiments',
|
|
200
|
-
req,
|
|
201
|
-
overrideAccess: false,
|
|
202
199
|
depth: 0,
|
|
203
200
|
limit: 2,
|
|
204
201
|
where: {
|
|
@@ -218,7 +215,7 @@ const metricIds = (experiment)=>[
|
|
|
218
215
|
}
|
|
219
216
|
]
|
|
220
217
|
}
|
|
221
|
-
});
|
|
218
|
+
}, system);
|
|
222
219
|
return busy.docs;
|
|
223
220
|
})());
|
|
224
221
|
input.flagPointBusy = (await busyPoints.get(key)).some((doc)=>String(doc.id) !== String(experiment.id));
|
|
@@ -228,10 +225,8 @@ const metricIds = (experiment)=>[
|
|
|
228
225
|
if (layerId !== undefined) {
|
|
229
226
|
const key = String(layerId);
|
|
230
227
|
if (!layers.has(key)) layers.set(key, (async ()=>{
|
|
231
|
-
const result = await req
|
|
228
|
+
const result = await findStartDocuments(req, {
|
|
232
229
|
collection: 'xp-layers',
|
|
233
|
-
req,
|
|
234
|
-
overrideAccess: false,
|
|
235
230
|
depth: 0,
|
|
236
231
|
limit: 1,
|
|
237
232
|
where: {
|
|
@@ -239,15 +234,13 @@ const metricIds = (experiment)=>[
|
|
|
239
234
|
equals: layerId
|
|
240
235
|
}
|
|
241
236
|
}
|
|
242
|
-
});
|
|
237
|
+
}, system);
|
|
243
238
|
const layer = result.docs[0];
|
|
244
239
|
const usedSlices = [];
|
|
245
240
|
let page = 1;
|
|
246
241
|
while(true){
|
|
247
|
-
const usage = await req
|
|
242
|
+
const usage = await findStartDocuments(req, {
|
|
248
243
|
collection: 'xp-experiments',
|
|
249
|
-
req,
|
|
250
|
-
overrideAccess: false,
|
|
251
244
|
depth: 0,
|
|
252
245
|
limit: 100,
|
|
253
246
|
page,
|
|
@@ -268,7 +261,7 @@ const metricIds = (experiment)=>[
|
|
|
268
261
|
}
|
|
269
262
|
]
|
|
270
263
|
}
|
|
271
|
-
});
|
|
264
|
+
}, system);
|
|
272
265
|
for (const doc of usage.docs)if (Array.isArray(doc.layerSlices)) usedSlices.push(...doc.layerSlices);
|
|
273
266
|
if (!usage.hasNextPage) break;
|
|
274
267
|
page++;
|
|
@@ -284,7 +277,7 @@ const metricIds = (experiment)=>[
|
|
|
284
277
|
const paths = experiment.kind === 'page' ? experiment.arms.flatMap((a)=>typeof a.pageTarget === 'string' ? [
|
|
285
278
|
a.pageTarget
|
|
286
279
|
] : []) : await placementPaths(req, options, uniquePlacementDocs(input.placements ?? []));
|
|
287
|
-
input.interactions = await placementInteractions(req, await req.transactionID != null ? txExecutor(req) : pooledExecutor(req.payload), options, experiment, paths.map(normalisePath));
|
|
280
|
+
input.interactions = await placementInteractions(req, await req.transactionID != null ? txExecutor(req) : pooledExecutor(req.payload), options, experiment, paths.map(normalisePath), system);
|
|
288
281
|
}
|
|
289
282
|
if (input.metrics.some((metric)=>metric.source.startsWith('click:'))) input.goalContent = await goalContent(req, options, experiment, input.placements ? uniquePlacementDocs(input.placements.filter((placement)=>placement.published)) : undefined);
|
|
290
283
|
inputs.set(String(experiment.id), input);
|
|
@@ -475,7 +468,9 @@ export async function preflightData(req, { experimentId, options, placementLocal
|
|
|
475
468
|
} catch {}
|
|
476
469
|
}
|
|
477
470
|
}
|
|
478
|
-
const requiredSlots = e.arms.
|
|
471
|
+
const requiredSlots = e.arms.flatMap((arm)=>arm.kind === 'holdout' || arm.key === 'holdout' ? [] : [
|
|
472
|
+
arm.key
|
|
473
|
+
]);
|
|
479
474
|
const blocks = input.placements ?? [];
|
|
480
475
|
let placements = new Array(blocks.length);
|
|
481
476
|
let nextPlacement = 0;
|
|
@@ -511,7 +506,20 @@ export async function preflightData(req, { experimentId, options, placementLocal
|
|
|
511
506
|
};
|
|
512
507
|
}
|
|
513
508
|
}));
|
|
509
|
+
let contentLocales;
|
|
514
510
|
if (blocks.some((placement)=>placement.locale)) {
|
|
511
|
+
const { placementLocale, placementDefaultLocale, placementLocaleCodes } = input;
|
|
512
|
+
const selected = placementLocale && placementLocaleCodes?.includes(placementLocale) ? placementLocale : placementDefaultLocale;
|
|
513
|
+
if (selected && placementLocaleCodes) {
|
|
514
|
+
const labels = placementLanguageNames(req, placementLocaleCodes);
|
|
515
|
+
contentLocales = {
|
|
516
|
+
selected,
|
|
517
|
+
labels: Object.fromEntries(placementLocaleCodes.map((code, index)=>[
|
|
518
|
+
code,
|
|
519
|
+
labels[index] ?? code
|
|
520
|
+
]))
|
|
521
|
+
};
|
|
522
|
+
}
|
|
515
523
|
// Summarize occurrences within one language and publication state first.
|
|
516
524
|
// Combine languages only when the complete displayed row agrees.
|
|
517
525
|
const languageRows = new Map();
|
|
@@ -529,14 +537,19 @@ export async function preflightData(req, { experimentId, options, placementLocal
|
|
|
529
537
|
const groups = new Map();
|
|
530
538
|
for (const indices of languageRows.values()){
|
|
531
539
|
const rows = indices.map((index)=>placements[index]), first = rows[0];
|
|
540
|
+
const slots = Object.fromEntries(BLOCK_SLOTS.map((slot)=>[
|
|
541
|
+
slot,
|
|
542
|
+
Math.min(...rows.map((row)=>row.slots[slot]))
|
|
543
|
+
]));
|
|
544
|
+
const partlyFilledSlots = first.detail === 'Draft' ? BLOCK_SLOTS.filter((slot)=>slots[slot] === 0 && rows.some((row)=>row.slots[slot] > 0)) : [];
|
|
532
545
|
const row = {
|
|
533
546
|
...first,
|
|
534
547
|
slotCount: rows.length,
|
|
535
548
|
ok: rows.every((row)=>row.ok),
|
|
536
|
-
slots
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
549
|
+
slots,
|
|
550
|
+
...partlyFilledSlots.length ? {
|
|
551
|
+
partlyFilledSlots
|
|
552
|
+
} : {}
|
|
540
553
|
};
|
|
541
554
|
const key = JSON.stringify(row);
|
|
542
555
|
const group = groups.get(key) ?? {
|
|
@@ -551,7 +564,10 @@ export async function preflightData(req, { experimentId, options, placementLocal
|
|
|
551
564
|
...groups.values()
|
|
552
565
|
].map(({ row, codes })=>({
|
|
553
566
|
...row,
|
|
554
|
-
...placementLanguages(req, codes)
|
|
567
|
+
...placementLanguages(req, codes),
|
|
568
|
+
...codes.length ? {
|
|
569
|
+
localeCodes: codes
|
|
570
|
+
} : {}
|
|
555
571
|
}));
|
|
556
572
|
}
|
|
557
573
|
for (const placement of input.flagPlacements ?? [])placements.push({
|
|
@@ -569,8 +585,16 @@ export async function preflightData(req, { experimentId, options, placementLocal
|
|
|
569
585
|
for (const arm of e.arms.filter((arm)=>arm.kind !== 'holdout')){
|
|
570
586
|
const path = arm.pageTarget ?? '';
|
|
571
587
|
let page = null;
|
|
588
|
+
let doc;
|
|
572
589
|
try {
|
|
573
590
|
page = path && collection ? await collection.findByPath(path, req) : null;
|
|
591
|
+
if (path && collection && !page) {
|
|
592
|
+
doc = await findDraftPageByPath(req, collection, path);
|
|
593
|
+
if (doc) page = {
|
|
594
|
+
id: doc.id,
|
|
595
|
+
published: false
|
|
596
|
+
};
|
|
597
|
+
}
|
|
574
598
|
} catch (cause) {
|
|
575
599
|
onPreviewFailure(cause, {
|
|
576
600
|
collection: collection.slug,
|
|
@@ -597,9 +621,8 @@ export async function preflightData(req, { experimentId, options, placementLocal
|
|
|
597
621
|
});
|
|
598
622
|
continue;
|
|
599
623
|
}
|
|
600
|
-
let doc;
|
|
601
624
|
try {
|
|
602
|
-
doc
|
|
625
|
+
doc ??= await req.payload.findByID({
|
|
603
626
|
collection: collection.slug,
|
|
604
627
|
id: page.id,
|
|
605
628
|
req,
|
|
@@ -663,7 +686,15 @@ export async function preflightData(req, { experimentId, options, placementLocal
|
|
|
663
686
|
}
|
|
664
687
|
}
|
|
665
688
|
return {
|
|
689
|
+
document: {
|
|
690
|
+
status: e.status,
|
|
691
|
+
phase: e.phase,
|
|
692
|
+
updatedAt: e.updatedAt
|
|
693
|
+
},
|
|
666
694
|
checks: checkStart(input),
|
|
695
|
+
...metric && browserWritableMetric(metric.source, options) ? {
|
|
696
|
+
browserWritablePrimaryId: metric.id
|
|
697
|
+
} : {},
|
|
667
698
|
...input.goalContent ? {
|
|
668
699
|
goalNotes: input.metrics.filter((m)=>m.source.startsWith('click:') && input.goalContent && !input.goalContent.skipped && !input.goalContent.unchecked.length && !input.goalContent.keys.some((k)=>`click:${k.key}` === m.source)).map((m)=>({
|
|
669
700
|
metricId: m.id,
|
|
@@ -671,6 +702,9 @@ export async function preflightData(req, { experimentId, options, placementLocal
|
|
|
671
702
|
}))
|
|
672
703
|
} : {},
|
|
673
704
|
placements,
|
|
705
|
+
...contentLocales ? {
|
|
706
|
+
contentLocales
|
|
707
|
+
} : {},
|
|
674
708
|
...e.kind === 'page' ? {
|
|
675
709
|
pagePlacements
|
|
676
710
|
} : {},
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import type { RoundBody } from '../types/endpoints.js';
|
|
1
2
|
import type { PayloadRequest } from 'payload';
|
|
2
3
|
import type { DocId } from '../types/contracts.js';
|
|
3
|
-
export declare function releaseHoldout(req: PayloadRequest, { experimentId }: {
|
|
4
|
+
export declare function releaseHoldout(req: PayloadRequest, { experimentId, phase: expectedPhase }: RoundBody & {
|
|
4
5
|
experimentId: DocId;
|
|
5
6
|
}): Promise<{
|
|
6
7
|
doc: import("payload").JsonObject & import("payload").TypeWithID;
|
|
@@ -1,14 +1,16 @@
|
|
|
1
|
+
import { requireCurrentRound } from './phaseRecord.js';
|
|
1
2
|
import { relationshipId } from './checkStart.js';
|
|
2
3
|
import { withTransition } from './kernel.js';
|
|
3
4
|
import { readPhaseRecord, setPhaseEndedAt } from './phaseRecord.js';
|
|
4
5
|
import { readExperiment, refuse, updateExperiment } from './start.js';
|
|
5
|
-
export async function releaseHoldout(req, { experimentId }) {
|
|
6
|
+
export async function releaseHoldout(req, { experimentId, phase: expectedPhase }) {
|
|
6
7
|
const before = await readExperiment(req, experimentId);
|
|
7
8
|
const { result: doc, revision } = await withTransition(req, {
|
|
8
9
|
experimentId,
|
|
9
10
|
layerId: relationshipId(before.layer)
|
|
10
11
|
}, async ({ req })=>{
|
|
11
12
|
const current = await readExperiment(req, experimentId);
|
|
13
|
+
requireCurrentRound(expectedPhase, current.phase);
|
|
12
14
|
const decision = current.decision;
|
|
13
15
|
if (current.status !== 'decided' || !decision?.winnerArm || decision.holdoutReleasedAt) refuse('invalid-status');
|
|
14
16
|
const phase = await readPhaseRecord(req, experimentId, current.phase);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import type { RoundBody } from '../types/endpoints.js';
|
|
1
2
|
import type { PayloadRequest } from 'payload';
|
|
2
3
|
import type { DocId } from '../types/contracts.js';
|
|
3
|
-
export declare function releasePages(req: PayloadRequest, { experimentId }: {
|
|
4
|
+
export declare function releasePages(req: PayloadRequest, { experimentId, phase: expectedPhase }: RoundBody & {
|
|
4
5
|
experimentId: DocId;
|
|
5
6
|
}): Promise<{
|
|
6
7
|
doc: import("payload").JsonObject & import("payload").TypeWithID;
|
|
@@ -1,13 +1,15 @@
|
|
|
1
|
+
import { requireCurrentRound } from './phaseRecord.js';
|
|
1
2
|
import { relationshipId } from './checkStart.js';
|
|
2
3
|
import { withTransition } from './kernel.js';
|
|
3
4
|
import { readExperiment, refuse, updateExperiment } from './start.js';
|
|
4
|
-
export async function releasePages(req, { experimentId }) {
|
|
5
|
+
export async function releasePages(req, { experimentId, phase: expectedPhase }) {
|
|
5
6
|
const before = await readExperiment(req, experimentId);
|
|
6
7
|
const { result: doc, revision } = await withTransition(req, {
|
|
7
8
|
experimentId,
|
|
8
9
|
layerId: relationshipId(before.layer)
|
|
9
10
|
}, async ({ req })=>{
|
|
10
11
|
const current = await readExperiment(req, experimentId);
|
|
12
|
+
requireCurrentRound(expectedPhase, current.phase);
|
|
11
13
|
const decision = current.decision;
|
|
12
14
|
if (current.kind !== 'page' || current.status !== 'archived' || !decision?.winnerArm || decision.discardedAt || decision.pagesReleasedAt) refuse('invalid-status');
|
|
13
15
|
const at = new Date().toISOString();
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { DocId, MetricSource } from '../types/contracts.js';
|
|
2
|
+
import type { StartExperimentWarning } from '../types/endpoints.js';
|
|
2
3
|
export interface MetricDefinition extends Record<string, unknown> {
|
|
3
4
|
id: DocId;
|
|
4
5
|
source: string;
|
|
@@ -22,8 +23,5 @@ export declare function resolveCaps(metrics: MetricDefinition[], sources: Metric
|
|
|
22
23
|
historyUnits?: number;
|
|
23
24
|
capNotice?: "no-history";
|
|
24
25
|
})[];
|
|
25
|
-
detail:
|
|
26
|
-
metricId: DocId;
|
|
27
|
-
message: string;
|
|
28
|
-
}[];
|
|
26
|
+
detail: StartExperimentWarning[];
|
|
29
27
|
}>;
|
|
@@ -3,24 +3,22 @@ import type { DocId, ResolvedOptions } from '../types/contracts.js';
|
|
|
3
3
|
import type { RefusalCode } from '../types/endpoints.js';
|
|
4
4
|
import { type StartExperiment } from './checkStart.js';
|
|
5
5
|
export type TransitionExperiment = StartExperiment & Record<string, unknown> & {
|
|
6
|
-
phase?: number;
|
|
7
6
|
seed?: string;
|
|
8
|
-
updatedAt?: string;
|
|
9
7
|
layerSlices?: number[] | null;
|
|
10
8
|
};
|
|
11
9
|
export declare function readExperiment(req: PayloadRequest, id: DocId): Promise<TransitionExperiment>;
|
|
12
|
-
export declare function refuse(code: RefusalCode, detail?: unknown): never;
|
|
13
|
-
export declare function updateExperiment(req: PayloadRequest, id: DocId, data: Record<string, unknown
|
|
10
|
+
export declare function refuse(code: RefusalCode, detail?: unknown, controlLabel?: string): never;
|
|
11
|
+
export declare function updateExperiment(req: PayloadRequest, id: DocId, data: Record<string, unknown>, system?: boolean): Promise<import("payload").JsonObject & import("payload").TypeWithID>;
|
|
14
12
|
export declare function start<TUser extends {
|
|
15
13
|
id: DocId;
|
|
16
|
-
}>(req: PayloadRequest, { experimentId, options }: {
|
|
14
|
+
}>(req: PayloadRequest, { experimentId, options, phase: expectedPhase, system, onlyIfNeverStarted, }: {
|
|
17
15
|
experimentId: DocId;
|
|
18
16
|
options: ResolvedOptions<TUser>;
|
|
17
|
+
phase?: number;
|
|
18
|
+
system?: boolean;
|
|
19
|
+
onlyIfNeverStarted?: boolean;
|
|
19
20
|
}): Promise<{
|
|
20
|
-
detail?:
|
|
21
|
-
metricId: DocId;
|
|
22
|
-
message: string;
|
|
23
|
-
}[] | undefined;
|
|
21
|
+
detail?: import("../types/endpoints.js").StartExperimentWarning[] | undefined;
|
|
24
22
|
doc: import("payload").JsonObject & import("payload").TypeWithID;
|
|
25
23
|
revision: number;
|
|
26
24
|
}>;
|
|
@@ -1,22 +1,26 @@
|
|
|
1
|
+
import { withSlotsFor } from '../arms/model.js';
|
|
1
2
|
import { nestedPlacementNames, nameNestedPlacements } from './nestedPlacementNames.js';
|
|
2
3
|
import { nestedTestCopy } from '../puck/nestedTestCopy.js';
|
|
3
4
|
import { goalContent } from '../goals/fairness.js';
|
|
5
|
+
import { browserWritableMetric } from '../events/writable.js';
|
|
4
6
|
import { detached } from './placementInteractions.js';
|
|
5
7
|
import { lockAndRescanPlacements, placementInteractions } from './placementInteractions.js';
|
|
6
8
|
import { lockPagePaths } from '../db/locks.js';
|
|
7
9
|
import { lockMetricsForFreeze } from '../db/metricUsage.js';
|
|
8
10
|
import { DEFAULT_SEQUENTIAL_TUNING_PARAMETER } from '../constants.js';
|
|
9
11
|
import { claimSlices } from '../db/slices.js';
|
|
10
|
-
import { READINESS_COPY, asymmetricGoalsCopy, sameAddressCopy, interactingTestsCopy, pageInUseCopy, unpublishedPageCopy } from '../testSurface/copy/readiness.js';
|
|
12
|
+
import { READINESS_COPY, asymmetricGoalsCopy, firstStartOnlyCopy, sameAddressCopy, interactingTestsCopy, pageInUseCopy, unpublishedPageCopy } from '../testSurface/copy/readiness.js';
|
|
11
13
|
import { GROUP_LABELS } from '../testSurface/copy/arms.js';
|
|
14
|
+
import { controlVersionLabel } from '../labels/arms.js';
|
|
12
15
|
import { XpRefusal } from '../errors.js';
|
|
13
16
|
import { isOpValid } from '../targeting/ops.js';
|
|
14
17
|
import { newSeed } from '../runtime/seed.js';
|
|
15
18
|
import { checkStart, pageTargetPaths, relationshipId } from './checkStart.js';
|
|
16
19
|
import { withTransition } from './kernel.js';
|
|
17
|
-
import { writePhaseRecord } from './phaseRecord.js';
|
|
18
|
-
import { loadPageTestsInUse,
|
|
20
|
+
import { requireCurrentRound, writePhaseRecord } from './phaseRecord.js';
|
|
21
|
+
import { loadPageTestsInUse, loadStartInputsBatch, readStartInputExperiment, unpublishedPageTargets } from './preflightData.js';
|
|
19
22
|
import { resolveCaps } from './resolveCaps.js';
|
|
23
|
+
import { findStartDocuments, readStartState } from './startReads.js';
|
|
20
24
|
export async function readExperiment(req, id) {
|
|
21
25
|
// §7.8: internal lookup serves the authorised transition write. Preserve
|
|
22
26
|
// admin-only analysis.method/kind for freezing; return access-filtered docs.
|
|
@@ -35,7 +39,8 @@ export async function readExperiment(req, id) {
|
|
|
35
39
|
if (!docs[0]) throw new XpRefusal('not-found', 'Experiment not found', undefined, 404);
|
|
36
40
|
return docs[0];
|
|
37
41
|
}
|
|
38
|
-
export function refuse(code, detail) {
|
|
42
|
+
export function refuse(code, detail, controlLabel) {
|
|
43
|
+
const groupLabel = (key)=>key === 'control' ? controlVersionLabel(controlLabel) : GROUP_LABELS[key];
|
|
39
44
|
const messages = {
|
|
40
45
|
'nested-tests': nestedTestCopy.readiness(detail),
|
|
41
46
|
'goal-in-some-versions': asymmetricGoalsCopy(detail),
|
|
@@ -50,7 +55,7 @@ export function refuse(code, detail) {
|
|
|
50
55
|
'page-in-use': pageInUseCopy(detail?.paths?.[0] ?? 'this page'),
|
|
51
56
|
'version-same-address': (()=>{
|
|
52
57
|
const d = detail;
|
|
53
|
-
return sameAddressCopy(
|
|
58
|
+
return sameAddressCopy(groupLabel(d?.arm ?? 'variantA'), groupLabel(d?.otherArm ?? 'control'), d?.path ?? 'this address');
|
|
54
59
|
})(),
|
|
55
60
|
'page-target-unpublished': unpublishedPageCopy(typeof detail === 'string' ? detail : 'This page'),
|
|
56
61
|
'invalid-status': 'This action is not available in the current status.',
|
|
@@ -82,15 +87,16 @@ export function refuse(code, detail) {
|
|
|
82
87
|
].includes(code);
|
|
83
88
|
throw new XpRefusal(code, messages[code] ?? 'The experiment is not ready to start.', detail, code === 'entry-not-found' ? 404 : conflict ? 409 : 422);
|
|
84
89
|
}
|
|
85
|
-
export async function updateExperiment(req, id, data) {
|
|
86
|
-
// §7.8:
|
|
87
|
-
await req.payload.update({
|
|
90
|
+
export async function updateExperiment(req, id, data, system = false) {
|
|
91
|
+
// §7.8: an authorized manager transition or trusted system Start writes locked plugin fields.
|
|
92
|
+
const updated = await req.payload.update({
|
|
88
93
|
collection: 'xp-experiments',
|
|
89
94
|
req,
|
|
90
95
|
id,
|
|
91
96
|
data,
|
|
92
97
|
overrideAccess: true
|
|
93
98
|
});
|
|
99
|
+
if (system) return updated;
|
|
94
100
|
const { docs } = await req.payload.find({
|
|
95
101
|
collection: 'xp-experiments',
|
|
96
102
|
req,
|
|
@@ -106,43 +112,74 @@ export async function updateExperiment(req, id, data) {
|
|
|
106
112
|
if (!docs[0]) throw new XpRefusal('not-found', 'Experiment not found', undefined, 404);
|
|
107
113
|
return docs[0];
|
|
108
114
|
}
|
|
109
|
-
|
|
110
|
-
const input = await
|
|
115
|
+
async function prepareStart(req, options, before, system) {
|
|
116
|
+
const input = (await loadStartInputsBatch(req, options, [
|
|
117
|
+
before
|
|
118
|
+
], false, system)).get(String(before.id));
|
|
111
119
|
if (!input) throw new XpRefusal('not-found', 'Experiment not found', undefined, 404);
|
|
112
|
-
const full = await readExperiment(req,
|
|
113
|
-
if (full.updatedAt !==
|
|
120
|
+
const full = await readExperiment(req, before.id);
|
|
121
|
+
if (full.updatedAt !== before.updatedAt) refuse('stale-draft');
|
|
114
122
|
// Review reads respect field access; internal writes must preserve hidden config.
|
|
115
123
|
input.experiment = {
|
|
116
|
-
...
|
|
124
|
+
...before,
|
|
117
125
|
kind: full.kind,
|
|
118
126
|
analysis: full.analysis
|
|
119
127
|
};
|
|
120
128
|
// Warning-only codes always have ok: true. These exclusions narrow
|
|
121
129
|
// ReadinessCode to RefusalCode, which intentionally excludes warnings.
|
|
122
130
|
const failed = checkStart(input).find((check)=>!check.ok);
|
|
123
|
-
if (failed && failed.code !== 'page-targets-unchecked' && failed.code !== 'make-content-unsupported') refuse(failed.code, failed.detail);
|
|
124
|
-
const before = input.experiment;
|
|
125
|
-
const updatedAt = before.updatedAt;
|
|
131
|
+
if (failed && failed.code !== 'page-targets-unchecked' && failed.code !== 'make-content-unsupported') refuse(failed.code, failed.detail, before.arms.find((arm)=>arm.kind === 'control')?.label);
|
|
126
132
|
const at = new Date();
|
|
127
133
|
const caps = await resolveCaps(input.metrics, options.metricSources ?? [], at);
|
|
128
|
-
|
|
134
|
+
return {
|
|
135
|
+
input,
|
|
136
|
+
at,
|
|
137
|
+
caps
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
export async function start(req, { experimentId, options, phase: expectedPhase, system = false, onlyIfNeverStarted = false }) {
|
|
141
|
+
const before = await readStartInputExperiment(req, experimentId, system);
|
|
142
|
+
if (!before) throw new XpRefusal('not-found', 'Experiment not found', undefined, 404);
|
|
143
|
+
const { updatedAt } = before;
|
|
144
|
+
const prepared = await prepareStart(req, options, before, system).catch((error)=>{
|
|
145
|
+
if (!onlyIfNeverStarted && expectedPhase === undefined) throw error;
|
|
146
|
+
// Conditional Start checks the locked document before reporting a preflight failure.
|
|
147
|
+
return {
|
|
148
|
+
error
|
|
149
|
+
};
|
|
150
|
+
});
|
|
151
|
+
const kind = 'error' in prepared ? before.kind : prepared.input.experiment.kind;
|
|
152
|
+
const { result: { doc, detail }, revision } = await withTransition(req, {
|
|
129
153
|
experimentId,
|
|
130
154
|
layerId: relationshipId(before.layer),
|
|
131
|
-
flagPointId:
|
|
155
|
+
flagPointId: kind === 'flag' ? before.flagPoint : undefined,
|
|
156
|
+
requireOwnedTransaction: system
|
|
132
157
|
}, async ({ req, exec })=>{
|
|
133
158
|
const current = await readExperiment(req, experimentId);
|
|
159
|
+
// A concurrent Start or Stop must yield the locked status before considering a stale snapshot.
|
|
160
|
+
if (onlyIfNeverStarted && (current.status !== 'draft' || (current.phase ?? 0) !== 0)) {
|
|
161
|
+
const detail = {
|
|
162
|
+
status: current.status,
|
|
163
|
+
phase: current.phase ?? 0
|
|
164
|
+
};
|
|
165
|
+
throw new XpRefusal('first-start-only', firstStartOnlyCopy(current.status), detail, 409);
|
|
166
|
+
}
|
|
167
|
+
requireCurrentRound(expectedPhase, current.phase);
|
|
134
168
|
if (current.updatedAt !== updatedAt) refuse('stale-draft');
|
|
135
169
|
if (current.status !== 'draft' && current.status !== 'stopped') refuse('invalid-status');
|
|
170
|
+
if ('error' in prepared) throw prepared.error;
|
|
171
|
+
const { input, at, caps } = prepared;
|
|
172
|
+
const controlLabel = current.arms.find((arm)=>arm.kind === 'control')?.label;
|
|
136
173
|
let placementDocs;
|
|
137
174
|
if (current.kind === 'block') {
|
|
138
|
-
const rescan = await lockAndRescanPlacements(req, exec, options, current, input.placements ?? []);
|
|
175
|
+
const rescan = await lockAndRescanPlacements(req, exec, options, current, input.placements ?? [], system);
|
|
139
176
|
placementDocs = rescan.docs;
|
|
140
177
|
const failure = checkStart({
|
|
141
178
|
...input,
|
|
142
179
|
experiment: current,
|
|
143
|
-
placements: nameNestedPlacements(rescan.placements, await nestedPlacementNames(req, rescan.placements))
|
|
180
|
+
placements: nameNestedPlacements(rescan.placements, await nestedPlacementNames(req, rescan.placements, system))
|
|
144
181
|
}).find((check)=>!check.ok);
|
|
145
|
-
if (failure && failure.code !== 'page-targets-unchecked' && failure.code !== 'make-content-unsupported') refuse(failure.code, failure.detail);
|
|
182
|
+
if (failure && failure.code !== 'page-targets-unchecked' && failure.code !== 'make-content-unsupported') refuse(failure.code, failure.detail, controlLabel);
|
|
146
183
|
}
|
|
147
184
|
if (current.kind === 'page') {
|
|
148
185
|
// Independent experiment/layer locks do not serialize overlapping pages.
|
|
@@ -155,7 +192,7 @@ export async function start(req, { experimentId, options }) {
|
|
|
155
192
|
pageTestsInUse: await loadPageTestsInUse(req)
|
|
156
193
|
}).find((check)=>check.code === 'page-in-use' && !check.ok);
|
|
157
194
|
if (recheck) refuse('page-in-use', recheck.detail);
|
|
158
|
-
const conflicts = await placementInteractions(req, exec, options, current, pageTargetPaths(current.arms));
|
|
195
|
+
const conflicts = await placementInteractions(req, exec, options, current, pageTargetPaths(current.arms), system);
|
|
159
196
|
if (conflicts.length) refuse('interacting-tests', conflicts);
|
|
160
197
|
if (options.pages) {
|
|
161
198
|
// The page guard takes the same path locks, so a delete, unpublish or rename that committed
|
|
@@ -174,10 +211,8 @@ export async function start(req, { experimentId, options }) {
|
|
|
174
211
|
}
|
|
175
212
|
}
|
|
176
213
|
if (current.kind === 'flag' && current.flagPoint) {
|
|
177
|
-
const busy = await req
|
|
214
|
+
const busy = await findStartDocuments(req, {
|
|
178
215
|
collection: 'xp-experiments',
|
|
179
|
-
req,
|
|
180
|
-
overrideAccess: false,
|
|
181
216
|
depth: 0,
|
|
182
217
|
limit: 2,
|
|
183
218
|
where: {
|
|
@@ -197,15 +232,10 @@ export async function start(req, { experimentId, options }) {
|
|
|
197
232
|
}
|
|
198
233
|
]
|
|
199
234
|
}
|
|
200
|
-
});
|
|
235
|
+
}, system);
|
|
201
236
|
if (busy.docs.some((doc)=>String(doc.id) !== String(experimentId))) refuse('flag-point-busy');
|
|
202
237
|
const point = options.flagPoints.find((point)=>point.id === current.flagPoint);
|
|
203
|
-
const state = await req
|
|
204
|
-
slug: 'xp-state',
|
|
205
|
-
req,
|
|
206
|
-
overrideAccess: false,
|
|
207
|
-
depth: 0
|
|
208
|
-
});
|
|
238
|
+
const state = await readStartState(req, system);
|
|
209
239
|
const defaults = state.flagDefaults;
|
|
210
240
|
current.arms = current.arms.map((arm)=>arm.kind === 'control' ? {
|
|
211
241
|
...arm,
|
|
@@ -215,7 +245,7 @@ export async function start(req, { experimentId, options }) {
|
|
|
215
245
|
...input,
|
|
216
246
|
experiment: current
|
|
217
247
|
}).find((check)=>!check.ok);
|
|
218
|
-
if (recheck && recheck.code !== 'page-targets-unchecked' && recheck.code !== 'make-content-unsupported') refuse(recheck.code, recheck.detail);
|
|
248
|
+
if (recheck && recheck.code !== 'page-targets-unchecked' && recheck.code !== 'make-content-unsupported') refuse(recheck.code, recheck.detail, controlLabel);
|
|
219
249
|
}
|
|
220
250
|
if (input.metrics.some((metric)=>metric.source.startsWith('click:'))) {
|
|
221
251
|
const content = await detached(req, ()=>goalContent(req, options, current, placementDocs));
|
|
@@ -265,15 +295,17 @@ export async function start(req, { experimentId, options }) {
|
|
|
265
295
|
...metric,
|
|
266
296
|
metricId: metric.id,
|
|
267
297
|
addedAt: startedAt,
|
|
298
|
+
browserWritable: browserWritableMetric(metric.source, options),
|
|
268
299
|
role: String(relationshipId(current.metrics?.primary)) === String(metric.id) ? 'primary' : current.metrics?.guardrails?.some((id)=>String(relationshipId(id)) === String(metric.id)) ? 'guardrail' : 'secondary'
|
|
269
300
|
}));
|
|
301
|
+
const arms = current.kind === 'block' ? withSlotsFor(current.arms, 'block') : current.arms;
|
|
270
302
|
await writePhaseRecord(req, {
|
|
271
303
|
experiment: experimentId,
|
|
272
304
|
phase,
|
|
273
305
|
phaseKind: 'test',
|
|
274
306
|
seed,
|
|
275
307
|
startedAt,
|
|
276
|
-
arms
|
|
308
|
+
arms,
|
|
277
309
|
allocation: current.allocation,
|
|
278
310
|
allocationChanges: [],
|
|
279
311
|
targeting,
|
|
@@ -303,21 +335,25 @@ export async function start(req, { experimentId, options }) {
|
|
|
303
335
|
},
|
|
304
336
|
contentChanges: []
|
|
305
337
|
});
|
|
306
|
-
|
|
338
|
+
const doc = await updateExperiment(req, experimentId, {
|
|
307
339
|
status: 'running',
|
|
308
340
|
phase,
|
|
309
341
|
seed,
|
|
310
342
|
startedAt,
|
|
311
343
|
stoppedAt: null,
|
|
312
344
|
layerSlices,
|
|
313
|
-
arms
|
|
314
|
-
});
|
|
345
|
+
arms
|
|
346
|
+
}, system);
|
|
347
|
+
return {
|
|
348
|
+
doc,
|
|
349
|
+
detail: caps.detail
|
|
350
|
+
};
|
|
315
351
|
});
|
|
316
352
|
return {
|
|
317
353
|
doc,
|
|
318
354
|
revision: revision,
|
|
319
|
-
...
|
|
320
|
-
detail
|
|
355
|
+
...detail.length ? {
|
|
356
|
+
detail
|
|
321
357
|
} : {}
|
|
322
358
|
};
|
|
323
359
|
}
|