refactor(daemon): move the device selection cluster into @agent-device/device-selection - #2396
Conversation
…package git-rename src/core/dispatch-resolve.ts, src/core/device-selection-resolver.ts and src/request/device-inventory-context.ts (plus their tests and fixtures) into a new private package @agent-device/device-selection (deps: contracts, host-kit, kernel). One subpath per module points straight at the moved file; no index.ts, no re-export at the old path. Consumers switch to the owning specifier in the follow-up commit.
…teways and switch consumers to the device-selection package
The composition root (src/platform-runtime-device-inventory.ts) now attaches an optional findInstalledApp probe to the composed device inventory gateways, lazily importing the Apple simulator app-resolution mechanics. Device selection reads the probe from the request context instead of importing a platform package directly, so absent probes fall back to the ordinary inventory rules. All consumers switch to the @agent-device/device-selection/{dispatch-resolve,device-selection-resolver,device-inventory-context} subpaths; the moved tests carry a package-local inventory test util.
TARGET_DAG_RANK gains the device-selection leaf zone and drops the retired request zone; the back-edge fixture and the capture-kit ALS substrate fixture move to the package path.
|
Size Report
Startup median (7 runs, lower is better):
|
|
The move looks sound at ee11cdb, but the new installed-app probe needs one production-wiring regression. The moved selection tests supply the probe themselves, so removing it from createComposedDeviceInventoryGateways would leave those tests green while app-based simulator selection silently falls back. Add a test through that factory and the request context with two booted simulators and one installed-app match; show it fails when the factory omits the probe. Current CI passes. |
… selection The moved selection tests inject their own probe, so nothing covered the composition root actually attaching findInstalledApp to the gateways: omitting it would leave those tests green while app-based selection silently fell back to the generic local rules. The new case runs two booted simulators through createComposedDeviceInventoryGateways and the request context, fakes only the leaf xcrun spawn (core tool-provider), and asserts the single-app-installed-local selection plus both probe consults.
|
Added in b93bfe1: 'narrows app-based simulator selection through the factory-installed probe' in src/platform-runtime-device-inventory.test.ts (the factory's co-located test). It runs two booted simulators through createComposedDeviceInventoryGateways + withDeviceInventoryContext with com.example.demo installed on exactly one, and asserts device.id, reason: single-app-installed-local, and that the probe consulted both simulators. Only the leaf xcrun spawn is faked (runXcrun in platform-apple's core tool-provider), so the real findIosSimulatorInstalledApp → listapps chain executes behind the factory-installed probe. Red proof: with findInstalledApp removed from the factory's return, the same test fails with AMBIGUOUS_MATCH ("2 devices match this request equally") — the silent fallback to generic local rules you described. |
|
The new regression test closes the wiring gap: it exercises the real inventory factory and selection route, with only the tool invocation mocked. Code review is clean at b93bfe1. The iOS alert-replacement test is still failing, but looks unrelated to this device-selection move; the relevant package, coverage and integration checks pass. |
Summary
Moves the device-selection cluster (
dispatch-resolve,device-selection-resolver,device-inventory-context+ their tests/fixtures) into a new private workspace package@agent-device/device-selection— one subpath per module, no index, no re-export shims at the old paths.Device selection no longer imports platform-apple app-resolution directly: the composition root (
src/platform-runtime-device-inventory.ts) attaches an optionalfindInstalledAppprobe to the composed inventory gateways (deferred Apple import), and the package reads the probe from the request context — absent probes fall back to the ordinary inventory rules. All ~60 consumers switch to the package subpaths; the layering gates gain the new leaf zone (therequestzone is retired).Dependency deltas (value edges, depgraph recipe: edges from the daemon-server zone to root files in other zones): 936 → 919 (−17, the three moved files). Replay root value deps: 6 → 4 (−2).
Validation
pnpm check:affected --runon the rebased head: format/lint/typecheck/layering/di-seams/fallow/mcp-metadata/build/package/integration-node/macos-coverage all green; vitest-related 3856/3857 — one transient 5s hard-timeout intrace-runtime.test.ts(not in this diff) passes in ~1.3s in isolation.pnpm test:unit: remaining failures are wall-clock budget flakes reproducible on baseline under the same host load (load avg ~45: concurrent emulators + other worktree suites);test:smokegreen.check:fallow: no new findings; test-file-size ratchet and eager-closure budgets green;check:production-exportsunchanged (all 65 pre-existing, none in touched files).