| Layer | Speed | What | Runs when |
|---|---|---|---|
| Lint + format | ms | Code style, type errors | Every commit |
| Template unit tests | ms | Generator output, bash -n |
bun test |
| Parsing unit tests | ms | Token extraction, version parsing | bun test |
| VM provisioning | ~5 min | Scripts run on real Ubuntu VM | bun run test:vm |
| Snapshot-based | ~30s | Clone golden VM, test from checkpoint | Future |
| Stub openclaw | seconds | Fake openclaw binary, test CLI flow | Future |
| Full e2e | 10+ min | Complete wizard → onboard → verify | Manual |
bun testRuns all *.test.ts files under src/. Covers template generators and parsing logic.
bun run lint # ESLint — catch errors and bad patterns
bun run format:check # Prettier — check formatting consistency
bun run format # Prettier — auto-fix formattingbun run test:vmRequires Lima installed on the host. Creates (or reuses) a clawctl-test VM
and verifies provisioning outcomes: commands exist, services are enabled,
PATH is correct.
The tests are gated by the CLAWCTL_VM_TESTS=1 env var and won't run
during normal bun test.
When you add a new template generator:
-
Add an entry to the
bashGeneratorsarray insrc/templates/templates.test.ts:["generateMyScript", generateMyScript, ["expected-content", "keywords"]],
-
This automatically tests:
- Starts with
#!/bin/bashandset -euo pipefail - Contains your expected content strings
- Passes
bash -nsyntax validation
- Starts with
-
If the template takes parameters, add a dedicated
describeblock (seegenerateLimaYamlfor an example).
The idea: maintain a pre-provisioned VM snapshot that can be cloned in ~30 seconds instead of provisioning from scratch (~5 min).
To create a golden snapshot:
- Run full provisioning on a fresh VM
- Stop the VM
- Save it as a template:
limactl snapshot create clawctl-golden - Tests clone from this snapshot instead of creating from scratch
This requires Lima snapshot support and a workflow for keeping the golden image up to date when provisioning scripts change.
For testing the CLI flow without a real OpenClaw installation:
-
Create a fake
openclawbinary that:- Responds to
--versionwith a version string - Responds to
onboardby writing expected config files and exiting 0 - Responds to
doctorwith exit 0 - Responds to
daemon install/start/restartwith exit 0 - Responds to
config setwith exit 0
- Responds to
-
Place it on PATH before the real binary in tests
-
This enables testing the full CLI wizard flow in seconds without VM or network access.