omega-mission
Omega Mission: seeded-Omega mission orchestrator (hash-chained journal, tiered command checks). Host-tested; live dispatch not yet run.
Brought by drakestapleton
omega-mission / tests / referee.py
| 1 | """Independent test referee only: subprocess observations, hashlib oracle, mutants. |
| 2 | No production behavior is implemented here. No network, worker, or GPU dispatch. |
| 3 | """ |
| 4 | import hashlib |
| 5 | import json |
| 6 | import os |
| 7 | from pathlib import Path |
| 8 | import shutil |
| 9 | import subprocess |
| 10 | import tempfile |
| 11 | |
| 12 | ROOT = Path(__file__).resolve().parent.parent |
| 13 | MV = Path(os.environ.get('OMEGA_MV', str(ROOT.parent / 'omega-mv'))).resolve() |
| 14 | HEAD = 'a' * 40 |
| 15 | OTHER = 'b' * 40 |
| 16 | cases = 0 |
| 17 | mutants = 0 |
| 18 | |
| 19 | |
| 20 | def run(argv, expected=0, label=None): |
| 21 | global cases |
| 22 | p = subprocess.run([str(x) for x in argv], capture_output=True, timeout=30) |
| 23 | assert p.returncode == expected, (label, argv, p.returncode, expected, p.stdout, p.stderr) |
| 24 | if label: |
| 25 | cases += 1 |
| 26 | print('PASS', label, flush=True) |
| 27 | return p |
| 28 | |
| 29 | |
| 30 | def text(path, data): |
| 31 | path.write_text(data) |
| 32 | return path |
| 33 | |
| 34 | |
| 35 | with tempfile.TemporaryDirectory(prefix='omega-mission-test-') as tmp: |
| 36 | T = Path(tmp) |
| 37 | # Exercise the installed entry point, not a different implementation. |
| 38 | run(['sh', ROOT / 'install.sh', T / 'opt', T / 'bin'], label='install') |
| 39 | M = T / 'bin/mission' |
| 40 | installed = (T / 'opt/mission').read_bytes() |
| 41 | run(['sh', ROOT / 'install.sh', T / 'opt', T / 'bin'], label='reinstall-same-bytes') |
| 42 | other = T / 'opt-other'; other.mkdir() |
| 43 | (other / 'mission').write_bytes(installed + b'\0') |
| 44 | run(['sh', ROOT / 'install.sh', other, T / 'bin'], 2, 'prefix-different-bytes') |
| 45 | assert M.resolve() == (T / 'opt/mission').resolve() |
| 46 | plainbin = T / 'plainbin'; plainbin.mkdir() |
| 47 | text(plainbin / 'mission', 'operator file\n') |
| 48 | run(['sh', ROOT / 'install.sh', T / 'opt', plainbin], 2, 'non-symlink-not-clobbered') |
| 49 | assert (plainbin / 'mission').read_text() == 'operator file\n' |
| 50 | fields = ['slice1', 'owner', 'reviewer', 'repo', 'src', '2,14', 'none', 'none', |
| 51 | 'build-run', HEAD, 'mission verify good.journal', |
| 52 | 'mission verify bad.journal', 'omc'] |
| 53 | mission = text(T / 'mission', '|'.join(fields) + '\n') |
| 54 | plan = run([M, 'plan', mission], label='plan-positive') |
| 55 | assert json.loads(plan.stdout)['verifier'] == 'reviewer' |
| 56 | for idx, value, label, rc in [ |
| 57 | (2, '', 'missing-verifier', 2), (2, 'owner', 'self-verifier', 2), |
| 58 | (2, 'OWNER', 'self-verifier-case', 2), |
| 59 | (5, '3', 'core3', 2), (5, '7', 'core7', 2), (5, '15', 'core15', 2), |
| 60 | (5, '2-4', 'forbidden-range', 2), (5, '14-12', 'descending-range', 2), |
| 61 | (6, 'gb10', 'gpu-no-lease', 2), (7, '', 'empty-lease', 2), |
| 62 | (12, 'git push', 'plan-push', 3), (12, 'git merge', 'plan-merge', 3), |
| 63 | (12, 'rad push', 'plan-rad-push', 3), (12, 'gh issue create', 'plan-gh-write', 3), |
| 64 | (12, 'sh -c touch', 'worker-shell', 3), (4, '../src', 'parent-path', 2), |
| 65 | (9, 'bad', 'short-head', 2), (8, 'publish', 'unknown-tier', 2), |
| 66 | (4, 'src,/etc', 'absolute-second-path', 2), |
| 67 | (4, 'src,', 'empty-last-path', 2), |
| 68 | (4, 'src,,other', 'empty-middle-path', 2), |
| 69 | (4, 'src,.git/hooks', 'git-metadata-path', 3), |
| 70 | (4, '.git', 'git-metadata-root', 3), |
| 71 | (10, 'git -c alias.p=push p origin', 'acceptance-alias-push', 3), |
| 72 | (10, 'git send-pack origin', 'acceptance-send-pack', 3), |
| 73 | (10, 'env rad patch', 'acceptance-env-rad', 3), |
| 74 | (11, 'sh -c x', 'negative-shell-string', 3), |
| 75 | (11, 'tests/../../bin/x', 'negative-parent-exec', 3), |
| 76 | (11, '/usr/bin/git status', 'negative-absolute-exec', 3), |
| 77 | (11, 'mission step j s MERGED p', 'negative-mission-step', 3), |
| 78 | ]: |
| 79 | bad = fields.copy(); bad[idx] = value |
| 80 | run([M, 'plan', text(T / 'bad', '|'.join(bad) + '\n')], rc, label) |
| 81 | run([M, 'plan', text(T / 'duplicate', mission.read_text() * 2)], 2, 'duplicate-id') |
| 82 | run([M, 'plan', text(T / 'partial', mission.read_text().rstrip())], 2, 'partial-mission') |
| 83 | repo_argv = fields.copy(); repo_argv[10] = 'sh tests/check.sh fixtures'; repo_argv[11] = 'tests/build/run --in lhs=a.bin' |
| 84 | run([M, 'plan', text(T / 'repo-argv', '|'.join(repo_argv) + '\n')], 0, 'verifier-repo-relative-argv') |
| 85 | nogpu = fields.copy(); nogpu[8] = 'lease' |
| 86 | nogpu[12] = 'spark-window open job --gb10 exclusive --quiet none --lease 5 --wait' |
| 87 | run([M, 'plan', text(T / 'bad', '|'.join(nogpu) + '\n')], 3, 'gpu-none-cannot-open-window') |
| 88 | # check binds the requested tier to a RUNNING slice's planned tier in a journal. |
| 89 | lease_f = fields.copy(); lease_f[0] = 'lslice'; lease_f[6:9] = ['gb10', 'spark-window-exclusive', 'lease'] |
| 90 | cmission = text(T / 'check-mission', '|'.join(fields) + '\n' + '|'.join(lease_f) + '\n') |
| 91 | CJ = T / 'check-journal' |
| 92 | ccl = text(T / 'check-claims', ''.join(f'| mission | {i} | owner | repo | src | 2,14 | active |\n' for i in ['slice1', 'lslice'])) |
| 93 | run([M, 'step', CJ, 'slice1', 'PROPOSED', cmission]) |
| 94 | run([M, 'step', CJ, 'lslice', 'PROPOSED', cmission]) |
| 95 | run([M, 'check', CJ, 'slice1', 'read-only', 'git', 'status'], 4, 'check-needs-running') |
| 96 | for sid, receipt in [('slice1', f'RUN slice1 owner {HEAD}\n'), ('lslice', f'RUN lslice owner {HEAD} fixture-lease-NOT-LIVE\n')]: |
| 97 | run([M, 'step', CJ, sid, 'CLAIMED', ccl]) |
| 98 | run([M, 'step', CJ, sid, 'RUNNING', text(T / 'check-run', receipt)]) |
| 99 | open_argv = ['spark-window', 'open', 'job', '--gb10', 'exclusive', '--quiet', 'none', '--lease', '5', '--wait'] |
| 100 | for sid, tier, command, rc, label in [ |
| 101 | ('slice1', 'read-only', ['git', 'status'], 0, 'read-git-status'), |
| 102 | ('slice1', 'read-only', ['touch', 'x'], 3, 'read-refuses-write'), |
| 103 | ('slice1', 'local-edit', ['touch', 'src/x'], 0, 'local-touch'), |
| 104 | ('slice1', 'local-edit', ['touch', 'x'], 3, 'touch-outside-paths'), |
| 105 | ('slice1', 'local-edit', ['mkdir', '/tmp/x'], 3, 'mkdir-absolute'), |
| 106 | ('slice1', 'local-edit', ['touch', 'src/../.git/hooks/pre-commit'], 3, 'touch-parent-escape'), |
| 107 | ('slice1', 'read-only', ['cat', 'src/a.om'], 0, 'cat-in-paths'), |
| 108 | ('slice1', 'read-only', ['cat', '/home/user/.config/gh/hosts.yml'], 3, 'cat-absolute-secret'), |
| 109 | ('slice1', 'read-only', ['cat', 'src/../../../etc/shadow'], 3, 'cat-parent-escape'), |
| 110 | ('slice1', 'read-only', ['cat', 'srcx/a'], 3, 'cat-sibling-prefix'), |
| 111 | ('slice1', 'local-edit', ['omc'], 3, 'local-refuses-build'), |
| 112 | ('slice1', 'build-run', ['omc'], 0, 'build-omc'), |
| 113 | ('slice1', 'read-only', ['git', '-c', 'alias.status=push', 'status'], 3, 'git-option-bypass'), |
| 114 | ('lslice', 'lease', ['sh', '-c', 'git push'], 3, 'shell-bypass'), |
| 115 | ('lslice', 'lease', ['/usr/bin/git', 'push'], 3, 'absolute-push'), |
| 116 | ('lslice', 'lease', ['git', 'push'], 3, 'lease-refuses-git-push'), |
| 117 | ('lslice', 'lease', ['rad', 'push'], 3, 'lease-refuses-rad-push'), |
| 118 | ('lslice', 'lease', ['gh', 'pr', 'merge'], 3, 'lease-refuses-gh-write'), |
| 119 | ('lslice', 'build-run', open_argv, 3, 'below-lease'), |
| 120 | ('lslice', 'lease', open_argv, 0, 'lease-admission-only'), |
| 121 | ('slice1', 'lease', open_argv, 3, 'tier-above-plan'), |
| 122 | ('lslice', 'lease', open_argv[:8] + ['1', '--wait'], 0, 'lease-min-1'), |
| 123 | ('lslice', 'lease', open_argv[:8] + ['20', '--wait'], 0, 'lease-max-20'), |
| 124 | ('lslice', 'lease', open_argv[:8] + ['0', '--wait'], 3, 'lease-zero'), |
| 125 | ('lslice', 'lease', open_argv[:8] + ['21', '--wait'], 3, 'lease-over-max'), |
| 126 | ('lslice', 'lease', open_argv[:8] + ['05', '--wait'], 3, 'lease-leading-zero'), |
| 127 | ('lslice', 'lease', open_argv[:8] + ['99999999', '--wait'], 3, 'lease-huge'), |
| 128 | ('nosuch', 'read-only', ['git', 'status'], 4, 'check-unknown-slice'), |
| 129 | ]: |
| 130 | run([M, 'check', CJ, sid, tier, *command], rc, label) |
| 131 | assert not (T / 'x').exists() |
| 132 | |
| 133 | dog = ROOT / 'missions/omega-factory-next.mission' |
| 134 | p = run([M, 'plan', dog], label='factory-plan') |
| 135 | rows = [json.loads(x) for x in p.stdout.decode().splitlines()] |
| 136 | assert [(r['id'], r['owner'], r['verifier'], r['head'][:8], r['cores']) for r in rows] == [ |
| 137 | ('DRA-454-import', 'HloImportOm', 'OmegaVerify455', '38b7d58d', '12-13'), |
| 138 | ('DRA-455-N1', 'Fix455b', 'OmegaVerify455', '38b7d58d', '12-13'), |
| 139 | ('DRA-455-repin', 'OmegaFactoryPjrt', 'OmegaVerifyPjrt', '427857ff', '16-18')], rows |
| 140 | assert all(r['gpu'] == 'gb10' and r['tier'] == 'lease' for r in rows) |
| 141 | lines = dog.read_text().splitlines() |
| 142 | for n, line in enumerate(lines): |
| 143 | owner = line.split('|')[1] |
| 144 | for idx, val, label in [(2, owner, 'factory-self-review'), |
| 145 | (2, owner.upper(), 'factory-self-review-case'), |
| 146 | (5, '7', 'factory-forbidden-core'), |
| 147 | (7, 'none', 'factory-no-lease')]: |
| 148 | bad = line.split('|'); bad[idx] = val |
| 149 | doc = lines[:n] + ['|'.join(bad)] + lines[n + 1:] |
| 150 | q = run([M, 'plan', text(T / 'dog-bad', '\n'.join(doc) + '\n')], 2, f'{label}-{n}') |
| 151 | assert q.stdout == b'', label |
| 152 | dup = [lines[0], lines[0].replace('HloImportOm', 'Fix455b', 1)] |
| 153 | q = run([M, 'plan', text(T / 'dog-bad', '\n'.join(dup) + '\n')], 2, 'factory-duplicate-id') |
| 154 | assert q.stdout == b'' |
| 155 | |
| 156 | def claim(owner='owner', state='active'): |
| 157 | return f'| mission | slice1 | {owner} | repo | src | 2,14 | {state} |\n' |
| 158 | |
| 159 | claims = text(T / 'CLAIMS.md', '# claims\n' + claim()) |
| 160 | running = text(T / 'running', f'RUN slice1 owner {HEAD}\n') |
| 161 | ready = text(T / 'ready', f'READY slice1 {HEAD} acceptance=0 negative=1\n') |
| 162 | verdict = text(T / 'verdict', f'VERDICT MERGE head={HEAD}\nreviewer=reviewer\n') |
| 163 | wrong = text(T / 'wrong-head', f'VERDICT MERGE head={OTHER}\nreviewer=reviewer\n') |
| 164 | selfreview = text(T / 'self-review', f'VERDICT MERGE head={HEAD}\nreviewer=owner\n') |
| 165 | merge = text(T / 'publish', f'| review.verdict.txt | repo | patchid | {HEAD} | {OTHER} | merged via abcdef12 (see Desk merges) | 2026-11-07 |\n') |
| 166 | J = T / 'journal' |
| 167 | run([M, 'step', J, 'slice1', 'PROPOSED', mission], label='proposed') |
| 168 | run([M, 'step', J, 'slice1', 'PROPOSED', mission], 5, 'repeat-proposed') |
| 169 | run([M, 'step', J, 'slice1', 'READY', ready], 4, 'skipped-state') |
| 170 | text(claims, claim('intruder')) |
| 171 | run([M, 'step', J, 'slice1', 'CLAIMED', claims], 4, 'wrong-claim') |
| 172 | text(claims, claim() + claim(state='released')) |
| 173 | run([M, 'step', J, 'slice1', 'CLAIMED', claims], 4, 'latest-release-wins') |
| 174 | text(claims, claim()) |
| 175 | run([M, 'step', J, 'slice1', 'CLAIMED', claims], label='claimed') |
| 176 | run([M, 'step', J, 'slice1', 'RUNNING', running], label='running') |
| 177 | run([M, 'step', J, 'slice1', 'READY', ready], label='ready') |
| 178 | readybytes = J.read_bytes() |
| 179 | run([M, 'step', J, 'slice1', 'VERIFIED', wrong], 4, 'wrong-verdict-head') |
| 180 | run([M, 'step', J, 'slice1', 'VERIFIED', selfreview], 4, 'owner-cannot-review') |
| 181 | assert J.read_bytes() == readybytes |
| 182 | run([M, 'step', J, 'slice1', 'VERIFIED', verdict], label='verified') |
| 183 | baseonly = text(T / 'baseonly', f'| {HEAD} | repo | patch | {OTHER} | {HEAD} | merged via abcdef12 (see Desk merges) | date |\n') |
| 184 | run([M, 'step', J, 'slice1', 'MERGED', baseonly], 4, 'publish-head-not-base') |
| 185 | wrongrepo = text(T / 'wrongrepo', f'| repo | another | patch | {HEAD} | {OTHER} | merged via abcdef12 (see Desk merges) | date |\n') |
| 186 | run([M, 'step', J, 'slice1', 'MERGED', wrongrepo], 4, 'publish-repo-column') |
| 187 | for status_cell, label in [('merged NOT', 'publish-status-prefix-only'), |
| 188 | ('merged via abcdef12 (see Desk merges) NOT', 'publish-status-trailing'), |
| 189 | ('merged via ABCDEF12 (see Desk merges)', 'publish-status-uppercase-sha'), |
| 190 | ('open', 'publish-status-open')]: |
| 191 | cell = text(T / 'status-cell', f'| review.verdict.txt | repo | patchid | {HEAD} | {OTHER} | {status_cell} | 2026-11-07 |\n') |
| 192 | run([M, 'step', J, 'slice1', 'MERGED', cell], 4, label) |
| 193 | run([M, 'step', J, 'slice1', 'MERGED', merge], label='radpublish-merged') |
| 194 | run([M, 'verify', J], label='replay') |
| 195 | status = run([M, 'status', J], label='status') |
| 196 | assert json.loads(status.stdout)['state'] == 'MERGED' |
| 197 | link = T / 'journal-link'; link.symlink_to(J) |
| 198 | linkbytes = J.read_bytes() |
| 199 | run([M, 'verify', link], 6, 'symlinked-journal-refused') |
| 200 | run([M, 'status', link], 6, 'symlinked-journal-status-refused') |
| 201 | run([M, 'step', link, 'slice1', 'MERGED', merge], 6, 'symlinked-journal-step-refused') |
| 202 | assert J.read_bytes() == linkbytes |
| 203 | missing = T / 'no-such-journal' |
| 204 | run([M, 'step', missing, 'slice1', 'CLAIMED', claims], 6, 'step-missing-journal') |
| 205 | run([M, 'resume', missing, 'slice1', 'next', claims], 6, 'resume-missing-journal') |
| 206 | assert not missing.exists() |
| 207 | # Independent chain oracle, including the complete previous line and own prefix checksum. |
| 208 | previous = b'0' * 64 |
| 209 | for line in J.read_bytes().splitlines(keepends=True): |
| 210 | prefix, checksum = line.rstrip(b'\n').rsplit(b'|', 1) |
| 211 | assert prefix.split(b'|')[0] == previous |
| 212 | assert hashlib.sha256(prefix + b'|').hexdigest().encode() == checksum |
| 213 | previous = hashlib.sha256(line).hexdigest().encode() |
| 214 | cases += 1; print('PASS independent-sha256-chain', flush=True) |
| 215 | damaged = bytearray(J.read_bytes()); damaged[70] ^= 1 |
| 216 | (T / 'tamper').write_bytes(damaged) |
| 217 | run([M, 'verify', T / 'tamper'], 5, 'tampered-journal') |
| 218 | (T / 'tail').write_bytes(J.read_bytes()[:-1]) |
| 219 | run([M, 'verify', T / 'tail'], 5, 'torn-tail') |
| 220 | # A maliciously rehashed illegal transition still fails state replay. |
| 221 | lines = J.read_bytes().splitlines() |
| 222 | changed = [] |
| 223 | previous = b'0' * 64 |
| 224 | for line in [lines[0], *lines[2:]]: |
| 225 | parts = line.split(b'|'); parts[0] = previous |
| 226 | prefix = b'|'.join(parts[:-1]) + b'|' |
| 227 | rebuilt = prefix + hashlib.sha256(prefix).hexdigest().encode() + b'\n' |
| 228 | changed.append(rebuilt); previous = hashlib.sha256(rebuilt).hexdigest().encode() |
| 229 | (T / 'skip-rehashed').write_bytes(b''.join(changed)) |
| 230 | run([M, 'verify', T / 'skip-rehashed'], 5, 'rehashed-skipped-state') |
| 231 | |
| 232 | # Handoff/restarter are fresh processes, using only journal+CLAIMS, installed path. |
| 233 | H = T / 'handoff'; H.write_bytes(readybytes) |
| 234 | text(claims, claim() + claim('next')) |
| 235 | run([M, 'resume', H, 'slice1', 'next', claims], 4, 'live-owner-handoff-refused') |
| 236 | text(claims, claim(state='released') + claim('reviewer')) |
| 237 | run([M, 'resume', H, 'slice1', 'reviewer', claims], 2, 'handoff-to-verifier-refused') |
| 238 | text(claims, claim(state='released') + claim('Reviewer')) |
| 239 | run([M, 'resume', H, 'slice1', 'Reviewer', claims], 2, 'handoff-to-verifier-case-refused') |
| 240 | text(claims, claim(state='released') + claim('next')) |
| 241 | run([M, 'resume', H, 'slice1', 'next', claims], label='released-owner-handoff') |
| 242 | s = run([M, 'status', H], label='restart-from-journal') |
| 243 | assert json.loads(s.stdout)['owner'] == 'next' |
| 244 | assert json.loads(s.stdout)['state'] == 'READY' |
| 245 | run([M, 'step', H, 'slice1', 'VERIFIED', verdict], label='new-owner-continues') |
| 246 | run([M, 'verify', H], label='handoff-chain-replays') |
| 247 | # Missing claims evidence and fake publication refuse. |
| 248 | run([M, 'step', H, 'slice1', 'MERGED', verdict], 4, 'merge-needs-publish-record') |
| 249 | # READY binds the produced head, not the initial checkout head. |
| 250 | changedhead = T / 'changedhead' |
| 251 | changedhead.write_bytes(b''.join(readybytes.splitlines(keepends=True)[:3])) |
| 252 | newready = text(T / 'newready', f'READY slice1 {OTHER} acceptance=0 negative=1\n') |
| 253 | run([M, 'step', changedhead, 'slice1', 'READY', newready], label='ready-produced-head') |
| 254 | run([M, 'step', changedhead, 'slice1', 'VERIFIED', verdict], 4, 'old-head-after-ready-refused') |
| 255 | run([M, 'step', changedhead, 'slice1', 'VERIFIED', wrong], label='produced-head-reviewed') |
| 256 | run([M, 'verify', changedhead], label='produced-head-replay') |
| 257 | |
| 258 | # GPU receipt must carry a lease identifier; this never opens a lease. |
| 259 | gpu = fields.copy(); gpu[6:9] = ['gb10', 'spark-window-exclusive', 'lease'] |
| 260 | gpufile = text(T / 'gpu-mission', '|'.join(gpu) + '\n') |
| 261 | G = T / 'gpu-journal' |
| 262 | run([M, 'step', G, 'slice1', 'PROPOSED', gpufile], label='gpu-plan-only') |
| 263 | text(claims, claim()) |
| 264 | run([M, 'step', G, 'slice1', 'CLAIMED', claims], label='gpu-claim-only') |
| 265 | run([M, 'step', G, 'slice1', 'RUNNING', running], 4, 'gpu-without-lease-receipt') |
| 266 | leased = text(T / 'leased', f'RUN slice1 owner {HEAD} fixture-lease-NOT-LIVE\n') |
| 267 | run([M, 'step', G, 'slice1', 'RUNNING', leased], label='gpu-receipt-fixture-only') |
| 268 | zero = text(T / 'zero-negative', f'READY slice1 {HEAD} acceptance=0 negative=0\n') |
| 269 | run([M, 'step', G, 'slice1', 'READY', zero], 4, 'negative-control-must-fail') |
| 270 | # DRA-455: failing receipts are journaled as terminal FAILED, never silently dropped. |
| 271 | runbytes = b''.join(readybytes.splitlines(keepends=True)[:3]) |
| 272 | for code in ['124', '127', '137', '139']: |
| 273 | F = T / f'failed-{code}'; F.write_bytes(runbytes) |
| 274 | badneg = text(T / 'fail-ready', f'READY slice1 {HEAD} acceptance=0 negative={code}\n') |
| 275 | run([M, 'step', F, 'slice1', 'READY', badneg], 4, f'negative-exit-{code}-recorded-failed') |
| 276 | assert json.loads(run([M, 'status', F]).stdout)['state'] == 'FAILED' |
| 277 | run([M, 'step', F, 'slice1', 'READY', ready], 4, 'no-ready-after-failed') |
| 278 | run([M, 'verify', F], label='failed-replays') |
| 279 | F = T / 'failed-acceptance'; F.write_bytes(runbytes) |
| 280 | accfail = text(T / 'acc-fail', f'READY slice1 {HEAD} acceptance=1 negative=1\n') |
| 281 | run([M, 'step', F, 'slice1', 'READY', accfail], 4, 'acceptance-failure-recorded') |
| 282 | assert json.loads(run([M, 'status', F]).stdout)['state'] == 'FAILED' |
| 283 | F = T / 'malformed-head'; F.write_bytes(runbytes) |
| 284 | upper = text(T / 'upper-head', f'READY slice1 {"A" * 40} acceptance=0 negative=1\n') |
| 285 | run([M, 'step', F, 'slice1', 'READY', upper], 2, 'malformed-head-not-a-failure') |
| 286 | assert F.read_bytes() == runbytes |
| 287 | R = T / 'rejected'; R.write_bytes(readybytes) |
| 288 | selfreject = text(T / 'self-reject', f'VERDICT REJECT head={HEAD}\nreviewer=owner\n') |
| 289 | run([M, 'step', R, 'slice1', 'VERIFIED', selfreject], 4, 'owner-reject-not-recorded') |
| 290 | assert R.read_bytes() == readybytes |
| 291 | reject = text(T / 'reject', f'VERDICT REJECT head={HEAD}\nreviewer=reviewer\n') |
| 292 | run([M, 'step', R, 'slice1', 'VERIFIED', reject], 4, 'reject-recorded-failed') |
| 293 | assert json.loads(run([M, 'status', R]).stdout)['state'] == 'FAILED' |
| 294 | run([M, 'step', R, 'slice1', 'VERIFIED', verdict], 4, 'no-merge-verdict-after-reject') |
| 295 | text(claims, claim(state='released') + claim('next')) |
| 296 | run([M, 'resume', R, 'slice1', 'next', claims], 4, 'no-handoff-after-failed') |
| 297 | run([M, 'verify', R], label='reject-replays') |
| 298 | |
| 299 | second = fields.copy(); second[0] = 'slice2' |
| 300 | multifile = text(T / 'multi', mission.read_text() + '|'.join(second) + '\n') |
| 301 | result = run([M, 'plan', multifile], label='multi-slice-plan') |
| 302 | assert len(result.stdout.splitlines()) == 2 |
| 303 | multi = T / 'multi-journal' |
| 304 | run([M, 'step', multi, 'slice1', 'PROPOSED', multifile], label='multi-first') |
| 305 | run([M, 'step', multi, 'slice2', 'PROPOSED', multifile], label='multi-second') |
| 306 | result = run([M, 'status', multi], label='multi-status') |
| 307 | assert {json.loads(x)['id'] for x in result.stdout.splitlines()} == {'slice1', 'slice2'} |
| 308 | |
| 309 | # Each chain check is necessary on its own: an unrehashed swap of independent events |
| 310 | # breaks only the previous-line link; an edit to the last event whose evidence stays valid |
| 311 | # breaks only that event's own checksum. |
| 312 | a, b = multi.read_bytes().splitlines(keepends=True) |
| 313 | swapped = T / 'swapped'; swapped.write_bytes(b + a) |
| 314 | run([M, 'verify', swapped], 5, 'unrehashed-independent-swap') |
| 315 | last = readybytes.splitlines(keepends=True) |
| 316 | old_ev, new_ev = b'negative=1'.hex().encode(), b'negative=2'.hex().encode() |
| 317 | assert last[-1].count(old_ev) == 1 |
| 318 | edited = T / 'edited-last'; edited.write_bytes(b''.join(last[:-1]) + last[-1].replace(old_ev, new_ev)) |
| 319 | run([M, 'verify', edited], 5, 'edited-last-valid-evidence') |
| 320 | |
| 321 | # Semantic guard mutants, all must compile, then violate a negative test. |
| 322 | src = (ROOT / 'journal.om').read_text() |
| 323 | def order_journal(mj): |
| 324 | mj.write_bytes(J.read_bytes().splitlines(keepends=True)[0]) |
| 325 | return ['step', mj, 'slice1', 'READY', ready] |
| 326 | def verified_with(ev): |
| 327 | def setup(mj): |
| 328 | mj.write_bytes(readybytes) |
| 329 | return ['step', mj, 'slice1', 'VERIFIED', ev] |
| 330 | return setup |
| 331 | mutations = [ |
| 332 | ('reviewer', 'wadd reviewer\nwfield 2\nexact', 'wadd reviewer\nwfield 1\nexact', verified_with(selfreview)), |
| 333 | ('head', 'wfield 9\nwadd reviewer', 'wadd badhead\nwadd reviewer', verified_with(wrong)), |
| 334 | ('order', 'if ne st add get states s 1\ndie 4\nend', 'if false\ndie 4\nend', order_journal), |
| 335 | ('chainlink', 'if ne get jb i get prev i\ndie 5', 'if false\ndie 5', lambda mj: ['verify', swapped]), |
| 336 | ('selfsum', 'if ne get jb add get jo 5 i get digest i\ndie 5', 'if false\ndie 5', lambda mj: ['verify', edited]), |
| 337 | ] |
| 338 | for name, old, new, setup in mutations: |
| 339 | assert src.count(old) == 1, name |
| 340 | altered = src.replace(old, new, 1) |
| 341 | if name == 'head': |
| 342 | altered = 'text badhead "' + OTHER + '"\n' + altered |
| 343 | if name == 'order': |
| 344 | altered = altered.replace('if ne st add get states s 1\ndie 5\nend', 'if false\ndie 5\nend', 1) |
| 345 | composed = 'om2\n' + (ROOT / 'sha.om').read_text() + (ROOT / 'mission.om').read_text() + altered |
| 346 | mutant = T / ('mutant-' + name) |
| 347 | c = subprocess.run([MV / 'seed/out/omc'], input=composed.encode(), capture_output=True, timeout=90) |
| 348 | assert c.returncode == 0, (name, c.stderr) |
| 349 | mutant.write_bytes(c.stdout); mutant.chmod(0o755) |
| 350 | # Baseline refuses; broken implementation accepts, so the negative assertion catches it. |
| 351 | run([mutant, *setup(T / ('journal-' + name))], 0) |
| 352 | mutants += 1 |
| 353 | print('MUTANT_CAUGHT', name, flush=True) |
| 354 | |
| 355 | print(f'HOST_TESTED cases={cases} mutants_caught={mutants} live_dispatch=NOT_RUN') |