← Keyhac crftwr/keyhac on GitHub · craftware

Testing

How Keyhac2 is tested, the reusable harness patterns, and what has been verified live on each OS.

Test layers

Testing the skill: quality-loop (qa/)

A packaged skill is a snapshot with no repository behind it, and this repository is full of the answers. So “is the skill self-contained?” cannot be asked from a session that has read doc/, examples/actions/ or the source. That session cannot unsee them. make qa asks it properly, through quality-loop (a dev dependency; the design is #205):

Runs are authorized by a person. They cost model time, they swap your config.py, and screen scenarios open windows.

make qa CASE=11                        # attached; quit your own Keyhac first
.venv/bin/quality-loop run 11          # the same, in the background
.venv/bin/quality-loop watch           # follow it: run.log and status.json
.venv/bin/quality-loop findings        # new / still there / gone / back

In a VM (#271), the run’s Keyhac is off this machine’s keyboard and screen, and your own Keyhac can keep running. Set KEYHAC_QA_GUEST to an SSH host alias for the VM:

KEYHAC_QA_GUEST=qa-mac make qa CASE=13

The VM layer is quality-loop’s (quality_loop.guest, its docs/guests.md), shared with XeFM (xefm#750); qa/guest.py keeps only what is Keyhac’s: what is staged and how Keyhac starts. What that alias means on this machine goes in ~/.config/quality-loop/guests.toml (KEYHAC_QA_GUESTS names another file), outside the repository: the shared folder as <host path>=<guest path>, the image’s interpreter as python (required for a Windows guest), and the VM itself, so that the run starts it from a clean state and puts it away afterwards.

Keyhac’s runs use the image’s free-threaded Python, which is what the apps embed (#369): free_threaded_python in the table, and on the Windows guest free_threaded_python_arm64 for --arch arm64. python stays as it was, since the table is shared and XeFM still runs on it. make test-vm (and so make release-test) checks the interpreter has the GIL off before it stages anything, and stops if not; the suite’s test_nothing_the_apps_import_turns_the_gil_back_on then checks that every dependency, as that guest installs it, keeps it off. On qa-mac the free-threaded framework (PythonT.framework, bundle org.python.pythont) needs no grant of its own: started over SSH, it runs under the Accessibility and Input Monitoring grant to sshd-keygen-wrapper.

Without a VM in the table, the guest is used as it is, already running. KEYHAC_QA_SHARE overrides the table’s share.

Claude stays on the host: the room, the operator, the evidence and cleanroom/. The run’s home and a copy of this working tree go on the share. Keyhac is started in the guest’s desktop session, and its endpoint is forwarded over SSH, so the host’s own bridge reaches it. qa/guest.py has the details.

Both have run scenarios end to end (13 on both, 12 on macOS). On both, the run’s Keyhac starts the way the test suite does: no Keyhac is used from the image, its free-threaded Python (3.15t, fixed per image) gets a fresh venv for the run with the third-party packages - pyproject.toml’s and PuiKit’s - from a pip cache on the share, and PuiKit is ours, so it is staged from this checkout’s environment, not installed. Everything under test is this checkout’s. (Until 2026-11 a macOS guest ran the staged keyhac/ inside the image’s Keyhac.app, whose bundled PuiKit went stale the first time the pin was raised past it, and every run stopped at start-up.)

The guest is the test environment. Start each run from a clean state: a Tart clone of a base image, deleted afterwards, or a VMware snapshot taken while the VM was running, reverted to before the run, as above. What the clean state needs, found the hard way:

Screens go up in the guest. The adapter’s screen_backend() hands the operator quality_loop.guest.screens in place of this machine’s backend. Each screen_open / screen_close runs quality-loop’s own Safari / Terminal or Edge / Windows Terminal code in the guest, from the run’s stage. On macOS that goes over SSH; on Windows it goes through a scheduled task in the desktop session. The pages stay served on the host’s 127.0.0.1, and a reverse tunnel (ssh -R, same port) makes that address the guest’s too, so the page’s events come back unchanged. A terminal screen’s script runs with the image’s interpreter in the guest.

What the clean state needs for screens:

qa/quality-loop.toml names qa/run.py as the adapter for the quality-loop command. The conductor skill (.claude/skills/quality-loop/, installed and upgraded only by quality-loop init, never edited by hand) runs the loop with you: plans from qa/PLAN.md, runs, reads the findings, files them as Issues, fixes what you choose and retests, under a policy you set. Ask Claude Code in this checkout to “run the QA loop”.

tests/test_qa.py checks, without a room, that every scenario parses and names declared screens, that every fixture config loads on both platforms, that the evidence tools answer correctly on rooms whose outcome is known, and that the quality-loop command finds this adapter and its scenarios check.

qa/action_rules.py holds the skill’s mechanical rules for an action (waits, not sleeps; no coordinates; bounded loops; …). The operator runs it on a room’s action as rules <room>, and tests/test_action_authoring_evals.py calibrates it both ways: the hand-written examples pass, and qa/fixtures/violates_every_rule.py trips every rule.

Cross-cutting patterns

Windows harness patterns (worth keeping)

Driving a Windows VM from the Mac over SSH

A Windows guest in VMware Fusion can be built, run and checked from the Mac without touching its desktop: build.ps1, a Keyhac.exe launch, and a result file to collect. Everything here addresses the guest as qa-win, an SSH host alias. Its address, user and key are per machine and live only in ~/.ssh/config, never in this repository.

Why not vmrun. A Windows 11 guest has a vTPM, which makes Fusion encrypt the VM partially, and vmrun then refuses every operation without the encryption password, checkToolsState included. SSH needs no password on the command line and works the same for any VM product.

Guest setup, once. In an elevated PowerShell:

Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0
Start-Service sshd; Set-Service sshd -StartupType Automatic

# The rule the capability creates covers the Private profile only, and a
# VM's network is usually Public. Widen it to every profile, but only for
# the host's subnet.
Set-NetFirewallRule -Name OpenSSH-Server-In-TCP -Profile Any -RemoteAddress <host subnet>/24

# An administrator logs in with this file, not ~/.ssh/authorized_keys.
$f = "$env:ProgramData\ssh\administrators_authorized_keys"
Add-Content -Path $f -Value '<public key>' -Encoding ascii
icacls $f /inheritance:r /grant "Administrators:F" /grant "SYSTEM:F"

New-ItemProperty -Path "HKLM:\SOFTWARE\OpenSSH" -Name DefaultShell `
  -Value "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -PropertyType String -Force
Restart-Service sshd

Add-WindowsCapability downloads from Windows Update and can sit at a full progress bar for many minutes. Get-WindowsCapability -Online -Name OpenSSH.Server* in another window says whether it has finished. If it reports Installed while the first window still sits there, interrupt it and carry on from Start-Service.

Host setup, once. A key of its own (ssh-keygen -t ed25519 -f ~/.ssh/<key>), whose .pub is the <public key> above, and:

Host qa-win
    HostName <guest IP>
    User <guest user>
    IdentityFile ~/.ssh/<key>
    IdentitiesOnly yes

Finding the guest’s IP. A bridged guest gets it from DHCP, so it can move. Read the MAC from the .vmx (ethernet0.generatedAddress), ping the subnet once so the ARP table fills, and look the MAC up in arp -an. A guest with the Public profile does not answer ping, but the ARP entry is there anyway.

Running things.

The #279 entry in the live verification record below used this setup.

macOS testing lessons (encoded in tests/test_mac_window.py etc.)

Live verification record

Everything automatable has been run live on both OSes (Windows 11 Home 10.0.26200; macOS 15 on this machine). Highlights and the bugs the passes caught:

Two things the pass itself got wrong, both worth keeping in mind for any Windows UI harness:

Notepad 11 drops and reorders injected input, and this is the target’s doing, not ours. hello-keys arrived in its text box as helloke-ys; a Ctrl-V came through as a bare v; and an injected Ctrl-V is silently dropped outright often enough that the pass retries it. The same strings down the same code path — including with a real hook installed and through InputContext, which is what fill.py uses — land intact in a plain Win32 control 30/30 (tests/test_win_send_text.py and a scratch probe), so the reordering is WinUI’s, not SendInput’s and not the hook’s. Two consequences: keys is not trustworthy against XAML editors, which is an argument for the existing paste-first default; and every one of these arrived as a loud failure because set_text reads back what it wrote. That rule is what turned a silently corrupted document into a FillFailed naming the text it actually found.

The interactive pass before a release

The genuinely-interactive checks were tracked in issue #10 and are all through as of 2026-08-07, but they are a standing pass, not a burnt-down backlog: they describe what to repeat before a release, since nothing here is covered by the automated harnesses. The two that needed hardware this machine does not have — a JIS keyboard, and a Japanese input method — were passed by hand on 2026-08-07 and stay on the list for the next release rather than being struck off. What the IME entry checks inverted on 2026-08-26: the chooser no longer takes keyboard focus, so its filter field no longer composes, and that is now the thing to confirm rather than the thing to fix.

Where 2.2.1 left it, since “nothing outstanding” is a claim that goes stale one release at a time: on macOS the tray “Edit Config” click and mouse feel were both verified live (2026-08-07). On Windows, 2.2.1 re-passed the Japanese IME, the tray icon and menu, and the console’s log pane, hook checkbox and log-level dropdown by hand (2026-08-08), and ran the bundle pass 11/11 against a bundle built from the PyPI PuiKit wheel. The one check not repeated for 2.2.1 is JIS layout detection, for want of the keyboard — skipped and recorded, not assumed.