"""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 ", "One & two\nthree", folder="Adolfo", runner=_success_runner( {"title": "Test <title>", "body": "One & two\nthree", "folder": "Adolfo"}, {"id": "new-1", "title": "Test <title>", "folder": "Adolfo"}, ), ) assert created["id"] == "new-1" def test_update_and_delete_notes_use_fixed_jxa_and_json_arguments(): updated = update_note( "x-coredata://note-1", title="Updated", body="New body", runner=_success_runner( {"id": "x-coredata://note-1", "title": "Updated", "body": "New body"}, {"id": "x-coredata://note-1", "title": "Updated"}, ), ) assert updated["title"] == "Updated" deleted = delete_note( "x-coredata://note-1", runner=_success_runner({"id": "x-coredata://note-1"}, {"id": "x-coredata://note-1", "deleted": True}), ) assert deleted["deleted"] is True def test_notes_cli_is_available_at_top_level_and_macmini_alias(monkeypatch): monkeypatch.setattr("reyna_cli.cli.list_notes", lambda **_: [{"id": "n1", "title": "Test"}]) top_level = runner.invoke(app, ["notes", "list", "--json"]) assert top_level.exit_code == 0 assert json.loads(top_level.stdout)["notes"][0]["id"] == "n1" compatibility_alias = runner.invoke(app, ["macmini", "notes", "list", "--json"]) assert compatibility_alias.exit_code == 0 assert json.loads(compatibility_alias.stdout)["notes"][0]["title"] == "Test"