Device plugins
A device plugin is a separate HTTP service that owns one kind of hardware — boards, displays, anything else. MonkeyTester never touches the hardware itself, and a plugin that implements the contract works from any test with no change to MonkeyTester.
The contract (contract_version 1)
Full text: PLUGIN_API.md in the MonkeyTester repo. Everything a test asks of a plugin is an action run as a job:
POST /jobs {device, action, params, timeout_ms}— the plugin answers at once with a job id.GET /jobs/<id>?wait=<seconds>blocks until the job finishes orwaitruns out.- The job ends in exactly one terminal state; the step passes only on
passed. A job that fails is still HTTP 200 withstate: "failed".
| Endpoint | Purpose |
|---|---|
GET /health | Open; must answer with the plugin contract (monkeytester-plugin, version 1) — this gates registration. |
GET /devices | Owned hardware with state, capabilities and details. |
GET /actions | Every action with a parameter schema — how the runner types key=value strings (int, float, bool, json) and validates calls. |
POST /jobs, GET /jobs/<id>, POST /jobs/<id>/cancel | Start, wait for, cancel a job. |
GET /events?device=…&since=… | Device event log (for long-polling state changes). |
POST /uploads | Upload files for actions when the path can't live on the plugin's host; the action then gets upload:<id>. |
Conventions: JSON/UTF-8, milliseconds unless named otherwise; a plugin started with a token (PLUGIN_TOKEN) demands X-Plugin-Token on every request except GET /health. After the security update the token is mandatory on any non-loopback bind: a plugin told to listen beyond 127.0.0.1/::1/localhost without one refuses to start; on loopback it is optional; HTTP errors carry {"error", "code"} with codes bad_request unauthorized not_found unknown_action unknown_device device_busy internal. A plugin must run on Linux and macOS; hardware paths are paths on the plugin's host.
Registering plugins in the viewer
- Settings → Plugins → Manage device plugins: add name + address. The address is saved only when its
GET /healthanswers with the plugin contract. Saved as thepluginsmap inRun/config.json. - The environment variable
MT_PLUGINS=name=url[,name=url]is imported into that map once at viewer start and ignored after that — don't keep editing it. - AI is the exception: its address is set only in that row's Configure panel (saved as
visual_plugin_url), never in the manage box. - The page lists active plugins with their live state, capabilities and connected devices; add/edit/remove from there.
- Tokens: each plugin's token is entered in the viewer's Settings and sent as
X-Plugin-Token. The field is write-only — the viewer checks the token against the plugin before saving, then shows only whether it is configured, its last four characters and when it was saved (Replace / Remove to change it). The old variablesPLUGIN_TOKENandMT_PLUGIN_TOKEN_<NAME>are imported into Settings once, when Settings has no token, and ignored after that. A missing or wrong token shows 401. - Plugins on the viewer's own host (the lab's ESP32 plugins) listen on
127.0.0.1by default and need no token; one on another machine must have a token.
Using a plugin from a test
Example with a fictional plugin fisher that owns an aquarium controller:
PLUGIN: fisher factory-reset
PLUGIN: fisher set-temp celsius=24
PLUGIN: fisher expect
GET /status -> 200 {"heater":"off","ok":true}
END
VERIFY: The dashboard shows the heater off
PLUGIN: fisher clear
- The runner checks
GET /healthon a plugin's first use in a run and cachesGET /actions; an unknown plugin or action fails the step with the list of known ones. - Actions run one job at a time per device; jobs wait for the action's own default timeout unless
timeout=overrides it. - Failures are machine-readable — codes like
unknown_device(HTTP 404 onPOST /jobs),bad_request,device_busyor plugin-specific ones; see each plugin'sACTIONS.mdfor its codes.
Writing your own plugin
A plugin is just an HTTP server implementing the contract; the shipped plugin repos keep the generic server (jobs, long-poll waits, events, uploads) in one file and add discovery and actions in another. The contract is the whole coupling: implement it and your hardware works from any test.
- Answer
GET /healthwith the contract,GET /deviceswith your hardware,GET /actionswith actions and parameter schemas. - Implement
POST /jobs+GET /jobs/<id>; end every job in exactly one terminal state and pass only on real success. - Follow the family's security rules: default to a loopback bind, refuse to start on a non-loopback bind without a token, compare tokens in constant time, and keep
GET /healthfree of configuration and secrets (see Security). - Ship a systemd user unit (Linux) and a launchd plist (macOS) in
packaging/, and document your actions in anACTIONS.md. - Register it in the viewer and drive it from a test with
PLUGIN:steps.