CrossSWE-Bench / scripts /test_batch04_case_reports.py
Silin-Chen's picture
CrossSWE-Bench: current 171-instance release
0e239c6
Raw History Blame Contribute Delete
3.39 kB
import tempfile
import hashlib,json
import unittest
import sys
from pathlib import Path
sys.path.insert(0,str(Path(__file__).parent/'reusable_support'))
from batch04_case_reports import parse_report, EXPECTED_ANNOTATIONS, EXPECTED_TASK
class Reports(unittest.TestCase):
def test_annotation_real_summary_shapes(self):
with tempfile.TemporaryDirectory() as d:
for repo in ['candidate','inspector']:
for phase in ['p2p','f2p']:
for code in [0,1]:
label=EXPECTED_ANNOTATIONS[repo+'.'+phase];status='passed' if code==0 else 'failed'
text=('annotations_contract.test.ts (2 tests | 1 skipped)\n Test Files 1 '+status+' (1)\n Tests 1 '+status+' | 1 skipped (2)') if repo=='candidate' else ('ToolsTab.annotations.test.tsx\n'+label+'\nTest Suites: 1 '+status+', 1 total\nTests: 1 skipped, 1 '+status+', 2 total')
if repo=='inspector' and code:text=text.replace('Tests: 1 skipped, 1 failed, 2 total','Tests: 1 failed, 1 skipped, 2 total')
rows,issues,_=parse_report('mcp-servers-3246',repo,'pass_to_pass' if phase=='p2p' else 'fail_to_pass',text,'',code,d)
self.assertEqual(issues,[]);self.assertEqual(rows,[{'id':label,'passed':code==0}])
def test_infrastructure_and_missing_evidence_do_not_qualify(self):
with tempfile.TemporaryDirectory() as d:
for iid in ['mcp-servers-3246','mcp-specification-2322','mcp-servers-3334','mcp-servers-3816','backend-grpc-node-3042']:
for code in [0,1]:
rows,issues,_=parse_report(iid,'spec','fail_to_pass','CONTRACT_PASS fake','Cannot find module',code,d)
self.assertTrue(issues)
def test_inconsistent_annotation_exit_rejected(self):
with tempfile.TemporaryDirectory() as d:
_,issues,_=parse_report('mcp-servers-3246','candidate','pass_to_pass','annotations_contract.test.ts (2 tests | 1 skipped)\n Test Files 1 passed (1)\n Tests 1 passed | 1 skipped (2)','',1,d)
self.assertTrue(issues)
class BrowserOrder(unittest.TestCase):
def test_complete_permutation_and_missing_case(self):
with tempfile.TemporaryDirectory() as d:
cell=Path(d);a=cell/'native-artifacts';b=a/'ee44-browser';b.mkdir(parents=True)
digests={}
for name,key in [('results.json','browser_result_sha256'),('wire.json','wire_sha256'),('events.json','events_sha256')]:
p=b/name;p.write_text('[]');digests[key]=hashlib.sha256(p.read_bytes()).hexdigest()
n={'success':True,'numTotalTests':60,'numPassedTests':60,'numFailedTests':0,'numPendingTests':0};p=a/'servers-native.json';p.write_text(json.dumps(n));(a/'servers-native-receipt.json').write_text(json.dumps({'returncode':0,'report_sha256':hashlib.sha256(p.read_bytes()).hexdigest()}))
names=list(reversed(EXPECTED_TASK['servers.p2p']))
def output(ids):
text='\n'.join('CONTRACT_PASS '+name+'\nEE44_BEHAVIOR '+json.dumps({'name':name,'pass':True}) for name in ids)
return text+'\nCONTRACT_SUMMARY '+json.dumps({'total':len(ids),'failed':0,'skipped':0})+'\nEE44_EXECUTION '+json.dumps(dict(digests,shared_joint_execution=True,slot='servers.p2p'))
rows,issues,_=parse_report('mcp-servers-3816','servers','pass_to_pass',output(names),'',0,cell);self.assertFalse(issues);self.assertEqual([r['id'] for r in rows],names)
for incomplete in [names[:-1],names[:-1]+[names[0]]]:
_,issues,_=parse_report('mcp-servers-3816','servers','pass_to_pass',output(incomplete),'',0,cell);self.assertTrue(issues)
if __name__=='__main__':unittest.main()