Skip to content

Commit 1aa9403

Browse files
committed
fix(test): align mock latest result schema
1 parent fe07bc9 commit 1aa9403

2 files changed

Lines changed: 26 additions & 16 deletions

File tree

test/contract/p4-schema.test.ts

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ const LATEST_RESULT_REQUIRED = [
8383
'targetUrl',
8484
'failedStepIndex',
8585
'failureKind',
86+
'verdict',
87+
'executionStatus',
8688
'summary',
8789
] as const;
8890
// `targetUrlSource` (D1) is OPTIONAL — present on backends that shipped the D1
@@ -109,6 +111,15 @@ const FAILURE_KINDS = new Set<unknown>([
109111
'unknown',
110112
null,
111113
]);
114+
const VERDICTS = new Set<unknown>(['passed', 'failed', 'blocked', 'cancelled', 'unknown', null]);
115+
const EXECUTION_STATUSES = new Set<unknown>([
116+
'queued',
117+
'running',
118+
'completed',
119+
'cancelled',
120+
'error',
121+
'unknown',
122+
]);
112123

113124
function expectKeysMatch(value: Record<string, unknown>, allowed: Set<string>, label: string) {
114125
for (const key of Object.keys(value)) {
@@ -178,17 +189,6 @@ function validateTestStepList(value: unknown, label = 'TestStepList'): void {
178189
}
179190
}
180191

181-
function validateResultSummary(value: unknown, label: string): void {
182-
expect(value, label).toBeTypeOf('object');
183-
expect(value, label).not.toBeNull();
184-
const obj = value as Record<string, unknown>;
185-
expectKeysMatch(obj, new Set(['passed', 'failed', 'skipped']), label);
186-
for (const k of ['passed', 'failed', 'skipped']) {
187-
expect(typeof obj[k], `${label}.${k}`).toBe('number');
188-
expect((obj[k] as number) >= 0, `${label}.${k} >= 0`).toBe(true);
189-
}
190-
}
191-
192192
function validateLatestResult(value: unknown, label = 'LatestResult'): void {
193193
expect(value, `${label}: must be an object`).toBeTypeOf('object');
194194
expect(value, `${label}: must not be null`).not.toBeNull();
@@ -215,7 +215,9 @@ function validateLatestResult(value: unknown, label = 'LatestResult'): void {
215215
expect((obj.failedStepIndex as number) >= 1, `${label}.failedStepIndex >= 1`).toBe(true);
216216
}
217217
expect(FAILURE_KINDS.has(obj.failureKind), `${label}.failureKind`).toBe(true);
218-
validateResultSummary(obj.summary, `${label}.summary`);
218+
expect(VERDICTS.has(obj.verdict), `${label}.verdict`).toBe(true);
219+
expect(EXECUTION_STATUSES.has(obj.executionStatus), `${label}.executionStatus`).toBe(true);
220+
expect(typeof obj.summary, `${label}.summary`).toBe('string');
219221
}
220222

221223
describe('P4 schema contract — fixtures match the OpenAPI shapes', () => {

test/mock-backend/fixtures.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,9 @@ export const latestResultRunningFixture = {
243243
targetUrl: FIXTURE_TARGET_URL,
244244
failedStepIndex: null,
245245
failureKind: null,
246-
summary: { passed: 0, failed: 0, skipped: 0 },
246+
verdict: null,
247+
executionStatus: 'running' as const,
248+
summary: 'Run is still in progress.',
247249
};
248250

249251
export const latestResultPassedFixture = {
@@ -260,7 +262,9 @@ export const latestResultPassedFixture = {
260262
targetUrlSource: 'run' as const,
261263
failedStepIndex: null,
262264
failureKind: null,
263-
summary: { passed: 8, failed: 0, skipped: 0 },
265+
verdict: 'passed' as const,
266+
executionStatus: 'completed' as const,
267+
summary: 'Passed all 8 steps.',
264268
};
265269

266270
export const latestResultFailedFixture = {
@@ -277,7 +281,9 @@ export const latestResultFailedFixture = {
277281
targetUrlSource: 'run' as const,
278282
failedStepIndex: 5,
279283
failureKind: 'assertion' as const,
280-
summary: { passed: 4, failed: 1, skipped: 0 },
284+
verdict: 'failed' as const,
285+
executionStatus: 'completed' as const,
286+
summary: 'Failed (assertion) on step 5: expected cart badge to show 1 item, but it was empty.',
281287
};
282288

283289
export const failureContextFixture = {
@@ -351,7 +357,9 @@ export const failureContextNoAnalysisFixture = {
351357
targetUrl: 'https://staging.example.com/',
352358
failedStepIndex: 2,
353359
failureKind: 'unknown' as const,
354-
summary: { passed: 1, failed: 1, skipped: 0 },
360+
verdict: 'failed' as const,
361+
executionStatus: 'completed' as const,
362+
summary: 'Failed with no detailed analysis available.',
355363
},
356364
steps: [],
357365
code: {

0 commit comments

Comments
 (0)