Skip to content

Commit 0064ea0

Browse files
Add allowClientError to Scenario interface for expected client failures (#123)
* Add allowClientError to Scenario interface for expected client failures * Apply suggestion from @pcarleton Co-authored-by: Paul Carleton <paulcarletonjr@gmail.com> --------- Co-authored-by: Paul Carleton <paulcarletonjr@gmail.com>
1 parent c2f3fda commit 0064ea0

5 files changed

Lines changed: 19 additions & 5 deletions

File tree

src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,8 @@ program
207207
const { overallFailure } = printClientResults(
208208
result.checks,
209209
verbose,
210-
result.clientOutput
210+
result.clientOutput,
211+
result.allowClientError
211212
);
212213

213214
if (options.expectedFailures) {

src/runner/client.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ export async function runConformanceTest(
9797
checks: ConformanceCheck[];
9898
clientOutput: ClientExecutionResult;
9999
resultDir?: string;
100+
allowClientError?: boolean;
100101
}> {
101102
let resultDir: string | undefined;
102103

@@ -164,7 +165,8 @@ export async function runConformanceTest(
164165
return {
165166
checks,
166167
clientOutput,
167-
resultDir
168+
resultDir,
169+
allowClientError: scenario.allowClientError
168170
};
169171
} finally {
170172
await scenario.stop();
@@ -174,7 +176,8 @@ export async function runConformanceTest(
174176
export function printClientResults(
175177
checks: ConformanceCheck[],
176178
verbose: boolean = false,
177-
clientOutput?: ClientExecutionResult
179+
clientOutput?: ClientExecutionResult,
180+
allowClientError: boolean = false
178181
): {
179182
passed: number;
180183
failed: number;
@@ -195,7 +198,10 @@ export function printClientResults(
195198
? clientOutput.exitCode !== 0
196199
: false;
197200
const overallFailure =
198-
failed > 0 || warnings > 0 || clientTimedOut || clientExitedWithError;
201+
failed > 0 ||
202+
warnings > 0 ||
203+
clientTimedOut ||
204+
(clientExitedWithError && !allowClientError);
199205

200206
if (verbose) {
201207
// Verbose mode: JSON goes to stdout for piping to jq/jless
@@ -215,7 +221,7 @@ export function printClientResults(
215221
console.error(`\n⚠️ CLIENT TIMED OUT - Test incomplete`);
216222
}
217223

218-
if (clientExitedWithError && !clientTimedOut) {
224+
if (clientExitedWithError && !clientTimedOut && !allowClientError) {
219225
console.error(
220226
`\n⚠️ CLIENT EXITED WITH ERROR (code ${clientOutput?.exitCode}) - Test may be incomplete`
221227
);

src/scenarios/client/auth/resource-mismatch.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export class ResourceMismatchScenario implements Scenario {
2929
name = 'auth/resource-mismatch';
3030
description =
3131
'Tests that client rejects when PRM resource does not match server URL';
32+
allowClientError = true;
3233

3334
private authServer = new ServerLifecycle();
3435
private server = new ServerLifecycle();

src/scenarios/client/auth/scope-handling.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,7 @@ export class ScopeRetryLimitScenario implements Scenario {
479479
name = 'auth/scope-retry-limit';
480480
description =
481481
'Tests that client implements retry limits to prevent infinite authorization loops on repeated 403 responses';
482+
allowClientError = true;
482483
private authServer = new ServerLifecycle();
483484
private server = new ServerLifecycle();
484485
private checks: ConformanceCheck[] = [];

src/types.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ export interface ScenarioUrls {
3636
export interface Scenario {
3737
name: string;
3838
description: string;
39+
/**
40+
* If true, a non-zero client exit code is expected and will not cause the test to fail.
41+
* Use this for scenarios where the client is expected to error (e.g., rejecting invalid auth).
42+
*/
43+
allowClientError?: boolean;
3944
start(): Promise<ScenarioUrls>;
4045
stop(): Promise<void>;
4146
getChecks(): ConformanceCheck[];

0 commit comments

Comments
 (0)