Skip to content

Commit

Permalink
Remove prerequisites from evaluation detail.
Browse files Browse the repository at this point in the history
  • Loading branch information
kinyoklion committed Oct 14, 2024
1 parent 7a6cc71 commit 7ffe8e5
Show file tree
Hide file tree
Showing 8 changed files with 9 additions and 97 deletions.
11 changes: 0 additions & 11 deletions packages/shared/common/src/api/data/LDEvaluationDetail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,6 @@ export interface LDEvaluationDetail {
* An object describing the main factor that influenced the flag evaluation value.
*/
reason: LDEvaluationReason;

/**
* An optional ordered list of prerequisite flag keys evaluated while determining the flags value.
* This will only include the direct prerequisites of the flag.
*/
prerequisites?: string[];
}

export interface LDEvaluationDetailTyped<TFlag> {
Expand All @@ -53,9 +47,4 @@ export interface LDEvaluationDetailTyped<TFlag> {
* An object describing the main factor that influenced the flag evaluation value.
*/
reason: LDEvaluationReason;

/**
* An ordered list of prerequisite flag keys evaluated while determining the flags value.
*/
prerequisites?: string[];
}
4 changes: 2 additions & 2 deletions packages/shared/sdk-client/src/LDClientImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -350,13 +350,13 @@ export default class LDClientImpl implements LDClient {
}
}

const successDetail = createSuccessEvaluationDetail(value, variation, reason, prerequisites);
const successDetail = createSuccessEvaluationDetail(value, variation, reason);
if (value === undefined || value === null) {
this.logger.debug('Result value is null. Providing default value.');
successDetail.value = defaultValue;
}

successDetail.prerequisites?.forEach((prereqKey) => {
prerequisites?.forEach((prereqKey) => {
this.variation(prereqKey, undefined);
});
this._eventProcessor?.sendEvent(
Expand Down
4 changes: 0 additions & 4 deletions packages/shared/sdk-client/src/evaluation/evaluationDetail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,11 @@ export function createSuccessEvaluationDetail(
value: LDFlagValue,
variationIndex?: number,
reason?: LDEvaluationReason,
prerequisites?: string[],
): LDEvaluationDetail {
const res: LDEvaluationDetail = {
value,
variationIndex: variationIndex ?? null,
reason: reason ?? null,
};
if (prerequisites) {
res.prerequisites = prerequisites;
}
return res;
}
69 changes: 0 additions & 69 deletions packages/shared/sdk-server/__tests__/LDClient.evaluation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,75 +253,6 @@ describe('given an LDClient with test data', () => {
expect(res.reason.kind).toEqual('ERROR');
expect(res.reason.errorKind).toEqual('WRONG_TYPE');
});

it('includes prerequisite information for flags with prerequisites', async () => {
await td.update(td.flag('is-prereq').valueForAll(true));
await td.usePreconfiguredFlag({
key: 'has-prereq-depth-1',
on: true,
prerequisites: [
{
key: 'is-prereq',
variation: 0,
},
],
fallthrough: {
variation: 0,
},
offVariation: 1,
variations: [true, false],
clientSideAvailability: {
usingMobileKey: true,
usingEnvironmentId: true,
},
clientSide: true,
version: 4,
});

const res = await client.variationDetail('has-prereq-depth-1', defaultUser, false);
expect(res.value).toEqual(true);
expect(res.reason.kind).toEqual('FALLTHROUGH');
expect(res.prerequisites).toEqual(['is-prereq']);
});

it.each([
['boolVariationDetail', true, false],
['numberVariationDetail', 42, 3.14],
['stringVariationDetail', 'value', 'default'],
['jsonVariationDetail', { value: 'value' }, { value: 'default' }],
])(
'includes prerequisite information for typed evals',
async (method: string, value: any, def: any) => {
await td.update(td.flag('is-prereq').valueForAll(true));
await td.usePreconfiguredFlag({
key: 'has-prereq-depth-1',
on: true,
prerequisites: [
{
key: 'is-prereq',
variation: 0,
},
],
fallthrough: {
variation: 0,
},
offVariation: 1,
variations: [value, def],
clientSideAvailability: {
usingMobileKey: true,
usingEnvironmentId: true,
},
clientSide: true,
version: 4,
});

// @ts-ignore Typescript cannot infer the matching method types.
const res = await client[method]('has-prereq-depth-1', defaultUser, def);
expect(res.value).toEqual(value);
expect(res.reason.kind).toEqual('FALLTHROUGH');
expect(res.prerequisites).toEqual(['is-prereq']);
},
);
});

describe('given an offline client', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ describe('given a flag payload with prerequisites', () => {

expect(res.detail.reason.kind).toEqual('FALLTHROUGH');

expect(res.detail.prerequisites).toEqual(['is-prereq']);
expect(res.prerequisites).toEqual(['is-prereq']);
});

it('can track prerequisites for a prereq of a prereq', async () => {
Expand All @@ -150,7 +150,7 @@ describe('given a flag payload with prerequisites', () => {

expect(res.detail.reason.kind).toEqual('FALLTHROUGH');

expect(res.detail.prerequisites).toEqual(['has-prereq-depth-1']);
expect(res.prerequisites).toEqual(['has-prereq-depth-1']);
});

it('can track prerequisites for a flag with multiple prereqs with and without additional prereqs', async () => {
Expand All @@ -162,11 +162,7 @@ describe('given a flag payload with prerequisites', () => {

expect(res.detail.reason.kind).toEqual('FALLTHROUGH');

expect(res.detail.prerequisites).toEqual([
'has-prereq-depth-1',
'has-prereq-depth-2',
'is-prereq',
]);
expect(res.prerequisites).toEqual(['has-prereq-depth-1', 'has-prereq-depth-2', 'is-prereq']);
});

it('has can handle a prerequisite failure', async () => {
Expand All @@ -180,6 +176,6 @@ describe('given a flag payload with prerequisites', () => {
expect(res.detail.reason.kind).toEqual('PREREQUISITE_FAILED');
expect(res.detail.reason.prerequisiteKey).toEqual('has-prereq-depth-1');

expect(res.detail.prerequisites).toEqual(['has-prereq-depth-1']);
expect(res.prerequisites).toEqual(['has-prereq-depth-1']);
});
});
3 changes: 1 addition & 2 deletions packages/shared/sdk-server/src/LDClientImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,6 @@ export default class LDClientImpl implements LDClient {
value: res.detail.value as TResult,
reason: res.detail.reason,
variationIndex: res.detail.variationIndex,
prerequisites: res.detail.prerequisites,
};
resolve(typedRes);
},
Expand Down Expand Up @@ -668,7 +667,7 @@ export default class LDClientImpl implements LDClient {
flag.trackEvents || requireExperimentData,
requireExperimentData,
detailsOnlyIfTracked,
res.detail.prerequisites,
res.prerequisites,
);
iterCb(true);
});
Expand Down
1 change: 1 addition & 0 deletions packages/shared/sdk-server/src/evaluation/EvalResult.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Reasons from './Reasons';
*/
export default class EvalResult {
public events?: internal.InputEvalEvent[];
public prerequisites?: string[];

protected constructor(
public readonly isError: boolean,
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/sdk-server/src/evaluation/Evaluator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ export default class Evaluator {
};
}
if (state.prerequisites) {
res.detail.prerequisites = state.prerequisites;
res.prerequisites = state.prerequisites;
}
res.events = state.events;
cb(res);
Expand Down

0 comments on commit 7ffe8e5

Please sign in to comment.