43 lines
1.1 KiB
Python
43 lines
1.1 KiB
Python
"""Tests for `raycast_api.discovery.bundle`."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
from raycast_api.discovery.bundle import (
|
|
bundle_hash,
|
|
find_index_mjs,
|
|
locate_node_bundle,
|
|
read_bundle_source,
|
|
)
|
|
from raycast_api.errors import DiscoveryError
|
|
|
|
|
|
def test_locate_node_bundle(mock_app: Path) -> None:
|
|
bundle = locate_node_bundle(mock_app)
|
|
assert bundle.name == "test_RaycastDesktopApp.bundle"
|
|
|
|
|
|
def test_locate_node_bundle_missing(tmp_path: Path) -> None:
|
|
app = tmp_path / "Empty.app"
|
|
(app / "Contents" / "Resources").mkdir(parents=True)
|
|
with pytest.raises(DiscoveryError, match="No RaycastDesktopApp bundle"):
|
|
locate_node_bundle(app)
|
|
|
|
|
|
def test_find_index_mjs(mock_app: Path) -> None:
|
|
p = find_index_mjs(mock_app)
|
|
assert p.name == "index.mjs"
|
|
assert "SignReq" in read_bundle_source(p)
|
|
|
|
|
|
def test_bundle_hash_stable(mock_app: Path, tmp_path: Path) -> None:
|
|
a = bundle_hash(find_index_mjs(mock_app))
|
|
b = bundle_hash(find_index_mjs(mock_app))
|
|
assert a == b
|
|
other = tmp_path / "other.mjs"
|
|
other.write_text("different content")
|
|
assert bundle_hash(other) != a
|