Datasets:
Download scripts/reusable_support/batch04_case_reports.py from CrossSWE/CrossSWE-Bench: direct link, hf CLI and curl.
- Browser
- Download file 16.3 kB
-
https://huggingface.co/datasets/CrossSWE/CrossSWE-Bench/resolve/main/scripts/reusable_support/batch04_case_reports.py
- Command line
-
hf download hf://datasets/CrossSWE/CrossSWE-Bench/scripts/reusable_support/batch04_case_reports.py
-
curl -L -o batch04_case_reports.py https://huggingface.co/datasets/CrossSWE/CrossSWE-Bench/resolve/main/scripts/reusable_support/batch04_case_reports.py
16.3 kB
| """Reparse the five frozen batch04 native protocols without running tests.""" | |
| from collections import Counter | |
| import hashlib | |
| import json | |
| from pathlib import Path | |
| import re | |
| def packets(text, prefix): | |
| return [json.loads(line[len(prefix):]) for line in text.splitlines() if line.startswith(prefix)] | |
| def load(root, name): | |
| return json.loads((root / name).read_text()) | |
| def parse_report(iid, repository, kind, stdout, stderr, returncode, cell): | |
| phase = 'p2p' if kind == 'pass_to_pass' else 'f2p' | |
| rows, issues, meta = [], [], {} | |
| artifacts = Path(cell) / 'native-artifacts' | |
| try: | |
| if iid == 'mcp-specification-2322': | |
| raw = packets(stdout, 'CROSSSWE_CASE ') | |
| summaries = packets(stdout, 'CROSSSWE_SUMMARY ') | |
| assert len(summaries) == 1 | |
| s = summaries[0] | |
| assert s['repo'] == repository and s['group'] == phase and not s['skipped'] | |
| assert [r['name'] for r in raw] == EXPECTED_SPEC[repository + '.' + phase] | |
| assert s['results'] == raw and all(r['status'] in ('passed', 'failed') for r in raw) | |
| root = artifacts / 'mrtr-formal' | |
| body = load(root, 'body-receipt.json') | |
| assert hashlib.sha256((root/'body-receipt.json').read_bytes()).hexdigest() == s['body_receipt_sha256'] | |
| assert body['source_before'] == body['source_after'] | |
| expected_exec = {'native_generate','provided','generated','native_protocol','provided_joint','generated_joint'} | |
| assert set(body['executions']) == expected_exec | |
| assert body['executions']['native_generate']['exit_code'] == 0 | |
| for label, execution in body['executions'].items(): | |
| assert execution['exit_code'] in (0, 1) | |
| logname = {'provided':'provided-ajv','generated':'generated-ajv','provided_joint':'provided-joint-ajv','generated_joint':'generated-joint-ajv'}.get(label,label) | |
| assert hashlib.sha256((root/(logname+'.log')).read_bytes()).hexdigest() == execution['log_sha256'] | |
| native = load(root/'protocol', 'native-protocol-result.json') | |
| assert native['model_contents_read'] is False and len(native['semantic_groups']) == 18 | |
| assert all(r['status'] in ('pass','fail') for r in native['semantic_groups']) | |
| for r in raw: | |
| if repository == 'spec': | |
| assert set(r['detail']) == {'provided','generated'} | |
| assert all(type(v['passed']) is bool and (len(v['cases']) > 0 or (r['name'].startswith('joint_pending_') and not v['passed'])) for v in r['detail'].values()) | |
| assert (r['status'] == 'passed') == all(v['passed'] for v in r['detail'].values()) | |
| else: | |
| assert r['detail'] is not None and r['detail']['phase'] == phase | |
| assert (r['status'] == 'passed') == (r['detail']['status'] == 'pass') | |
| rows = [{'id':r['name'], 'passed':r['status']=='passed'} for r in raw] | |
| assert s['executed'] == len(rows) and s['passed'] == sum(r['passed'] for r in rows) and s['failed'] == sum(not r['passed'] for r in rows) | |
| meta = {'count_unit':'schema or native protocol semantic group; shared bodies run once per world', | |
| 'native_protocol_counts':native['counts'], 'body_receipt_sha256':s['body_receipt_sha256']} | |
| elif iid == 'mcp-servers-3334': | |
| root=artifacts/'elicitation'; s=load(root,repository+'-'+phase+'-summary.json') | |
| summaries=packets(stdout,'CROSSSWE_COUNTS '); assert len(summaries)==1 | |
| assert summaries[0] == {k:s[k] for k in ['repo','mode','tests_run','passed','failed','skipped']} | |
| assert s['repo']==repository and s['mode']==phase and not s['skipped'] | |
| raw=s['cases']; assert [r['name'] for r in raw]==EXPECTED_URL[repository+'.'+phase] | |
| for r in raw: | |
| full=load(root,r['name']+'.json'); assert full['repo']==repository and full['mode']==phase and full['passed']==r['passed'] | |
| assert full['outbound'] and full['inbound'] and type(full['passed']) is bool | |
| assert re.search(r'^(PASS|FAIL) '+re.escape(r['name'])+r'(?: |$)',stdout,re.M) | |
| rows=[{'id':r['name'],'passed':r['passed']} for r in raw] | |
| assert s['tests_run']==len(rows) and s['passed']==sum(r['passed'] for r in rows) and s['failed']==sum(not r['passed'] for r in rows) | |
| joint=load(root,'joint-run-receipt.json');assert joint['returncode']==0 | |
| meta={'count_unit':'real Inspector/Everything browser scenario; shared browser body once per world','joint_execution':True} | |
| elif iid == 'mcp-servers-3816': | |
| raw=re.findall(r'^CONTRACT_(PASS|FAIL) (.+)$',stdout,re.M) | |
| assert Counter(name for status,name in raw)==Counter(EXPECTED_TASK[repository+'.'+phase]) | |
| details=packets(stdout,'EE44_BEHAVIOR '); assert [r['name'] for r in details]==[name for status,name in raw] | |
| assert all(type(r['pass']) is bool for r in details) | |
| rows=[{'id':name,'passed':status=='PASS'} for status,name in raw] | |
| assert [r['passed'] for r in rows]==[r['pass'] for r in details] | |
| summaries=packets(stdout,'CONTRACT_SUMMARY ');assert len(summaries)==1 | |
| s=summaries[0];assert s['total']==len(rows) and s['failed']==sum(not r['passed'] for r in rows) and not s['skipped'] | |
| executions=packets(stdout,'EE44_EXECUTION ');assert len(executions)==1 | |
| e=executions[0];assert e['shared_joint_execution'] and e['slot']==repository+'.'+phase | |
| root=artifacts/'ee44-browser' | |
| for name,key in [('results.json','browser_result_sha256'),('wire.json','wire_sha256'),('events.json','events_sha256')]: | |
| assert hashlib.sha256((root/name).read_bytes()).hexdigest()==e[key] | |
| meta={'count_unit':'browser scenario or native regression group; shared browser body once per world','joint_execution':True} | |
| if phase=='p2p': | |
| n=load(artifacts,repository+'-native.json');receipt=load(artifacts,repository+'-native-receipt.json') | |
| assert receipt['returncode']==0 and n['success'] and n['numPassedTests']>0 and n['numFailedTests']==0 and n.get('numPendingTests',0)==0 | |
| assert hashlib.sha256((artifacts/(repository+'-native.json')).read_bytes()).hexdigest()==receipt['report_sha256'] | |
| meta['nested_native_tests']={k:n[k] for k in ['numTotalTests','numPassedTests','numFailedTests']} | |
| elif iid == 'mcp-servers-3246': | |
| text=re.sub(r'\x1b\[[0-9;]*m','',stdout+'\n'+stderr) | |
| expected=EXPECTED_ANNOTATIONS[repository+'.'+phase] | |
| if repository=='candidate': | |
| assert 'annotations_contract.test.ts' in text and re.search(r'Test Files\s+1 (?:passed|failed)',text) | |
| assert re.search(r'Tests\s+1 (?:passed|failed)\s*\|\s*1 skipped\s*\(2\)',text) | |
| summary=re.findall(r'^\s*Tests\s+([^\n]+)',text,re.M);assert len(summary)==1 and '(2)' in summary[0] | |
| counts={label:int(n) for n,label in re.findall(r'(\d+) (passed|failed|skipped)',summary[0])} | |
| assert counts==({'passed':1,'skipped':1} if returncode==0 else {'failed':1,'skipped':1}) | |
| assert '(2 tests | 1 skipped)' in text or '(2 tests | 1 failed | 1 skipped)' in text | |
| else: | |
| assert 'ToolsTab.annotations.test.tsx' in text and re.search(r'Test Suites:\s+1 (?:passed|failed), 1 total',text) | |
| summary=re.findall(r'^Tests:\s+([^\n]+)',text,re.M);assert len(summary)==1 | |
| counts={label:int(n) for n,label in re.findall(r'(\d+) (passed|failed|skipped|total)',summary[0])} | |
| assert counts==({'skipped':1,'passed':1,'total':2} if returncode==0 else {'skipped':1,'failed':1,'total':2}) | |
| assert expected in ' '.join(text.split()) | |
| rows=[{'id':expected,'passed':returncode==0}] | |
| meta={'count_unit':'selected native Vitest/Jest test case','native_selected_tests':1,'native_name_filtered_tests':1} | |
| elif iid == 'mcp-specification-2685': | |
| data=[json.loads(line) for line in stdout.splitlines() if line.startswith('{')] | |
| raw=[r for r in data if 'case' in r];summaries=[r for r in data if r.get('summary') is True] | |
| assert len(summaries)==1 | |
| scope={'spec':'spec_runtime_repeat','quickstart':'quickstart','ruby_sdk':'ruby_sdk'}[repository] | |
| expected=EXPECTED_RUBY[('ruby_sdk' if repository=='ruby_sdk' else 'quickstart')+'.'+phase] | |
| assert [r['case'] for r in raw]==expected | |
| assert all(r['scope']==scope and r['mode']==phase and type(r['passed']) is bool for r in raw) | |
| summary=summaries[0];assert summary['scope']==scope and summary['mode']==phase | |
| assert summary['executed']==len(raw) and summary['passed']==sum(r['passed'] for r in raw) and summary['failed']==sum(not r['passed'] for r in raw) | |
| assert summary['repeated_quickstart_coverage']==(repository=='spec') | |
| assert '/testbed/modelcontextprotocol/ruby-sdk/lib/mcp/client.rb' in summary['sdk_loaded_paths'] | |
| assert all(p.startswith('/testbed/modelcontextprotocol/ruby-sdk/lib/mcp/') for p in summary['sdk_loaded_paths']) | |
| rows=[{'id':r['case'],'passed':r['passed']} for r in raw] | |
| meta={'count_unit':'live Ruby stdio/handshake scenario','sdk_loaded_paths':summary['sdk_loaded_paths'],'scope':scope,'repeated_quickstart_coverage':summary['repeated_quickstart_coverage']} | |
| if repository=='ruby_sdk' and phase=='p2p': | |
| native=re.findall(r'^(\d+) runs, (\d+) assertions, (\d+) failures, (\d+) errors, (\d+) skips$',stdout,re.M) | |
| assert len(native)==1 | |
| runs,assertions,failed,errors,skips=map(int,native[0]);assert runs>0 and assertions>0 and failed==errors==skips==0 | |
| meta['nested_native_tests']={'runs':runs,'assertions':assertions,'failures':failed,'errors':errors,'skips':skips} | |
| elif iid == 'backend-grpc-node-3042': | |
| if repository=='definitelytyped': | |
| expected='/testbed/DefinitelyTyped/DefinitelyTyped/types/node/node-tests/'+('assert.ts' if phase=='p2p' else 'crossrepo-certificate-dn.ts') | |
| assert expected in stdout.splitlines() | |
| if returncode: | |
| assert phase=='f2p' and re.search(r'(?:tls|crossrepo-certificate-dn)\.ts\(\d+,\d+\): error TS\d+:',stdout) | |
| meta={'count_unit':'strict native TypeScript compiler contract','resolved_input_files':len([l for l in stdout.splitlines() if l.startswith('/') and l.endswith('.ts')])} | |
| else: | |
| assert stdout.count('> tsc -p . --pretty false')==4 | |
| if returncode: | |
| assert phase=='f2p' and re.search(r'(?:rbac|certificate).*error TS\d+:',stdout) | |
| elif phase=='f2p': | |
| packets_=[json.loads(l) for l in stdout.splitlines() if l.startswith('{')] | |
| assert packets_[-1]=={'test':'crossrepo_tls_dn_rbac','cases':15,'result':'pass'} | |
| assert len([r for r in packets_ if r.get('result')=='pass' and 'case' in r])==12 | |
| meta={'count_unit':'native TypeScript compilation/RBAC contract command','prerequisite_package_compiles':4,'rbac_assertions_when_compilation_passes':15 if phase=='f2p' and returncode==0 else 0} | |
| rows=[{'id':repository+'/'+phase+'/native-compiler-contract','passed':returncode==0}] | |
| else: | |
| raise ValueError('Unsupported batch04 protocol') | |
| except (AssertionError,ValueError,KeyError,TypeError,IndexError,OSError) as e: | |
| issues.append('Incomplete/malformed native evidence: '+type(e).__name__+': '+str(e)) | |
| if not rows or len(rows)!=len({r['id'] for r in rows}):issues.append('Empty or duplicate case inventory') | |
| if any(token in stdout+'\n'+stderr for token in ['MODULE_NOT_FOUND','ERR_MODULE_NOT_FOUND','Cannot find module','ModuleNotFoundError:','TimeoutExpired:','cannot load such file','Bundler::GemNotFound']):issues.append('Dependency/infrastructure failure') | |
| if rows and returncode!=int(any(not r['passed'] for r in rows)):issues.append('Exit status disagrees with native outcomes') | |
| return rows,issues,meta | |
| EXPECTED_SPEC = {'spec.p2p': ['p2p:pending_task', 'p2p:legacy_completions', 'p2p:legacy_required_payload', 'p2p:legacy_errors', 'p2p:legacy_rpc', 'p2p:legacy_requests', 'p2p:legacy_client_inputs', 'p2p:legacy_task_status', 'joint_existing_wire'], 'spec.f2p': ['f2p:pending_tool', 'f2p:pending_resource', 'f2p:pending_prompt', 'f2p:task_followup', 'f2p:retry_fields', 'f2p:pending_validation', 'joint_pending_tool', 'joint_pending_non_tool'], 'conformance.p2p': ['legacy_tools-call-simple-text', 'legacy_resources-read-text', 'legacy_prompts-get-simple'], 'conformance.f2p': ['native_server_registry_and_checks', 'native_server_three_input_methods', 'native_server_multiround_and_non_tool', 'native_server_state_and_key_followup', 'native_server_rejection_and_capability_boundary', 'native_client_native', 'native_client_opaque_unicode_keys', 'native_client_empty_state_keys', 'native_detector_wrong_state', 'native_detector_dropped_state', 'native_detector_reused_rpc_id', 'native_detector_no_state_extra', 'native_detector_unrelated_state', 'native_detector_unrelated_responses', 'native_detector_complete_retried']} | |
| EXPECTED_URL = {'servers.f2p': ['url_accept', 'url_decline', 'url_cancel', 'url_protocol_error'], 'inspector.f2p': ['visible_destination_and_isolated_popup', 'repeat_url_then_form', 'unsafe_javascript', 'unsafe_data', 'unsafe_file'], 'servers.p2p': ['form_decline', 'form_cancel'], 'inspector.p2p': ['form_accept_content', 'form_required_validation', 'form_email_validation']} | |
| EXPECTED_TASK = {'servers.f2p': ['streamable-http-accept-1', 'streamable-http-accept-2', 'streamable-http-decline-1', 'streamable-http-cancel-1'], 'inspector.f2p': ['streamable-http-accept-1', 'streamable-http-accept-2', 'streamable-http-decline-1', 'streamable-http-cancel-1', 'sdk-queue-accept-1', 'sdk-queue-accept-2'], 'servers.p2p': ['stdio-accept-1', 'stdio-accept-2', 'stdio-decline-1', 'stdio-cancel-1', 'sse-accept-1', 'sse-accept-2', 'sse-decline-1', 'sse-cancel-1', 'stdio-unambiguous-1', 'stdio-completed-quiescent', 'stdio-echo-unicode', 'sse-unambiguous-1', 'sse-completed-quiescent', 'sse-echo-unicode', 'streamable-http-unambiguous-1', 'streamable-http-completed-quiescent', 'streamable-http-echo-unicode', 'native-servers-regression'], 'inspector.p2p': ['stdio-accept-1', 'stdio-accept-2', 'stdio-decline-1', 'stdio-cancel-1', 'sse-accept-1', 'sse-accept-2', 'sse-decline-1', 'sse-cancel-1', 'stdio-unambiguous-1', 'stdio-completed-quiescent', 'stdio-echo-unicode', 'sse-unambiguous-1', 'sse-completed-quiescent', 'sse-echo-unicode', 'streamable-http-unambiguous-1', 'streamable-http-completed-quiescent', 'streamable-http-echo-unicode', 'sdk-terminal-failed', 'sdk-terminal-cancelled', 'native-inspector-regression']} | |
| EXPECTED_ANNOTATIONS = {'candidate.p2p': 'regression: existing echo and annotated content invocation remains intact', 'candidate.f2p': 'publishes representative annotations through the existing register interface', 'inspector.p2p': 'regression: a tool without annotations can still be invoked with its input', 'inspector.f2p': 'renders all four actual server hints and updates them when the selected tool changes'} | |
| EXPECTED_RUBY = {'quickstart.p2p': ['quickstart_executable_live_roundtrip', 'quickstart_unsupported_extension_regression'], 'quickstart.f2p': ['quickstart_handshake_precedes_public_tool_use', 'quickstart_reject_error_before_tools', 'quickstart_reject_unsupported_version_before_tools'], 'ruby_sdk.p2p': ['implicit_first_request_and_repeated_tools', 'stdio_unicode_and_empty_arguments'], 'ruby_sdk.f2p': ['explicit_handshake_options_and_idempotence', 'close_clears_public_state_and_reconnects', 'supported_server_protocol_negotiation', 'reject_error_before_ready', 'reject_missing_result_before_ready', 'reject_nonobject_result_before_ready', 'reject_unsupported_version_before_ready', 'retry_after_server_rejects_first_initialize']} | |