Skip to content

Commit c710f1c

Browse files
Merge branch 'main' into dependabot/npm_and_yarn/dev-dependencies-0ee6d34581
2 parents 1b0d558 + dcd7130 commit c710f1c

9 files changed

Lines changed: 475 additions & 279 deletions

File tree

__tests__/functional/e2e.functional.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ describe('E2E Test Cases', () => {
6565
clientId: process.env.VITE_ATHENA_CLIENT_ID ?? '',
6666
clientSecret: process.env.VITE_ATHENA_CLIENT_SECRET ?? '',
6767
audience: parseAudience(process.env.VITE_ATHENA_AUDIENCE),
68-
scope: 'manage:classify',
6968
},
7069
});
7170

@@ -120,7 +119,7 @@ describe('E2E Test Cases', () => {
120119
format: getImageFormat(filename),
121120
});
122121

123-
expect(response.error, `Classification error for ${filename}`).toBeNull();
122+
expect(response.error, `Classification error for ${filename}`).toBeUndefined();
124123

125124
// Build actual weights map
126125
const actualWeights = new Map<string, number>();

__tests__/functional/main.functional.test.ts

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
ClassifierSdk,
55
type ClassifyImageInput,
66
ImageFormat,
7+
parseAudience,
78
} from '../../src/index.js';
89
import fs from 'fs';
910
import { randomUUID } from 'crypto';
@@ -13,16 +14,18 @@ describe('ClassifierSdk Functional Tests', () => {
1314
it('should listDeployments and return responses (smoke test)', async ({
1415
expect,
1516
}) => {
16-
// This is a smoke test. You must have a running gRPC server at localhost:50051 for this to pass.
17+
// This is a smoke test. The gRPC server address is taken from VITE_ATHENA_GRPC_ADDRESS,
18+
// falling back to the SDK default if the variable is not set.
1719
// You may want to mock the gRPC client for true unit testing.
1820
const sdk = new ClassifierSdk({
1921
deploymentId: process.env.VITE_ATHENA_DEPLOYMENT_ID,
2022
affiliate: process.env.VITE_ATHENA_AFFILIATE,
23+
grpcAddress: process.env.VITE_ATHENA_GRPC_ADDRESS,
2124
authentication: {
2225
issuerUrl: process.env.VITE_OAUTH_ISSUER,
2326
clientId: process.env.VITE_ATHENA_CLIENT_ID,
2427
clientSecret: process.env.VITE_ATHENA_CLIENT_SECRET,
25-
scope: 'manage:classify',
28+
audience: parseAudience(process.env.VITE_ATHENA_AUDIENCE),
2629
},
2730
});
2831

@@ -46,11 +49,12 @@ describe('ClassifierSdk Functional Tests', () => {
4649
const sdk = new ClassifierSdk({
4750
deploymentId: process.env.VITE_ATHENA_DEPLOYMENT_ID,
4851
affiliate: process.env.VITE_ATHENA_AFFILIATE,
52+
grpcAddress: process.env.VITE_ATHENA_GRPC_ADDRESS,
4953
authentication: {
5054
issuerUrl: process.env.VITE_OAUTH_ISSUER,
5155
clientId: process.env.VITE_ATHENA_CLIENT_ID,
5256
clientSecret: process.env.VITE_ATHENA_CLIENT_SECRET,
53-
scope: 'manage:classify',
57+
audience: parseAudience(process.env.VITE_ATHENA_AUDIENCE),
5458
},
5559
});
5660

@@ -60,8 +64,8 @@ describe('ClassifierSdk Functional Tests', () => {
6064
};
6165

6266
const response = await sdk.classifySingle(input);
63-
expect(response.classifications).toBe(true);
64-
expect(response.error).toBeNull();
67+
expect(Array.isArray(response.classifications)).toBe(true);
68+
expect(response.error).toBeUndefined();
6569
}, 10000);
6670
});
6771

@@ -70,17 +74,19 @@ describe('ClassifierSdk Functional Tests', () => {
7074
expect,
7175
annotate,
7276
}) => {
73-
// This is a smoke test. You must have a running gRPC server at localhost:50051 for this to pass.
77+
// This is a smoke test. The gRPC server address is taken from VITE_ATHENA_GRPC_ADDRESS,
78+
// falling back to the SDK default if the variable is not set.
7479
// You may want to mock the gRPC client for true unit testing.
7580
const imagePath = __dirname + '/448x448.jpg';
7681
const sdk = new ClassifierSdk({
7782
deploymentId: process.env.VITE_ATHENA_DEPLOYMENT_ID,
7883
affiliate: process.env.VITE_ATHENA_AFFILIATE,
84+
grpcAddress: process.env.VITE_ATHENA_GRPC_ADDRESS,
7985
authentication: {
8086
issuerUrl: process.env.VITE_OAUTH_ISSUER,
8187
clientId: process.env.VITE_ATHENA_CLIENT_ID,
8288
clientSecret: process.env.VITE_ATHENA_CLIENT_SECRET,
83-
scope: 'manage:classify',
89+
audience: parseAudience(process.env.VITE_ATHENA_AUDIENCE),
8490
},
8591
});
8692

@@ -172,11 +178,12 @@ describe('ClassifierSdk Functional Tests', () => {
172178
const sdk = new ClassifierSdk({
173179
deploymentId: process.env.VITE_ATHENA_DEPLOYMENT_ID,
174180
affiliate: process.env.VITE_ATHENA_AFFILIATE,
181+
grpcAddress: process.env.VITE_ATHENA_GRPC_ADDRESS,
175182
authentication: {
176183
issuerUrl: process.env.VITE_OAUTH_ISSUER,
177184
clientId: process.env.VITE_ATHENA_CLIENT_ID,
178185
clientSecret: process.env.VITE_ATHENA_CLIENT_SECRET,
179-
scope: 'manage:classify',
186+
audience: parseAudience(process.env.VITE_ATHENA_AUDIENCE),
180187
},
181188
});
182189

@@ -251,17 +258,19 @@ describe('ClassifierSdk Functional Tests', () => {
251258
expect,
252259
annotate,
253260
}) => {
254-
// This is a smoke test. You must have a running gRPC server at localhost:50051 for this to pass.
261+
// This is a smoke test. The gRPC server address is taken from VITE_ATHENA_GRPC_ADDRESS,
262+
// falling back to the SDK default if the variable is not set.
255263
// You may want to mock the gRPC client for true unit testing.
256264
const imagePath = __dirname + '/448x448.jpg';
257265
const sdk = new ClassifierSdk({
258266
deploymentId: process.env.VITE_ATHENA_DEPLOYMENT_ID,
259267
affiliate: process.env.VITE_ATHENA_AFFILIATE,
268+
grpcAddress: process.env.VITE_ATHENA_GRPC_ADDRESS,
260269
authentication: {
261270
issuerUrl: process.env.VITE_OAUTH_ISSUER,
262271
clientId: process.env.VITE_ATHENA_CLIENT_ID,
263272
clientSecret: process.env.VITE_ATHENA_CLIENT_SECRET,
264-
scope: 'manage:classify',
273+
audience: parseAudience(process.env.VITE_ATHENA_AUDIENCE),
265274
},
266275
});
267276

__tests__/unit/authenticationManager.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ const options: AuthenticationOptions = {
2222
clientId: 'client-id',
2323
clientSecret: 'client-secret',
2424
issuerUrl: 'https://issuer.example.com',
25-
scope: 'manage:classify',
2625
};
2726

2827
describe('AuthenticationManager', () => {
@@ -46,7 +45,7 @@ describe('AuthenticationManager', () => {
4645
);
4746
expect(openidClient.clientCredentialsGrant).toHaveBeenCalledWith(
4847
mockDiscovery,
49-
{ audience: 'crisp-athena-live', scope: options.scope },
48+
{ audience: 'crisp-athena-live' },
5049
);
5150
});
5251

__tests__/unit/main.test.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ describe('ClassifierSdk', () => {
3737
issuerUrl: 'https://test-issuer.com',
3838
clientId: 'test-client-id',
3939
clientSecret: 'test-client-secret',
40-
scope: 'manage:classify',
4140
},
4241
});
4342
});
@@ -57,7 +56,6 @@ describe('ClassifierSdk', () => {
5756
issuerUrl: 'https://test-issuer.com',
5857
clientId: 'test-client-id',
5958
clientSecret: 'test-client-secret',
60-
scope: 'manage:classify',
6159
},
6260
});
6361

@@ -74,7 +72,6 @@ describe('ClassifierSdk', () => {
7472
issuerUrl: 'https://test-issuer.com',
7573
clientId: 'test-client-id',
7674
clientSecret: 'test-client-secret',
77-
scope: 'manage:classify',
7875
},
7976
});
8077

__tests__/unit/module-import.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ describe('Module Import Tests', () => {
6363
issuerUrl: 'https://test-issuer.com',
6464
clientId: 'test-client-id',
6565
clientSecret: 'test-client-secret',
66-
scope: 'manage:classify',
6766
},
6867
});
6968

samples/e2e-testcases/index.ts

Lines changed: 59 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,61 @@ function compareResults(
233233
return differences;
234234
}
235235

236+
/**
237+
* Format structured SDK and runtime errors for readable CLI output.
238+
*/
239+
function formatError(error: unknown): string {
240+
if (error instanceof Error) {
241+
const details = error as Error & {
242+
code?: unknown;
243+
details?: unknown;
244+
};
245+
246+
const parts = [details.message, details.details]
247+
.filter((value): value is string => typeof value === 'string' && value.length > 0);
248+
249+
if (typeof details.code === 'number' || typeof details.code === 'string') {
250+
parts.unshift(`code ${details.code}`);
251+
}
252+
253+
if (parts.length > 1 || (parts.length === 1 && parts[0] !== error.message)) {
254+
return parts.join(' - ');
255+
}
256+
return error.message;
257+
}
258+
259+
if (typeof error === 'string') {
260+
return error;
261+
}
262+
263+
if (error && typeof error === 'object') {
264+
const details = error as {
265+
code?: unknown;
266+
message?: unknown;
267+
details?: unknown;
268+
};
269+
270+
const parts = [details.message, details.details]
271+
.filter((value): value is string => typeof value === 'string' && value.length > 0);
272+
273+
if (typeof details.code === 'number' || typeof details.code === 'string') {
274+
parts.unshift(`code ${details.code}`);
275+
}
276+
277+
if (parts.length > 0) {
278+
return parts.join(' - ');
279+
}
280+
281+
try {
282+
return JSON.stringify(error);
283+
} catch {
284+
return String(error);
285+
}
286+
}
287+
288+
return String(error);
289+
}
290+
236291
/**
237292
* Main execution
238293
*/
@@ -293,7 +348,9 @@ async function main(): Promise<void> {
293348
});
294349

295350
if (response.error) {
296-
console.error(` ✗ ${filename} - Classification error: ${response.error}`);
351+
console.error(
352+
` ✗ ${filename} - Classification error: ${formatError(response.error)}`,
353+
);
297354
results.push({ filename, passed: false, differences: [] });
298355
continue;
299356
}
@@ -323,7 +380,7 @@ async function main(): Promise<void> {
323380
}
324381
}
325382
} catch (error) {
326-
const message = error instanceof Error ? error.message : String(error);
383+
const message = formatError(error);
327384
console.error(` ✗ ${filename} - Error: ${message}`);
328385
results.push({ filename, passed: false, differences: [] });
329386
}

0 commit comments

Comments
 (0)