@featurevisor/core 3.9.0 → 3.11.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.
- package/lib/cli/options.js +7 -0
- package/lib/cli/options.js.map +1 -1
- package/lib/cli/plugins.js +2 -0
- package/lib/cli/plugins.js.map +1 -1
- package/lib/diff/compare.d.ts +9 -0
- package/lib/diff/compare.js +31 -0
- package/lib/diff/compare.js.map +1 -0
- package/lib/diff/details.d.ts +11 -0
- package/lib/diff/details.js +179 -0
- package/lib/diff/details.js.map +1 -0
- package/lib/diff/git.d.ts +28 -0
- package/lib/diff/git.js +195 -0
- package/lib/diff/git.js.map +1 -0
- package/lib/diff/index.d.ts +36 -0
- package/lib/diff/index.js +222 -0
- package/lib/diff/index.js.map +1 -0
- package/lib/evaluate/explain.d.ts +43 -0
- package/lib/evaluate/explain.js +421 -0
- package/lib/evaluate/explain.js.map +1 -0
- package/lib/evaluate/index.d.ts +1 -0
- package/lib/evaluate/index.js +80 -19
- package/lib/evaluate/index.js.map +1 -1
- package/lib/evaluate/validateExplanation.d.ts +5 -0
- package/lib/evaluate/validateExplanation.js +175 -0
- package/lib/evaluate/validateExplanation.js.map +1 -0
- package/package.json +2 -2
|
@@ -0,0 +1,421 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getEvaluationValue = getEvaluationValue;
|
|
4
|
+
exports.summarizeEvaluation = summarizeEvaluation;
|
|
5
|
+
exports.explainEvaluation = explainEvaluation;
|
|
6
|
+
exports.printExplanation = printExplanation;
|
|
7
|
+
const cliFormat_1 = require("../tester/cliFormat");
|
|
8
|
+
function getEvaluationValue(evaluation) {
|
|
9
|
+
if (evaluation.type === "flag")
|
|
10
|
+
return evaluation.enabled;
|
|
11
|
+
if (evaluation.type === "variable")
|
|
12
|
+
return evaluation.variableValue;
|
|
13
|
+
return typeof evaluation.variationValue !== "undefined"
|
|
14
|
+
? evaluation.variationValue
|
|
15
|
+
: evaluation.variation?.value;
|
|
16
|
+
}
|
|
17
|
+
function summarizeEvaluation(evaluation) {
|
|
18
|
+
switch (evaluation.reason) {
|
|
19
|
+
case "feature_not_found":
|
|
20
|
+
return "The feature is absent from the generated datafile.";
|
|
21
|
+
case "variable_not_found":
|
|
22
|
+
return "The variable is absent from the evaluated datafile entity.";
|
|
23
|
+
case "disabled":
|
|
24
|
+
return "The feature is disabled; no value was supplied for this evaluation.";
|
|
25
|
+
case "variation_disabled":
|
|
26
|
+
return "The feature is disabled. Its disabledVariationValue supplied the variation.";
|
|
27
|
+
case "variable_disabled":
|
|
28
|
+
return "The feature is disabled. The variable's disabledValue supplied the value.";
|
|
29
|
+
case "variable_default":
|
|
30
|
+
return evaluation.enabled === false
|
|
31
|
+
? "The feature is disabled. useDefaultWhenDisabled supplied the variable's defaultValue."
|
|
32
|
+
: "The SDK returned the variable's defaultValue.";
|
|
33
|
+
case "required":
|
|
34
|
+
return "A required feature did not satisfy its enabled or variation requirement.";
|
|
35
|
+
case "required_features_unmet":
|
|
36
|
+
return "The global variable's required features were not satisfied. Its disabled value policy supplied the result, if any.";
|
|
37
|
+
case "forced":
|
|
38
|
+
return "A force entry supplied the result.";
|
|
39
|
+
case "sticky":
|
|
40
|
+
return "A sticky value supplied the result.";
|
|
41
|
+
case "no_variations":
|
|
42
|
+
return "The feature has no variations to evaluate.";
|
|
43
|
+
case "out_of_range":
|
|
44
|
+
return "The bucket value is outside the feature's allocated group ranges.";
|
|
45
|
+
case "no_match":
|
|
46
|
+
return "No eligible result was selected. A selector, rollout boundary, or variation allocation can cause this result.";
|
|
47
|
+
case "variable_override_rule":
|
|
48
|
+
return evaluation.featureKey
|
|
49
|
+
? "A variable override on the matched feature rule supplied the value."
|
|
50
|
+
: "A global variable override supplied the value.";
|
|
51
|
+
case "variable_override_variation":
|
|
52
|
+
return "A variable override on the selected variation supplied the value.";
|
|
53
|
+
case "allocated":
|
|
54
|
+
return evaluation.type === "flag"
|
|
55
|
+
? "The SDK enabled the feature within its allocated group range."
|
|
56
|
+
: "The selected variation supplied the result.";
|
|
57
|
+
case "rule":
|
|
58
|
+
return evaluation.traffic?.percentage === 0
|
|
59
|
+
? "The matched rule has a rollout percentage of 0, so the feature is disabled."
|
|
60
|
+
: evaluation.type === "flag"
|
|
61
|
+
? "The SDK determined the flag result from the matched rule and its rollout."
|
|
62
|
+
: "The matched rule supplied the result.";
|
|
63
|
+
case "error":
|
|
64
|
+
return "The SDK reported an evaluation error.";
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
// Decode only for presentation. Never match selectors or repeat an SDK evaluation.
|
|
68
|
+
function readableSelector(value) {
|
|
69
|
+
if (typeof value !== "string" || !/^[\[{]/.test(value))
|
|
70
|
+
return value;
|
|
71
|
+
try {
|
|
72
|
+
return JSON.parse(value);
|
|
73
|
+
}
|
|
74
|
+
catch {
|
|
75
|
+
return value;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
function selectors(value) {
|
|
79
|
+
return {
|
|
80
|
+
...(value.conditions !== undefined && { conditions: readableSelector(value.conditions) }),
|
|
81
|
+
...(value.segments !== undefined && { segments: readableSelector(value.segments) }),
|
|
82
|
+
...(value.requiredFeatures !== undefined && { requiredFeatures: value.requiredFeatures }),
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
function authoredPath(variable, environment, path) {
|
|
86
|
+
let overrides = Array.isArray(variable.overrides)
|
|
87
|
+
? variable.overrides
|
|
88
|
+
: environment
|
|
89
|
+
? variable.overrides?.[environment]
|
|
90
|
+
: undefined;
|
|
91
|
+
const result = [];
|
|
92
|
+
for (const key of path) {
|
|
93
|
+
const override = overrides?.find((entry) => entry.key === key);
|
|
94
|
+
if (!override)
|
|
95
|
+
return undefined;
|
|
96
|
+
result.push(override);
|
|
97
|
+
overrides = override.overrides;
|
|
98
|
+
}
|
|
99
|
+
return result;
|
|
100
|
+
}
|
|
101
|
+
/** Augment an existing result. This function never calls or reimplements the SDK. */
|
|
102
|
+
function explainEvaluation(evaluation, datafile, diagnostics, options) {
|
|
103
|
+
const value = getEvaluationValue(evaluation);
|
|
104
|
+
const featureKey = evaluation.featureKey ?? options.feature;
|
|
105
|
+
const variableKey = evaluation.variableKey ?? options.variable;
|
|
106
|
+
const evidence = [];
|
|
107
|
+
const add = (basis, title, details) => evidence.push({ basis, title, details });
|
|
108
|
+
const limitations = [
|
|
109
|
+
"This explains the SDK outcome, not a complete execution trace. Individual failed checks and short circuits are not recorded.",
|
|
110
|
+
"Definitions and compiled selectors are supporting information, not additional evaluations. Local definitions may differ from deployed datafiles.",
|
|
111
|
+
];
|
|
112
|
+
if (options.target) {
|
|
113
|
+
limitations.push("Target context can simplify selectors during building. Authored selectors are shown as provenance, not replayed against the supplied context.");
|
|
114
|
+
}
|
|
115
|
+
const feature = featureKey ? datafile.features[featureKey] : undefined;
|
|
116
|
+
const variable = !featureKey && variableKey ? datafile.variables?.[variableKey] : undefined;
|
|
117
|
+
const describeSelectors = (candidate) => {
|
|
118
|
+
const details = selectors(candidate);
|
|
119
|
+
const keys = new Set();
|
|
120
|
+
const visit = (expression) => {
|
|
121
|
+
if (typeof expression === "string" && expression !== "*")
|
|
122
|
+
keys.add(expression);
|
|
123
|
+
else if (Array.isArray(expression))
|
|
124
|
+
expression.forEach(visit);
|
|
125
|
+
else if (expression && typeof expression === "object") {
|
|
126
|
+
for (const key of ["and", "or", "not"]) {
|
|
127
|
+
if (key in expression)
|
|
128
|
+
visit(expression[key]);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
visit(details.segments);
|
|
133
|
+
if (keys.size) {
|
|
134
|
+
details.segmentDefinitions = Array.from(keys, (key) => ({
|
|
135
|
+
key,
|
|
136
|
+
present: Object.prototype.hasOwnProperty.call(datafile.segments, key),
|
|
137
|
+
conditions: readableSelector(datafile.segments[key]?.conditions),
|
|
138
|
+
}));
|
|
139
|
+
}
|
|
140
|
+
return details;
|
|
141
|
+
};
|
|
142
|
+
if ((featureKey && !feature) || (!featureKey && !variable)) {
|
|
143
|
+
add("definition", "Entity availability", {
|
|
144
|
+
definedInProject: options.definitionExists,
|
|
145
|
+
presentInDatafile: false,
|
|
146
|
+
note: options.definitionExists
|
|
147
|
+
? "The entity exists locally but is absent from this datafile. Check Target selection, exposure and archiving. No specific exclusion cause is inferred."
|
|
148
|
+
: "The SDK result is authoritative for this datafile.",
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
if (evaluation.error) {
|
|
152
|
+
add("sdk-result", "Evaluation error", {
|
|
153
|
+
name: evaluation.error.name,
|
|
154
|
+
message: evaluation.error.message,
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
if (evaluation.bucketValue !== undefined || evaluation.bucketKey !== undefined) {
|
|
158
|
+
add("sdk-result", "Bucketing reported by the SDK", {
|
|
159
|
+
bucketKey: evaluation.bucketKey,
|
|
160
|
+
bucketValue: evaluation.bucketValue,
|
|
161
|
+
bucketBy: feature?.bucketBy,
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
if (evaluation.traffic) {
|
|
165
|
+
add("sdk-result", "Matched rule", {
|
|
166
|
+
key: evaluation.ruleKey,
|
|
167
|
+
percentage: evaluation.traffic.percentage,
|
|
168
|
+
...describeSelectors(evaluation.traffic),
|
|
169
|
+
allocation: evaluation.traffic.allocation,
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
if (evaluation.force) {
|
|
173
|
+
add("sdk-result", "Selected force", {
|
|
174
|
+
index: evaluation.forceIndex,
|
|
175
|
+
...evaluation.force,
|
|
176
|
+
...describeSelectors(evaluation.force),
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
const requirements = evaluation.requiredFeatures ??
|
|
180
|
+
evaluation.required ??
|
|
181
|
+
variable?.requiredFeatures ??
|
|
182
|
+
feature?.requiredFeatures ??
|
|
183
|
+
feature?.required;
|
|
184
|
+
if (requirements !== undefined) {
|
|
185
|
+
add("definition", "Declared root requirements (not a per requirement trace)", {
|
|
186
|
+
requiredFeatures: requirements,
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
if (evaluation.type === "variation" && value !== undefined) {
|
|
190
|
+
add("sdk-result", "Returned variation", { value });
|
|
191
|
+
}
|
|
192
|
+
if (evaluation.type === "variable") {
|
|
193
|
+
const schema = evaluation.variableSchema ?? variable;
|
|
194
|
+
if (schema) {
|
|
195
|
+
add("definition", "Variable value policy", {
|
|
196
|
+
type: schema.type,
|
|
197
|
+
defaultValue: schema.defaultValue,
|
|
198
|
+
disabledValue: schema.disabledValue,
|
|
199
|
+
useDefaultWhenDisabled: schema.useDefaultWhenDisabled,
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
if (evaluation.variableOverrideIndex !== undefined ||
|
|
203
|
+
evaluation.variableOverrideKey !== undefined) {
|
|
204
|
+
add("sdk-result", "Selected variable override", {
|
|
205
|
+
key: evaluation.variableOverrideKey,
|
|
206
|
+
path: evaluation.variableOverridePath,
|
|
207
|
+
compiledIndex: evaluation.variableOverrideIndex,
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
const selected = variable?.overrides?.[evaluation.variableOverrideIndex ?? -1] ??
|
|
211
|
+
(evaluation.reason === "variable_override_rule" && variableKey
|
|
212
|
+
? evaluation.traffic?.variableOverrides?.[variableKey]?.[evaluation.variableOverrideIndex ?? -1]
|
|
213
|
+
: undefined);
|
|
214
|
+
if (selected) {
|
|
215
|
+
add("definition", "Selected compiled override selectors", describeSelectors(selected));
|
|
216
|
+
if (variable) {
|
|
217
|
+
add("definition", "Global override selection policy", {
|
|
218
|
+
policy: "The SDK selects the first matching compiled override. Nested descendants precede their parent fallbacks. Mutations are resolved during building, not in the SDK.",
|
|
219
|
+
});
|
|
220
|
+
const path = evaluation.variableOverridePath ??
|
|
221
|
+
(evaluation.variableOverrideKey !== undefined ? [evaluation.variableOverrideKey] : []);
|
|
222
|
+
const authored = options.authoredVariable && path.length > 0
|
|
223
|
+
? authoredPath(options.authoredVariable, options.environment, path)
|
|
224
|
+
: undefined;
|
|
225
|
+
if (authored) {
|
|
226
|
+
add("definition", "Authored value construction (build time)", {
|
|
227
|
+
defaultValue: options.authoredVariable?.defaultValue,
|
|
228
|
+
overrides: authored.map((override, index) => ({
|
|
229
|
+
path: path.slice(0, index + 1),
|
|
230
|
+
...selectors(override),
|
|
231
|
+
...(override.mutate !== undefined
|
|
232
|
+
? { mutate: override.mutate }
|
|
233
|
+
: { value: override.value }),
|
|
234
|
+
})),
|
|
235
|
+
compiledValue: selected.value,
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
else if (options.authoredVariable) {
|
|
239
|
+
limitations.push("The selected compiled override could not be mapped to an authored override path.");
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
if (featureKey) {
|
|
244
|
+
limitations.push("Feature variable mutations are resolved during building. The result identifies the selected source where available, but does not contain a mutation history.");
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
// Preserve observation order and repeated calls. Diagnostics do not identify
|
|
248
|
+
// parent evaluations, so do not invent a dependency tree or expected values.
|
|
249
|
+
const observations = diagnostics.flatMap((diagnostic) => {
|
|
250
|
+
const nested = diagnostic.details.evaluation;
|
|
251
|
+
if (!nested || typeof nested !== "object" || !("type" in nested) || !("reason" in nested))
|
|
252
|
+
return [];
|
|
253
|
+
const observed = nested;
|
|
254
|
+
if (observed === evaluation)
|
|
255
|
+
return [];
|
|
256
|
+
return [
|
|
257
|
+
{
|
|
258
|
+
type: observed.type,
|
|
259
|
+
featureKey: observed.featureKey,
|
|
260
|
+
variableKey: observed.variableKey,
|
|
261
|
+
reason: observed.reason,
|
|
262
|
+
hasValue: getEvaluationValue(observed) !== undefined,
|
|
263
|
+
value: getEvaluationValue(observed),
|
|
264
|
+
ruleKey: observed.ruleKey,
|
|
265
|
+
},
|
|
266
|
+
];
|
|
267
|
+
});
|
|
268
|
+
if (observations.length) {
|
|
269
|
+
add("sdk-diagnostic", "Related evaluations observed during this call", { observations });
|
|
270
|
+
}
|
|
271
|
+
const issues = diagnostics
|
|
272
|
+
.filter((entry) => entry.level === "warn" || entry.level === "error")
|
|
273
|
+
.map((entry) => ({ level: entry.level, code: entry.code, message: entry.message }));
|
|
274
|
+
if (issues.length)
|
|
275
|
+
add("sdk-diagnostic", "Warnings and errors", { issues });
|
|
276
|
+
return {
|
|
277
|
+
version: 1,
|
|
278
|
+
mode: "outcome",
|
|
279
|
+
source: {
|
|
280
|
+
kind: "local-project",
|
|
281
|
+
environment: options.environment || false,
|
|
282
|
+
set: options.set,
|
|
283
|
+
target: options.target,
|
|
284
|
+
},
|
|
285
|
+
result: {
|
|
286
|
+
type: evaluation.type,
|
|
287
|
+
featureKey,
|
|
288
|
+
variableKey,
|
|
289
|
+
reason: evaluation.reason,
|
|
290
|
+
hasValue: value !== undefined,
|
|
291
|
+
...(value !== undefined && { value }),
|
|
292
|
+
},
|
|
293
|
+
summary: summarizeEvaluation(evaluation),
|
|
294
|
+
evidence,
|
|
295
|
+
limitations,
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
function paint(text, colour) {
|
|
299
|
+
return process.env.NO_COLOR !== undefined || process.env.FORCE_COLOR === "0"
|
|
300
|
+
? text
|
|
301
|
+
: (0, cliFormat_1.colorize)(text, colour);
|
|
302
|
+
}
|
|
303
|
+
function compact(value) {
|
|
304
|
+
const text = JSON.stringify(value) ?? "unavailable";
|
|
305
|
+
return text.length > 180 ? `${text.slice(0, 177)}...` : text;
|
|
306
|
+
}
|
|
307
|
+
// Describe declarations, never claim that these individual checks were executed.
|
|
308
|
+
function describeSelector(value) {
|
|
309
|
+
if (value === "*")
|
|
310
|
+
return "everyone";
|
|
311
|
+
if (typeof value === "string")
|
|
312
|
+
return value;
|
|
313
|
+
if (Array.isArray(value))
|
|
314
|
+
return value.map(describeSelector).join(" AND ");
|
|
315
|
+
if (!value || typeof value !== "object")
|
|
316
|
+
return compact(value);
|
|
317
|
+
const group = value;
|
|
318
|
+
for (const operator of ["and", "or", "not"]) {
|
|
319
|
+
if (Array.isArray(group[operator])) {
|
|
320
|
+
const expression = group[operator]
|
|
321
|
+
.map(describeSelector)
|
|
322
|
+
.join(operator === "or" ? " OR " : " AND ");
|
|
323
|
+
return `${operator === "not" ? "NOT " : ""}(${expression})`;
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
if (typeof group.attribute === "string") {
|
|
327
|
+
const operators = {
|
|
328
|
+
equals: "=",
|
|
329
|
+
notEquals: "!=",
|
|
330
|
+
greaterThan: ">",
|
|
331
|
+
greaterThanOrEquals: ">=",
|
|
332
|
+
lessThan: "<",
|
|
333
|
+
lessThanOrEquals: "<=",
|
|
334
|
+
notExists: "is absent",
|
|
335
|
+
exists: "is present",
|
|
336
|
+
};
|
|
337
|
+
const operator = String(group.operator);
|
|
338
|
+
return `${group.attribute} ${operators[operator] ?? operator}${group.value !== undefined ? ` ${compact(group.value)}` : ""}`;
|
|
339
|
+
}
|
|
340
|
+
return compact(value);
|
|
341
|
+
}
|
|
342
|
+
function printExplanation(explanation, showNotice = true) {
|
|
343
|
+
const { result, evidence } = explanation;
|
|
344
|
+
const detail = (title) => evidence.find((entry) => entry.title === title)?.details;
|
|
345
|
+
const line = (label, value) => console.log(` ${paint(label, 36)} ${value}`);
|
|
346
|
+
const resultColour = result.reason === "error" ? 31 : !result.hasValue || result.value === false ? 33 : 32;
|
|
347
|
+
const value = result.hasValue ? JSON.stringify(result.value, null, 2) : "No value returned";
|
|
348
|
+
console.log(`\n ${paint(`Value: ${value.replace(/\n/g, "\n ")}`, resultColour)}`);
|
|
349
|
+
console.log(` Explanation: ${explanation.summary}`);
|
|
350
|
+
const rule = detail("Matched rule");
|
|
351
|
+
if (rule)
|
|
352
|
+
line("Rule:", `${paint(String(rule.key), 36)}${typeof rule.percentage === "number" ? ` (${rule.percentage / 1000}% rollout)` : ""}`);
|
|
353
|
+
const force = detail("Selected force");
|
|
354
|
+
if (force)
|
|
355
|
+
line("Force:", `entry ${Number(force.index) + 1}`);
|
|
356
|
+
const override = detail("Selected variable override");
|
|
357
|
+
if (override)
|
|
358
|
+
line("Override:", Array.isArray(override.path)
|
|
359
|
+
? override.path.join(" → ")
|
|
360
|
+
: String(override.key ?? `compiled entry ${Number(override.compiledIndex) + 1}`));
|
|
361
|
+
const selection = detail("Selected compiled override selectors") ?? force ?? rule;
|
|
362
|
+
if (selection) {
|
|
363
|
+
if (selection.conditions !== undefined)
|
|
364
|
+
line("Conditions (definition):", describeSelector(selection.conditions));
|
|
365
|
+
if (selection.segments !== undefined)
|
|
366
|
+
line("Segments (definition):", describeSelector(selection.segments));
|
|
367
|
+
const segments = (selection.segmentDefinitions ?? []);
|
|
368
|
+
for (const segment of segments.slice(0, 4)) {
|
|
369
|
+
console.log(paint(` ${segment.key}: ${segment.present ? describeSelector(segment.conditions) : "absent from datafile"}`, 2));
|
|
370
|
+
}
|
|
371
|
+
if (segments.length > 4)
|
|
372
|
+
console.log(paint(` +${segments.length - 4} segment definitions in JSON`, 2));
|
|
373
|
+
}
|
|
374
|
+
const root = detail("Declared root requirements (not a per requirement trace)");
|
|
375
|
+
const requirements = (label, input) => {
|
|
376
|
+
if (input === undefined)
|
|
377
|
+
return;
|
|
378
|
+
const items = Array.isArray(input) ? input : [input];
|
|
379
|
+
line(label, items
|
|
380
|
+
.map((item) => typeof item === "string"
|
|
381
|
+
? `${item} enabled`
|
|
382
|
+
: `${item.feature ?? item.key} ${item.enabled === false ? "disabled" : "enabled"}${item.variation !== undefined ? `, variation ${compact(item.variation)}` : ""}`)
|
|
383
|
+
.join("; "));
|
|
384
|
+
};
|
|
385
|
+
requirements("Requires (definition):", root?.requiredFeatures);
|
|
386
|
+
requirements("Override requires (definition):", selection?.requiredFeatures);
|
|
387
|
+
const bucket = detail("Bucketing reported by the SDK");
|
|
388
|
+
if (bucket)
|
|
389
|
+
console.log(paint(` Bucket: ${bucket.bucketValue ?? "unavailable"} / 100000 · key ${compact(bucket.bucketKey)}`, 2));
|
|
390
|
+
const construction = detail("Authored value construction (build time)");
|
|
391
|
+
if (construction) {
|
|
392
|
+
const steps = construction.overrides;
|
|
393
|
+
const fields = Array.from(new Set(steps.flatMap((step) => step.mutate && typeof step.mutate === "object" ? Object.keys(step.mutate) : [])));
|
|
394
|
+
const replacements = steps.filter((step) => Object.prototype.hasOwnProperty.call(step, "value")).length;
|
|
395
|
+
line("Built from:", `default value${fields.length ? `; mutations to ${fields.join(", ")}` : ""}${replacements ? `; ${replacements} value replacement${replacements === 1 ? "" : "s"}` : ""}`);
|
|
396
|
+
}
|
|
397
|
+
const related = detail("Related evaluations observed during this call");
|
|
398
|
+
if (related) {
|
|
399
|
+
// Collapse repeated observations only in the human view, not in the JSON evidence.
|
|
400
|
+
const observations = Array.from(new Set(related.observations.map((entry) => `${entry.featureKey}${entry.variableKey ? `.${entry.variableKey}` : ""} ${entry.type}: ${entry.hasValue ? compact(entry.value) : "no value"} (${entry.reason})`)));
|
|
401
|
+
for (const observation of observations.slice(0, 4))
|
|
402
|
+
line("Observed:", observation);
|
|
403
|
+
if (observations.length > 4)
|
|
404
|
+
console.log(paint(` +${observations.length - 4} related results in JSON`, 2));
|
|
405
|
+
}
|
|
406
|
+
const availability = detail("Entity availability");
|
|
407
|
+
if (availability?.definedInProject)
|
|
408
|
+
console.log(paint(" Defined locally, but absent from this datafile. Check Target selection, exposure and archiving.", 33));
|
|
409
|
+
const error = detail("Evaluation error");
|
|
410
|
+
if (error)
|
|
411
|
+
console.log(paint(` ${error.name}: ${error.message}`, 31));
|
|
412
|
+
const issues = detail("Warnings and errors");
|
|
413
|
+
for (const issue of (issues?.issues ?? [])) {
|
|
414
|
+
console.log(paint(` ${issue.level}: ${issue.message}`, issue.level === "error" ? 31 : 33));
|
|
415
|
+
}
|
|
416
|
+
if (showNotice) {
|
|
417
|
+
console.log(paint(`\n Local project${explanation.source.set ? ` · set ${explanation.source.set}` : ""}. Outcome explanation, not a complete execution trace.`, 2));
|
|
418
|
+
console.log(paint(" Full evidence and limitations: --explain --json", 2));
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
//# sourceMappingURL=explain.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"explain.js","sourceRoot":"","sources":["../../src/evaluate/explain.ts"],"names":[],"mappings":";;AA2CA,gDAMC;AAED,kDAiDC;AA6CD,8CA0NC;AA6CD,4CA+HC;AArhBD,mDAA+C;AAyC/C,SAAgB,kBAAkB,CAAC,UAAsB;IACvD,IAAI,UAAU,CAAC,IAAI,KAAK,MAAM;QAAE,OAAO,UAAU,CAAC,OAAO,CAAC;IAC1D,IAAI,UAAU,CAAC,IAAI,KAAK,UAAU;QAAE,OAAO,UAAU,CAAC,aAAa,CAAC;IACpE,OAAO,OAAO,UAAU,CAAC,cAAc,KAAK,WAAW;QACrD,CAAC,CAAC,UAAU,CAAC,cAAc;QAC3B,CAAC,CAAC,UAAU,CAAC,SAAS,EAAE,KAAK,CAAC;AAClC,CAAC;AAED,SAAgB,mBAAmB,CAAC,UAAsB;IACxD,QAAQ,UAAU,CAAC,MAAM,EAAE,CAAC;QAC1B,KAAK,mBAAmB;YACtB,OAAO,oDAAoD,CAAC;QAC9D,KAAK,oBAAoB;YACvB,OAAO,4DAA4D,CAAC;QACtE,KAAK,UAAU;YACb,OAAO,qEAAqE,CAAC;QAC/E,KAAK,oBAAoB;YACvB,OAAO,6EAA6E,CAAC;QACvF,KAAK,mBAAmB;YACtB,OAAO,2EAA2E,CAAC;QACrF,KAAK,kBAAkB;YACrB,OAAO,UAAU,CAAC,OAAO,KAAK,KAAK;gBACjC,CAAC,CAAC,uFAAuF;gBACzF,CAAC,CAAC,+CAA+C,CAAC;QACtD,KAAK,UAAU;YACb,OAAO,0EAA0E,CAAC;QACpF,KAAK,yBAAyB;YAC5B,OAAO,oHAAoH,CAAC;QAC9H,KAAK,QAAQ;YACX,OAAO,oCAAoC,CAAC;QAC9C,KAAK,QAAQ;YACX,OAAO,qCAAqC,CAA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C,IAAI,KAAK,KAAK,CAAC,OAAO,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC;IACvE,MAAM,MAAM,GAAG,MAAM,CAAC,qBAAqB,CAAC,CAAC;IAC7C,KAAK,MAAM,KAAK,IAAI,CAAC,MAAM,EAAE,MAAM,IAAI,EAAE,CAAmC,EAAE,CAAC;QAC7E,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,KAAK,CAAC,KAAK,KAAK,KAAK,CAAC,OAAO,EAAE,EAAE,KAAK,CAAC,KAAK,KAAK,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IAC9F,CAAC;IACD,IAAI,UAAU,EAAE,CAAC;QACf,OAAO,CAAC,GAAG,CACT,KAAK,CACH,oBAAoB,WAAW,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,UAAU,WAAW,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,EAAE,wDAAwD,EAC5I,CAAC,CACF,CACF,CAAC;QACF,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,mDAAmD,EAAE,CAAC,CAAC,CAAC,CAAC;IAC7E,CAAC;AACH,CAAC"}
|
package/lib/evaluate/index.d.ts
CHANGED
package/lib/evaluate/index.js
CHANGED
|
@@ -6,6 +6,8 @@ const sdk_1 = require("@featurevisor/sdk");
|
|
|
6
6
|
const buildRuntimeDatafiles_1 = require("../builder/buildRuntimeDatafiles");
|
|
7
7
|
const validation_1 = require("../cli/validation");
|
|
8
8
|
const error_1 = require("../error");
|
|
9
|
+
const explain_1 = require("./explain");
|
|
10
|
+
const validateExplanation_1 = require("./validateExplanation");
|
|
9
11
|
const sets_1 = require("../sets");
|
|
10
12
|
const cliFormat_1 = require("../tester/cliFormat");
|
|
11
13
|
function printEvaluationDetails(evaluation) {
|
|
@@ -38,8 +40,14 @@ function printHeader(message) {
|
|
|
38
40
|
console.log(cliFormat_1.CLI_FORMAT_BOLD, message);
|
|
39
41
|
console.log("");
|
|
40
42
|
}
|
|
41
|
-
async function evaluateFeatureWithDatafile(datafileContent, options, target) {
|
|
43
|
+
async function evaluateFeatureWithDatafile(datafileContent, options, target, explanationOptions) {
|
|
42
44
|
let diagnostics = [];
|
|
45
|
+
const explain = (evaluation, entries, variable) => {
|
|
46
|
+
const metadata = { ...explanationOptions, ...options, variable, target };
|
|
47
|
+
const explanation = (0, explain_1.explainEvaluation)(evaluation, datafileContent, entries, metadata);
|
|
48
|
+
(0, validateExplanation_1.assertExplanationMatchesEvaluation)(evaluation, explanation, datafileContent, metadata);
|
|
49
|
+
return explanation;
|
|
50
|
+
};
|
|
43
51
|
const f = (0, sdk_1.createFeaturevisor)({
|
|
44
52
|
datafile: datafileContent,
|
|
45
53
|
logLevel: "debug",
|
|
@@ -48,8 +56,12 @@ async function evaluateFeatureWithDatafile(datafileContent, options, target) {
|
|
|
48
56
|
if (options.variable && !options.feature) {
|
|
49
57
|
const evaluation = f.evaluateVariable(options.variable, options.context);
|
|
50
58
|
const evaluationDiagnostics = [...diagnostics];
|
|
59
|
+
const explanation = options.explain
|
|
60
|
+
? explain(evaluation, evaluationDiagnostics, options.variable)
|
|
61
|
+
: undefined;
|
|
62
|
+
const result = explanation ? { ...evaluation, explanation } : evaluation;
|
|
51
63
|
if (options.json)
|
|
52
|
-
return
|
|
64
|
+
return result;
|
|
53
65
|
console.log("");
|
|
54
66
|
console.log(cliFormat_1.CLI_FORMAT_BOLD, "Evaluating Featurevisor variable");
|
|
55
67
|
console.log(` ${(0, cliFormat_1.colorize)("Variable", cliFormat_1.CLI_COLOR_CYAN)}: ${options.variable}`);
|
|
@@ -59,10 +71,15 @@ async function evaluateFeatureWithDatafile(datafileContent, options, target) {
|
|
|
59
71
|
console.log(` ${(0, cliFormat_1.colorize)("Context", cliFormat_1.CLI_COLOR_CYAN)}: ${JSON.stringify(options.context)}`);
|
|
60
72
|
if (options.verbose)
|
|
61
73
|
printDiagnostics(evaluationDiagnostics);
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
74
|
+
if (explanation) {
|
|
75
|
+
(0, explain_1.printExplanation)(explanation);
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
console.log(cliFormat_1.CLI_FORMAT_GREEN, `Value: ${JSON.stringify(evaluation.variableValue)}`);
|
|
79
|
+
console.log("\nDetails:\n");
|
|
80
|
+
printEvaluationDetails(evaluation);
|
|
81
|
+
}
|
|
82
|
+
return result;
|
|
66
83
|
}
|
|
67
84
|
const featureKey = options.feature;
|
|
68
85
|
const flagEvaluation = f.evaluateFlag(featureKey, options.context);
|
|
@@ -90,8 +107,19 @@ async function evaluateFeatureWithDatafile(datafileContent, options, target) {
|
|
|
90
107
|
variation: variationEvaluation,
|
|
91
108
|
variables: variableEvaluations,
|
|
92
109
|
};
|
|
110
|
+
const explanation = options.explain
|
|
111
|
+
? {
|
|
112
|
+
flag: explain(flagEvaluation, flagEvaluationDiagnostics),
|
|
113
|
+
variation: explain(variationEvaluation, variationEvaluationDiagnostics),
|
|
114
|
+
variables: Object.fromEntries(Object.entries(variableEvaluations).map(([key, evaluation]) => [
|
|
115
|
+
key,
|
|
116
|
+
explain(evaluation, variableEvaluationDiagnostics[key], key),
|
|
117
|
+
])),
|
|
118
|
+
}
|
|
119
|
+
: undefined;
|
|
120
|
+
const result = explanation ? { ...allEvaluations, explanation } : allEvaluations;
|
|
93
121
|
if (options.json) {
|
|
94
|
-
return
|
|
122
|
+
return result;
|
|
95
123
|
}
|
|
96
124
|
console.log("");
|
|
97
125
|
console.log(cliFormat_1.CLI_FORMAT_BOLD, "Evaluating Featurevisor feature");
|
|
@@ -105,21 +133,34 @@ async function evaluateFeatureWithDatafile(datafileContent, options, target) {
|
|
|
105
133
|
if (options.verbose) {
|
|
106
134
|
printDiagnostics(flagEvaluationDiagnostics);
|
|
107
135
|
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
136
|
+
if (explanation) {
|
|
137
|
+
(0, explain_1.printExplanation)(explanation.flag);
|
|
138
|
+
}
|
|
139
|
+
else {
|
|
140
|
+
console.log(flagEvaluation.enabled ? cliFormat_1.CLI_FORMAT_GREEN : cliFormat_1.CLI_FORMAT_YELLOW, `Value: ${flagEvaluation.enabled}`);
|
|
141
|
+
console.log("\nDetails:\n");
|
|
142
|
+
printEvaluationDetails(flagEvaluation);
|
|
143
|
+
}
|
|
111
144
|
// variation
|
|
112
145
|
printHeader("Variation");
|
|
113
146
|
if (feature?.variations) {
|
|
114
147
|
if (options.verbose) {
|
|
115
148
|
printDiagnostics(variationEvaluationDiagnostics);
|
|
116
149
|
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
150
|
+
if (explanation) {
|
|
151
|
+
(0, explain_1.printExplanation)(explanation.variation, false);
|
|
152
|
+
}
|
|
153
|
+
else {
|
|
154
|
+
console.log(cliFormat_1.CLI_FORMAT_GREEN, `Value: ${JSON.stringify((0, explain_1.getEvaluationValue)(variationEvaluation))}`);
|
|
155
|
+
console.log("\nDetails:\n");
|
|
156
|
+
printEvaluationDetails(variationEvaluation);
|
|
157
|
+
}
|
|
120
158
|
}
|
|
121
159
|
else {
|
|
122
|
-
|
|
160
|
+
if (explanation)
|
|
161
|
+
(0, explain_1.printExplanation)(explanation.variation, false);
|
|
162
|
+
else
|
|
163
|
+
console.log(cliFormat_1.CLI_FORMAT_YELLOW, "No variations defined.");
|
|
123
164
|
}
|
|
124
165
|
// variables
|
|
125
166
|
if (feature?.variablesSchema) {
|
|
@@ -131,16 +172,21 @@ async function evaluateFeatureWithDatafile(datafileContent, options, target) {
|
|
|
131
172
|
const variableValue = typeof value.variableValue !== "undefined"
|
|
132
173
|
? JSON.stringify(value.variableValue)
|
|
133
174
|
: value.variableValue;
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
175
|
+
if (explanation) {
|
|
176
|
+
(0, explain_1.printExplanation)(explanation.variables[key], false);
|
|
177
|
+
}
|
|
178
|
+
else {
|
|
179
|
+
console.log(cliFormat_1.CLI_FORMAT_GREEN, `Value: ${variableValue}`);
|
|
180
|
+
console.log("\nDetails:\n");
|
|
181
|
+
printEvaluationDetails(value);
|
|
182
|
+
}
|
|
137
183
|
}
|
|
138
184
|
}
|
|
139
185
|
else {
|
|
140
186
|
printHeader("Variables");
|
|
141
187
|
console.log(cliFormat_1.CLI_FORMAT_YELLOW, "No variables defined.");
|
|
142
188
|
}
|
|
143
|
-
return
|
|
189
|
+
return result;
|
|
144
190
|
}
|
|
145
191
|
async function evaluateFeature(deps, options) {
|
|
146
192
|
if (Boolean(options.feature) === Boolean(options.variable)) {
|
|
@@ -155,9 +201,23 @@ async function evaluateFeature(deps, options) {
|
|
|
155
201
|
revision: "include-all-features",
|
|
156
202
|
inflate: options.inflate,
|
|
157
203
|
});
|
|
204
|
+
const definitionExists = options.explain
|
|
205
|
+
? options.variable
|
|
206
|
+
? await deps.datasource.variableExists(options.variable)
|
|
207
|
+
: await deps.datasource.featureExists(options.feature)
|
|
208
|
+
: undefined;
|
|
209
|
+
const explanationOptions = options.explain
|
|
210
|
+
? {
|
|
211
|
+
set: deps.datasource.getSet(),
|
|
212
|
+
definitionExists,
|
|
213
|
+
authoredVariable: options.variable && definitionExists
|
|
214
|
+
? await deps.datasource.readVariable(options.variable)
|
|
215
|
+
: undefined,
|
|
216
|
+
}
|
|
217
|
+
: undefined;
|
|
158
218
|
const results = [];
|
|
159
219
|
for (const entry of datafiles) {
|
|
160
|
-
const evaluations = await evaluateFeatureWithDatafile(entry.datafile, options, entry.target);
|
|
220
|
+
const evaluations = await evaluateFeatureWithDatafile(entry.datafile, options, entry.target, explanationOptions);
|
|
161
221
|
results.push({ target: entry.target, evaluations });
|
|
162
222
|
}
|
|
163
223
|
if (options.json) {
|
|
@@ -186,6 +246,7 @@ exports.evaluatePlugin = {
|
|
|
186
246
|
json: parsed.json,
|
|
187
247
|
pretty: parsed.pretty,
|
|
188
248
|
verbose: parsed.verbose,
|
|
249
|
+
explain: parsed.explain,
|
|
189
250
|
target: parsed.target,
|
|
190
251
|
inflate: typeof parsed.inflate !== "undefined"
|
|
191
252
|
? (0, validation_1.parsePositiveIntegerOption)("--inflate", parsed.inflate, 1)
|