Skip to content

Commit 98d6592

Browse files
committed
Add getHandler to everything-client for cleaner test imports
Instead of importing individual handlers, tests can now import getHandler and look up handlers by scenario name.
1 parent 20b98a1 commit 98d6592

2 files changed

Lines changed: 11 additions & 13 deletions

File tree

examples/clients/typescript/everything-client.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,14 @@ function registerScenarios(names: string[], handler: ScenarioHandler): void {
4242
}
4343
}
4444

45+
/**
46+
* Get a scenario handler by name.
47+
* Returns undefined if no handler is registered for the scenario.
48+
*/
49+
export function getHandler(scenarioName: string): ScenarioHandler | undefined {
50+
return scenarioHandlers[scenarioName];
51+
}
52+
4553
// ============================================================================
4654
// Basic scenarios (initialize, tools-call)
4755
// ============================================================================

src/scenarios/client/auth/index.test.ts

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@ import { runClient as ignoreScopeClient } from '../../../../examples/clients/typ
1010
import { runClient as partialScopesClient } from '../../../../examples/clients/typescript/auth-test-partial-scopes';
1111
import { runClient as ignore403Client } from '../../../../examples/clients/typescript/auth-test-ignore-403';
1212
import { runClient as noRetryLimitClient } from '../../../../examples/clients/typescript/auth-test-no-retry-limit';
13-
import {
14-
runClientCredentialsJwt,
15-
runClientCredentialsBasic
16-
} from '../../../../examples/clients/typescript/everything-client';
13+
import { getHandler } from '../../../../examples/clients/typescript/everything-client';
1714
import { setLogLevel } from '../../../../examples/clients/typescript/helpers/logger';
1815

1916
beforeAll(() => {
@@ -29,13 +26,6 @@ const allowClientErrorScenarios = new Set<string>([
2926
'auth/scope-retry-limit'
3027
]);
3128

32-
// Map of scenario names to their specific client handlers
33-
const scenarioClientMap: Record<string, (serverUrl: string) => Promise<void>> =
34-
{
35-
'auth/client-credentials-jwt': runClientCredentialsJwt,
36-
'auth/client-credentials-basic': runClientCredentialsBasic
37-
};
38-
3929
describe('Client Auth Scenarios', () => {
4030
// Generate individual test for each auth scenario
4131
for (const scenario of authScenariosList) {
@@ -44,8 +34,8 @@ describe('Client Auth Scenarios', () => {
4434
// TODO: skip in a native way?
4535
return;
4636
}
47-
// Use scenario-specific client if available, otherwise use goodClient
48-
const clientFn = scenarioClientMap[scenario.name] ?? goodClient;
37+
// Use everything-client handler if available, otherwise use goodClient
38+
const clientFn = getHandler(scenario.name) ?? goodClient;
4939
const runner = new InlineClientRunner(clientFn);
5040
await runClientAgainstScenario(runner, scenario.name, {
5141
allowClientError: allowClientErrorScenarios.has(scenario.name)

0 commit comments

Comments
 (0)