Skip to content
C.W.K.
Lesson 03 of 06 · published

The Lab and Its Fixtures

~15 min · lab, fixtures, integration-tests, gui-testing, fail-closed

Level 0Idle Hands
0 XP0/39 lessons0/12 achievements
0/100 XP to next level100 XP to go0% complete
"None of Dad's Macs is a test fixture." — Tinker architecture

Where Tinker Is Allowed to Be Tested

Hiding real apps on a real screen is not something to try on the Mac Dad is editing on. Tinker's builds and tests run in one place: the registered Pippa Home lab, in the pippa account on Pippa's own Mac, admitted by that Mac's lab coordinator so a test run never collides with recording or a broadcast. The rule is enforced, not hoped for. Every test and lab script begins with require-lab.py, which resolves the lab's fleet label from the family registry and compares it, and the account name, with the Mac it is running on. Anywhere else it exits with "Builds and tests require the registered Pippa Home lab account." Fail closed, before the first experiment.

Three Layers of Test

Engine tests in Swift Testing use the fake visibility seam from track 2 to cover pre-hidden apps, overlap, process replacement, partial failure, proven non-attempts, standing refusals, persistence failure, recovery after restart and emergency stop mid-hide — fast and deterministic. Python tests run the vendored kit's drift check and the real AppActions root against the worker, including actor refusal and request replay. Lab fixtures do the part no fake can: a tiny executable, tinker-fixture, is wrapped into disposable, ad-hoc-signed apps and launched through Launch Services, and a dedicated helper app hides and shows them for real, checks they are still running afterwards, and closes them when it is done.

The GUI Lab

A separate run builds a lab copy of Tinker.app, launches a fixture app with a display name containing spaces and parentheses, and starts Tinker with a lab snapshot flag. Tinker then drives its own Settings through real AppKit mouse events — choosing an app in the picker, saving, reopening the Settings scene — and captures a screenshot of each tab. Through its own door it exercises status, actions, change and activity lists, a restore, the refusals that matter — a foreign actor, a foreign Host, a browser Origin, a forwarded caller — and one case that must succeed: a tunnel arriving at 127.0.0.1 with a different port in Host. The script checks every capture and record exists, verifies the bundle's signature is still intact, and finally checks the quit record: the app must have left through a quit Apple event with its release finished.

What the Lab Learned

The lab is where several lessons in this quest came from: hide() returning false before the hide landed; Swift Testing macros needing explicit predicates for AppKit visibility; fixtures needing to finish launching before a check; clicks in a flipped hosting view needing window coordinates. Each became a commit, and each would have been invisible to a unit test whose fake agreed with its author.

Code

Fail closed: the lab identity comes from the registry (from scripts/require-lab.py)·python
"""Fail closed before experiments; registry placement owns the lab identity."""
import sys
from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / 'bridge'))
import kit_family_endpoints as family

lab = family.host_fleet_label(str(family.FAMILY_SERVICES['cwkPippaHome']['host']))
actual = (Path.home() / '.config/fleet-label').read_text().strip()
if actual != lab or Path.home().name != 'pippa':
    raise SystemExit('Builds and tests require the registered Pippa Home lab account.')
The test entry point (scripts/test.sh)·bash
#!/bin/bash
set -euo pipefail
cd "$(dirname "$0")/.."
PYTHON="$HOME/miniconda3/envs/cwk-tinker/bin/python"
"$PYTHON" scripts/require-lab.py
swift test --jobs 2
"$PYTHON" -m pytest -q Tests
bash scripts/lab-visibility.sh
What the GUI lab insists on before it calls a run good (from scripts/lab-ui.sh)·bash
for name in presets shortcuts activity access configuration; do
  test -s "$OUTPUT/$name.png"
done
for name in settings-interaction watchfire health actions status changes restore activity \
            actor-refusal tunnel-actions foreign-host-refusal browser-refusal forwarded-refusal; do
  test -s "$OUTPUT/$name.json"
done
# The app left through a quit Apple event, as it does at logout, and its
# deferred termination finished the release instead of timing out.
grep -Fq '"path":"apple-event","released":true' "$OUTPUT/quit.json"

External links

Exercise

List three behaviours of your own app that only the real OS can confirm, and for each design a disposable fixture that lets you test it without touching anything a person relies on. What check, like require-lab.py, would stop the test from running anywhere else?
Hint
Good candidates are anything that crosses a process boundary or depends on permission: window visibility, file coordination, notifications, URL handling. A fixture is usually a tiny app or file created just for the run and removed after. The guard should derive 'the right place' from data you already maintain (a registry, a config), compare it with where the code is running, and exit before the first effect.

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue

Comments 0

🔔 Reply notifications (sign in)
Sign in — Please sign in to comment.

No comments yet — be the first.