{"record":{"id":"91d5fab3e7d79be1","repo":"JuliusBrussee/caveman","slug":"where-cohort-arms-are-not-baseline-then-alterna","errorCode":null,"errorMessage":"${where} cohort arms are not baseline then alternative","messagePattern":"(.+?) cohort arms are not baseline then alternative","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/shared/contracts/scripts/validate-continuous-improvement.mjs","lineNumber":143,"sourceCode":"    const expectedShare = runs > 0 ? weighted / runs : 0;\n    if (Math.abs(motif.structural_cost_share - expectedShare) > 1e-6) {\n      throw new Error(`${where} structural_cost_share ${motif.structural_cost_share} != ${expectedShare}`);\n    }\n  }\n  motifCount += report.motifs.length;\n\n  // The causal investigation of every case: the cohort's arms, the traces it\n  // selected from them, and the backward hard-dependency slice.\n  const unitsByID = new Map(report.analysis_units.map((unit) => [unit.id, unit]));\n  const familiesByID = new Map(report.task_families.map((family) => [family.id, family]));\n  for (const item of report.cases) {\n    const where = `report fixture ${reportPaths[index]}: case ${item.id}`;\n    const family = familiesByID.get(item.cohort.task_family_id);\n    if (!family) throw new Error(`${where} cohort references a task family that is not in this report`);\n    const familyUnits = new Set(family.analysis_unit_ids);\n    if (item.cohort.family_unit_count !== familyUnits.size) throw new Error(`${where} cohort family unit count disagrees with the task family`);\n    const roles = item.cohort.arms.map((arm) => arm.role);\n    if (roles.join(\",\") !== \"baseline,alternative\") throw new Error(`${where} cohort arms are not baseline then alternative`);\n    const armVariants = new Map();\n    let comparedUnits = 0;\n    for (const arm of item.cohort.arms) {\n      const variant = variantsByID.get(arm.variant_id);\n      if (!variant) throw new Error(`${where} cohort arm ${arm.role} references a workflow variant that is not in this report`);\n      if (variant.task_family_id !== family.id) throw new Error(`${where} cohort arm ${arm.role} uses a variant of another task family`);\n      armVariants.set(arm.role, variant);\n      comparedUnits += arm.unit_count;\n    }\n    const excluded = item.cohort.excluded_units.reduce((total, exclusion) => total + exclusion.unit_count, 0);\n    if (comparedUnits + excluded !== item.cohort.family_unit_count) {\n      throw new Error(`${where} cohort arms (${comparedUnits}) plus exclusions (${excluded}) do not account for its ${item.cohort.family_unit_count} family units`);\n    }\n\n    const selectedPerArm = new Map();\n    for (const trace of item.representative_traces) {\n      const variant = armVariants.get(trace.arm);\n      if (!variant || variant.id !== trace.variant_id) throw new Error(`${where} representative trace names a variant that is not that arm's variant`);","sourceCodeStart":125,"sourceCodeEnd":161,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/packages/shared/contracts/scripts/validate-continuous-improvement.mjs#L125-L161","documentation":"Every cohort must expose exactly two arms in a fixed order: the first with role \"baseline\" and the second with role \"alternative\". The validator joins the arm roles with commas and compares against the literal string \"baseline,alternative\". Any other ordering, extra arms, missing arms, or wrong role names triggers this error.","triggerScenarios":"A report fixture case where `cohort.arms` has roles in any arrangement other than exactly [\"baseline\",\"alternative\"] — e.g. arms reversed, roles misspelled (\"control\"/\"treatment\"), only one arm, or three arms.","commonSituations":"Authoring fixtures with different role vocabulary; programmatically building arms with nondeterministic key order; refactoring the schema to support multi-arm experiments without updating fixtures.","solutions":["Reorder/renames cohort.arms so the first arm has role \"baseline\" and the second has role \"alternative\".","Remove extra arms or add the missing second arm so exactly two arms exist.","Regenerate the fixture using the tooling that emits the canonical baseline-then-alternative layout."],"exampleFix":"// before\narms: [{ role: \"alternative\", ... }, { role: \"baseline\", ... }]\n\n// after\narms: [{ role: \"baseline\", ... }, { role: \"alternative\", ... }]","handlingStrategy":"validation","validationCode":"for (const c of report.cases) {\n  const roles = c.cohort.arms.map((a) => a.role);\n  if (roles.join(',') !== 'baseline,alternative') {\n    throw new Error(`case ${c.id}: arms must be exactly [baseline, alternative], got [${roles.join(', ')}]`);\n  }\n}","typeGuard":"function isBaselineAlternativeArms(arms) {\n  return Array.isArray(arms) && arms.length === 2 &&\n    arms[0]?.role === 'baseline' && arms[1]?.role === 'alternative';\n}","tryCatchPattern":"try {\n  validateReport(report);\n} catch (err) {\n  if (String(err.message).includes('arms are not baseline then alternative')) {\n    console.error('Normalize arm order/roles to [baseline, alternative]:', err.message);\n  } else throw err;\n}","preventionTips":["Use a fixture-builder helper that always emits arms as [baseline, alternative].","Never rely on object key insertion order for arm arrays; sort explicitly before serializing.","Stick to the canonical role vocabulary ('baseline'/'alternative'); do not invent synonyms.","Validate fixtures in CI before merging report changes."],"tags":["fixture-validation","enum-value","arm-ordering"],"backgroundTag":"invalid-enum-value","analyzedSha":"3ee70a102609e550bd2e68004bf5990a9341c851","analyzedAt":"2026-09-20T15:53:39.229Z","contentChangedAt":"2026-09-20T15:53:39.229Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}