Something went wrong. Try again.
Personal fork of prime agent. Mirror of: https://mnemosyne.sigilzero.dev/sigilzero/prime-agent
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154#!/usr/bin/env python3"""Mock-only evidence guards. Never starts a product binary."""import copyimport unittestfrom unittest.mock import Mock, patch
from review_at_completion_parity import ( CASES, children_visible, close_terminal, compare, completion_rows, discover_direct, frame,)from review_dock_screen import DockScreen
def observations(): side = {'behavior_verified': True, 'cleanup_verified': True, 'inputs': ['40646972', '09'], 'frames': {'after': {'text': 'only_child.rs', 'menu_rows': ['only_child.rs'], 'children_visible': True}}} return {'runs': {kind: {'cases': {case: copy.deepcopy(side) for case in CASES}} for kind in ('ts', 'rust')}}
class EvidenceGuards(unittest.TestCase): def discovery(self, tag, argv, ownership=True): files = {'environ': Mock(), 'cmdline': Mock()} files['environ'].read_bytes.return_value = b'PA_GOAL_FIXTURE_ID=' + tag + b'\0' files['cmdline'].read_bytes.return_value = argv
class Entry: name = '42'
def __truediv__(self, key): return files[key]
scope = Mock(root='/case', direct={}, targets={}) scope.ownership.return_value = ownership with patch('review_at_completion_parity.Path') as proc, \ patch('review_at_completion_parity.process_identity', return_value=('proc:10', 'S')): proc.return_value.iterdir.return_value = [Entry()] discover_direct(scope, ['/binary', '--daemon-socket', '/case/fixture.sock']) return scope
def test_constructor_recovery_requires_exact_tag_and_argv(self): argv = b'/binary\0--daemon-socket\0/case/fixture.sock\0' self.assertEqual(self.discovery(b'/case', argv).targets, {42: 'proc:10'}) self.assertEqual(self.discovery(b'/other-case', argv).targets, {}) self.assertEqual(self.discovery(b'/case', b'/other-binary\0').targets, {})
def test_reused_identity_is_rejected_after_constructor_recovery(self): argv = b'/binary\0--daemon-socket\0/case/fixture.sock\0' scope = self.discovery(b'/case', argv, ownership=False) self.assertEqual((scope.targets, scope.direct), ({}, {}))
def test_editor_token_does_not_count_as_a_child_menu(self): text = '│ @"dir with spaces/only_child.rs"\nmodel · 0 tokens' self.assertFalse(children_visible(text)) self.assertEqual(completion_rows(text), [])
def test_actual_menu_row_counts_beside_quoted_editor(self): self.assertTrue(children_visible('› only_child.rs dir with spaces/only_child.rs\n' '│ @"dir with spaces/"'))
def test_directory_row_alone_is_not_a_child(self): self.assertFalse(children_visible('› dir with spaces/ dir with spaces\n│ @dir'))
def test_intended_ts_closed_menu_is_reported_without_normalization(self): receipt = observations() for case in CASES: receipt['runs']['ts']['cases'][case]['frames']['after'].update( children_visible=False, menu_rows=[], text='│ @"dir with spaces/"') result = compare(receipt) self.assertTrue(all(not row['ts_children_visible'] and row['rust_children_visible'] and not row['full_text_equal'] and not row['menu_rows_equal'] for row in result.values()))
def test_missing_rust_children_fails_even_when_other_phases_pass(self): receipt = observations() receipt['runs']['rust']['cases']['enter']['frames']['after']['children_visible'] = False with self.assertRaises(AssertionError): compare(receipt)
def test_unexecuted_case_cannot_pass(self): receipt = observations() receipt['runs']['ts']['cases']['tab']['behavior_verified'] = False with self.assertRaises(AssertionError): compare(receipt)
def test_failed_cleanup_cannot_pass(self): receipt = observations() receipt['runs']['rust']['cases']['typed_slash']['cleanup_verified'] = False with self.assertRaises(AssertionError): compare(receipt)
def test_caught_case_error_cannot_pass(self): receipt = observations() receipt['runs']['ts']['cases']['enter']['error'] = 'capture failed' with self.assertRaises(AssertionError): compare(receipt)
def test_different_keys_cannot_claim_comparison(self): receipt = observations() receipt['runs']['ts']['cases']['tab']['inputs'] = ['different'] with self.assertRaises(AssertionError): compare(receipt)
def test_unknown_terminal_geometry_cannot_pass_frame_evidence(self): screen = DockScreen() screen.feed(b'\x1b[3S') with self.assertRaises(AssertionError): frame(Mock(screen=screen, raw=bytearray()))
def test_cleanup_fallback_remains_red_and_joins_peer(self): terminal = Mock(raw=bytearray(), master=7) terminal.process.poll.return_value = None scope = Mock(targets={}) scope.live.return_value = [] server = Mock(commands=[], errors=[]) observed = {} with patch('review_at_completion_parity.discover_direct'), \ patch('review_at_completion_parity.time.monotonic', side_effect=[0, 20]), \ patch('review_at_completion_parity.os.close'): with self.assertRaisesRegex(AssertionError, 'ordinary TUI exit'): close_terminal(terminal, scope, server, observed) self.assertFalse(observed['cleanup_verified']) server.close.assert_called_once()
def test_peer_still_joins_when_pty_close_fails(self): terminal = Mock(raw=bytearray(), master=7) terminal.process.poll.return_value = 0 scope = Mock(targets={}) server = Mock(commands=[], errors=[]) observed = {} with patch('review_at_completion_parity.discover_direct'), \ patch('review_at_completion_parity.os.close', side_effect=OSError('close failed')): with self.assertRaisesRegex(AssertionError, 'PTY close'): close_terminal(terminal, scope, server, observed) self.assertFalse(observed['cleanup_verified']) server.close.assert_called_once()
def test_constructor_failure_still_discovers_and_rejects_live_owned_processes(self): scope = Mock(targets={}) scope.live.return_value = [] scope.wait_gone.side_effect = AssertionError('owned child survived') server = Mock(commands=[], errors=[]) observed = {} with patch('review_at_completion_parity.discover_direct') as discover: with self.assertRaisesRegex(AssertionError, 'owned child survived'): close_terminal(None, scope, server, observed) discover.assert_called_once() self.assertFalse(observed['cleanup_verified']) server.close.assert_called_once()
if __name__ == '__main__': unittest.main()