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
omega-mv / seed / host / test_gate_integrity.py
| 1 | #!/usr/bin/env python3 |
| 2 | """Offline orchestration controls; no GPU, service, or historical receipt writes.""" |
| 3 | import os |
| 4 | from pathlib import Path |
| 5 | import shutil |
| 6 | import subprocess |
| 7 | import tempfile |
| 8 | import unittest |
| 9 | |
| 10 | ROOT = Path(__file__).resolve().parents[2] |
| 11 | |
| 12 | |
| 13 | class GateIntegrity(unittest.TestCase): |
| 14 | def setUp(self): |
| 15 | self.tmp = tempfile.TemporaryDirectory(prefix="omega-gate-control-") |
| 16 | self.root = Path(self.tmp.name) |
| 17 | self.addCleanup(self.tmp.cleanup) |
| 18 | subprocess.run(["git", "init", "-q", str(self.root)], check=True) |
| 19 | self.put("marker", "offline control\n") |
| 20 | self.git("add", "marker") |
| 21 | self.git("-c", "user.name=Offline Control", "-c", "user.email=control@example.invalid", |
| 22 | "commit", "-qm", "control") |
| 23 | |
| 24 | def git(self, *args): |
| 25 | return subprocess.run(["git", *args], cwd=self.root, check=True, |
| 26 | stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
| 27 | |
| 28 | def put(self, name, content, executable=False): |
| 29 | path = self.root / name |
| 30 | path.parent.mkdir(parents=True, exist_ok=True) |
| 31 | path.write_text(content) |
| 32 | if executable: |
| 33 | path.chmod(0o700) |
| 34 | return path |
| 35 | |
| 36 | def copy(self, name): |
| 37 | dest = self.root / name |
| 38 | dest.parent.mkdir(parents=True, exist_ok=True) |
| 39 | shutil.copy2(ROOT / name, dest) |
| 40 | |
| 41 | def invoke(self, *args): |
| 42 | return subprocess.run(args, cwd=self.root, capture_output=True, text=True, timeout=60) |
| 43 | |
| 44 | def secret_gate(self): |
| 45 | self.copy("tests/gates/run.sh") |
| 46 | return self.invoke("bash", "tests/gates/run.sh", "zero-disk-secrets") |
| 47 | |
| 48 | def test_clean_secret_control(self): |
| 49 | result = self.secret_gate() |
| 50 | self.assertEqual(result.returncode, 0, result.stdout + result.stderr) |
| 51 | self.assertIn("AIEN-OBS env_files_found false", result.stdout) |
| 52 | |
| 53 | def test_deep_secret(self): |
| 54 | self.put("a/b/c/d/e/space and\nnewline/.env.production", "not a credential\n") |
| 55 | self.assertNotEqual(self.secret_gate().returncode, 0) |
| 56 | |
| 57 | def test_long_positive_search(self): |
| 58 | for index in range(2000): |
| 59 | self.put(f"secrets/.env.{index:04d}." + "x" * 180, "control\n") |
| 60 | self.assertNotEqual(self.secret_gate().returncode, 0) |
| 61 | |
| 62 | def test_tracked_generated_secret(self): |
| 63 | self.put("build/output/.env.production", "control\n") |
| 64 | self.git("add", "-f", "build/output/.env.production") |
| 65 | self.assertNotEqual(self.secret_gate().returncode, 0) |
| 66 | |
| 67 | def test_search_failure(self): |
| 68 | bindir = self.root / "bin" |
| 69 | self.put("bin/find", "#!/bin/sh\nexit 2\n", executable=True) |
| 70 | self.copy("tests/gates/run.sh") |
| 71 | result = subprocess.run(["bash", "tests/gates/run.sh", "zero-disk-secrets"], |
| 72 | cwd=self.root, capture_output=True, text=True, |
| 73 | env={**os.environ, "PATH": str(bindir) + ":" + os.environ["PATH"]}) |
| 74 | self.assertNotEqual(result.returncode, 0) |
| 75 | |
| 76 | def regression_setup(self): |
| 77 | self.copy("seed/host/regression.sh") |
| 78 | self.copy("seed/rung4/om4.bin") |
| 79 | self.copy("seed/out/omc") |
| 80 | manifest = ROOT / "seed/host/original-fixtures.tsv" |
| 81 | if manifest.exists(): |
| 82 | self.copy("seed/host/original-fixtures.tsv") |
| 83 | paths = [line.split("\t")[0] for line in manifest.read_text().splitlines()] |
| 84 | else: |
| 85 | paths = ["seed/rung4/tests/echo.om"] |
| 86 | for name in paths: |
| 87 | self.copy(name) |
| 88 | self.git("add", "seed") |
| 89 | # Remaining corpus roots are also part of the committed baseline. |
| 90 | for name in ("tests", "tools"): |
| 91 | if (self.root / name).exists(): |
| 92 | self.git("add", name) |
| 93 | return paths |
| 94 | |
| 95 | def test_nonempty_regression_control(self): |
| 96 | self.regression_setup() |
| 97 | result = self.invoke("sh", "seed/host/regression.sh") |
| 98 | self.assertEqual(result.returncode, 0, result.stdout + result.stderr) |
| 99 | |
| 100 | def test_missing_baseline(self): |
| 101 | paths = self.regression_setup() |
| 102 | for name in paths: |
| 103 | (self.root / name).unlink() |
| 104 | self.assertNotEqual(self.invoke("sh", "seed/host/regression.sh").returncode, 0) |
| 105 | |
| 106 | def test_both_compilers_refuse(self): |
| 107 | self.regression_setup() |
| 108 | for name in ("seed/rung4/om4.bin", "seed/out/omc"): |
| 109 | self.put(name, "#!/bin/sh\ncat >/dev/null\nexit 9\n", executable=True) |
| 110 | self.assertNotEqual(self.invoke("sh", "seed/host/regression.sh").returncode, 0) |
| 111 | |
| 112 | def test_empty_manifest(self): |
| 113 | self.regression_setup() |
| 114 | self.put("seed/host/original-fixtures.tsv", "") |
| 115 | self.assertNotEqual(self.invoke("sh", "seed/host/regression.sh").returncode, 0) |
| 116 | |
| 117 | def test_duplicate_manifest(self): |
| 118 | self.regression_setup() |
| 119 | manifest = self.root / "seed/host/original-fixtures.tsv" |
| 120 | line = manifest.read_text().splitlines()[0] if manifest.exists() else "seed/rung4/tests/echo.om\t0" |
| 121 | self.put("seed/host/original-fixtures.tsv", (line + "\n") * 62) |
| 122 | self.assertNotEqual(self.invoke("sh", "seed/host/regression.sh").returncode, 0) |
| 123 | |
| 124 | def test_missing_ir_is_not_qualification(self): |
| 125 | self.copy("seed/host/check.sh") |
| 126 | self.copy("seed/out/omc") |
| 127 | self.put("seed/omega-from-seed.sh", "#!/bin/sh\ntouch rebuild-was-run\n") |
| 128 | for name in ("gate", "negative", "regression"): |
| 129 | self.put(f"seed/host/{name}.sh", "#!/bin/sh\nexit 0\n") |
| 130 | for name in ["gate-ir"] + [f"gate{i}" for i in range(7, 19)]: |
| 131 | self.put(f"seed/omc/{name}.sh", "#!/bin/sh\nexit 0\n") |
| 132 | result = self.invoke("sh", "seed/host/check.sh") |
| 133 | self.assertNotEqual(result.returncode, 0, result.stdout + result.stderr) |
| 134 | self.assertFalse((self.root / "rebuild-was-run").exists()) |
| 135 | self.assertNotIn("PASS native-host qualification", result.stdout) |
| 136 | |
| 137 | |
| 138 | if __name__ == "__main__": |
| 139 | unittest.main(verbosity=2) |