interplane.Get Omega
Read in your language

omega-mv

Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.

Brought by drakestapleton

branch main Branches Tags History

omega-mv / tests / universal / test_evidence_lifecycle.py

57 lines · 2806 bytes Raw Blame History
1"""Regression for failed attempts retaining prior successful evidence."""
2import json
3import os
4from pathlib import Path
5import shutil
6import subprocess
7import sys
8import tempfile
9import unittest
10
11ROOT = Path(__file__).resolve().parents[2]
12
13class EvidenceLifecycle(unittest.TestCase):
14 def attempt(self, corrupt_contract):
15 with tempfile.TemporaryDirectory(prefix='omega625-evidence-') as td:
16 root = Path(td)
17 (root/'tests/universal').mkdir(parents=True)
18 (root/'spec/universal').mkdir(parents=True)
19 for rel in ['tests/universal/semantics.py', 'spec/universal/semantics.md', 'spec/universal/profiles.json']:
20 shutil.copyfile(ROOT/rel, root/rel)
21 if corrupt_contract:
22 with (root/'spec/universal/semantics.md').open('a') as f:
23 f.write('\nchanged contract\n')
24 out = root/'out'
25 out.mkdir()
26 receipt = out/'receipt.json'
27 receipt.write_text(json.dumps({'result':'PASS', 'attempt':'older'}))
28 env = dict(os.environ, UNIVERSAL_OUT=str(out), CC=str(root/'compiler-does-not-exist'))
29 proc = subprocess.run([sys.executable, str(root/'tests/universal/semantics.py')], env=env, capture_output=True, text=True, timeout=10)
30 self.assertEqual(proc.returncode, 1, proc.stdout+proc.stderr)
31 self.assertIn('FAIL:', proc.stderr)
32 self.assertIn('STALE_CONTRACT_DIGEST' if corrupt_contract else 'compiler-does-not-exist', proc.stderr)
33 self.assertFalse(receipt.exists(), 'failed attempt retained stale PASS receipt')
34
35 def test_missing_compiler_invalidates_prior_pass(self):
36 self.attempt(False)
37
38 def test_probe_build_failure_invalidates_prior_pass(self):
39 with tempfile.TemporaryDirectory(prefix='omega625-build-') as td:
40 root = Path(td)
41 (root/'mk').mkdir()
42 (root/'tests/universal').mkdir(parents=True)
43 for rel in ['mk/universal.mk', 'tests/universal/osc_probe.c']:
44 shutil.copyfile(ROOT/rel, root/rel)
45 receipt = root/'out/universal-semantics/receipt.json'
46 receipt.parent.mkdir(parents=True)
47 receipt.write_text('{"result":"PASS","attempt":"older"}')
48 proc = subprocess.run(['make','-f','mk/universal.mk','OUT_DIR=out','CC=false','test-universal-semantics'], cwd=root, capture_output=True, text=True, timeout=10)
49 self.assertEqual(proc.returncode, 2, proc.stdout+proc.stderr)
50 self.assertIn('false', proc.stdout)
51 self.assertFalse(receipt.exists(), 'failed probe build retained stale PASS receipt')
52
53 def test_stale_contract_invalidates_prior_pass(self):
54 self.attempt(True)
55
56if __name__ == '__main__':
57 unittest.main()