"""Validate explicit case reports without treating missing output as a failure case.""" def parse_contract_cases(stdout, expected_count, returncode): import json rows, summaries, issues = [], [], [] try: for line in stdout.splitlines(): if line.startswith('CONTRACT_CASE '): rows.append(json.loads(line[len('CONTRACT_CASE '):])) elif line.startswith('CONTRACT_SUMMARY '): summaries.append(json.loads(line[len('CONTRACT_SUMMARY '):])) except (ValueError, TypeError): return rows, ['Malformed native case JSON'] ids = [r.get('id', r.get('name')) for r in rows] if len(rows) != expected_count or any(not x for x in ids) or len(ids) != len(set(ids)): issues.append('Native case inventory incomplete or duplicated') if any(type(r.get('passed')) is not bool for r in rows): issues.append('Missing boolean case outcome') if len(summaries) != 1: issues.append('Missing or duplicate native summary') else: s = summaries[0] if s.get('tests', s.get('total')) != expected_count or s.get('skipped', 0): issues.append('Native summary coverage mismatch') if 'passed' in s and s['passed'] != sum(r.get('passed') is True for r in rows): issues.append('Native summary outcome mismatch') expected_exit = int(any(r.get('passed') is False for r in rows)) if returncode != expected_exit: issues.append('Native exit status disagrees with case outcomes') return rows, issues