@delmaredigital/payload-experiments 0.4.1 → 0.5.1
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 -5
- package/dist/admin/blocks/model.js +2 -0
- package/dist/admin/copy/blocks.d.ts +1 -0
- package/dist/admin/copy/blocks.js +1 -0
- package/dist/admin/copy/status.d.ts +3 -0
- package/dist/admin/copy/status.js +3 -0
- package/dist/admin/placementStatus.model.js +3 -0
- package/dist/admin/status.model.d.ts +3 -2
- package/dist/admin/status.model.js +9 -3
- package/dist/admin/surface/ResultsRoute.js +2 -1
- package/dist/admin/surface/TestsHome.d.ts +2 -1
- package/dist/admin/surface/TestsHome.js +31 -11
- package/dist/admin/surface/TestsSurface.js +4 -0
- package/dist/admin/surface/home.model.d.ts +11 -6
- package/dist/admin/surface/home.model.js +19 -8
- package/dist/admin/surface/newTest/PageWizard.js +13 -3
- package/dist/admin/surface/results/ResultsHeader.js +43 -9
- package/dist/admin/surface/test/TestPage.js +11 -1
- package/dist/admin/useLayerUsage.d.ts +1 -1
- package/dist/admin/views/buildSurfaceProps.js +3 -0
- package/dist/blocks/placementLocale.d.ts +14 -0
- package/dist/blocks/placementLocale.js +80 -13
- package/dist/blocks/placementPublication.d.ts +14 -0
- package/dist/blocks/placementPublication.js +24 -0
- package/dist/cohorts/build.d.ts +35 -0
- package/dist/cohorts/build.js +134 -0
- package/dist/cohorts/key.d.ts +12 -0
- package/dist/cohorts/key.js +15 -0
- package/dist/cohorts/maintenance.d.ts +10 -0
- package/dist/cohorts/maintenance.js +70 -0
- package/dist/cohorts/readiness.d.ts +30 -0
- package/dist/cohorts/readiness.js +54 -0
- package/dist/cohorts/readinessData.d.ts +29 -0
- package/dist/cohorts/readinessData.js +123 -0
- package/dist/cohorts/rule.d.ts +33 -0
- package/dist/cohorts/rule.js +50 -0
- package/dist/collections/cohortMembers.d.ts +4 -0
- package/dist/collections/cohortMembers.js +95 -0
- package/dist/collections/experiments/config.js +157 -7
- package/dist/collections/experiments/editability.js +10 -6
- package/dist/collections/experiments/lockHook.js +39 -20
- package/dist/collections/index.js +4 -1
- package/dist/collections/phases.js +4 -1
- package/dist/constants.d.ts +2 -0
- package/dist/constants.js +2 -0
- package/dist/db/adapter.d.ts +2 -1
- package/dist/db/adapter.js +17 -4
- package/dist/db/appends.d.ts +2 -1
- package/dist/db/appends.js +3 -2
- package/dist/db/bulkPlacementRemoval.d.ts +5 -0
- package/dist/db/bulkPlacementRemoval.js +7 -2
- package/dist/db/cohortMembership.d.ts +11 -0
- package/dist/db/cohortMembership.js +31 -0
- package/dist/db/cohortPool.d.ts +9 -0
- package/dist/db/cohortPool.js +53 -0
- package/dist/db/cohortTransactions.d.ts +3 -0
- package/dist/db/cohortTransactions.js +52 -0
- package/dist/db/cohorts.d.ts +72 -0
- package/dist/db/cohorts.js +280 -0
- package/dist/db/erase.d.ts +2 -0
- package/dist/db/erase.js +21 -2
- package/dist/db/events.d.ts +2 -0
- package/dist/db/events.js +8 -0
- package/dist/db/executor.d.ts +2 -0
- package/dist/db/executor.js +8 -0
- package/dist/db/locks.d.ts +7 -0
- package/dist/db/locks.js +13 -1
- package/dist/db/names.d.ts +95 -1
- package/dist/db/names.js +95 -1
- package/dist/db/occupancy.d.ts +21 -0
- package/dist/db/occupancy.js +46 -0
- package/dist/db/pageBindings.d.ts +2 -2
- package/dist/db/pageBindings.js +3 -3
- package/dist/db/pageOccupancy.d.ts +4 -4
- package/dist/db/pageOccupancy.js +13 -10
- package/dist/db/pgExecutor.d.ts +4 -0
- package/dist/db/pgExecutor.js +1 -1
- package/dist/db/placements.d.ts +6 -1
- package/dist/db/placements.js +27 -1
- package/dist/db/results.d.ts +5 -2
- package/dist/db/results.js +32 -5
- package/dist/db/slices.d.ts +9 -2
- package/dist/db/slices.js +15 -8
- package/dist/db/snapshots.d.ts +16 -1
- package/dist/db/snapshots.js +27 -2
- package/dist/db/sql.d.ts +2 -2
- package/dist/db/sql.js +1 -2
- package/dist/endpoints/cohortSources.d.ts +16 -0
- package/dist/endpoints/cohortSources.js +335 -0
- package/dist/endpoints/contentLocale.d.ts +1 -1
- package/dist/endpoints/duplicateOriginal.d.ts +1 -0
- package/dist/endpoints/events.js +82 -18
- package/dist/endpoints/index.js +45 -1
- package/dist/endpoints/pausedBy.d.ts +14 -0
- package/dist/endpoints/pausedBy.js +94 -0
- package/dist/endpoints/preflight.js +4 -1
- package/dist/endpoints/previewToken.js +2 -0
- package/dist/endpoints/results.d.ts +2 -2
- package/dist/endpoints/results.js +111 -3
- package/dist/endpoints/routeId.d.ts +2 -1
- package/dist/endpoints/routeId.js +6 -2
- package/dist/endpoints/summary.js +24 -1
- package/dist/endpoints/transitions.d.ts +7 -0
- package/dist/endpoints/transitions.js +50 -1
- package/dist/events/rows.d.ts +1 -1
- package/dist/events/rows.js +5 -3
- package/dist/exports/index.d.ts +2 -0
- package/dist/exports/index.js +1 -0
- package/dist/exports/runtimeProxy.d.ts +1 -0
- package/dist/exports/runtimeProxy.js +1 -0
- package/dist/hooks/blockRemovalRule.d.ts +1 -1
- package/dist/hooks/blockRemovalRule.js +12 -8
- package/dist/hooks/pageGuard.d.ts +7 -1
- package/dist/hooks/pageGuard.js +177 -4
- package/dist/hooks/puckNestedTests.d.ts +1 -1
- package/dist/hooks/puckNestedTests.js +3 -1
- package/dist/labels/status.d.ts +15 -0
- package/dist/labels/status.js +12 -0
- package/dist/manifest/compile.d.ts +15 -4
- package/dist/manifest/compile.js +91 -3
- package/dist/onInit.js +4 -6
- package/dist/options.d.ts +1 -0
- package/dist/options.js +10 -0
- package/dist/proxy/consentFallback.d.ts +1 -1
- package/dist/proxy/consentFallback.js +4 -4
- package/dist/proxy/control.d.ts +1 -1
- package/dist/proxy/control.js +2 -2
- package/dist/proxy/pageRewrite.d.ts +1 -1
- package/dist/proxy/pageRewrite.js +3 -2
- package/dist/proxy/resolve.js +76 -17
- package/dist/puck/ExperimentPicker.js +2 -1
- package/dist/puck/copy.d.ts +6 -5
- package/dist/puck/copy.js +3 -7
- package/dist/puck/editor/ExperimentSlotEditor.js +16 -5
- package/dist/puck/editor/QuickTestActions.js +7 -1
- package/dist/puck/editor/armWrites.js +6 -1
- package/dist/puck/editor/copy.d.ts +3 -0
- package/dist/puck/editor/copy.js +3 -0
- package/dist/puck/editor/editor.css +2 -1
- package/dist/puck/editor/editor.model.d.ts +2 -1
- package/dist/puck/editor/editor.model.js +2 -0
- package/dist/puck/editor/placementsCache.d.ts +1 -1
- package/dist/puck/editor/placementsCache.js +6 -3
- package/dist/results/analyse.d.ts +3 -1
- package/dist/results/analyse.js +20 -3
- package/dist/results/health.d.ts +11 -0
- package/dist/results/health.js +38 -0
- package/dist/results/power.d.ts +1 -1
- package/dist/results/power.js +1 -1
- package/dist/results/snapshot.d.ts +8 -2
- package/dist/results/snapshot.js +23 -1
- package/dist/results/unitValues.d.ts +48 -0
- package/dist/results/unitValues.js +166 -0
- package/dist/runtime/assign.d.ts +7 -3
- package/dist/runtime/assign.js +12 -4
- package/dist/runtime/cohortCookie.d.ts +15 -0
- package/dist/runtime/cohortCookie.js +72 -0
- package/dist/runtime/cohortLookup.d.ts +9 -0
- package/dist/runtime/cohortLookup.js +25 -0
- package/dist/runtime/eligibility.d.ts +11 -5
- package/dist/runtime/eligibility.js +33 -7
- package/dist/runtime/header.d.ts +1 -0
- package/dist/runtime/header.js +1 -1
- package/dist/runtime/proxyRuntime.js +5 -1
- package/dist/runtime/targeting.d.ts +3 -2
- package/dist/runtime/targeting.js +2 -1
- package/dist/sanitizeReadinessDetail.d.ts +2 -2
- package/dist/sanitizeReadinessDetail.js +41 -4
- package/dist/schedule/activeTime.d.ts +28 -0
- package/dist/schedule/activeTime.js +322 -0
- package/dist/schedule/ranges.d.ts +13 -0
- package/dist/schedule/ranges.js +11 -0
- package/dist/schedule/roundTime.d.ts +10 -0
- package/dist/schedule/roundTime.js +45 -0
- package/dist/schedule/types.d.ts +29 -0
- package/dist/schedule/types.js +1 -0
- package/dist/server/cohortLookup.d.ts +3 -0
- package/dist/server/cohortLookup.js +7 -0
- package/dist/server/eraseUser.d.ts +1 -0
- package/dist/server/getAssignments.js +63 -40
- package/dist/server/previewDraft.d.ts +1 -1
- package/dist/server/previewDraft.js +3 -2
- package/dist/server/recordContentChange.d.ts +1 -1
- package/dist/server/recordContentChange.js +42 -20
- package/dist/server/recordExposures.js +4 -2
- package/dist/server/runResults.js +97 -150
- package/dist/testSurface/actions/LifecycleAction.d.ts +2 -1
- package/dist/testSurface/actions/LifecycleAction.js +15 -5
- package/dist/testSurface/actions/actions.model.d.ts +13 -2
- package/dist/testSurface/actions/actions.model.js +38 -5
- package/dist/testSurface/api.d.ts +13 -1
- package/dist/testSurface/api.js +19 -0
- package/dist/testSurface/copy/actions.d.ts +13 -0
- package/dist/testSurface/copy/actions.js +13 -0
- package/dist/testSurface/copy/cohorts.d.ts +68 -0
- package/dist/testSurface/copy/cohorts.js +81 -0
- package/dist/testSurface/copy/common.d.ts +2 -3
- package/dist/testSurface/copy/common.js +4 -4
- package/dist/testSurface/copy/inputs.d.ts +3 -0
- package/dist/testSurface/copy/inputs.js +3 -0
- package/dist/testSurface/copy/readiness.d.ts +20 -6
- package/dist/testSurface/copy/readiness.js +42 -9
- package/dist/testSurface/copy/results.d.ts +1 -0
- package/dist/testSurface/copy/results.js +1 -0
- package/dist/testSurface/copy/schedule.d.ts +58 -0
- package/dist/testSurface/copy/schedule.js +150 -0
- package/dist/testSurface/copy/surface.d.ts +2 -0
- package/dist/testSurface/copy/surface.js +2 -0
- package/dist/testSurface/copy/testPage.d.ts +12 -2
- package/dist/testSurface/copy/testPage.js +17 -2
- package/dist/testSurface/format/roundProgress.d.ts +13 -1
- package/dist/testSurface/format/roundProgress.js +34 -5
- package/dist/testSurface/format/scheduleStatus.d.ts +34 -0
- package/dist/testSurface/format/scheduleStatus.js +93 -0
- package/dist/testSurface/format/useScheduleClock.d.ts +3 -0
- package/dist/testSurface/format/useScheduleClock.js +20 -0
- package/dist/testSurface/labels.d.ts +4 -9
- package/dist/testSurface/labels.js +2 -7
- package/dist/testSurface/lockedNotice.model.d.ts +2 -2
- package/dist/testSurface/lockedNotice.model.js +16 -3
- package/dist/testSurface/readPreflight.d.ts +3 -0
- package/dist/testSurface/readPreflight.js +14 -0
- package/dist/testSurface/readinessRead.d.ts +2 -2
- package/dist/testSurface/results/DataQualityPanel.js +7 -7
- package/dist/testSurface/results/results.model.d.ts +1 -1
- package/dist/testSurface/results/results.model.js +34 -6
- package/dist/testSurface/review/cohortEstimate.d.ts +11 -0
- package/dist/testSurface/review/cohortEstimate.js +32 -0
- package/dist/testSurface/surface/contracts.d.ts +2 -1
- package/dist/testSurface/surface/contracts.js +1 -0
- package/dist/testSurface/surface/editorPlacement.d.ts +1 -0
- package/dist/testSurface/surface/readiness/ActionDialogs.d.ts +3 -2
- package/dist/testSurface/surface/readiness/ActionDialogs.js +121 -32
- package/dist/testSurface/surface/readiness/Banner.js +29 -11
- package/dist/testSurface/surface/readiness/readiness.model.d.ts +20 -2
- package/dist/testSurface/surface/readiness/readiness.model.js +35 -5
- package/dist/testSurface/surface/readiness/useTransition.js +17 -5
- package/dist/testSurface/surface/results/ResultsBody.js +44 -8
- package/dist/testSurface/surface/results/useResults.d.ts +16 -1
- package/dist/testSurface/surface/results/useResults.js +17 -6
- package/dist/testSurface/surface/test/CohortRuleEditor.d.ts +16 -0
- package/dist/testSurface/surface/test/CohortRuleEditor.js +492 -0
- package/dist/testSurface/surface/test/LengthSection.js +26 -6
- package/dist/testSurface/surface/test/ScheduleDateInput.d.ts +4 -0
- package/dist/testSurface/surface/test/ScheduleDateInput.js +15 -0
- package/dist/testSurface/surface/test/ScheduleSection.d.ts +2 -0
- package/dist/testSurface/surface/test/ScheduleSection.js +322 -0
- package/dist/testSurface/surface/test/Section.js +1 -1
- package/dist/testSurface/surface/test/TargetingSection.js +306 -182
- package/dist/testSurface/surface/test/TestSurface.js +9 -0
- package/dist/testSurface/surface/test/fields.d.ts +2 -1
- package/dist/testSurface/surface/test/fields.js +3 -3
- package/dist/testSurface/surface/test/jumpToSection.d.ts +1 -1
- package/dist/testSurface/surface/test/jumpToSection.js +4 -4
- package/dist/testSurface/surface/test/testPage.css +26 -0
- package/dist/testSurface/surface/testDocument.model.d.ts +12 -1
- package/dist/testSurface/surface/testDocument.model.js +2 -1
- package/dist/testSurface/surface/useTestDocument.js +11 -4
- package/dist/testSurface/targeting/targeting.model.d.ts +2 -1
- package/dist/testSurface/targeting/targeting.model.js +1 -1
- package/dist/testSurface/useApi.d.ts +12 -0
- package/dist/transitions/addMetric.js +5 -2
- package/dist/transitions/allocate.js +6 -1
- package/dist/transitions/assertNoOverlap.d.ts +9 -0
- package/dist/transitions/assertNoOverlap.js +24 -0
- package/dist/transitions/buildCohorts.d.ts +10 -0
- package/dist/transitions/buildCohorts.js +68 -0
- package/dist/transitions/cancelSchedule.d.ts +4 -0
- package/dist/transitions/cancelSchedule.js +42 -0
- package/dist/transitions/checkStart.d.ts +17 -3
- package/dist/transitions/checkStart.js +20 -7
- package/dist/transitions/decide.js +40 -13
- package/dist/transitions/kernel.d.ts +3 -1
- package/dist/transitions/kernel.js +5 -2
- package/dist/transitions/pause.d.ts +4 -0
- package/dist/transitions/pause.js +35 -0
- package/dist/transitions/phaseRecord.d.ts +19 -2
- package/dist/transitions/phaseRecord.js +50 -11
- package/dist/transitions/placementInteractions.d.ts +7 -2
- package/dist/transitions/placementInteractions.js +9 -7
- package/dist/transitions/placements.d.ts +4 -3
- package/dist/transitions/placements.js +28 -14
- package/dist/transitions/preflightData.d.ts +11 -3
- package/dist/transitions/preflightData.js +134 -81
- package/dist/transitions/reschedule.d.ts +4 -0
- package/dist/transitions/reschedule.js +58 -0
- package/dist/transitions/resume.d.ts +4 -0
- package/dist/transitions/resume.js +32 -0
- package/dist/transitions/scheduledRound.d.ts +18 -0
- package/dist/transitions/scheduledRound.js +42 -0
- package/dist/transitions/start.d.ts +4 -0
- package/dist/transitions/start.js +139 -56
- package/dist/transitions/startReads.d.ts +14 -0
- package/dist/transitions/startReads.js +27 -0
- package/dist/transitions/stop.d.ts +10 -0
- package/dist/transitions/stop.js +35 -22
- package/dist/types/admin.d.ts +1 -1
- package/dist/types/contracts.d.ts +7 -1
- package/dist/types/endpoints.d.ts +72 -3
- package/dist/types/manifest.d.ts +9 -0
- package/dist/types/runtime.d.ts +5 -0
- package/dist/types/snapshot.d.ts +10 -0
- package/dist/types/status.d.ts +1 -0
- package/dist/types/status.js +1 -0
- package/dist/types/surface.d.ts +1 -0
- package/dist/ui/Feedback.d.ts +9 -6
- package/dist/ui/Feedback.js +10 -9
- package/dist/ui/SelectControl.js +1 -1
- package/dist/ui/ui.css +2 -1
- package/package.json +2 -2
|
@@ -1,16 +1,23 @@
|
|
|
1
|
+
import { refreshCohorts, sweepCohorts } from '../cohorts/maintenance.js';
|
|
2
|
+
import { isCohortRule } from '../cohorts/rule.js';
|
|
3
|
+
import { cohortExitedUnits } from '../db/cohorts.js';
|
|
4
|
+
import { withCohortExitDefault } from '../results/snapshot.js';
|
|
5
|
+
import { metricUnitValues, readUnitMetricEvents, unitValueContext } from '../results/unitValues.js';
|
|
1
6
|
import { asymmetricGoal, goalContent, goalPlacementDetail, LEGACY_FAIRNESS } from '../goals/fairness.js';
|
|
2
7
|
import { XpAnalysisError } from '../errors.js';
|
|
3
|
-
import { canonicalHealth, mergePageHealth, rapidBrowserEvents } from '../results/health.js';
|
|
8
|
+
import { canonicalHealth, cohortNoExposures, mergePageHealth, rapidBrowserEvents } from '../results/health.js';
|
|
4
9
|
import { safeError } from '../log.js';
|
|
5
10
|
import { createLocalReq } from 'payload';
|
|
6
|
-
import { resultsCandidates, resultsExecutor, writeSnapshots } from '../db/snapshots.js';
|
|
11
|
+
import { dueScheduledStops, resultsCandidates, resultsExecutor, writeSnapshots } from '../db/snapshots.js';
|
|
12
|
+
import { DAY_MS } from '../schedule/roundTime.js';
|
|
7
13
|
import { sweepEvents } from '../db/sweep.js';
|
|
8
|
-
import { armMismatchCount,
|
|
14
|
+
import { armMismatchCount, phaseExposureRows, rolloutExposureRows } from '../db/results.js';
|
|
9
15
|
import { raceDeadline, ResultsBudgetError, RESULTS_TIMEOUT_MARGIN_MS } from '../db/executor.js';
|
|
10
16
|
import { analysePhase } from '../results/analyse.js';
|
|
11
17
|
import { firstExposures, perUnitValues, timestampMs } from '../results/aggregate.js';
|
|
12
18
|
import { rolloutAnalysisUnits } from '../results/rolloutUnits.js';
|
|
13
|
-
import {
|
|
19
|
+
import { eligibleIdentityLinks } from '../results/identityCredit.js';
|
|
20
|
+
import { stopScheduledExperiment } from '../transitions/stop.js';
|
|
14
21
|
function* convertingUnits(units, values, ages) {
|
|
15
22
|
for (const [id, value] of values){
|
|
16
23
|
if (value > 0) yield {
|
|
@@ -30,11 +37,14 @@ async function analyseCandidate(exec, candidate, options, now, deadline, unavail
|
|
|
30
37
|
weight: arm.kind === 'holdout' ? candidate.testArms.at(-1).weight : 100 - candidate.testArms.at(-1).weight
|
|
31
38
|
}))
|
|
32
39
|
} : phase;
|
|
33
|
-
const to = new Date(Math.min(+now, phase.endedAt == null ? Infinity : timestampMs(phase.endedAt)));
|
|
40
|
+
const to = new Date(Math.min(+now, phase.endedAt == null ? Infinity : timestampMs(phase.endedAt), phase.schedule?.endAt ? timestampMs(phase.schedule.endAt) : Infinity));
|
|
34
41
|
const query = {
|
|
35
42
|
experimentId: phase.experiment,
|
|
36
43
|
phase: phase.phase,
|
|
37
|
-
|
|
44
|
+
startedAt: phase.startedAt,
|
|
45
|
+
endedAt: to,
|
|
46
|
+
schedule: phase.schedule,
|
|
47
|
+
pauses: phase.pauses
|
|
38
48
|
};
|
|
39
49
|
const exposed = firstExposures(await phaseExposureRows(exec, query), {
|
|
40
50
|
endedAt: to
|
|
@@ -43,8 +53,9 @@ async function analyseCandidate(exec, candidate, options, now, deadline, unavail
|
|
|
43
53
|
if (phase.phaseKind === 'rollout') {
|
|
44
54
|
const eligible = rolloutAnalysisUnits({
|
|
45
55
|
exposuresAllPhases: await rolloutExposureRows(exec, {
|
|
46
|
-
|
|
47
|
-
respectPhaseEnds: true
|
|
56
|
+
experimentId: phase.experiment,
|
|
57
|
+
respectPhaseEnds: true,
|
|
58
|
+
now: to
|
|
48
59
|
}),
|
|
49
60
|
rolloutPhase: phase.phase,
|
|
50
61
|
seed: phase.seed,
|
|
@@ -65,110 +76,29 @@ async function analyseCandidate(exec, candidate, options, now, deadline, unavail
|
|
|
65
76
|
// An age on an exposure is only written by browser ingestion, including
|
|
66
77
|
// browser-side manual exposures. Server-recorded exposures have unknown age.
|
|
67
78
|
let rapidActivity = rapidBrowserEvents(comparedArms, units.values());
|
|
68
|
-
const
|
|
69
|
-
|
|
70
|
-
];
|
|
71
|
-
const identities = candidate.unitType === 'visitor' ? await identityRows(exec, {
|
|
72
|
-
anonymousIds: ids
|
|
73
|
-
}) : [];
|
|
74
|
-
const userIds = [
|
|
75
|
-
...new Set(identities.map((identity)=>identity.userId))
|
|
76
|
-
];
|
|
77
|
-
const linked = new Set(userIds);
|
|
78
|
-
const identityConflicts = new Set();
|
|
79
|
-
const userByVisitor = new Map(identities.map((identity)=>[
|
|
80
|
-
identity.anonymousId,
|
|
81
|
-
identity.userId
|
|
82
|
-
]));
|
|
83
|
-
const linksByUser = new Map();
|
|
84
|
-
for (const identity of identities){
|
|
85
|
-
const links = linksByUser.get(identity.userId) ?? [];
|
|
86
|
-
links.push(identity);
|
|
87
|
-
linksByUser.set(identity.userId, links);
|
|
88
|
-
}
|
|
89
|
-
// Last arm credited per user: enough to detect that a user's credited events span arms (a conflict).
|
|
90
|
-
const creditedArms = new Map();
|
|
91
|
-
const noteCredit = (userId, unitId)=>{
|
|
92
|
-
const arm = units.get(unitId)?.arm;
|
|
93
|
-
if (arm === undefined) return;
|
|
94
|
-
const previous = creditedArms.get(userId);
|
|
95
|
-
if (previous !== undefined && previous !== arm) identityConflicts.add(userId);
|
|
96
|
-
creditedArms.set(userId, arm);
|
|
97
|
-
};
|
|
98
|
-
const credit = (events, userKeyed)=>{
|
|
99
|
-
if (candidate.unitType === 'user') return events.map((event)=>({
|
|
100
|
-
...event,
|
|
101
|
-
unitId: event.userId ?? event.unitId
|
|
102
|
-
}));
|
|
103
|
-
// §8.3's earliest exposed linked visitor applies only when the event has no
|
|
104
|
-
// exposed unit of its own. A visitor-keyed event stays on its own exposed
|
|
105
|
-
// browser even if an earlier linked browser saw another arm or is ineligible.
|
|
106
|
-
const direct = userKeyed ? [] : events.filter((event)=>units.has(event.unitId) || event.userId == null || !linked.has(event.userId));
|
|
107
|
-
const userEvents = events.filter((event)=>userKeyed || !units.has(event.unitId) && event.userId != null && linked.has(event.userId)).map((event)=>({
|
|
108
|
-
...event,
|
|
109
|
-
userId: String(event.userId ?? event.unitId)
|
|
110
|
-
}));
|
|
111
|
-
const credited = creditUserEvents(units, identities, userEvents, (userId)=>identityConflicts.add(userId)).events;
|
|
112
|
-
for (const event of direct)if (event.userId != null && linked.has(event.userId)) {
|
|
113
|
-
noteCredit(event.userId, event.unitId);
|
|
114
|
-
// Keep the eligible-link diagnostic when direct credit bypasses the helper.
|
|
115
|
-
const arms = new Set(eligibleIdentityLinks(linksByUser.get(event.userId), event.ts).map((link)=>units.get(link.anonymousId).arm));
|
|
116
|
-
arms.add(units.get(event.unitId).arm);
|
|
117
|
-
if (arms.size > 1) identityConflicts.add(event.userId);
|
|
118
|
-
}
|
|
119
|
-
for (const event of credited)noteCredit(userByVisitor.get(event.unitId), event.unitId);
|
|
120
|
-
return [
|
|
121
|
-
...direct,
|
|
122
|
-
...credited
|
|
123
|
-
];
|
|
124
|
-
};
|
|
79
|
+
const context = await unitValueContext(exec, candidate.unitType, units);
|
|
80
|
+
const { identities, userIds, identityConflicts } = context;
|
|
125
81
|
const metricData = [];
|
|
126
82
|
for (const definition of phase.metricDefinitions){
|
|
127
83
|
try {
|
|
128
84
|
if (Date.now() >= deadline) throw new ResultsBudgetError();
|
|
129
|
-
const kind = definition.kind;
|
|
130
|
-
const windowHours = phase.analysis.attributionWindowHours ?? definition.attributionWindowHours ?? 168;
|
|
131
|
-
const from = new Date([
|
|
132
|
-
...units.values()
|
|
133
|
-
].reduce((earliest, unit)=>Math.min(earliest, +unit.firstTs), timestampMs(phase.startedAt)));
|
|
134
|
-
const preFrom = new Date(+from - 14 * 86_400_000);
|
|
135
85
|
const storedEvents = definition.source.startsWith('events:') || definition.source.startsWith('click:');
|
|
136
86
|
const readAge = storedEvents && definition.role === 'primary' && !rapidActivity;
|
|
137
|
-
|
|
87
|
+
const input = await readUnitMetricEvents(exec, {
|
|
88
|
+
phase,
|
|
89
|
+
unitType: candidate.unitType,
|
|
90
|
+
units,
|
|
91
|
+
context,
|
|
92
|
+
definition,
|
|
93
|
+
options,
|
|
94
|
+
to,
|
|
95
|
+
deadline,
|
|
96
|
+
readAge,
|
|
97
|
+
includePrePeriod: phase.analysis.cuped === 'auto'
|
|
98
|
+
});
|
|
99
|
+
const { events, source, userKeyed, kind } = input;
|
|
100
|
+
let covariates;
|
|
138
101
|
if (storedEvents) {
|
|
139
|
-
const eventName = definition.source.startsWith('click:') ? definition.source : definition.source.slice(7);
|
|
140
|
-
if (!definition.source.startsWith('click:') && !options.eventSources?.some((source)=>source.name === eventName)) throw new XpAnalysisError('source-unavailable');
|
|
141
|
-
const read = async (start)=>{
|
|
142
|
-
if (candidate.unitType === 'user') return metricEventRows(exec, {
|
|
143
|
-
eventName,
|
|
144
|
-
userIds: ids,
|
|
145
|
-
from: start,
|
|
146
|
-
to,
|
|
147
|
-
readAge
|
|
148
|
-
});
|
|
149
|
-
const direct = await metricEventRows(exec, {
|
|
150
|
-
eventName,
|
|
151
|
-
unitIds: ids,
|
|
152
|
-
from: start,
|
|
153
|
-
to,
|
|
154
|
-
readAge,
|
|
155
|
-
forVisitors: true
|
|
156
|
-
});
|
|
157
|
-
const signedIn = await metricEventRows(exec, {
|
|
158
|
-
eventName,
|
|
159
|
-
userIds,
|
|
160
|
-
from: start,
|
|
161
|
-
to,
|
|
162
|
-
readAge,
|
|
163
|
-
forVisitors: true
|
|
164
|
-
});
|
|
165
|
-
// The two lookups overlap when a linked user's own browser was exposed.
|
|
166
|
-
return [
|
|
167
|
-
...direct,
|
|
168
|
-
...signedIn.filter((event)=>!units.has(event.unitId))
|
|
169
|
-
];
|
|
170
|
-
};
|
|
171
|
-
events = credit(await read(phase.analysis.cuped === 'auto' ? preFrom : from), false);
|
|
172
102
|
if (phase.analysis.cuped === 'auto') {
|
|
173
103
|
const preUnits = new Map([
|
|
174
104
|
...units
|
|
@@ -176,7 +106,7 @@ async function analyseCandidate(exec, candidate, options, now, deadline, unavail
|
|
|
176
106
|
id,
|
|
177
107
|
{
|
|
178
108
|
arm: unit.arm,
|
|
179
|
-
firstTs: new Date(+unit.firstTs - 14 *
|
|
109
|
+
firstTs: new Date(+unit.firstTs - 14 * DAY_MS)
|
|
180
110
|
}
|
|
181
111
|
]));
|
|
182
112
|
covariates = perUnitValues(preUnits, events, {
|
|
@@ -185,17 +115,7 @@ async function analyseCandidate(exec, candidate, options, now, deadline, unavail
|
|
|
185
115
|
});
|
|
186
116
|
}
|
|
187
117
|
} else {
|
|
188
|
-
|
|
189
|
-
if (!source || source.kind !== kind || definition.keyedBy && source.keyedBy !== definition.keyedBy) throw new XpAnalysisError('source-unavailable');
|
|
190
|
-
const userKeyed = source.keyedBy === 'user' && candidate.unitType === 'visitor';
|
|
191
|
-
if (candidate.unitType === 'user' && source.keyedBy !== 'user') throw new XpAnalysisError('unit-type-unavailable');
|
|
192
|
-
const sourceIds = userKeyed ? userIds : ids;
|
|
193
|
-
events = credit(await raceDeadline(deadline, ()=>source.query({
|
|
194
|
-
from,
|
|
195
|
-
to,
|
|
196
|
-
unitIds: sourceIds
|
|
197
|
-
})), userKeyed);
|
|
198
|
-
if (phase.analysis.cuped === 'auto' && source.covariate) {
|
|
118
|
+
if (phase.analysis.cuped === 'auto' && source?.covariate) {
|
|
199
119
|
const userUnits = new Map();
|
|
200
120
|
if (userKeyed) for (const link of identities){
|
|
201
121
|
const unit = units.get(link.anonymousId);
|
|
@@ -240,26 +160,7 @@ async function analyseCandidate(exec, candidate, options, now, deadline, unavail
|
|
|
240
160
|
}));
|
|
241
161
|
}
|
|
242
162
|
}
|
|
243
|
-
|
|
244
|
-
// The click-goal delta supersedes whole-phase attribution for mid-test adds.
|
|
245
|
-
// Retain pre-period events for CUPED above; exclude them from the outcome.
|
|
246
|
-
const outcomeEvents = definition.source.startsWith('click:') && definition.addedAt ? events.filter((event)=>timestampMs(event.ts) >= timestampMs(definition.addedAt)) : events;
|
|
247
|
-
const ages = new Map();
|
|
248
|
-
const values = perUnitValues(units, outcomeEvents, {
|
|
249
|
-
kind,
|
|
250
|
-
windowHours,
|
|
251
|
-
endedAt: to,
|
|
252
|
-
onAttributed: readAge ? (event, ts)=>{
|
|
253
|
-
if (event.unitAgeMs === undefined) return;
|
|
254
|
-
const previous = ages.get(event.unitId);
|
|
255
|
-
if (!previous || ts < previous.ts || ts === previous.ts && event.unitAgeMs > previous.unitAgeMs) {
|
|
256
|
-
ages.set(event.unitId, {
|
|
257
|
-
ts,
|
|
258
|
-
unitAgeMs: event.unitAgeMs
|
|
259
|
-
});
|
|
260
|
-
}
|
|
261
|
-
} : undefined
|
|
262
|
-
});
|
|
163
|
+
const { values, ages } = metricUnitValues(units, definition, input, to, readAge);
|
|
263
164
|
if (ages.size) rapidActivity = rapidBrowserEvents(comparedArms, convertingUnits(units, values, ages));
|
|
264
165
|
metricData.push({
|
|
265
166
|
metricId: definition.metricId,
|
|
@@ -299,7 +200,14 @@ async function analyseCandidate(exec, candidate, options, now, deadline, unavail
|
|
|
299
200
|
if (error instanceof ResultsBudgetError || Date.now() >= deadline) throw new ResultsBudgetError();
|
|
300
201
|
}
|
|
301
202
|
}
|
|
302
|
-
const
|
|
203
|
+
const currentStatus = candidate.status === 'paused' ? 'running' : candidate.status // 0.5 T3/T8 refines
|
|
204
|
+
;
|
|
205
|
+
const status = phase.endedAt != null || currentStatus === 'archived' ? 'stopped' : currentStatus;
|
|
206
|
+
const exits = new Set();
|
|
207
|
+
if (phase.phaseKind === 'test') for (const rule of phase.targeting ?? []){
|
|
208
|
+
if (!isCohortRule(rule) || !('key' in rule)) continue;
|
|
209
|
+
for (const id of (await cohortExitedUnits(exec, rule, candidate.unitType, units)))exits.add(id);
|
|
210
|
+
}
|
|
303
211
|
const snapshot = analysePhase({
|
|
304
212
|
phase: analysisPhase,
|
|
305
213
|
now,
|
|
@@ -312,6 +220,7 @@ async function analyseCandidate(exec, candidate, options, now, deadline, unavail
|
|
|
312
220
|
metricId
|
|
313
221
|
}, 'Experiment metric analysis failed'),
|
|
314
222
|
excludedMultiArm: exposed.excludedMultiArm,
|
|
223
|
+
cohortExits: exits.size,
|
|
315
224
|
armMismatch: await armMismatchCount(exec, query),
|
|
316
225
|
identityConflictShare: userIds.length ? identityConflicts.size / userIds.length : 0,
|
|
317
226
|
...phase.phaseKind === 'rollout' ? {
|
|
@@ -319,16 +228,16 @@ async function analyseCandidate(exec, candidate, options, now, deadline, unavail
|
|
|
319
228
|
controlLabel: candidate.testArms.find((arm)=>arm.kind === 'control')?.label
|
|
320
229
|
} : {}
|
|
321
230
|
});
|
|
322
|
-
if (rapidActivity) snapshot.health
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
];
|
|
231
|
+
if (rapidActivity) (snapshot.health ??= []).push({
|
|
232
|
+
code: 'rapid-browser-events'
|
|
233
|
+
});
|
|
234
|
+
const cohortHealth = phase.phaseKind === 'test' && phase.endedAt == null ? cohortNoExposures(phase, candidate.status, now, exposed.units.size + exposed.excludedMultiArm) : undefined;
|
|
235
|
+
if (cohortHealth) (snapshot.health ??= []).push(cohortHealth);
|
|
327
236
|
return snapshot;
|
|
328
237
|
}
|
|
329
238
|
export async function runResults(payload, { budgetMs = 20_000, experimentId, sweep = true } = {}) {
|
|
330
239
|
if (!Number.isFinite(budgetMs) || budgetMs < 0) throw new RangeError('budgetMs must be finite and nonnegative');
|
|
331
|
-
const started = Date.now(), deadline = started + budgetMs
|
|
240
|
+
const started = Date.now(), deadline = started + budgetMs;
|
|
332
241
|
const summary = {
|
|
333
242
|
ran: 0,
|
|
334
243
|
skipped: 0,
|
|
@@ -344,15 +253,44 @@ export async function runResults(payload, { budgetMs = 20_000, experimentId, swe
|
|
|
344
253
|
budgetExhausted: true
|
|
345
254
|
};
|
|
346
255
|
const options = payload.config.custom?.xp;
|
|
256
|
+
const now = options.runtime?.proxyRuntime.now?.() ?? new Date(started);
|
|
347
257
|
const retentionDays = options.events?.retentionDays ?? 180;
|
|
348
258
|
// Reserve up to one second (25% of short runs) for retention, even when host
|
|
349
259
|
// code never settles. The safety margin also leaves time to return the summary.
|
|
350
260
|
const analysisDeadline = deadline - (sweep ? Math.min(1000, budgetMs / 4) : 0) - RESULTS_TIMEOUT_MARGIN_MS;
|
|
351
261
|
const exec = resultsExecutor(payload, ()=>analysisDeadline - Date.now());
|
|
352
262
|
let candidates = [];
|
|
263
|
+
const failedStops = new Set();
|
|
353
264
|
try {
|
|
265
|
+
const due = await dueScheduledStops(exec, now.toISOString(), experimentId);
|
|
266
|
+
for (const { id, phase } of due){
|
|
267
|
+
if (Date.now() >= analysisDeadline) throw new ResultsBudgetError();
|
|
268
|
+
try {
|
|
269
|
+
const req = await raceDeadline(analysisDeadline, ()=>createLocalReq({}, payload));
|
|
270
|
+
await stopScheduledExperiment(req, {
|
|
271
|
+
experimentId: id,
|
|
272
|
+
phase,
|
|
273
|
+
dueBy: now,
|
|
274
|
+
deadline: analysisDeadline
|
|
275
|
+
});
|
|
276
|
+
} catch (error) {
|
|
277
|
+
if (error instanceof ResultsBudgetError) throw error;
|
|
278
|
+
// Leave this round out until its exact cutoff can be committed.
|
|
279
|
+
failedStops.add(String(id));
|
|
280
|
+
summary.skipped++;
|
|
281
|
+
summary.failed++;
|
|
282
|
+
payload.logger.error({
|
|
283
|
+
err: safeError(error),
|
|
284
|
+
experimentId: id
|
|
285
|
+
}, 'Scheduled experiment stop failed');
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
if (experimentId === undefined) await refreshCohorts(payload, {
|
|
289
|
+
now,
|
|
290
|
+
budgetMs: Math.max(0, Math.min(budgetMs / 4, analysisDeadline - Date.now()))
|
|
291
|
+
});
|
|
354
292
|
candidates = await resultsCandidates(exec, {
|
|
355
|
-
cutoff: new Date(
|
|
293
|
+
cutoff: new Date(+now - retentionDays * DAY_MS).toISOString(),
|
|
356
294
|
experimentId
|
|
357
295
|
});
|
|
358
296
|
} catch (error) {
|
|
@@ -369,26 +307,30 @@ export async function runResults(payload, { budgetMs = 20_000, experimentId, swe
|
|
|
369
307
|
const experiments = new Map();
|
|
370
308
|
for (const candidate of candidates){
|
|
371
309
|
const id = candidate.phase.experiment;
|
|
310
|
+
// A scheduled round can still be canceled and must have no results before go-live.
|
|
311
|
+
if (failedStops.has(String(id)) || timestampMs(candidate.phase.startedAt) > +now) continue;
|
|
372
312
|
experiments.set(id, [
|
|
373
313
|
...experiments.get(id) ?? [],
|
|
374
314
|
candidate
|
|
375
315
|
]);
|
|
376
316
|
}
|
|
317
|
+
let remaining = experiments.size;
|
|
377
318
|
for (const [id, phases] of experiments){
|
|
378
319
|
if (Date.now() >= analysisDeadline) {
|
|
379
320
|
summary.budgetExhausted = true;
|
|
380
|
-
summary.skipped +=
|
|
321
|
+
summary.skipped += remaining;
|
|
381
322
|
break;
|
|
382
323
|
}
|
|
324
|
+
remaining--;
|
|
383
325
|
try {
|
|
384
326
|
const snapshots = [];
|
|
385
327
|
for (const phase of phases){
|
|
386
328
|
if (Date.now() >= analysisDeadline) throw new ResultsBudgetError();
|
|
387
329
|
// Health refreshes must not reopen inference after the late-beacon grace.
|
|
388
|
-
snapshots.push(phase.frozenSnapshot ? {
|
|
330
|
+
snapshots.push(phase.frozenSnapshot ? withCohortExitDefault({
|
|
389
331
|
...phase.frozenSnapshot,
|
|
390
332
|
computedAt: now.toISOString()
|
|
391
|
-
} : await analyseCandidate(exec, phase, options, now, analysisDeadline, summary.unavailableMetrics, payload.logger));
|
|
333
|
+
}) : await analyseCandidate(exec, phase, options, now, analysisDeadline, summary.unavailableMetrics, payload.logger));
|
|
392
334
|
}
|
|
393
335
|
if (Date.now() >= analysisDeadline) throw new ResultsBudgetError();
|
|
394
336
|
const current = phases.find((candidate)=>candidate.phase.phase === candidate.currentPhase && (candidate.status === 'running' || candidate.status === 'decided'));
|
|
@@ -444,12 +386,12 @@ export async function runResults(payload, { budgetMs = 20_000, experimentId, swe
|
|
|
444
386
|
for (const [index, snapshot] of snapshots.entries()){
|
|
445
387
|
const previous = phases[index].previousHealth ?? phases[index].frozenSnapshot?.health ?? [];
|
|
446
388
|
const unjudged = previous.filter((row)=>row.code === 'goal-in-some-versions' && content && content.unchecked.length > 0 && clicks.some((metric)=>metric.metricId === row.metricId && !asymmetricGoal(content, metric.source, arms)));
|
|
447
|
-
const
|
|
389
|
+
const roundHealth = snapshot.health?.filter((row)=>row.code !== 'placement-unchecked' && row.code !== 'goal-in-some-versions' && row.code !== 'version-page-unchecked' && row.code !== 'version-page-unavailable') ?? [];
|
|
448
390
|
snapshot.health = mergePageHealth(unjudged, [
|
|
449
391
|
...health,
|
|
450
392
|
...goals,
|
|
451
393
|
...unchecked,
|
|
452
|
-
...
|
|
394
|
+
...roundHealth
|
|
453
395
|
]);
|
|
454
396
|
if (content?.skipped && current.kind === 'block') snapshot.goalFairnessNotice = LEGACY_FAIRNESS;
|
|
455
397
|
else delete snapshot.goalFairnessNotice;
|
|
@@ -495,6 +437,11 @@ export async function runResults(payload, { budgetMs = 20_000, experimentId, swe
|
|
|
495
437
|
const sweepDeadline = deadline - RESULTS_TIMEOUT_MARGIN_MS;
|
|
496
438
|
try {
|
|
497
439
|
const sweepExec = resultsExecutor(payload, ()=>sweepDeadline - Date.now());
|
|
440
|
+
await sweepCohorts(payload, {
|
|
441
|
+
now,
|
|
442
|
+
retentionDays,
|
|
443
|
+
deadline: Date.now() + Math.max(0, (sweepDeadline - Date.now()) / 2)
|
|
444
|
+
});
|
|
498
445
|
summary.swept = await sweepEvents(sweepExec, {
|
|
499
446
|
now,
|
|
500
447
|
retentionDays,
|
|
@@ -9,9 +9,10 @@ export declare function LifecycleButton({ action, reason, showReason, disabled,
|
|
|
9
9
|
busy?: boolean;
|
|
10
10
|
onClick: () => void;
|
|
11
11
|
}): import("react").JSX.Element;
|
|
12
|
-
export declare function LifecycleDialog({ action, test, surface, onClose }: {
|
|
12
|
+
export declare function LifecycleDialog({ action, test, surface, onClose, onSuccess }: {
|
|
13
13
|
action: ExperimentAction;
|
|
14
14
|
test: ActionTestApi;
|
|
15
15
|
surface: SurfaceProps;
|
|
16
16
|
onClose: () => void;
|
|
17
|
+
onSuccess?: () => void;
|
|
17
18
|
}): import("react").JSX.Element;
|
|
@@ -4,8 +4,9 @@ import { useId, useState } from 'react';
|
|
|
4
4
|
import { Button } from '../../ui/Button.js';
|
|
5
5
|
import { AddMetricAction, AllocateAction, ConfirmAction } from '../surface/readiness/ActionDialogs.js';
|
|
6
6
|
import { ReleasePagesDialog } from '../surface/results/ReleasePages.js';
|
|
7
|
-
import { actionGroupLabel, availableActions } from './actions.model.js';
|
|
7
|
+
import { actionGroupLabel, availableActions, buildAudienceAction } from './actions.model.js';
|
|
8
8
|
import { DecideDialog } from './DecideDialog.js';
|
|
9
|
+
import { useScheduleClock } from '../format/useScheduleClock.js';
|
|
9
10
|
export function LifecycleButton({ action, reason, showReason = true, disabled, ariaDisabled, busy, onClick }) {
|
|
10
11
|
const id = useId();
|
|
11
12
|
const help = showReason ? reason ?? action.hint : action.hint;
|
|
@@ -34,9 +35,12 @@ export function LifecycleButton({ action, reason, showReason = true, disabled, a
|
|
|
34
35
|
]
|
|
35
36
|
});
|
|
36
37
|
}
|
|
37
|
-
export function LifecycleDialog({ action, test, surface, onClose }) {
|
|
38
|
+
export function LifecycleDialog({ action, test, surface, onClose, onSuccess }) {
|
|
38
39
|
const [opened] = useState(test.doc);
|
|
39
40
|
const doc = test.doc ?? opened;
|
|
41
|
+
const now = useScheduleClock([
|
|
42
|
+
doc
|
|
43
|
+
], surface.timeZone);
|
|
40
44
|
const decision = doc.decision;
|
|
41
45
|
const winner = actionGroupLabel(decision?.winnerArm ?? 'control', doc.arms.find((arm)=>arm.key === decision?.winnerArm)?.label);
|
|
42
46
|
const props = {
|
|
@@ -44,12 +48,15 @@ export function LifecycleDialog({ action, test, surface, onClose }) {
|
|
|
44
48
|
surface,
|
|
45
49
|
onClose
|
|
46
50
|
};
|
|
47
|
-
const
|
|
51
|
+
const current = action.id === 'build-cohorts' && surface.canManage && (doc.status === 'draft' || doc.status === 'stopped') ? buildAudienceAction : availableActions({
|
|
48
52
|
...doc,
|
|
49
53
|
decision,
|
|
54
|
+
timeZone: surface.timeZone,
|
|
55
|
+
now,
|
|
50
56
|
canManage: surface.canManage,
|
|
51
57
|
canReadResults: surface.canReadResults
|
|
52
|
-
}).
|
|
58
|
+
}).find((item)=>item.id === action.id);
|
|
59
|
+
const changed = !test.doc || doc.phase !== opened.phase || !current || action.id === 'start' && (current.label !== action.label || current.confirm.body !== action.confirm.body);
|
|
53
60
|
if (action.id === 'decide') return /*#__PURE__*/ _jsx(DecideDialog, {
|
|
54
61
|
name: opened.name,
|
|
55
62
|
id: opened.id,
|
|
@@ -102,6 +109,9 @@ export function LifecycleDialog({ action, test, surface, onClose }) {
|
|
|
102
109
|
return /*#__PURE__*/ _jsx(ConfirmAction, {
|
|
103
110
|
...props,
|
|
104
111
|
action: action,
|
|
105
|
-
winnerLabel: winner
|
|
112
|
+
winnerLabel: winner,
|
|
113
|
+
now: now,
|
|
114
|
+
unavailable: changed,
|
|
115
|
+
onSuccess: onSuccess
|
|
106
116
|
});
|
|
107
117
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { ExperimentKind, Status } from '../../types/contracts.js';
|
|
2
2
|
import type { ArchiveBody, ContentReport } from '../../types/endpoints.js';
|
|
3
3
|
import { type PageReleaseDecision } from '../results/releasePages.model.js';
|
|
4
|
+
import type { ScheduleWindow } from '../../schedule/types.js';
|
|
4
5
|
export type ActionGroup = {
|
|
5
6
|
key: string;
|
|
6
7
|
label?: string;
|
|
@@ -11,7 +12,7 @@ export type ActionDecision = PageReleaseDecision & {
|
|
|
11
12
|
holdoutReleasedAt?: string | null;
|
|
12
13
|
contentReport?: ContentReport | null;
|
|
13
14
|
};
|
|
14
|
-
export type ActionId = 'start' | 'stop' | 'decide' | 'release-holdout' | 'make-content' | 'after-content' | 'archive' | 'discard' | 'hard-coded' | 'allocate' | 'add-metric' | 'delete' | 'release-pages';
|
|
15
|
+
export type ActionId = 'build-cohorts' | 'start' | 'stop' | 'pause' | 'resume' | 'reschedule' | 'cancel-schedule' | 'decide' | 'release-holdout' | 'make-content' | 'after-content' | 'archive' | 'discard' | 'hard-coded' | 'allocate' | 'add-metric' | 'delete' | 'release-pages';
|
|
15
16
|
export declare function isDestructiveAction(id: ActionId): boolean;
|
|
16
17
|
export type ExperimentAction = {
|
|
17
18
|
id: ActionId;
|
|
@@ -29,15 +30,25 @@ export type ExperimentAction = {
|
|
|
29
30
|
hint?: string;
|
|
30
31
|
unavailable?: string;
|
|
31
32
|
};
|
|
33
|
+
export declare const buildAudienceAction: ExperimentAction;
|
|
32
34
|
export declare function actionGroupLabel(key: string, storedLabel?: string): string;
|
|
33
35
|
export declare function canDeleteTest(status: string): status is "draft" | "archived";
|
|
34
|
-
export declare function availableActions({ name, status, kind, arms, allocation, decision, canManage, canReadResults }: {
|
|
36
|
+
export declare function availableActions({ name, status, kind, arms, allocation, decision, startedAt, schedule, timeZone, now, canManage, canReadResults }: {
|
|
35
37
|
name?: string;
|
|
36
38
|
status: Status;
|
|
37
39
|
kind: ExperimentKind;
|
|
38
40
|
arms?: readonly ActionGroup[] | null;
|
|
39
41
|
allocation?: number;
|
|
40
42
|
decision?: ActionDecision | null;
|
|
43
|
+
startedAt?: string | null;
|
|
44
|
+
schedule?: {
|
|
45
|
+
startAt?: string | null;
|
|
46
|
+
endAt?: string | null;
|
|
47
|
+
timeZone?: string | null;
|
|
48
|
+
windows?: ScheduleWindow[] | null;
|
|
49
|
+
} | null;
|
|
50
|
+
now?: number;
|
|
41
51
|
canManage: boolean;
|
|
42
52
|
canReadResults?: boolean;
|
|
53
|
+
timeZone?: string;
|
|
43
54
|
}): ExperimentAction[];
|
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
import { contentDone } from '../../contentDone.js';
|
|
2
|
-
import { armLabel } from '../labels.js';
|
|
3
|
-
import { ACTIONS_COPY as C, actionTitle, archiveCopy, discardCopy, hardCodedLabel, makeContentCopy, releaseCopy, stopCopy } from '../copy/actions.js';
|
|
2
|
+
import { armLabel, displayStatus } from '../labels.js';
|
|
3
|
+
import { ACTIONS_COPY as C, actionTitle, archiveCopy, discardCopy, hardCodedLabel, makeContentCopy, releaseCopy, scheduleStartCopy, stopCopy } from '../copy/actions.js';
|
|
4
4
|
import { REVIEW_COPY } from '../copy/review.js';
|
|
5
5
|
import { READINESS_COPY } from '../copy/readiness.js';
|
|
6
6
|
import { DELETE_TEST } from '../copy/testPage.js';
|
|
7
7
|
import { RESULTS_COPY } from '../copy/results.js';
|
|
8
8
|
import { canReleasePages } from '../results/releasePages.model.js';
|
|
9
|
+
import { isValidTimeZone } from '../../schedule/activeTime.js';
|
|
10
|
+
import { COHORT_COPY, COHORT_EDITOR } from '../copy/cohorts.js';
|
|
11
|
+
import { scheduleDate } from '../copy/schedule.js';
|
|
9
12
|
const destructiveActions = new Set([
|
|
10
13
|
'stop',
|
|
14
|
+
'cancel-schedule',
|
|
11
15
|
'decide',
|
|
12
16
|
'release-holdout',
|
|
13
17
|
'make-content',
|
|
@@ -22,17 +26,26 @@ const destructiveActions = new Set([
|
|
|
22
26
|
export function isDestructiveAction(id) {
|
|
23
27
|
return destructiveActions.has(id);
|
|
24
28
|
}
|
|
29
|
+
export const buildAudienceAction = {
|
|
30
|
+
id: 'build-cohorts',
|
|
31
|
+
label: COHORT_EDITOR.build,
|
|
32
|
+
tone: 'secondary',
|
|
33
|
+
confirm: {
|
|
34
|
+
title: COHORT_EDITOR.build,
|
|
35
|
+
body: COHORT_COPY.timeout
|
|
36
|
+
}
|
|
37
|
+
};
|
|
25
38
|
export function actionGroupLabel(key, storedLabel) {
|
|
26
39
|
return storedLabel?.trim() || armLabel(key);
|
|
27
40
|
}
|
|
28
41
|
export function canDeleteTest(status) {
|
|
29
42
|
return status === 'draft' || status === 'archived';
|
|
30
43
|
}
|
|
31
|
-
export function availableActions({ name, status, kind, arms = [], allocation, decision, canManage, canReadResults = canManage }) {
|
|
44
|
+
export function availableActions({ name, status, kind, arms = [], allocation, decision, startedAt, schedule, timeZone, now = Date.now(), canManage, canReadResults = canManage }) {
|
|
32
45
|
if (!canManage) return [];
|
|
33
46
|
const action = (id, label, body, tone = 'secondary', archive, phrase)=>{
|
|
34
47
|
const confirmLabel = id === 'hard-coded' ? C.confirmPermanentWinner : label;
|
|
35
|
-
const titleKey = id === 'start' &&
|
|
48
|
+
const titleKey = id === 'start' && label === C.restart ? 'restart' : id;
|
|
36
49
|
const titleLead = Object.hasOwn(C.titleLead, titleKey) ? C.titleLead[titleKey] : confirmLabel;
|
|
37
50
|
return {
|
|
38
51
|
id,
|
|
@@ -53,7 +66,9 @@ export function availableActions({ name, status, kind, arms = [], allocation, de
|
|
|
53
66
|
} : {}
|
|
54
67
|
};
|
|
55
68
|
};
|
|
56
|
-
const
|
|
69
|
+
const scheduledStart = Date.parse(schedule?.startAt ?? '');
|
|
70
|
+
const zone = schedule?.timeZone || timeZone;
|
|
71
|
+
const start = scheduledStart > now ? action('start', C.schedule, scheduleStartCopy(scheduleDate(new Date(scheduledStart), zone && isValidTimeZone(zone) ? zone : 'UTC', 'day', new Date(now)), Boolean(schedule?.windows?.length)), 'primary') : action('start', status === 'stopped' ? C.restart : C.start, status === 'stopped' ? C.restartBody : C.startBody, 'primary');
|
|
57
72
|
const control = actionGroupLabel('control', arms?.find((group)=>group.kind === 'control' || group.key === 'control')?.label);
|
|
58
73
|
const decide = canReadResults ? [
|
|
59
74
|
action('decide', C.decide, C.decideBody, 'primary')
|
|
@@ -72,13 +87,31 @@ export function availableActions({ name, status, kind, arms = [], allocation, de
|
|
|
72
87
|
] : [],
|
|
73
88
|
remove
|
|
74
89
|
];
|
|
90
|
+
if (displayStatus({
|
|
91
|
+
status,
|
|
92
|
+
startedAt
|
|
93
|
+
}, now) === 'scheduled') return [
|
|
94
|
+
action('cancel-schedule', C.cancelSchedule, C.cancelScheduleBody, 'danger')
|
|
95
|
+
];
|
|
96
|
+
const reschedule = schedule?.startAt || schedule?.endAt || schedule?.windows?.length ? [
|
|
97
|
+
action('reschedule', C.reschedule, C.rescheduleBody)
|
|
98
|
+
] : [];
|
|
99
|
+
if (status === 'paused') return [
|
|
100
|
+
action('resume', C.resume, C.resumeBody, 'primary'),
|
|
101
|
+
...decide,
|
|
102
|
+
action('add-metric', READINESS_COPY.addGoal, ''),
|
|
103
|
+
...reschedule,
|
|
104
|
+
action('stop', C.stop, stopCopy(control), 'danger')
|
|
105
|
+
];
|
|
75
106
|
if (status === 'running') return [
|
|
76
107
|
...decide,
|
|
108
|
+
action('pause', C.pause, C.pauseBody),
|
|
77
109
|
action('add-metric', READINESS_COPY.addGoal, ''),
|
|
78
110
|
{
|
|
79
111
|
...action('allocate', READINESS_COPY.allocate, REVIEW_COPY.allocationBody),
|
|
80
112
|
unavailable: allocation !== undefined && allocation >= 100 ? READINESS_COPY.everyone : undefined
|
|
81
113
|
},
|
|
114
|
+
...reschedule,
|
|
82
115
|
action('stop', C.stop, stopCopy(control), 'danger')
|
|
83
116
|
];
|
|
84
117
|
if (status === 'stopped') return [
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { DocId } from '../types/contracts.js';
|
|
2
|
-
import type { CopyPagePlan, CopyPageResult, DeleteImpactResult, WrapBlockBody, PagesResult, PlacementStatusBody, PlacementStatusResult, RestoreContentEntryBody, RestoreContentEntryResult, DismissContentEntryBody, DismissContentEntryResult, AddMetricBody, AllocateBody, ArchiveBody, DecideBody, MakeContentResult, AddMetricResult, ClickKeysResult, PreflightResult, PreviewTokenResult, RefusalCode, ResultsResponse, SummaryResponse, TransitionSuccess } from '../types/endpoints.js';
|
|
2
|
+
import type { CohortSourcesResult, CopyPagePlan, CopyPageResult, DeleteImpactResult, WrapBlockBody, PagesResult, PlacementStatusBody, PlacementStatusResult, RestoreContentEntryBody, RestoreContentEntryResult, DismissContentEntryBody, DismissContentEntryResult, AddMetricBody, AllocateBody, ArchiveBody, DecideBody, MakeContentResult, AddMetricResult, ClickKeysResult, PauseAttribution, PauseBody, PreflightResult, PreviewTokenResult, RefusalCode, RescheduleBody, ResultsResponse, SummaryResponse, TransitionSuccess } from '../types/endpoints.js';
|
|
3
3
|
import { refusalMessage } from './copy/common.js';
|
|
4
4
|
export type ApiResult<T> = {
|
|
5
5
|
ok: true;
|
|
@@ -30,6 +30,13 @@ export declare function createApi(apiBase: string, contentLocale?: string): {
|
|
|
30
30
|
page?: number;
|
|
31
31
|
mode?: "block";
|
|
32
32
|
}, signal?: AbortSignal) => Promise<ApiResult<PagesResult>>;
|
|
33
|
+
cohortSources: (q: string, exclude: DocId, signal?: AbortSignal) => Promise<ApiResult<CohortSourcesResult>>;
|
|
34
|
+
buildCohorts: (id: DocId) => Promise<ApiResult<{
|
|
35
|
+
cohorts: Array<{
|
|
36
|
+
key: string;
|
|
37
|
+
members: number;
|
|
38
|
+
}>;
|
|
39
|
+
}>>;
|
|
33
40
|
previewPageCopy: (id: DocId, arm: string, signal?: AbortSignal) => Promise<ApiResult<CopyPagePlan>>;
|
|
34
41
|
makePageCopy: (id: DocId, arm: string, plan: CopyPagePlan) => Promise<ApiResult<CopyPageResult>>;
|
|
35
42
|
placementStatus: (body: PlacementStatusBody) => Promise<ApiResult<PlacementStatusResult>>;
|
|
@@ -37,6 +44,10 @@ export declare function createApi(apiBase: string, contentLocale?: string): {
|
|
|
37
44
|
allocate: (id: DocId, body: AllocateBody, options?: RequestOptions) => Promise<ApiResult<TransitionSuccess>>;
|
|
38
45
|
addMetric: (id: DocId, body: AddMetricBody, options?: RequestOptions) => Promise<ApiResult<AddMetricResult>>;
|
|
39
46
|
stop: (id: DocId, phase?: number) => Promise<ApiResult<TransitionSuccess>>;
|
|
47
|
+
pause: (id: DocId, body: PauseBody) => Promise<ApiResult<TransitionSuccess>>;
|
|
48
|
+
resume: (id: DocId, phase?: number) => Promise<ApiResult<TransitionSuccess>>;
|
|
49
|
+
reschedule: (id: DocId, body: RescheduleBody) => Promise<ApiResult<TransitionSuccess>>;
|
|
50
|
+
cancelSchedule: (id: DocId, phase?: number) => Promise<ApiResult<TransitionSuccess>>;
|
|
40
51
|
decide: (id: DocId, body: DecideBody) => Promise<ApiResult<TransitionSuccess>>;
|
|
41
52
|
releaseHoldout: (id: DocId, phase?: number) => Promise<ApiResult<TransitionSuccess>>;
|
|
42
53
|
releasePages: (id: DocId, phase?: number) => Promise<ApiResult<TransitionSuccess>>;
|
|
@@ -55,6 +66,7 @@ export declare function createApi(apiBase: string, contentLocale?: string): {
|
|
|
55
66
|
recompute: (id: DocId) => Promise<ApiResult<{
|
|
56
67
|
snapshotId: string;
|
|
57
68
|
}>>;
|
|
69
|
+
pausedBy: (signal: AbortSignal) => Promise<ApiResult<Record<string, PauseAttribution>>>;
|
|
58
70
|
summary: (ids: readonly DocId[]) => Promise<ApiResult<SummaryResponse>>;
|
|
59
71
|
};
|
|
60
72
|
export {};
|