@delmaredigital/payload-experiments 0.4.0-rc.7 → 0.4.0-rc.9
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 +12 -12
- package/dist/admin/blocks/model.js +2 -2
- package/dist/admin/copy/blocks.js +1 -1
- package/dist/admin/surface/ResultsRoute.js +17 -11
- package/dist/admin/surface/TestsHome.js +53 -20
- package/dist/admin/surface/newTest/PageWizard.js +8 -2
- package/dist/admin/surface/results/ResultsHeader.js +11 -6
- package/dist/admin/surface/test/TestPage.js +3 -3
- package/dist/blocks/formState.js +1 -1
- 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/metricsGuards.js +2 -0
- package/dist/collections/serialize.js +5 -4
- 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/results.d.ts +5 -1
- package/dist/db/results.js +21 -5
- package/dist/db/snapshots.d.ts +1 -0
- package/dist/endpoints/deleteImpact.js +2 -1
- package/dist/endpoints/events.js +103 -39
- package/dist/endpoints/index.js +2 -8
- package/dist/endpoints/placementStatus.js +7 -4
- package/dist/endpoints/results.d.ts +1 -1
- package/dist/endpoints/results.js +6 -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/transitions.js +37 -24
- 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/hooks/hostHook.js +6 -2
- package/dist/hooks/pageGuard.js +4 -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.js +5 -0
- 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.js +5 -4
- package/dist/puck/editor/ExperimentSlotEditor.js +182 -58
- package/dist/puck/editor/QuickTestActions.d.ts +5 -2
- package/dist/puck/editor/QuickTestActions.js +16 -4
- package/dist/puck/editor/ResultsReadout.d.ts +2 -1
- package/dist/puck/editor/ResultsReadout.js +2 -1
- package/dist/puck/editor/VersionBuilder.d.ts +13 -2
- package/dist/puck/editor/VersionBuilder.js +133 -49
- package/dist/puck/editor/armWrites.js +1 -1
- package/dist/puck/editor/armsCache.js +1 -3
- package/dist/puck/editor/copy.d.ts +4 -1
- package/dist/puck/editor/copy.js +4 -1
- package/dist/puck/editor/editor.chrome.css +1 -0
- package/dist/puck/editor/editor.css +1 -0
- package/dist/puck/editor/editor.model.d.ts +1 -0
- package/dist/puck/editor/placementsCache.d.ts +5 -1
- package/dist/puck/editor/placementsCache.js +17 -9
- package/dist/puck/editor/usePageSaveReadiness.d.ts +9 -0
- package/dist/puck/editor/usePageSaveReadiness.js +34 -0
- package/dist/puck/editor/usePlacementNotice.d.ts +2 -2
- package/dist/puck/editor/usePlacementNotice.js +5 -4
- package/dist/results/aggregate.d.ts +6 -3
- package/dist/results/aggregate.js +9 -9
- 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.js +2 -1
- 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 +52 -14
- 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/actions/DecideDialog.d.ts +4 -1
- package/dist/testSurface/actions/DecideDialog.js +32 -14
- package/dist/testSurface/actions/MakeContentResult.d.ts +4 -3
- package/dist/testSurface/actions/MakeContentResult.js +9 -1
- package/dist/testSurface/api.d.ts +5 -5
- package/dist/testSurface/api.js +21 -9
- package/dist/testSurface/copy/actions.d.ts +1 -0
- package/dist/testSurface/copy/actions.js +1 -0
- package/dist/testSurface/copy/common.d.ts +3 -1
- package/dist/testSurface/copy/common.js +4 -2
- package/dist/testSurface/copy/languages.d.ts +1 -0
- package/dist/testSurface/copy/languages.js +1 -0
- package/dist/testSurface/copy/metrics.d.ts +1 -0
- package/dist/testSurface/copy/metrics.js +1 -0
- package/dist/testSurface/copy/readiness.d.ts +12 -1
- package/dist/testSurface/copy/readiness.js +18 -1
- package/dist/testSurface/copy/results.d.ts +5 -2
- package/dist/testSurface/copy/results.js +5 -2
- package/dist/testSurface/copy/testPage.d.ts +20 -2
- package/dist/testSurface/copy/testPage.js +34 -3
- package/dist/testSurface/readPreflight.d.ts +5 -0
- package/dist/testSurface/readPreflight.js +7 -0
- package/dist/testSurface/readinessRead.d.ts +3 -0
- package/dist/testSurface/readinessRead.js +4 -0
- package/dist/testSurface/results/VerdictHero.d.ts +2 -1
- package/dist/testSurface/results/VerdictHero.js +5 -1
- package/dist/testSurface/results/results.model.d.ts +1 -1
- package/dist/testSurface/results/results.model.js +6 -2
- package/dist/testSurface/surface/contracts.d.ts +8 -1
- package/dist/testSurface/surface/editorPlacement.d.ts +2 -2
- package/dist/testSurface/surface/editorPlacement.js +1 -1
- package/dist/testSurface/surface/pageBlock/pageBlock.model.js +2 -2
- package/dist/testSurface/surface/pagePicker/PageCombobox.js +20 -6
- package/dist/testSurface/surface/readiness/ActionDialogs.d.ts +4 -2
- package/dist/testSurface/surface/readiness/ActionDialogs.js +39 -34
- package/dist/testSurface/surface/readiness/Banner.js +23 -12
- package/dist/testSurface/surface/readiness/SaveStatus.d.ts +4 -3
- package/dist/testSurface/surface/readiness/SaveStatus.js +15 -15
- package/dist/testSurface/surface/readiness/readiness.model.d.ts +6 -1
- package/dist/testSurface/surface/readiness/readiness.model.js +108 -11
- package/dist/testSurface/surface/readiness/useTransition.d.ts +4 -4
- package/dist/testSurface/surface/readiness/useTransition.js +12 -10
- package/dist/testSurface/surface/results/ReleasePages.d.ts +4 -2
- package/dist/testSurface/surface/results/ReleasePages.js +5 -4
- package/dist/testSurface/surface/results/ResultsBody.d.ts +4 -2
- package/dist/testSurface/surface/results/ResultsBody.js +86 -43
- package/dist/testSurface/surface/results/useResults.d.ts +7 -6
- package/dist/testSurface/surface/results/useResults.js +3 -2
- package/dist/testSurface/surface/setting/parts.js +58 -18
- package/dist/testSurface/surface/test/AdvancedSection.js +1 -0
- package/dist/testSurface/surface/test/DeleteTest.d.ts +6 -2
- package/dist/testSurface/surface/test/DeleteTest.js +145 -54
- package/dist/testSurface/surface/test/GoalSection.js +7 -3
- package/dist/testSurface/surface/test/LengthSection.js +3 -0
- package/dist/testSurface/surface/test/PageHoldout.js +4 -1
- package/dist/testSurface/surface/test/ReadinessBar.js +1 -1
- package/dist/testSurface/surface/test/TargetingSection.js +77 -12
- package/dist/testSurface/surface/test/TestSurface.js +81 -19
- package/dist/testSurface/surface/test/VersionsSection.js +56 -29
- package/dist/testSurface/surface/test/fields.d.ts +29 -4
- package/dist/testSurface/surface/test/fields.js +159 -39
- package/dist/testSurface/surface/test/pageParts.js +14 -5
- 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 +22 -4
- package/dist/testSurface/surface/useTestDocument.js +407 -160
- package/dist/testSurface/useApi.d.ts +5 -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 +1 -4
- 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 +2 -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/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 +67 -41
- 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 +6 -8
- package/dist/transitions/start.js +67 -34
- 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/contracts.d.ts +6 -3
- package/dist/types/endpoints.d.ts +52 -9
- package/dist/types/runtime.d.ts +15 -9
- package/dist/types/snapshot.d.ts +2 -0
- package/dist/ui/ChipsInput.d.ts +8 -1
- package/dist/ui/ChipsInput.js +17 -4
- package/package.json +2 -2
|
@@ -16,9 +16,9 @@ const slots = [
|
|
|
16
16
|
'variantB',
|
|
17
17
|
'variantC'
|
|
18
18
|
];
|
|
19
|
-
async function placementDocuments(req, query,
|
|
20
|
-
// §7.8 page
|
|
21
|
-
if (
|
|
19
|
+
async function placementDocuments(req, query, readAll) {
|
|
20
|
+
// §7.8: page guards, visitor impact and system Start need all placements to check the visitor surface.
|
|
21
|
+
if (readAll) return req.payload.find({
|
|
22
22
|
...query,
|
|
23
23
|
req,
|
|
24
24
|
overrideAccess: true
|
|
@@ -245,7 +245,7 @@ export async function scanBlockPlacements(req, args) {
|
|
|
245
245
|
}
|
|
246
246
|
}
|
|
247
247
|
} : {}
|
|
248
|
-
}, args.pageGuard);
|
|
248
|
+
}, args.pageGuard || args.system);
|
|
249
249
|
for (const localized of changedDocuments(result.docs, args.change, collection, draft, page, Boolean(draftsEnabled)))for (const view of reader.views){
|
|
250
250
|
const doc = reader.read(localized, 'all-locales', view).doc;
|
|
251
251
|
const documentKey = JSON.stringify([
|
|
@@ -382,7 +382,7 @@ export async function scanBlockPlacements(req, args) {
|
|
|
382
382
|
}
|
|
383
383
|
}
|
|
384
384
|
} : {}
|
|
385
|
-
}, args.pageGuard);
|
|
385
|
+
}, args.pageGuard || args.system);
|
|
386
386
|
for (const localized of changedDocuments(result.docs, args.change, collection, draft, page, Boolean(draftsEnabled)))for (const view of reader.views){
|
|
387
387
|
const doc = reader.read(localized, 'all-locales', view).doc;
|
|
388
388
|
const documentKey = JSON.stringify([
|
|
@@ -10,9 +10,10 @@ export interface PreflightDependencies {
|
|
|
10
10
|
/** Read-only inputs shared with Start's pre-transaction checks. Start must re-read
|
|
11
11
|
* the document and lock-sensitive facts inside its transition (CORE-10b).
|
|
12
12
|
*/
|
|
13
|
+
export declare function readStartInputExperiment(req: PayloadRequest, experimentId: DocId, system?: boolean): Promise<StartExperiment | null>;
|
|
13
14
|
export declare function loadStartInputs<TUser extends {
|
|
14
15
|
id: DocId;
|
|
15
|
-
}>(req: PayloadRequest, options: ResolvedOptions<TUser>, experimentId: DocId): Promise<CheckStartInput | null>;
|
|
16
|
+
}>(req: PayloadRequest, options: ResolvedOptions<TUser>, experimentId: DocId, system?: boolean): Promise<CheckStartInput | null>;
|
|
16
17
|
/** Occupancy from the arms the runtime routes on (frozen rounds), shared by preflight and
|
|
17
18
|
* Start's locked recheck. Raw SQL on the request's transaction when there is one. */
|
|
18
19
|
export declare function loadPageTestsInUse(req: PayloadRequest): Promise<NonNullable<CheckStartInput['pageTestsInUse']>>;
|
|
@@ -26,7 +27,7 @@ export declare function unpublishedPageTargets<TUser extends {
|
|
|
26
27
|
*/
|
|
27
28
|
export declare function loadStartInputsBatch<TUser extends {
|
|
28
29
|
id: DocId;
|
|
29
|
-
}>(req: PayloadRequest, options: ResolvedOptions<TUser>, experiments: StartExperiment[], tolerateErrors?: boolean): Promise<Map<string, CheckStartInput | null>>;
|
|
30
|
+
}>(req: PayloadRequest, options: ResolvedOptions<TUser>, experiments: StartExperiment[], tolerateErrors?: boolean, system?: boolean): Promise<Map<string, CheckStartInput | null>>;
|
|
30
31
|
export declare function preflightData<TUser extends {
|
|
31
32
|
id: DocId;
|
|
32
33
|
}>(req: PayloadRequest, { experimentId, options, placementLocale }: {
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { nestedPlacementNames, nameNestedPlacements } from './nestedPlacementNames.js';
|
|
2
2
|
import { placementReader } from '../blocks/placementLocale.js';
|
|
3
|
-
import {
|
|
3
|
+
import { BLOCK_SLOTS } from '../blocks/model.js';
|
|
4
|
+
import { placementLanguageNames, placementLanguages } from '../blocks/placementLanguages.js';
|
|
4
5
|
import { goalContent, OUTSIDE_GOAL } from '../goals/fairness.js';
|
|
6
|
+
import { browserWritableMetric } from '../events/writable.js';
|
|
5
7
|
import { placementInteractions, placementPaths, uniquePlacementDocs } from './placementInteractions.js';
|
|
6
8
|
import { Forbidden, NotFound } from 'payload';
|
|
7
9
|
import { normalisePath } from '../runtime/normalisePath.js';
|
|
@@ -13,17 +15,16 @@ import { checkStart, relationshipId } from './checkStart.js';
|
|
|
13
15
|
import { flagPlacements, scanBlockPlacements } from './placements.js';
|
|
14
16
|
import { routedPageTests } from '../db/pageOccupancy.js';
|
|
15
17
|
import { pooledExecutor, txExecutor } from '../db/executor.js';
|
|
18
|
+
import { findStartDocuments, readStartState } from './startReads.js';
|
|
16
19
|
const failureDetail = (cause)=>{
|
|
17
20
|
const name = cause instanceof Error ? cause.name : undefined;
|
|
18
21
|
return cause instanceof Forbidden || name === 'Forbidden' ? 'forbidden' : cause instanceof NotFound || name === 'NotFound' ? 'not-found' : 'placements-failed';
|
|
19
22
|
};
|
|
20
23
|
/** Read-only inputs shared with Start's pre-transaction checks. Start must re-read
|
|
21
24
|
* the document and lock-sensitive facts inside its transition (CORE-10b).
|
|
22
|
-
*/ export async function
|
|
23
|
-
const found = await req
|
|
25
|
+
*/ export async function readStartInputExperiment(req, experimentId, system = false) {
|
|
26
|
+
const found = await findStartDocuments(req, {
|
|
24
27
|
collection: 'xp-experiments',
|
|
25
|
-
req,
|
|
26
|
-
overrideAccess: false,
|
|
27
28
|
depth: 0,
|
|
28
29
|
limit: 1,
|
|
29
30
|
where: {
|
|
@@ -31,12 +32,15 @@ const failureDetail = (cause)=>{
|
|
|
31
32
|
equals: experimentId
|
|
32
33
|
}
|
|
33
34
|
}
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
|
|
35
|
+
}, system);
|
|
36
|
+
return found.docs[0] ?? null;
|
|
37
|
+
}
|
|
38
|
+
export async function loadStartInputs(req, options, experimentId, system = false) {
|
|
39
|
+
const experiment = await readStartInputExperiment(req, experimentId, system);
|
|
40
|
+
if (!experiment) return null;
|
|
37
41
|
return (await loadStartInputsBatch(req, options, [
|
|
38
42
|
experiment
|
|
39
|
-
])).get(String(experiment.id)) ?? null;
|
|
43
|
+
], false, system)).get(String(experiment.id)) ?? null;
|
|
40
44
|
}
|
|
41
45
|
/** Occupancy from the arms the runtime routes on (frozen rounds), shared by preflight and
|
|
42
46
|
* Start's locked recheck. Raw SQL on the request's transaction when there is one. */ export async function loadPageTestsInUse(req) {
|
|
@@ -74,16 +78,14 @@ const metricIds = (experiment)=>[
|
|
|
74
78
|
].map(relationshipId).filter((id)=>id !== undefined);
|
|
75
79
|
/** Shared, request-scoped reads for summary; a failed row is null in tolerant mode.
|
|
76
80
|
* Preflight/Start use the same builder and retain their throwing read behaviour.
|
|
77
|
-
*/ export async function loadStartInputsBatch(req, options, experiments, tolerateErrors = false) {
|
|
81
|
+
*/ export async function loadStartInputsBatch(req, options, experiments, tolerateErrors = false, system = false) {
|
|
78
82
|
const ids = [
|
|
79
83
|
...new Set(experiments.flatMap(metricIds))
|
|
80
84
|
];
|
|
81
85
|
const metrics = (async ()=>{
|
|
82
86
|
if (!ids.length) return [];
|
|
83
|
-
const result = await req
|
|
87
|
+
const result = await findStartDocuments(req, {
|
|
84
88
|
collection: 'xp-metrics',
|
|
85
|
-
req,
|
|
86
|
-
overrideAccess: false,
|
|
87
89
|
depth: 0,
|
|
88
90
|
pagination: false,
|
|
89
91
|
limit: ids.length,
|
|
@@ -92,7 +94,7 @@ const metricIds = (experiment)=>[
|
|
|
92
94
|
in: ids
|
|
93
95
|
}
|
|
94
96
|
}
|
|
95
|
-
});
|
|
97
|
+
}, system);
|
|
96
98
|
return result.docs;
|
|
97
99
|
})();
|
|
98
100
|
const blockSlugs = new Set(experiments.filter((e)=>e.kind === 'block').map((e)=>e.slug));
|
|
@@ -144,13 +146,14 @@ const metricIds = (experiment)=>[
|
|
|
144
146
|
slugs: blockSlugs,
|
|
145
147
|
compareVersions: true,
|
|
146
148
|
puckCollections: options.puck?.collections ?? [],
|
|
147
|
-
blocksCollections: options.blocks?.collections ?? []
|
|
149
|
+
blocksCollections: options.blocks?.collections ?? [],
|
|
150
|
+
system
|
|
148
151
|
});
|
|
149
152
|
input.placements = (await blocks).get(experiment.slug) ?? [];
|
|
150
153
|
if (input.placements.some((p)=>p.nestedTests?.length)) {
|
|
151
154
|
nestedNames ??= nestedPlacementNames(req, [
|
|
152
155
|
...(await blocks).values()
|
|
153
|
-
].flat());
|
|
156
|
+
].flat(), system);
|
|
154
157
|
input.placements = nameNestedPlacements(input.placements, await nestedNames);
|
|
155
158
|
}
|
|
156
159
|
} catch (cause) {
|
|
@@ -162,12 +165,7 @@ const metricIds = (experiment)=>[
|
|
|
162
165
|
if (point) {
|
|
163
166
|
state ??= (async ()=>{
|
|
164
167
|
try {
|
|
165
|
-
const doc = await req
|
|
166
|
-
slug: 'xp-state',
|
|
167
|
-
req,
|
|
168
|
-
overrideAccess: false,
|
|
169
|
-
depth: 0
|
|
170
|
-
});
|
|
168
|
+
const doc = await readStartState(req, system);
|
|
171
169
|
return doc.flagDefaults;
|
|
172
170
|
} catch (cause) {
|
|
173
171
|
const error = cause;
|
|
@@ -195,10 +193,8 @@ const metricIds = (experiment)=>[
|
|
|
195
193
|
const key = experiment.flagPoint;
|
|
196
194
|
if (!busyPoints.has(key)) busyPoints.set(key, (async ()=>{
|
|
197
195
|
// Two rows suffice to find a peer, including when the batch contains that peer.
|
|
198
|
-
const busy = await req
|
|
196
|
+
const busy = await findStartDocuments(req, {
|
|
199
197
|
collection: 'xp-experiments',
|
|
200
|
-
req,
|
|
201
|
-
overrideAccess: false,
|
|
202
198
|
depth: 0,
|
|
203
199
|
limit: 2,
|
|
204
200
|
where: {
|
|
@@ -218,7 +214,7 @@ const metricIds = (experiment)=>[
|
|
|
218
214
|
}
|
|
219
215
|
]
|
|
220
216
|
}
|
|
221
|
-
});
|
|
217
|
+
}, system);
|
|
222
218
|
return busy.docs;
|
|
223
219
|
})());
|
|
224
220
|
input.flagPointBusy = (await busyPoints.get(key)).some((doc)=>String(doc.id) !== String(experiment.id));
|
|
@@ -228,10 +224,8 @@ const metricIds = (experiment)=>[
|
|
|
228
224
|
if (layerId !== undefined) {
|
|
229
225
|
const key = String(layerId);
|
|
230
226
|
if (!layers.has(key)) layers.set(key, (async ()=>{
|
|
231
|
-
const result = await req
|
|
227
|
+
const result = await findStartDocuments(req, {
|
|
232
228
|
collection: 'xp-layers',
|
|
233
|
-
req,
|
|
234
|
-
overrideAccess: false,
|
|
235
229
|
depth: 0,
|
|
236
230
|
limit: 1,
|
|
237
231
|
where: {
|
|
@@ -239,15 +233,13 @@ const metricIds = (experiment)=>[
|
|
|
239
233
|
equals: layerId
|
|
240
234
|
}
|
|
241
235
|
}
|
|
242
|
-
});
|
|
236
|
+
}, system);
|
|
243
237
|
const layer = result.docs[0];
|
|
244
238
|
const usedSlices = [];
|
|
245
239
|
let page = 1;
|
|
246
240
|
while(true){
|
|
247
|
-
const usage = await req
|
|
241
|
+
const usage = await findStartDocuments(req, {
|
|
248
242
|
collection: 'xp-experiments',
|
|
249
|
-
req,
|
|
250
|
-
overrideAccess: false,
|
|
251
243
|
depth: 0,
|
|
252
244
|
limit: 100,
|
|
253
245
|
page,
|
|
@@ -268,7 +260,7 @@ const metricIds = (experiment)=>[
|
|
|
268
260
|
}
|
|
269
261
|
]
|
|
270
262
|
}
|
|
271
|
-
});
|
|
263
|
+
}, system);
|
|
272
264
|
for (const doc of usage.docs)if (Array.isArray(doc.layerSlices)) usedSlices.push(...doc.layerSlices);
|
|
273
265
|
if (!usage.hasNextPage) break;
|
|
274
266
|
page++;
|
|
@@ -284,7 +276,7 @@ const metricIds = (experiment)=>[
|
|
|
284
276
|
const paths = experiment.kind === 'page' ? experiment.arms.flatMap((a)=>typeof a.pageTarget === 'string' ? [
|
|
285
277
|
a.pageTarget
|
|
286
278
|
] : []) : 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));
|
|
279
|
+
input.interactions = await placementInteractions(req, await req.transactionID != null ? txExecutor(req) : pooledExecutor(req.payload), options, experiment, paths.map(normalisePath), system);
|
|
288
280
|
}
|
|
289
281
|
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
282
|
inputs.set(String(experiment.id), input);
|
|
@@ -475,7 +467,9 @@ export async function preflightData(req, { experimentId, options, placementLocal
|
|
|
475
467
|
} catch {}
|
|
476
468
|
}
|
|
477
469
|
}
|
|
478
|
-
const requiredSlots = e.arms.
|
|
470
|
+
const requiredSlots = e.arms.flatMap((arm)=>arm.kind === 'holdout' || arm.key === 'holdout' ? [] : [
|
|
471
|
+
arm.key
|
|
472
|
+
]);
|
|
479
473
|
const blocks = input.placements ?? [];
|
|
480
474
|
let placements = new Array(blocks.length);
|
|
481
475
|
let nextPlacement = 0;
|
|
@@ -511,7 +505,20 @@ export async function preflightData(req, { experimentId, options, placementLocal
|
|
|
511
505
|
};
|
|
512
506
|
}
|
|
513
507
|
}));
|
|
508
|
+
let contentLocales;
|
|
514
509
|
if (blocks.some((placement)=>placement.locale)) {
|
|
510
|
+
const { placementLocale, placementDefaultLocale, placementLocaleCodes } = input;
|
|
511
|
+
const selected = placementLocale && placementLocaleCodes?.includes(placementLocale) ? placementLocale : placementDefaultLocale;
|
|
512
|
+
if (selected && placementLocaleCodes) {
|
|
513
|
+
const labels = placementLanguageNames(req, placementLocaleCodes);
|
|
514
|
+
contentLocales = {
|
|
515
|
+
selected,
|
|
516
|
+
labels: Object.fromEntries(placementLocaleCodes.map((code, index)=>[
|
|
517
|
+
code,
|
|
518
|
+
labels[index] ?? code
|
|
519
|
+
]))
|
|
520
|
+
};
|
|
521
|
+
}
|
|
515
522
|
// Summarize occurrences within one language and publication state first.
|
|
516
523
|
// Combine languages only when the complete displayed row agrees.
|
|
517
524
|
const languageRows = new Map();
|
|
@@ -529,14 +536,19 @@ export async function preflightData(req, { experimentId, options, placementLocal
|
|
|
529
536
|
const groups = new Map();
|
|
530
537
|
for (const indices of languageRows.values()){
|
|
531
538
|
const rows = indices.map((index)=>placements[index]), first = rows[0];
|
|
539
|
+
const slots = Object.fromEntries(BLOCK_SLOTS.map((slot)=>[
|
|
540
|
+
slot,
|
|
541
|
+
Math.min(...rows.map((row)=>row.slots[slot]))
|
|
542
|
+
]));
|
|
543
|
+
const partlyFilledSlots = first.detail === 'Draft' ? BLOCK_SLOTS.filter((slot)=>slots[slot] === 0 && rows.some((row)=>row.slots[slot] > 0)) : [];
|
|
532
544
|
const row = {
|
|
533
545
|
...first,
|
|
534
546
|
slotCount: rows.length,
|
|
535
547
|
ok: rows.every((row)=>row.ok),
|
|
536
|
-
slots
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
548
|
+
slots,
|
|
549
|
+
...partlyFilledSlots.length ? {
|
|
550
|
+
partlyFilledSlots
|
|
551
|
+
} : {}
|
|
540
552
|
};
|
|
541
553
|
const key = JSON.stringify(row);
|
|
542
554
|
const group = groups.get(key) ?? {
|
|
@@ -551,7 +563,10 @@ export async function preflightData(req, { experimentId, options, placementLocal
|
|
|
551
563
|
...groups.values()
|
|
552
564
|
].map(({ row, codes })=>({
|
|
553
565
|
...row,
|
|
554
|
-
...placementLanguages(req, codes)
|
|
566
|
+
...placementLanguages(req, codes),
|
|
567
|
+
...codes.length ? {
|
|
568
|
+
localeCodes: codes
|
|
569
|
+
} : {}
|
|
555
570
|
}));
|
|
556
571
|
}
|
|
557
572
|
for (const placement of input.flagPlacements ?? [])placements.push({
|
|
@@ -663,7 +678,15 @@ export async function preflightData(req, { experimentId, options, placementLocal
|
|
|
663
678
|
}
|
|
664
679
|
}
|
|
665
680
|
return {
|
|
681
|
+
document: {
|
|
682
|
+
status: e.status,
|
|
683
|
+
phase: e.phase,
|
|
684
|
+
updatedAt: e.updatedAt
|
|
685
|
+
},
|
|
666
686
|
checks: checkStart(input),
|
|
687
|
+
...metric && browserWritableMetric(metric.source, options) ? {
|
|
688
|
+
browserWritablePrimaryId: metric.id
|
|
689
|
+
} : {},
|
|
667
690
|
...input.goalContent ? {
|
|
668
691
|
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
692
|
metricId: m.id,
|
|
@@ -671,6 +694,9 @@ export async function preflightData(req, { experimentId, options, placementLocal
|
|
|
671
694
|
}))
|
|
672
695
|
} : {},
|
|
673
696
|
placements,
|
|
697
|
+
...contentLocales ? {
|
|
698
|
+
contentLocales
|
|
699
|
+
} : {},
|
|
674
700
|
...e.kind === 'page' ? {
|
|
675
701
|
pagePlacements
|
|
676
702
|
} : {},
|
|
@@ -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
10
|
export declare function refuse(code: RefusalCode, detail?: unknown): never;
|
|
13
|
-
export declare function updateExperiment(req: PayloadRequest, id: DocId, data: Record<string, unknown
|
|
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,25 @@
|
|
|
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';
|
|
12
14
|
import { XpRefusal } from '../errors.js';
|
|
13
15
|
import { isOpValid } from '../targeting/ops.js';
|
|
14
16
|
import { newSeed } from '../runtime/seed.js';
|
|
15
17
|
import { checkStart, pageTargetPaths, relationshipId } from './checkStart.js';
|
|
16
18
|
import { withTransition } from './kernel.js';
|
|
17
|
-
import { writePhaseRecord } from './phaseRecord.js';
|
|
18
|
-
import { loadPageTestsInUse,
|
|
19
|
+
import { requireCurrentRound, writePhaseRecord } from './phaseRecord.js';
|
|
20
|
+
import { loadPageTestsInUse, loadStartInputsBatch, readStartInputExperiment, unpublishedPageTargets } from './preflightData.js';
|
|
19
21
|
import { resolveCaps } from './resolveCaps.js';
|
|
22
|
+
import { findStartDocuments, readStartState } from './startReads.js';
|
|
20
23
|
export async function readExperiment(req, id) {
|
|
21
24
|
// §7.8: internal lookup serves the authorised transition write. Preserve
|
|
22
25
|
// admin-only analysis.method/kind for freezing; return access-filtered docs.
|
|
@@ -82,15 +85,16 @@ export function refuse(code, detail) {
|
|
|
82
85
|
].includes(code);
|
|
83
86
|
throw new XpRefusal(code, messages[code] ?? 'The experiment is not ready to start.', detail, code === 'entry-not-found' ? 404 : conflict ? 409 : 422);
|
|
84
87
|
}
|
|
85
|
-
export async function updateExperiment(req, id, data) {
|
|
86
|
-
// §7.8:
|
|
87
|
-
await req.payload.update({
|
|
88
|
+
export async function updateExperiment(req, id, data, system = false) {
|
|
89
|
+
// §7.8: an authorized manager transition or trusted system Start writes locked plugin fields.
|
|
90
|
+
const updated = await req.payload.update({
|
|
88
91
|
collection: 'xp-experiments',
|
|
89
92
|
req,
|
|
90
93
|
id,
|
|
91
94
|
data,
|
|
92
95
|
overrideAccess: true
|
|
93
96
|
});
|
|
97
|
+
if (system) return updated;
|
|
94
98
|
const { docs } = await req.payload.find({
|
|
95
99
|
collection: 'xp-experiments',
|
|
96
100
|
req,
|
|
@@ -106,14 +110,16 @@ export async function updateExperiment(req, id, data) {
|
|
|
106
110
|
if (!docs[0]) throw new XpRefusal('not-found', 'Experiment not found', undefined, 404);
|
|
107
111
|
return docs[0];
|
|
108
112
|
}
|
|
109
|
-
|
|
110
|
-
const input = await
|
|
113
|
+
async function prepareStart(req, options, before, system) {
|
|
114
|
+
const input = (await loadStartInputsBatch(req, options, [
|
|
115
|
+
before
|
|
116
|
+
], false, system)).get(String(before.id));
|
|
111
117
|
if (!input) throw new XpRefusal('not-found', 'Experiment not found', undefined, 404);
|
|
112
|
-
const full = await readExperiment(req,
|
|
113
|
-
if (full.updatedAt !==
|
|
118
|
+
const full = await readExperiment(req, before.id);
|
|
119
|
+
if (full.updatedAt !== before.updatedAt) refuse('stale-draft');
|
|
114
120
|
// Review reads respect field access; internal writes must preserve hidden config.
|
|
115
121
|
input.experiment = {
|
|
116
|
-
...
|
|
122
|
+
...before,
|
|
117
123
|
kind: full.kind,
|
|
118
124
|
analysis: full.analysis
|
|
119
125
|
};
|
|
@@ -121,26 +127,54 @@ export async function start(req, { experimentId, options }) {
|
|
|
121
127
|
// ReadinessCode to RefusalCode, which intentionally excludes warnings.
|
|
122
128
|
const failed = checkStart(input).find((check)=>!check.ok);
|
|
123
129
|
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;
|
|
126
130
|
const at = new Date();
|
|
127
131
|
const caps = await resolveCaps(input.metrics, options.metricSources ?? [], at);
|
|
128
|
-
|
|
132
|
+
return {
|
|
133
|
+
input,
|
|
134
|
+
at,
|
|
135
|
+
caps
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
export async function start(req, { experimentId, options, phase: expectedPhase, system = false, onlyIfNeverStarted = false }) {
|
|
139
|
+
const before = await readStartInputExperiment(req, experimentId, system);
|
|
140
|
+
if (!before) throw new XpRefusal('not-found', 'Experiment not found', undefined, 404);
|
|
141
|
+
const { updatedAt } = before;
|
|
142
|
+
const prepared = await prepareStart(req, options, before, system).catch((error)=>{
|
|
143
|
+
if (!onlyIfNeverStarted && expectedPhase === undefined) throw error;
|
|
144
|
+
// Conditional Start checks the locked document before reporting a preflight failure.
|
|
145
|
+
return {
|
|
146
|
+
error
|
|
147
|
+
};
|
|
148
|
+
});
|
|
149
|
+
const kind = 'error' in prepared ? before.kind : prepared.input.experiment.kind;
|
|
150
|
+
const { result: { doc, detail }, revision } = await withTransition(req, {
|
|
129
151
|
experimentId,
|
|
130
152
|
layerId: relationshipId(before.layer),
|
|
131
|
-
flagPointId:
|
|
153
|
+
flagPointId: kind === 'flag' ? before.flagPoint : undefined,
|
|
154
|
+
requireOwnedTransaction: system
|
|
132
155
|
}, async ({ req, exec })=>{
|
|
133
156
|
const current = await readExperiment(req, experimentId);
|
|
157
|
+
// A concurrent Start or Stop must yield the locked status before considering a stale snapshot.
|
|
158
|
+
if (onlyIfNeverStarted && (current.status !== 'draft' || (current.phase ?? 0) !== 0)) {
|
|
159
|
+
const detail = {
|
|
160
|
+
status: current.status,
|
|
161
|
+
phase: current.phase ?? 0
|
|
162
|
+
};
|
|
163
|
+
throw new XpRefusal('first-start-only', firstStartOnlyCopy(current.status), detail, 409);
|
|
164
|
+
}
|
|
165
|
+
requireCurrentRound(expectedPhase, current.phase);
|
|
134
166
|
if (current.updatedAt !== updatedAt) refuse('stale-draft');
|
|
135
167
|
if (current.status !== 'draft' && current.status !== 'stopped') refuse('invalid-status');
|
|
168
|
+
if ('error' in prepared) throw prepared.error;
|
|
169
|
+
const { input, at, caps } = prepared;
|
|
136
170
|
let placementDocs;
|
|
137
171
|
if (current.kind === 'block') {
|
|
138
|
-
const rescan = await lockAndRescanPlacements(req, exec, options, current, input.placements ?? []);
|
|
172
|
+
const rescan = await lockAndRescanPlacements(req, exec, options, current, input.placements ?? [], system);
|
|
139
173
|
placementDocs = rescan.docs;
|
|
140
174
|
const failure = checkStart({
|
|
141
175
|
...input,
|
|
142
176
|
experiment: current,
|
|
143
|
-
placements: nameNestedPlacements(rescan.placements, await nestedPlacementNames(req, rescan.placements))
|
|
177
|
+
placements: nameNestedPlacements(rescan.placements, await nestedPlacementNames(req, rescan.placements, system))
|
|
144
178
|
}).find((check)=>!check.ok);
|
|
145
179
|
if (failure && failure.code !== 'page-targets-unchecked' && failure.code !== 'make-content-unsupported') refuse(failure.code, failure.detail);
|
|
146
180
|
}
|
|
@@ -155,7 +189,7 @@ export async function start(req, { experimentId, options }) {
|
|
|
155
189
|
pageTestsInUse: await loadPageTestsInUse(req)
|
|
156
190
|
}).find((check)=>check.code === 'page-in-use' && !check.ok);
|
|
157
191
|
if (recheck) refuse('page-in-use', recheck.detail);
|
|
158
|
-
const conflicts = await placementInteractions(req, exec, options, current, pageTargetPaths(current.arms));
|
|
192
|
+
const conflicts = await placementInteractions(req, exec, options, current, pageTargetPaths(current.arms), system);
|
|
159
193
|
if (conflicts.length) refuse('interacting-tests', conflicts);
|
|
160
194
|
if (options.pages) {
|
|
161
195
|
// The page guard takes the same path locks, so a delete, unpublish or rename that committed
|
|
@@ -174,10 +208,8 @@ export async function start(req, { experimentId, options }) {
|
|
|
174
208
|
}
|
|
175
209
|
}
|
|
176
210
|
if (current.kind === 'flag' && current.flagPoint) {
|
|
177
|
-
const busy = await req
|
|
211
|
+
const busy = await findStartDocuments(req, {
|
|
178
212
|
collection: 'xp-experiments',
|
|
179
|
-
req,
|
|
180
|
-
overrideAccess: false,
|
|
181
213
|
depth: 0,
|
|
182
214
|
limit: 2,
|
|
183
215
|
where: {
|
|
@@ -197,15 +229,10 @@ export async function start(req, { experimentId, options }) {
|
|
|
197
229
|
}
|
|
198
230
|
]
|
|
199
231
|
}
|
|
200
|
-
});
|
|
232
|
+
}, system);
|
|
201
233
|
if (busy.docs.some((doc)=>String(doc.id) !== String(experimentId))) refuse('flag-point-busy');
|
|
202
234
|
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
|
-
});
|
|
235
|
+
const state = await readStartState(req, system);
|
|
209
236
|
const defaults = state.flagDefaults;
|
|
210
237
|
current.arms = current.arms.map((arm)=>arm.kind === 'control' ? {
|
|
211
238
|
...arm,
|
|
@@ -265,15 +292,17 @@ export async function start(req, { experimentId, options }) {
|
|
|
265
292
|
...metric,
|
|
266
293
|
metricId: metric.id,
|
|
267
294
|
addedAt: startedAt,
|
|
295
|
+
browserWritable: browserWritableMetric(metric.source, options),
|
|
268
296
|
role: String(relationshipId(current.metrics?.primary)) === String(metric.id) ? 'primary' : current.metrics?.guardrails?.some((id)=>String(relationshipId(id)) === String(metric.id)) ? 'guardrail' : 'secondary'
|
|
269
297
|
}));
|
|
298
|
+
const arms = current.kind === 'block' ? withSlotsFor(current.arms, 'block') : current.arms;
|
|
270
299
|
await writePhaseRecord(req, {
|
|
271
300
|
experiment: experimentId,
|
|
272
301
|
phase,
|
|
273
302
|
phaseKind: 'test',
|
|
274
303
|
seed,
|
|
275
304
|
startedAt,
|
|
276
|
-
arms
|
|
305
|
+
arms,
|
|
277
306
|
allocation: current.allocation,
|
|
278
307
|
allocationChanges: [],
|
|
279
308
|
targeting,
|
|
@@ -303,21 +332,25 @@ export async function start(req, { experimentId, options }) {
|
|
|
303
332
|
},
|
|
304
333
|
contentChanges: []
|
|
305
334
|
});
|
|
306
|
-
|
|
335
|
+
const doc = await updateExperiment(req, experimentId, {
|
|
307
336
|
status: 'running',
|
|
308
337
|
phase,
|
|
309
338
|
seed,
|
|
310
339
|
startedAt,
|
|
311
340
|
stoppedAt: null,
|
|
312
341
|
layerSlices,
|
|
313
|
-
arms
|
|
314
|
-
});
|
|
342
|
+
arms
|
|
343
|
+
}, system);
|
|
344
|
+
return {
|
|
345
|
+
doc,
|
|
346
|
+
detail: caps.detail
|
|
347
|
+
};
|
|
315
348
|
});
|
|
316
349
|
return {
|
|
317
350
|
doc,
|
|
318
351
|
revision: revision,
|
|
319
|
-
...
|
|
320
|
-
detail
|
|
352
|
+
...detail.length ? {
|
|
353
|
+
detail
|
|
321
354
|
} : {}
|
|
322
355
|
};
|
|
323
356
|
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { PayloadRequest } from 'payload';
|
|
2
|
+
type StartReadQuery = Parameters<PayloadRequest['payload']['find']>[0] & {
|
|
3
|
+
collection: 'xp-experiments' | 'xp-metrics' | 'xp-layers';
|
|
4
|
+
};
|
|
5
|
+
export declare function findStartDocuments(req: PayloadRequest, query: StartReadQuery, system?: boolean): Promise<import("payload").PaginatedDocs<import("payload").JsonObject & import("payload").TypeWithID>>;
|
|
6
|
+
export declare function readStartState(req: PayloadRequest, system?: boolean): Promise<import("payload").JsonObject>;
|
|
7
|
+
export {};
|