@featurevisor/core 3.10.0 → 4.0.0

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.
Files changed (299) hide show
  1. package/README.md +20 -2
  2. package/lib/assess-distribution/index.js +6 -2
  3. package/lib/assess-distribution/index.js.map +1 -1
  4. package/lib/benchmark/index.d.ts +1 -1
  5. package/lib/benchmark/index.js +15 -10
  6. package/lib/benchmark/index.js.map +1 -1
  7. package/lib/builder/applyContextToConditions.d.ts +5 -4
  8. package/lib/builder/applyContextToConditions.js +84 -89
  9. package/lib/builder/applyContextToConditions.js.map +1 -1
  10. package/lib/builder/applyContextToDatafile.d.ts +2 -2
  11. package/lib/builder/applyContextToDatafile.js +45 -149
  12. package/lib/builder/applyContextToDatafile.js.map +1 -1
  13. package/lib/builder/applyContextToSegments.d.ts +6 -4
  14. package/lib/builder/applyContextToSegments.js +9 -98
  15. package/lib/builder/applyContextToSegments.js.map +1 -1
  16. package/lib/builder/buildDatafile.d.ts +15 -6
  17. package/lib/builder/buildDatafile.js +320 -220
  18. package/lib/builder/buildDatafile.js.map +1 -1
  19. package/lib/builder/buildProject.d.ts +2 -1
  20. package/lib/builder/buildProject.js +36 -37
  21. package/lib/builder/buildProject.js.map +1 -1
  22. package/lib/builder/buildRuntimeDatafiles.js +2 -0
  23. package/lib/builder/buildRuntimeDatafiles.js.map +1 -1
  24. package/lib/builder/environments.d.ts +3 -0
  25. package/lib/builder/environments.js +26 -0
  26. package/lib/builder/environments.js.map +1 -0
  27. package/lib/builder/hashes.d.ts +5 -5
  28. package/lib/builder/hashes.js +82 -100
  29. package/lib/builder/hashes.js.map +1 -1
  30. package/lib/builder/inflate.d.ts +7 -0
  31. package/lib/builder/inflate.js +26 -0
  32. package/lib/builder/inflate.js.map +1 -0
  33. package/lib/builder/mutateVariables.d.ts +6 -2
  34. package/lib/builder/mutateVariables.js +26 -18
  35. package/lib/builder/mutateVariables.js.map +1 -1
  36. package/lib/builder/mutationEntries.d.ts +5 -0
  37. package/lib/builder/mutationEntries.js +23 -0
  38. package/lib/builder/mutationEntries.js.map +1 -0
  39. package/lib/builder/mutator.d.ts +4 -2
  40. package/lib/builder/mutator.js +20 -209
  41. package/lib/builder/mutator.js.map +1 -1
  42. package/lib/builder/traffic.d.ts +2 -4
  43. package/lib/builder/traffic.js +48 -19
  44. package/lib/builder/traffic.js.map +1 -1
  45. package/lib/builder/variableOverrideProgram.d.ts +9 -0
  46. package/lib/builder/variableOverrideProgram.js +147 -0
  47. package/lib/builder/variableOverrideProgram.js.map +1 -0
  48. package/lib/catalog.d.ts +23 -0
  49. package/lib/catalog.js +117 -0
  50. package/lib/catalog.js.map +1 -0
  51. package/lib/cli/cli.d.ts +2 -0
  52. package/lib/cli/cli.js +38 -13
  53. package/lib/cli/cli.js.map +1 -1
  54. package/lib/cli/options.js +78 -17
  55. package/lib/cli/options.js.map +1 -1
  56. package/lib/cli/plugins.js +13 -3
  57. package/lib/cli/plugins.js.map +1 -1
  58. package/lib/cli/suggestions.d.ts +4 -0
  59. package/lib/cli/suggestions.js +61 -0
  60. package/lib/cli/suggestions.js.map +1 -0
  61. package/lib/config/allowedConditions.d.ts +9 -0
  62. package/lib/config/allowedConditions.js +44 -0
  63. package/lib/config/allowedConditions.js.map +1 -0
  64. package/lib/config/index.d.ts +1 -0
  65. package/lib/config/index.js +1 -0
  66. package/lib/config/index.js.map +1 -1
  67. package/lib/config/projectConfig.d.ts +9 -3
  68. package/lib/config/projectConfig.js +68 -11
  69. package/lib/config/projectConfig.js.map +1 -1
  70. package/lib/config/removedGroups.d.ts +5 -0
  71. package/lib/config/removedGroups.js +62 -0
  72. package/lib/config/removedGroups.js.map +1 -0
  73. package/lib/datasource/adapter.d.ts +10 -1
  74. package/lib/datasource/adapter.js.map +1 -1
  75. package/lib/datasource/attributeNamespaces.d.ts +14 -0
  76. package/lib/datasource/attributeNamespaces.js +70 -0
  77. package/lib/datasource/attributeNamespaces.js.map +1 -0
  78. package/lib/datasource/composition.d.ts +5 -0
  79. package/lib/datasource/composition.js +19 -0
  80. package/lib/datasource/composition.js.map +1 -0
  81. package/lib/datasource/conditions.d.ts +20 -0
  82. package/lib/datasource/conditions.js +113 -0
  83. package/lib/datasource/conditions.js.map +1 -0
  84. package/lib/datasource/datasource.d.ts +18 -12
  85. package/lib/datasource/datasource.js +137 -76
  86. package/lib/datasource/datasource.js.map +1 -1
  87. package/lib/datasource/dependencies.d.ts +52 -0
  88. package/lib/datasource/dependencies.js +347 -0
  89. package/lib/datasource/dependencies.js.map +1 -0
  90. package/lib/datasource/filesystemAdapter.d.ts +31 -1
  91. package/lib/datasource/filesystemAdapter.js +581 -99
  92. package/lib/datasource/filesystemAdapter.js.map +1 -1
  93. package/lib/datasource/index.d.ts +3 -0
  94. package/lib/datasource/index.js +3 -0
  95. package/lib/datasource/index.js.map +1 -1
  96. package/lib/datasource/parseError.d.ts +5 -0
  97. package/lib/datasource/parseError.js +68 -0
  98. package/lib/datasource/parseError.js.map +1 -0
  99. package/lib/datasource/testSpecs.d.ts +4 -0
  100. package/lib/datasource/testSpecs.js +40 -0
  101. package/lib/datasource/testSpecs.js.map +1 -0
  102. package/lib/diff/compare.d.ts +9 -0
  103. package/lib/diff/compare.js +31 -0
  104. package/lib/diff/compare.js.map +1 -0
  105. package/lib/diff/details.d.ts +11 -0
  106. package/lib/diff/details.js +210 -0
  107. package/lib/diff/details.js.map +1 -0
  108. package/lib/diff/git.d.ts +28 -0
  109. package/lib/diff/git.js +195 -0
  110. package/lib/diff/git.js.map +1 -0
  111. package/lib/diff/index.d.ts +36 -0
  112. package/lib/diff/index.js +229 -0
  113. package/lib/diff/index.js.map +1 -0
  114. package/lib/error.d.ts +1 -0
  115. package/lib/error.js +6 -0
  116. package/lib/error.js.map +1 -1
  117. package/lib/evaluate/explain.d.ts +15 -2
  118. package/lib/evaluate/explain.js +273 -79
  119. package/lib/evaluate/explain.js.map +1 -1
  120. package/lib/evaluate/index.js +128 -17
  121. package/lib/evaluate/index.js.map +1 -1
  122. package/lib/evaluate/probeConditions.d.ts +30 -0
  123. package/lib/evaluate/probeConditions.js +165 -0
  124. package/lib/evaluate/probeConditions.js.map +1 -0
  125. package/lib/evaluate/validateExplanation.js +175 -16
  126. package/lib/evaluate/validateExplanation.js.map +1 -1
  127. package/lib/find-duplicate-segments/findDuplicateSegments.js +20 -1
  128. package/lib/find-duplicate-segments/findDuplicateSegments.js.map +1 -1
  129. package/lib/find-usage/index.d.ts +14 -1
  130. package/lib/find-usage/index.js +359 -155
  131. package/lib/find-usage/index.js.map +1 -1
  132. package/lib/generate-code/typescript.js +156 -60
  133. package/lib/generate-code/typescript.js.map +1 -1
  134. package/lib/info/index.js +11 -5
  135. package/lib/info/index.js.map +1 -1
  136. package/lib/init/index.js +234 -28
  137. package/lib/init/index.js.map +1 -1
  138. package/lib/linter/attributeSchema.d.ts +6 -11
  139. package/lib/linter/attributeSchema.js +59 -53
  140. package/lib/linter/attributeSchema.js.map +1 -1
  141. package/lib/linter/comparisonOperators.d.ts +18 -0
  142. package/lib/linter/comparisonOperators.js +82 -0
  143. package/lib/linter/comparisonOperators.js.map +1 -0
  144. package/lib/linter/composedOverrideSchema.d.ts +5 -0
  145. package/lib/linter/composedOverrideSchema.js +243 -0
  146. package/lib/linter/composedOverrideSchema.js.map +1 -0
  147. package/lib/linter/compositionWarnings.d.ts +8 -0
  148. package/lib/linter/compositionWarnings.js +212 -0
  149. package/lib/linter/compositionWarnings.js.map +1 -0
  150. package/lib/linter/conditionKinds.d.ts +12 -0
  151. package/lib/linter/conditionKinds.js +129 -0
  152. package/lib/linter/conditionKinds.js.map +1 -0
  153. package/lib/linter/conditionSchema.d.ts +8 -2
  154. package/lib/linter/conditionSchema.js +253 -52
  155. package/lib/linter/conditionSchema.js.map +1 -1
  156. package/lib/linter/contextWarnings.d.ts +13 -0
  157. package/lib/linter/contextWarnings.js +241 -0
  158. package/lib/linter/contextWarnings.js.map +1 -0
  159. package/lib/linter/definitionReferences.d.ts +39 -0
  160. package/lib/linter/definitionReferences.js +234 -0
  161. package/lib/linter/definitionReferences.js.map +1 -0
  162. package/lib/linter/dependencyDepth.d.ts +14 -0
  163. package/lib/linter/dependencyDepth.js +106 -0
  164. package/lib/linter/dependencyDepth.js.map +1 -0
  165. package/lib/linter/diagnostics.d.ts +129 -0
  166. package/lib/linter/diagnostics.js +84 -0
  167. package/lib/linter/diagnostics.js.map +1 -0
  168. package/lib/linter/featureSchema.d.ts +189 -72
  169. package/lib/linter/featureSchema.js +385 -210
  170. package/lib/linter/featureSchema.js.map +1 -1
  171. package/lib/linter/lintProject.d.ts +4 -1
  172. package/lib/linter/lintProject.js +449 -143
  173. package/lib/linter/lintProject.js.map +1 -1
  174. package/lib/linter/mutationNotation.d.ts +7 -1
  175. package/lib/linter/mutationNotation.js +40 -20
  176. package/lib/linter/mutationNotation.js.map +1 -1
  177. package/lib/linter/mutationOrder.d.ts +6 -0
  178. package/lib/linter/mutationOrder.js +105 -0
  179. package/lib/linter/mutationOrder.js.map +1 -0
  180. package/lib/linter/mutationResultPaths.d.ts +4 -0
  181. package/lib/linter/mutationResultPaths.js +131 -0
  182. package/lib/linter/mutationResultPaths.js.map +1 -0
  183. package/lib/linter/mutationSchema.d.ts +3 -0
  184. package/lib/linter/mutationSchema.js +32 -0
  185. package/lib/linter/mutationSchema.js.map +1 -0
  186. package/lib/linter/printError.d.ts +3 -0
  187. package/lib/linter/printError.js +38 -25
  188. package/lib/linter/printError.js.map +1 -1
  189. package/lib/linter/regexSafety.d.ts +19 -0
  190. package/lib/linter/regexSafety.js +307 -0
  191. package/lib/linter/regexSafety.js.map +1 -0
  192. package/lib/linter/removedConditionFields.d.ts +10 -0
  193. package/lib/linter/removedConditionFields.js +47 -0
  194. package/lib/linter/removedConditionFields.js.map +1 -0
  195. package/lib/linter/requiredFeaturesSchema.d.ts +2 -2
  196. package/lib/linter/requiredFeaturesSchema.js +32 -28
  197. package/lib/linter/requiredFeaturesSchema.js.map +1 -1
  198. package/lib/linter/requiredVariableCost.d.ts +5 -0
  199. package/lib/linter/requiredVariableCost.js +60 -0
  200. package/lib/linter/requiredVariableCost.js.map +1 -0
  201. package/lib/linter/requiredVariablesSchema.d.ts +13 -0
  202. package/lib/linter/requiredVariablesSchema.js +498 -0
  203. package/lib/linter/requiredVariablesSchema.js.map +1 -0
  204. package/lib/linter/reservedNames.d.ts +12 -0
  205. package/lib/linter/reservedNames.js +52 -0
  206. package/lib/linter/reservedNames.js.map +1 -0
  207. package/lib/linter/schema.d.ts +12 -15
  208. package/lib/linter/schema.js +108 -26
  209. package/lib/linter/schema.js.map +1 -1
  210. package/lib/linter/schemaFormats.d.ts +35 -0
  211. package/lib/linter/schemaFormats.js +66 -0
  212. package/lib/linter/schemaFormats.js.map +1 -0
  213. package/lib/linter/segmentSchema.d.ts +11 -1
  214. package/lib/linter/segmentSchema.js +12 -2
  215. package/lib/linter/segmentSchema.js.map +1 -1
  216. package/lib/linter/testSchema.d.ts +394 -2
  217. package/lib/linter/testSchema.js +565 -34
  218. package/lib/linter/testSchema.js.map +1 -1
  219. package/lib/linter/variableSchema.d.ts +60 -43
  220. package/lib/linter/variableSchema.js +459 -60
  221. package/lib/linter/variableSchema.js.map +1 -1
  222. package/lib/linter/zodHelpers.d.ts +8 -1
  223. package/lib/linter/zodHelpers.js +9 -1
  224. package/lib/linter/zodHelpers.js.map +1 -1
  225. package/lib/list/index.js +384 -66
  226. package/lib/list/index.js.map +1 -1
  227. package/lib/list/matrix.d.ts +2 -2
  228. package/lib/list/matrix.js +60 -39
  229. package/lib/list/matrix.js.map +1 -1
  230. package/lib/list/scenarios.d.ts +8 -0
  231. package/lib/list/scenarios.js +84 -0
  232. package/lib/list/scenarios.js.map +1 -0
  233. package/lib/promoter/index.d.ts +1 -1
  234. package/lib/promoter/index.js +469 -210
  235. package/lib/promoter/index.js.map +1 -1
  236. package/lib/sets.js +14 -5
  237. package/lib/sets.js.map +1 -1
  238. package/lib/tester/checks.d.ts +12 -0
  239. package/lib/tester/checks.js +418 -0
  240. package/lib/tester/checks.js.map +1 -0
  241. package/lib/tester/coverage.d.ts +16 -0
  242. package/lib/tester/coverage.js +64 -0
  243. package/lib/tester/coverage.js.map +1 -0
  244. package/lib/tester/datafileKey.d.ts +4 -0
  245. package/lib/tester/datafileKey.js +18 -0
  246. package/lib/tester/datafileKey.js.map +1 -0
  247. package/lib/tester/diagnostics.d.ts +5 -0
  248. package/lib/tester/diagnostics.js +32 -0
  249. package/lib/tester/diagnostics.js.map +1 -0
  250. package/lib/tester/index.d.ts +2 -0
  251. package/lib/tester/printTestResult.d.ts +3 -2
  252. package/lib/tester/printTestResult.js +53 -8
  253. package/lib/tester/printTestResult.js.map +1 -1
  254. package/lib/tester/provenance.d.ts +21 -0
  255. package/lib/tester/provenance.js +98 -0
  256. package/lib/tester/provenance.js.map +1 -0
  257. package/lib/tester/report.d.ts +78 -0
  258. package/lib/tester/report.js +246 -0
  259. package/lib/tester/report.js.map +1 -0
  260. package/lib/tester/segments.d.ts +23 -0
  261. package/lib/tester/segments.js +103 -0
  262. package/lib/tester/segments.js.map +1 -0
  263. package/lib/tester/testFeature.d.ts +2 -0
  264. package/lib/tester/testFeature.js +17 -8
  265. package/lib/tester/testFeature.js.map +1 -1
  266. package/lib/tester/testProject.d.ts +15 -3
  267. package/lib/tester/testProject.js +198 -83
  268. package/lib/tester/testProject.js.map +1 -1
  269. package/lib/tester/testSegment.d.ts +2 -4
  270. package/lib/tester/testSegment.js +89 -7
  271. package/lib/tester/testSegment.js.map +1 -1
  272. package/lib/tester/testVariable.d.ts +2 -2
  273. package/lib/tester/testVariable.js +195 -24
  274. package/lib/tester/testVariable.js.map +1 -1
  275. package/lib/utils/conditionReferences.d.ts +5 -0
  276. package/lib/utils/conditionReferences.js +30 -0
  277. package/lib/utils/conditionReferences.js.map +1 -0
  278. package/lib/utils/extractKeys.d.ts +7 -3
  279. package/lib/utils/extractKeys.js +32 -113
  280. package/lib/utils/extractKeys.js.map +1 -1
  281. package/lib/utils/git.d.ts +7 -2
  282. package/lib/utils/git.js +87 -72
  283. package/lib/utils/git.js.map +1 -1
  284. package/package.json +11 -8
  285. package/lib/builder/getFeatureRanges.d.ts +0 -11
  286. package/lib/builder/getFeatureRanges.js +0 -70
  287. package/lib/builder/getFeatureRanges.js.map +0 -1
  288. package/lib/datasource/requiredFeatures.d.ts +0 -14
  289. package/lib/datasource/requiredFeatures.js +0 -75
  290. package/lib/datasource/requiredFeatures.js.map +0 -1
  291. package/lib/linter/checkCircularDependency.d.ts +0 -3
  292. package/lib/linter/checkCircularDependency.js +0 -8
  293. package/lib/linter/checkCircularDependency.js.map +0 -1
  294. package/lib/linter/checkPercentageExceedingSlot.d.ts +0 -3
  295. package/lib/linter/checkPercentageExceedingSlot.js +0 -45
  296. package/lib/linter/checkPercentageExceedingSlot.js.map +0 -1
  297. package/lib/linter/groupSchema.d.ts +0 -11
  298. package/lib/linter/groupSchema.js +0 -31
  299. package/lib/linter/groupSchema.js.map +0 -1
@@ -1,9 +1,188 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getChecksZodSchema = getChecksZodSchema;
4
+ exports.getTestAuthoringShapes = getTestAuthoringShapes;
3
5
  exports.getTestsZodSchema = getTestsZodSchema;
6
+ exports.getScenariosZodSchema = getScenariosZodSchema;
4
7
  const zod_1 = require("zod");
8
+ const diagnostics_1 = require("./diagnostics");
5
9
  const zodHelpers_1 = require("./zodHelpers");
6
- function getTestsZodSchema(projectConfig, availableFeatureKeys, availableSegmentKeys, availableTargetKeys, availableVariableKeys = [], featuresByKey = {}) {
10
+ const checks_1 = require("../tester/checks");
11
+ const matrix_1 = require("../list/matrix");
12
+ const scenarios_1 = require("../list/scenarios");
13
+ const testSpecs_1 = require("../datasource/testSpecs");
14
+ const comparisonOperators_1 = require("./comparisonOperators");
15
+ // Mirrors the SDK EvaluationReason union. Test specs compare these strings exactly.
16
+ const evaluationReasons = [
17
+ "feature_not_found",
18
+ "disabled",
19
+ "no_variations",
20
+ "variation_disabled",
21
+ "variable_not_found",
22
+ "variable_default",
23
+ "variable_composed",
24
+ "variable_disabled",
25
+ "variable_override_variation",
26
+ "variable_override_rule",
27
+ "conditions_unmet",
28
+ "no_match",
29
+ "forced",
30
+ "sticky",
31
+ "rule",
32
+ "allocated",
33
+ "error",
34
+ ];
35
+ /** Structural check grammar shared by linting and generated editor schemas. */
36
+ function getChecksZodSchema() {
37
+ const placeholder = zod_1.z.string().regex(/^\${{\s*([^{}]+?)\s*}}$/);
38
+ const operator = (names) => zod_1.z.union([zod_1.z.enum(names), placeholder]);
39
+ const unary = ["exists", "notExists", "isNull", "notNull", "empty", "notEmpty"];
40
+ const regex = ["matches", "notMatches"];
41
+ const binary = checks_1.checkOperators.filter((operator) => !unary.includes(operator) &&
42
+ !regex.includes(operator));
43
+ const metadata = { key: zod_1.z.string().min(1).optional(), description: zod_1.z.string().optional() };
44
+ const reference = zod_1.z
45
+ .object({
46
+ feature: zod_1.z.string().min(1).optional(),
47
+ variable: zod_1.z.string().min(1).optional(),
48
+ path: zod_1.z.union([zod_1.z.string(), zod_1.z.array(zod_1.z.union([zod_1.z.string(), zod_1.z.number()]))]).optional(),
49
+ })
50
+ .strict();
51
+ const jsonValue = zod_1.z.lazy(() => zod_1.z.union([
52
+ zod_1.z.string(),
53
+ zod_1.z.number(),
54
+ zod_1.z.boolean(),
55
+ zod_1.z.null(),
56
+ zod_1.z.array(jsonValue),
57
+ zod_1.z.record(zod_1.z.string(), jsonValue),
58
+ ]));
59
+ const variableBase = {
60
+ ...metadata,
61
+ feature: zod_1.z.string().min(1).optional(),
62
+ variable: zod_1.z.string().min(1).optional(),
63
+ path: reference.shape.path,
64
+ };
65
+ const flags = zod_1.z.union([
66
+ zod_1.z
67
+ .string()
68
+ .regex(/^[gims]*$/)
69
+ .refine((value) => new Set(value).size === value.length),
70
+ placeholder,
71
+ ]);
72
+ const variableLeaves = [
73
+ zod_1.z.object({ ...variableBase, operator: operator(unary) }).strict(),
74
+ zod_1.z.object({ ...variableBase, operator: operator(binary), value: jsonValue }).strict(),
75
+ zod_1.z.object({ ...variableBase, operator: operator(binary), compareTo: reference }).strict(),
76
+ zod_1.z
77
+ .object({
78
+ ...variableBase,
79
+ operator: operator(regex),
80
+ value: jsonValue,
81
+ regexFlags: flags.optional(),
82
+ })
83
+ .strict(),
84
+ zod_1.z
85
+ .object({
86
+ ...variableBase,
87
+ operator: operator(regex),
88
+ compareTo: reference,
89
+ regexFlags: flags.optional(),
90
+ })
91
+ .strict(),
92
+ ];
93
+ const segment = zod_1.z
94
+ .object({
95
+ ...metadata,
96
+ segment: zod_1.z.string().min(1),
97
+ matches: zod_1.z.union([zod_1.z.boolean(), placeholder]),
98
+ })
99
+ .strict();
100
+ const featureByEnabled = zod_1.z
101
+ .object({
102
+ ...metadata,
103
+ feature: zod_1.z.string().min(1),
104
+ enabled: zod_1.z.union([zod_1.z.boolean(), placeholder]),
105
+ variation: zod_1.z.union([zod_1.z.string(), zod_1.z.null()]).optional(),
106
+ })
107
+ .strict();
108
+ const featureByVariation = zod_1.z
109
+ .object({
110
+ ...metadata,
111
+ feature: zod_1.z.string().min(1),
112
+ variation: zod_1.z.union([zod_1.z.string(), zod_1.z.null()]),
113
+ enabled: zod_1.z.union([zod_1.z.boolean(), placeholder]).optional(),
114
+ })
115
+ .strict();
116
+ const check = zod_1.z.lazy(() => zod_1.z.union([
117
+ zod_1.z.object({ ...metadata, and: checks }).strict(),
118
+ zod_1.z.object({ ...metadata, or: checks }).strict(),
119
+ zod_1.z.object({ ...metadata, not: checks }).strict(),
120
+ segment,
121
+ featureByEnabled,
122
+ featureByVariation,
123
+ ...variableLeaves,
124
+ ]));
125
+ const checks = zod_1.z
126
+ .array(check)
127
+ .min(1, "checks and logical groups must be nonempty arrays");
128
+ return checks;
129
+ }
130
+ function rootOwnerSuggestion(value) {
131
+ if (!value || typeof value !== "object" || Array.isArray(value))
132
+ return undefined;
133
+ const candidates = ["feature", "segment", "variable"];
134
+ for (const key of Object.keys(value)) {
135
+ for (const owner of candidates) {
136
+ if (key === owner)
137
+ continue;
138
+ const previous = Array.from({ length: owner.length + 1 }, (_, i) => i);
139
+ let row = previous;
140
+ for (let i = 0; i < key.length; i++) {
141
+ const next = [i + 1];
142
+ for (let j = 0; j < owner.length; j++) {
143
+ next.push(Math.min(next[j] + 1, row[j + 1] + 1, row[j] + (key[i] === owner[j] ? 0 : 1)));
144
+ }
145
+ row = next;
146
+ }
147
+ if (row[owner.length] <= 1)
148
+ return { key, owner };
149
+ }
150
+ }
151
+ return undefined;
152
+ }
153
+ function getTestAuthoringShapes(projectConfig, availableFeatureKeys, availableSegmentKeys, availableTargetKeys, availableVariableKeys = [], featuresByKey = {}, segmentsByKey = {}) {
154
+ const checksZodSchema = getChecksZodSchema();
155
+ /** Feature assertions named sticky features `sticky` before v4. */
156
+ function refineRemovedSticky(assertion, path, ctx) {
157
+ if (assertion.sticky === undefined)
158
+ return;
159
+ ctx.addIssue({
160
+ code: "custom",
161
+ path: [...path, "sticky"],
162
+ message: "Replace `sticky` with `stickyFeatures`, as in segment and variable specs.",
163
+ params: { code: "removed_test_field" },
164
+ });
165
+ }
166
+ const configuredEnvironments = Array.isArray(projectConfig.environments)
167
+ ? projectConfig.environments
168
+ : undefined;
169
+ /** One environment field for every spec kind, with messages that say what to change. */
170
+ function environmentZodSchema(required) {
171
+ if (!configuredEnvironments) {
172
+ return zod_1.z
173
+ .never({
174
+ error: "Remove environment. This project does not configure environments.",
175
+ })
176
+ .optional();
177
+ }
178
+ const available = configuredEnvironments.join(", ");
179
+ const schema = (0, zodHelpers_1.refineWithMessage)(zod_1.z.string({
180
+ error: (issue) => issue.input === undefined
181
+ ? `Add environment. This project configures environments: ${available}.`
182
+ : "environment must be a string",
183
+ }), (value) => value.indexOf("${{") === 0 || configuredEnvironments.includes(value), (value) => `Unknown environment "${value}". Available environments: ${available}.`);
184
+ return required ? schema : schema.optional();
185
+ }
7
186
  function validateAssertionKeys(assertions, ctx) {
8
187
  const keyedAssertions = assertions.filter((assertion) => typeof assertion.key === "string");
9
188
  if (keyedAssertions.length > 0 && keyedAssertions.length !== assertions.length) {
@@ -148,7 +327,7 @@ function getTestsZodSchema(projectConfig, availableFeatureKeys, availableSegment
148
327
  ctx.addIssue({
149
328
  code: zod_1.z.ZodIssueCode.custom,
150
329
  path: [featureKey],
151
- message: `Unknown feature "${featureKey}"`,
330
+ message: `Unknown feature "${featureKey}".${(0, diagnostics_1.suggestKey)(featureKey, availableFeatureKeys)}`,
152
331
  });
153
332
  return;
154
333
  }
@@ -196,10 +375,11 @@ function getTestsZodSchema(projectConfig, availableFeatureKeys, availableSegment
196
375
  });
197
376
  function validateVariableExpectations(assertion, ctx) {
198
377
  if (typeof assertion.expectedValue === "undefined" &&
378
+ typeof assertion.checks === "undefined" &&
199
379
  typeof assertion.expectedEvaluation === "undefined") {
200
380
  ctx.addIssue({
201
381
  code: zod_1.z.ZodIssueCode.custom,
202
- message: "Expected at least one of expectedValue or expectedEvaluation",
382
+ message: "Expected at least one of expectedValue, expectedEvaluation, or checks",
203
383
  });
204
384
  }
205
385
  }
@@ -256,7 +436,20 @@ function getTestsZodSchema(projectConfig, availableFeatureKeys, availableSegment
256
436
  .object({
257
437
  type: zod_1.z.enum(["flag", "variation", "variable"]).optional(),
258
438
  featureKey: zod_1.z.string().optional(),
259
- reason: zod_1.z.string().optional(),
439
+ reason: zod_1.z
440
+ .string()
441
+ .superRefine((reason, ctx) => {
442
+ if (evaluationReasons.includes(reason) || reason.includes("${{"))
443
+ return;
444
+ ctx.addIssue({
445
+ code: zod_1.z.ZodIssueCode.custom,
446
+ message: reason === "required" || reason === "required_features_unmet"
447
+ ? `Evaluation reason "${reason}" was removed in v4. Unmet feature dependencies are conditions now, so use "conditions_unmet".`
448
+ : `Unknown evaluation reason "${reason}".${(0, diagnostics_1.suggestKey)(reason, evaluationReasons)}`,
449
+ params: { code: "unknown_evaluation_reason" },
450
+ });
451
+ })
452
+ .optional(),
260
453
  bucketKey: zod_1.z.string().optional(),
261
454
  bucketValue: zod_1.z.number().optional(),
262
455
  ruleKey: zod_1.z.string().optional(),
@@ -265,10 +458,8 @@ function getTestsZodSchema(projectConfig, availableFeatureKeys, availableSegment
265
458
  traffic: zod_1.z.unknown().optional(),
266
459
  forceIndex: zod_1.z.number().int().nonnegative().optional(),
267
460
  force: zod_1.z.unknown().optional(),
268
- required: zod_1.z.unknown().optional(),
269
- requiredFeatures: zod_1.z.unknown().optional(),
461
+ conditions: zod_1.z.unknown().optional(),
270
462
  stickyFeature: zod_1.z.unknown().optional(),
271
- sticky: zod_1.z.unknown().optional(),
272
463
  variation: zod_1.z.unknown().optional(),
273
464
  variationValue: zod_1.z.string().optional(),
274
465
  variableKey: zod_1.z.string().optional(),
@@ -277,9 +468,24 @@ function getTestsZodSchema(projectConfig, availableFeatureKeys, availableSegment
277
468
  variableOverrideIndex: zod_1.z.number().int().nonnegative().optional(),
278
469
  variableOverrideKey: zod_1.z.string().optional(),
279
470
  variableOverridePath: zod_1.z.array(zod_1.z.string()).optional(),
471
+ variableOverridePaths: zod_1.z.array(zod_1.z.array(zod_1.z.string()).min(1)).optional(),
280
472
  variable: zod_1.z.unknown().optional(),
473
+ requiredFeatures: zod_1.z.unknown().optional(),
474
+ requiredVariables: zod_1.z.unknown().optional(),
281
475
  })
282
476
  .strict()
477
+ .superRefine((expectedEvaluation, ctx) => {
478
+ for (const key of ["requiredFeatures", "requiredVariables"]) {
479
+ if (!Object.prototype.hasOwnProperty.call(expectedEvaluation, key))
480
+ continue;
481
+ ctx.addIssue({
482
+ code: zod_1.z.ZodIssueCode.custom,
483
+ path: [key],
484
+ message: `\`${key}\` was removed from evaluations in v4. Dependencies are conditions now. Assert \`reason: conditions_unmet\` for an unmet dependency.`,
485
+ params: { code: "removed_evaluation_field" },
486
+ });
487
+ }
488
+ })
283
489
  .refine((expectedEvaluation) => Object.keys(expectedEvaluation).length > 0, "Expected evaluation must contain at least one field");
284
490
  const expectedEvaluationsZodSchema = zod_1.z
285
491
  .object({
@@ -291,7 +497,7 @@ function getTestsZodSchema(projectConfig, availableFeatureKeys, availableSegment
291
497
  const segmentTestZodSchema = zod_1.z
292
498
  .object({
293
499
  promotable: zod_1.z.boolean().optional(),
294
- segment: (0, zodHelpers_1.refineWithMessage)(zod_1.z.string(), (value) => availableSegmentKeys.includes(value), (value) => `Unknown segment "${value}"`),
500
+ segment: (0, zodHelpers_1.refineWithMessage)(zod_1.z.string(), (value) => availableSegmentKeys.includes(value), (value) => `Unknown segment "${value}".${(0, diagnostics_1.suggestKey)(value, availableSegmentKeys)}`),
295
501
  assertions: zod_1.z
296
502
  .array(zod_1.z
297
503
  .object({
@@ -300,20 +506,54 @@ function getTestsZodSchema(projectConfig, availableFeatureKeys, availableSegment
300
506
  matrix: matrixZodSchema.optional(),
301
507
  description: zod_1.z.string().optional(),
302
508
  context: zod_1.z.record(zod_1.z.string(), zod_1.z.unknown()),
509
+ environment: environmentZodSchema(false),
510
+ at: atZodSchema.optional(),
511
+ stickyFeatures: stickyFeaturesZodSchema.optional(),
512
+ stickyVariables: stickyVariablesZodSchema.optional(),
303
513
  expectedToMatch: zod_1.z.boolean(),
304
514
  })
305
515
  .strict()
306
516
  .superRefine((assertion, ctx) => {
307
517
  validateMatrixPlaceholders(assertion, assertion.matrix, [], ctx);
518
+ validateMatrixAt(assertion, ctx);
519
+ validateMatrixSelectorValues(assertion.environment, assertion.matrix, projectConfig.environments || [], "environment", ctx);
520
+ validateStickyFeatureMatrixValues(assertion.stickyFeatures, assertion.matrix, ["stickyFeatures"], ctx);
308
521
  }))
309
522
  .min(1, "Test spec must contain at least one assertion")
310
523
  .superRefine(validateAssertionKeys),
311
524
  })
312
- .strict();
525
+ .strict()
526
+ .superRefine((spec, ctx) => {
527
+ function hasDependency(expression, seen = new Set()) {
528
+ if (typeof expression === "string") {
529
+ if (expression === "*" || seen.has(expression))
530
+ return false;
531
+ return hasDependency(segmentsByKey[expression]?.conditions, new Set(seen).add(expression));
532
+ }
533
+ if (Array.isArray(expression))
534
+ return expression.some((child) => hasDependency(child, seen));
535
+ if (!expression || typeof expression !== "object")
536
+ return false;
537
+ if ("feature" in expression || "variable" in expression)
538
+ return true;
539
+ return ["and", "or", "not"].some((key) => hasDependency(expression[key], seen));
540
+ }
541
+ if (Array.isArray(projectConfig.environments) &&
542
+ hasDependency(segmentsByKey[spec.segment]?.conditions)) {
543
+ spec.assertions.forEach((assertion, index) => {
544
+ if (assertion.environment === undefined)
545
+ ctx.addIssue({
546
+ code: "custom",
547
+ path: ["assertions", index, "environment"],
548
+ message: "An environment is required when a segment depends on a feature or variable.",
549
+ });
550
+ });
551
+ }
552
+ });
313
553
  const featureTestZodSchema = zod_1.z
314
554
  .object({
315
555
  promotable: zod_1.z.boolean().optional(),
316
- feature: (0, zodHelpers_1.refineWithMessage)(zod_1.z.string(), (value) => availableFeatureKeys.includes(value), (value) => `Unknown feature "${value}"`),
556
+ feature: (0, zodHelpers_1.refineWithMessage)(zod_1.z.string(), (value) => availableFeatureKeys.includes(value), (value) => `Unknown feature "${value}".${(0, diagnostics_1.suggestKey)(value, availableFeatureKeys)}`),
317
557
  assertions: zod_1.z
318
558
  .array(zod_1.z
319
559
  .object({
@@ -322,20 +562,7 @@ function getTestsZodSchema(projectConfig, availableFeatureKeys, availableSegment
322
562
  matrix: matrixZodSchema.optional(),
323
563
  description: zod_1.z.string().optional(),
324
564
  at: atZodSchema,
325
- environment: Array.isArray(projectConfig.environments)
326
- ? (0, zodHelpers_1.refineWithMessage)(zod_1.z.string(), (value) => {
327
- if (value.indexOf("${{") === 0) {
328
- // allow unknown strings for matrix
329
- return true;
330
- }
331
- // otherwise only known environments should be passed
332
- if (Array.isArray(projectConfig.environments) &&
333
- projectConfig.environments.includes(value)) {
334
- return true;
335
- }
336
- return false;
337
- }, (value) => `Unknown environment "${value}"`)
338
- : zod_1.z.never().optional(),
565
+ environment: environmentZodSchema(true),
339
566
  target: (0, zodHelpers_1.refineWithMessage)(zod_1.z.string(), (value) => {
340
567
  if (value.indexOf("${{") === 0) {
341
568
  return true;
@@ -343,7 +570,10 @@ function getTestsZodSchema(projectConfig, availableFeatureKeys, availableSegment
343
570
  return availableTargetKeys.includes(value);
344
571
  }, (value) => `Unknown target "${value}"`).optional(),
345
572
  // parent
346
- sticky: zod_1.z.record(zod_1.z.string(), zod_1.z.record(zod_1.z.string(), zod_1.z.any())).optional(),
573
+ stickyFeatures: stickyFeaturesZodSchema.optional(),
574
+ stickyVariables: stickyVariablesZodSchema.optional(),
575
+ // Accepted only to explain the rename. See refineRemovedSticky.
576
+ sticky: zod_1.z.unknown().optional(),
347
577
  context: zod_1.z.record(zod_1.z.string(), zod_1.z.unknown()).optional(),
348
578
  defaultVariationValue: zod_1.z.string().optional(),
349
579
  defaultVariableValues: zod_1.z.record(zod_1.z.string(), zod_1.z.unknown()).optional(),
@@ -352,9 +582,13 @@ function getTestsZodSchema(projectConfig, availableFeatureKeys, availableSegment
352
582
  expectedVariables: zod_1.z.record(zod_1.z.string(), zod_1.z.unknown()).optional(),
353
583
  expectedEvaluations: expectedEvaluationsZodSchema.optional(),
354
584
  children: zod_1.z
355
- .array(zod_1.z.object({
585
+ .array(zod_1.z
586
+ .object({
587
+ description: zod_1.z.string().optional(),
356
588
  // copied from parent
357
- sticky: zod_1.z.record(zod_1.z.string(), zod_1.z.record(zod_1.z.string(), zod_1.z.any())).optional(),
589
+ stickyFeatures: stickyFeaturesZodSchema.optional(),
590
+ stickyVariables: stickyVariablesZodSchema.optional(),
591
+ sticky: zod_1.z.unknown().optional(),
358
592
  context: zod_1.z.record(zod_1.z.string(), zod_1.z.unknown()).optional(),
359
593
  defaultVariationValue: zod_1.z.string().optional(),
360
594
  defaultVariableValues: zod_1.z.record(zod_1.z.string(), zod_1.z.unknown()).optional(),
@@ -362,15 +596,20 @@ function getTestsZodSchema(projectConfig, availableFeatureKeys, availableSegment
362
596
  expectedVariation: zod_1.z.string().nullable().optional(),
363
597
  expectedVariables: zod_1.z.record(zod_1.z.string(), zod_1.z.unknown()).optional(),
364
598
  expectedEvaluations: expectedEvaluationsZodSchema.optional(),
365
- }))
599
+ })
600
+ .strict())
366
601
  .optional(),
367
602
  })
368
603
  .strict()
369
604
  .superRefine((assertion, ctx) => {
605
+ refineRemovedSticky(assertion, [], ctx);
606
+ assertion.children?.forEach((child, index) => refineRemovedSticky(child, ["children", index], ctx));
370
607
  validateMatrixPlaceholders(assertion, assertion.matrix, [], ctx);
371
608
  validateMatrixAt(assertion, ctx);
372
609
  validateMatrixSelectorValues(assertion.environment, assertion.matrix, projectConfig.environments || [], "environment", ctx);
373
610
  validateMatrixSelectorValues(assertion.target, assertion.matrix, availableTargetKeys, "target", ctx);
611
+ validateStickyFeatureMatrixValues(assertion.stickyFeatures, assertion.matrix, ["stickyFeatures"], ctx);
612
+ assertion.children?.forEach((child, index) => validateStickyFeatureMatrixValues(child.stickyFeatures, assertion.matrix, ["children", index, "stickyFeatures"], ctx));
374
613
  }))
375
614
  .min(1, "Test spec must contain at least one assertion")
376
615
  .superRefine(validateAssertionKeys),
@@ -387,9 +626,7 @@ function getTestsZodSchema(projectConfig, availableFeatureKeys, availableSegment
387
626
  promotable: zod_1.z.boolean().optional(),
388
627
  matrix: matrixZodSchema.optional(),
389
628
  description: zod_1.z.string().optional(),
390
- environment: Array.isArray(projectConfig.environments)
391
- ? (0, zodHelpers_1.refineWithMessage)(zod_1.z.string(), (value) => value.indexOf("${{") === 0 || projectConfig.environments.includes(value), (value) => `Unknown environment "${value}"`)
392
- : zod_1.z.never().optional(),
629
+ environment: environmentZodSchema(true),
393
630
  target: (0, zodHelpers_1.refineWithMessage)(zod_1.z.string(), (value) => value.indexOf("${{") === 0 || availableTargetKeys.includes(value), (value) => `Unknown target "${value}"`).optional(),
394
631
  at: atZodSchema.optional(),
395
632
  stickyFeatures: stickyFeaturesZodSchema.optional(),
@@ -398,15 +635,18 @@ function getTestsZodSchema(projectConfig, availableFeatureKeys, availableSegment
398
635
  defaultVariableValue: zod_1.z.unknown().optional(),
399
636
  expectedValue: zod_1.z.unknown().optional(),
400
637
  expectedEvaluation: expectedEvaluationZodSchema.optional(),
638
+ checks: checksZodSchema.optional(),
401
639
  children: zod_1.z
402
640
  .array(zod_1.z
403
641
  .object({
642
+ description: zod_1.z.string().optional(),
404
643
  stickyFeatures: stickyFeaturesZodSchema.optional(),
405
644
  stickyVariables: stickyVariablesZodSchema.optional(),
406
645
  context: zod_1.z.record(zod_1.z.string(), zod_1.z.unknown()).optional(),
407
646
  defaultVariableValue: zod_1.z.unknown().optional(),
408
647
  expectedValue: zod_1.z.unknown().optional(),
409
648
  expectedEvaluation: expectedEvaluationZodSchema.optional(),
649
+ checks: checksZodSchema.optional(),
410
650
  })
411
651
  .strict()
412
652
  .superRefine(validateVariableExpectations))
@@ -425,10 +665,11 @@ function getTestsZodSchema(projectConfig, availableFeatureKeys, availableSegment
425
665
  });
426
666
  if (typeof assertion.expectedValue === "undefined" &&
427
667
  typeof assertion.expectedEvaluation === "undefined" &&
668
+ typeof assertion.checks === "undefined" &&
428
669
  !assertion.children?.length) {
429
670
  ctx.addIssue({
430
671
  code: zod_1.z.ZodIssueCode.custom,
431
- message: "Expected at least one of expectedValue, expectedEvaluation, or children",
672
+ message: "Expected at least one of expectedValue, expectedEvaluation, checks, or children",
432
673
  });
433
674
  }
434
675
  }))
@@ -436,7 +677,72 @@ function getTestsZodSchema(projectConfig, availableFeatureKeys, availableSegment
436
677
  .superRefine(validateAssertionKeys),
437
678
  })
438
679
  .strict();
439
- return zod_1.z.unknown().superRefine((value, ctx) => {
680
+ const scenarioTestZodSchema = zod_1.z
681
+ .object({
682
+ scenario: zod_1.z.string().min(1),
683
+ promotable: zod_1.z.boolean().optional(),
684
+ assertions: zod_1.z
685
+ .array(zod_1.z
686
+ .object({
687
+ key: zod_1.z.string().min(1).optional(),
688
+ promotable: zod_1.z.boolean().optional(),
689
+ description: zod_1.z.string().optional(),
690
+ matrix: matrixZodSchema.optional(),
691
+ environment: environmentZodSchema(true),
692
+ target: zod_1.z.string().optional(),
693
+ at: atZodSchema.optional(),
694
+ context: zod_1.z.record(zod_1.z.string(), zod_1.z.unknown()).optional(),
695
+ stickyFeatures: stickyFeaturesZodSchema.optional(),
696
+ stickyVariables: stickyVariablesZodSchema.optional(),
697
+ checks: checksZodSchema.optional(),
698
+ children: zod_1.z
699
+ .array(zod_1.z
700
+ .object({
701
+ description: zod_1.z.string().optional(),
702
+ context: zod_1.z.record(zod_1.z.string(), zod_1.z.unknown()).optional(),
703
+ stickyFeatures: stickyFeaturesZodSchema.optional(),
704
+ stickyVariables: stickyVariablesZodSchema.optional(),
705
+ checks: checksZodSchema,
706
+ })
707
+ .strict())
708
+ .min(1)
709
+ .optional(),
710
+ })
711
+ .strict()
712
+ .superRefine((assertion, ctx) => {
713
+ if (assertion.checks === undefined && !assertion.children?.length)
714
+ ctx.addIssue({
715
+ code: "custom",
716
+ message: "Scenario assertions require checks or children",
717
+ });
718
+ validateMatrixPlaceholders(assertion, assertion.matrix, [], ctx);
719
+ validateMatrixAt(assertion, ctx);
720
+ validateMatrixSelectorValues(assertion.environment, assertion.matrix, projectConfig.environments || [], "environment", ctx);
721
+ validateMatrixSelectorValues(assertion.target, assertion.matrix, availableTargetKeys, "target", ctx);
722
+ if (assertion.environment &&
723
+ !assertion.environment.startsWith("${{") &&
724
+ !(projectConfig.environments || []).includes(assertion.environment))
725
+ ctx.addIssue({
726
+ code: "custom",
727
+ path: ["environment"],
728
+ message: `Unknown environment "${assertion.environment}"`,
729
+ });
730
+ if (assertion.target &&
731
+ !assertion.target.startsWith("${{") &&
732
+ !availableTargetKeys.includes(assertion.target))
733
+ ctx.addIssue({
734
+ code: "custom",
735
+ path: ["target"],
736
+ message: `Unknown target "${assertion.target}"`,
737
+ });
738
+ validateStickyFeatureMatrixValues(assertion.stickyFeatures, assertion.matrix, ["stickyFeatures"], ctx);
739
+ assertion.children?.forEach((child, i) => validateStickyFeatureMatrixValues(child.stickyFeatures, assertion.matrix, ["children", i, "stickyFeatures"], ctx));
740
+ }))
741
+ .min(1)
742
+ .superRefine(validateAssertionKeys),
743
+ })
744
+ .strict();
745
+ const schema = zod_1.z.unknown().superRefine((value, ctx) => {
440
746
  const candidate = value && typeof value === "object" ? value : {};
441
747
  const schema = Object.prototype.hasOwnProperty.call(candidate, "feature")
442
748
  ? featureTestZodSchema
@@ -444,11 +750,236 @@ function getTestsZodSchema(projectConfig, availableFeatureKeys, availableSegment
444
750
  ? segmentTestZodSchema
445
751
  : Object.prototype.hasOwnProperty.call(candidate, "variable")
446
752
  ? variableTestZodSchema
447
- : zod_1.z.never();
753
+ : Object.prototype.hasOwnProperty.call(candidate, "scenario")
754
+ ? scenarioTestZodSchema
755
+ : zod_1.z.never();
448
756
  const result = schema.safeParse(value);
449
757
  if (!result.success) {
450
758
  result.error.issues.forEach((issue) => ctx.addIssue({ ...issue }));
759
+ if (result.error.issues.some((issue) => issue.path.includes("checks"))) {
760
+ const owner = typeof candidate.variable === "string" ? candidate.variable : undefined;
761
+ (Array.isArray(candidate.assertions) ? candidate.assertions : []).forEach((assertion, index) => {
762
+ const entries = [
763
+ { value: assertion, path: ["assertions", index] },
764
+ ...(Array.isArray(assertion?.children)
765
+ ? assertion.children.map((child, childIndex) => ({
766
+ value: child,
767
+ path: ["assertions", index, "children", childIndex],
768
+ }))
769
+ : []),
770
+ ];
771
+ for (const entry of entries) {
772
+ if (entry.value?.checks === undefined)
773
+ continue;
774
+ try {
775
+ (0, checks_1.getCheckReferences)(entry.value.checks, owner);
776
+ }
777
+ catch (error) {
778
+ ctx.addIssue({
779
+ code: zod_1.z.ZodIssueCode.custom,
780
+ path: [...entry.path, "checks"],
781
+ message: error instanceof Error ? error.message : String(error),
782
+ });
783
+ }
784
+ }
785
+ });
786
+ }
787
+ return;
788
+ }
789
+ if (typeof candidate.feature === "string") {
790
+ const feature = featuresByKey[candidate.feature];
791
+ // Definition metadata is optional for callers generating editor schemas.
792
+ if (feature) {
793
+ const assertions = candidate.assertions;
794
+ assertions.forEach((assertion, index) => {
795
+ const expectations = [
796
+ { value: assertion, path: ["assertions", index] },
797
+ ...(assertion.children || []).map((child, i) => ({
798
+ value: child,
799
+ path: ["assertions", index, "children", i],
800
+ })),
801
+ ];
802
+ for (const item of expectations) {
803
+ if (Object.prototype.hasOwnProperty.call(item.value, "expectedVariation") &&
804
+ !feature.variations?.length &&
805
+ feature.disabledVariationValue === undefined) {
806
+ ctx.addIssue({
807
+ code: zod_1.z.ZodIssueCode.custom,
808
+ path: [...item.path, "expectedVariation"],
809
+ message: `Feature "${candidate.feature}" has no variations. Use expectedToBeEnabled to test its flag.`,
810
+ });
811
+ }
812
+ for (const key of Object.keys(item.value.expectedVariables || {})) {
813
+ if (!Object.prototype.hasOwnProperty.call(feature.variablesSchema || {}, key)) {
814
+ ctx.addIssue({
815
+ code: zod_1.z.ZodIssueCode.custom,
816
+ path: [...item.path, "expectedVariables", key],
817
+ message: `Unknown variable "${key}" in feature "${candidate.feature}".${(0, diagnostics_1.suggestKey)(key, Object.keys(feature.variablesSchema || {}))}`,
818
+ });
819
+ }
820
+ }
821
+ }
822
+ });
823
+ }
824
+ }
825
+ if ("variable" in candidate || "scenario" in candidate) {
826
+ const owner = typeof candidate.variable === "string" ? candidate.variable : undefined;
827
+ candidate.assertions.forEach((assertion, index) => {
828
+ const combinations = assertion.matrix ? (0, matrix_1.getMatrixCombinations)(assertion.matrix) : [{}];
829
+ for (const combination of combinations) {
830
+ const expanded = (0, matrix_1.applyCombinationToValue)(assertion, combination);
831
+ const expectations = [
832
+ { value: expanded, path: ["assertions", index] },
833
+ ...(expanded.children || []).map((child, i) => ({
834
+ value: child,
835
+ path: ["assertions", index, "children", i],
836
+ })),
837
+ ];
838
+ for (const item of expectations) {
839
+ if (item.value.checks === undefined)
840
+ continue;
841
+ for (const issue of (0, comparisonOperators_1.findDisallowedOperators)(item.value.checks, projectConfig.disallowOperators || [], [...item.path, "checks"])) {
842
+ ctx.addIssue({
843
+ code: zod_1.z.ZodIssueCode.custom,
844
+ path: issue.path,
845
+ message: `Operator "${issue.operator}" is disallowed by project configuration.`,
846
+ });
847
+ }
848
+ try {
849
+ const references = (0, checks_1.getCheckReferences)(item.value.checks, owner);
850
+ for (const reference of references) {
851
+ if (reference.segment !== undefined) {
852
+ if (!availableSegmentKeys.includes(reference.segment))
853
+ throw new Error(`Unknown segment "${reference.segment}".${(0, diagnostics_1.suggestKey)(reference.segment, availableSegmentKeys)}`);
854
+ }
855
+ else if (reference.feature !== undefined) {
856
+ if (!availableFeatureKeys.includes(reference.feature))
857
+ throw new Error(`Unknown feature "${reference.feature}".${(0, diagnostics_1.suggestKey)(reference.feature, availableFeatureKeys)}`);
858
+ if (reference.variable === undefined)
859
+ continue;
860
+ const feature = featuresByKey[reference.feature];
861
+ if (feature &&
862
+ !Object.prototype.hasOwnProperty.call(feature.variablesSchema || {}, reference.variable))
863
+ throw new Error(`Unknown variable "${reference.variable}" in feature "${reference.feature}"`);
864
+ }
865
+ else {
866
+ const key = reference.variable || owner;
867
+ if (!availableVariableKeys.includes(key))
868
+ throw new Error(`Unknown global variable "${key}"`);
869
+ }
870
+ }
871
+ }
872
+ catch (error) {
873
+ ctx.addIssue({
874
+ code: "custom",
875
+ path: [...item.path, "checks"],
876
+ message: error instanceof Error ? error.message : String(error),
877
+ });
878
+ }
879
+ }
880
+ }
881
+ });
882
+ }
883
+ });
884
+ return {
885
+ schema,
886
+ featureTestZodSchema,
887
+ segmentTestZodSchema,
888
+ variableTestZodSchema,
889
+ scenarioTestZodSchema,
890
+ };
891
+ }
892
+ function getExecutionTestSchema(...args) {
893
+ return getTestAuthoringShapes(...args).schema;
894
+ }
895
+ /** Classify authored specs by their root shape, independently of their directory. */
896
+ function getTestsZodSchema(...args) {
897
+ const schema = getExecutionTestSchema(...args);
898
+ const scenarioSchema = getScenarioAuthoringSchema(schema);
899
+ return zod_1.z.unknown().superRefine((value, ctx) => {
900
+ let entityType;
901
+ try {
902
+ entityType = (0, testSpecs_1.classifyTestSpec)(value);
903
+ }
904
+ catch (error) {
905
+ const suggestion = rootOwnerSuggestion(value);
906
+ ctx.addIssue({
907
+ code: "custom",
908
+ path: suggestion ? [suggestion.key] : [],
909
+ message: suggestion
910
+ ? `Unknown root owner "${suggestion.key}". Did you mean "${suggestion.owner}"?`
911
+ : error.message,
912
+ });
913
+ return;
914
+ }
915
+ const result = (entityType === "scenario" ? scenarioSchema : schema).safeParse(value);
916
+ if (!result.success)
917
+ result.error.issues.forEach((issue) => ctx.addIssue({ ...issue }));
918
+ });
919
+ }
920
+ /** Reuse assertion validation while reporting paths in the authored root shape. */
921
+ function getScenariosZodSchema(...args) {
922
+ return getScenarioAuthoringSchema(getExecutionTestSchema(...args));
923
+ }
924
+ function getScenarioAuthoringSchema(schema) {
925
+ return zod_1.z.unknown().superRefine((value, ctx) => {
926
+ if (!value || typeof value !== "object" || Array.isArray(value)) {
927
+ ctx.addIssue({ code: "custom", message: "Scenario must be an object" });
928
+ return;
929
+ }
930
+ const assertion = value;
931
+ if ("key" in assertion) {
932
+ ctx.addIssue({
933
+ code: "custom",
934
+ path: ["key"],
935
+ message: "A scenario is identified by its filename; do not author a key.",
936
+ });
937
+ return;
938
+ }
939
+ if ("assertions" in assertion) {
940
+ ctx.addIssue({
941
+ code: "custom",
942
+ path: ["assertions"],
943
+ message: "Scenarios use checks at the root, without assertions.",
944
+ });
945
+ return;
946
+ }
947
+ if (!Array.isArray(assertion.checks) || !assertion.checks.length) {
948
+ ctx.addIssue({
949
+ code: "custom",
950
+ path: ["checks"],
951
+ message: "Scenarios require nonempty checks at the root",
952
+ });
451
953
  }
954
+ if (Array.isArray(assertion.children)) {
955
+ assertion.children.forEach((child, index) => {
956
+ if (!child || typeof child !== "object" || Array.isArray(child))
957
+ return;
958
+ if ("assertions" in child) {
959
+ ctx.addIssue({
960
+ code: "custom",
961
+ path: ["children", index, "assertions"],
962
+ message: "Scenario children use checks, without assertions.",
963
+ });
964
+ }
965
+ if (!Array.isArray(child.checks) || !child.checks.length) {
966
+ ctx.addIssue({
967
+ code: "custom",
968
+ path: ["children", index, "checks"],
969
+ message: "Scenario children require nonempty checks",
970
+ });
971
+ }
972
+ });
973
+ }
974
+ const result = schema.safeParse((0, scenarios_1.scenarioToExecution)(value, "scenario"));
975
+ if (!result.success)
976
+ result.error.issues.forEach((issue) => {
977
+ const path = issue.path[0] === "assertions" && issue.path[1] === 0 ? issue.path.slice(2) : issue.path;
978
+ const message = issue.message === "Scenario assertions require checks or children"
979
+ ? "Scenarios require nonempty checks at the root"
980
+ : issue.message;
981
+ ctx.addIssue({ ...issue, path, message });
982
+ });
452
983
  });
453
984
  }
454
985
  //# sourceMappingURL=testSchema.js.map