pairit 0.3.1 → 0.3.2
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/dist/index.js +62 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -9807,9 +9807,65 @@ async function attachHtmlToCompiledConfig(configPath, compiled) {
|
|
|
9807
9807
|
return sources;
|
|
9808
9808
|
}
|
|
9809
9809
|
|
|
9810
|
+
// src/randomize-lint.ts
|
|
9811
|
+
function lintRandomization(config) {
|
|
9812
|
+
const errors = [];
|
|
9813
|
+
const groupSize = singleGroupSize(config);
|
|
9814
|
+
const check = (where, settings) => {
|
|
9815
|
+
if (settings.distribute !== true)
|
|
9816
|
+
return;
|
|
9817
|
+
if (settings.scope !== "group") {
|
|
9818
|
+
errors.push(`${where}: distribute: true needs scope: group`);
|
|
9819
|
+
}
|
|
9820
|
+
const conditions = settings.conditions;
|
|
9821
|
+
if (!Array.isArray(conditions) || conditions.length === 0) {
|
|
9822
|
+
errors.push(`${where}: distribute: true needs a conditions list`);
|
|
9823
|
+
return;
|
|
9824
|
+
}
|
|
9825
|
+
if (groupSize !== undefined && conditions.length !== groupSize) {
|
|
9826
|
+
errors.push(`${where}: distribute: true needs one condition per group member (${conditions.length} conditions, groups of ${groupSize})`);
|
|
9827
|
+
}
|
|
9828
|
+
};
|
|
9829
|
+
config.pages?.forEach((page, pageIndex) => {
|
|
9830
|
+
const pageName = page.id ?? `pages[${pageIndex}]`;
|
|
9831
|
+
page.onEnter?.forEach((action, actionIndex) => {
|
|
9832
|
+
const a = action;
|
|
9833
|
+
if (a?.type === "randomize") {
|
|
9834
|
+
check(`${pageName}.onEnter[${actionIndex}]`, a);
|
|
9835
|
+
}
|
|
9836
|
+
});
|
|
9837
|
+
page.components?.forEach((component, componentIndex) => {
|
|
9838
|
+
const c = component;
|
|
9839
|
+
if (c?.type === "randomization" && c.props) {
|
|
9840
|
+
check(`${pageName}.components[${componentIndex}]`, c.props);
|
|
9841
|
+
}
|
|
9842
|
+
});
|
|
9843
|
+
});
|
|
9844
|
+
return errors;
|
|
9845
|
+
}
|
|
9846
|
+
function singleGroupSize(config) {
|
|
9847
|
+
const sizes = new Set;
|
|
9848
|
+
if (Array.isArray(config.matchmaking)) {
|
|
9849
|
+
for (const pool of config.matchmaking) {
|
|
9850
|
+
const size = pool?.num_users;
|
|
9851
|
+
sizes.add(typeof size === "number" ? size : 2);
|
|
9852
|
+
}
|
|
9853
|
+
}
|
|
9854
|
+
for (const page of config.pages ?? []) {
|
|
9855
|
+
for (const component of page.components ?? []) {
|
|
9856
|
+
const c = component;
|
|
9857
|
+
if (c?.type !== "matchmaking" || c.props?.poolId !== undefined)
|
|
9858
|
+
continue;
|
|
9859
|
+
const size = c.props?.num_users;
|
|
9860
|
+
sizes.add(typeof size === "number" ? size : 2);
|
|
9861
|
+
}
|
|
9862
|
+
}
|
|
9863
|
+
return sizes.size === 1 ? [...sizes][0] : undefined;
|
|
9864
|
+
}
|
|
9865
|
+
|
|
9810
9866
|
// src/index.ts
|
|
9811
9867
|
var program2 = new Command;
|
|
9812
|
-
program2.name("pairit").description("CLI for Pairit experiment configs").version("0.3.
|
|
9868
|
+
program2.name("pairit").description("CLI for Pairit experiment configs").version("0.3.2").option("--env <name>", "Target environment: staging or production", (value) => {
|
|
9813
9869
|
try {
|
|
9814
9870
|
return parseEnvName(value);
|
|
9815
9871
|
} catch (error) {
|
|
@@ -10101,6 +10157,7 @@ async function lintConfig(configPath) {
|
|
|
10101
10157
|
});
|
|
10102
10158
|
});
|
|
10103
10159
|
}
|
|
10160
|
+
errors.push(...lintRandomization(config));
|
|
10104
10161
|
if (errors.length) {
|
|
10105
10162
|
throw new Error(errors.join(", "));
|
|
10106
10163
|
}
|
|
@@ -10162,6 +10219,10 @@ async function compileConfig(configPath) {
|
|
|
10162
10219
|
}
|
|
10163
10220
|
async function buildUploadPayload(configPath, options) {
|
|
10164
10221
|
const sourceConfig = await loadConfig(configPath);
|
|
10222
|
+
const randomizationErrors = lintRandomization(sourceConfig);
|
|
10223
|
+
if (randomizationErrors.length) {
|
|
10224
|
+
throw new Error(randomizationErrors.join(", "));
|
|
10225
|
+
}
|
|
10165
10226
|
const allowRetake = sourceConfig.allowRetake === true;
|
|
10166
10227
|
const requireAuth = sourceConfig.requireAuth;
|
|
10167
10228
|
const compiledPath = await compileConfig(configPath);
|