Skip to content

Dodaios is an open-source agent OS for your desktop: it runs your coding agents, browser and apps by voice or chat, on your own machine. Formerly Personal Jarvis.

fix(macos): judge Spotlight health by behaviour, not the data volume's mdutil state

Harald Herz9166cc08064c
diff --git a/docs/BUGS.md b/docs/BUGS.md
index 154d35e133..f9ad49456a 100644
--- a/docs/BUGS.md
+++ b/docs/BUGS.md
@@ -15243,31 +15243,40 @@ nothing.
The bundle is built in a hidden `.jarvis-native-*` directory and renamed into
place, and nothing ever asked Spotlight to import it. The docstring claiming
"announce to LaunchServices so Spotlight can find it" was simply wrong.
-2. *Machine.* On the reporting Mac the Data volume's Spotlight store itself was
- broken: `mdutil -s /System/Volumes/Data` answered "Error: unknown indexing
- state", and `mdfind` returned no item changed in the preceding four days.
- Freshly created test apps and plain text files in `~/Applications`,
- `~/Downloads` and `~/Desktop` stayed unindexed for minutes, with and without
- `mdimport`. On such a volume nothing new becomes searchable, whichever app
- wrote it, and only an administrator can re-enable the store.
+2. *Machine.* On the reporting Mac (macOS 15.7) the Spotlight index had
+ stalled: `mdutil -s /` said "Indexing enabled", yet `mdfind` returned no
+ item changed in the preceding four days. Every app installed or updated
+ since 2026-09-12 (Excel, PowerPoint, Claude, Personal Jarvis) was missing
+ from search while older apps were found, and freshly created files stayed
+ unindexed even after `mdimport`. No app can repair that; the index has to
+ be rebuilt with `sudo mdutil -E /`.
**Fix.** `jarvis/setup/macos_search_index.py`: every install/repair path already
calls `register_with_launch_services`, which now also runs `mdimport` on the
-bundle and checks the volume with `df -P` + `mdutil -s <mount point>`. A
-disabled or broken store logs a WARNING carrying the exact repair command
-(`sudo mdutil -i on <vol> && sudo mdutil -E <vol>`). `python -m jarvis --doctor`
-gained `macos-spotlight`: store broken → warn + repair command; bundle not in
-the index → warn + `mdimport`; indexed → ok. `mdutil -s` must be given the mount
-point — handed the bundle path it echoes that path back as the "volume", which
-the live probe caught before it shipped.
+bundle and checks the indexing switch of the volume holding it (`df -P`, then
+`mdutil -s`). Indexing switched off logs a WARNING with the exact repair
+command. `python -m jarvis --doctor` gained `macos-spotlight`: indexing off →
+warn + `mdutil -i on`; import requested and the bundle still not listed after
+20 s → warn "index looks stalled" + `sudo mdutil -E /`; indexed → ok.
+
+Two traps found live on the way, both pinned by tests:
+- `mdutil -s <folder>` echoes the folder back as the "volume", so it must be
+ given a mount point.
+- `/System/Volumes/Data` answers "unknown indexing state" and refuses
+ `mdutil -i` with error -405 on a HEALTHY Mac: the APFS system volume group is
+ indexed and administered through `/`. The first version of the check read
+ that answer as a broken store and would have warned on every Mac; it now
+ asks `/` and judges a stall only by an import that never appears.
**Class rule.** "Registered" is not "searchable": verify against the index the
-user's search box actually reads, and when the OS index itself is broken say so
-with the command that fixes it instead of claiming the app is findable.
-
-**Guards.** `tests/unit/setup/test_macos_search_index.py` (verbatim broken-store
-`mdutil` output, mount-point resolution, import on registration, a Spotlight
-crash never blocks `lsregister`), `tests/unit/diagnostics/test_doctor_diagnostics.py`
+user's search box actually reads, judge the OS index only on behaviour macOS
+shows, and when that index is broken say so with the command that fixes it
+instead of claiming the app is findable.
+
+**Guards.** `tests/unit/setup/test_macos_search_index.py` (verbatim data-volume
+`mdutil` output never counts as a defect, control-volume and mount-point
+resolution, stalled-index wait, import on registration, a Spotlight crash never
+blocks `lsregister`), `tests/unit/diagnostics/test_doctor_diagnostics.py`
(`check_macos_spotlight`).
## BUG-217: macOS asked for every permission again after each rebuild, and the Music prompt never stuck (HIGH, FIXED 2026-09-16)
diff --git a/docs/os-parity.md b/docs/os-parity.md
index be4382b7d5..9260127a20 100644
--- a/docs/os-parity.md
+++ b/docs/os-parity.md
@@ -317,9 +317,10 @@ succeeded while its announcement did not.
**Fix pass 2026-09-16 (macOS: registered is not searchable, BUG-216).**
LaunchServices and Spotlight are separate indexes; `lsregister` alone left the
bundle out of Spotlight search. macOS now also imports the bundle with
-`mdimport` and checks the volume's Spotlight store (`mdutil -s` on the mount
-point), logging the admin repair command when the store is disabled or broken;
-`--doctor` reports the same as `macos-spotlight`. Windows and Linux are
+`mdimport` and checks the indexing switch of the volume that controls it (`/`
+for the APFS data volume), logging the admin repair command when indexing is
+off; `--doctor` (`macos-spotlight`) additionally detects a stalled index by an
+import that never appears. Windows and Linux are
unchanged — their index announcements already feed the search the user types
into.
diff --git a/jarvis/diagnostics/doctor.py b/jarvis/diagnostics/doctor.py
index aa90096f9c..8599ed154b 100644
--- a/jarvis/diagnostics/doctor.py
+++ b/jarvis/diagnostics/doctor.py
@@ -301,16 +301,20 @@ def check_macos_spotlight() -> list[DoctorFinding]:
"""Whether Spotlight can actually find the installed macOS app.
LaunchServices registration does not put an app into Spotlight's search
- (2026-09-16 report): the search field answers from the per-volume metadata
- store, which can be broken machine-wide. Report the store state and whether
- the bundle is really indexed, with the command that fixes each.
+ (BUG-216): the search field answers from the metadata store, which can be
+ switched off or stalled machine-wide. Judged only on what macOS shows — the
+ volume's indexing switch, and whether a requested import ever appears.
"""
import sys as _sys
if _sys.platform != "darwin":
return []
from jarvis.setup.macos_app_bundle import macos_app_bundle_path
- from jarvis.setup.macos_search_index import indexed_bundle_paths, spotlight_volume_issue
+ from jarvis.setup.macos_search_index import (
+ STALLED_INDEX_REPAIR_COMMAND,
+ spotlight_volume_issue,
+ wait_until_indexed,
+ )
bundle = macos_app_bundle_path()
if not bundle.exists():
@@ -319,11 +323,10 @@ def check_macos_spotlight() -> list[DoctorFinding]:
if issue is not None:
return [DoctorFinding(
"macos-spotlight", "warn",
- f"Spotlight cannot index {bundle.name}: {issue.reason} on {issue.volume} "
- "— no new file on this volume becomes searchable",
+ f"Spotlight cannot find {bundle.name}: {issue.reason} on {issue.volume}",
hint=f"{issue.repair_command} (admin password; reindexing takes a while)",
)]
- indexed = indexed_bundle_paths()
+ indexed = wait_until_indexed(bundle)
if indexed is None:
return [DoctorFinding(
"macos-spotlight", "info", "Spotlight could not be queried for the app bundle",
@@ -331,12 +334,13 @@ def check_macos_spotlight() -> list[DoctorFinding]:
if not indexed:
return [DoctorFinding(
"macos-spotlight", "warn",
- f"{bundle.name} is installed but not in the Spotlight index",
- hint=f'mdimport "{bundle}"',
+ f"{bundle.name} is installed, but Spotlight did not index it after an "
+ "import request — the Spotlight index looks stalled, so other newly "
+ "installed apps are missing from search too",
+ hint=f"{STALLED_INDEX_REPAIR_COMMAND} (admin password; rebuilds the whole "
+ "index, which can take hours)",
)]
- return [DoctorFinding(
- "macos-spotlight", "ok", f"Spotlight finds {bundle.name} ({indexed[0]})",
- )]
+ return [DoctorFinding("macos-spotlight", "ok", f"Spotlight finds {bundle.name}")]
def run_doctor(config: Any) -> list[DoctorFinding]:
diff --git a/jarvis/setup/macos_search_index.py b/jarvis/setup/macos_search_index.py
index ab2cf91346..a580f1bb6f 100644
--- a/jarvis/setup/macos_search_index.py
+++ b/jarvis/setup/macos_search_index.py
@@ -8,10 +8,17 @@ The bundle is built in a hidden ``.jarvis-native-*`` directory and renamed
into ``~/Applications``, and that import is left to the FSEvents stream; this
module asks for it explicitly with ``mdimport``.
-It also names the case no app can repair: a volume whose Spotlight store is
-disabled or broken (``mdutil -s`` answers "unknown indexing state") indexes
-nothing new at all, so the only honest result is the exact admin command that
-re-enables the store. Every probe is bounded, macOS-only and never raises.
+It also names the cases no app can repair, each only on evidence macOS gives:
+indexing switched off for the volume (``mdutil -s``), or a stalled index that
+accepts an import request and still never lists the bundle
+(``wait_until_indexed``). Both come with the exact admin command. Every probe
+is bounded, macOS-only and never raises.
+
+``mdutil`` is asked about the volume that CONTROLS indexing. Since macOS 10.15
+the user data lives on ``/System/Volumes/Data``, firmlinked under ``/``; that
+volume answers ``mdutil -s`` with "unknown indexing state" and refuses
+``mdutil -i`` with error -405 even on a healthy Mac, because the system volume
+group is indexed and administered through ``/``.
"""
from __future__ import annotations
@@ -19,6 +26,8 @@ from __future__ import annotations
import logging
import subprocess
import sys
+import time
+from collections.abc import Callable
from dataclasses import dataclass
from pathlib import Path
@@ -32,6 +41,8 @@ _MDUTIL = "/usr/bin/mdutil"
_MDFIND = "/usr/bin/mdfind"
_DF = "/bin/df"
_TIMEOUT_S = 30
+# The data half of the APFS system volume group; indexing is controlled at "/".
+_SYSTEM_DATA_VOLUME = "/System/Volumes/Data"
@dataclass(frozen=True)
@@ -46,6 +57,11 @@ class SpotlightVolumeIssue:
return f"sudo mdutil -i on {self.volume} && sudo mdutil -E {self.volume}"
+# A stalled index reports "Indexing enabled" and simply stops absorbing
+# changes; erasing the store makes mds rebuild it from scratch.
+STALLED_INDEX_REPAIR_COMMAND = "sudo mdutil -E /"
+
+
def _run(argv: list[str]) -> subprocess.CompletedProcess[str] | None:
if sys.platform != "darwin" or not Path(argv[0]).is_file():
return None
@@ -101,10 +117,8 @@ def parse_mdutil_status(output: str) -> SpotlightVolumeIssue | None:
return None
if "indexing disabled" in lowered:
return SpotlightVolumeIssue(volume or "/", "Spotlight indexing is turned off")
- if "unknown indexing state" in lowered:
- return SpotlightVolumeIssue(
- volume or "/", "the Spotlight index is not working (unknown indexing state)"
- )
+ # "unknown indexing state" is what a healthy /System/Volumes/Data answers
+ # too, so it proves nothing on its own.
return None
@@ -119,6 +133,11 @@ def parse_df_mount_point(output: str) -> str | None:
return fields[5].strip() if len(fields) == 6 else None
+def indexing_control_volume(mount_point: str) -> str:
+ """The volume whose ``mdutil`` state governs ``mount_point``."""
+ return "/" if mount_point == _SYSTEM_DATA_VOLUME else mount_point
+
+
def _mount_point(path: Path) -> str | None:
result = _run([_DF, "-P", str(path)])
if result is None or result.returncode != 0:
@@ -129,12 +148,13 @@ def _mount_point(path: Path) -> str | None:
def spotlight_volume_issue(path: Path) -> SpotlightVolumeIssue | None:
"""Whether the volume holding ``path`` can index new items at all.
- ``mdutil -s`` must be given the mount point: handed any other path it
- echoes that path back, and the repair command would then name a folder.
+ ``mdutil -s`` must be given a mount point: handed any other path it echoes
+ that path back, and the repair command would then name a folder.
"""
- volume = _mount_point(path)
- if volume is None:
+ mount = _mount_point(path)
+ if mount is None:
return None
+ volume = indexing_control_volume(mount)
result = _run([_MDUTIL, "-s", volume])
if result is None:
return None
@@ -156,6 +176,34 @@ def indexed_bundle_paths(bundle_id: str = MACOS_BUNDLE_ID) -> list[Path] | None:
]
+def wait_until_indexed(
+ bundle: Path,
+ *,
+ timeout_s: float = 20.0,
+ poll_s: float = 2.0,
+ sleep: Callable[[float], None] = time.sleep,
+ clock: Callable[[], float] = time.monotonic,
+) -> bool | None:
+ """Request an import of ``bundle`` and wait for Spotlight to list it.
+
+ ``True`` once it is indexed, ``False`` when Spotlight accepted the request
+ and still did not list the bundle in time — the observable shape of a
+ stalled index — and ``None`` when Spotlight could not be asked at all.
+ """
+ if not request_spotlight_import(bundle):
+ return None
+ deadline = clock() + timeout_s
+ while True:
+ indexed = indexed_bundle_paths()
+ if indexed is None:
+ return None
+ if bundle in indexed:
+ return True
+ if clock() >= deadline:
+ return False
+ sleep(poll_s)
+
+
def announce_to_spotlight(bundle: Path) -> bool:
"""Import ``bundle`` into Spotlight and warn when its volume cannot index.
@@ -176,11 +224,14 @@ def announce_to_spotlight(bundle: Path) -> bool:
__all__ = [
+ "STALLED_INDEX_REPAIR_COMMAND",
"SpotlightVolumeIssue",
"announce_to_spotlight",
"indexed_bundle_paths",
+ "indexing_control_volume",
"parse_df_mount_point",
"parse_mdutil_status",
"request_spotlight_import",
"spotlight_volume_issue",
+ "wait_until_indexed",
]
diff --git a/tests/unit/diagnostics/test_doctor_diagnostics.py b/tests/unit/diagnostics/test_doctor_diagnostics.py
index 588e0ba00d..9a7ab66784 100644
--- a/tests/unit/diagnostics/test_doctor_diagnostics.py
+++ b/tests/unit/diagnostics/test_doctor_diagnostics.py
@@ -10,6 +10,8 @@ from __future__ import annotations
from types import SimpleNamespace
+import pytest
+
from jarvis.diagnostics import doctor
from jarvis.diagnostics.doctor import (
check_brain_provider,
@@ -20,6 +22,15 @@ from jarvis.diagnostics.doctor import (
)
[email protected](autouse=True)
+def _no_live_spotlight(monkeypatch) -> None:
+ """The Spotlight check waits on the host's real index; unit tests never do."""
+ from jarvis.setup import macos_search_index
+
+ monkeypatch.setattr(macos_search_index, "spotlight_volume_issue", lambda _p: None)
+ monkeypatch.setattr(macos_search_index, "wait_until_indexed", lambda _b: True)
+
+
def test_router_tools_ok_with_real_registry() -> None:
"""The shipped ROUTER_TOOLS set must have NO phantom — every name resolves.
@@ -218,38 +229,44 @@ def _spotlight_env(monkeypatch, tmp_path, *, issue=None, indexed=None):
monkeypatch.setattr(sys, "platform", "darwin")
monkeypatch.setattr(macos_app_bundle, "macos_app_bundle_path", lambda **_kw: bundle)
monkeypatch.setattr(macos_search_index, "spotlight_volume_issue", lambda _p: issue)
- monkeypatch.setattr(macos_search_index, "indexed_bundle_paths", lambda *_a: indexed)
+ monkeypatch.setattr(macos_search_index, "wait_until_indexed", lambda _b: indexed)
return bundle
-def test_spotlight_check_names_the_broken_store_and_its_repair(monkeypatch, tmp_path) -> None:
+def test_spotlight_check_names_switched_off_indexing_and_its_repair(monkeypatch, tmp_path) -> None:
from jarvis.setup.macos_search_index import SpotlightVolumeIssue
_spotlight_env(
monkeypatch,
tmp_path,
- issue=SpotlightVolumeIssue("/System/Volumes/Data", "the Spotlight index is not working"),
+ issue=SpotlightVolumeIssue("/", "Spotlight indexing is turned off"),
)
[finding] = doctor.check_macos_spotlight()
assert finding.status == "warn"
- assert "/System/Volumes/Data" in finding.message
- assert finding.hint is not None and "sudo mdutil -i on /System/Volumes/Data" in finding.hint
+ assert finding.hint is not None and finding.hint.startswith("sudo mdutil -i on / &&")
-def test_spotlight_check_flags_an_unindexed_bundle(monkeypatch, tmp_path) -> None:
- bundle = _spotlight_env(monkeypatch, tmp_path, indexed=[])
+def test_spotlight_check_flags_a_stalled_index(monkeypatch, tmp_path) -> None:
+ _spotlight_env(monkeypatch, tmp_path, indexed=False)
[finding] = doctor.check_macos_spotlight()
assert finding.status == "warn"
- assert finding.hint == f'mdimport "{bundle}"'
+ assert "stalled" in finding.message
+ assert finding.hint is not None and finding.hint.startswith("sudo mdutil -E /")
def test_spotlight_check_ok_when_indexed(monkeypatch, tmp_path) -> None:
- bundle = _spotlight_env(monkeypatch, tmp_path, indexed=[tmp_path / "Personal Jarvis.app"])
+ bundle = _spotlight_env(monkeypatch, tmp_path, indexed=True)
[finding] = doctor.check_macos_spotlight()
assert finding.status == "ok"
assert bundle.name in finding.message
+def test_spotlight_check_is_neutral_when_spotlight_cannot_be_asked(monkeypatch, tmp_path) -> None:
+ _spotlight_env(monkeypatch, tmp_path, indexed=None)
+ [finding] = doctor.check_macos_spotlight()
+ assert finding.status == "info"
+
+
def test_spotlight_check_is_silent_off_macos(monkeypatch) -> None:
import sys
diff --git a/tests/unit/setup/test_macos_search_index.py b/tests/unit/setup/test_macos_search_index.py
index 7e229ec4db..2ec68f5fdf 100644
--- a/tests/unit/setup/test_macos_search_index.py
+++ b/tests/unit/setup/test_macos_search_index.py
@@ -3,8 +3,9 @@
The 2026-09-16 report: ``~/Applications/Personal Jarvis.app`` was registered
with LaunchServices (``lsregister -dump`` listed it) yet Spotlight returned
nothing. Spotlight answers from its own per-volume metadata store; these tests
-pin that the bundle is imported there and that a volume whose store is broken
-is named with the admin repair command instead of passing silently.
+pin that the bundle is imported there, that a switched-off or stalled index is
+named with the admin repair command, and that the normal "unknown indexing
+state" of macOS's data volume is never mistaken for a defect.
"""
from __future__ import annotations
@@ -21,20 +22,27 @@ from jarvis.setup.macos_search_index import (
SpotlightVolumeIssue,
announce_to_spotlight,
indexed_bundle_paths,
+ indexing_control_volume,
parse_df_mount_point,
parse_mdutil_status,
request_spotlight_import,
spotlight_volume_issue,
+ wait_until_indexed,
)
-# Verbatim ``mdutil -s /System/Volumes/Data`` output from the affected Mac.
-_BROKEN_DATA_VOLUME = "/System/Volumes/Data:\n\tError: unknown indexing state.\n"
-_HEALTHY = "/System/Volumes/Data:\n\tIndexing enabled. \n"
+# Verbatim ``mdutil -s /System/Volumes/Data`` output. macOS answers this for
+# the data volume on healthy Macs too; indexing is administered through "/".
+_DATA_VOLUME_UNKNOWN = "/System/Volumes/Data:\n\tError: unknown indexing state.\n"
+_HEALTHY = "/:\n\tIndexing enabled. \n"
_DISABLED = "/Volumes/External:\n\tIndexing disabled.\n"
_DF_DATA = (
"Filesystem 512-blocks Used Available Capacity Mounted on\n"
"/dev/disk3s5 478724992 373871528 31615632 93% /System/Volumes/Data\n"
)
+_DF_EXTERNAL = (
+ "Filesystem 512-blocks Used Available Capacity Mounted on\n"
+ "/dev/disk5s1 100 50 50 50% /Volumes/External\n"
+)
class _Result:
@@ -60,26 +68,19 @@ def fake_tools(monkeypatch: pytest.MonkeyPatch):
return calls, replies
-def test_broken_store_is_recognized_with_its_volume() -> None:
- issue = parse_mdutil_status(_BROKEN_DATA_VOLUME)
+def test_disabled_indexing_is_recognized_with_its_repair() -> None:
+ issue = parse_mdutil_status(_DISABLED)
- assert issue == SpotlightVolumeIssue(
- "/System/Volumes/Data", "the Spotlight index is not working (unknown indexing state)"
- )
+ assert issue == SpotlightVolumeIssue("/Volumes/External", "Spotlight indexing is turned off")
assert issue.repair_command == (
- "sudo mdutil -i on /System/Volumes/Data && sudo mdutil -E /System/Volumes/Data"
+ "sudo mdutil -i on /Volumes/External && sudo mdutil -E /Volumes/External"
)
-def test_disabled_indexing_is_recognized() -> None:
- issue = parse_mdutil_status(_DISABLED)
-
- assert issue is not None
- assert issue.volume == "/Volumes/External"
- assert "turned off" in issue.reason
-
-
[email protected]("output", [_HEALTHY, "", "something macOS may print one day\n"])
+ "output",
+ [_HEALTHY, _DATA_VOLUME_UNKNOWN, "", "something macOS may print one day\n"],
+)
def test_only_a_reported_failure_counts_as_an_issue(output: str) -> None:
"""A warning must rest on a state macOS reported, never on a guess."""
assert parse_mdutil_status(output) is None
@@ -125,32 +126,97 @@ def test_a_missing_tool_never_raises(monkeypatch: pytest.MonkeyPatch) -> None:
assert spotlight_volume_issue(Path("/a")) is None
-def test_announce_warns_with_the_repair_command_on_a_broken_store(
+def test_announce_warns_with_the_repair_command_when_indexing_is_off(
fake_tools, caplog: pytest.LogCaptureFixture
) -> None:
calls, replies = fake_tools
- replies["df"] = _Result(stdout=_DF_DATA)
- replies["mdutil"] = _Result(stdout=_BROKEN_DATA_VOLUME)
- bundle = Path("/Users/u/Applications/Personal Jarvis.app")
+ replies["df"] = _Result(stdout=_DF_EXTERNAL)
+ replies["mdutil"] = _Result(stdout=_DISABLED)
+ bundle = Path("/Volumes/External/Applications/Personal Jarvis.app")
with caplog.at_level(logging.WARNING, logger=macos_search_index.__name__):
assert announce_to_spotlight(bundle) is True
assert [Path(argv[0]).name for argv in calls] == ["mdimport", "df", "mdutil"]
- assert "sudo mdutil -i on /System/Volumes/Data &&" in caplog.text
+ assert "sudo mdutil -i on /Volumes/External &&" in caplog.text
-def test_mdutil_is_asked_about_the_mount_point_not_the_bundle(fake_tools) -> None:
- """Handed the bundle path, ``mdutil -s`` echoes it back as the "volume"
- (seen live) and the repair command would name the app folder."""
+def test_the_data_volume_is_judged_through_the_root_volume(fake_tools) -> None:
+ """``/System/Volumes/Data`` answers "unknown indexing state" and refuses
+ ``mdutil -i`` (-405) on a healthy Mac; its indexing is controlled at "/".
+ Both were seen live on macOS 15."""
calls, replies = fake_tools
replies["df"] = _Result(stdout=_DF_DATA)
- replies["mdutil"] = _Result(stdout=_BROKEN_DATA_VOLUME)
+ replies["mdutil"] = _Result(stdout=_HEALTHY)
issue = spotlight_volume_issue(Path("/Users/u/Applications/Personal Jarvis.app"))
- assert calls[-1] == ["/usr/bin/mdutil", "-s", "/System/Volumes/Data"]
- assert issue is not None and issue.volume == "/System/Volumes/Data"
+ assert calls[-1] == ["/usr/bin/mdutil", "-s", "/"]
+ assert issue is None
+
+
+ ("mount", "control"),
+ [("/System/Volumes/Data", "/"), ("/", "/"), ("/Volumes/External", "/Volumes/External")],
+)
+def test_indexing_control_volume(mount: str, control: str) -> None:
+ assert indexing_control_volume(mount) == control
+
+
+def test_mdutil_is_never_handed_the_bundle_path(fake_tools) -> None:
+ """Handed a folder, ``mdutil -s`` echoes it back as the "volume" (seen
+ live) and a repair command would name the app folder."""
+ calls, replies = fake_tools
+ replies["df"] = _Result(stdout=_DF_EXTERNAL)
+ replies["mdutil"] = _Result(stdout=_DISABLED)
+
+ issue = spotlight_volume_issue(Path("/Volumes/External/Apps/Personal Jarvis.app"))
+
+ assert calls[-1] == ["/usr/bin/mdutil", "-s", "/Volumes/External"]
+ assert issue is not None and issue.volume == "/Volumes/External"
+
+
+class _Clock:
+ def __init__(self) -> None:
+ self.now = 0.0
+
+ def __call__(self) -> float:
+ return self.now
+
+ def sleep(self, seconds: float) -> None:
+ self.now += seconds
+
+
+def test_wait_reports_an_index_that_catches_up(monkeypatch: pytest.MonkeyPatch) -> None:
+ bundle = Path("/Users/u/Applications/Personal Jarvis.app")
+ answers = iter([[], [], [bundle]])
+ monkeypatch.setattr(macos_search_index, "request_spotlight_import", lambda _b: True)
+ monkeypatch.setattr(macos_search_index, "indexed_bundle_paths", lambda: next(answers))
+ clock = _Clock()
+
+ assert wait_until_indexed(bundle, sleep=clock.sleep, clock=clock) is True
+
+
+def test_wait_reports_a_stalled_index(monkeypatch: pytest.MonkeyPatch) -> None:
+ """The reporting Mac: "Indexing enabled", import accepted, never listed."""
+ bundle = Path("/Users/u/Applications/Personal Jarvis.app")
+ monkeypatch.setattr(macos_search_index, "request_spotlight_import", lambda _b: True)
+ monkeypatch.setattr(macos_search_index, "indexed_bundle_paths", lambda: [])
+ clock = _Clock()
+
+ assert wait_until_indexed(bundle, timeout_s=10, sleep=clock.sleep, clock=clock) is False
+ assert clock.now >= 10
+
+
[email protected](("imported", "listing"), [(False, []), (True, None)])
+def test_wait_is_unknown_when_spotlight_cannot_be_asked(
+ monkeypatch: pytest.MonkeyPatch, imported: bool, listing: list[Path] | None
+) -> None:
+ monkeypatch.setattr(macos_search_index, "request_spotlight_import", lambda _b: imported)
+ monkeypatch.setattr(macos_search_index, "indexed_bundle_paths", lambda: listing)
+ clock = _Clock()
+
+ assert wait_until_indexed(Path("/a.app"), sleep=clock.sleep, clock=clock) is None
def test_an_unknown_mount_point_reports_no_issue(fake_tools) -> None:
@@ -183,7 +249,7 @@ def test_announce_is_quiet_on_a_healthy_volume(
) -> None:
_calls, replies = fake_tools
replies["df"] = _Result(stdout=_DF_DATA)
- replies["mdutil"] = _Result(stdout=_HEALTHY)
+ replies["mdutil"] = _Result(stdout=_DATA_VOLUME_UNKNOWN)
with caplog.at_level(logging.WARNING, logger=macos_search_index.__name__):
announce_to_spotlight(Path("/Users/u/Applications/Personal Jarvis.app"))