Skip to content

Commit 24c9ac6

Browse files
committed
Make condition evaluation optional in the adapter
1 parent db8c33c commit 24c9ac6

3 files changed

Lines changed: 67 additions & 3 deletions

File tree

packages/server/api/src/app/benchmark/provider-adapter.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@ export type ProviderAdapter = {
4949
method: string,
5050
context: WizardContext,
5151
): Promise<BenchmarkWizardOption[]>;
52-
evaluateCondition(
52+
evaluateCondition?: (
5353
condition: string,
5454
context: WizardContext,
55-
): Promise<boolean>;
55+
) => Promise<boolean>;
5656
};
5757

5858
const providers = new Map<string, ProviderAdapter>();

packages/server/api/src/app/benchmark/wizard.service.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,13 @@ async function resolveNextStep(
4444
if (!nextStepDef.conditional) {
4545
return nextStepDef;
4646
}
47-
const conditionResult = await providerAdapter.evaluateCondition(
47+
const evaluateCondition = providerAdapter.evaluateCondition;
48+
if (!evaluateCondition) {
49+
throwValidationError(
50+
'Benchmark provider does not support conditional wizard steps',
51+
);
52+
}
53+
const conditionResult = await evaluateCondition(
4854
nextStepDef.conditional.when,
4955
context,
5056
);

packages/server/api/test/unit/benchmark/wizard.service.test.ts

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,4 +404,62 @@ describe('resolveWizardNavigation', () => {
404404
adapters.delete('misconfig');
405405
}
406406
});
407+
408+
it('throws when next step has conditional but adapter has no evaluateCondition', async () => {
409+
const noConditionAdapterConfig = {
410+
provider: 'no-condition-fn' as const,
411+
steps: [
412+
{
413+
id: 'a',
414+
title: 'Step A',
415+
selectionType: 'single' as const,
416+
optionsSource: { type: 'dynamic' as const, method: 'listA' },
417+
nextStep: 'b',
418+
},
419+
{
420+
id: 'b',
421+
title: 'Step B',
422+
selectionType: 'single' as const,
423+
conditional: {
424+
when: 'showB',
425+
onSuccess: {
426+
optionsSource: {
427+
type: 'static' as const,
428+
values: [{ id: 'b1', displayName: 'B1' }],
429+
},
430+
},
431+
onFailure: { skipToStep: 'c' },
432+
},
433+
nextStep: 'c',
434+
},
435+
{
436+
id: 'c',
437+
title: 'Step C',
438+
selectionType: 'single' as const,
439+
optionsSource: {
440+
type: 'static' as const,
441+
values: [{ id: 'c1', displayName: 'C1' }],
442+
},
443+
},
444+
],
445+
};
446+
const noConditionAdapter: ProviderAdapter = {
447+
config: noConditionAdapterConfig,
448+
resolveOptions: mockResolveOptions,
449+
};
450+
adapters.set('no-condition-fn', noConditionAdapter);
451+
try {
452+
await expect(
453+
resolveWizardNavigation(
454+
'no-condition-fn',
455+
{ currentStep: 'a' },
456+
TEST_PROJECT_ID,
457+
),
458+
).rejects.toThrow(
459+
/Benchmark provider does not support conditional wizard steps/,
460+
);
461+
} finally {
462+
adapters.delete('no-condition-fn');
463+
}
464+
});
407465
});

0 commit comments

Comments
 (0)