Skip to content

Commit 899b5b7

Browse files
cameroncookecodex
andcommitted
fix(test): Handle malformed xcresult summaries
Return null when xcresult summary parsing receives malformed JSON so the exported parser matches its nullable contract and callers can safely fall back to streamed counts. Refs #397 Co-Authored-By: Codex <noreply@openai.com>
1 parent 271ba1c commit 899b5b7

2 files changed

Lines changed: 16 additions & 1 deletion

File tree

src/utils/__tests__/xcresult-test-failures.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ describe('parseXcresultTestSummaryCounts', () => {
2727
skipped: 0,
2828
});
2929
});
30+
31+
it('returns null for malformed JSON summary output', () => {
32+
expect(parseXcresultTestSummaryCounts('warning: no summary available')).toBeNull();
33+
expect(parseXcresultTestSummaryCounts('')).toBeNull();
34+
});
3035
});
3136

3237
describe('parseXcresultFailureMessage', () => {

src/utils/xcresult-test-failures.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,17 @@ function isSummaryCount(value: unknown): value is number {
2727
}
2828

2929
export function parseXcresultTestSummaryCounts(raw: string): Counts | null {
30-
const summary = JSON.parse(raw) as XcresultTestSummary;
30+
let summary: XcresultTestSummary;
31+
try {
32+
const parsed = JSON.parse(raw) as unknown;
33+
if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {
34+
return null;
35+
}
36+
summary = parsed as XcresultTestSummary;
37+
} catch {
38+
return null;
39+
}
40+
3141
const { passedTests, failedTests, skippedTests } = summary;
3242

3343
if (

0 commit comments

Comments
 (0)