Skip to content

An agent skill for creating detailed, interactive isometric illustrations of real-world machines and complex systems. Generates polished SVGs with optional WebGL shaders and 3D effects.

fix(drive): reject unknown actions before running a session

Rudy Celekliaf47018ca70a
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index bf7b18d..a9eb75f 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -25,6 +25,9 @@ jobs:
with:
node-version: 22
+ - name: Drive action regressions
+ run: node --test scripts/drive-actions.test.mjs
+
- name: Dial indicator
run: |
node examples/dial-indicator/build.mjs
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 8152ae2..4c37a06 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -12,6 +12,8 @@ All notable changes to Anatomy are recorded here. The format follows [Keep a Cha
### Fixed
+- `scripts/drive.mjs` now rejects unknown actions before running the session, so a misspelled verification step cannot report success.
+
- `examples/test-rig/` drew its glass button dark in the light theme. `stretch.css` now has light values for its own colours.
### Changed
diff --git a/scripts/drive-actions.test.mjs b/scripts/drive-actions.test.mjs
new file mode 100644
index 0000000..6888a4b
--- /dev/null
+++ b/scripts/drive-actions.test.mjs
@@ -0,0 +1,46 @@
+import assert from "node:assert/strict";
+import { execFile } from "node:child_process";
+import { mkdtemp, rm, writeFile } from "node:fs/promises";
+import { tmpdir } from "node:os";
+import { join } from "node:path";
+import { promisify } from "node:util";
+import { fileURLToPath } from "node:url";
+import test from "node:test";
+
+const execute = promisify(execFile);
+const drive = fileURLToPath(new URL("drive.mjs", import.meta.url));
+
+async function run(actions) {
+ const directory = await mkdtemp(join(tmpdir(), "anatomy-drive-actions-"));
+ try {
+ const page = join(directory, "figure.html");
+ const file = join(directory, "actions.json");
+ await writeFile(page, '<!doctype html><div class="iso-plate">Figure</div>');
+ await writeFile(file, JSON.stringify(actions));
+ try {
+ return { code: 0, ...await execute(process.execPath, [drive, page, "--actions", file], { timeout: 30000 }) };
+ } catch (error) {
+ return { code: error.code, stdout: error.stdout, stderr: error.stderr };
+ }
+ } finally {
+ await rm(directory, { recursive: true, force: true });
+ }
+}
+
+test("unknown actions fail instead of silently skipping verification", async () => {
+ const result = await run([["unti", "false", 1]]);
+ assert.equal(result.code, 1);
+ assert.match(result.stderr, /unknown action unti/);
+});
+
+test("valid actions still execute after validation", async () => {
+ const result = await run([["wait", 1], ["eval", "({checked:true})"]]);
+ assert.equal(result.code, 0);
+ assert.match(result.stdout, /eval: \{"checked":true\}/);
+});
+
+test("an invalid later action fails before earlier actions execute", async () => {
+ const result = await run([["eval", "({shouldNotRun:true})"], ["screenshot", "out.png"]]);
+ assert.equal(result.code, 1);
+ assert.doesNotMatch(result.stdout, /shouldNotRun/);
+});
diff --git a/scripts/drive.mjs b/scripts/drive.mjs
index ef2c90b..bd21ad7 100644
--- a/scripts/drive.mjs
+++ b/scripts/drive.mjs
@@ -102,6 +102,11 @@ async function main() {
}
const [target, script] = rest;
const actions = options.actions ?? JSON.parse(script ?? "[]");
+ const kinds = new Set(["scroll", "wait", "move", "click", "drag", "key", "slow", "until", "eval", "shot", "lines", "turn", "orbit", "sheet"]);
+ if (!Array.isArray(actions)) throw new Error("actions must be an array");
+ for (const action of actions) {
+ if (!Array.isArray(action) || !kinds.has(action[0])) throw new Error(`unknown action ${Array.isArray(action) ? action[0] : action}`);
+ }
const url = /^https?:|^file:/.test(target) ? target : pathToFileURL(resolve(target)).href;
const binary = chromePath();
if (!binary) {
@@ -287,7 +292,7 @@ async function main() {
console.log(`shot ${out}`);
}
failed += result.problems.length;
- } else console.log(`unknown action ${kind}`);
+ }
}
console.log(problems.length ? problems.join("\n") : "console: clean");
socket.close();