LittlePlyResearch notebook

test_contract.py

python · 35 lines · Exact bytes

Line 1 ↗
Version & provenance · service-cm7-v1

Recorded SHA-256 00be1ba6d707e67b515e905ebec9b408cc245b13077f361984f028ad61a6d5dbRendered SHA-256 00be1ba6d707e67b515e905ebec9b408cc245b13077f361984f028ad61a6d5db

Apache-2.0 original project code. License notes. Line links are stable within this snapshot. Live CM-7 release 29e68a8e8533-39446d6ca608. Selected checkpoint 29e68a8e85336cbb1f56efdad36bd76217728b6a376d1e5f74e89887d21383da. Explicit source allowlist; private configuration, credentials, state and logs excluded. Shared service dependencies remain in historical service snapshots.

1import sys,json,unittest,importlib.util,hashlib
2from pathlib import Path
3root=Path(__file__).resolve().parent
4release=Path(json.loads((root/'candidate.json').read_text())['path'])
5sys.path[:0]=[str(release/'lichess_service'),str(release/'modelcode'),str(release)]
6import cm7_joint
7sys.modules['adapter']=cm7_joint
8source=root.parent.parent/'task-14/causal-chess-v1'
9spec=importlib.util.spec_from_file_location('evaluated_tests',source/'cm7-final-evaluation/test_adapter.py')
10mod=importlib.util.module_from_spec(spec);spec.loader.exec_module(mod)
11class Contract(unittest.TestCase):
12    def test_frozen_evaluated_sources(self):
13        pairs=[('lichess_service/cm7_joint.py','cm7-final-evaluation/adapter.py')]+[('state-v2/'+n,'state-v2/'+n) for n in ('codec.py','model.py','records.py')]
14        for a,b in pairs:self.assertEqual((release/a).read_bytes(),(source/b).read_bytes())
15    def test_long_history_fixed_prompt_keeps_board(self):
16        b=cm7_joint.c.chess.Board()
17        for _ in range(90):
18            for m in ('g1f3','g8f6','f3g1','f6g8'):b.push_uci(m)
19        before=(b.fen(),list(b.move_stack))
20        p=cm7_joint.c.prompt(b,16)
21        self.assertEqual(len(p['input_ids']),120)
22        self.assertEqual(len(p['attention_mask']),120)
23        self.assertEqual(before,(b.fen(),list(b.move_stack)))
24    def test_manifest_and_policy_retention(self):
25        m=json.loads((release/'manifest.json').read_text());base=release.parent/m['base_release']
26        for name,expected in m['files'].items():
27            with (release/name).open('rb') as f:self.assertEqual(hashlib.file_digest(f,'sha256').hexdigest(),expected)
28        for name in ('mate-policy.json','littleply-mate','mate_backend.py','lichess_service/local_play.py','lichess_service/standing.py','lichess_service/scheduler.py'):
29            self.assertEqual((release/name).read_bytes(),(base/name).read_bytes())
30if __name__=='__main__':
31    suite=unittest.TestSuite([unittest.defaultTestLoader.loadTestsFromModule(mod),unittest.defaultTestLoader.loadTestsFromTestCase(Contract)])
32    result=unittest.TextTestRunner(verbosity=2).run(suite)
33    sys.exit(not result.wasSuccessful())
34
35