qa: input-inject QA log — REWORK (normalise-before-hotkey-match finding)
Gates green; verified KeyState.swift and Injector.swift against InputSimulation.cs, Receiver.cs, InitAndCleanup.cs, InputHook.cs and Event.cs. One confirmed finding: KeyState normalises side-less modifier VKs before chord/hotkey matching, so a lock-chord replay matches hotkeys Windows' side-specific-only switch would not match from the same bytes — contradicts this lane's own protocol.md §10.4 note 3 citation. One plausible finding: the configurable lock hotkey is missing Windows' RunOnLogonDesktop/RunOnScrSaverDesktop guard, undocumented either way. Co-Authored-By: Claude Sonnet 5 <[email protected]>
This commit is contained in:
1 parent
ccb058ed3a
commit
22b077b5df
1 file changed
+124
@@ -329,4 +329,128 @@ injector encodes the lock chord, the Engine sends it).
|
||||
|
||||
## QA log
|
||||
|
||||
### 2026-09-16 — QA (lane `input-inject`, dev from 3c51e95)
|
||||
|
||||
`tools/guard.sh -t 600 -- tools/gates.sh` green (swift-format lint
|
||||
--strict, `MWBCore` layering, `swift build -Xswiftc -warnings-as-errors`).
|
||||
Nothing was run that posts a `CGEvent`, locks the screen or moves the
|
||||
cursor (invariant 5) — verified by build and by reading
|
||||
`Sources/MWBMac/KeyState.swift` and `Sources/MWBMac/Injector.swift`
|
||||
top to bottom against `App/Class/InputSimulation.cs` (whole file),
|
||||
`App/Core/Receiver.cs:100-200`, `App/Core/InitAndCleanup.cs:214-243`,
|
||||
`App/Class/InputHook.cs:485-512` and `App/Core/Event.cs:260-275`.
|
||||
|
||||
Confirmed correct and faithfully ported: the injected-event tag on
|
||||
every posted event including `releaseAll()`'s ups; the modifier flag
|
||||
word (device + device-independent masks) applied to every posted key
|
||||
and mouse event, with `state.note` ordered before `state.eventFlags`
|
||||
so a modifier's own down/up event reports the *post*-transition state;
|
||||
`Md.WheelDelta`'s three meanings and the X-button 1/2 → macOS 3/4
|
||||
mapping; wheel `/120` with a per-axis remainder that survives across
|
||||
calls; click-count tracking via `ClickTracker` keyed off
|
||||
`EventTap.now()`; the four intercepted chords and their eat/lock/
|
||||
release-all combinations (Ctrl+Alt+Del eaten no lock, Win+L eaten +
|
||||
locked, Ctrl+Alt+End not eaten, `HotKeyLockMachine` eaten + locked);
|
||||
`releaseAll()` with no rate limit, ordinary keys before modifiers,
|
||||
clearing `KeyState.chord` afterward; all mutable state confined to
|
||||
`Injector`'s serial `queue`, `@unchecked Sendable` justified in the
|
||||
file header and actually honoured (every mutation site is reached
|
||||
only through `queue.async`/`queue.sync`). No key, VK or click content
|
||||
is logged at any level (`grep log\.` in `Injector.swift` shows three
|
||||
call sites, none naming a key). The
|
||||
`Coordinates.absoluteMove(...) → fromUniversal(..., in: primary)`
|
||||
two-step de-normalisation is the right reading of
|
||||
`InputSimulation.cs:160-173`: `dx`/`dy` there are computed by scaling
|
||||
the *desktop* rectangle into *primary*-monitor 0..65535 units and
|
||||
handed to `SendInput` `MOUSEEVENTF_ABSOLUTE`, which MSDN documents as
|
||||
primary-monitor-relative whenever `MOUSEEVENTF_VIRTUALDESK` is absent
|
||||
(confirmed absent, docs/protocol.md §1 framing note and grep of the
|
||||
module) — `fromUniversal` over `desktop` alone, the plausible
|
||||
alternative, would be wrong whenever desktop ≠ primary. Verified by
|
||||
hand-tracing `Sources/MWBCore/Coordinates.swift`
|
||||
`absoluteMove`/`fromUniversal` against the same four `w/h/l/t`
|
||||
products Windows computes.
|
||||
|
||||
**Findings.**
|
||||
|
||||
1. **`KeyState` normalises a side-less modifier VK to its left variant
|
||||
*before* chord/hotkey matching, so a lock-chord replay now matches
|
||||
hotkeys Windows would not match from the same bytes.**
|
||||
`Sources/MWBMac/Injector.swift:123-125` calls
|
||||
`KeyState.normalise(vk: data.virtualKey)` and passes the
|
||||
*normalised* result into `state.process(vk:isUp:lockMachine:)`,
|
||||
whose chord-tracking switches
|
||||
(`Sources/MWBMac/KeyState.swift:134-140` `releaseChord`,
|
||||
`:153-157` `processDown`) match on `KeyMap.leftControl` /
|
||||
`.leftMenu` / `.leftShift`. But
|
||||
`Injector.lockChord(for:)` (`Injector.swift:361-372`) — the wire
|
||||
encoding of `InputHook.GetVkCodesList`
|
||||
(`App/Class/InputHook.cs:485-512`) — emits the *side-less* codes
|
||||
`VK.MENU` (0x12), `VK.SHIFT` (0x10) and `VK.CONTROL` (0x11) for
|
||||
Alt/Shift/Ctrl (only Win gets the side-specific `VK.LWIN`), and on
|
||||
Windows those exact codes reach `InputProcessKeyEx`
|
||||
(`App/Class/InputSimulation.cs:372-403` the `LLKHF.UP` switch,
|
||||
`:418-438` the down switch) whose `case` labels are
|
||||
`VK.LCONTROL`/`VK.RCONTROL`, `VK.LMENU`/`VK.RMENU`,
|
||||
`VK.LSHIFT`/`VK.RSHIFT` — side-specific only. A side-less
|
||||
`VK.CONTROL`/`VK.MENU`/`VK.SHIFT` therefore never sets
|
||||
Windows' `ctrlDown`/`altDown`/`shiftDown`, so
|
||||
`Common.HotkeyMatched(..., Setting.Values.HotKeyLockMachine)`
|
||||
(`InputSimulation.cs:406`) can only be satisfied by a lock-chord
|
||||
replay when the configured `HotKeyLockMachine` requires *no*
|
||||
modifier other than Win (only `winDown` is reachable via the
|
||||
side-specific `VK.LWIN` `GetVkCodesList` sends) — for the shipped
|
||||
default, Win+Ctrl+Alt+L, the general branch on Windows never
|
||||
matches from a replay at all, and the machine locks only because
|
||||
the *separate*, hardcoded `case (VK)'L': if (winDown)` branch
|
||||
(`InputSimulation.cs:450-460`) fires on `winDown` alone. The
|
||||
port's `normalise`-before-`process` ordering sets `chord.control`
|
||||
and `chord.option` true on the side-less codes too, so
|
||||
`lockMachine.matches(...)` in `KeyState.processDown`
|
||||
(`KeyState.swift:149`) *does* match for any `HotKeyLockMachine`
|
||||
that requires Ctrl and/or Alt, not only Win. For the shipped
|
||||
default this happens to be unobservable — both platforms end up
|
||||
locking, Windows via the hardcoded `'L'` branch, the port via
|
||||
`lockMachine.matches` — but for any other configured lock hotkey
|
||||
that requires Ctrl or Alt (a legal, user-settable
|
||||
`HotKeyLockMachine`), a lock-chord replay would fail to lock the
|
||||
real Windows peer it targets while locking a Mac peer, which is
|
||||
exactly the wire-compatibility invariant (CLAUDE.md invariant 1)
|
||||
this lane is supposed to hold. It also contradicts this lane's own
|
||||
citation in `docs/protocol.md` §10.4 note 3 and this README's
|
||||
Assumptions ("the side-less VK_SHIFT/CONTROL/MENU do not touch
|
||||
[the chord state]... They are a *separate* set of facts from what
|
||||
the local keyboard is holding") — the code does not implement the
|
||||
fact the lane itself recorded. Fix direction: match hotkeys and
|
||||
update the chord on the *raw* `data.virtualKey`, and normalise only
|
||||
for `keycode(for:)`/`postKey`/`state.note` (the posting path, where
|
||||
the Assumptions bullet about mapping to the left key actually
|
||||
applies). **CONFIRMED.**
|
||||
|
||||
2. **The configurable lock hotkey is eaten and locks unconditionally;
|
||||
Windows gates it on desktop state.** `InputSimulation.cs:408-409`
|
||||
wraps the `HotKeyLockMachine` match in
|
||||
`if (!Common.RunOnLogonDesktop && !Common.RunOnScrSaverDesktop)` —
|
||||
on the logon or screen-saver desktop, `HotkeyMatched` can be true
|
||||
and `eatKey` still stays `false` (the key is not swallowed and no
|
||||
lock happens). `KeyState.processDown`
|
||||
(`Sources/MWBMac/KeyState.swift:147-152`) has no equivalent guard:
|
||||
`lockMachine.matches(...)` unconditionally eats and locks. This is
|
||||
not in the Assumptions/Handshakes as an intentional omission, and
|
||||
`docs/protocol.md` §10.5 does not mention it either. It may be
|
||||
legitimately inapplicable on macOS (no separate logon-desktop
|
||||
session the way Windows has one, and `CGEventTap` input injection
|
||||
is typically blocked outright once the screen is actually locked),
|
||||
but that reasoning is not recorded anywhere, so the next reader has
|
||||
no way to tell "considered and N/A" from "missed." Note only — the
|
||||
Win+L hardcoded branch (`InputSimulation.cs:450-460`) has no such
|
||||
guard on Windows either, so `KeyState`'s handling of *that* chord
|
||||
is not in question. **PLAUSIBLE**, record the reasoning either in
|
||||
Assumptions or as a §10.5 note.
|
||||
|
||||
No fixes applied in this pass beyond the log entry itself — both
|
||||
findings are behavioural, not typos.
|
||||
|
||||
Verdict: REWORK
|
||||
|
||||
## Review
|
||||
Reference in new issue
Block a user