Skip to content

Add macOS CI and initial tests #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: macOS Tests

on:
push:
branches: [main]
pull_request:

jobs:
test:
runs-on: macos-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements-dev.txt
pip install .
- name: Lint
run: |
ruff check .
black --check .
- name: Test
run: pytest -q
4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ package-mode = true
include = ["src/nodetool/package_metadata/nodetool-apple.json"]
repository = "https://github.com/nodetool-ai/nodetool-apple"

[tool.ruff]
[tool.ruff.lint]
extend-ignore = ["F401", "F841"]

[tool.poetry.dependencies]
python = "^3.11"
nodetool-core = { git = "https://github.com/nodetool-ai/nodetool-core.git", rev = "main" }
Expand Down
4 changes: 3 additions & 1 deletion src/nodetool/nodes/apple/dictionary.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ def is_cacheable(cls) -> bool:

async def process(self, context: ProcessingContext) -> list[str]:
if not IS_MACOS:
raise NotImplementedError("Dictionary functionality is only available on macOS")
raise NotImplementedError(
"Dictionary functionality is only available on macOS"
)
if not self.term:
return []

Expand Down
4 changes: 3 additions & 1 deletion src/nodetool/nodes/apple/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ def is_cacheable(cls) -> bool:

async def process(self, context: ProcessingContext):
if not IS_MACOS:
raise NotImplementedError("Messages functionality is only available on macOS")
raise NotImplementedError(
"Messages functionality is only available on macOS"
)
text_content = escape_for_applescript(self.text)
recipient = escape_for_applescript(self.recipient)

Expand Down
8 changes: 7 additions & 1 deletion src/nodetool/nodes/apple/notes.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

export_notes_script = Path(__file__).parent / "exportnotes.applescript"


def escape_for_applescript(text: str) -> str:
"""Escape special characters for AppleScript strings."""
# First escape backslashes, then quotes
Expand All @@ -33,6 +34,7 @@ class CreateNote(BaseNode):
- Create documentation or records
- Save workflow outputs as notes
"""

title: str = Field(default="", description="Title of the note")
body: str = Field(default="", description="Content of the note")
folder: str = Field(default="Notes", description="Notes folder to save to")
Expand Down Expand Up @@ -68,10 +70,14 @@ async def process(self, context: ProcessingContext):
except subprocess.CalledProcessError as e:
raise Exception(f"Failed to create note: {e.stderr}")


class ReadNotes(BaseNode):
"""Read notes from Apple Notes via AppleScript"""

note_limit: int = Field(default=10, description="Maximum number of notes to export")
note_limit_per_folder: int = Field(default=10, description="Maximum notes per folder")
note_limit_per_folder: int = Field(
default=10, description="Maximum notes per folder"
)

@classmethod
def is_cacheable(cls) -> bool:
Expand Down
4 changes: 3 additions & 1 deletion src/nodetool/nodes/apple/screen.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ class CaptureScreen(BaseNode):

async def process(self, context: ProcessingContext) -> ImageRef:
if not IS_MACOS:
raise NotImplementedError("Screen capture functionality is only available on macOS")
raise NotImplementedError(
"Screen capture functionality is only available on macOS"
)
main_display = Quartz.CGMainDisplayID() # type: ignore

# If region is specified, capture that region, otherwise capture full screen
Expand Down
12 changes: 12 additions & 0 deletions tests/test_escape_for_applescript.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from nodetool.nodes.apple.notes import escape_for_applescript


def test_escape_quotes_and_backslashes():
text = 'Hello "World" \\ Test'
expected = 'Hello \\"World\\" \\\\ Test'
assert escape_for_applescript(text) == expected


def test_escape_newlines():
text = "line1\nline2"
assert escape_for_applescript(text) == "line1\\nline2"
17 changes: 17 additions & 0 deletions tests/test_nodes_cacheable.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import pytest
from nodetool.nodes.apple import calendar, notes, messages, speech, dictionary

CASES = [
(calendar.CreateCalendarEvent, False),
(calendar.ListCalendarEvents, False),
(notes.CreateNote, False),
(notes.ReadNotes, False),
(messages.SendMessage, False),
(speech.SayText, False),
(dictionary.SearchDictionary, True),
]


@pytest.mark.parametrize("node_cls,expected", CASES)
def test_node_is_cacheable(node_cls, expected):
assert node_cls.is_cacheable() is expected