refactor(daemon): inline the touch sub-switch into the interaction dispatcher - #2302
Conversation
…spatcher interaction-touch.ts was a 31-line pass-through re-switching on press/click/longpress/hover/fill only to call the same five handlers handleInteractionCommands already imports transitively. Inline the five cases into the existing switch and delete the file, dropping one hop from the press/click/longpress/hover/fill dispatch path. Point the response-construction-guard sentinel at interaction-touch-press.ts (a file that still exists) so it keeps watching for a hand-rolled responseData branch across the touch handler set.
Size Report
Startup median (7 runs, lower is better):
|
PR review findings on #2302: - The ADR-0011 responseData guard scanned files by an interaction-touch*.ts name prefix, which stopped covering the touch dispatch switch once it moved into interaction.ts. Added a targeted second check that extracts the press/click/longpress/hover/fill case bodies from interaction.ts and scans them for hand-rolled responseData, without widening the whole-file scan onto interaction.ts (which also hosts the unrelated `type` command's legitimate local responseData construction). Planted red: reverted one switch case to a hand-rolled responseData construction twice (press, then click) and reran `npx vitest run src/daemon/interaction/internal/__tests__/interaction-response-construction-guard.test.ts`; both times the new test failed with the expected "Hand-rolled interaction responseData found in the touch dispatch switch" message, then passed clean again after reverting. - docs/adr/0019-end-state-hop-trace.md pinned itself to a commit and claimed the press/Android route was untouched by this PR, but the PR's whole point is merging two of that table's traced files (interaction.ts, interaction-touch.ts). Merged the corresponding table rows, renumbered the remaining hops, updated the file/class summary counts and every downstream hop-range reference in the same doc, and did the same for the one line in docs/adr/0019-request-bound-platform-runtime.md that also cited the now-stale 24-hop figure.
|
Sentinel review at 292c0ed. P2: the new case-body regex stops at the first nested case/default, so a hand-rolled responseData after a nested switch in press is invisible to the construction guard; the previous whole-file scan caught it. The delegation move itself is behavior-preserving, but the filename exception plus copied command list weakens the invariant. Keep construction enforcement at the owning typed/delegation boundary or reuse structural parsing instead of formatting-sensitive case extraction. Plant a nested switch followed by hand-rolled responseData and prove the gate rejects it before restoring. Hold readiness until this is resolved. |
The ADR-0011 guard extracted each touch case body with a regex that stopped at the first nested case/default, so a hand-rolled responseData placed after a nested switch was invisible. Parse interaction.ts with oxc-parser instead and require every press/click/longpress/hover/fill case to be exactly one return await <handler>(...) where the handler is imported from an interaction-touch*.ts module. Inline planted-red cases cover the nested-switch shape, an inline literal, a foreign callee, and a missing command.
|
Addressed in de50360. The case-body regex is gone; the guard now parses |
* origin/main: perf: bundle runtime dependencies and report full install size (#2310) ci: avoid unrelated Apple runner cache invalidation (#2303) fix(web): preserve the backend ref so snapshot refs match actionable refs (#2283) test(daemon): session-open-url-prewarm through the request seam (#2304) test(daemon): session-devices-batch-runtime through the request seam (#2305) chore(gates): layering baselines ratchet against merge-base (#2299) test(daemon): one typed conformance helper for the daemon runtime suites (#2298) chore(layering): derive the contracts export inventory from package.json (#2297) perf: bundle tar-stream to reduce install footprint (#2286)
|
Sentinel review at 0b982bf: The nested-switch enforcement hole is fixed by the AST delegation check, independently reviewed. One actionable gate failure remains: delegationOf at interaction-response-construction-guard.test.ts:105 is 11 cyclomatic / 9 cognitive and fails Fallow in Compatibility & Provenance (job101366047914). Simplify/split the owning AST shape checks without raising the baseline, retain the planted negatives, and rerun the gate. Size also fails from incompatible base-report js.rawBytes; device CI must clear separately. No readiness label. |
|
Summary
interaction-touch.tswas a 31-line pass-through: a second command-name switch that onlyre-dispatched
press/click/longpress/hover/fillto the same handlershandleInteractionCommandsalready pulled in. Inlined those five cases into the existingswitch in
src/daemon/interaction/internal/interaction.tsand deletedinteraction-touch.ts.No client-, operator-, or command-author-visible behavior change — this only removes one
indirection hop on the press/click/longpress/hover/fill dispatch path (−1 hop).
Review follow-ups landed in the same branch:
interaction-touch*.tsname prefix,which stopped covering the switch once it moved into
interaction.ts. The dispatcher is nowheld to a structural rule instead: the guard parses
interaction.tswith oxc-parser andrequires every
press/click/longpress/hover/fillcase to be exactly onereturn await <handler>(...)whose callee is imported from aninteraction-touch*.tsmodule.Nothing can be constructed in the switch at all, so a nested switch, a local
responseData,an inline literal or a foreign callee all fail. The guard's own tests plant each of those
shapes in an inline dispatcher source and assert the exact violation.
docs/adr/0019-end-state-hop-trace.mdtraced both files this PR merges by name and pinneditself as unaffected by this PR. Merged the corresponding table rows, renumbered the
remaining hops, and updated every downstream count/range reference in that doc and in
docs/adr/0019-request-bound-platform-runtime.md.Validation
Tested at
de5036093f(structural guard),0b982bfcc0(oxfmt only) and31af37752b(folds the delegation check under fallow's complexity threshold, then merges main for the #2310 size-report schema) on top of292c0edb220e50f5f34f9436c777fafad631eba0.npx vitest run src/daemon/interaction/internal/__tests__/— 30 files, 197 passednpx tsc -p tsconfig.json --noEmit— cleannpx oxlinton the changed test file — cleande5036093f): gavepressa nestedswitchfollowed by a hand-rolledresponseDatain the realinteraction.ts; the guard failed withcase 'press': the case body is not exactly onereturn await (...)``, then passed clean afterreverting. The same shape, an inline response literal, a non-touch callee and a removed
command are pinned as permanent inline planted-red cases in the guard test (7 tests green).