Download code/tests/check_code.py from zhizeng115/EchoScout-FourTask: direct link, hf CLI and curl.
- Browser
- Download file 3.14 kB
-
https://huggingface.co/datasets/zhizeng115/EchoScout-FourTask/resolve/main/code/tests/check_code.py
- Command line
-
hf download hf://datasets/zhizeng115/EchoScout-FourTask/code/tests/check_code.py
-
curl -L -o check_code.py https://huggingface.co/datasets/zhizeng115/EchoScout-FourTask/resolve/main/code/tests/check_code.py
3.14 kB
| """Dependency-free source integrity, protocol and packaging checks.""" | |
| import ast,json,sys,unittest,hashlib | |
| from pathlib import Path | |
| R=Path(__file__).resolve().parents[1];sys.path.insert(0,str(R)) | |
| from evaluation.fourtask_common_v3.contract import messages,parse_action,verify_same_state,digest | |
| from training.echoscout_no_sft_v1.train import SPEC,config_for,transformed | |
| class CodeChecks(unittest.TestCase): | |
| def test_syntax_and_json(self): | |
| for p in R.rglob('*.py'):ast.parse(p.read_text(),filename=str(p.relative_to(R))) | |
| for p in R.rglob('*.json'): | |
| if 'workspace' not in p.parts and 'runs' not in p.parts:json.loads(p.read_text()) | |
| def test_action_contract(self): | |
| self.assertEqual(parse_action('<answer>rotate(-180,90)</answer>',[0,0]),('rotate',-180,90)) | |
| for s in ['rotate(1,0)','<answer>rotate(181,0)</answer>','<answer>rotate(1.5,0)</answer>','<answer>submit(1,0)</answer>','<answer>rotate(1,0)</answer><answer>submit(0,0)</answer>']: | |
| self.assertIsNone(parse_action(s,[0,0])) | |
| self.assertEqual(parse_action('Reasoning. <answer>submit(315,0)</answer>',[315,0]),('submit',315,0)) | |
| def test_observation_contract(self): | |
| m=messages('Find the bell.',[0,0],['<answer>rotate(30,0)</answer>'],2,'vision_stereo') | |
| self.assertEqual(sum(c['type']=='image' for c in m[1]['content']),2) | |
| self.assertEqual(sum(c['type']=='audio' for c in m[1]['content']),1) | |
| v=messages('Find the bell.',[0,0],[],1,'vision_only') | |
| self.assertFalse(any(c['type']=='audio' for c in v[1]['content'])) | |
| with self.assertRaises(AssertionError):messages('x',[0,0],[],11,'vision_only') | |
| def test_input_audit_detects_drift(self): | |
| keys=['episode_id','state_hash','track','protocol_sha256','semantic_prompt_sha256','rgb_sha256','audio_source_sha256','audio_effective_sha256'] | |
| a={k:digest(k) for k in keys};self.assertTrue(verify_same_state([a,a.copy()])) | |
| b=dict(a,semantic_prompt_sha256='changed') | |
| with self.assertRaises(AssertionError):verify_same_state([a,b]) | |
| def test_matched_ablation(self): | |
| for parent in SPEC['parents']: | |
| config=config_for(parent);source,code,changes=transformed(parent) | |
| self.assertEqual(config['sft_steps'],0);self.assertEqual(config['idm_steps'],600) | |
| self.assertEqual(config['alignment_steps'],400 if parent=='hvs_original' else 200) | |
| self.assertEqual(len(changes),3);ast.parse(code) | |
| for p,h in SPEC['source_sha256'].items():self.assertEqual(hashlib.sha256((R/p).read_bytes()).hexdigest(),h) | |
| def test_local_import_closure(self): | |
| for p in R.rglob('*.py'): | |
| for node in ast.walk(ast.parse(p.read_text())): | |
| if not isinstance(node,ast.ImportFrom) or not node.module:continue | |
| if node.level: | |
| base=p.parent | |
| for _ in range(node.level-1):base=base.parent | |
| candidates=[base.joinpath(*node.module.split('.'))] | |
| elif node.module.split('.')[0] in ['training','evaluation','omini','hvs_core','sound_search_core','run_sound_search']: | |
| candidates=[R.joinpath(*node.module.split('.')),R/'tools'/node.module] | |
| else:continue | |
| self.assertTrue(any(q.with_suffix('.py').exists() or (q/'__init__.py').exists() for q in candidates),(p,node.module)) | |
| if __name__=='__main__':unittest.main() | |