"""Regression tests for direct mutable Apple Notes CLI support. Notes are deliberately implemented in Python through a fixed JXA script, not in the stable Swift privacy host. That preserves the signed launcher binary. """ from __future__ import annotations import json from types import SimpleNamespace from typer.testing import CliRunner from reyna_cli.cli import app from reyna_cli.notes_direct import create_note, delete_note, list_notes, read_note, update_note runner = CliRunner() def _success_runner(expected_payload, result): def run(argv, **kwargs): assert argv[:5] == ["/usr/bin/osascript", "-l", "JavaScript", "-e", argv[4]] assert argv[5] == "--" assert json.loads(argv[6]) == expected_payload return SimpleNamespace(returncode=0, stdout=json.dumps(result), stderr="") return run def test_list_notes_uses_fixed_jxa_and_json_argument(): notes = list_notes( query="family", folder="Adolfo", include_preview=True, limit=7, runner=_success_runner( {"query": "family", "folder": "Adolfo", "includePreview": True, "limit": 7}, [{"id": "n1", "title": "Family", "folder": "Adolfo"}], ), ) assert notes == [{"id": "n1", "title": "Family", "folder": "Adolfo"}] def test_read_and_create_notes_use_json_arguments_without_script_interpolation(): note = read_note( "x-coredata://note-1", runner=_success_runner( {"id": "x-coredata://note-1"}, {"id": "x-coredata://note-1", "title": "Existing", "plaintext": "body"}, ), ) assert note["title"] == "Existing" created = create_note( "Test