hyderhusainarastu/hardware-mod-toolkit/hardware-in-the-loop-testing
Claude Code and agent skill by hyderhusainarastu/hardware-mod-toolkit
- community
- ext:[{"type":"hook","description":"Pre/post lifecycle hooks"}]
Checking that the SKILL.md file is still in the repository.
Make hardware-safety rules machine-enforced: a force-mock gate so automated runs never open a real device, fake transports, static regression guards, shared test vectors, a human hardware checklist. Use when agents or CI run against a project that also talks to real hardware.
Install
npx vskill@latest install hyderhusainarastu/hardware-mod-toolkit/hardware-in-the-loop-testingSemi-extensibleMentions customization, but needs skill-specific knowledge. Read the extensible skills standard
SKILL.md
The same SKILL.md was published earlier as hyderhusainarastu/hardware-mod-toolkit/hardware-in-the-loop-testing.
hardware-in-the-loop-testing
Two things actually went wrong in the worked example this skill is drawn from (github.com/hyderhusainarastu/byok-mod), and a prose rule ("never touch hardware") prevented neither of them:
- **An agent-run host command opened the real, physically-connected device's serial
port** — twice — from a plain CLI invocation outside the test suite, with no device operation actually intended.
- **An editor/session hook fired a device command in the background during an
unrelated run.** A Stop-style hook ran a "harmless" status/notify command while a long-running dashboard loop already held the port open. The hook's command opened a second, non-exclusive handle to the same port, which reset the device's protocol session counter out from under the loop — the loop then saw a sequence-gap NACK (E_SEQ_GAP) it treated as fatal and crashed, and the actual root cause took a full diagnosis pass to find because nothing had logged that a second process had touched the port at all.
Neither incident involved malice or a missed warning — both commands did exactly what they were told to do. What was missing was a mechanism that made "don't open a real port from an automated context" true regardless of what any individual command line, hook, or agent decided to run. That's what this skill builds: four layers of enforcement, weakest to strongest, plus the specific hazard (hooks) that defeated the weaker layers in practice, plus the parts of a safety net that genuinely cannot be automated and have to become a human checklist instead.
This generalizes past serial ports: "real hardware" here also covers a physical display, a Bluetooth/BLE link, an SD card the device reads at boot, or any other side channel an automated test run could accidentally exercise against a real unit.
1. The four enforcement layers
Layer them — do not treat any single one as sufficient, because each has a distinct failure mode:
Layer 1 — the prose rule
"Automated agents and CI never open a real device." Necessary, cited in templates/CLAUDE.md, and — on its own — exactly what both incidents above show is insufficient. Keep it, but never stop here.
Layer 2 — an environment gate the transport itself honours
Pick one environment variable name, e.g. <MOCK_ENV_VAR> (the worked example used BYOK_FORCE_MOCK), and check it in exactly one place: the low-level transport's own connect/open call, before it ever resolves or opens a port.
Design choices that matter here, each one taken from a real gap the incidents exposed:
- **Make the raised error a subclass of whatever error class every call site already
catches for "no device found."** The worked example's gate raises a TransportError subclass because every existing except TransportError (and every narrower except (WrongDevice, NoDeviceFound, HandshakeFailed, TransportError)) call site, including a fallback path that queues work for later instead of crashing, already degrades gracefully for that family. A gate that raises a new, uncaught exception type instead turns "safely refused" into "the whole process crashes" — worse than the thing it's protecting against.
- The gate changes nothing for a real end user. The variable is unset by default in
every shipped/installed context; only a dev/agent/CI shell exports it. Document that export as a step the shell performs (export <MOCK_ENV_VAR>=1 before running any device CLI directly), not as something the tool sets automatically — an automatically-set gate is one more thing that can silently stop being set.
- State explicitly that the test suite itself never needs the variable, because it
never reaches this code path at all (Layer 3 replaces the transport before the gate check would run). The gate exists for the shells and hooks that run the real CLI directly, outside the test harness.
- Set the gate in every automated prompt template and CI job, not just in test
setup — an agent invoked to "check device status" from a shell that never sourced the gate is exactly the failure mode incident 1 was.
Layer 3 — a fake transport injected in every test, so nothing enumerates ports at all
Layer 2 still resolves a real port list before refusing to open it, on some code paths — fine for a gate, not fine for a full test suite, which should never call into a real port-enumeration API at all. Give tests a fake that:
- satisfies the same interface the real transport needs (
.read/.write/
.close / .is_open at minimum),
- decodes every outbound byte with the project's own real wire-protocol parser,
not a hand-rolled stub — so a test failure here means the code under test actually produced a malformed frame, not that the fake diverged from the real format,
- answers every ACK-requiring request generically (a HELLO gets a real
HELLO_ACK-shaped payload; everything else gets a minimal ACK) rather than scripting one exchange at a time, with an override path (type_replies={...}) for the handful of tests that need a specific typed reply,
- can be told to go silent for specific message types (
silent_types={...}) to model
"the write succeeded, nothing ever answered it" — what a real disconnect looks like from the requesting side,
- drives a fake/manual clock for every timeout and backoff delay in the transport
under test, so a reconnect-backoff test costs milliseconds of real wall-clock time instead of the seconds the real backoff schedule specifies:
- exposes a way to inject unsolicited device events into the read buffer directly
(a button press, a status-changed notification) for event-polling tests, without those events needing a real request/response round trip.
For a helper process the real device side spawns (a capture helper, a companion binary invoked as a subprocess) rather than a library call, write the fake as a standalone script run as a real subprocess, understanding only the handful of CLI flags the real one uses, and add test-only flags the real binary doesn't have (a fixed frame count, a synthetic failure mode, a forced non-zero exit code) so failure paths are reachable without a device:
Build one fake per external dependency that a test would otherwise have to talk to for real (the transport, a capture helper, a cloud call) — each is small, and each removes one more way a test run could accidentally touch something real.
Layer 4 — scripts that refuse dangerous arguments outright
For any standalone script that can touch real hardware when run directly (a backup tool, a device-info probe, a flashing wrapper), refuse dangerous input at two points independently — see skills/mcu-safe-backup/SKILL.md §4 for the full pattern (argument-level refusal before anything runs, a second refusal on the fully assembled command line immediately before every invocation, dry-run by default with an explicit --yes required to execute anything). That skill's gate is this layer's concrete implementation for the "one script that is allowed to write" case; this skill's layers 1–3 are what keep every other automated path from ever reaching that script's own gate in the first place.
2. Hooks are a hazard
An editor or session hook that runs a device-touching command on some event (a file save, a session Stop, a periodic tick) will eventually fire during a test run or underneath a running long-lived loop — that is what happened in the incident this skill opens with, and it is not a one-off: hooks fire on events the hook author does not fully control the timing of, and "this command is harmless, it only reads status" is not the same claim as "this command never opens a competing handle to a port something else already owns."
If a hook must exist that can touch the device:
- Gate it on whether the long-running consumer of that device is currently running
— a pgrep-style check for the loop's process name/PID file before the hook does anything device-touching, skipping (not queuing, not retrying) if the loop is live. This is a stopgap, not a fix: prefer routing the hook through the loop's own IPC path instead (below), because a process-existence check has an unavoidable race between "checked" and "acted."
- Route the command through the running loop's own queue/IPC mechanism instead of
opening the device directly — e.g. a small JSON file or socket the loop already polls for out-of-band requests, so "notify the device" becomes "write a request the loop will pick up and serialize onto the one connection it already owns," never a second competing open().
- Disable the hook for the duration of any test run or long-lived session,
explicitly, rather than trusting a race-prone runtime check alone.
- Make the transport itself detect and log a second open (or refuse it outright,
where the OS/driver allows exclusive opens) so a future incident like this one is a one-line log message instead of a multi-hour diagnosis session reconstructing what touched the port and when.
Treat every hook, cron job, or background watcher in the project inventory as a candidate for this hazard — audit for "does anything fire on a timer or an editor event that could open this device" whenever a new hook is added, not just when a crash prompts the question.
3. Static regression guards
After any incident that had a specific, nameable root cause in source (not just "a bug"), add a host-only, dependency-free script that fails on the exact source condition that made the incident possible — not a general linter, a narrow check tied to one incident's actual root cause. Worked example (a firmware task-stack overflow that crashed on boot): the incident's source condition was four separate facts about the code, and the guard checks exactly those four:
This is the start of the file. Read the full SKILL.md on GitHub.
Security
- Security scanPassed, 95 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/hardware-in-the-loop-testing/SKILL.md
Popularity
- Repository stars
- 1
- 7-day trend score
- 3
Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.
Extension points
hookPre/post lifecycle hooks
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/hyderhusainarastu/hardware-mod-toolkit/hardware-in-the-loop-testing)