Skip to content

Commit 8c7bf44

Browse files
fix(install): verify Finder extension registration after launch
1 parent 6adf267 commit 8c7bf44

3 files changed

Lines changed: 45 additions & 10 deletions

File tree

‎scripts/install_debug.py‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -204,17 +204,18 @@ def installed_finder_registration():
204204

205205
def launch_installed(previous_finder_pids, previous_election):
206206
run(LSREGISTER, "-f", APP)
207+
# Launch Services may discover the embedded extension only at first launch.
208+
run("/usr/bin/open", "-a", APP)
209+
if not wait_for(lambda: process_ids(APP / "Contents/MacOS/FileMint"), 15):
210+
raise InstallError(f"Launch did not produce a running FileMint at {APP}")
211+
print(f"Running FileMint at {APP}", flush=True)
212+
207213
registration = wait_for(installed_finder_registration, 10)
208214
if not registration:
209215
registered = ", ".join(str(path) for path, _ in finder_registrations()) or "none"
210216
raise InstallError(f"Expected one Finder extension at the installed path. Registrations: {registered}")
211217
extension_path, election = registration[0]
212218
print(f"Finder extension registered at {extension_path}", flush=True)
213-
214-
run("/usr/bin/open", "-a", APP)
215-
if not wait_for(lambda: process_ids(APP / "Contents/MacOS/FileMint"), 15):
216-
raise InstallError(f"Launch did not produce a running FileMint at {APP}")
217-
print(f"Running FileMint at {APP}", flush=True)
218219
if previous_election in ("+", "-") and previous_election != election:
219220
print("Finder extension election changed. Check the system's Finder Extensions setting.", file=sys.stderr)
220221
if election == "+":

‎scripts/test_install_debug.py‎

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#!/usr/bin/env python3
2-
"""Exercise Debug bundle replacement with real directories on the same volume."""
2+
"""Exercise Debug bundle replacement and launch verification."""
3+
from contextlib import redirect_stdout
4+
from io import StringIO
35
from pathlib import Path
46
import tempfile
57
import unittest
@@ -58,6 +60,37 @@ def test_concurrent_first_install_is_preserved(self):
5860
self.assertTrue((self.destination / "old").is_file())
5961
self.assertTrue((self.staged / "new").is_file())
6062

63+
def test_finder_extension_may_be_discovered_only_after_launch(self):
64+
app = installer.APP
65+
finder = app / installer.FINDER
66+
commands = []
67+
68+
def run(*args):
69+
commands.append(args)
70+
71+
def registrations():
72+
self.assertIn(("/usr/bin/open", "-a", app), commands)
73+
return [(finder, "+")]
74+
75+
with patch.object(installer, "run", side_effect=run), \
76+
patch.object(installer, "process_ids", side_effect=[{100}, {200}]), \
77+
patch.object(installer, "finder_registrations", side_effect=registrations), \
78+
redirect_stdout(StringIO()) as status:
79+
installer.launch_installed(set(), "+")
80+
81+
self.assertEqual(commands, [(installer.LSREGISTER, "-f", app), ("/usr/bin/open", "-a", app)])
82+
self.assertIn(f"Finder extension registered at {finder}", status.getvalue())
83+
self.assertIn("Finder extension process reloaded.", status.getvalue())
84+
85+
def test_launch_does_not_accept_another_finder_registration(self):
86+
finder = installer.APP / installer.FINDER
87+
other = self.destination / installer.FINDER
88+
with patch.object(installer, "run"), patch.object(installer, "process_ids", return_value={100}), \
89+
patch.object(installer, "wait_for", side_effect=lambda check, _: check()), \
90+
patch.object(installer, "finder_registrations", return_value=[(finder, "+"), (other, "=")]), \
91+
redirect_stdout(StringIO()), self.assertRaisesRegex(installer.InstallError, "Expected one Finder extension"):
92+
installer.launch_installed(set(), "+")
93+
6194

6295
if __name__ == "__main__":
6396
unittest.main()

‎specs/domains/distribution.md‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,11 @@ Part of the [FileMint SPEC](../SPEC.md). This file owns the behavior below; othe
2929
wrapper name before replacement.
3030
Respect normal FileMint termination and leave the previous app installed if
3131
it declines to quit. Replace the bundle atomically and restore the prior
32-
bundle if installed signature verification fails before launch. Use only the
33-
installed path for launch, clean up the current run's temporary registrations,
34-
and verify the resulting Finder registration. Finder enablement remains under
35-
macOS user control. This workflow is local to the development Mac.
32+
bundle if installed signature verification fails before launch. Clean up the
33+
current run's temporary registrations, open only the installed app, then
34+
verify the resulting Finder registration. Launch can trigger discovery of the
35+
embedded extension. Finder enablement remains under macOS user control.
36+
This workflow is local to the development Mac.
3637

3738
## Distribution
3839

0 commit comments

Comments
 (0)