Skip to content

armgit / cua

Public Imported from GitHub
0

Scale computer-use 2.0 with open-source drivers, cross-OS sandboxes, and benchmarks for training, evaluation, and data generation.

test(hyprland-plugin): share proof fixtures and prune replayed checks (#4124)

Francesco Bonacci5fb2558ea162
diff --git a/libs/cua-driver/hyprland-plugin/tests/README.md b/libs/cua-driver/hyprland-plugin/tests/README.md
index 1aa3b64c0b..5891ce430a 100644
--- a/libs/cua-driver/hyprland-plugin/tests/README.md
+++ b/libs/cua-driver/hyprland-plugin/tests/README.md
@@ -408,3 +408,24 @@ unload command separately; none is application mutation proof. Likewise,
individual `cua-driver call` requests are driver-side tests, not plugin
capabilities. They may be exercised to diagnose an agent integration, but
must not appear in the plugin capability result.
+
+## Portable harness test ownership
+
+The `*_test.py` suites run in hosted CI with every native boundary mocked. Keep
+them cheap to trust:
+
+- Put shared plans, trace pages, status builders, and UI snapshots in
+ `proof_fixtures.py`. Never import one `*_test.py` from another or borrow a
+ `TestCase` as a helper. Proofs that hash their own tests into
+ `provenance.json` also hash `proof_fixtures.py`; update those lists when a
+ test file is added, renamed, or removed.
+- Test a shared helper once, at its owner: `trace_interval` in
+ `production_realapp_proof_test.py`, `primary_trace.analyze` in
+ `primary_trace_test.py`, `validate_app_profile` and
+ `verify_fresh_observation` in `production_cancel_proof_test.py`, and
+ `verify_status` and `validate_min_motion` in
+ `production_desktop_fault_proof_test.py`. A consumer keeps one case that
+ proves it calls the helper.
+- Give every negative row the error it must raise. A bare
+ `assertRaises(AssertionError)` also passes when an earlier, unrelated guard
+ fails.
diff --git a/libs/cua-driver/hyprland-plugin/tests/primary_observer.py b/libs/cua-driver/hyprland-plugin/tests/primary_observer.py
index 4a67d65dce..acb0dfd1f1 100644
--- a/libs/cua-driver/hyprland-plugin/tests/primary_observer.py
+++ b/libs/cua-driver/hyprland-plugin/tests/primary_observer.py
@@ -162,14 +162,17 @@ def analyze(before, after, journal, wire, intervals, primary_before, primary_aft
"""An incomplete observation raises; a complete observation can fail isolation."""
assert before['identity'] == after['identity'], 'observer identity changed'
start, end = before['marker'], after['marker']
- assert start['kind'] == end['kind'] == 'sync' and start['nonce'] != end['nonce']
- assert start['time'] < end['time'] and end['time'] - start['time'] <= MAX_INTERVAL_NS
+ assert start['kind'] == end['kind'] == 'sync' and start['nonce'] != end['nonce'], 'sync markers are not distinct'
+ assert start['time'] < end['time'] and end['time'] - start['time'] <= MAX_INTERVAL_NS, \
+ 'observer interval is empty or exceeds its bound'
assert journal[start['seq'] - 1] == start and journal[end['seq'] - 1] == end, 'sync marker journal mismatch'
assert end['seq'] == len(journal), 'end marker is not the final retained journal row'
- assert 0 <= start['wire_start'] < start['wire_end'] <= end['wire_start'] < end['wire_end'] == len(wire)
+ assert 0 <= start['wire_start'] < start['wire_end'] <= end['wire_start'] < end['wire_end'] == len(wire), \
+ 'sync markers do not bracket the wire log'
sync_barrier(wire[start['wire_start']:start['wire_end']])
sync_barrier(wire[end['wire_start']:end['wire_end']])
- assert start['held'] is True and start['buttons'] == [1] and not start['keys_down']
+ assert start['held'] is True and start['buttons'] == [1] and not start['keys_down'], \
+ 'observer baseline lacks the held primary grab'
assert start['window_active'] is True and start['canvas_focus'] is True, 'foreground fixture is not focused'
assert intervals and all(start['time'] <= begin < finish <= end['time'] for begin, finish in intervals), \
'observer does not cover the complete action/control interval'
diff --git a/libs/cua-driver/hyprland-plugin/tests/primary_trace_test.py b/libs/cua-driver/hyprland-plugin/tests/primary_trace_test.py
index b185ba7a48..21f919c179 100644
--- a/libs/cua-driver/hyprland-plugin/tests/primary_trace_test.py
+++ b/libs/cua-driver/hyprland-plugin/tests/primary_trace_test.py
@@ -2,17 +2,7 @@ import unittest
import copy
from unittest.mock import Mock, patch
from primary_trace import Trace, analyze
-
-
-def trace(*events):
- rows = [[i + 1, i * 1_000_000, kind, x, y, actor, state]
- for i, (kind, x, y, actor, state) in enumerate(events)]
- return dict(hook=True, active=False, overflow=False, timed_out=False,
- count=len(rows), events=rows)
-
-
-START = ('start', 100, 200, 0, 0)
-STOP = ('stop', 100, 200, 0, 0)
+from proof_fixtures import START, STOP, primary_trace as trace
class TraceTest(unittest.TestCase):
@@ -139,7 +129,8 @@ class TraceTest(unittest.TestCase):
self.assertEqual(analyze(bad)['result'], 'inconclusive')
def test_primary_focus_keys_and_releases_fail(self):
- for kind in ('pointer_focus', 'keyboard_enter', 'keyboard_key', 'pointer_button'):
+ for kind in ('pointer_focus', 'keyboard_focus', 'keyboard_enter', 'keyboard_key',
+ 'pointer_button', 'pointer_axis'):
self.assertEqual(analyze(trace(START, (kind, 100, 200, 0, 0), STOP))['result'], 'failed')
def test_real_overlap_is_measured_from_dispatch_not_animation(self):
@@ -150,9 +141,14 @@ class TraceTest(unittest.TestCase):
self.assertEqual(result['agent_drag_overlap_ms'], 1)
def test_controlled_motion_must_match_every_command_in_order(self):
- data = trace(START, ('cursor', 120, 200, 0, 0), ('cursor', 100, 200, 0, 0), STOP)
- self.assertEqual(analyze(data, expected_motion=[[120, 200], [100, 200]])['result'], 'passed')
- self.assertEqual(analyze(data, expected_motion=[[100, 200]])['result'], 'failed')
+ route = [[120, 200], [100, 200]]
+ events = [('cursor', *point, 0, 0) for point in route]
+ self.assertEqual(analyze(trace(START, *events, STOP), expected_motion=route)['result'], 'passed')
+ self.assertEqual(analyze(trace(START, *events, STOP), expected_motion=[[100, 200]])['result'], 'failed')
+ for rows in (events[:1], list(reversed(events)), [events[0], ('cursor', 150, 200, 0, 0), events[1]],
+ [events[0], ('pointer_axis', 120, 200, 0, 0), events[1]]):
+ with self.subTest(rows=rows):
+ self.assertEqual(analyze(trace(START, *rows, STOP), expected_motion=route)['result'], 'failed')
def test_controlled_motion_reconciles_all_observed_positions(self):
moved = ('cursor', 120, 200, 0, 0)
diff --git a/libs/cua-driver/hyprland-plugin/tests/production_active_lock_proof.py b/libs/cua-driver/hyprland-plugin/tests/production_active_lock_proof.py
index aa8b77d357..07da0b8654 100644
--- a/libs/cua-driver/hyprland-plugin/tests/production_active_lock_proof.py
+++ b/libs/cua-driver/hyprland-plugin/tests/production_active_lock_proof.py
@@ -295,7 +295,7 @@ def run(args):
policy = pointer_cleanup(fixture.config)
origin = provenance(args, plan)
for name in (Path(__file__).name, 'production_active_lock_proof_test.py',
- 'production_lock_refusal_proof.py', 'production_lock_refusal_proof_test.py',
+ 'production_lock_refusal_proof.py', 'production_lock_refusal_proof_test.py', 'proof_fixtures.py',
'session_lock_fixture.c', 'production_session_fault_proof.py',
'production_desktop_fault_proof.py', 'production_cancel_proof.py', 'desktop_faults.py'):
path = Path(__file__).with_name(name)
diff --git a/libs/cua-driver/hyprland-plugin/tests/production_active_lock_proof_test.py b/libs/cua-driver/hyprland-plugin/tests/production_active_lock_proof_test.py
index afe2e00670..0fbac940f5 100644
--- a/libs/cua-driver/hyprland-plugin/tests/production_active_lock_proof_test.py
+++ b/libs/cua-driver/hyprland-plugin/tests/production_active_lock_proof_test.py
@@ -12,8 +12,7 @@ from unittest.mock import Mock, patch
import production_active_lock_proof as proof
import production_lock_refusal_proof as settled
-from production_lock_refusal_proof_test import plan as lock_plan
-from production_session_fault_proof_test import ACTIVE, CANCEL, PARTIAL, status, trace, retained_status, motion_gate
+from proof_fixtures import ACTIVE, CANCEL, PARTIAL, ink, inkscape_profile, lock_plan, motion_gate, retained_status, status, trace
def plan():
@@ -37,7 +36,45 @@ def record():
'gate_status': status(1, held=True), 'after': status(2)}
+def ready_fixture():
+ """An armed lock helper that reported ready and has not been asked to lock."""
+ fixture = object.__new__(proof.ActiveLockFixture)
+ fixture.child = Mock(stdin=io.BytesIO(), poll=Mock(return_value=None))
+ fixture.record = {'before': status(1), 'ready': {'event': 'ready', 'observed_ns': 1}}
+ fixture.config = {}
+ fixture.requested = False
+ fixture.check_targets = Mock()
+ fixture.check_binary = Mock()
+ fixture.check_running_binary = Mock()
+ fixture.locked = Mock()
+ fixture.event = Mock(return_value={'event': 'locked', 'observed_ns': 7_000_000})
+ return fixture
+
+
class OracleTests(unittest.TestCase):
+ def test_inkscape_only_profile_reaches_the_shared_app_profile_gate(self):
+ candidate = {**inkscape_profile(plan()), 'recovery': {'pointer_stages': ['scroll_down', 'scroll_up']}}
+ proof.validate_plan(candidate)
+ candidate['agents'][0]['document'] = '/synthetic/private.svg'
+ with self.assertRaisesRegex(AssertionError, 'absolute synthetic SVG document'):
+ proof.validate_plan(candidate)
+
+ def test_scroll_recovery_uses_existing_pixel_and_semantic_oracle(self):
+ before, pixels = ink()
+ before.update(proof_image='synthetic.png', proof_observation_started_ns=1)
+ spec = {'app': 'inkscape', 'name': 'recovery', 'target': {'pid': 20, 'window_id': 200},
+ 'pointer_stage': 'move_rectangle'}
+ with patch.object(proof, 'grounded_snapshot', return_value=before), \
+ patch.object(proof.pointer_grounding, 'read_pixels', return_value=pixels):
+ prepared = proof.prepare_recovery(Mock(), spec, ['scroll_down', 'scroll_up'])
+ self.assertIn(prepared['stage'], ('scroll_down', 'scroll_up'))
+ self.assertEqual(prepared['prepared_ns'], 1)
+ with self.assertRaises(AssertionError):
+ proof.pointer_grounding.verify(before, pixels, prepared['oracle'])
+ shift = -10 if prepared['stage'] == 'scroll_down' else 10
+ after, moved = ink(scroll_y=shift)
+ self.assertTrue(proof.pointer_grounding.verify(after, moved, prepared['oracle'])['verified'])
+
def test_recovery_grounding_uses_original_snapshot_time_not_wrapper_clock(self):
client = Mock()
spec = plan()['agents'][0]
@@ -141,12 +178,9 @@ class OracleTests(unittest.TestCase):
proof.verify_cancelled(trace(ACTIVE + tail), record(), action())
def test_incomplete_trace_rewritten_history_or_missing_held_prefix_fail(self):
- for field, value in (('overflow', True), ('timed_out', True), ('hook', False),
- ('active', False), ('count', 100)):
- page = trace(CANCEL)
- page[field] = value
- with self.subTest(field=field), self.assertRaises(AssertionError):
- proof.verify_cancelled(page, record(), action())
+ # Page validity is owned by trace_interval (realapp TraceIntervalTests); one case proves wiring.
+ with self.assertRaisesRegex(AssertionError, 'dropped events'):
+ proof.verify_cancelled({**trace(CANCEL), 'overflow': True}, record(), action())
for mutation in ('history', 'press', 'admitted', 'start'):
candidate, page = record(), trace(CANCEL)
if mutation == 'history':
@@ -221,21 +255,12 @@ class OracleTests(unittest.TestCase):
class FixtureTests(unittest.TestCase):
- def fixture(self):
- fixture = object.__new__(proof.ActiveLockFixture)
- fixture.child = Mock(stdin=io.BytesIO(), poll=Mock(return_value=None))
- fixture.record = {'before': status(1), 'ready': {'event': 'ready', 'observed_ns': 1}}
- fixture.config = {}
- fixture.requested = False
- fixture.check_targets = Mock()
- fixture.check_binary = Mock()
- fixture.check_running_binary = Mock()
- fixture.locked = Mock()
- fixture.event = Mock(return_value={'event': 'locked', 'observed_ns': 7_000_000})
- return fixture
+ def test_active_fixture_reuses_the_settled_lock_restore_and_binary_checks(self):
+ self.assertIs(proof.ActiveLockFixture.restore, settled.LockFixture.restore)
+ self.assertIs(proof.ActiveLockFixture.check_running_binary, settled.LockFixture.check_running_binary)
def test_injection_sends_one_lock_only_after_exact_identity_and_fresh_held_gate(self):
- fixture = self.fixture()
+ fixture = ready_fixture()
pending = Mock(done=Mock(return_value=False))
with patch.object(proof, 'power'), \
patch.object(proof, 'production_status', side_effect=[status(1, held=True), status(2)]), \
@@ -253,7 +278,7 @@ class FixtureTests(unittest.TestCase):
def test_finished_stale_changed_identity_or_nonheld_drag_never_sends_lock(self):
for failure in ('finished', 'stale_trace', 'stale_status', 'ready_expired',
'not_held', 'target', 'binary', 'running_binary', 'generation'):
- fixture = self.fixture()
+ fixture = ready_fixture()
pending = Mock(done=Mock(return_value=failure == 'finished'))
gate = status(1, held=failure != 'not_held')
if failure == 'generation':
@@ -278,7 +303,7 @@ class FixtureTests(unittest.TestCase):
self.assertFalse(fixture.requested)
def test_lost_lock_ack_keeps_requested_state_for_graceful_cleanup(self):
- fixture = self.fixture()
+ fixture = ready_fixture()
fixture.event.side_effect = TimeoutError('lost acknowledgement')
with patch.object(proof, 'power'), \
patch.object(proof, 'production_status', return_value=status(1, held=True)), \
@@ -289,11 +314,9 @@ class FixtureTests(unittest.TestCase):
self.assertTrue(fixture.requested)
self.assertEqual(fixture.child.stdin.getvalue(), b'LOCK\n')
self.assertNotEqual(fixture.record.get('result'), 'acknowledged')
- self.assertIs(proof.ActiveLockFixture.restore, settled.LockFixture.restore)
- self.assertIs(proof.ActiveLockFixture.check_running_binary, settled.LockFixture.check_running_binary)
def test_arm_does_not_lock_and_binds_running_helper_after_ready(self):
- fixture = self.fixture()
+ fixture = ready_fixture()
fixture.child = None
child = Mock(pid=99)
identity = {'pid': 99, 'uid': 1000, 'exe': '/test/session_lock_fixture', 'starttime': '1'}
@@ -507,28 +530,31 @@ class RunTests(unittest.TestCase):
self.assertIn('failed-transition-trace.json', evidence)
-class RetainedPointerTests(unittest.TestCase):
def test_full_retained_episode_checks_unlock_and_pre_recovery_presence(self):
- result, evidence, events, clients = RunTests().episode(retained=True)
+ result, evidence, events, clients = self.episode(retained=True)
self.assertEqual(result, 0, evidence['result.json'])
self.assertEqual(evidence['result.json']['continuous_isolation_across_transitions'], 'unproven')
self.assertLess(events.index('explicit_unlock'), events.index('launch_50'))
for failure in ('unlock_leave', 'lost_presence'):
- result, evidence, events, clients = RunTests().episode(failure, retained=True)
+ result, evidence, events, clients = self.episode(failure, retained=True)
with self.subTest(failure=failure):
self.assertEqual(result, 1)
self.assertNotIn('launch_50', events)
self.assertEqual(evidence['result.json']['recovery']['result'], 'unproven')
+
+class RetainedPointerTests(unittest.TestCase):
def test_active_lock_accepts_opt_in_motion_and_cleanup_only(self):
value = plan()
value['fault'].update(pointer_cleanup='retained_inert', min_motion_px=12.5)
proof.validate_plan(value)
- for change in ({'pointer_cleanup': 'unknown'}, {'extra': True},
- *({'min_motion_px': v} for v in (None, True, 0, -1, float('inf'), float('nan')))):
+ # Policy and threshold validity are owned by desktop_fault; one case each proves wiring.
+ for change, error in (({'pointer_cleanup': 'unknown'}, 'unknown pointer cleanup policy'),
+ ({'extra': True}, 'unsupported fault option'),
+ ({'min_motion_px': 0}, 'positive finite min_motion_px')):
bad = deepcopy(value)
bad['fault'].update(change)
- with self.subTest(change=change), self.assertRaises(AssertionError):
+ with self.subTest(change=change), self.assertRaisesRegex(AssertionError, error):
proof.validate_plan(bad)
def test_retained_cancellation_both_lanes_is_not_transition_isolation(self):
@@ -563,7 +589,7 @@ class RetainedPointerTests(unittest.TestCase):
def test_motion_poll_preserves_short_ready_window_and_brackets_status(self):
for failure in (None, 'insufficient', 'lane', 'stale'):
- fixture = FixtureTests().fixture()
+ fixture = ready_fixture()
fixture.config.update(pointer_cleanup='retained_inert', min_motion_px=12)
fixture.record.update(pointer_cleanup='retained_inert', min_motion_px=12)
value = record()
diff --git a/libs/cua-driver/hyprland-plugin/tests/production_active_primary_proof.py b/libs/cua-driver/hyprland-plugin/tests/production_active_primary_proof.py
index 9867a1f9a2..b55f143ed9 100644
--- a/libs/cua-driver/hyprland-plugin/tests/production_active_primary_proof.py
+++ b/libs/cua-driver/hyprland-plugin/tests/production_active_primary_proof.py
@@ -418,7 +418,7 @@ def run(args):
app_process_identity(spec['app'], spec['target']['pid'])
origin = provenance(args, plan)
for name in (Path(__file__).name, 'production_active_primary_proof_test.py',
- 'primary_hover_fixture.c', 'primary_hover_fixture_test.py',
+ 'primary_hover_fixture.c', 'primary_hover_fixture_test.py', 'proof_fixtures.py',
'production_active_lock_proof.py', 'production_primary_conflict_proof.py',
'production_desktop_fault_proof.py', 'production_session_fault_proof.py'):
path = Path(__file__).with_name(name)
diff --git a/libs/cua-driver/hyprland-plugin/tests/production_active_primary_proof_test.py b/libs/cua-driver/hyprland-plugin/tests/production_active_primary_proof_test.py
index ba808bd803..4db568c186 100644
--- a/libs/cua-driver/hyprland-plugin/tests/production_active_primary_proof_test.py
+++ b/libs/cua-driver/hyprland-plugin/tests/production_active_primary_proof_test.py
@@ -9,8 +9,7 @@ import unittest
from unittest.mock import Mock, patch
import production_active_primary_proof as proof
-from production_primary_conflict_proof_test import plan as settled_plan
-from production_session_fault_proof_test import ACTIVE, CANCEL, PARTIAL, status, trace
+from proof_fixtures import ACTIVE, CANCEL, PARTIAL, inkscape_profile, primary_conflict_plan as settled_plan, status, trace
def plan():
@@ -49,6 +48,13 @@ def action():
class OracleTests(unittest.TestCase):
+ def test_inkscape_only_profile_reaches_the_shared_app_profile_gate(self):
+ candidate = {**inkscape_profile(plan()), 'recovery': {'pointer_stages': ['scroll_down', 'scroll_up']}}
+ proof.validate_plan(candidate)
+ candidate['agents'][0]['document'] = '/synthetic/private.svg'
+ with self.assertRaisesRegex(AssertionError, 'absolute synthetic SVG document'):
+ proof.validate_plan(candidate)
+
def test_parked_foreground_accepts_new_observation_time_only(self):
before = {'kind': 'state', 'time': 10, 'clicks': 2, 'keys': '',
'scroll': 0, 'motion': 4, 'held': False}
@@ -99,26 +105,21 @@ class OracleTests(unittest.TestCase):
self.verify(fault=fault)
def test_raw_primary_transition_is_never_filtered_or_relabelled_as_isolation(self):
- for kind in ('cursor', 'pointer_focus', 'keyboard_focus', 'pointer_button', 'keyboard_key'):
- page = boundary()
- row = [len(page['events']) + 1, 13_000_000, kind, 100, 100, 0, 0]
- if kind == 'cursor':
- row[3] += 10
- page['events'].append(row)
- page['count'] += 1
- original = deepcopy(page)
- result = proof.transition_evidence(page)
- self.assertEqual(result['raw_primary_analysis']['result'], 'failed')
- self.assertEqual(result['continuous_primary_isolation'], 'unproven')
- self.assertEqual(page, original)
- self.assertEqual(self.verify(page=page)['result'], 'verified')
+ # Which primary rows fail is primary_trace_test's contract; this one keeps the raw result.
+ page = boundary()
+ page['events'].append([len(page['events']) + 1, 13_000_000, 'keyboard_focus', 100, 100, 0, 0])
+ page['count'] += 1
+ original = deepcopy(page)
+ result = proof.transition_evidence(page)
+ self.assertEqual(result['raw_primary_analysis']['result'], 'failed')
+ self.assertEqual(result['continuous_primary_isolation'], 'unproven')
+ self.assertEqual(page, original)
+ self.assertEqual(self.verify(page=page)['result'], 'verified')
def test_incomplete_trace_bad_history_and_preexisting_primary_changes_fail(self):
- for field, value in (('overflow', True), ('hook', False), ('timed_out', True), ('active', False), ('count', 99)):
- page = boundary()
- page[field] = value
- with self.subTest(field=field), self.assertRaises(AssertionError):
- self.verify(page=page)
+ # Page validity is owned by trace_interval (realapp TraceIntervalTests); one case proves wiring.
+ with self.assertRaisesRegex(AssertionError, 'dropped events'):
+ self.verify(page={**boundary(), 'overflow': True})
page = boundary()
page['events'][0][1] += 1
with self.assertRaises(AssertionError):
@@ -220,12 +221,12 @@ class OracleTests(unittest.TestCase):
candidate = plan()
candidate['fault']['min_motion_px'] = 12
proof.validate_plan(candidate)
- for value in (True, 0, -1, float('inf'), float('nan'), '12'):
- with self.subTest(value=value), self.assertRaises(AssertionError):
- proof.validate_plan({**candidate, 'fault': {'kind': 'primary_hover', 'min_motion_px': value}})
+ # Threshold validity is owned by desktop_fault's MotionGateTests; one value proves wiring.
+ with self.assertRaisesRegex(AssertionError, 'positive finite min_motion_px'):
+ proof.validate_plan({**candidate, 'fault': {'kind': 'primary_hover', 'min_motion_px': 0}})
fault = record()
fault.update(min_motion_px=12, gate_first=deepcopy(fault['prefix']))
- with self.assertRaises(AssertionError):
+ with self.assertRaisesRegex(AssertionError, 'motion gate requires surface coordinates'):
self.verify(fault=fault)
def test_two_sample_path_requires_both_exact_observed_movements(self):
@@ -265,14 +266,6 @@ class OracleTests(unittest.TestCase):
with self.subTest(mutation=mutation), self.assertRaises(AssertionError):
self.verify(page=bad_page, fault=bad_fault)
- def test_recovery_chooses_effective_stage_from_current_selection(self):
- before = {'snapshot_id': 'new-after-cancellation'}
- for b2, stage in ((True, 'click_a1'), (False, 'click_b2')):
- with patch.object(proof.pointer_grounding, 'rows', return_value=['fresh']), \
- patch.object(proof.pointer_grounding, 'calc_formula_selection', return_value=b2) as selection:
- self.assertEqual(proof.recovery_stage(before), stage)
- selection.assert_called_once_with(before, ['fresh'], 'B2')
-
def test_invalid_plan_writes_failed_evidence_without_native_actions(self):
with tempfile.TemporaryDirectory() as directory:
root = Path(directory)
@@ -313,16 +306,13 @@ class OracleTests(unittest.TestCase):
runtime = {'pid': 102, 'directory': str(Path.cwd())}
previous = {'snapshot_id': 's00000001', 'proof_runtime': {**runtime, 'pid': 101},
'proof_image': 'previous.png', 'proof_observation_started_ns': 10, 'proof_observation_finished_ns': 20}
- for failure in (None, 'cached', 'same_snapshot', 'same_artifact', 'dead'):
+ # Freshness rules are owned by cancel's ObservationTests; one stale case proves wiring.
+ for failure in (None, 'cached'):
observed = {**previous, 'proof_runtime': runtime, 'proof_image': 'fresh.png',
'proof_observation_started_ns': 40, 'proof_observation_finished_ns': 50}
if failure == 'cached':
observed.update(proof_observation_started_ns=10, proof_observation_finished_ns=20)
- elif failure == 'same_snapshot':
- observed = dict(previous)
- elif failure == 'same_artifact':
- observed['proof_image'] = previous['proof_image']
- client = Mock(directory=Path.cwd(), process=Mock(pid=102, poll=Mock(return_value=0 if failure == 'dead' else None)))
+ client = Mock(directory=Path.cwd(), process=Mock(pid=102, poll=Mock(return_value=None)))
with self.subTest(failure=failure), \
patch.object(proof, 'grounded_snapshot', return_value=observed), \
patch.object(proof.time, 'monotonic_ns', side_effect=[30, 60]), \
diff --git a/libs/cua-driver/hyprland-plugin/tests/production_agent_conflict_proof.py b/libs/cua-driver/hyprland-plugin/tests/production_agent_conflict_proof.py
index 0405d54c37..e3b3552c6f 100644
--- a/libs/cua-driver/hyprland-plugin/tests/production_agent_conflict_proof.py
+++ b/libs/cua-driver/hyprland-plugin/tests/production_agent_conflict_proof.py
@@ -257,7 +257,7 @@ def run(args):
desktop = ExactDesktop(plan)
app_process_identity(spec['app'], spec['target']['pid'])
origin = provenance(args, plan)
- for name in (Path(__file__).name, 'production_agent_conflict_proof_test.py',
+ for name in (Path(__file__).name, 'production_agent_conflict_proof_test.py', 'proof_fixtures.py',
'production_primary_conflict_proof.py', 'desktop_faults.py', 'production_cancel_proof.py',
'production_desktop_fault_proof.py', 'production_geometry_fault_proof.py'):
path = Path(__file__).with_name(name)
diff --git a/libs/cua-driver/hyprland-plugin/tests/production_agent_conflict_proof_test.py b/libs/cua-driver/hyprland-plugin/tests/production_agent_conflict_proof_test.py
index 28eaa95d06..9570fcae8e 100644
--- a/libs/cua-driver/hyprland-plugin/tests/production_agent_conflict_proof_test.py
+++ b/libs/cua-driver/hyprland-plugin/tests/production_agent_conflict_proof_test.py
@@ -9,57 +9,33 @@ import unittest
from unittest.mock import Mock, patch
import production_agent_conflict_proof as proof
+from proof_fixtures import BOUNDS, DELIVERED, VM, client, conflict_trace as trace, identity, status
-BOUNDS = {'x': 10, 'y': 20, 'width': 800, 'height': 600}
REFUSED = {'isError': True, 'structuredContent': {'effect': 'refused', 'reason': 'agent_target_busy', 'lane': 1}}
PRIMARY_REFUSED = {'isError': True, 'structuredContent': {'effect': 'refused', 'reason': 'primary_target_busy', 'lane': 1}}
-DELIVERED = {'structuredContent': {'effect': 'unverifiable', 'route': 'synthetic_events',
- 'delivery': {'mode': 'background'}}}
RECTANGLE = {'x': 100, 'y': 200, 'w': 60, 'h': 40, 'center': [129, 219]}
GEOMETRY = {'X': 1.0, 'Y': 2.0, 'W': 3.0, 'H': 4.0}
ORACLE = {'app': 'inkscape', 'stage': 'scroll_down', 'rectangle': RECTANGLE, 'geometry': GEOMETRY}
-def identity(pid, name='app'):
- return {'pid': pid, 'uid': 1000, 'starttime': '123', 'exe': '/usr/bin/' + name}
-
-
def plan(stage='scroll_down', recovery='scroll_visible'):
return {'purpose': 'agent_conflict', 'case': 'passive_hover_refusal', 'app_profile': 'inkscape-only',
'disposable': True,
- 'vm': {'machine_id': 'a' * 32, 'boot_id': 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa'},
- 'compositor': {**identity(50, 'Hyprland'), 'instance': 'test_1'},
- 'processes': {'target': identity(20, 'inkscape'), 'foreground': identity(10)},
+ 'vm': dict(VM),
+ 'compositor': {**identity(50, '/usr/bin/Hyprland'), 'instance': 'test_1'},
+ 'processes': {'target': identity(20, '/usr/bin/inkscape'), 'foreground': identity(10)},
'foreground': {'pid': 10, 'window_id': 100}, 'primary_point': [20, 20], 'package_versions': {},
'agents': [{'app': 'inkscape', 'name': 'agent-conflict', 'target': {'pid': 20, 'window_id': 200},
'document': '/tmp/cua/cua-smoke-inkscape.svg', 'bounds': dict(BOUNDS), 'pointer_stage': stage, 'drag': {}}],
'refused': {'pointer_stage': proof.OPPOSITE[stage]}, 'recovery': {'pointer_stage': recovery}}
-def trace(events=(), active=True):
- rows = [(0, 'start', 0, 0), *events]
- if not active:
- rows += [(20, 'stop', 0, 0)]
- return {'hook': True, 'active': active, 'overflow': False, 'timed_out': False, 'count': len(rows),
- 'events': [[i + 1, timestamp, kind, 30, 40, lane, value]
- for i, (timestamp, kind, lane, value) in enumerate(rows)]}
-
-
def scroll_rows(lane, start=1):
return [(start, 'agent_admitted', lane, 0), (start + 1, 'pointer_axis', lane, 1),
(start + 2, 'agent_action_end', lane, 0)]
-def status():
- return {'configured': True, 'transport': {'ready': True}, 'input': {
- 'protocol': 3, 'test_only': False, 'transport_ready': True,
- 'seat_lifetime': 'compositor', 'upgrade': 'desktop_restart', 'lanes': [
- {'lane': lane, 'held_button': 0, 'held_keys': 0, 'drag_active': False,
- 'lease_active': False, 'keyboard_focus': False, 'pointer_focus': False, 'reserved': False}
- for lane in (0, 1)]}}
-
-
def owner_status(owner_lane, *, peer_reserved=False, orphan=False):
value = status()
value['input']['lanes'][owner_lane].update(pointer_focus=True, reserved=not orphan)
@@ -67,10 +43,6 @@ def owner_status(owner_lane, *, peer_reserved=False, orphan=False):
return value
-def client(pid):
- return Mock(directory=Path.cwd(), process=Mock(pid=pid, poll=Mock(return_value=None)))
-
-
class PlanTests(unittest.TestCase):
def test_plan_requires_exact_narrow_same_client_scroll_cell(self):
for stage in proof.SCROLL_STAGES:
@@ -175,9 +147,9 @@ class OracleTests(unittest.TestCase):
after = trace(scroll_rows(1) + [(9, kind, lane, 0)])
with self.subTest(kind=kind, lane=lane), self.assertRaises(AssertionError):
proof.verify_refusal(before, after, REFUSED, 0)
- for key, value in (('hook', False), ('active', False), ('overflow', True), ('timed_out', True), ('count', 9)):
- with self.subTest(key=key), self.assertRaises(AssertionError):
- proof.verify_refusal(before, {**before, key: value}, REFUSED, 0)
+ # Page validity is owned by trace_interval (realapp TraceIntervalTests); one case proves wiring.
+ with self.assertRaisesRegex(AssertionError, 'dropped events'):
+ proof.verify_refusal(before, {**before, 'overflow': True}, REFUSED, 0)
changed = deepcopy(before)
changed['events'][1][1] += 1
with self.assertRaisesRegex(AssertionError, 'history'):
@@ -203,7 +175,7 @@ class OracleTests(unittest.TestCase):
geometry = stack.enter_context(patch.object(proof.pointer_grounding, 'inkscape_geometry',
return_value={**GEOMETRY, 'X': 1.5} if failure == 'geometry' else dict(GEOMETRY)))
if failure:
- with self.assertRaises(Exception):
+ with self.assertRaises((AssertionError, proof.pointer_grounding.GroundingUnavailable)):
proof.verify_no_effect(after, image, oracle)
else:
result = proof.verify_no_effect(after, image, oracle)
@@ -227,10 +199,6 @@ class OracleTests(unittest.TestCase):
proof.verify_close_events(before, trace(scroll_rows(1) + [(9, kind, 1, 0)]), {'agent_cancel'})
with self.assertRaises(AssertionError):
proof.verify_close_events(before, trace(scroll_rows(1) + [(9, 'agent_admitted', 1, 0)]), {'agent_admitted'})
- # Primary events on lane 0 are the trace oracle's job at TRACE_STOP; the
- # stopped trace must still fail on them.
- stopped = trace(scroll_rows(1) + [(9, 'keyboard_key', 0, 1)], active=False)
- self.assertEqual(proof.analyze(stopped)['result'], 'failed')
class ActionTests(unittest.TestCase):
@@ -251,8 +219,8 @@ class ActionTests(unittest.TestCase):
actor.tool.assert_not_called()
def test_single_normal_scroll_fresh_snapshot_unknown_never_replayed(self):
- cases = {'owner': (None, 'guard', 'stale', 'unknown', 'same_snapshot', 'cached', 'before_return',
- 'same_runtime', 'effect', 'pre_activity', 'dead_before', 'observation', 'lane_mismatch',
+ # Freshness rules are owned by cancel's ObservationTests; 'cached' proves wiring.
+ cases = {'owner': (None, 'guard', 'stale', 'unknown', 'cached', 'same_runtime', 'effect', 'pre_activity', 'dead_before', 'observation', 'lane_mismatch',
'refused_instead', 'two_lanes'),
'refused': (None, 'guard', 'stale', 'unknown', 'pre_activity', 'delivered', 'primary_reason',
'owner_lane', 'admitted', 'pointer_leave', 'moved', 'geometry', 'observation'),
@@ -288,12 +256,8 @@ class ActionTests(unittest.TestCase):
'proof_observation_started_ns': 10, 'proof_observation_finished_ns': 20}
after = {**before, 'proof_runtime': {'pid': 102, 'directory': str(Path.cwd())},
'proof_image': 'after.png', 'proof_observation_started_ns': 50, 'proof_observation_finished_ns': 60}
- if failure == 'same_snapshot':
- after = dict(before)
- elif failure == 'cached':
+ if failure == 'cached':
after.update(proof_observation_started_ns=10, proof_observation_finished_ns=20)
- elif failure == 'before_return':
- after['proof_observation_started_ns'] = 39
snapshots = stack.enter_context(patch.object(proof, 'grounded_snapshot',
side_effect=[before, AssertionError('snapshot unavailable')] if failure == 'observation' else [before, after]))
stack.enter_context(patch.object(proof.time, 'monotonic_ns', side_effect=
diff --git a/libs/cua-driver/hyprland-plugin/tests/production_app_profile_test.py b/libs/cua-driver/hyprland-plugin/tests/production_app_profile_test.py
index 0564fee6f9..5da5c4eeb5 100644
--- a/libs/cua-driver/hyprland-plugin/tests/production_app_profile_test.py
+++ b/libs/cua-driver/hyprland-plugin/tests/production_app_profile_test.py
@@ -2,8 +2,6 @@
import copy
import json
from pathlib import Path
-import subprocess
-import sys
import tempfile
from types import SimpleNamespace
import unittest
@@ -13,30 +11,16 @@ from production_app_smoke import (PACKAGES, artifact_identity, create_documents,
digest, package_owner, profile_packages, source_identities)
from production_realapp_proof import (capacity_reservations, inkscape_client_identity,
validate_plan, verify_output)
-from production_realapp_proof_test import capacity_plan, plan
-
-
-def inkscape_plan(capacity=False):
- candidate = capacity_plan() if capacity else plan()
- candidate['app_profile'] = 'inkscape-only'
- candidate['package_versions'] = {'inkscape': '1.4.4-6'}
- for index, spec in enumerate(candidate['agents']):
- spec.update(app='inkscape', document=f'/synthetic/lane-{index}.svg')
- candidate['outputs'] = [] if capacity else [
- {'agent': i, 'path': spec['document'], 'format': 'svg',
- 'xpath': './/svg:rect[@id="smoke-rectangle"]',
- 'namespaces': {'svg': 'http://www.w3.org/2000/svg'},
- 'rect_translation': [[2, 2], [0, 0]]}
- for i, spec in enumerate(candidate['agents'])]
- return candidate
+from proof_fixtures import capacity_plan, inkscape_plan, lane, lane_status, plan
class AppProfileTests(unittest.TestCase):
def test_profile_is_explicit_and_keeps_exact_package_gate(self):
- self.assertEqual(profile_packages('calc-inkscape'), PACKAGES)
- self.assertEqual(profile_packages('inkscape-only'), {'inkscape': '1.4.4-6'})
+ self.assertEqual(profile_packages('calc-inkscape'),
+ {name: PACKAGES[name] for name in ('libreoffice-fresh', 'inkscape')})
+ self.assertEqual(profile_packages('inkscape-only'), {'inkscape': PACKAGES['inkscape']})
for value in ('all', 'inkscape', '', None):
- with self.subTest(value=value), self.assertRaises(AssertionError):
+ with self.subTest(value=value), self.assertRaisesRegex(AssertionError, 'unknown app qualification profile'):
profile_packages(value)
def test_single_app_smoke_does_not_create_calc_document(self):
@@ -48,16 +32,22 @@ class AppProfileTests(unittest.TestCase):
with self.assertRaises(FileExistsError):
create_documents(directory, 'inkscape-only')
- def test_inkscape_executable_owner_and_version_are_both_exact(self):
+ def test_executable_owner_and_version_are_both_exact(self):
with tempfile.TemporaryDirectory() as temporary:
- executable = Path(temporary).resolve() / 'inkscape'
+ executable = Path(temporary).resolve() / 'app'
executable.write_bytes(b'synthetic executable')
executable.chmod(0o700)
- for replies in (['other-package'], ['inkscape', 'inkscape 1.4.4-7']):
- with patch('production_app_smoke.read', side_effect=replies), self.assertRaises(AssertionError):
- package_owner(executable, 'inkscape')
- with patch('production_app_smoke.read', side_effect=['inkscape', 'inkscape 1.4.4-6']):
- self.assertEqual(package_owner(executable, 'inkscape'), digest(executable))
+ for package in ('inkscape', 'libreoffice-fresh'):
+ qualified = f'{package} {PACKAGES[package]}'
+ for replies, error, queries in ((['other-package', qualified], 'noncanonical package owner', 1),
+ ([package, qualified + '-1'], 'not the qualified version', 2)):
+ with self.subTest(package=package, error=error), \
+ patch('production_app_smoke.read', side_effect=replies) as read, \
+ self.assertRaisesRegex(AssertionError, error):
+ package_owner(executable, package)
+ self.assertEqual(read.call_count, queries)
+ with patch('production_app_smoke.read', side_effect=[package, qualified]):
+ self.assertEqual(package_owner(executable, package), digest(executable))
def test_apps_and_capacity_need_explicit_profile_and_independent_clients(self):
for capacity in (False, True):
@@ -95,35 +85,18 @@ class AppProfileTests(unittest.TestCase):
with self.subTest(plan=candidate), self.assertRaises(AssertionError):
validate_plan(candidate)
- def test_capacity_keeps_two_admissions_exact_third_refusal_and_serial_order(self):
- for mutate in (
- lambda p: p.update(agents=p['agents'][:2]),
- lambda p: p['phases'][2].update(expect={'kind': 'dispatched'}),
- lambda p: p['phases'][2]['expect'].update(reason='target_unavailable'),
- lambda p: p['phases'][2].update(agent=0),
- lambda p: p.update(require_overlap=True),
- lambda p: p.update(moving_primary=True),
- ):
- candidate = inkscape_plan(True)
- mutate(candidate)
- with self.subTest(plan=candidate), self.assertRaises(AssertionError):
- validate_plan(candidate)
-
def test_capacity_owners_must_retain_both_reservations_through_third_refusal(self):
- status = {'state': 'input_v3_candidate', 'input': {'protocol': 3, 'test_only': False,
- 'transport_ready': True, 'lanes': [
- {'lane': lane, 'reserved': True, 'lease_active': False, 'drag_active': False,
- 'held_keys': 0, 'held_button': 0, 'epoch': 50 + lane, 'desktop_generation': 4}
- for lane in (0, 1)]}}
+ status = lane_status(*(lane(index, reserved=True, epoch=50 + index, desktop_generation=4)
+ for index in (0, 1)))
previous = capacity_reservations(status, [1], {})
both = capacity_reservations(status, [1, 2], previous)
self.assertEqual(capacity_reservations(status, [1, 2], both), both)
- for lane in (0, 1):
+ for index in (0, 1):
for change in ({'reserved': False}, {'epoch': 100}, {'desktop_generation': 5},
{'held_keys': 1}, {'held_button': 272}, {'lease_active': True}):
bad = copy.deepcopy(status)
- bad['input']['lanes'][lane].update(change)
- with self.subTest(lane=lane, change=change), self.assertRaises(AssertionError):
+ bad['input']['lanes'][index].update(change)
+ with self.subTest(lane=index, change=change), self.assertRaises(AssertionError):
capacity_reservations(bad, [1, 2], both)
def test_saved_svg_must_change_exact_rectangle_without_resizing(self):
@@ -163,20 +136,6 @@ class AppProfileTests(unittest.TestCase):
class ProfileProvenanceTests(unittest.TestCase):
- def test_helper_clis_expose_separate_source_and_artifact_options(self):
- names = ('app_smoke', 'realapp_proof', 'active_lock_proof', 'active_primary_proof',
- 'cancel_proof', 'desktop_fault_proof', 'geometry_fault_proof', 'idle_reconnect_proof',
- 'lock_refusal_proof', 'primary_conflict_proof', 'session_fault_proof',
- 'target_lifetime_proof', 'policy_proof')
- for name in names:
- with self.subTest(helper=name):
- output = subprocess.check_output(
- [sys.executable, str(Path(__file__).with_name(f'production_{name}.py')), '--help'],
- text=True, timeout=10)
- for option in ('--source-sha', '--harness-source', '--harness-sha', '--artifact-role',
- '--kit-manifest', '--profile-manifest', '--build-provenance'):
- self.assertIn(option, output)
-
def test_clean_exact_product_and_harness_checkouts_are_independent(self):
with tempfile.TemporaryDirectory() as temporary:
root = Path(temporary).resolve()
diff --git a/libs/cua-driver/hyprland-plugin/tests/production_app_smoke.py b/libs/cua-driver/hyprland-plugin/tests/production_app_smoke.py
index 6ea503ff3b..9c812d3570 100644
--- a/libs/cua-driver/hyprland-plugin/tests/production_app_smoke.py
+++ b/libs/cua-driver/hyprland-plugin/tests/production_app_smoke.py
@@ -58,7 +58,7 @@ def package_owner(path, package):
assert path.resolve(strict=True) == path, 'noncanonical package executable'
assert path.is_file() and path.stat().st_mode & 0o111, 'package executable is not executable'
assert read(['pacman', '-Qqo', str(path)]) == package, 'noncanonical package owner'
- assert read(['pacman', '-Q', package]) == f'{package} {PACKAGES[package]}'
+ assert read(['pacman', '-Q', package]) == f'{package} {PACKAGES[package]}', 'package is not the qualified version'
return digest(path)
diff --git a/libs/cua-driver/hyprland-plugin/tests/production_app_smoke_test.py b/libs/cua-driver/hyprland-plugin/tests/production_app_smoke_test.py
index aa738e07c0..768411084b 100644
--- a/libs/cua-driver/hyprland-plugin/tests/production_app_smoke_test.py
+++ b/libs/cua-driver/hyprland-plugin/tests/production_app_smoke_test.py
@@ -1,6 +1,5 @@
"""No native applications or input: fixtures and fail-closed orchestration only."""
import copy
-import io
import os
from pathlib import Path
import tempfile
@@ -9,60 +8,18 @@ from unittest.mock import Mock, patch
import zipfile
from production_app_smoke import (
- LIMITS, GroundingUnavailable, check_delivery, create_documents, ground, input_step,
+ GroundingUnavailable, check_delivery, create_documents, ground, input_step,
kernel_file_identity, launch_arguments, mapped_plugin, package_owner,
require_background_target, require_enabled_plugin, run_app, verify_calc, verify_inkscape,
)
+from proof_fixtures import CALC, INKSCAPE, INKSCAPE_SELECTED, changed_ods
TARGET = {'pid': 123, 'window_id': 456}
GOOD_DELIVERY = {'structuredContent': {'route': 'synthetic_events',
'effect': 'unverifiable',
'delivery': {'mode': 'background'}}}
-CALC = {'window_title': 'cua-smoke-calc.ods - LibreOffice Calc',
- 'elements': [{'role': 'text', 'label': 'Name Box', 'value': 'A1'}]}
WINDOWS = {'structuredContent': {'windows': [TARGET]}}
-INKSCAPE = {
- 'elements': [
- {'element_index': 10, 'role': 'menu', 'label': 'Edit', 'enabled': True},
- {'element_index': 11, 'parent_index': 10, 'role': 'menu item',
- 'label': 'Select All', 'enabled': True},
- {'element_index': 12, 'role': 'table cell', 'label': 'smoke-rectangle', 'enabled': True}],
- 'tree_markdown': '\n'.join([
- ' - [10] menu "Edit" [actions=[click]]',
- ' - [11] menu item "Select All" [actions=[click]]',
- ' - [12] table cell "smoke-rectangle" [actions=[activate]]',
- ' - label = "No objects selected. Click, Shift+click, Alt+scroll mouse on top of '
- 'objects, or drag around objects to select."']),
-}
-INKSCAPE_SELECTED = {
- 'elements': [{'element_index': 1, 'role': 'table cell',
- 'label': 'smoke-rectangle', 'enabled': True}] + [
- {'element_index': index, 'role': 'spin button', 'label': f'{value:.3f}',
- 'value': f'{value:.1f}', 'enabled': True}
- for index, value in enumerate((40, 60, 80, 50), 2)],
- 'tree_markdown': '\n'.join([
- ' - [1] table cell "smoke-rectangle" [actions=[activate]]',
- ' - label = "Rectangle in root. Click selection again to toggle scale/rotation handles."',
- *[f' - label = "{axis}:"\n - [{index}] spin button "{value:.3f}" '
- f'value="{value:.1f}" [actions=[activate]]'
- for index, (axis, value) in enumerate((('X', 40), ('Y', 60), ('W', 80), ('H', 50)), 2)]]),
-}
-
-
-def changed_ods(original, text='abc', empty_first=False):
- destination = io.BytesIO()
- with zipfile.ZipFile(io.BytesIO(original)) as source, zipfile.ZipFile(destination, 'w') as target:
- for name in source.namelist():
- value = source.read(name)
- if name == 'content.xml':
- cell = (f'<table:table-cell office:value-type="string"><text:p>{text}</text:p>'
- '</table:table-cell>')
- if empty_first:
- cell = '<table:table-cell/>' + cell
- value = value.replace(b'<table:table-cell/>', cell.encode())
- target.writestr(name, value)
- return destination.getvalue()
class FixtureTests(unittest.TestCase):
@@ -189,14 +146,6 @@ class FixtureTests(unittest.TestCase):
self.assertEqual(identity[2], plugin.stat().st_ino)
self.assertTrue(all(type(value) is int and value >= 0 for value in identity))
- def test_alpm_owner_required_even_when_version_matches(self):
- executable = self.directory / 'app'
- executable.write_bytes(b'synthetic executable')
- executable.chmod(0o700)
- with patch('production_app_smoke.read', return_value='unrelated-package'):
- with self.assertRaisesRegex(AssertionError, 'noncanonical package owner'):
- package_owner(executable, 'libreoffice-fresh')
-
def test_package_executable_rejects_symlink_and_nonexecutable(self):
executable = self.directory / 'app'
executable.write_bytes(b'synthetic executable')
@@ -260,9 +209,6 @@ class InputTests(unittest.TestCase):
with self.assertRaises(GroundingUnavailable):
ground({**state, 'elements': state['elements'] + [state['elements'][1]]}, 'calc', 'insert')
- def test_route_family_does_not_claim_plugin_transport_attribution(self):
- self.assertIs(LIMITS['plugin_transport_attribution'], False)
-
def test_inkscape_requires_document_command_and_exact_initial_status(self):
ground(INKSCAPE, 'inkscape', 'select')
for index, replacement in [(0, {'role': 'label'}), (0, {'enabled': False}),
@@ -327,19 +273,14 @@ class InputTests(unittest.TestCase):
with self.assertRaises(GroundingUnavailable):
ground(state, 'inkscape', 'move')
- def test_grounding_rejects_dialog_missing_selection_and_missing_canvas(self):
+ def test_calc_grounding_rejects_empty_tree_dialog_and_wrong_selection(self):
+ # Inkscape stages are owned by the two Inkscape grounding tables above.
ground(CALC, 'calc', 'insert')
for state in ({'elements': []},
{'elements': [{'role': 'dialog', 'label': 'Recover documents'}]},
{'elements': [{'role': 'text', 'label': 'Name Box', 'value': 'B1'}]}):
- with self.assertRaises(GroundingUnavailable):
+ with self.subTest(state=state), self.assertRaises(GroundingUnavailable):
ground(state, 'calc', 'insert')
- with self.assertRaises(GroundingUnavailable):
- ground(CALC, 'inkscape', 'select')
- ground(INKSCAPE, 'inkscape', 'select')
- with self.assertRaises(GroundingUnavailable):
- ground({'elements': [{'role': 'status bar', 'value': 'No objects selected'}]}, 'inkscape', 'move')
- ground(INKSCAPE_SELECTED, 'inkscape', 'move')
def test_snapshot_action_snapshot_and_no_replay(self):
mcp = Mock()
@@ -364,7 +305,7 @@ class InputTests(unittest.TestCase):
dialog = {**CALC, 'elements': [{'role': 'dialog'}]}
mcp.tool.side_effect = [{'structuredContent': CALC}, WINDOWS, partial,
{'structuredContent': dialog}, WINDOWS]
- with self.assertRaises(AssertionError):
+ with self.assertRaisesRegex(AssertionError, 'partial/refused input cannot pass'):
input_step(mcp, TARGET, 'cua-smoke-calc.ods', 'calc', 'insert', 'type_text', {'text': 'abc'})
self.assertEqual(mcp.tool.call_count, 5)
diff --git a/libs/cua-driver/hyprland-plugin/tests/production_cancel_proof.py b/libs/cua-driver/hyprland-plugin/tests/production_cancel_proof.py
index 3ce90d12d7..4aff96f04a 100644
--- a/libs/cua-driver/hyprland-plugin/tests/production_cancel_proof.py
+++ b/libs/cua-driver/hyprland-plugin/tests/production_cancel_proof.py
@@ -451,8 +451,7 @@ def verify_cancellation(stopped, kill_prefix, victim_lane, sibling_lane):
'continuous_isolation': isolation, 'synthetic_cleanup': 'verified'}
-def call_drag(client, spec, prepared=None, guard=None):
- prepared = prepare_drag(client, spec) if prepared is None else prepared
+def call_drag(client, spec, prepared, guard=None):
assert prepared['target'] == spec['target'] and prepared['session'] == spec['name']
if guard:
guard()
@@ -493,7 +492,7 @@ def run(args):
assert args.trace_socket and args.trace_socket.name in ('cua-input-v3.sock', 'cua-input-v3-2.sock'), \
'cancellation requires continuous v3 trace'
origin = provenance(args, plan)
- for name in ('production_cancel_proof.py', 'production_cancel_proof_test.py'):
+ for name in ('production_cancel_proof.py', 'production_cancel_proof_test.py', 'proof_fixtures.py'):
path = Path(__file__).with_name(name)
origin['files'][name] = {'path': str(path.resolve()), 'sha256': hashlib.sha256(path.read_bytes()).hexdigest()}
save('provenance.json', origin)
diff --git a/libs/cua-driver/hyprland-plugin/tests/production_cancel_proof_test.py b/libs/cua-driver/hyprland-plugin/tests/production_cancel_proof_test.py
index 35721a66e3..a9ece4df91 100644
--- a/libs/cua-driver/hyprland-plugin/tests/production_cancel_proof_test.py
+++ b/libs/cua-driver/hyprland-plugin/tests/production_cancel_proof_test.py
@@ -2,7 +2,6 @@
from contextlib import ExitStack
from concurrent.futures import ThreadPoolExecutor
from copy import deepcopy
-import importlib
import json
from pathlib import Path
import subprocess
@@ -14,12 +13,13 @@ import unittest
from unittest.mock import Mock, patch
from production_cancel_proof import (
- GROUNDING_DISPATCH_RESERVE_NS, MAX_GROUNDING_AGE_NS, PROFILE,
+ GROUNDING_DISPATCH_RESERVE_NS, MAX_GROUNDING_AGE_NS, POINTER_SNAPSHOT_LIMITS, PROFILE,
active_drags, call_drag, close_owned, grounded_snapshot,
pair_has_dispatch_budget, poll_active, prepare_drag, prepare_drags, recover_once, run, stopped_prefix,
- terminate_owned, validate_plan, verify_cancellation, verify_fresh_observation,
+ terminate_owned, validate_app_profile, validate_plan, verify_cancellation, verify_fresh_observation,
verify_recovery_cleanup, verify_recovery_trace,
)
+from proof_fixtures import assert_rejects, client, identity, inkscape_profile, trace
BOUNDS = {'x': 0, 'y': 0, 'width': 800, 'height': 600}
@@ -34,12 +34,6 @@ def plan():
for i, app in enumerate(('calc', 'inkscape'))]}
-def trace(rows, active=True):
- return {'hook': True, 'active': active, 'overflow': False, 'timed_out': False, 'count': len(rows),
- 'events': [[i + 1, ms * 1_000_000, kind, 100, 100, lane, value]
- for i, (ms, kind, lane, value) in enumerate(rows)]}
-
-
START = [(0, 'start', 0, 0)]
FIRST = START + [(1, 'agent_admitted', 1, 0), (2, 'agent_drag_start', 1, 0), (2, 'pointer_button', 1, 1)]
OVERLAP = FIRST + [(10, 'agent_admitted', 2, 0), (11, 'agent_drag_start', 2, 0),
@@ -72,105 +66,40 @@ def recovery_rows(tool='click', lane=1):
class InkscapeProfileTests(unittest.TestCase):
- def candidates(self):
- for name in ('cancel', 'geometry_fault', 'primary_conflict', 'desktop_fault', 'session_fault',
- 'lock_refusal', 'active_lock', 'active_primary', 'idle_reconnect', 'target_lifetime'):
- module = importlib.import_module('production_' + name + '_proof')
- candidate = importlib.import_module('production_' + name + '_proof_test').plan()
- candidate['app_profile'] = 'inkscape-only'
- for i, spec in enumerate(candidate['agents']):
- spec.update(app='inkscape', document=f'/synthetic/agent-{i}/cua-smoke-inkscape.svg')
- if name != 'idle_reconnect':
- spec.update(pointer_stage='move_rectangle', drag={})
- for key in ('identities', 'processes'):
- if key in candidate:
- candidate[key]['target']['exe'] = '/usr/bin/inkscape'
- if name in ('active_lock', 'active_primary'):
- candidate['recovery'] = {'pointer_stages': ['scroll_down', 'scroll_up']}
- elif name == 'target_lifetime':
- old, fresh = candidate['agents'][0], candidate['recovery']['agent']
- fresh.update(app='inkscape', document='/synthetic/replacement/cua-smoke-inkscape.svg',
- pointer_stage='click_rectangle')
- candidate['recovery']['identity']['exe'] = '/usr/bin/inkscape'
- for i, spec in enumerate((old, fresh)):
- spec['app_id_tag'] = f'cua-profile-lane-{i}'
- spec['owned'].pop('profile')
- spec['owned']['document']['path'] = spec['document']
- elif name != 'idle_reconnect':
- candidate['recovery'] = {'pointer_stage': 'scroll_down'}
- yield name, module, candidate
-
- def test_all_fault_profiles_accept_only_exact_inkscape_plan_shapes(self):
- for name, module, candidate in self.candidates():
- with self.subTest(name=name):
- module.validate_plan(candidate)
- mutations = [lambda p: p.update(app_profile='unreviewed'),
- lambda p: p['agents'][0].update(app='calc'),
- lambda p: p['agents'][0].update(pointer_stage='click_a1'),
- lambda p: p['agents'][0].update(document='/synthetic/private.svg'),
- lambda p: p['agents'][0]['target'].update(window_id=p['foreground']['window_id'])]
- for key in ('identities', 'processes'):
- if key in candidate:
- mutations.append(lambda p, k=key: p[k]['target'].update(exe='/usr/bin/soffice.bin'))
- mutations.append(lambda p, k=key: p[k]['target'].update(pid=999))
- if name == 'target_lifetime':
- mutations.extend([lambda p: p['recovery']['agent'].update(pointer_stage='move_rectangle'),
- lambda p: p['recovery']['identity'].update(exe='/usr/bin/soffice.bin'),
- lambda p: p['recovery']['agent'].update(app_id_tag=p['agents'][0]['app_id_tag']),
- lambda p: p['recovery']['agent']['owned']['document'].update(path='/synthetic/wrong.svg')])
- for mutate in mutations:
- changed = deepcopy(candidate)
- mutate(changed)
- with self.subTest(name=name, changed=changed), self.assertRaises(AssertionError):
- module.validate_plan(changed)
-
- def test_scroll_recovery_uses_existing_pixel_and_semantic_oracle(self):
- import production_active_lock_proof as active
- from production_pointer_grounding_test import ink
- before, pixels = ink()
- before.update(proof_image='synthetic.png', proof_observation_started_ns=1)
- spec = {'app': 'inkscape', 'name': 'recovery', 'target': {'pid': 20, 'window_id': 200},
- 'pointer_stage': 'move_rectangle'}
- with patch.object(active, 'grounded_snapshot', return_value=before), \
- patch.object(active.pointer_grounding, 'read_pixels', return_value=pixels):
- prepared = active.prepare_recovery(Mock(), spec, ['scroll_down', 'scroll_up'])
- self.assertIn(prepared['stage'], ('scroll_down', 'scroll_up'))
- self.assertEqual(prepared['prepared_ns'], 1)
- with self.assertRaises(AssertionError):
- active.pointer_grounding.verify(before, pixels, prepared['oracle'])
- shift = -10 if prepared['stage'] == 'scroll_down' else 10
- after, moved = ink(scroll_y=shift)
- self.assertTrue(active.pointer_grounding.verify(after, moved, prepared['oracle'])['verified'])
-
- def test_refusal_scroll_keeps_exact_target_and_original_observation(self):
- import production_session_fault_proof as session
- from production_pointer_grounding_test import ink
- before, pixels = ink()
- target = {'pid': 20, 'window_id': 200}
- before.update(**target, proof_image='synthetic.png', proof_observation_started_ns=1)
- spec = {'app': 'inkscape', 'name': 'refusal', 'target': target, 'bounds': before['window_bounds']}
- prepared = {'snapshot': before, 'target': dict(target), 'prepared_ns': 1}
- with patch.object(session.pointer_grounding, 'read_pixels', return_value=pixels):
- probe = session.prepare_refusal(prepared, spec, 'scroll_down')
- self.assertEqual(probe['tool'], 'scroll')
- self.assertEqual(probe['prepared_ns'], 1)
- before['window_id'] += 1
- with self.assertRaises(AssertionError):
- session.prepare_refusal(prepared, spec, 'scroll_down')
-
- def test_new_action_dispatch_uses_scroll_without_drag_or_replay(self):
- import production_lock_refusal_proof as lock
- for tool in ('click', 'scroll', 'drag'):
- actor = Mock()
- record = {'outcome': 'unknown', 'replayed': False, 'prepared_ns': 1, 'tool': tool}
- with patch.object(lock.time, 'monotonic_ns', return_value=2):
- if tool == 'drag':
- with self.assertRaises(AssertionError):
- lock.click_once(actor, {'x': 1}, record, Mock(), 'action')
- actor.tool.assert_not_called()
- else:
- lock.click_once(actor, {'x': 1}, record, Mock(), 'action')
- actor.tool.assert_called_once_with(tool, {'x': 1})
+ def test_app_profile_refuses_each_inkscape_only_violation(self):
+ base = inkscape_profile({**plan(), 'recovery': {'pointer_stage': 'scroll_down'},
+ 'processes': {'target': identity(20, '/usr/bin/inkscape')}})
+ self.assertEqual(validate_app_profile(base), 'inkscape-only')
+ self.assertEqual(validate_app_profile({**base, 'recovery': {'pointer_stage': 'scroll_visible'}}), 'inkscape-only')
+ clicks = deepcopy(base)
+ for spec in clicks['agents']:
+ spec.update(pointer_stage='click_rectangle', drag={'from_x': 1})
+ self.assertEqual(validate_app_profile(clicks, require_drag=False), 'inkscape-only')
+ assert_rejects(self, validate_app_profile, base, [
+ ('unknown app profile', lambda p: p.update(app_profile='unreviewed')),
+ ('requires Inkscape targets', lambda p: p['agents'][0].update(app='calc')),
+ ('absolute synthetic SVG document', lambda p: p['agents'][0].update(document='/synthetic/private.svg')),
+ ('absolute synthetic SVG document', lambda p: p['agents'][0].update(
+ document='synthetic/cua-smoke-inkscape.svg')),
+ ('distinct documents required', lambda p: p['agents'][1].update(document=p['agents'][0]['document'])),
+ ('distinct native windows required', lambda p: p['agents'][0]['target'].update(
+ window_id=p['foreground']['window_id'])),
+ ('freshly grounded rectangle drags', lambda p: p['agents'][0].update(pointer_stage='click_a1')),
+ ('freshly grounded rectangle drags', lambda p: p['agents'][0].update(drag={'from_x': 1})),
+ ('supported scroll stage', lambda p: p['recovery'].update(pointer_stage='click_b2')),
+ # Only cancellation recovery may choose the visible scroll direction.
+ ('supported scroll stage', lambda p: p.update(purpose='geometry_fault',
+ recovery={'pointer_stage': 'scroll_visible'})),
+ ('wrong Inkscape executable identity', lambda p: p['processes']['target'].update(
+ exe='/usr/bin/soffice.bin')),
+ ])
+
+ def test_inkscape_only_profile_reaches_the_shared_app_profile_gate(self):
+ candidate = inkscape_profile({**plan(), 'recovery': {'pointer_stage': 'scroll_down'}})
+ validate_plan(candidate)
+ candidate['agents'][0]['document'] = '/synthetic/private.svg'
+ with self.assertRaisesRegex(AssertionError, 'absolute synthetic SVG document'):
+ validate_plan(candidate)
def test_native_document_identity_is_checked_before_driver_observation(self):
import production_cancel_proof as cancellation
@@ -199,15 +128,10 @@ class TelemetryTests(unittest.TestCase):
return [(ms, kind, 3 - lane if lane else lane, value) for ms, kind, lane, value in rows]
self.assertEqual(verify_cancellation(trace(swap(FINISH), False), trace(swap(OVERLAP)), 2, 1)['result'], 'verified')
- def test_missing_truncated_overflowed_and_reordered_telemetry_fail(self):
- for field, value in [('hook', False), ('active', False), ('overflow', True), ('timed_out', True),
- ('count', 100), ('events', []), ('events', [[1, 0, 'bogus', 0, 0, 0, 0]])]:
- with self.subTest(field=field), self.assertRaises(AssertionError):
- active_drags({**trace(OVERLAP), field: value})
- page = trace(OVERLAP)
- page['events'][3][0] = 100
- with self.assertRaises(AssertionError):
- active_drags(page)
+ def test_unknown_event_kind_cannot_authorize_kill(self):
+ # Page validity is owned by trace_interval; this proves active_drags applies it.
+ with self.assertRaisesRegex(AssertionError, 'incomplete dispatch telemetry'):
+ active_drags(trace(OVERLAP + [(151, 'bogus', 1, 0)]))
def test_cancelled_ended_or_unheld_drag_cannot_authorize_kill(self):
for kind, value in [('agent_cancel', 0), ('agent_drag_end', 0), ('pointer_button', 0),
@@ -256,13 +180,6 @@ class TelemetryTests(unittest.TestCase):
self.assertEqual(page, trace(OVERLAP))
-def client(pid):
- process = Mock(pid=pid, poll=Mock(return_value=None))
- process.kill.side_effect = lambda: setattr(process.poll, 'return_value', -9)
- process.terminate.side_effect = lambda: setattr(process.poll, 'return_value', -15)
- return Mock(process=process, failed=False)
-
-
class RecoveryTests(unittest.TestCase):
def test_completed_recovery_allows_only_seat_cleanup(self):
rows = recovery_rows()
@@ -279,10 +196,9 @@ class RecoveryTests(unittest.TestCase):
with self.subTest(kind=kind, lane=lane), self.assertRaises(AssertionError):
verify_recovery_cleanup(prefix,
trace(rows + cleanup + [(2028, kind, lane, 0), (2030, 'stop', 0, 0)], False))
- for field, value in (('active', True), ('hook', False), ('overflow', True),
- ('timed_out', True), ('count', 0)):
- with self.subTest(field=field), self.assertRaises(AssertionError):
- verify_recovery_cleanup(prefix, {**trace(rows + [(2030, 'stop', 0, 0)], False), field: value})
+ # The cleanup page must be the stopped trace; its flags are owned by primary_trace_test.
+ with self.assertRaises(AssertionError):
+ verify_recovery_cleanup(prefix, {**trace(rows + [(2030, 'stop', 0, 0)], False), 'active': True})
changed = trace(rows + cleanup + [(2030, 'stop', 0, 0)], False)
changed['events'][1][1] += 1
with self.assertRaisesRegex(AssertionError, 'history'):
@@ -324,9 +240,8 @@ class RecoveryTests(unittest.TestCase):
damaged.pop(missing)
with self.assertRaises(AssertionError):
verify_recovery_trace(boundary, trace(damaged), lane, tool)
- for key in ('hook', 'active'):
- with self.assertRaises(AssertionError):
- verify_recovery_trace(boundary, {**after, key: False}, lane, tool)
+ with self.assertRaisesRegex(AssertionError, 'not live'):
+ verify_recovery_trace(boundary, {**after, 'hook': False}, lane, tool)
changed = trace(rows)
changed['events'][1][1] += 1
with self.assertRaisesRegex(AssertionError, 'history'):
@@ -464,24 +379,6 @@ class OwnershipTests(unittest.TestCase):
for owned in clients:
owned.tool.assert_not_called()
- def test_pair_freshness_boundary_and_attempt_cap(self):
- limit = MAX_GROUNDING_AGE_NS - GROUNDING_DISPATCH_RESERVE_NS
- for age, attempts, error in ((limit, 1, None), (limit + 1, 2, 'insufficient dispatch time'),
- (MAX_GROUNDING_AGE_NS + 1, 2, 'insufficient dispatch time'),
- (-1, 1, 'in the future')):
- with self.subTest(age=age):
- clients, save = [client(100), client(101)], Mock()
- with patch('production_cancel_proof.prepare_drag', return_value={'prepared_ns': 100}) as observe, \
- patch('production_cancel_proof.time.monotonic_ns', return_value=100 + age):
- if error:
- with self.assertRaisesRegex(AssertionError, error):
- prepare_drags(clients, plan()['agents'], save)
- else:
- prepare_drags(clients, plan()['agents'], save)
- self.assertEqual(observe.call_count, 2 * attempts)
- for owned in clients:
- owned.tool.assert_not_called()
-
def test_grounding_retention_time_counts_toward_pair_freshness(self):
clients, now = [client(100), client(101)], [100]
def save(name, item):
@@ -681,7 +578,8 @@ class OwnershipTests(unittest.TestCase):
self.assertEqual(result['proof_observation_finished_ns'], 300)
self.assertEqual(result['proof_runtime'], {'pid': 101, 'directory': str(root.resolve())})
self.assertEqual(mcp.tool.call_args.args, ('get_window_state', {
- **spec['target'], 'session': spec['name'], 'max_elements': 3000}))
+ **spec['target'], 'session': spec['name'], **POINTER_SNAPSHOT_LIMITS['inkscape']}))
+ self.assertNotIn('max_depth', mcp.tool.call_args.args[1])
# A bounded walk is not permission to omit the existing oracle.
with patch('production_cancel_proof.pointer_grounding.read_pixels', return_value='pixels'):
with self.assertRaisesRegex(RuntimeError, 'snapshot has no semantic elements'):
@@ -748,12 +646,12 @@ class OwnershipTests(unittest.TestCase):
terminate_owned(victim, sibling, [Mock(done=lambda: done)])
victim.process.kill.assert_not_called()
- def test_unknown_drag_is_called_once_with_fresh_grounding(self):
+ def test_unknown_drag_is_called_once_with_its_prepared_grounding(self):
mcp, spec = Mock(), plan()['agents'][0]
mcp.tool.side_effect = TimeoutError('lost reply')
with patch('production_cancel_proof.grounded_snapshot', return_value={'proof_observation_started_ns': 100}) as snapshot, \
patch('production_cancel_proof.time.monotonic_ns', return_value=100):
- result = call_drag(mcp, spec)
+ result = call_drag(mcp, spec, prepare_drag(mcp, spec))
snapshot.assert_called_once_with(mcp, spec['target'], spec)
self.assertEqual(result['outcome'], 'unknown')
self.assertFalse(result['replayed'])
diff --git a/libs/cua-driver/hyprland-plugin/tests/production_desktop_fault_proof.py b/libs/cua-driver/hyprland-plugin/tests/production_desktop_fault_proof.py
index 92e6dab315..64e85f40d6 100644
--- a/libs/cua-driver/hyprland-plugin/tests/production_desktop_fault_proof.py
+++ b/libs/cua-driver/hyprland-plugin/tests/production_desktop_fault_proof.py
@@ -663,7 +663,7 @@ def run(args):
report['scope'] = 'native-' + plan['fault']['kind'].replace('_', '-')
assert args.trace_socket.name in ('cua-input-v3.sock', 'cua-input-v3-2.sock')
origin = provenance(args, plan)
- for name in ('production_desktop_fault_proof.py', 'production_desktop_fault_proof_test.py',
+ for name in ('production_desktop_fault_proof.py', 'production_desktop_fault_proof_test.py', 'proof_fixtures.py',
'production_geometry_fault_proof.py', 'production_cancel_proof.py',
'input_config_toggle.py', 'desktop_faults.py'):
path = Path(__file__).with_name(name)
diff --git a/libs/cua-driver/hyprland-plugin/tests/production_desktop_fault_proof_test.py b/libs/cua-driver/hyprland-plugin/tests/production_desktop_fault_proof_test.py
index 0556d7797c..ea7f7ee052 100644
--- a/libs/cua-driver/hyprland-plugin/tests/production_desktop_fault_proof_test.py
+++ b/libs/cua-driver/hyprland-plugin/tests/production_desktop_fault_proof_test.py
@@ -12,8 +12,7 @@ import unittest
from unittest.mock import Mock, patch
import production_desktop_fault_proof as proof
-from production_geometry_fault_proof_test import (ACTIVE, CANCEL, BOUNDS, action,
- client, plan as geometry_plan, trace)
+from proof_fixtures import ACTIVE, BOUNDS, CANCEL, action, client, geometry_plan, inkscape_profile, trace
def plan(kind='config_disable'):
@@ -352,10 +351,10 @@ class MotionGateTests(unittest.TestCase):
with self.assertRaisesRegex(AssertionError, 'history'):
proof.poll_fault_active(Mock(collect=Mock(side_effect=[first, changed])), trace(ACTIVE[:1]),
Mock(done=Mock(return_value=False)), 12)
- for field, value in (('overflow', True), ('timed_out', True), ('active', False), ('hook', False), ('count', 0)):
- with self.subTest(field=field), self.assertRaises(AssertionError):
- proof.poll_fault_active(Mock(collect=Mock(return_value={**motion_trace(), field: value})),
- trace(ACTIVE[:1]), Mock(done=Mock(return_value=False)), 12)
+ # Page validity is owned by trace_interval (realapp TraceIntervalTests); one case proves wiring.
+ with self.assertRaisesRegex(AssertionError, 'dropped events'):
+ proof.poll_fault_active(Mock(collect=Mock(return_value={**motion_trace(), 'overflow': True})),
+ trace(ACTIVE[:1]), Mock(done=Mock(return_value=False)), 12)
with patch.object(proof.time, 'monotonic', side_effect=[0, .01, .02, .03, .04, .30]), \
self.assertRaisesRegex(AssertionError, 'stale'):
proof.poll_fault_active(Mock(collect=Mock(return_value=motion_trace())), trace(ACTIVE[:1]),
@@ -532,22 +531,18 @@ class OracleTests(unittest.TestCase):
proof.verify_fault(trace(late_release), record(), restoration(), action())
def test_reconnected_trace_must_be_complete_and_preserve_prefix(self):
- for key, value in (('overflow', True), ('timed_out', True), ('hook', False), ('active', False), ('count', 0)):
- with self.subTest(key=key), self.assertRaises(AssertionError):
- proof.verify_fault({**trace(CANCEL), key: value}, record(), restoration(), action())
+ # Page validity is owned by trace_interval (realapp TraceIntervalTests); one case proves wiring.
+ with self.assertRaisesRegex(AssertionError, 'dropped events'):
+ proof.verify_fault({**trace(CANCEL), 'overflow': True}, record(), restoration(), action())
for page in (trace(CANCEL[5:]), trace(CANCEL)):
page['events'][1][1] += 1
with self.assertRaises(AssertionError):
proof.verify_fault(page, record(), restoration(), action())
- def test_primary_input_focus_and_transient_warp_fail(self):
- for kind, value in (('pointer_button', 0), ('keyboard_key', 1), ('pointer_axis', 0), ('pointer_focus', 0)):
- with self.subTest(kind=kind), self.assertRaises(AssertionError):
- proof.verify_fault(trace(CANCEL + [(11, kind, 0, value)]), record(), restoration(), action())
- page = trace(CANCEL + [(11, 'cursor', 0, 0), (12, 'cursor', 0, 0)])
- page['events'][-2][3] += 5
- with self.assertRaises(AssertionError):
- proof.verify_fault(page, record(), restoration(), action())
+ def test_primary_input_fails_the_fault(self):
+ # Primary classification is owned by primary_trace_test; one case proves wiring.
+ with self.assertRaisesRegex(AssertionError, "'result': 'failed'"):
+ proof.verify_fault(trace(CANCEL + [(11, 'keyboard_key', 0, 1)]), record(), restoration(), action())
def test_exact_fault_bytes_and_restoration_required(self):
for key, value in (('result', 'unproven'), ('kind', 'keymap'), ('config', {'sha256': 'bad'})):
@@ -559,6 +554,13 @@ class OracleTests(unittest.TestCase):
class SafetyTests(unittest.TestCase):
+ def test_inkscape_only_profile_reaches_the_shared_app_profile_gate(self):
+ candidate = inkscape_profile(plan())
+ proof.validate_plan(candidate)
+ candidate['agents'][0]['document'] = '/synthetic/private.svg'
+ with self.assertRaisesRegex(AssertionError, 'absolute synthetic SVG document'):
+ proof.validate_plan(candidate)
+
def test_plan_rejects_other_faults_and_incomplete_identity(self):
proof.validate_plan(plan())
for change in ({'disposable': False}, {'fault': {'kind': 'keymap'}}, {'fault': {'kind': 'dpms'}},
diff --git a/libs/cua-driver/hyprland-plugin/tests/production_geometry_fault_proof.py b/libs/cua-driver/hyprland-plugin/tests/production_geometry_fault_proof.py
index 3b79b80328..53e8818849 100644
--- a/libs/cua-driver/hyprland-plugin/tests/production_geometry_fault_proof.py
+++ b/libs/cua-driver/hyprland-plugin/tests/production_geometry_fault_proof.py
@@ -318,7 +318,8 @@ def run(args):
assert args.trace_socket.name in ('cua-input-v3.sock', 'cua-input-v3-2.sock')
fault = GeometryFault(plan)
origin = provenance(args, plan)
- for name in ('production_geometry_fault_proof.py', 'production_geometry_fault_proof_test.py', 'production_cancel_proof.py'):
+ for name in ('production_geometry_fault_proof.py', 'production_geometry_fault_proof_test.py', 'proof_fixtures.py',
+ 'production_cancel_proof.py'):
path = Path(__file__).with_name(name)
origin['files'][name] = {'path': str(path.resolve()), 'sha256': hashlib.sha256(path.read_bytes()).hexdigest()}
save('provenance.json', origin)
diff --git a/libs/cua-driver/hyprland-plugin/tests/production_geometry_fault_proof_test.py b/libs/cua-driver/hyprland-plugin/tests/production_geometry_fault_proof_test.py
index 994ea10e0c..df43242e83 100644
--- a/libs/cua-driver/hyprland-plugin/tests/production_geometry_fault_proof_test.py
+++ b/libs/cua-driver/hyprland-plugin/tests/production_geometry_fault_proof_test.py
@@ -9,33 +9,8 @@ import unittest
from unittest.mock import Mock, patch
import production_geometry_fault_proof as proof
-
-
-BOUNDS = {'x': 10, 'y': 20, 'width': 800, 'height': 600}
-PARTIAL = {'structuredContent': {'effect': 'partial', 'route': 'synthetic_events',
- 'delivery': {'mode': 'background', 'delivered_count': 1}}}
-DELIVERED = {'structuredContent': {'effect': 'unverifiable', 'route': 'synthetic_events',
- 'delivery': {'mode': 'background'}}}
-
-
-def plan(kind='move', app='calc'):
- return {'purpose': 'geometry_fault', 'disposable': True, 'compositor': {'pid': 50, 'instance': 'test_1'},
- 'foreground': {'pid': 10, 'window_id': 100}, 'primary_point': [20, 20],
- 'agents': [{'app': app, 'name': 'geometry', 'target': {'pid': 20, 'window_id': 200},
- 'bounds': dict(BOUNDS), 'pointer_stage': proof.POINTER_STAGES[app], 'drag': {}}],
- 'fault': {'kind': kind, 'to': [30, 40] if kind == 'move' else [820, 620]},
- 'recovery': {'pointer_stage': 'click_b2' if app == 'calc' else 'scroll_down'}}
-
-
-def trace(rows, active=True):
- return {'hook': True, 'active': active, 'overflow': False, 'timed_out': False, 'count': len(rows),
- 'events': [[i + 1, ms * 1_000_000, kind, 100, 100, lane, value]
- for i, (ms, kind, lane, value) in enumerate(rows)]}
-
-
-ACTIVE = [(0, 'start', 0, 0), (1, 'agent_admitted', 1, 0), (2, 'agent_drag_start', 1, 0),
- (3, 'pointer_button', 1, 1), (4, 'pointer_motion', 1, 0)]
-CANCEL = ACTIVE + [(8, 'agent_cancel', 1, 0), (9, 'pointer_button', 1, 0), (10, 'pointer_leave', 1, 0)]
+from proof_fixtures import (ACTIVE, BOUNDS, CANCEL, DELIVERED, PARTIAL, action, client, geometry_plan as plan,
+ inkscape_profile, trace)
def record():
@@ -45,16 +20,6 @@ def record():
'before_bounds': dict(BOUNDS), 'expected_bounds': {**BOUNDS, 'x': 30, 'y': 40}}
-def action(response=PARTIAL):
- return {'outcome': 'response', 'response': deepcopy(response), 'replayed': False}
-
-
-def client(pid, alive=True):
- process = Mock(pid=pid, poll=Mock(return_value=None if alive else 0))
- process.kill.side_effect = lambda: setattr(process.poll, 'return_value', -9)
- return Mock(process=process)
-
-
class OracleTests(unittest.TestCase):
def test_partial_and_unknown_preserve_delivery_uncertainty(self):
for observed in (action(), {'outcome': 'unknown', 'error': 'lost reply', 'replayed': False},
@@ -70,24 +35,20 @@ class OracleTests(unittest.TestCase):
proof.fault_outcome({**action(), 'replayed': True})
def test_incomplete_and_discontinuous_telemetry_cannot_pass(self):
- for key, value in [('hook', False), ('active', False), ('overflow', True), ('timed_out', True), ('count', 0)]:
- with self.subTest(key=key), self.assertRaises(AssertionError):
- proof.verify_fault({**trace(CANCEL), key: value}, record(), action())
+ # Page validity is owned by trace_interval (realapp TraceIntervalTests); one case proves wiring.
+ with self.assertRaisesRegex(AssertionError, 'dropped events'):
+ proof.verify_fault({**trace(CANCEL), 'overflow': True}, record(), action())
changed = trace(CANCEL)
changed['events'][1][1] += 1
with self.assertRaisesRegex(AssertionError, 'history'):
proof.verify_fault(changed, record(), action())
- def test_primary_warp_and_input_leak_fail_even_with_equal_endpoints(self):
- for kind, lane, value in [('cursor', 0, 0), ('pointer_focus', 0, 0), ('pointer_button', 0, 0),
- ('keyboard_key', 0, 1), ('pointer_axis', 0, 0)]:
- rows = trace(CANCEL + [(12, kind, lane, value), (13, 'pointer_leave', 1, 0)])
- if kind == 'cursor':
- rows['events'][-2][3] += 1
- rows['events'][-1][2] = 'cursor' # Warp back: endpoint-only checks would miss it.
- rows['events'][-1][5] = 0
- with self.subTest(kind=kind), self.assertRaises(AssertionError):
- proof.verify_fault(rows, record(), action())
+ def test_primary_warp_fails_even_with_equal_endpoints(self):
+ # Primary classification is owned by primary_trace_test; one warp proves wiring.
+ rows = trace(CANCEL + [(12, 'cursor', 0, 0), (13, 'cursor', 0, 0)])
+ rows['events'][-2][3] += 1 # Warp back: endpoint-only checks would miss it.
+ with self.assertRaisesRegex(AssertionError, "'result': 'failed'"):
+ proof.verify_fault(rows, record(), action())
def test_own_lane_cancellation_release_and_no_continuation_required(self):
mutations = [ACTIVE, CANCEL[:5] + CANCEL[6:], CANCEL[:6] + CANCEL[7:],
@@ -124,6 +85,13 @@ class OracleTests(unittest.TestCase):
class OwnershipTests(unittest.TestCase):
+ def test_inkscape_only_profile_reaches_the_shared_app_profile_gate(self):
+ candidate = inkscape_profile(plan())
+ proof.validate_plan(candidate)
+ candidate['agents'][0]['document'] = '/synthetic/private.svg'
+ with self.assertRaisesRegex(AssertionError, 'absolute synthetic SVG document'):
+ proof.validate_plan(candidate)
+
def test_resize_keeps_center_not_top_left_and_inverse_restores_exact_frame(self):
before = {'x': 983, 'y': 576, 'width': 480, 'height': 480}
smaller = {'x': 987, 'y': 580, 'width': 472, 'height': 472}
diff --git a/libs/cua-driver/hyprland-plugin/tests/production_idle_reconnect_proof.py b/libs/cua-driver/hyprland-plugin/tests/production_idle_reconnect_proof.py
index 25b94ddb2f..19bd80511b 100644
--- a/libs/cua-driver/hyprland-plugin/tests/production_idle_reconnect_proof.py
+++ b/libs/cua-driver/hyprland-plugin/tests/production_idle_reconnect_proof.py
@@ -288,7 +288,7 @@ def run(args):
validate_plan(plan)
assert args.trace_socket.name in ('cua-input-v3.sock', 'cua-input-v3-2.sock')
origin = provenance(args, plan)
- for name in ('production_idle_reconnect_proof.py', 'production_idle_reconnect_proof_test.py',
+ for name in ('production_idle_reconnect_proof.py', 'production_idle_reconnect_proof_test.py', 'proof_fixtures.py',
'production_cancel_proof.py'):
path = Path(__file__).with_name(name)
origin['files'][name] = {'path': str(path.resolve()), 'sha256': hashlib.sha256(path.read_bytes()).hexdigest()}
diff --git a/libs/cua-driver/hyprland-plugin/tests/production_idle_reconnect_proof_test.py b/libs/cua-driver/hyprland-plugin/tests/production_idle_reconnect_proof_test.py
index 54e4571042..0d097d6864 100644
--- a/libs/cua-driver/hyprland-plugin/tests/production_idle_reconnect_proof_test.py
+++ b/libs/cua-driver/hyprland-plugin/tests/production_idle_reconnect_proof_test.py
@@ -9,6 +9,7 @@ import unittest
from unittest.mock import Mock, patch
import production_idle_reconnect_proof as proof
+from proof_fixtures import inkscape_profile
BOUNDS = {'x': 0, 'y': 0, 'width': 800, 'height': 600}
@@ -80,8 +81,8 @@ class ExpiryTests(unittest.TestCase):
with self.assertRaisesRegex(AssertionError, '85 seconds'):
proof.wait_for_idle_expiry(value, runtime(value), status(), 1, 0, Mock(),
read_status=lambda: status(), now=clock.now, sleep=clock.sleep)
- self.assertLessEqual(clock.ns + proof.STATUS_READ_BUDGET_NS - 1_000_000_000, 85_000_000_000)
- self.assertGreaterEqual(clock.ns, 60_000_000_000)
+ # 1 s polls stop once a 5 s status read could end after the 85 s deadline.
+ self.assertEqual(clock.ns, 81_000_000_000)
value.tool.assert_not_called()
def test_early_disconnect_and_ambiguous_expiry_fail_closed(self):
@@ -223,18 +224,12 @@ class ClickTests(unittest.TestCase):
class IdentityAndPlanTests(unittest.TestCase):
- def test_target_and_geometry_checks_use_real_snapshot_helper(self):
- spec = {**plan()['agents'][0], 'pointer_stage': 'click_b2'}
- for window, bounds in [({'pid': 20, 'window_id': 201}, BOUNDS),
- ({'pid': 21, 'window_id': 200}, BOUNDS),
- ({'pid': 20, 'window_id': 200}, {**BOUNDS, 'x': 1})]:
- value = client()
- value.tool.side_effect = [
- {'structuredContent': {'windows': [window]}},
- {'structuredContent': {'window_bounds': bounds, 'screenshot_width': 800, 'screenshot_height': 600}}]
- with self.subTest(window=window, bounds=bounds), self.assertRaises(AssertionError):
- proof.grounded_snapshot(value, spec['target'], spec)
- self.assertTrue(all(call.args[0] != 'click' for call in value.tool.call_args_list))
+ def test_inkscape_only_profile_reaches_the_shared_app_profile_gate(self):
+ candidate = inkscape_profile(plan(), drag=False)
+ proof.validate_plan(candidate)
+ candidate['agents'][0]['document'] = '/synthetic/private.svg'
+ with self.assertRaisesRegex(AssertionError, 'absolute synthetic SVG document'):
+ proof.validate_plan(candidate)
def test_runtime_object_pid_and_liveness_are_fixed(self):
original = client()
diff --git a/libs/cua-driver/hyprland-plugin/tests/production_lock_refusal_proof.py b/libs/cua-driver/hyprland-plugin/tests/production_lock_refusal_proof.py
index 0d8a4ce836..67d0156810 100644
--- a/libs/cua-driver/hyprland-plugin/tests/production_lock_refusal_proof.py
+++ b/libs/cua-driver/hyprland-plugin/tests/production_lock_refusal_proof.py
@@ -376,7 +376,8 @@ def run(args):
validate_plan(plan)
fixture = LockFixture(plan, args)
origin = provenance(args, plan)
- for name in (Path(__file__).name, 'production_lock_refusal_proof_test.py', 'session_lock_fixture.c',
+ for name in (Path(__file__).name, 'production_lock_refusal_proof_test.py', 'proof_fixtures.py',
+ 'session_lock_fixture.c',
'production_session_fault_proof.py', 'production_desktop_fault_proof.py',
'desktop_faults.py', 'production_cancel_proof.py'):
path = Path(__file__).with_name(name)
diff --git a/libs/cua-driver/hyprland-plugin/tests/production_lock_refusal_proof_test.py b/libs/cua-driver/hyprland-plugin/tests/production_lock_refusal_proof_test.py
index ed78e2aeb7..35c37ee4ef 100644
--- a/libs/cua-driver/hyprland-plugin/tests/production_lock_refusal_proof_test.py
+++ b/libs/cua-driver/hyprland-plugin/tests/production_lock_refusal_proof_test.py
@@ -12,13 +12,7 @@ import unittest
from unittest.mock import Mock, patch
import production_lock_refusal_proof as proof
-from production_session_fault_proof_test import plan as session_plan, status, trace, REFUSED, retained_status
-
-
-def plan():
- return {**session_plan(), 'purpose': 'lock_refusal', 'fault': {'kind': 'lock'},
- 'lock_fixture': {'path': '/test/session_lock_fixture', 'device': 1, 'inode': 2,
- 'uid': 1000, 'sha256': 'b' * 64, 'source_sha256': 'c' * 64}}
+from proof_fixtures import REFUSED, inkscape_profile, lock_plan as plan, retained_status, status, trace
def refusal():
@@ -29,7 +23,27 @@ def refusal():
'trace_before': trace([(3, 'start', 0, 0)]), 'trace_after': trace([(3, 'start', 0, 0)])}
+def locked_fixture():
+ """A lock helper that has acknowledged LOCK and awaits restoration."""
+ fixture = object.__new__(proof.LockFixture)
+ fixture.child = Mock(stdin=io.BytesIO(), stdout=Mock(), wait=Mock(return_value=0))
+ fixture.events = [{'event': 'locked', 'observed_ns': 10}]
+ fixture.record = {'after': status(2)}
+ fixture.requested, fixture.restored = True, False
+ fixture.deadline_ns = 100
+ fixture.config = {}
+ fixture.locked = Mock()
+ return fixture
+
+
class PlanTests(unittest.TestCase):
+ def test_inkscape_only_profile_reaches_the_shared_app_profile_gate(self):
+ candidate = inkscape_profile(plan())
+ proof.validate_plan(candidate)
+ candidate['agents'][0]['document'] = '/synthetic/private.svg'
+ with self.assertRaisesRegex(AssertionError, 'absolute synthetic SVG document'):
+ proof.validate_plan(candidate)
+
def test_lock_preflight_accepts_only_inert_unreserved_hover_before_launch(self):
for reserved in (False, True):
with self.subTest(reserved=reserved), tempfile.TemporaryDirectory() as directory:
@@ -135,6 +149,19 @@ class PlanTests(unittest.TestCase):
class OracleTests(unittest.TestCase):
+ def test_new_action_dispatch_uses_scroll_without_drag_or_replay(self):
+ for tool in ('click', 'scroll', 'drag'):
+ actor = Mock()
+ record = {'outcome': 'unknown', 'replayed': False, 'prepared_ns': 1, 'tool': tool}
+ with self.subTest(tool=tool), patch.object(proof.time, 'monotonic_ns', return_value=2):
+ if tool == 'drag':
+ with self.assertRaisesRegex(AssertionError, 'only a new non-drag action'):
+ proof.click_once(actor, {'x': 1}, record, Mock(), 'action')
+ actor.tool.assert_not_called()
+ else:
+ proof.click_once(actor, {'x': 1}, record, Mock(), 'action')
+ actor.tool.assert_called_once_with(tool, {'x': 1})
+
def test_prelock_refresh_is_bounded_and_retains_actual_observations(self):
spec = {**plan()['agents'][0], 'pointer_stage': 'click_b2'}
for age in (1_000_000_000, 3_750_000_000, 3_750_000_001, 6_000_000_000):
@@ -268,14 +295,6 @@ class OracleTests(unittest.TestCase):
self.assertEqual(saved[-1][1]['observed_ns'], 3)
self.assertFalse(saved[-1][1]['replayed'])
- def test_saving_evidence_cannot_allow_expired_grounding_to_dispatch(self):
- client = Mock()
- record = {'outcome': 'unknown', 'replayed': False, 'prepared_ns': 1}
- with patch.object(proof.time, 'monotonic_ns', return_value=proof.MAX_GROUNDING_AGE_NS + 2), \
- self.assertRaisesRegex(AssertionError, 'grounding expired'):
- proof.click_once(client, {}, record, Mock(), 'attempt.json')
- client.tool.assert_not_called()
-
def test_new_runtime_allows_reaped_refusal_but_rejects_reuse_or_live_closed_process(self):
def runtime(pid, closed=False, exited=False):
return SimpleNamespace(closed=closed, process=Mock(pid=pid, poll=Mock(return_value=0 if exited else None)))
@@ -409,19 +428,8 @@ class FixtureTests(unittest.TestCase):
self.assertRaises(AssertionError):
proof.settle_locked(fixture)
- def fixture(self):
- fixture = object.__new__(proof.LockFixture)
- fixture.child = Mock(stdin=io.BytesIO(), stdout=Mock(), wait=Mock(return_value=0))
- fixture.events = [{'event': 'locked', 'observed_ns': 10}]
- fixture.record = {'after': status(2)}
- fixture.requested, fixture.restored = True, False
- fixture.deadline_ns = 100
- fixture.config = {}
- fixture.locked = Mock()
- return fixture
-
def test_restore_requires_protocol_ack_and_successful_exit_never_kill(self):
- fixture = self.fixture()
+ fixture = locked_fixture()
def acknowledgement():
event = {'event': 'unlocked', 'observed_ns': 50}
fixture.events.append(event)
@@ -438,7 +446,7 @@ class FixtureTests(unittest.TestCase):
def test_missing_ack_or_deadline_unlock_cannot_pass(self):
for failure in ('missing_ack', 'early_ack', 'deadline', 'bad_exit'):
- fixture = self.fixture()
+ fixture = locked_fixture()
event = {'event': 'unlocked', 'observed_ns': 30 if failure == 'early_ack' else 110 if failure == 'deadline' else 50}
def acknowledgement():
fixture.events.append(event)
@@ -458,7 +466,7 @@ class FixtureTests(unittest.TestCase):
fixture.child.wait.assert_called_once()
def test_failed_lock_guard_still_closes_stdin_and_reaps(self):
- fixture = self.fixture()
+ fixture = locked_fixture()
fixture.locked.side_effect = AssertionError('already unlocked')
with patch.object(proof.time, 'monotonic_ns', return_value=40), \
self.assertRaisesRegex(AssertionError, 'already unlocked'):
@@ -469,7 +477,7 @@ class FixtureTests(unittest.TestCase):
fixture.child.terminate.assert_not_called()
def test_cleanup_waits_for_independent_deadline_without_signaling(self):
- fixture = self.fixture()
+ fixture = locked_fixture()
fixture.deadline_ns = 20_000_000_000
fixture.read_event = Mock()
fixture.child.wait.side_effect = subprocess.TimeoutExpired('session_lock_fixture', 22)
@@ -484,7 +492,7 @@ class FixtureTests(unittest.TestCase):
self.assertFalse(fixture.restored)
def test_event_reader_retains_protocol_evidence_and_rejects_bad_clock(self):
- fixture = self.fixture()
+ fixture = locked_fixture()
fixture.events = []
fixture.buffer = b'{"event":"ready","observed_ns":10}\n'
with patch.object(proof.time, 'monotonic_ns', return_value=20):
@@ -495,7 +503,7 @@ class FixtureTests(unittest.TestCase):
self.assertEqual(len(fixture.events), 1)
def test_partial_event_never_blocks_on_readline(self):
- fixture = self.fixture()
+ fixture = locked_fixture()
fixture.events, fixture.buffer = [], b''
with patch.object(proof.select, 'select', side_effect=[([fixture.child.stdout], [], []), ([], [], [])]), \
patch.object(proof.os, 'read', return_value=b'{"event":"locked"'):
@@ -576,7 +584,7 @@ class RetainedPointerTests(unittest.TestCase):
patch.object(proof.time, 'monotonic_ns', side_effect=[1, 100_000_001]), \
patch.object(proof, 'wait_for', side_effect=sample_twice):
self.assertEqual(proof.settle_locked(settling)['status'], retained_status())
- fixture = FixtureTests().fixture()
+ fixture = locked_fixture()
fixture.config['pointer_cleanup'] = 'retained_inert'
fixture.record['after'] = retained_status(2)
fixture.events = [{'event': 'locked', 'observed_ns': 2}]
@@ -595,7 +603,6 @@ class RetainedPointerTests(unittest.TestCase):
self.assertEqual(fixture.restore()['result'], 'restored')
fixture.child.kill.assert_not_called()
fixture.child.terminate.assert_not_called()
- self.assertEqual(proof.LOCK_MS, 20000)
if __name__ == '__main__':
diff --git a/libs/cua-driver/hyprland-plugin/tests/production_pointer_grounding_test.py b/libs/cua-driver/hyprland-plugin/tests/production_pointer_grounding_test.py
index 1351876b81..ba8fe567a3 100644
--- a/libs/cua-driver/hyprland-plugin/tests/production_pointer_grounding_test.py
+++ b/libs/cua-driver/hyprland-plugin/tests/production_pointer_grounding_test.py
@@ -3,27 +3,7 @@ import copy
import unittest
import production_pointer_grounding as pointer
-from production_app_smoke_test import INKSCAPE, INKSCAPE_SELECTED
-from primary_trace_test import START, STOP, trace
-
-
-class Image:
- width = height = 500
-
- def __init__(self):
- self.points = {}
-
- def rgb(self, x, y):
- assert 0 <= x < self.width and 0 <= y < self.height
- return self.points.get((x, y), (255, 255, 255))
-
- def rectangle(self, x, y, w, h):
- self.points.update({(a, b): (51, 102, 153) for a in range(x, x + w) for b in range(y, y + h)})
-
-
-def snapshot(app):
- return {'window_title': f'cua-smoke-{app}', 'window_bounds': {'x': 600, 'y': 400, 'width': 500, 'height': 500},
- 'screenshot_width': 500, 'screenshot_height': 500}
+from proof_fixtures import START, STOP, Image, app_snapshot as snapshot, ink, primary_trace as trace
def calc(selection='A2', scroll=0):
@@ -56,23 +36,6 @@ def highlighted_calc():
return state, image
-def ink(selected=True, dx=0, dy=0, scroll_y=0):
- state = {**snapshot('inkscape'), **copy.deepcopy(INKSCAPE_SELECTED if selected else INKSCAPE)}
- if selected:
- for row in state['elements']:
- if row['role'] == 'spin button':
- row['frame'] = {'x': 700, 'y': 435, 'w': 100, 'h': 34}
- for index, value in ((2, 40 + dx * .8), (3, 60 + dy * .8)):
- row = next(row for row in state['elements'] if row['element_index'] == index)
- state['tree_markdown'] = state['tree_markdown'].replace(
- f'[{index}] spin button "{row["label"]}" value="{row["value"]}"',
- f'[{index}] spin button "{value:.3f}" value="{value:.1f}"')
- row.update(label=f'{value:.3f}', value=f'{value:.1f}')
- image = Image()
- image.rectangle(120 + dx, 150 + dy + scroll_y, 100, 60)
- return state, image
-
-
class PointerGroundingTests(unittest.TestCase):
def test_recovery_scroll_chooses_visible_space_before_input(self):
for offset, expected, movement in ((21, 'scroll_up', 80), (160, 'scroll_down', -80)):
diff --git a/libs/cua-driver/hyprland-plugin/tests/production_policy_proof_test.py b/libs/cua-driver/hyprland-plugin/tests/production_policy_proof_test.py
index 4c29f59ac0..13386c4553 100644
--- a/libs/cua-driver/hyprland-plugin/tests/production_policy_proof_test.py
+++ b/libs/cua-driver/hyprland-plugin/tests/production_policy_proof_test.py
@@ -10,13 +10,35 @@ import unittest
from unittest.mock import Mock, patch
from production_app_smoke import GroundingUnavailable, create_documents
-from production_app_smoke_test import CALC, INKSCAPE, INKSCAPE_SELECTED, changed_ods
+from proof_fixtures import CALC, INKSCAPE, INKSCAPE_SELECTED, changed_ods
from production_policy_proof import (
CASES, DENIALS, MANAGED_ENV, SMOKE_STEPS, check_refusal, documents_for_case,
expected_refusal, run, snapshot, start_client, validate_plan, verify_evidence,
)
+# cua-driver-core: policy.rs:391 via authorize_policy_layers ("{name} policy: ...") and
+# AuthorizationError::Denied; consent.rs:101 around session_manifest.rs:309.
+OUTSIDE_MANIFEST = {'code': 'bounded_resource_outside_manifest',
+ 'message': 'protected resource is outside the capability manifest: '
+ 'desktop pid 20 window 200 is outside the capability manifest'}
+REFUSALS = {
+ ('managed_deny', 'calc'): {'code': 'permission_denied',
+ 'message': "Permission denied: managed policy: tool 'type_text' is explicitly denied"},
+ ('managed_deny', 'inkscape'): {'code': 'permission_denied',
+ 'message': "Permission denied: managed policy: tool 'hotkey' is explicitly denied"},
+ **{(case, app): OUTSIDE_MANIFEST for case in ('resource_wrong_pid', 'resource_wrong_window')
+ for app in ('calc', 'inkscape')},
+}
+
+
+def refusal(candidate):
+ expected = dict(REFUSALS[candidate['case'], candidate['app']])
+ target = candidate['target']
+ expected['message'] = expected['message'].replace('pid 20 window 200', f"pid {target['pid']} window {target['window_id']}")
+ return expected
+
+
def plan(case='resource_wrong_window', app='calc', mode='unrestricted'):
suffix = 'calc.ods' if app == 'calc' else 'inkscape.svg'
return {'case': case, 'app': app, 'mode': mode, 'disposable': True,
@@ -53,7 +75,7 @@ def evidence(candidate):
('keyboard_key', 0), ('agent_action_end', 0)]:
events.append([len(events) + 1, len(events), kind, 100, 100, 1, pressed])
response = ({'isError': True, 'structuredContent': {
- 'status': 'refused', 'refusal': expected_refusal(candidate)}} if denied else
+ 'status': 'refused', 'refusal': refusal(candidate)}} if denied else
{'structuredContent': {'effect': 'unverifiable', 'route': 'synthetic_events',
'delivery': {'mode': 'background'}}})
result['actions'].append({'stage': stage, 'tool': tool, 'phase': 'deny' if denied else 'control',
@@ -109,12 +131,18 @@ class PolicyTests(unittest.TestCase):
self.assertIsNone(manifest)
self.assertIsNone(managed)
continue
- target = manifest['resources']['desktop']['windows'][0]
- self.assertEqual(target['pid'], 21 if case == 'resource_wrong_pid' else 20)
- self.assertEqual(target['window_id'], 201 if case == 'resource_wrong_window' else 200)
- self.assertEqual('deny' in (managed or {}), case == 'managed_deny')
- self.assertEqual(manifest['version'], 3)
- self.assertTrue(manifest['expires_after'] and manifest['idle_timeout'])
+ # Literal reviewed documents; the evidence fixture above builds its own copy.
+ tools = ['get_window_state', 'type_text', 'press_key', 'hotkey']
+ window = {'pid': 21 if case == 'resource_wrong_pid' else 20,
+ 'window_id': 201 if case == 'resource_wrong_window' else 200}
+ self.assertEqual(manifest, {'version': 3, 'expires_after': '5m', 'idle_timeout': '2m',
+ 'allow': {'tools': tools},
+ 'resources': {'desktop': {'windows': [window]}}})
+ if case == 'managed_deny':
+ denied = 'type_text' if app == 'calc' else 'hotkey'
+ self.assertEqual(managed, {'allow': {'tools': tools}, 'deny': {'tools': [denied]}})
+ else:
+ self.assertEqual(managed, {'allow': {'tools': tools}} if case == 'managed_allow' else None)
def test_plan_rejects_scope_escape_and_non_synthetic_document(self):
mutations = [lambda p: p.update(disposable=False), lambda p: p.update(case='arbitrary'),
@@ -132,24 +160,28 @@ class PolicyTests(unittest.TestCase):
validate_plan(candidate)
def test_source_exact_envelope_and_admission_boundary(self):
- for case in DENIALS:
- expected = expected_refusal(plan(case))
+ for (case, app), expected in REFUSALS.items():
+ with self.subTest(case=case, app=app):
+ self.assertEqual(expected_refusal(plan(case, app)), expected)
core = {'isError': True, 'structuredContent': {'status': 'refused', 'refusal': expected}}
- check_refusal(core, expected)
- invalid = [dict(core, isError=False),
- dict(core, structuredContent={'effect': 'refused', 'reason': expected['code']}),
- dict(core, structuredContent={**core['structuredContent'], 'delivery': {'mode': 'background'}}),
- dict(core, structuredContent={'status': 'refused', 'refusal': {**expected, 'code': 'lane_busy'}}),
- dict(core, content=[{'type': 'text', 'text': 'Permission denied'}])]
- for result in invalid:
- with self.subTest(case=case, result=result), self.assertRaises(AssertionError):
+ self.assertEqual(check_refusal(core, expected),
+ 'core-admission' if expected['code'] == 'permission_denied' else 'core-resource-admission')
+ invalid = [(dict(core, isError=False), 'must be an MCP error'),
+ (dict(core, structuredContent={'effect': 'refused', 'reason': expected['code']}), 'common policy refusal'),
+ (dict(core, structuredContent={**core['structuredContent'], 'delivery': {'mode': 'background'}}),
+ 'common policy refusal'),
+ (dict(core, structuredContent={'status': 'refused', 'refusal': {**expected, 'code': 'lane_busy'}}),
+ 'common policy refusal'),
+ (dict(core, content=[{'type': 'text', 'text': 'Permission denied'}]), 'conflicting refusal text')]
+ for result, error in invalid:
+ with self.subTest(case=case, app=app, result=result), self.assertRaisesRegex(AssertionError, error):
check_refusal(result, expected)
- expected = expected_refusal(plan('managed_deny'))
+ expected = REFUSALS['managed_deny', 'calc']
flat = {'isError': True, 'structuredContent': {'code': 'permission_denied'},
'content': [{'type': 'text', 'text': expected['message']}]}
self.assertEqual(check_refusal(flat, expected), 'mcp-tool-admission')
flat['content'][0]['text'] = expected['message'].replace('managed', 'user')
- with self.assertRaises(AssertionError):
+ with self.assertRaisesRegex(AssertionError, 'wrong MCP permission refusal'):
check_refusal(flat, expected)
def test_policy_injection_is_process_local_restored_and_never_overwrites_host_ceiling(self):
@@ -179,8 +211,12 @@ class PolicyTests(unittest.TestCase):
class OracleTests(unittest.TestCase):
def test_only_inkscape_snapshots_bound_visited_nodes_and_keep_images_and_depth(self):
- for app in ('calc', 'inkscape'):
- for stage in SMOKE_STEPS[app]:
+ # Inkscape select/move grounding needs the full tree before input; later reads are bounded.
+ bounded = {('inkscape', 'select', False), ('inkscape', 'move', False),
+ ('inkscape', 'save', True), ('inkscape', 'save', False)}
+ for app, stages in (('calc', ('insert', 'commit', 'save')), ('inkscape', ('select', 'move', 'save'))):
+ self.assertEqual(tuple(SMOKE_STEPS[app]), stages)
+ for stage in stages:
for before in (True, False):
with self.subTest(app=app, stage=stage, before=before):
candidate = plan(app=app)
@@ -190,7 +226,7 @@ class OracleTests(unittest.TestCase):
{'structuredContent': {'windows': [candidate['target']]}}, expected]
self.assertEqual(snapshot(client, candidate, stage=stage, before=before), expected)
arguments = {**candidate['target'], 'session': 'policy-proof'}
- if app == 'inkscape' and not (stage in ('select', 'move') and before):
+ if (app, stage, before) in bounded:
arguments['max_elements'] = 2500
client.tool.assert_called_with('get_window_state', arguments)
@@ -425,9 +461,9 @@ class OrchestrationTests(unittest.TestCase):
[('observer', 'list_windows'), (observer, 'get_window_state')])
def test_inkscape_missing_grounding_stops_before_dispatch_without_retry(self):
+ # Missing selection before Right is owned by the next test.
for missing, expected_actions in ((('observer', 'select'), []),
- (('control', 'select'), [('denied', 'hotkey')]),
- (('control', 'move'), [('denied', 'hotkey'), ('control', 'hotkey')])):
+ (('control', 'select'), [('denied', 'hotkey')])):
with self.subTest(missing=missing), tempfile.TemporaryDirectory() as temporary:
status, report, calls, clients = self.exercise(
Path(temporary), app='inkscape', missing_grounding=missing)
diff --git a/libs/cua-driver/hyprland-plugin/tests/production_primary_conflict_proof.py b/libs/cua-driver/hyprland-plugin/tests/production_primary_conflict_proof.py
index 62d31f6960..39d6432e61 100644
--- a/libs/cua-driver/hyprland-plugin/tests/production_primary_conflict_proof.py
+++ b/libs/cua-driver/hyprland-plugin/tests/production_primary_conflict_proof.py
@@ -289,7 +289,7 @@ def run(args):
desktop = ExactDesktop(plan)
app_process_identity(spec['app'], spec['target']['pid'])
origin = provenance(args, plan)
- for name in (Path(__file__).name, 'production_primary_conflict_proof_test.py',
+ for name in (Path(__file__).name, 'production_primary_conflict_proof_test.py', 'proof_fixtures.py',
'desktop_faults.py', 'production_cancel_proof.py',
'production_desktop_fault_proof.py', 'production_geometry_fault_proof.py'):
path = Path(__file__).with_name(name)
diff --git a/libs/cua-driver/hyprland-plugin/tests/production_primary_conflict_proof_test.py b/libs/cua-driver/hyprland-plugin/tests/production_primary_conflict_proof_test.py
index 87310f1f9f..a7152b576b 100644
--- a/libs/cua-driver/hyprland-plugin/tests/production_primary_conflict_proof_test.py
+++ b/libs/cua-driver/hyprland-plugin/tests/production_primary_conflict_proof_test.py
@@ -9,55 +9,15 @@ import unittest
from unittest.mock import Mock, patch
import production_primary_conflict_proof as proof
+from proof_fixtures import (BOUNDS, DELIVERED, client, conflict_trace as trace, identity, inkscape_profile,
+ primary_conflict_plan as plan, status)
-BOUNDS = {'x': 10, 'y': 20, 'width': 800, 'height': 600}
REFUSED = {'isError': True, 'structuredContent': {'effect': 'refused', 'reason': 'primary_target_busy', 'lane': 0}}
-DELIVERED = {'structuredContent': {'effect': 'unverifiable', 'route': 'synthetic_events',
- 'delivery': {'mode': 'background'}}}
-
-
-def identity(pid, name='app'):
- return {'pid': pid, 'uid': 1000, 'starttime': '123', 'exe': '/usr/bin/' + name}
-
-
-def plan(app='calc'):
- return {'purpose': 'primary_conflict', 'case': 'initial_refusal', 'disposable': True,
- 'vm': {'machine_id': 'a' * 32, 'boot_id': 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa'},
- 'compositor': {**identity(50, 'Hyprland'), 'instance': 'test_1'},
- 'processes': {'target': identity(20), 'foreground': identity(10)},
- 'foreground': {'pid': 10, 'window_id': 100}, 'primary_point': [20, 20], 'package_versions': {},
- 'agents': [{'app': app, 'name': 'primary-conflict', 'target': {'pid': 20, 'window_id': 200},
- 'bounds': dict(BOUNDS), 'pointer_stage': 'select_range' if app == 'calc' else 'move_rectangle', 'drag': {}}],
- 'recovery': {'pointer_stage': 'click_b2' if app == 'calc' else 'scroll_down'}}
-
-
-def trace(events=(), active=True):
- rows = [(0, 'start', 0, 0), *events]
- if not active:
- rows += [(20, 'stop', 0, 0)]
- return {'hook': True, 'active': active, 'overflow': False, 'timed_out': False, 'count': len(rows),
- 'events': [[i + 1, timestamp, kind, 30, 40, lane, value]
- for i, (timestamp, kind, lane, value) in enumerate(rows)]}
-
-
RECOVERY = [(1, 'agent_admitted', 1, 0), (2, 'pointer_button', 1, 1),
(3, 'pointer_button', 1, 0), (4, 'agent_action_end', 1, 0)]
-def status():
- return {'configured': True, 'transport': {'ready': True}, 'input': {
- 'protocol': 3, 'test_only': False, 'transport_ready': True,
- 'seat_lifetime': 'compositor', 'upgrade': 'desktop_restart', 'lanes': [
- {'lane': lane, 'held_button': 0, 'held_keys': 0, 'drag_active': False,
- 'lease_active': False, 'keyboard_focus': False, 'pointer_focus': False, 'reserved': False}
- for lane in (0, 1)]}}
-
-
-def client(pid):
- return Mock(directory=Path.cwd(), process=Mock(pid=pid, poll=Mock(return_value=None)))
-
-
class OracleTests(unittest.TestCase):
def test_refusal_keeps_only_its_connection_reservation_without_authority(self):
for lane in (0, 1):
@@ -98,21 +58,14 @@ class OracleTests(unittest.TestCase):
proof.verify_refusal(before, before, REFUSED)
def test_incomplete_or_rewritten_trace_cannot_pass(self):
- for key, value in (('hook', False), ('active', False), ('overflow', True), ('timed_out', True), ('count', 9)):
- with self.subTest(key=key), self.assertRaises(AssertionError):
- proof.verify_refusal(trace(), {**trace(), key: value}, REFUSED)
+ # Page validity is owned by trace_interval (realapp TraceIntervalTests); one case proves wiring.
+ with self.assertRaisesRegex(AssertionError, 'dropped events'):
+ proof.verify_refusal(trace(), {**trace(), 'overflow': True}, REFUSED)
changed = trace()
changed['events'][0][3] += 1
with self.assertRaisesRegex(AssertionError, 'history'):
proof.verify_refusal(trace(), changed, REFUSED)
- def test_trace_oracle_never_ignores_primary_input_or_warp_and_return(self):
- for kind in ('pointer_focus', 'keyboard_focus', 'pointer_button', 'keyboard_key', 'pointer_axis'):
- self.assertEqual(proof.analyze(trace([(1, kind, 0, 0)], active=False))['result'], 'failed')
- warped = trace([(1, 'cursor', 0, 0), (2, 'cursor', 0, 0)], active=False)
- warped['events'][1][3] += 20
- self.assertEqual(proof.analyze(warped)['result'], 'failed')
-
def test_current_held_state_and_preexisting_reservations_are_checked(self):
proof.clear_status(status(), unreserved=True)
for field, value in (('held_button', 272), ('held_keys', 1), ('held_keys', False),
@@ -138,11 +91,18 @@ class OracleTests(unittest.TestCase):
class OwnershipTests(unittest.TestCase):
+ def test_inkscape_only_profile_reaches_the_shared_app_profile_gate(self):
+ candidate = inkscape_profile(plan())
+ proof.validate_plan(candidate)
+ candidate['agents'][0]['document'] = '/synthetic/private.svg'
+ with self.assertRaisesRegex(AssertionError, 'absolute synthetic SVG document'):
+ proof.validate_plan(candidate)
+
def test_trace_requires_exact_socket_peer_and_unowned_trace(self):
path = Path('/run/user/1000/hypr/test_1/cua-input-v3.sock')
for failure in (None, 'peer', 'protocol', 'active', 'owner', 'alias'):
desktop = object.__new__(proof.ExactDesktop)
- desktop.instance, desktop.compositor = 'test_1', identity(50, 'Hyprland')
+ desktop.instance, desktop.compositor = 'test_1', identity(50, '/usr/bin/Hyprland')
desktop.guard = Mock()
tracer = Mock(hello={'protocol': 2 if failure == 'protocol' else 3})
tracer.collect.return_value = {'active': failure == 'active'}
@@ -188,7 +148,7 @@ class OwnershipTests(unittest.TestCase):
candidate = plan()
desktop = object.__new__(proof.ExactDesktop)
desktop.plan, desktop.instance = candidate, 'test_1'
- desktop.compositor = identity(50, 'Hyprland')
+ desktop.compositor = identity(50, '/usr/bin/Hyprland')
rows = deepcopy(windows)
if failure == 'address':
rows[0]['address'] = '0xc9'
@@ -218,8 +178,8 @@ class OwnershipTests(unittest.TestCase):
class ActionTests(unittest.TestCase):
def test_single_normal_call_fresh_snapshot_unknown_never_replayed(self):
for phase in ('refusal', 'recovery'):
- for failure in (None, 'guard', 'stale', 'unknown', 'same_snapshot', 'same_artifact', 'cached',
- 'before_return', 'same_runtime', 'effect', 'pre_activity',
+ # Freshness rules are owned by cancel's ObservationTests; 'cached' proves wiring.
+ for failure in (None, 'guard', 'stale', 'unknown', 'cached', 'same_runtime', 'effect', 'pre_activity',
'dead_before', 'dead_after', 'observation'):
if phase == 'refusal' and failure == 'effect':
continue
@@ -241,14 +201,8 @@ class ActionTests(unittest.TestCase):
'proof_observation_started_ns': 10, 'proof_observation_finished_ns': 20}
after = {**before, 'proof_runtime': {'pid': 102, 'directory': str(Path.cwd())},
'proof_image': 'after.png', 'proof_observation_started_ns': 50, 'proof_observation_finished_ns': 60}
- if failure == 'same_snapshot':
- after = dict(before)
- elif failure == 'same_artifact':
- after['proof_image'] = before['proof_image']
- elif failure == 'cached':
+ if failure == 'cached':
after.update(proof_observation_started_ns=10, proof_observation_finished_ns=20)
- elif failure == 'before_return':
- after['proof_observation_started_ns'] = 39
prepared = {'snapshot': before, 'arguments': {'x': 20, 'y': 30}, 'oracle': {'stage': 'click_b2'},
'prepared_ns': 10}
stack.enter_context(patch.object(proof, 'prepare_drag', return_value=prepared))
@@ -408,7 +362,7 @@ class RunTests(unittest.TestCase):
self.assertTrue((args.evidence / 'recovery-trace.json').exists())
self.assertEqual(set(report['phases']), {'refusal', 'recovery'})
files = json.loads((args.evidence / 'provenance.json').read_text())['files']
- for name in ('desktop_faults.py', 'production_cancel_proof.py',
+ for name in ('desktop_faults.py', 'production_cancel_proof.py', 'proof_fixtures.py',
'production_desktop_fault_proof.py', 'production_geometry_fault_proof.py'):
self.assertEqual(len(files[name]['sha256']), 64)
if failure == 'reserved_refusal':
diff --git a/libs/cua-driver/hyprland-plugin/tests/production_primary_observer_test.py b/libs/cua-driver/hyprland-plugin/tests/production_primary_observer_test.py
index 86b9fb35aa..36713464f7 100644
--- a/libs/cua-driver/hyprland-plugin/tests/production_primary_observer_test.py
+++ b/libs/cua-driver/hyprland-plugin/tests/production_primary_observer_test.py
@@ -15,10 +15,10 @@ import unittest
from unittest.mock import Mock, patch
from types import SimpleNamespace
-from primary_observer import (MAX_BYTES, PrimaryObserver, analyze, journal_rows,
+from primary_observer import (MAX_BYTES, MAX_INTERVAL_NS, PrimaryObserver, analyze, journal_rows,
primary_wire_state, sync_barrier, verify_negative_control, wire_rows)
from production_realapp_proof import run
-from production_realapp_proof_test import plan
+from proof_fixtures import harness_args, patch_module, plan, run_replacements
def wire(*lines):
@@ -209,24 +209,33 @@ class ObserverAnalysisTests(unittest.TestCase):
verify_negative_control(analyze(*values))
def test_full_interval_fresh_heartbeats_and_sync_callbacks_are_mandatory(self):
- for mutation in (
- lambda v: v[1]['identity'].update(pid=11),
- lambda v: v[1]['marker'].update(nonce='a' * 32),
- lambda v: v[1]['marker'].update(time=4_000_000_000),
- lambda v: v[4].append((1_999_999_999, 2_100_000_000)),
- lambda v: v[4].append((2_100_000_000, 2_300_000_000)),
- lambda v: v[4].clear(),
- lambda v: v[0]['marker'].update(held=False),
- lambda v: v[0]['marker'].update(canvas_focus=False),
- lambda v: v[0]['marker'].update(wire_end=len(BASE)),
+ def end_after(ns):
+ def mutate(values):
+ # The end marker is also the retained journal row.
+ values[1]['marker']['time'] = values[0]['marker']['time'] + ns
+ return mutate
+ for pattern, mutation in (
+ ('observer identity changed', lambda v: v[1]['identity'].update(pid=11)),
+ ('sync markers are not distinct', lambda v: v[1]['marker'].update(nonce='a' * 32)),
+ ('empty or exceeds its bound', end_after(0)),
+ ('empty or exceeds its bound', end_after(MAX_INTERVAL_NS + 1)),
+ ('heartbeat gap', end_after(MAX_INTERVAL_NS)),
+ ('does not cover', lambda v: v[4].append((1_999_999_999, 2_100_000_000))),
+ ('does not cover', lambda v: v[4].append((2_100_000_000, 2_300_000_000))),
+ ('does not cover', lambda v: v[4].clear()),
+ ('lacks the held primary grab', lambda v: v[0]['marker'].update(held=False)),
+ ('not focused', lambda v: v[0]['marker'].update(canvas_focus=False)),
+ ('do not bracket the wire log', lambda v: v[0]['marker'].update(wire_end=len(BASE))),
):
values = observation(DUPLICATES)
mutation(values)
- with self.assertRaises(AssertionError):
+ with self.subTest(pattern=pattern), self.assertRaisesRegex(AssertionError, pattern):
analyze(*values)
- for data in (b'', SYNC.replace(b'wl_callback#21.done(2)\n', b''),
+ # Drop the whole second callback record, not just its text: a truncated
+ # line would fail as an incomplete log before the barrier is checked.
+ for data in (b'', SYNC.replace(wire('wl_callback#21.done(2)'), b''),
SYNC.replace(b'wl_callback#21.done', b'wl_callback#22.done')):
- with self.assertRaises(AssertionError):
+ with self.subTest(data=data), self.assertRaisesRegex(AssertionError, 'missing complete independent Wayland sync'):
sync_barrier(data)
def test_baseline_requires_one_native_surface_with_proven_pointer_grab_and_idle_keyboard(self):
@@ -253,11 +262,8 @@ class ObserverAnalysisTests(unittest.TestCase):
class ObserverFileTests(unittest.TestCase):
- def test_fixture_help_is_portable_and_optimized_execution_is_refused(self):
+ def test_optimized_fixture_execution_is_refused(self):
fixture = Path(__file__).with_name('primary_observer_fixture.py')
- help_text = subprocess.check_output([sys.executable, str(fixture), '--help'], text=True, timeout=5)
- self.assertIn('--control', help_text)
- self.assertIn('--wire', help_text)
optimized = subprocess.run([sys.executable, '-O', str(fixture), '--help'], text=True,
capture_output=True, timeout=5)
self.assertNotEqual(optimized.returncode, 0)
@@ -267,7 +273,11 @@ class ObserverFileTests(unittest.TestCase):
with tempfile.TemporaryDirectory() as temporary:
source = Path(temporary) / 'fixture.py'
source.write_text('synthetic fixture')
- for fault in (None, 'peer', 'uid', 'nonce', 'stale', 'future', 'source', 'truncated', 'process'):
+ errors = {None: None, 'peer': 'socket peer mismatch', 'uid': 'socket peer mismatch',
+ 'nonce': 'stale observer synchronization', 'stale': 'stale observer synchronization',
+ 'future': 'stale observer synchronization', 'source': 'source identity mismatch',
+ 'truncated': 'incomplete observer acknowledgement', 'process': 'observer process changed'}
+ for fault, error in errors.items():
with self.subTest(fault=fault):
observer = object.__new__(PrimaryObserver)
observer.control = Mock(lstat=Mock(return_value=SimpleNamespace(st_mode=stat.S_IFSOCK, st_uid=os.getuid())))
@@ -294,7 +304,7 @@ class ObserverFileTests(unittest.TestCase):
if fault is None:
self.assertEqual(observer._sync()['controller_interval'], [1000, 2000])
else:
- with self.assertRaises(AssertionError):
+ with self.assertRaisesRegex(AssertionError, error):
observer._sync()
def test_inode_prefix_size_and_recording_limits_fail_closed(self):
@@ -340,11 +350,7 @@ class ObserverGateTests(unittest.TestCase):
output = root / f'output-{i}'
output.write_bytes(b'baseline')
oracle['path'] = str(output)
- path = root / 'plan.json'
- path.write_text(json.dumps(candidate))
- args = SimpleNamespace(plan=path, evidence=root / 'evidence', artifact_role='production', trace_socket=None,
- primary_observer=root / 'control.sock', foreground_journal=root / 'journal',
- primary_grab=root / 'primary-grab', driver=root / 'driver', record_video=False)
+ args = harness_args(root, candidate, artifact_role='production', primary_observer=root / 'control.sock')
agents = [Mock(process=Mock(pid=101 + i, poll=Mock(return_value=None))) for i in range(2)]
recorder = Mock()
def tool(name, arguments):
@@ -370,16 +376,10 @@ class ObserverGateTests(unittest.TestCase):
self.assertTrue(all(began[0] <= first < last <= time.monotonic_ns() for first, last in intervals))
return result
observer.finish.side_effect = finish
- replacements = {'provenance': Mock(return_value={}), 'PrimaryObserver': Mock(return_value=observer),
+ patch_module(stack, 'production_realapp_proof', run_replacements(self, held, **{
+ 'PrimaryObserver': Mock(return_value=observer),
'DirectMCP': Mock(side_effect=agents + [recorder]), 'subprocess.Popen': Mock(return_value=grab),
- 'subprocess.run': Mock(), 'primary_acknowledgement': Mock(return_value='HELD\n'),
- 'verify_output': Mock(return_value={'verified': True}),
- 'wait_for': lambda predicate: self.assertTrue(predicate()),
- 'state': lambda path: {'held': held[0], 'clicks': 0, 'keys': 0, 'scroll': 0},
- 'wm': lambda: {'pid': 10, 'address': '0x64', 'workspace': 1, 'cursor': {'x': 100, 'y': 200}},
- 'stop_process': lambda process: held.__setitem__(0, False)}
- for name, replacement in replacements.items():
- stack.enter_context(patch('production_realapp_proof.' + name, replacement))
+ 'subprocess.run': Mock(), 'verify_output': Mock(return_value={'verified': True})}))
should_pass = (purpose == 'apps') == (detection == 'passed')
self.assertEqual(run(args), 0 if should_pass else 1)
observer.start.assert_called_once()
@@ -394,19 +394,6 @@ class ObserverGateTests(unittest.TestCase):
self.assertEqual(report['scope'], 'production-package-primary-control')
self.assertFalse(held[0])
- def test_explicit_production_requires_observer_before_any_driver_process(self):
- with tempfile.TemporaryDirectory() as temporary:
- root = Path(temporary)
- path = root / 'plan.json'
- path.write_text(json.dumps(plan()))
- args = SimpleNamespace(plan=path, evidence=root / 'evidence', artifact_role='production', trace_socket=None)
- with patch('production_realapp_proof.provenance') as origin, patch('production_realapp_proof.DirectMCP') as spawn:
- self.assertEqual(run(args), 1)
- origin.assert_not_called()
- spawn.assert_not_called()
- result = json.loads((args.evidence / 'result.json').read_text())
- self.assertIn('requires the independent primary observer', result['error'])
- self.assertEqual(result['continuous_isolation'], 'unproven')
if __name__ == '__main__':
diff --git a/libs/cua-driver/hyprland-plugin/tests/production_realapp_proof.py b/libs/cua-driver/hyprland-plugin/tests/production_realapp_proof.py
index b5fd87b813..2ae82a2aed 100644
--- a/libs/cua-driver/hyprland-plugin/tests/production_realapp_proof.py
+++ b/libs/cua-driver/hyprland-plugin/tests/production_realapp_proof.py
@@ -80,18 +80,21 @@ def validate_plan(plan):
assert not plan.get('moving_primary') and not plan.get('require_overlap'), \
'policy_cache requires serial actions and a parked primary'
spec = plan['agents'][0]
- assert spec['app'] in ('calc', 'inkscape')
+ assert spec['app'] in ('calc', 'inkscape'), 'policy_cache needs a reviewed Calc or Inkscape target'
assert isinstance(spec['name'], str) and spec['name'], 'policy_cache needs a fixed session'
profile = spec['profile']
assert profile['mode'] in ('standard', 'bounded', 'unrestricted')
- assert profile.get('manifest') and profile.get('approve_manifest') is True
- assert profile['mode'] != 'unrestricted' or profile.get('acknowledge_unrestricted') is True
+ assert profile.get('manifest') and profile.get('approve_manifest') is True, \
+ 'policy_cache needs an approved reviewed manifest'
+ assert profile['mode'] != 'unrestricted' or profile.get('acknowledge_unrestricted') is True, \
+ 'unrestricted policy_cache needs explicit acknowledgement'
assert len(plan['phases']) == 3, 'policy_cache needs allow, deny, fresh allow'
for index, step in enumerate(plan['phases']):
assert 'parallel' not in step and step.get('agent') == 0, 'policy_cache must reuse agent 0 serially'
expected = step.get('expect', {'kind': 'dispatched'})
if index == 1:
- assert expected.get('kind') == 'refused' and expected.get('reason') == 'permission_denied'
+ assert expected.get('kind') == 'refused' and expected.get('reason') == 'permission_denied', \
+ 'policy_cache denial must be permission_denied'
assert expected.get('message') in manifest_tool_messages(step['tool']), \
'policy_cache needs an exact manifest tool-ceiling refusal'
else:
@@ -122,7 +125,7 @@ def validate_plan(plan):
assert set(target) == {'pid', 'window_id'}
assert type(target['pid']) is int and target['pid'] > 0
if capacity or policy_cache or inkscape_only:
- assert type(target['window_id']) is int and target['window_id'] > 0
+ assert type(target['window_id']) is int and target['window_id'] > 0, 'reviewed target needs an exact window id'
if inkscape_only:
assert len({target['window_id'] for target in targets}) == len(targets), 'apps must be distinct native clients'
documents = [Path(spec['document']) for spec in plan['agents']]
@@ -215,8 +218,8 @@ def trace_interval(before, after):
"""Validate complete active prefixes before interpreting their difference."""
for page in (before, after):
assert isinstance(page, dict), 'missing dispatch telemetry'
- assert page.get('hook') is True and page.get('active') is True
- assert page.get('overflow') is False and page.get('timed_out') is False
+ assert page.get('hook') is True and page.get('active') is True, 'dispatch telemetry is not live'
+ assert page.get('overflow') is False and page.get('timed_out') is False, 'dispatch telemetry dropped events'
rows = page.get('events')
assert isinstance(rows, list) and rows, 'empty dispatch telemetry'
assert type(page.get('count')) is int and page['count'] == len(rows), 'incomplete dispatch telemetry'
@@ -572,11 +575,10 @@ def provenance(args, plan):
return origin
-def require_primary_active(grab, deadline_ns, now_ns=None):
+def require_primary_active(grab, deadline_ns):
"""Do not dispatch or accept a proof after its bounded primary grab ends."""
assert grab is not None and grab.poll() is None, 'primary grab helper exited'
- now_ns = time.monotonic_ns() if now_ns is None else now_ns
- assert deadline_ns is not None and now_ns < deadline_ns, 'primary grab deadline expired'
+ assert deadline_ns is not None and time.monotonic_ns() < deadline_ns, 'primary grab deadline expired'
def run(args):
diff --git a/libs/cua-driver/hyprland-plugin/tests/production_realapp_proof_test.py b/libs/cua-driver/hyprland-plugin/tests/production_realapp_proof_test.py
index ac60ff0085..eccb3a1802 100644
--- a/libs/cua-driver/hyprland-plugin/tests/production_realapp_proof_test.py
+++ b/libs/cua-driver/hyprland-plugin/tests/production_realapp_proof_test.py
@@ -20,10 +20,23 @@ from production_realapp_proof import (SMOKE_STEPS, app_process_identity, provena
passive_focus_evidence,
expected_primary_motion, move_primary, primary_acknowledgement,
parallel_actions, primary_trajectory, require_primary_active,
- PRIMARY_LIFETIME_MS, POINTER_EPISODES, run, validate_plan, verify_output)
-from primary_trace import analyze
-from primary_trace_test import START, STOP, trace
-from production_app_smoke_test import INKSCAPE, INKSCAPE_SELECTED
+ PRIMARY_LIFETIME_MS, POINTER_EPISODES, run, trace_interval, validate_plan,
+ verify_output)
+from proof_fixtures import (INKSCAPE, INKSCAPE_SELECTED, START, STOP, assert_rejects, capacity_events, capacity_plan,
+ harness_args, inkscape_plan, lane, lane_status, patch_module, plan,
+ policy_cache_plan, primary_trace as trace, run_replacements)
+
+
+def focus_evidence(rows):
+ """Passive-focus checkpoints around one lane-1 episode, then its stopped trace."""
+ focus_page = {'hook': True, 'active': True, 'overflow': False, 'timed_out': False,
+ 'count': len(rows), 'events': rows}
+ before = {'status': lane_status(lane(0, reserved=True, pointer_focus=True), lane(1)), 'trace': focus_page}
+ after = {'status': copy.deepcopy(before['status'])}
+ after['status']['input']['lanes'][0]['reserved'] = False
+ stopped = {**focus_page, 'active': False, 'count': len(rows) + 1,
+ 'events': rows + [[len(rows) + 1, len(rows), 'stop', 100, 100, 0, 0]]}
+ return before, after, stopped
class PassiveFocusTests(unittest.TestCase):
@@ -35,20 +48,7 @@ class PassiveFocusTests(unittest.TestCase):
if kind in ('pointer_enter', 'pointer_motion'):
row.extend((10, 20))
rows.append(row)
- page = {'hook': True, 'active': True, 'overflow': False, 'timed_out': False,
- 'count': len(rows), 'events': rows}
- values = [{'lane': lane, 'epoch': f'lane-{lane}', 'desktop_generation': 1,
- 'reserved': lane == 0, 'pointer_focus': lane == 0,
- 'keyboard_focus': False, 'lease_active': False, 'drag_active': False,
- 'held_button': 0, 'held_keys': 0} for lane in (0, 1)]
- status = {'state': 'input_v3_candidate', 'input': {'protocol': 3, 'test_only': False,
- 'transport_ready': True, 'lanes': values}}
- before = {'status': status, 'trace': page}
- after = {'status': copy.deepcopy(status)}
- after['status']['input']['lanes'][0]['reserved'] = False
- stopped = {**page, 'active': False, 'count': len(rows) + 1,
- 'events': rows + [[len(rows) + 1, len(rows), 'stop', 100, 100, 0, 0]]}
- return before, after, stopped
+ return focus_evidence(rows)
accepted = [
['pointer_leave', 'agent_admitted', 'pointer_enter', 'pointer_motion', 'agent_action_end'],
@@ -72,23 +72,10 @@ class PassiveFocusTests(unittest.TestCase):
passive_focus_evidence(*evidence(kinds))
def test_passive_focus_retains_presence_without_authority_after_close(self):
- rows = [[1, 0, 'start', 100, 100, 0, 0],
- [2, 1, 'pointer_enter', 100, 100, 1, 0, 10, 20],
- [3, 2, 'pointer_motion', 100, 100, 1, 0, 10, 20],
- [4, 3, 'agent_action_end', 100, 100, 1, 0]]
- page = {'hook': True, 'active': True, 'overflow': False, 'timed_out': False,
- 'count': len(rows), 'events': rows}
- values = [{'lane': lane, 'epoch': f'lane-{lane}', 'desktop_generation': 1,
- 'reserved': lane == 0, 'pointer_focus': lane == 0,
- 'keyboard_focus': False, 'lease_active': False, 'drag_active': False,
- 'held_button': 0, 'held_keys': 0} for lane in (0, 1)]
- status = {'state': 'input_v3_candidate', 'input': {'protocol': 3, 'test_only': False,
- 'transport_ready': True, 'lanes': values}}
- before = {'status': status, 'trace': page}
- after = {'status': copy.deepcopy(status)}
- after['status']['input']['lanes'][0].update(reserved=False)
- stopped = {**page, 'active': False, 'count': len(rows) + 1,
- 'events': rows + [[5, 4, 'stop', 100, 100, 0, 0]]}
+ before, after, stopped = focus_evidence([[1, 0, 'start', 100, 100, 0, 0],
+ [2, 1, 'pointer_enter', 100, 100, 1, 0, 10, 20],
+ [3, 2, 'pointer_motion', 100, 100, 1, 0, 10, 20],
+ [4, 3, 'agent_action_end', 100, 100, 1, 0]])
def append_synthetic(t, kind):
t['events'].insert(-1, [5, 4, kind, 100, 100, 1, 0])
t['events'][-1][0] = 6
@@ -117,49 +104,6 @@ class PassiveFocusTests(unittest.TestCase):
self.assertEqual(passive_focus_evidence(b, a, t)['lanes'], [1])
-def plan():
- return {'purpose': 'apps', 'foreground': {'pid': 10, 'window_id': 100},
- 'agents': [{'app': 'calc', 'target': {'pid': 20, 'window_id': 200}},
- {'app': 'inkscape', 'target': {'pid': 30, 'window_id': 300}}],
- 'phases': [{'parallel': [{'agent': 0, 'tool': 'drag', 'arguments': {}},
- {'agent': 1, 'tool': 'drag', 'arguments': {}}]}],
- 'outputs': [{'agent': 0, 'attributes': {'value': '96'}},
- {'agent': 1, 'rect_translation': [[10, 20], [30, 40]]}]}
-
-
-def capacity_plan():
- result = {**plan(), 'purpose': 'capacity', 'outputs': []}
- result['agents'].append({'app': 'inkscape', 'target': {'pid': 40, 'window_id': 400}})
- for index, spec in enumerate(result['agents']):
- spec.update(name='same-public-name', profile={'mode': 'standard'},
- bounds={'x': 0, 'y': 0, 'width': 600, 'height': 600})
- result['phases'] = [{'agent': index, 'tool': 'click', 'arguments': {'x': 20, 'y': 30}}
- for index in range(3)]
- result['phases'][2]['expect'] = {'kind': 'refused', 'reason': 'lane_busy'}
- return result
-
-
-def capacity_events(lane):
- return [('agent_admitted', 100, 200, lane, 0),
- ('pointer_button', 100, 200, lane, 1),
- ('pointer_button', 100, 200, lane, 0),
- ('agent_action_end', 100, 200, lane, 0)]
-
-
-def policy_cache_plan():
- result = capacity_plan()
- result.update(purpose='policy_cache', agents=result['agents'][:1])
- result['agents'][0]['profile'].update(manifest='reviewed.yaml', approve_manifest=True)
- result['phases'] = [
- {'agent': 0, 'tool': 'click', 'arguments': {'x': 20, 'y': 30}},
- {'agent': 0, 'tool': 'press_key', 'arguments': {'key': 'ESC'},
- 'expect': {'kind': 'refused', 'reason': 'permission_denied',
- 'message': "Permission denied: capability manifest denies tool 'press_key'"}},
- {'agent': 0, 'tool': 'click', 'arguments': {'x': 30, 'y': 40}},
- ]
- return result
-
-
class ProvenanceTests(unittest.TestCase):
def test_runtime_provenance_refusal_precedes_app_inspection(self):
with patch('production_realapp_proof.runtime_provenance',
@@ -222,31 +166,33 @@ class PolicyCacheTests(unittest.TestCase):
candidate['agents'][0]['profile'].update(mode=mode, acknowledge_unrestricted=True)
candidate['phases'][1]['expect']['message'] = message
validate_plan(candidate)
- for mutate in (lambda p: p['agents'].append(copy.deepcopy(p['agents'][0])),
- lambda p: p['agents'][0].update(app='fixture'),
- lambda p: p['agents'][0].update(name=''),
- lambda p: p['agents'][0]['target'].update(window_id=None),
- lambda p: p['agents'][0]['profile'].pop('manifest'),
- lambda p: p['agents'][0]['profile'].update(approve_manifest=False),
- lambda p: p['agents'][0]['profile'].update(mode='unrestricted'),
- lambda p: p['phases'].pop(),
- lambda p: p['phases'][1].update(agent=1),
- lambda p: p['phases'][1].update(parallel=[]),
- lambda p: p['phases'][1].update(tool='click'),
- lambda p: p['phases'][2].update(tool='scroll'),
- lambda p: p['phases'][2].update(expect={'kind': 'unknown'}),
- lambda p: p['phases'][1]['expect'].update(reason='lane_busy'),
- lambda p: p['phases'][1]['expect'].update(reason='bounded_resource_outside_manifest'),
- lambda p: p['phases'][1]['expect'].pop('message'),
- lambda p: p['phases'][1]['expect'].update(message='Permission denied'),
- lambda p: p['phases'][1]['arguments'].update(pid=99),
- lambda p: p['phases'][1]['arguments'].update(session='new'),
- lambda p: p.update(moving_primary=True),
- lambda p: p.update(require_overlap=True)):
- bad = policy_cache_plan()
- mutate(bad)
- with self.subTest(plan=bad), self.assertRaises(AssertionError):
- validate_plan(bad)
+ click_denial = "Permission denied: capability manifest denies tool 'click'"
+ assert_rejects(self, validate_plan, policy_cache_plan(), [
+ ('one persistent runtime', lambda p: p['agents'].append(copy.deepcopy(p['agents'][0]))),
+ ('reviewed Calc or Inkscape target', lambda p: p['agents'][0].update(app='fixture')),
+ ('fixed session', lambda p: p['agents'][0].update(name='')),
+ ('exact window id', lambda p: p['agents'][0]['target'].update(window_id=None)),
+ ('approved reviewed manifest', lambda p: p['agents'][0]['profile'].pop('manifest')),
+ ('approved reviewed manifest', lambda p: p['agents'][0]['profile'].update(approve_manifest=False)),
+ ('explicit acknowledgement', lambda p: p['agents'][0]['profile'].update(mode='unrestricted')),
+ ('allow, deny, fresh allow', lambda p: p['phases'].pop()),
+ ('reuse agent 0 serially', lambda p: p['phases'][1].update(agent=1)),
+ ('reuse agent 0 serially', lambda p: p['phases'][1].update(parallel=[])),
+ # Denying the allowed tool must reach the distinct-tool guard, not the message guard.
+ ('distinct denied tool', lambda p: p['phases'][1].update(
+ tool='click', expect={**p['phases'][1]['expect'], 'message': click_denial})),
+ ('distinct denied tool', lambda p: p['phases'][2].update(tool='scroll')),
+ ('permitted calls must dispatch', lambda p: p['phases'][2].update(expect={'kind': 'unknown'})),
+ ('must be permission_denied', lambda p: p['phases'][1]['expect'].update(reason='lane_busy')),
+ ('must be permission_denied', lambda p: p['phases'][1]['expect'].update(
+ reason='bounded_resource_outside_manifest')),
+ ('exact manifest tool-ceiling refusal', lambda p: p['phases'][1]['expect'].pop('message')),
+ ('exact manifest tool-ceiling refusal', lambda p: p['phases'][1]['expect'].update(message='Permission denied')),
+ ('overrides reviewed ownership', lambda p: p['phases'][1]['arguments'].update(pid=99)),
+ ('overrides reviewed ownership', lambda p: p['phases'][1]['arguments'].update(session='new')),
+ ('parked primary', lambda p: p.update(moving_primary=True)),
+ ('parked primary', lambda p: p.update(require_overlap=True)),
+ ])
def test_exact_common_envelope_excludes_plugin_and_other_policy_refusals(self):
expected = policy_cache_plan()['phases'][1]['expect']
@@ -299,36 +245,37 @@ class PolicyCacheTests(unittest.TestCase):
with self.subTest(response=bad), self.assertRaises(AssertionError):
check_manifest_refusal(bad, expected, 'press_key')
- def test_missing_trace_fails_before_process_launch(self):
- with tempfile.TemporaryDirectory() as directory:
- root = Path(directory)
- path = root / 'plan.json'
- path.write_text(json.dumps(policy_cache_plan()))
- args = SimpleNamespace(plan=path, evidence=root / 'evidence', trace_socket=None)
- with patch('production_realapp_proof.provenance') as provenance, \
- patch('production_realapp_proof.DirectMCP') as spawn:
- self.assertEqual(run(args), 1)
- provenance.assert_not_called()
- spawn.assert_not_called()
- result = json.loads((args.evidence / 'result.json').read_text())
- self.assertEqual(result['error'], 'policy_cache requires continuous trace')
- self.assertEqual(result['policy_cache']['result'], 'unproven')
-
def test_runner_persistent_runtime_quiet_denial_and_failures_without_replay(self):
- for failure in (None, 'changed_lane', 'missing_input', 'wrong_refusal', 'plugin_refusal',
- 'admitted_on_denial', 'input_on_denial', 'denial_before_snapshot',
- 'denial_after_snapshot', 'next_snapshot_input', 'gap_input', 'dead_runtime', 'changed_runtime',
- 'transport', 'partial', 'unknown', 'missing_hook', 'reset_trace',
- 'cleanup_reset', 'foreground_input', 'cleanup_failure', 'stale_window'):
+ # Each failure must fail for its own reason: in the result, or in cleanup.
+ failures = {
+ None: None,
+ 'changed_lane': ('error', 'compositor lane changed'),
+ 'missing_input': ('error', 'admission, input, and completion evidence'),
+ 'wrong_refusal': ('error', 'wrong MCP manifest tool-ceiling refusal'),
+ 'plugin_refusal': ('error', 'common authorization refusal, not a plugin error'),
+ 'admitted_on_denial': ('error', 'denied call reached a synthetic lane'),
+ 'input_on_denial': ('error', 'denied call reached a synthetic lane'),
+ 'denial_before_snapshot': ('error', 'denied call reached a synthetic lane'),
+ 'denial_after_snapshot': ('error', 'denied call reached a synthetic lane'),
+ 'next_snapshot_input': ('error', 'denied call reached a synthetic lane'),
+ 'gap_input': ('error', 'denied call reached a synthetic lane'),
+ 'dead_runtime': ('error', 'Driver process exited'),
+ 'changed_runtime': ('error', 'policy_cache runtime changed'),
+ 'transport': ('error', 'unknown effect'),
+ 'partial': ('error', "'effect': 'partial'"),
+ 'unknown': ('error', "'mode': 'unknown'"),
+ 'missing_hook': ('error', 'dispatch telemetry is not live'),
+ 'reset_trace': ('error', 'trace history changed'),
+ 'cleanup_reset': ('finish_trace', 'policy_cache trace history changed at cleanup'),
+ 'foreground_input': ('finish_trace', "'result': 'failed'"),
+ 'cleanup_failure': ('close_agent_0', 'cleanup failed'),
+ 'stale_window': ('error', 'reviewed PID/window identity is stale or ambiguous'),
+ }
+ for failure, expected_error in failures.items():
with self.subTest(failure=failure), tempfile.TemporaryDirectory() as directory, ExitStack() as stack:
root = Path(directory)
candidate = policy_cache_plan()
- path = root / 'plan.json'
- path.write_text(json.dumps(candidate))
- args = SimpleNamespace(plan=path, evidence=root / 'evidence',
- trace_socket=root / 'cua-input-v3.sock', driver=root / 'driver',
- primary_grab=root / 'primary-grab', foreground_journal=root / 'journal',
- record_video=False)
+ args = harness_args(root, candidate, trace_socket=root / 'cua-input-v3.sock')
calls, events, held = [], [START], [True]
agent = Mock(process=Mock(pid=101, poll=Mock(return_value=None)))
observer = Mock()
@@ -403,17 +350,9 @@ class PolicyCacheTests(unittest.TestCase):
trace_client.collect.side_effect = collect
if failure == 'cleanup_failure':
agent.close.side_effect = RuntimeError('cleanup failed')
- grab = Mock(poll=Mock(return_value=None))
- replacements = {'provenance': Mock(return_value={}),
- 'DirectMCP': Mock(side_effect=[agent, observer]), 'Trace': Mock(return_value=trace_client),
- 'subprocess.Popen': Mock(return_value=grab),
- 'primary_acknowledgement': Mock(return_value='HELD\n'),
- 'wait_for': lambda predicate: self.assertTrue(predicate()),
- 'state': lambda path: {'held': held[0], 'clicks': 0, 'keys': 0, 'scroll': 0},
- 'wm': lambda: {'pid': 10, 'address': '0x10', 'workspace': 1, 'cursor': {'x': 100, 'y': 200}},
- 'stop_process': lambda process: held.__setitem__(0, False)}
- for name, replacement in replacements.items():
- stack.enter_context(patch('production_realapp_proof.' + name, replacement))
+ replacements = run_replacements(self, held, DirectMCP=Mock(side_effect=[agent, observer]),
+ Trace=Mock(return_value=trace_client))
+ patch_module(stack, 'production_realapp_proof', replacements)
self.assertEqual(run(args), 0 if failure is None else 1)
mutations = [name for name, _ in calls if name in ('click', 'press_key')]
self.assertEqual(mutations, ['click', 'press_key', 'click'][:len(mutations)])
@@ -430,45 +369,54 @@ class PolicyCacheTests(unittest.TestCase):
self.assertEqual(replacements['DirectMCP'].call_args.args[2],
{'mode': 'unrestricted', 'acknowledge_unrestricted': True})
result = json.loads((args.evidence / 'result.json').read_text())
+ cleanup = {row['operation']: row['error']
+ for row in json.loads((args.evidence / 'cleanup.json').read_text())['errors']}
if failure is None:
self.assertEqual(mutations, ['click', 'press_key', 'click'])
self.assertEqual(result['policy_cache']['compositor_lane'], 1)
self.assertEqual(result['continuous_isolation'], 'passed')
self.assertEqual(result['synthetic_cleanup'], 'verified')
+ self.assertEqual(cleanup, {})
for index in range(3):
self.assertTrue((args.evidence / f'policy-cache-phase-{index}-trace.json').is_file())
+ else:
+ where, pattern = expected_error
+ self.assertRegex(result['error'] if where == 'error' else cleanup[where], pattern)
if failure in ('transport', 'dead_runtime', 'changed_runtime', 'gap_input', 'next_snapshot_input'):
self.assertEqual(mutations, ['click', 'press_key'])
class CapacityTests(unittest.TestCase):
def test_plan_requires_three_serial_independent_qualified_targets(self):
- validate_plan(capacity_plan())
- for mutate in (lambda p: p.update(phases=[]),
- lambda p: p.update(phases=p['phases'][:2]),
- lambda p: p.update(agents=p['agents'][:2]),
- lambda p: p['phases'][1].update(agent=0),
- lambda p: p['phases'][0].update(parallel=[]),
- lambda p: p['phases'][0].update(expect={'kind': 'unknown'}),
- lambda p: p['phases'][2].pop('expect'),
- lambda p: p['phases'][2].update(expect={'kind': 'refused', 'reason': 'permission_denied'}),
- lambda p: p['agents'][2].update(target=p['agents'][1]['target']),
- lambda p: p['agents'][2]['target'].update(window_id=None),
- lambda p: p['agents'][2].update(app='fixture'),
- lambda p: p.update(moving_primary=True),
- lambda p: p.update(require_overlap=True)):
- bad = capacity_plan()
- mutate(bad)
- with self.subTest(plan=bad), self.assertRaises(AssertionError):
- validate_plan(bad)
- # Capacity does not redefine the normal reviewed permission contract.
- for mode in ('standard', 'bounded', 'unrestricted'):
- candidate = capacity_plan()
- candidate['agents'][0]['profile']['mode'] = mode
- validate_plan(candidate)
- for purpose in ('apps', 'policy', 'negative_control'):
- with self.assertRaises(AssertionError):
- validate_plan({**capacity_plan(), 'purpose': purpose})
+ for app_profile, factory in (('calc-inkscape', capacity_plan),
+ ('inkscape-only', lambda: inkscape_plan(capacity=True))):
+ validate_plan(factory())
+ for mutate in (lambda p: p.update(phases=[]),
+ lambda p: p.update(phases=p['phases'][:2]),
+ lambda p: p.update(agents=p['agents'][:2]),
+ lambda p: p['phases'][1].update(agent=0),
+ lambda p: p['phases'][2].update(agent=0),
+ lambda p: p['phases'][0].update(parallel=[]),
+ lambda p: p['phases'][0].update(expect={'kind': 'unknown'}),
+ lambda p: p['phases'][2].pop('expect'),
+ lambda p: p['phases'][2].update(expect={'kind': 'refused', 'reason': 'permission_denied'}),
+ lambda p: p['agents'][2].update(target=p['agents'][1]['target']),
+ lambda p: p['agents'][2]['target'].update(window_id=None),
+ lambda p: p['agents'][2].update(app='fixture'),
+ lambda p: p.update(moving_primary=True),
+ lambda p: p.update(require_overlap=True)):
+ bad = factory()
+ mutate(bad)
+ with self.subTest(app_profile=app_profile, plan=bad), self.assertRaises(AssertionError):
+ validate_plan(bad)
+ # Capacity does not redefine the normal reviewed permission contract.
+ for mode in ('standard', 'bounded', 'unrestricted'):
+ candidate = factory()
+ candidate['agents'][0]['profile']['mode'] = mode
+ validate_plan(candidate)
+ for purpose in ('apps', 'policy', 'negative_control'):
+ with self.assertRaises(AssertionError):
+ validate_plan({**factory(), 'purpose': purpose})
def test_lane_needs_actual_ordered_input_and_completion(self):
before = {**trace(START), 'active': True}
@@ -481,12 +429,11 @@ class CapacityTests(unittest.TestCase):
[(kind, x, y, 0, state) for kind, x, y, lane, state in events]):
with self.subTest(rows=rows), self.assertRaises(AssertionError):
capacity_lane(before, {**trace(START, *rows), 'active': True}, 'click')
- for malformed in (None, {}, {**after, 'events': []}, {**after, 'hook': False},
- {**after, 'overflow': True}, {**after, 'count': 0},
- {**after, 'timed_out': True}, {**after, 'events': [[1]]}):
- with self.subTest(trace=malformed), self.assertRaises(AssertionError):
- capacity_lane(before, malformed, 'click')
- with self.assertRaises(AssertionError):
+ # Page validity belongs to trace_interval; one case proves it is applied.
+ with self.assertRaisesRegex(AssertionError, 'dropped events'):
+ capacity_lane(before, {**after, 'overflow': True}, 'click')
+ # A pointer click cannot count as keyboard input.
+ with self.assertRaisesRegex(AssertionError, 'admission, input, and completion'):
capacity_lane(before, after, 'press_key')
def test_summary_rejects_incomplete_wrong_lane_and_wrong_refusal(self):
@@ -507,27 +454,22 @@ class CapacityTests(unittest.TestCase):
with self.subTest(actions=bad), self.assertRaises(AssertionError):
verify_capacity(bad)
- def test_missing_trace_fails_before_process_launch(self):
- with tempfile.TemporaryDirectory() as directory:
- root = Path(directory)
- source_plan = root / 'plan.json'
- source_plan.write_text(json.dumps(capacity_plan()))
- args = SimpleNamespace(plan=source_plan, evidence=root / 'evidence', trace_socket=None)
- with patch('production_realapp_proof.provenance') as provenance, \
- patch('production_realapp_proof.DirectMCP') as spawn:
- self.assertEqual(run(args), 1)
- provenance.assert_not_called()
- spawn.assert_not_called()
- result = json.loads((args.evidence / 'result.json').read_text())
- self.assertEqual(result['error'], 'capacity requires continuous trace')
- self.assertEqual(result['capacity']['result'], 'unproven')
-
def test_runner_serial_capacity_and_failures_without_replay(self):
- cases = [(app_profile, failure) for app_profile in ('calc-inkscape', 'inkscape-only')
- for failure in (None, 'same_lane', 'missing_input', 'wrong_refusal', 'dispatch_on_refusal',
- 'dead_runtime', 'stale_window', 'transport', 'missing_hook', 'reset_trace')]
- cases += [('inkscape-only', failure) for failure in ('owner_lost', 'owner_changed', 'document_changed')]
- for app_profile, failure in cases:
+ failures = {None: None, 'same_lane': 'capacity needs distinct compositor lanes',
+ 'missing_input': 'capacity needs admission, input, and completion evidence',
+ 'wrong_refusal': "'reason': 'permission_denied'",
+ 'dispatch_on_refusal': 'denied call reached a synthetic lane',
+ 'dead_runtime': 'Driver process exited',
+ 'stale_window': 'reviewed PID/window identity is stale or ambiguous',
+ 'transport': 'unknown effect', 'missing_hook': 'dispatch telemetry is not live',
+ 'reset_trace': 'trace history changed'}
+ owner_failures = {'owner_lost': 'capacity owner lost its lane reservation',
+ 'owner_changed': 'capacity lane ownership changed',
+ 'document_changed': 'snapshot document mismatch'}
+ cases = [(app_profile, failure, error) for app_profile in ('calc-inkscape', 'inkscape-only')
+ for failure, error in failures.items()]
+ cases += [('inkscape-only', failure, error) for failure, error in owner_failures.items()]
+ for app_profile, failure, expected_error in cases:
with self.subTest(app_profile=app_profile, failure=failure), tempfile.TemporaryDirectory() as directory, ExitStack() as stack:
root = Path(directory)
candidate = capacity_plan()
@@ -535,12 +477,7 @@ class CapacityTests(unittest.TestCase):
candidate['app_profile'] = app_profile
for i, spec in enumerate(candidate['agents']):
spec.update(app='inkscape', document=str(root.resolve() / f'lane-{i}.svg'))
- path = root / 'plan.json'
- path.write_text(json.dumps(candidate))
- args = SimpleNamespace(plan=path, evidence=root / 'evidence',
- trace_socket=root / 'cua-input-v3.sock', driver=root / 'driver',
- primary_grab=root / 'primary-grab', foreground_journal=root / 'journal',
- record_video=False)
+ args = harness_args(root, candidate, trace_socket=root / 'cua-input-v3.sock')
calls, events, held = [], [START], [True]
agents = [Mock(process=Mock(pid=101 + i, poll=Mock(return_value=None))) for i in range(3)]
observer = Mock()
@@ -589,26 +526,15 @@ class CapacityTests(unittest.TestCase):
events[:] = [START]
return {**trace(*events), 'active': events[-1] != STOP, 'hook': failure != 'missing_hook'}
trace_client.collect.side_effect = collect
- grab = Mock(poll=Mock(return_value=None))
def input_status():
third_called = ('click', 2) in calls
- return {'state': 'input_v3_candidate', 'input': {'protocol': 3, 'test_only': False,
- 'transport_ready': True, 'lanes': [
- {'lane': lane, 'reserved': not (third_called and failure == 'owner_lost'),
- 'epoch': 100 if third_called and failure == 'owner_changed' else 50 + lane,
- 'desktop_generation': 1, 'lease_active': False, 'drag_active': False,
- 'held_keys': 0, 'held_button': 0} for lane in (0, 1)]}}
- replacements = {'provenance': Mock(return_value={}),
- 'read_input_status': input_status,
- 'DirectMCP': Mock(side_effect=agents + [observer]), 'Trace': Mock(return_value=trace_client),
- 'subprocess.Popen': Mock(return_value=grab),
- 'primary_acknowledgement': Mock(return_value='HELD\n'),
- 'wait_for': lambda predicate: self.assertTrue(predicate()),
- 'state': lambda path: {'held': held[0], 'clicks': 0, 'keys': 0, 'scroll': 0},
- 'wm': lambda: {'pid': 10, 'address': '0x10', 'workspace': 1, 'cursor': {'x': 100, 'y': 200}},
- 'stop_process': lambda process: held.__setitem__(0, False)}
- for name, replacement in replacements.items():
- stack.enter_context(patch('production_realapp_proof.' + name, replacement))
+ return lane_status(*(lane(index, reserved=not (third_called and failure == 'owner_lost'),
+ epoch=100 if third_called and failure == 'owner_changed' else 51 + index)
+ for index in (0, 1)))
+ replacements = run_replacements(self, held, read_input_status=input_status,
+ DirectMCP=Mock(side_effect=agents + [observer]),
+ Trace=Mock(return_value=trace_client))
+ patch_module(stack, 'production_realapp_proof', replacements)
self.assertEqual(run(args), 0 if failure is None else 1)
action_indexes = [index for name, index in calls if name == 'click']
self.assertEqual(action_indexes, list(range(len(action_indexes))))
@@ -637,6 +563,8 @@ class CapacityTests(unittest.TestCase):
self.assertEqual(set(result['actions'][2]['persistent_owners']), {'1', '2'})
self.assertTrue((args.evidence / 'capacity-agent-2-owners-before.json').is_file())
self.assertTrue((args.evidence / 'capacity-agent-2-owners-after.json').is_file())
+ else:
+ self.assertRegex(result['error'], expected_error)
class PlanTests(unittest.TestCase):
@@ -745,11 +673,17 @@ class SmokeStageTests(unittest.TestCase):
'message': 'unconfirmed effect'}])
def test_runner_grounds_full_snapshots_and_never_recovers_or_replays(self):
+ failures = {None: None, 'unmarked': None,
+ 'no_elements': 'snapshot has no semantic elements',
+ 'dialog': 'unexpected dialog; no dismissal keys were sent',
+ 'extra_window': 'reviewed PID/window identity is stale or ambiguous',
+ 'after_dialog': 'unexpected dialog; no dismissal keys were sent',
+ 'transport': 'unknown input outcome'}
for app, stage, elements in (
('calc', 'insert', [{'role': 'table cell', 'label': 'A1', 'selected': True}]),
('inkscape', 'select', INKSCAPE['elements']),
('inkscape', 'move', INKSCAPE_SELECTED['elements'])):
- for failure in (None, 'no_elements', 'dialog', 'extra_window', 'after_dialog', 'transport', 'unmarked'):
+ for failure, expected_error in failures.items():
with self.subTest(app=app, stage=stage, failure=failure), \
tempfile.TemporaryDirectory() as directory, ExitStack() as stack:
root = Path(directory)
@@ -766,11 +700,7 @@ class SmokeStageTests(unittest.TestCase):
path = root / f'{i}.xml'
path.write_text('<synthetic/>')
candidate['outputs'][i]['path'] = str(path)
- path = root / 'plan.json'
- path.write_text(json.dumps(candidate))
- args = SimpleNamespace(plan=path, evidence=root / 'evidence', trace_socket=None,
- driver=root / 'driver', primary_grab=root / 'primary-grab',
- foreground_journal=root / 'journal', record_video=False)
+ args = harness_args(root, candidate)
calls, held = [], [True]
agents = [Mock(process=Mock(pid=101 + i, poll=Mock(return_value=None))) for i in range(2)]
observer = Mock()
@@ -806,19 +736,10 @@ class SmokeStageTests(unittest.TestCase):
for mcp in agents + [observer]:
mcp.tool.side_effect = tool
- replacements = {'provenance': Mock(return_value={}),
- 'DirectMCP': Mock(side_effect=agents + [observer]),
- 'subprocess.Popen': Mock(return_value=Mock(poll=Mock(return_value=None))),
- 'primary_acknowledgement': Mock(return_value='HELD\n'),
- 'verify_output': Mock(return_value={'verified': True}),
- 'wait_for': lambda predicate: self.assertTrue(predicate()),
- 'state': lambda path: {'held': held[0], 'clicks': 0, 'keys': 0, 'scroll': 0},
- 'wm': lambda: {'pid': 10, 'address': '0x10', 'workspace': 1,
- 'cursor': {'x': 100, 'y': 200}},
- 'stop_process': lambda process: held.__setitem__(0, False)}
- for name, replacement in replacements.items():
- stack.enter_context(patch('production_realapp_proof.' + name, replacement))
- self.assertEqual(run(args), 0 if failure in (None, 'unmarked') else 1)
+ patch_module(stack, 'production_realapp_proof', run_replacements(
+ self, held, DirectMCP=Mock(side_effect=agents + [observer]),
+ verify_output=Mock(return_value={'verified': True})))
+ self.assertEqual(run(args), 0 if expected_error is None else 1)
inputs = [i for i, row in enumerate(calls) if row[0] == 'input']
self.assertEqual(len(inputs), 0 if failure in ('no_elements', 'dialog', 'extra_window') else 1)
if inputs:
@@ -836,6 +757,8 @@ class SmokeStageTests(unittest.TestCase):
report = json.loads((args.evidence / 'result.json').read_text())
if failure is None:
self.assertEqual(report['actions'][0]['smoke_stage'], stage)
+ if expected_error:
+ self.assertRegex(report['error'], expected_error)
class PointerStageTests(unittest.TestCase):
@@ -871,14 +794,17 @@ class PointerStageTests(unittest.TestCase):
def test_primary_guard_fails_at_deadline_or_any_helper_exit(self):
helper = Mock(poll=Mock(return_value=None))
- require_primary_active(helper, 100, now_ns=99)
- for now in (100, 101):
- with self.assertRaisesRegex(AssertionError, 'deadline expired'):
- require_primary_active(helper, 100, now_ns=now)
- for code in (0, 1, -15):
- helper.poll.return_value = code
- with self.assertRaisesRegex(AssertionError, 'helper exited'):
- require_primary_active(helper, 100, now_ns=99)
+ with patch('production_realapp_proof.time.monotonic_ns', return_value=99) as clock:
+ require_primary_active(helper, 100)
+ for now in (100, 101):
+ clock.return_value = now
+ with self.assertRaisesRegex(AssertionError, 'deadline expired'):
+ require_primary_active(helper, 100)
+ clock.return_value = 99
+ for code in (0, 1, -15):
+ helper.poll.return_value = code
+ with self.assertRaisesRegex(AssertionError, 'helper exited'):
+ require_primary_active(helper, 100)
def test_pointer_stages_reject_supplied_coordinates_or_wrong_tool(self):
candidate = plan()
@@ -905,11 +831,7 @@ class PointerStageTests(unittest.TestCase):
output = root / f'{index}.xml'
output.write_text('<synthetic/>')
candidate['outputs'][index]['path'] = str(output)
- plan_path = root / 'plan.json'
- plan_path.write_text(json.dumps(candidate))
- args = SimpleNamespace(plan=plan_path, evidence=root / 'evidence', trace_socket=None,
- driver=root / 'driver', primary_grab=root / 'primary-grab',
- foreground_journal=root / 'journal', record_video=False)
+ args = harness_args(root, candidate)
targets = [candidate['foreground']] + [spec['target'] for spec in candidate['agents']]
clients, calls, held = [], [], [True]
clock_now = [1]
@@ -956,19 +878,12 @@ class PointerStageTests(unittest.TestCase):
side_effect=AssertionError('unchanged app') if failure == 'after' else None)
if failure == 'after_recovers':
verification.side_effect = [AssertionError('not settled'), {'verified': True}, {'verified': True}]
- replacements = {'provenance': Mock(return_value={}), 'DirectMCP': client,
- 'subprocess.Popen': Mock(return_value=grab),
+ patch_module(stack, 'production_realapp_proof', run_replacements(
+ self, held, DirectMCP=client, **{'subprocess.Popen': Mock(return_value=grab),
'time.monotonic_ns': lambda: clock_now[0],
- 'primary_acknowledgement': Mock(return_value='HELD\n'),
'verify_output': Mock(return_value={'verified': True}),
- 'wait_for': lambda predicate: self.assertTrue(predicate()),
- 'state': lambda path: {'held': held[0], 'clicks': 0, 'keys': 0, 'scroll': 0},
- 'wm': lambda: {'pid': 10, 'address': '0x10', 'workspace': 1, 'cursor': {'x': 100, 'y': 200}},
- 'stop_process': lambda process: held.__setitem__(0, False),
'pointer_grounding.read_pixels': lambda path: path,
- 'pointer_grounding.action': grounding, 'pointer_grounding.verify': verification}
- for name, replacement in replacements.items():
- stack.enter_context(patch('production_realapp_proof.' + name, replacement))
+ 'pointer_grounding.action': grounding, 'pointer_grounding.verify': verification}))
self.assertEqual(run(args), 0 if failure is None else 1)
inputs = [index for index, row in enumerate(calls) if row[0] == 'input']
self.assertEqual(len(inputs), 0 if failure in
@@ -1058,12 +973,53 @@ class ResponseTests(unittest.TestCase):
with self.assertRaises(AssertionError):
assert_no_dispatch(before, after)
- def test_no_dispatch_rejects_missing_or_changed_telemetry(self):
+ def test_no_dispatch_requires_valid_telemetry(self):
before = {**trace(START), 'active': True}
- for change in ({'hook': False}, {'overflow': True}, {'timed_out': True},
- {'count': 2}, {'active': False}, {'events': []}):
- with self.assertRaises(AssertionError):
- assert_no_dispatch(before, {**before, **change})
+ with self.assertRaisesRegex(AssertionError, 'dropped events'):
+ assert_no_dispatch(before, {**before, 'overflow': True})
+
+
+class TraceIntervalTests(unittest.TestCase):
+ """Owner of dispatch-interval page validity for every proof that reuses it."""
+
+ def test_returns_only_rows_appended_after_a_valid_prefix(self):
+ before = {**trace(START), 'active': True}
+ after = {**trace(START, ('agent_admitted', 100, 200, 1, 0)), 'active': True}
+ self.assertEqual(trace_interval(before, after), [after['events'][1]])
+ self.assertEqual(trace_interval(before, before), [])
+ motion = {**trace(START, ('pointer_motion', 100, 200, 1, 0)), 'active': True}
+ motion['events'][1].extend([10, 20]) # Surface coordinates are a valid row shape.
+ self.assertEqual(trace_interval(before, motion), [motion['events'][1]])
+
+ def test_rejects_missing_incomplete_malformed_stopped_or_rewritten_pages(self):
+ before = {**trace(START), 'active': True}
+ after = {**trace(START, ('cursor', 100, 200, 0, 0)), 'active': True}
+ def changed(update):
+ page = copy.deepcopy(after)
+ update(page)
+ return page
+ cases = [
+ ('missing dispatch telemetry', None),
+ ('not live', {**after, 'hook': False}),
+ ('not live', {**after, 'active': False}),
+ ('dropped events', {**after, 'overflow': True}),
+ ('dropped events', {**after, 'timed_out': True}),
+ ('empty dispatch telemetry', {**after, 'events': [], 'count': 0}),
+ ('incomplete dispatch telemetry', {**after, 'count': 3}),
+ ('malformed dispatch telemetry', changed(lambda p: p['events'][-1].pop())),
+ ('malformed trace sequence', changed(lambda p: p['events'][-1].__setitem__(0, '2'))),
+ ('incomplete dispatch telemetry', changed(lambda p: p['events'][-1].__setitem__(2, 'unknown'))),
+ ('incomplete dispatch telemetry', changed(lambda p: p['events'][-1].__setitem__(0, 3))),
+ ('trace already stopped', changed(lambda p: p['events'].insert(1, [2, 0, 'stop', 100, 200, 0, 0])
+ or p['events'][2].__setitem__(0, 3) or p.update(count=3))),
+ ('trace history changed', changed(lambda p: p['events'][0].__setitem__(3, 101))),
+ ]
+ for pattern, page in cases:
+ with self.subTest(pattern=pattern, page=page), self.assertRaisesRegex(AssertionError, pattern):
+ trace_interval(before, page)
+ # The prefix is held to the same contract as the interval end.
+ with self.assertRaisesRegex(AssertionError, 'dropped events'):
+ trace_interval({**before, 'overflow': True}, after)
class OutputTests(unittest.TestCase):
@@ -1133,21 +1089,6 @@ class MovingPrimaryTests(unittest.TestCase):
with self.subTest(log=log), self.assertRaises(AssertionError):
expected_primary_motion(log, route)
- def test_trace_must_match_commands_without_extra_motion_focus_or_grab_changes(self):
- route = [[120, 200], [100, 200]]
- commands = [motion_command(1, route[0]), motion_command(2, route[1], 3, 4)]
- expected = expected_primary_motion(commands, route)
- events = [('cursor', *point, 0, 0) for point in route]
- self.assertEqual(analyze(trace(START, *events, STOP), expected_motion=expected)['result'], 'passed')
- bad_events = [events[:1], list(reversed(events)),
- [events[0], ('cursor', 150, 200, 0, 0), *events[1:]]]
- for kind in ('pointer_focus', 'keyboard_focus', 'pointer_button', 'pointer_axis', 'keyboard_key'):
- bad_events.append([events[0], (kind, 120, 200, 0, 0), events[1]])
- for rows in bad_events:
- self.assertEqual(analyze(trace(START, *rows, STOP), expected_motion=expected)['result'], 'failed')
- self.assertEqual(analyze({**trace(START, *events, STOP), 'overflow': True},
- expected_motion=expected)['result'], 'inconclusive')
-
def test_acknowledgement_rejects_timeout_eof_partial_and_oversized_lines(self):
stream = Mock()
for chunks, readiness in (([b''], [[stream]]), ([b'MOVED 120'], [[stream], []]),
@@ -1177,22 +1118,6 @@ class MovingPrimaryTests(unittest.TestCase):
grab.stdin.flush.assert_called_once()
self.assertEqual(commands[0]['acknowledgement'], acknowledgement)
- def test_no_trace_fails_before_provenance_or_process_launch(self):
- with tempfile.TemporaryDirectory() as directory:
- root = Path(directory)
- source_plan = root / 'plan.json'
- source_plan.write_text(json.dumps({**plan(), 'moving_primary': True}))
- args = SimpleNamespace(plan=source_plan, evidence=root / 'evidence', trace_socket=None)
- with patch('production_realapp_proof.provenance') as provenance, \
- patch('production_realapp_proof.subprocess.Popen') as spawn:
- self.assertEqual(run(args), 1)
- provenance.assert_not_called()
- spawn.assert_not_called()
- result = json.loads((args.evidence / 'result.json').read_text())
- self.assertEqual(result['result'], 'failed')
- self.assertEqual(result['error'], 'moving primary requires continuous trace')
- self.assertEqual(result['continuous_isolation'], 'unproven')
-
def test_runner_uses_acknowledged_motion_and_brackets_background_action(self):
# Exercise orchestration without a compositor, Driver process, or GUI.
for during_action, failure in ((True, None), (False, None), (True, 'ack'),
@@ -1204,16 +1129,12 @@ class MovingPrimaryTests(unittest.TestCase):
bounds = {'x': 0, 'y': 0, 'width': 600, 'height': 600}
spec = {'target': {'pid': 20, 'window_id': 200}, 'bounds': bounds,
'name': 'agent', 'profile': {'mode': 'standard'}}
- source_plan = root / 'plan.json'
- source_plan.write_text(json.dumps({
+ args = harness_args(root, {
'purpose': 'policy', 'moving_primary': True, 'primary_point': [100, 200],
'foreground': {'pid': 10, 'window_id': 100}, 'agents': [spec],
'phases': [{'agent': 0, 'tool': 'click', 'arguments': {'x': 10, 'y': 20},
- 'expect': {'kind': 'refused', 'reason': 'permission_denied'}}]}))
- args = SimpleNamespace(plan=source_plan, evidence=root / 'evidence',
- trace_socket=root / 'cua-input-v3.sock', driver=root / 'driver',
- primary_grab=root / 'primary-grab', foreground_journal=root / 'journal',
- record_video=False)
+ 'expect': {'kind': 'refused', 'reason': 'permission_denied'}}]},
+ trace_socket=root / 'cua-input-v3.sock')
log, action_calls, held = [], [], [True]
def append_motion(point):
@@ -1270,22 +1191,17 @@ class MovingPrimaryTests(unittest.TestCase):
workers.append(worker)
return worker
- replacements = {
- 'provenance': Mock(return_value={}),
+ replacements = run_replacements(self, held, **{
'DirectMCP': Mock(side_effect=[agent, observer]),
'subprocess.Popen': Mock(return_value=grab),
'primary_acknowledgement': Mock(side_effect=AssertionError('incomplete HELD'))
if failure == 'startup' else Mock(return_value='HELD\n'),
'select.select': Mock(return_value=([grab.stdout], [], [])),
- 'wait_for': lambda predicate: self.assertTrue(predicate()),
- 'state': lambda path: {'held': held[0], 'clicks': 0, 'keys': 0, 'scroll': 0},
'wm': lambda: {'pid': 10, 'address': '0x10', 'workspace': 1,
'cursor': {'x': log[-1]['x'] if log else 100, 'y': 200}},
'Trace': Mock(return_value=trace_client), 'threading.Thread': thread,
- 'move_primary': movement, 'stop_process': lambda process: held.__setitem__(0, False),
- }
- for name, replacement in replacements.items():
- stack.enter_context(patch('production_realapp_proof.' + name, replacement))
+ 'move_primary': movement})
+ patch_module(stack, 'production_realapp_proof', replacements)
self.assertEqual(run(args), 0 if during_action and failure is None else 1)
if failure not in ('startup', 'motion'):
click_index = action_calls.index('click')
@@ -1393,13 +1309,31 @@ class RuntimeTests(unittest.TestCase):
self.assertEqual(spawn.call_args.kwargs['env']['CUA_DRIVER_PERMISSION_MODE'], 'unrestricted')
self.assertEqual(spawn.call_args.kwargs['env']['CUA_DRIVER_DANGEROUSLY_BYPASS_APPROVALS'], '1')
+ def test_unprovable_plans_fail_before_provenance_or_any_process(self):
+ cases = (
+ ('policy_cache requires continuous trace', policy_cache_plan(), {}, {'policy_cache': {'result': 'unproven'}}),
+ ('capacity requires continuous trace', capacity_plan(), {}, {'capacity': {'result': 'unproven'}}),
+ ('moving primary requires continuous trace', {**plan(), 'moving_primary': True}, {}, {}),
+ ('requires the independent primary observer', plan(), {'artifact_role': 'production'}, {}),
+ )
+ for error, candidate, overrides, retained in cases:
+ with self.subTest(error=error), tempfile.TemporaryDirectory() as directory, ExitStack() as stack:
+ args = harness_args(directory, candidate, **overrides)
+ launches = [stack.enter_context(patch('production_realapp_proof.' + name))
+ for name in ('provenance', 'DirectMCP', 'subprocess.Popen')]
+ self.assertEqual(run(args), 1)
+ for launch in launches:
+ launch.assert_not_called()
+ result = json.loads((args.evidence / 'result.json').read_text())
+ self.assertEqual(result['result'], 'failed')
+ self.assertRegex(result['error'], error)
+ self.assertEqual(result['continuous_isolation'], 'unproven')
+ for key, value in retained.items():
+ self.assertEqual(result[key], value)
+
def test_preflight_failure_is_retained_as_failure(self):
with tempfile.TemporaryDirectory() as directory:
- root = Path(directory)
- import json
- source_plan = root / 'plan.json'
- source_plan.write_text(json.dumps(plan()))
- args = SimpleNamespace(plan=source_plan, evidence=root / 'evidence')
+ args = harness_args(directory, plan())
with patch('production_realapp_proof.provenance', side_effect=AssertionError('SHA mismatch')):
self.assertEqual(run(args), 1)
result = json.loads((args.evidence / 'result.json').read_text())
@@ -1407,6 +1341,5 @@ class RuntimeTests(unittest.TestCase):
self.assertEqual(result['error'], 'SHA mismatch')
self.assertTrue((args.evidence / 'cleanup.json').is_file())
-
if __name__ == '__main__':
unittest.main()
diff --git a/libs/cua-driver/hyprland-plugin/tests/production_session_fault_proof.py b/libs/cua-driver/hyprland-plugin/tests/production_session_fault_proof.py
index f58833bf37..d130f57cf7 100644
--- a/libs/cua-driver/hyprland-plugin/tests/production_session_fault_proof.py
+++ b/libs/cua-driver/hyprland-plugin/tests/production_session_fault_proof.py
@@ -576,7 +576,7 @@ def run(args):
validate_plan(plan)
fault = SessionFault(plan, args)
origin = provenance(args, plan)
- for name in ('production_session_fault_proof.py', 'production_session_fault_proof_test.py',
+ for name in ('production_session_fault_proof.py', 'production_session_fault_proof_test.py', 'proof_fixtures.py',
'production_desktop_fault_proof.py', 'production_geometry_fault_proof.py',
'production_cancel_proof.py', 'desktop_faults.py'):
path = Path(__file__).with_name(name)
diff --git a/libs/cua-driver/hyprland-plugin/tests/production_session_fault_proof_test.py b/libs/cua-driver/hyprland-plugin/tests/production_session_fault_proof_test.py
index b13fd24ee1..4fe15f647c 100644
--- a/libs/cua-driver/hyprland-plugin/tests/production_session_fault_proof_test.py
+++ b/libs/cua-driver/hyprland-plugin/tests/production_session_fault_proof_test.py
@@ -11,53 +11,8 @@ import unittest
from unittest.mock import Mock, patch
import production_session_fault_proof as proof
-
-
-MONITOR = {'id': 0, 'name': 'Virtual-1', 'width': 1280, 'height': 800,
- 'x': 0, 'y': 0, 'scale': 1.0, 'transform': 0}
-BOUNDS = {'x': 10, 'y': 20, 'width': 800, 'height': 600}
-PARTIAL = {'structuredContent': {'effect': 'partial', 'route': 'synthetic_events',
- 'delivery': {'mode': 'background', 'delivered_count': 1}}}
-REFUSED = {'isError': True, 'structuredContent': {'effect': 'refused', 'reason': 'session_unavailable'}}
-
-
-def identity(pid, exe='/usr/bin/python3'):
- return {'pid': pid, 'uid': 1000, 'starttime': '123', 'exe': exe}
-
-
-def plan():
- return {'purpose': 'session_fault', 'disposable': True, 'fault': {'kind': 'dpms'},
- 'vm': {'machine_id': '1' * 32, 'boot_id': '12345678-1234-1234-1234-123456789abc'},
- 'compositor': {**identity(50, '/usr/bin/Hyprland'), 'instance': 'test_1'},
- 'foreground': {'pid': 10, 'window_id': 100}, 'primary_point': [20, 20],
- 'identities': {'foreground': identity(10), 'target': identity(20, '/usr/bin/soffice.bin')},
- 'foreground_fixture': {'sha256': 'a' * 64, 'journal': {'path': '/test/foreground.jsonl',
- 'device': 1, 'inode': 2, 'uid': 1000}}, 'monitors': [dict(MONITOR)],
- 'agents': [{'app': 'calc', 'name': 'session', 'target': {'pid': 20, 'window_id': 200},
- 'bounds': dict(BOUNDS), 'pointer_stage': 'select_range', 'drag': {}}],
- 'recovery': {'pointer_stage': 'click_b2'}}
-
-
-def status(generation=1, held=False):
- return {'configured': True, 'transport': {'ready': True}, 'input': {
- 'protocol': 3, 'test_only': False, 'seat_lifetime': 'compositor',
- 'upgrade': 'desktop_restart', 'transport_ready': True,
- 'lanes': [{'lane': lane, 'epoch': str(lane + 1) * 32, 'desktop_generation': generation,
- 'dispatches': 0, 'held_button': 272 if held and lane == 0 else 0,
- 'held_keys': 0, 'drag_active': held and lane == 0, 'lease_active': held and lane == 0,
- 'pointer_focus': held and lane == 0, 'keyboard_focus': False, 'reserved': held and lane == 0}
- for lane in (0, 1)]}}
-
-
-ACTIVE = [(0, 'start', 0, 0), (1, 'agent_admitted', 1, 0), (2, 'agent_drag_start', 1, 0),
- (3, 'pointer_button', 1, 1), (4, 'pointer_motion', 1, 0)]
-CANCEL = ACTIVE + [(8, 'agent_cancel', 1, 0), (9, 'pointer_button', 1, 0), (10, 'pointer_leave', 1, 0)]
-
-
-def trace(rows):
- return {'hook': True, 'active': True, 'overflow': False, 'timed_out': False, 'count': len(rows),
- 'events': [[i + 1, ms * 1_000_000, kind, 100, 100, lane, value]
- for i, (ms, kind, lane, value) in enumerate(rows)]}
+from proof_fixtures import (ACTIVE, CANCEL, MONITOR, PARTIAL, REFUSED, identity, ink, inkscape_profile, motion_gate,
+ retained_status, session_plan as plan, status, trace)
def fault_record():
@@ -77,6 +32,13 @@ def refusal_record():
class PlanTests(unittest.TestCase):
+ def test_inkscape_only_profile_reaches_the_shared_app_profile_gate(self):
+ candidate = inkscape_profile(plan())
+ proof.validate_plan(candidate)
+ candidate['agents'][0]['document'] = '/synthetic/private.svg'
+ with self.assertRaisesRegex(AssertionError, 'absolute synthetic SVG document'):
+ proof.validate_plan(candidate)
+
def test_exact_dpms_calc_plan_only(self):
proof.validate_plan(plan())
for change in ({'disposable': False}, {'purpose': 'apps'}, {'fault': {'kind': 'lock'}},
@@ -182,17 +144,15 @@ class OracleTests(unittest.TestCase):
with self.assertRaises(AssertionError):
proof.verify_cancelled(trace(CANCEL), fault_record(), {**action, 'response': REFUSED})
- def test_dpms_has_no_primary_focus_input_or_warp_suppression(self):
+ def test_dpms_does_not_suppress_primary_isolation_or_trace_validity(self):
+ # Primary classification is owned by primary_trace_test and page validity by
+ # trace_interval; one case each proves verify_cancelled applies them.
action = {'outcome': 'response', 'response': PARTIAL, 'replayed': False}
- for kind in ('cursor', 'pointer_focus', 'keyboard_focus', 'pointer_leave', 'pointer_button', 'keyboard_key', 'pointer_axis'):
- page = trace(CANCEL + [(11, kind, 0, 0), (12, 'cursor', 0, 0)])
- if kind == 'cursor':
- page['events'][-2][3] += 1 # Warp and return must still fail.
- with self.subTest(kind=kind), self.assertRaises(AssertionError):
- proof.verify_cancelled(page, fault_record(), action)
- for key, value in [('hook', False), ('overflow', True), ('timed_out', True), ('count', 0), ('active', False)]:
- with self.subTest(key=key), self.assertRaises(AssertionError):
- proof.verify_cancelled({**trace(CANCEL), key: value}, fault_record(), action)
+ page = trace(CANCEL + [(11, 'pointer_leave', 0, 0), (12, 'cursor', 0, 0)])
+ with self.assertRaisesRegex(AssertionError, "'result': 'failed'"):
+ proof.verify_cancelled(page, fault_record(), action)
+ with self.assertRaisesRegex(AssertionError, 'dropped events'):
+ proof.verify_cancelled({**trace(CANCEL), 'overflow': True}, fault_record(), action)
def test_status_is_production_v3_and_lifecycle_revokes_both_lanes(self):
proof.transition(status(1, held=True), status(2))
@@ -202,11 +162,11 @@ class OracleTests(unittest.TestCase):
changed['input']['lanes'][1][key] = value
with self.subTest(key=key), self.assertRaises(AssertionError):
proof.transition(status(1), changed)
- for key, value in [('test_only', True), ('protocol', 0), ('transport_ready', False)]:
- changed = status(2)
- changed['input'][key] = value
- with self.subTest(key=key), self.assertRaises(AssertionError):
- proof.lanes(changed)
+ # Production-status shape is owned by desktop_fault's verify_status; one case proves wiring.
+ changed = status(2)
+ changed['input']['test_only'] = True
+ with self.assertRaisesRegex(AssertionError, 'production v3 required'):
+ proof.lanes(changed)
def test_unobserved_power_or_watchdog_expiry_cannot_certify_cancellation(self):
action = {'outcome': 'response', 'response': PARTIAL, 'replayed': False}
@@ -292,17 +252,6 @@ class GroundingTests(unittest.TestCase):
for client in clients:
client.tool.assert_not_called()
- def test_failed_observation_never_dispatches_or_saves_a_complete_pair(self):
- clients = [Mock(process=Mock(pid=pid, poll=Mock(return_value=None))) for pid in (100, 101)]
- save = Mock()
- with patch.object(proof, 'prepare_drag', side_effect=AssertionError('bad snapshot')), \
- patch.object(proof, 'prepare_refusal', return_value={}):
- with self.assertRaisesRegex(AssertionError, 'bad snapshot'):
- proof.prepare_actions(clients, plan()['agents'][0], 'click_b2', save)
- save.assert_not_called()
- for client in clients:
- client.tool.assert_not_called()
-
def test_shared_runtime_is_rejected_before_observation(self):
client = Mock(process=Mock(pid=100, poll=Mock(return_value=None)))
with patch.object(proof, 'prepare_drag') as drag, patch.object(proof, 'prepare_refusal') as refusal:
@@ -326,6 +275,20 @@ class GroundingTests(unittest.TestCase):
'session': 'session-unavailable',
'prepared_ns': observed_ns, 'tool': 'click'})
+ def test_refusal_scroll_keeps_exact_target_and_original_observation(self):
+ before, pixels = ink()
+ target = {'pid': 20, 'window_id': 200}
+ before.update(**target, proof_image='synthetic.png', proof_observation_started_ns=1)
+ spec = {'app': 'inkscape', 'name': 'refusal', 'target': target, 'bounds': before['window_bounds']}
+ prepared = {'snapshot': before, 'target': dict(target), 'prepared_ns': 1}
+ with patch.object(proof.pointer_grounding, 'read_pixels', return_value=pixels):
+ probe = proof.prepare_refusal(prepared, spec, 'scroll_down')
+ self.assertEqual(probe['tool'], 'scroll')
+ self.assertEqual(probe['prepared_ns'], 1)
+ before['window_id'] += 1
+ with self.assertRaises(AssertionError):
+ proof.prepare_refusal(prepared, spec, 'scroll_down')
+
def test_shared_observation_requires_exact_identity_geometry_and_time(self):
spec = plan()['agents'][0]
original = {'snapshot': {**spec['target'], 'window_bounds': spec['bounds'],
@@ -518,12 +481,6 @@ class WatchdogTests(unittest.TestCase):
os.close(reader)
-def retained_status(generation=2, lane=1):
- value = status(generation)
- value['input']['lanes'][lane - 1]['pointer_focus'] = True
- return value
-
-
def claimed_refusal(interrupted_lane=1, claimed_lane=0):
value = refusal_record()
value.update(pointer_cleanup='retained_inert', lane=interrupted_lane,
@@ -538,30 +495,6 @@ def claimed_refusal(interrupted_lane=1, claimed_lane=0):
return value
-def motion_gate(record, lane=1):
- """A 13px surface-local movement, with the same held lane across status."""
- page = trace([(0, 'start', 0, 0), (1, 'agent_admitted', lane, 0),
- (2, 'agent_drag_start', lane, 0), (2.5, 'pointer_enter', lane, 0),
- (3, 'pointer_button', lane, 1), (4, 'pointer_motion', lane, 0)])
- for row in page['events']:
- row[1] = int(row[1])
- if row[2] in ('pointer_enter', 'pointer_motion'):
- row.extend([10 if row[2] == 'pointer_enter' else 23, 20])
- gate = status(1, held=True)
- if lane == 2:
- gate['input']['lanes'][0], gate['input']['lanes'][1] = gate['input']['lanes'][1], gate['input']['lanes'][0]
- for index, row in enumerate(gate['input']['lanes']):
- row['lane'], row['epoch'] = index, str(index + 1) * 32
- record.update(pointer_cleanup='retained_inert', min_motion_px=12,
- prefix=page, gate_first=deepcopy(page), lane=lane,
- status_started_ns=5_000_000, gate_status=gate, after=retained_status(2, lane))
- boundary = deepcopy(page)
- boundary['events'] += [[7, 8_000_000, 'agent_cancel', 100, 100, lane, 0],
- [8, 9_000_000, 'pointer_button', 100, 100, lane, 0]]
- boundary['count'] = len(boundary['events'])
- return boundary
-
-
class RetainedPointerTests(unittest.TestCase):
def test_fresh_claim_is_capacity_only_and_must_match_response_lane(self):
for interrupted in (1, 2):
@@ -670,11 +603,13 @@ class RetainedPointerTests(unittest.TestCase):
value = plan()
value['fault'].update(pointer_cleanup='retained_inert', min_motion_px=12.5)
proof.validate_plan(value)
- for change in ({'pointer_cleanup': 'anything'}, {'extra': True},
- *({'min_motion_px': v} for v in (None, True, 0, -1, float('inf'), float('nan'), '12'))):
+ # Threshold validity is owned by desktop_fault's MotionGateTests; one value proves wiring.
+ for change, error in (({'pointer_cleanup': 'anything'}, 'unknown pointer cleanup policy'),
+ ({'extra': True}, 'unsupported fault option'),
+ ({'min_motion_px': 0}, 'positive finite min_motion_px')):
bad = deepcopy(value)
bad['fault'].update(change)
- with self.subTest(change=change), self.assertRaises(AssertionError):
+ with self.subTest(change=change), self.assertRaisesRegex(AssertionError, error):
proof.validate_plan(bad)
def test_both_lanes_keep_inert_presence_only_when_explicitly_selected(self):
@@ -746,12 +681,6 @@ class RetainedPointerTests(unittest.TestCase):
bad['input']['lanes'][0][key] = change
with self.subTest(key=key), self.assertRaises(AssertionError):
proof.verify_stable_inert(value['after_close'], bad, 1)
- for key, field in (('before', 'reserved'), ('after', 'held_keys'),
- ('after', 'dispatches'), ('after', 'pointer_focus')):
- bad = deepcopy(value)
- bad[key]['input']['lanes'][0][field] = False if field == 'pointer_focus' else (1 if field in ('held_keys', 'dispatches') else True)
- with self.subTest(key=key, field=field), self.assertRaises(AssertionError):
- proof.verify_refusal(bad)
before = trace(CANCEL[:-1])
proof.verify_inert_interval(before, before)
for kind in ('pointer_leave', 'pointer_enter', 'pointer_motion', 'agent_admitted'):
diff --git a/libs/cua-driver/hyprland-plugin/tests/production_target_lifetime_proof.py b/libs/cua-driver/hyprland-plugin/tests/production_target_lifetime_proof.py
index 128aa3a4f8..a905138312 100644
--- a/libs/cua-driver/hyprland-plugin/tests/production_target_lifetime_proof.py
+++ b/libs/cua-driver/hyprland-plugin/tests/production_target_lifetime_proof.py
@@ -72,7 +72,8 @@ def validate_owned(spec):
document = owned['document']
assert set(document) == {'path', 'device', 'inode', 'uid', 'sha256'}
path = Path(document['path'])
- assert path.is_absolute() and path.name == ('cua-smoke-inkscape.svg' if spec['app'] == 'inkscape' else 'cua-smoke-calc.ods')
+ assert path.is_absolute() and path.name == ('cua-smoke-inkscape.svg' if spec['app'] == 'inkscape' else 'cua-smoke-calc.ods'), \
+ 'owned document must be the synthetic smoke document'
assert all(type(document[k]) is int and document[k] >= 0 for k in ('device', 'inode', 'uid'))
assert len(document['sha256']) == 64 and all(c in '0123456789abcdef' for c in document['sha256'])
if spec['app'] == 'inkscape':
@@ -91,7 +92,8 @@ def validate_plan(plan):
assert recovery['mode'] == 'prepared_distinct_process'
fresh = recovery['agent']
inkscape = plan.get('app_profile') == 'inkscape-only'
- assert fresh['pointer_stage'] in (('click_rectangle',) if inkscape else ('click_a1', 'click_b2'))
+ assert fresh['pointer_stage'] in (('click_rectangle',) if inkscape else ('click_a1', 'click_b2')), \
+ 'recovery needs a fresh click stage'
recovery_stage = 'scroll_down' if inkscape else 'click_b2'
base = {k: v for k, v in plan.items() if k != 'fault'}
primary_plan({**base, 'purpose': 'primary_conflict', 'case': 'initial_refusal',
@@ -471,7 +473,8 @@ def run(args):
fault = TargetLifetime(plan)
origin = provenance(args, plan)
origin['ownership'] = {key: plan[key] for key in ('vm', 'compositor', 'processes', 'recovery')}
- for name in ('production_target_lifetime_proof.py', 'production_target_lifetime_proof_test.py'):
+ for name in ('production_target_lifetime_proof.py', 'production_target_lifetime_proof_test.py',
+ 'proof_fixtures.py'):
path = Path(__file__).with_name(name)
origin['files'][name] = {'path': str(path.resolve()), 'sha256': hashlib.sha256(path.read_bytes()).hexdigest()}
save('provenance.json', origin)
diff --git a/libs/cua-driver/hyprland-plugin/tests/production_target_lifetime_proof_test.py b/libs/cua-driver/hyprland-plugin/tests/production_target_lifetime_proof_test.py
index 39d2b23da6..27ce2ecd07 100644
--- a/libs/cua-driver/hyprland-plugin/tests/production_target_lifetime_proof_test.py
+++ b/libs/cua-driver/hyprland-plugin/tests/production_target_lifetime_proof_test.py
@@ -12,8 +12,8 @@ import unittest
from unittest.mock import Mock, patch
import production_target_lifetime_proof as proof
-from production_primary_conflict_proof_test import plan as base_plan, identity, DELIVERED
-from production_session_fault_proof_test import ACTIVE, PARTIAL, status, trace
+from proof_fixtures import (ACTIVE, DELIVERED, PARTIAL, assert_rejects, identity, inkscape_profile,
+ primary_conflict_plan as base_plan, status, trace)
DESTROYED = ACTIVE + [(8, 'agent_cancel', 1, 0)]
@@ -68,6 +68,27 @@ def action():
class PlanTests(unittest.TestCase):
+ def test_inkscape_only_profile_binds_both_the_target_and_its_replacement(self):
+ candidate = inkscape_profile(plan())
+ old, fresh = candidate['agents'][0], candidate['recovery']['agent']
+ fresh.update(app='inkscape', document='/synthetic/replacement/cua-smoke-inkscape.svg',
+ pointer_stage='click_rectangle')
+ candidate['recovery']['identity']['exe'] = '/usr/bin/inkscape'
+ for index, spec in enumerate((old, fresh)):
+ spec['app_id_tag'] = f'cua-profile-lane-{index}'
+ spec['owned'].pop('profile')
+ spec['owned']['document']['path'] = spec['document']
+ proof.validate_plan(candidate)
+ assert_rejects(self, proof.validate_plan, candidate, [
+ ('absolute synthetic SVG document', lambda p: p['agents'][0].update(document='/synthetic/private.svg')),
+ ('fresh click stage', lambda p: p['recovery']['agent'].update(pointer_stage='move_rectangle')),
+ ('wrong Inkscape executable identity', lambda p: p['recovery']['identity'].update(exe='/usr/bin/soffice.bin')),
+ ('distinct Inkscape application instances', lambda p: p['recovery']['agent'].update(
+ app_id_tag=p['agents'][0]['app_id_tag'])),
+ ('synthetic smoke document', lambda p: p['recovery']['agent']['owned']['document'].update(
+ path='/synthetic/wrong.svg')),
+ ])
+
def test_inkscape_requires_exact_reviewed_app_id_tag_argv_and_identity(self):
spec = {'app': 'inkscape', 'app_id_tag': 'cua-profile-lane-0',
'document': '/synthetic/cua-smoke-inkscape.svg'}
@@ -207,11 +228,11 @@ class OracleTests(unittest.TestCase):
proof.verify_fault(trace(DESTROYED), record(), observed)
def test_raw_trace_rejects_corruption_primary_leaks_other_lane_and_replay(self):
- for field, value in (('hook', False), ('active', False), ('overflow', True), ('timed_out', True), ('count', 0)):
- with self.subTest(field=field), self.assertRaises(AssertionError):
- proof.verify_fault({**trace(DESTROYED), field: value}, record(), action())
- for kind, lane, value in [('pointer_button', 0, 0), ('keyboard_key', 0, 1), ('pointer_focus', 0, 0),
- ('pointer_axis', 0, 0), ('agent_cancel', 2, 0), ('agent_admitted', 1, 0),
+ # Page validity is owned by trace_interval (realapp TraceIntervalTests); one case proves wiring.
+ with self.assertRaisesRegex(AssertionError, 'dropped events'):
+ proof.verify_fault({**trace(DESTROYED), 'overflow': True}, record(), action())
+ # Primary classification is owned by primary_trace_test; one primary row proves wiring.
+ for kind, lane, value in [('keyboard_key', 0, 1), ('agent_cancel', 2, 0), ('agent_admitted', 1, 0),
('agent_drag_end', 1, 0), ('agent_drag_start', 1, 0), ('agent_action_end', 1, 0),
('pointer_motion', 1, 0), ('pointer_button', 1, 1), ('keyboard_key', 1, 1)]:
with self.subTest(kind=kind, lane=lane), self.assertRaises(AssertionError):
@@ -350,9 +371,6 @@ class RecoveryTests(unittest.TestCase):
self.assertTrue(result['unreserved'])
self.assertFalse(result['input_authority'])
self.assertEqual(result['parked_pointer_focus'], pointer)
- if pointer:
- with self.assertRaises(AssertionError):
- proof.lanes(after, cleared=True)
def test_final_cleanup_rejects_authority_wrong_lane_and_identity_drift(self):
before = recovery_status()
@@ -434,9 +452,9 @@ class RecoveryTests(unittest.TestCase):
proof.cleanup_trace(prefix, stopped, stopped=True)
def test_one_fresh_distinct_action_unknown_never_replayed(self):
+ # Freshness rules are owned by cancel's ObservationTests; 'cached' proves wiring.
for app, failure in product(('calc', 'inkscape'), (None, 'alive', 'reused_runtime', 'stale',
- 'unknown', 'bad_effect', 'same_snapshot', 'same_artifact', 'cached', 'before_return',
- 'same_runtime', 'dead_after')):
+ 'unknown', 'bad_effect', 'cached', 'same_runtime', 'dead_after')):
with self.subTest(app=app, failure=failure), ExitStack() as stack:
candidate = plan()
if app == 'inkscape':
@@ -455,14 +473,8 @@ class RecoveryTests(unittest.TestCase):
'proof_observation_started_ns': 100, 'proof_observation_finished_ns': 101}
after = {**before, 'proof_runtime': {'pid': 102, 'directory': str(Path.cwd())},
'proof_image': 'after.png', 'proof_observation_started_ns': 104, 'proof_observation_finished_ns': 105}
- if failure == 'same_snapshot':
- after = dict(before)
- elif failure == 'same_artifact':
- after['proof_image'] = before['proof_image']
- elif failure == 'cached':
+ if failure == 'cached':
after.update(proof_observation_started_ns=100, proof_observation_finished_ns=101)
- elif failure == 'before_return':
- after['proof_observation_started_ns'] = 102
prepared = {'target': fault.fresh['target'], 'snapshot': before, 'prepared_ns': 100,
'arguments': {'x': 20, 'y': 30}, 'oracle': {'stage': fault.fresh['pointer_stage']}}
stack.enter_context(patch.object(proof, 'prepare_drag', return_value=prepared))
diff --git a/libs/cua-driver/hyprland-plugin/tests/proof_fixtures.py b/libs/cua-driver/hyprland-plugin/tests/proof_fixtures.py
new file mode 100644
index 0000000000..31241a6389
--- /dev/null
+++ b/libs/cua-driver/hyprland-plugin/tests/proof_fixtures.py
@@ -0,0 +1,384 @@
+"""Shared synthetic fixtures for the Hyprland proof-harness tests.
+
+This is not a test module: discovery loads only ``*_test.py``. Proofs that
+hash their own tests into ``provenance.json`` also hash this file, because
+those tests are only reproducible together with it.
+"""
+from copy import deepcopy
+import io
+import json
+from pathlib import Path
+from types import SimpleNamespace
+from unittest.mock import Mock, patch
+import zipfile
+
+
+# Trace pages. Rows are [sequence, timestamp_ns, kind, x, y, lane, value].
+
+def page(rows, active=True):
+ """One complete, healthy trace page around already-built rows."""
+ return {'hook': True, 'active': active, 'overflow': False, 'timed_out': False,
+ 'count': len(rows), 'events': rows}
+
+
+def trace(rows, active=True, *, point=(100, 100), unit=1_000_000):
+ """Page from ``(time, kind, lane, value)`` rows; time is in ``unit`` ns."""
+ return page([[i + 1, int(time * unit), kind, *point, lane, value]
+ for i, (time, kind, lane, value) in enumerate(rows)], active)
+
+
+def conflict_trace(events=(), active=True):
+ """Page with its own start (and stop when inactive) at the primary point."""
+ rows = [(0, 'start', 0, 0), *events, *(() if active else ((20, 'stop', 0, 0),))]
+ return trace(rows, active, point=(30, 40), unit=1)
+
+
+START = ('start', 100, 200, 0, 0)
+STOP = ('stop', 100, 200, 0, 0)
+
+
+def primary_trace(*events):
+ """Stopped page from ``(kind, x, y, lane, value)`` events, 1 ms apart."""
+ return page([[i + 1, i * 1_000_000, kind, x, y, lane, value]
+ for i, (kind, x, y, lane, value) in enumerate(events)], active=False)
+
+
+ACTIVE = [(0, 'start', 0, 0), (1, 'agent_admitted', 1, 0), (2, 'agent_drag_start', 1, 0),
+ (3, 'pointer_button', 1, 1), (4, 'pointer_motion', 1, 0)]
+CANCEL = ACTIVE + [(8, 'agent_cancel', 1, 0), (9, 'pointer_button', 1, 0), (10, 'pointer_leave', 1, 0)]
+
+
+# Production v3 plugin status.
+
+def lane(index, **values):
+ """One inert, unreserved compositor lane; override fields by keyword."""
+ return {'lane': index, 'epoch': str(index + 1) * 32, 'desktop_generation': 1, 'dispatches': 0,
+ 'held_button': 0, 'held_keys': 0, 'drag_active': False, 'lease_active': False,
+ 'pointer_focus': False, 'keyboard_focus': False, 'reserved': False, **values}
+
+
+def lane_status(*lanes):
+ """Complete ``cua:status`` for a production v3 build (two inert lanes by default)."""
+ return {'state': 'input_v3_candidate', 'configured': True, 'transport': {'ready': True}, 'input': {
+ 'protocol': 3, 'test_only': False, 'seat_lifetime': 'compositor',
+ 'upgrade': 'desktop_restart', 'transport_ready': True,
+ 'lanes': list(lanes) or [lane(0), lane(1)]}}
+
+
+HELD = {'held_button': 272, 'drag_active': True, 'lease_active': True,
+ 'pointer_focus': True, 'reserved': True}
+
+
+def status(generation=1, held=False):
+ """Two lanes at one desktop generation; ``held`` gives lane 0 a held drag."""
+ return lane_status(*(lane(index, desktop_generation=generation, **(HELD if held and index == 0 else {}))
+ for index in (0, 1)))
+
+
+def retained_status(generation=2, lane=1):
+ """Cleared status that keeps passive pointer focus on one (1-based) lane."""
+ value = status(generation)
+ value['input']['lanes'][lane - 1]['pointer_focus'] = True
+ return value
+
+
+def motion_gate(record, lane=1):
+ """A 13px surface-local movement, with the same held lane across status."""
+ gate_page = trace([(0, 'start', 0, 0), (1, 'agent_admitted', lane, 0),
+ (2, 'agent_drag_start', lane, 0), (2.5, 'pointer_enter', lane, 0),
+ (3, 'pointer_button', lane, 1), (4, 'pointer_motion', lane, 0)])
+ for row in gate_page['events']:
+ if row[2] in ('pointer_enter', 'pointer_motion'):
+ row.extend([10 if row[2] == 'pointer_enter' else 23, 20])
+ gate = status(1, held=True)
+ if lane == 2:
+ gate['input']['lanes'].reverse()
+ for index, row in enumerate(gate['input']['lanes']):
+ row['lane'], row['epoch'] = index, str(index + 1) * 32
+ record.update(pointer_cleanup='retained_inert', min_motion_px=12,
+ prefix=gate_page, gate_first=deepcopy(gate_page), lane=lane,
+ status_started_ns=5_000_000, gate_status=gate, after=retained_status(2, lane))
+ boundary = deepcopy(gate_page)
+ boundary['events'] += [[7, 8_000_000, 'agent_cancel', 100, 100, lane, 0],
+ [8, 9_000_000, 'pointer_button', 100, 100, lane, 0]]
+ boundary['count'] = len(boundary['events'])
+ return boundary
+
+
+# Driver responses.
+
+PARTIAL = {'structuredContent': {'effect': 'partial', 'route': 'synthetic_events',
+ 'delivery': {'mode': 'background', 'delivered_count': 1}}}
+DELIVERED = {'structuredContent': {'effect': 'unverifiable', 'route': 'synthetic_events',
+ 'delivery': {'mode': 'background'}}}
+REFUSED = {'isError': True, 'structuredContent': {'effect': 'refused', 'reason': 'session_unavailable'}}
+
+
+def action(response=PARTIAL):
+ """One unreplayed Driver response retained by a fault proof."""
+ return {'outcome': 'response', 'response': deepcopy(response), 'replayed': False}
+
+
+# Processes and runtimes.
+
+def identity(pid, exe='/usr/bin/python3'):
+ return {'pid': pid, 'uid': 1000, 'starttime': '123', 'exe': exe}
+
+
+def client(pid, alive=True):
+ """Owned Driver runtime whose kill/terminate are observable through ``poll``."""
+ process = Mock(pid=pid, poll=Mock(return_value=None if alive else 0))
+ process.kill.side_effect = lambda: setattr(process.poll, 'return_value', -9)
+ process.terminate.side_effect = lambda: setattr(process.poll, 'return_value', -15)
+ return Mock(directory=Path.cwd(), process=process, failed=False)
+
+
+# Reviewed plans shared by several proofs.
+
+BOUNDS = {'x': 10, 'y': 20, 'width': 800, 'height': 600}
+VM = {'machine_id': 'a' * 32, 'boot_id': 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa'}
+
+
+def plan():
+ """Two-lane Calc/Inkscape real-app plan."""
+ return {'purpose': 'apps', 'foreground': {'pid': 10, 'window_id': 100},
+ 'agents': [{'app': 'calc', 'target': {'pid': 20, 'window_id': 200}},
+ {'app': 'inkscape', 'target': {'pid': 30, 'window_id': 300}}],
+ 'phases': [{'parallel': [{'agent': 0, 'tool': 'drag', 'arguments': {}},
+ {'agent': 1, 'tool': 'drag', 'arguments': {}}]}],
+ 'outputs': [{'agent': 0, 'attributes': {'value': '96'}},
+ {'agent': 1, 'rect_translation': [[10, 20], [30, 40]]}]}
+
+
+def capacity_plan():
+ result = {**plan(), 'purpose': 'capacity', 'outputs': []}
+ result['agents'].append({'app': 'inkscape', 'target': {'pid': 40, 'window_id': 400}})
+ for spec in result['agents']:
+ spec.update(name='same-public-name', profile={'mode': 'standard'},
+ bounds={'x': 0, 'y': 0, 'width': 600, 'height': 600})
+ result['phases'] = [{'agent': index, 'tool': 'click', 'arguments': {'x': 20, 'y': 30}}
+ for index in range(3)]
+ result['phases'][2]['expect'] = {'kind': 'refused', 'reason': 'lane_busy'}
+ return result
+
+
+def capacity_events(lane):
+ return [('agent_admitted', 100, 200, lane, 0),
+ ('pointer_button', 100, 200, lane, 1),
+ ('pointer_button', 100, 200, lane, 0),
+ ('agent_action_end', 100, 200, lane, 0)]
+
+
+def policy_cache_plan():
+ result = capacity_plan()
+ result.update(purpose='policy_cache', agents=result['agents'][:1])
+ result['agents'][0]['profile'].update(manifest='reviewed.yaml', approve_manifest=True)
+ result['phases'] = [
+ {'agent': 0, 'tool': 'click', 'arguments': {'x': 20, 'y': 30}},
+ {'agent': 0, 'tool': 'press_key', 'arguments': {'key': 'ESC'},
+ 'expect': {'kind': 'refused', 'reason': 'permission_denied',
+ 'message': "Permission denied: capability manifest denies tool 'press_key'"}},
+ {'agent': 0, 'tool': 'click', 'arguments': {'x': 30, 'y': 40}},
+ ]
+ return result
+
+
+def inkscape_plan(capacity=False):
+ """The opt-in two-Inkscape real-app (or capacity) plan with saved SVG oracles."""
+ candidate = capacity_plan() if capacity else plan()
+ candidate['app_profile'] = 'inkscape-only'
+ candidate['package_versions'] = {'inkscape': '1.4.4-6'}
+ for index, spec in enumerate(candidate['agents']):
+ spec.update(app='inkscape', document=f'/synthetic/lane-{index}.svg')
+ candidate['outputs'] = [] if capacity else [
+ {'agent': i, 'path': spec['document'], 'format': 'svg',
+ 'xpath': './/svg:rect[@id="smoke-rectangle"]',
+ 'namespaces': {'svg': 'http://www.w3.org/2000/svg'},
+ 'rect_translation': [[2, 2], [0, 0]]}
+ for i, spec in enumerate(candidate['agents'])]
+ return candidate
+
+
+GEOMETRY_STAGES = {'calc': 'select_range', 'inkscape': 'move_rectangle'}
+
+
+def geometry_plan(kind='move', app='calc'):
+ return {'purpose': 'geometry_fault', 'disposable': True, 'compositor': {'pid': 50, 'instance': 'test_1'},
+ 'foreground': {'pid': 10, 'window_id': 100}, 'primary_point': [20, 20],
+ 'agents': [{'app': app, 'name': 'geometry', 'target': {'pid': 20, 'window_id': 200},
+ 'bounds': dict(BOUNDS), 'pointer_stage': GEOMETRY_STAGES[app], 'drag': {}}],
+ 'fault': {'kind': kind, 'to': [30, 40] if kind == 'move' else [820, 620]},
+ 'recovery': {'pointer_stage': 'click_b2' if app == 'calc' else 'scroll_down'}}
+
+
+MONITOR = {'id': 0, 'name': 'Virtual-1', 'width': 1280, 'height': 800,
+ 'x': 0, 'y': 0, 'scale': 1.0, 'transform': 0}
+
+
+def session_plan():
+ return {'purpose': 'session_fault', 'disposable': True, 'fault': {'kind': 'dpms'},
+ 'vm': {'machine_id': '1' * 32, 'boot_id': '12345678-1234-1234-1234-123456789abc'},
+ 'compositor': {**identity(50, '/usr/bin/Hyprland'), 'instance': 'test_1'},
+ 'foreground': {'pid': 10, 'window_id': 100}, 'primary_point': [20, 20],
+ 'identities': {'foreground': identity(10), 'target': identity(20, '/usr/bin/soffice.bin')},
+ 'foreground_fixture': {'sha256': 'a' * 64, 'journal': {'path': '/test/foreground.jsonl',
+ 'device': 1, 'inode': 2, 'uid': 1000}}, 'monitors': [dict(MONITOR)],
+ 'agents': [{'app': 'calc', 'name': 'session', 'target': {'pid': 20, 'window_id': 200},
+ 'bounds': dict(BOUNDS), 'pointer_stage': 'select_range', 'drag': {}}],
+ 'recovery': {'pointer_stage': 'click_b2'}}
+
+
+def lock_plan():
+ return {**session_plan(), 'purpose': 'lock_refusal', 'fault': {'kind': 'lock'},
+ 'lock_fixture': {'path': '/test/session_lock_fixture', 'device': 1, 'inode': 2,
+ 'uid': 1000, 'sha256': 'b' * 64, 'source_sha256': 'c' * 64}}
+
+
+def primary_conflict_plan(app='calc'):
+ return {'purpose': 'primary_conflict', 'case': 'initial_refusal', 'disposable': True, 'vm': dict(VM),
+ 'compositor': {**identity(50, '/usr/bin/Hyprland'), 'instance': 'test_1'},
+ 'processes': {'target': identity(20), 'foreground': identity(10)},
+ 'foreground': {'pid': 10, 'window_id': 100}, 'primary_point': [20, 20], 'package_versions': {},
+ 'agents': [{'app': app, 'name': 'primary-conflict', 'target': {'pid': 20, 'window_id': 200},
+ 'bounds': dict(BOUNDS), 'pointer_stage': GEOMETRY_STAGES[app], 'drag': {}}],
+ 'recovery': {'pointer_stage': 'click_b2' if app == 'calc' else 'scroll_down'}}
+
+
+def inkscape_profile(candidate, *, drag=True):
+ """Convert a Calc fault plan to the opt-in ``inkscape-only`` profile."""
+ candidate = deepcopy(candidate)
+ candidate['app_profile'] = 'inkscape-only'
+ for index, spec in enumerate(candidate['agents']):
+ spec.update(app='inkscape', document=f'/synthetic/agent-{index}/cua-smoke-inkscape.svg')
+ if drag:
+ spec.update(pointer_stage='move_rectangle', drag={})
+ for key in ('identities', 'processes'):
+ if key in candidate:
+ candidate[key]['target']['exe'] = '/usr/bin/inkscape'
+ if 'pointer_stage' in candidate.get('recovery', {}):
+ candidate['recovery'] = {'pointer_stage': 'scroll_down'}
+ return candidate
+
+
+# Accessibility snapshots and synthetic pixels.
+
+CALC = {'window_title': 'cua-smoke-calc.ods - LibreOffice Calc',
+ 'elements': [{'role': 'text', 'label': 'Name Box', 'value': 'A1'}]}
+INKSCAPE = {
+ 'elements': [
+ {'element_index': 10, 'role': 'menu', 'label': 'Edit', 'enabled': True},
+ {'element_index': 11, 'parent_index': 10, 'role': 'menu item',
+ 'label': 'Select All', 'enabled': True},
+ {'element_index': 12, 'role': 'table cell', 'label': 'smoke-rectangle', 'enabled': True}],
+ 'tree_markdown': '\n'.join([
+ ' - [10] menu "Edit" [actions=[click]]',
+ ' - [11] menu item "Select All" [actions=[click]]',
+ ' - [12] table cell "smoke-rectangle" [actions=[activate]]',
+ ' - label = "No objects selected. Click, Shift+click, Alt+scroll mouse on top of '
+ 'objects, or drag around objects to select."']),
+}
+INKSCAPE_SELECTED = {
+ 'elements': [{'element_index': 1, 'role': 'table cell',
+ 'label': 'smoke-rectangle', 'enabled': True}] + [
+ {'element_index': index, 'role': 'spin button', 'label': f'{value:.3f}',
+ 'value': f'{value:.1f}', 'enabled': True}
+ for index, value in enumerate((40, 60, 80, 50), 2)],
+ 'tree_markdown': '\n'.join([
+ ' - [1] table cell "smoke-rectangle" [actions=[activate]]',
+ ' - label = "Rectangle in root. Click selection again to toggle scale/rotation handles."',
+ *[f' - label = "{axis}:"\n - [{index}] spin button "{value:.3f}" '
+ f'value="{value:.1f}" [actions=[activate]]'
+ for index, (axis, value) in enumerate((('X', 40), ('Y', 60), ('W', 80), ('H', 50)), 2)]]),
+}
+
+
+def changed_ods(original, text='abc', empty_first=False):
+ destination = io.BytesIO()
+ with zipfile.ZipFile(io.BytesIO(original)) as source, zipfile.ZipFile(destination, 'w') as target:
+ for name in source.namelist():
+ value = source.read(name)
+ if name == 'content.xml':
+ cell = (f'<table:table-cell office:value-type="string"><text:p>{text}</text:p>'
+ '</table:table-cell>')
+ if empty_first:
+ cell = '<table:table-cell/>' + cell
+ value = value.replace(b'<table:table-cell/>', cell.encode())
+ target.writestr(name, value)
+ return destination.getvalue()
+
+
+class Image:
+ width = height = 500
+
+ def __init__(self):
+ self.points = {}
+
+ def rgb(self, x, y):
+ assert 0 <= x < self.width and 0 <= y < self.height
+ return self.points.get((x, y), (255, 255, 255))
+
+ def rectangle(self, x, y, w, h):
+ self.points.update({(a, b): (51, 102, 153) for a in range(x, x + w) for b in range(y, y + h)})
+
+
+def app_snapshot(app):
+ return {'window_title': f'cua-smoke-{app}', 'window_bounds': {'x': 600, 'y': 400, 'width': 500, 'height': 500},
+ 'screenshot_width': 500, 'screenshot_height': 500}
+
+
+def ink(selected=True, dx=0, dy=0, scroll_y=0):
+ """Inkscape snapshot and pixels for the smoke rectangle, optionally moved."""
+ state = {**app_snapshot('inkscape'), **deepcopy(INKSCAPE_SELECTED if selected else INKSCAPE)}
+ if selected:
+ for row in state['elements']:
+ if row['role'] == 'spin button':
+ row['frame'] = {'x': 700, 'y': 435, 'w': 100, 'h': 34}
+ for index, value in ((2, 40 + dx * .8), (3, 60 + dy * .8)):
+ row = next(row for row in state['elements'] if row['element_index'] == index)
+ state['tree_markdown'] = state['tree_markdown'].replace(
+ f'[{index}] spin button "{row["label"]}" value="{row["value"]}"',
+ f'[{index}] spin button "{value:.3f}" value="{value:.1f}"')
+ row.update(label=f'{value:.3f}', value=f'{value:.1f}')
+ image = Image()
+ image.rectangle(120 + dx, 150 + dy + scroll_y, 100, 60)
+ return state, image
+
+
+# Real-app runner scaffolding (production_realapp_proof.run).
+
+def harness_args(root, candidate, **overrides):
+ """Write ``candidate`` as the reviewed plan and return runner arguments."""
+ path = Path(root) / 'plan.json'
+ path.write_text(json.dumps(candidate))
+ values = {'plan': path, 'evidence': Path(root) / 'evidence', 'trace_socket': None,
+ 'driver': Path(root) / 'driver', 'primary_grab': Path(root) / 'primary-grab',
+ 'foreground_journal': Path(root) / 'journal', 'record_video': False}
+ return SimpleNamespace(**{**values, **overrides})
+
+
+def run_replacements(case, held, **overrides):
+ """Desktop-free replacements for the runner's native primary and provenance reads."""
+ return {'provenance': Mock(return_value={}),
+ 'subprocess.Popen': Mock(return_value=Mock(poll=Mock(return_value=None))),
+ 'primary_acknowledgement': Mock(return_value='HELD\n'),
+ 'wait_for': lambda predicate: case.assertTrue(predicate()),
+ 'state': lambda path: {'held': held[0], 'clicks': 0, 'keys': 0, 'scroll': 0},
+ 'wm': lambda: {'pid': 10, 'address': '0x10', 'workspace': 1, 'cursor': {'x': 100, 'y': 200}},
+ 'stop_process': lambda process: held.__setitem__(0, False),
+ **overrides}
+
+
+def patch_module(stack, module, replacements):
+ for name, replacement in replacements.items():
+ stack.enter_context(patch(module + '.' + name, replacement))
+
+
+# Table-driven refusals.
+
+def assert_rejects(case, check, base, mutations, error=AssertionError):
+ """Each ``(pattern, mutate)`` row must fail ``check`` with its own message."""
+ for pattern, mutate in mutations:
+ candidate = deepcopy(base)
+ mutate(candidate)
+ with case.subTest(pattern=pattern), case.assertRaisesRegex(error, pattern):
+ check(candidate)
diff --git a/libs/cua-driver/hyprland-plugin/tests/realapp_proof_test.py b/libs/cua-driver/hyprland-plugin/tests/realapp_proof_test.py
index cd52e6e193..ab1652edf2 100644
--- a/libs/cua-driver/hyprland-plugin/tests/realapp_proof_test.py
+++ b/libs/cua-driver/hyprland-plugin/tests/realapp_proof_test.py
@@ -2,7 +2,7 @@ import unittest
import xml.etree.ElementTree as ET
from realapp_proof import cleanup_all, rect_position, released_synthetic_input, validate_plan
-from primary_trace_test import START, STOP, trace
+from proof_fixtures import START, STOP, primary_trace as trace
class ProofOracles(unittest.TestCase):