"""Exercise the packaged CAD probe/quit helpers without opening any project.""" import argparse import json from pathlib import Path import sys sys.path.insert(0, str(Path(__file__).resolve().parents[1] / 'src')) from dx_productivity.trial_task_center import isolated_cad from private_desktop_observer import PrivateDesktopObserver def main(): parser = argparse.ArgumentParser() parser.add_argument('--executable', type=Path, required=True) parser.add_argument('--output', type=Path, required=True) args = parser.parse_args() executable, output = args.executable.resolve(strict=True), args.output.resolve() output.mkdir(parents=True, exist_ok=False) root = output / 'data/tasks/packaged/quick-run' original_command = isolated_cad._helper_command original_environment = isolated_cad._child_environment commands = [] def helper(action, evidence, pid): command = (str(executable), '--private-cad-action', action, '--private-cad-evidence', str(evidence), '--private-cad-pid', str(pid)) commands.append({'action': action, 'executable': str(executable)}) return command def environment(value): result = dict(value) # Ensure helpers use the frozen bundle without the source import path. result.pop('PYTHONPATH', None) result.pop('PYTHONHOME', None) return result isolated_cad._helper_command = helper isolated_cad._child_environment = environment try: with PrivateDesktopObserver(output): with isolated_cad.IsolatedCadSession(root) as session: assert session.binding is not None and session.cad.poll() is None record = json.loads((root / 'private-desktop.json').read_text(encoding='utf-8')) observation = json.loads((output / 'desktop-observation.json').read_text(encoding='utf-8')) assert record['state'] == 'released' and record['clean'] assert [row['action'] for row in commands] == ['probe', 'quit'] assert observation['sessions'] and all(observation['cad_exit_confirmed'].values()) assert all(observation['desktop_absent'].values()) and not observation['observer_errors'] assert not observation['owned_cad_became_foreground'] and not observation['owned_cad_on_input_desktop'] assert observation['input_desktop_before'] == observation['input_desktop_after'] report = {'passed': True, 'commands': commands, 'session': record, 'source_path_removed_from_child': True, 'project_opened': False} (output / 'report.json').write_text(json.dumps(report, ensure_ascii=False, indent=2), encoding='utf-8') print(json.dumps(report, ensure_ascii=False), flush=True) finally: isolated_cad._helper_command = original_command isolated_cad._child_environment = original_environment if __name__ == '__main__': main()