fix(experiments): 移除系统预置并支持空白实验配置
- 迁移清理预置类型及关联分流数据,保留自建类型与清理审计 - 未配置实验时沿用应用默认行为,不自动创建类型或接入记录 - 补充空白系统启动回归与迁移说明
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
/** 后台实验生命周期与账号稳定分配;前台只消费短时决策并回报曝光。 */
|
||||
import {
|
||||
experimentType as scene,
|
||||
findExperimentType,
|
||||
normalizePlanValues,
|
||||
recordTypeRead,
|
||||
} from "./digital.experiment-types";
|
||||
@@ -309,27 +310,39 @@ export function planValue(
|
||||
: (e.config.presetB ?? fallback);
|
||||
return fallback;
|
||||
}
|
||||
/** 返回前台所需最小决策,规则、指定名单和提示词均不下发。 */
|
||||
export async function decide(account: string, scope: string) {
|
||||
const type = await scene(scope);
|
||||
/** 未配置方案或类型时返回默认行为,不创建类型、分组或接入记录。 */
|
||||
function defaultDecision(typeKey: string, typeRevision: number, value: unknown) {
|
||||
return {
|
||||
variant: "A" as const,
|
||||
reason: "default",
|
||||
fallbackVariant: "A" as const,
|
||||
decisionId: null,
|
||||
experimentId: null,
|
||||
presetId: undefined,
|
||||
presetSnapshot: undefined,
|
||||
value,
|
||||
typeKey,
|
||||
typeRevision,
|
||||
expiresAt: Date.now() + 60000,
|
||||
};
|
||||
}
|
||||
/** 通用决策要求已注册类型;应用内部可显式提供未配置时的默认行为。 */
|
||||
export async function decide(
|
||||
account: string,
|
||||
scope: string,
|
||||
unregistered?: { value: unknown },
|
||||
) {
|
||||
const type = await findExperimentType(scope);
|
||||
if (!type) {
|
||||
if (!unregistered) throw notFound("实验类型不存在");
|
||||
return defaultDecision(scope, 0, unregistered.value);
|
||||
}
|
||||
await recordTypeRead(type.id, type.contractRevision);
|
||||
const e = type.enabled
|
||||
? activeExperiment(await experiments(), type.consumerKey)
|
||||
: undefined;
|
||||
if (!e)
|
||||
return {
|
||||
variant: "A" as const,
|
||||
reason: "default",
|
||||
fallbackVariant: "A" as const,
|
||||
decisionId: null,
|
||||
experimentId: null,
|
||||
presetId: undefined,
|
||||
presetSnapshot: undefined,
|
||||
value: type.defaultValue,
|
||||
typeKey: type.id,
|
||||
typeRevision: type.contractRevision,
|
||||
expiresAt: Date.now() + 60000,
|
||||
};
|
||||
return defaultDecision(type.id, type.contractRevision, type.defaultValue);
|
||||
const d = await resolveExperiment(e, account);
|
||||
const tracked =
|
||||
e.state === "running" &&
|
||||
|
||||
Reference in New Issue
Block a user