Files
MeltMind/tools/test_phase2_local_freeze.py
T

20 lines
1.5 KiB
Python

import json,tempfile,unittest
from pathlib import Path
from unittest.mock import patch
import phase2_local_freeze_io as local
import phase2_fixed_io as original
class LocalBarrierTests(unittest.TestCase):
def test_original_verifier_and_tamper_detection(self):
with tempfile.TemporaryDirectory() as d:
b=Path(d)/'base';r=b/'run';r.mkdir(parents=True);(r/'contract.json').write_text('{}\n');p=b/'code.py';p.write_text('value=1\n')
with patch.multiple(local,BASE=b,STORE=Path(d)/'git',LOCK=Path(d)/'lock',ENGINEERING=b/'missing'),patch.object(original,'BASE',b):
local.freeze(r,'launch',[r/'contract.json',p]);proof=original.verify(r,'launch');self.assertFalse(proof['remote_published']);self.assertEqual(len(proof['commit']),40)
p.write_text('value=2\n')
with self.assertRaises(Exception):original.verify(r,'launch')
def test_sequential_barriers_preserve_prior_commit(self):
with tempfile.TemporaryDirectory() as d:
b=Path(d)/'base';r=b/'run';r.mkdir(parents=True);(r/'contract.json').write_text('{}\n');p=b/'code.py';p.write_text('value=1\n')
with patch.multiple(local,BASE=b,STORE=Path(d)/'git',LOCK=Path(d)/'lock',ENGINEERING=b/'missing'):
local.freeze(r,'one',[r/'contract.json',p]);one=json.loads((r/'one-git-freeze.json').read_text())['commit'];q=b/'model';q.write_text('fixed weights');local.freeze(r,'two',[r/'contract.json',q]);two=json.loads((r/'two-git-freeze.json').read_text())['commit'];self.assertNotEqual(one,two)
if __name__=='__main__':unittest.main()