Repository navigation
Commit bace781
authored
fix(macos): attach to a running app instead of launching a duplicate on open (#3707)
* fix(macos): attach to a running app instead of launching a duplicate on open
A macOS app started directly — by a supervisor or a dev script — is not
listed by LaunchServices until half a second or so after it spawns. During
that window `open -b` sees no instance and starts a second copy with no
arguments, which the session then drives instead of the copy the caller
owns (#3406).
The bundle open now reads the same view `open -b` consults and, when it
lists nothing while a process of that bundle is running, waits until
LaunchServices names the running copy before running `open` unchanged. An
already-listed bundle and a bundle with nothing running reach `open` on the
first read; the wait, every read, and the process scan share one budget, and
anything the probe cannot answer fails open so an open is never withheld.
* fix(macos): size the registration probe to finish the race it waits out
The probe's 5 s ceiling exceeded the healthy open it precedes by an order
of magnitude while the case it waits out registers within ~0.75 s. The
ceiling now covers the full poll plus the reads ahead of it with measured
room (reads cost well under 300 ms together on a healthy host), so a host
too loaded to answer within the wait is dropped at the remaining-budget
floor instead of holding the open for seconds the race never needs.
The batched bundle-identifier read gains a hermetic invariant against the
real plutil: one -extract answers for every plist it is named, in argument
order, so one call can pair every candidate bundle; the unit fakes cannot
carry that proof because they script the rows.
* test(macos): pin the real-plutil batch to the target's own pid
The registration stub answered any pid-pinned read, so a batch that paired
an identifier with the wrong bundle's process could still end the wait
green. Only pid 4242's query now reports an ASN and the test asserts the
exact read transcript, so a rotation of the row-to-path pairing (verified
by a disposable mutation: 3 failed, 17 passed) fails this test on the
target's pid rather than passing on another bundle's.
* test(macos): point the probe routing comment at its owning test
The final review caught that the comment in the routing test named
host-provider-open.test.ts, which does not exist. The probe assertions
live in launch-services-registration.test.ts, the file the comment
should route a reader to.
* fix(macos): read the process table through the provider's own executor
The probe ran lsappinfo, plutil and the open through the injected Apple
tool executor but read ps on the daemon's own host through the host-kit
default. A scoped Apple provider could then pair pids found on one host
with its lsappinfo and plutil on another. listHostProcesses({runCommand,
timeoutMs}) routes the scan through the same seam and deadline the other
reads already share, so the probe answers about one host end to end. The
owning tests now script ps through fakeMacHost instead of mocking the
process module.
* test(macos): let the fake host answer the process-table read like any read
fakeMacHost recorded the ps call and returned the table before consulting
the responder, so the scan could not be made to throw, fail, or time out
even though the probe now runs it through the same executor seam the
Error-answering stub exists for. The responder is consulted first and the
table is only the default answer. Three owning scenarios pin what the
probe does when the scan itself fails: a tool that cannot spawn and a
read killed at its budget end the probe with a typed diagnostic and the
original open, and a non-zero ps exit is the unreadable table the empty
answer already was — never 'nothing runs'.1 parent 5b97e14 commit bace781
6 files changed
Lines changed: 1006 additions & 0 deletions
File tree
- packages/platform-apple/src
- core/__tests__
- os/macos
- website/docs/docs
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
8 | 9 | | |
9 | 10 | | |
10 | 11 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
177 | 177 | | |
178 | 178 | | |
179 | 179 | | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
180 | 185 | | |
181 | 186 | | |
182 | 187 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
21 | 27 | | |
22 | 28 | | |
23 | 29 | | |
| |||
0 commit comments