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: fail browser drives on evaluation errors

Rudy Celekli1c63574356e4
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index bf7b18d..859daab 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -25,6 +25,9 @@ jobs:
with:
node-version: 22
+ - name: Browser driver regressions
+ run: node --test scripts/drive.test.mjs
+
- name: Dial indicator
run: |
node examples/dial-indicator/build.mjs
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 8152ae2..d0ed5ad 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 fails when a browser evaluation throws or rejects, rather than reporting a clean successful session.
+
- `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/CONTRIBUTING.md b/CONTRIBUTING.md
index 9f5dc61..538e85d 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -52,6 +52,12 @@ After a build, `git status --short` must show nothing unless you meant to change
Run the ones that match what you touched, and read every PNG they write: open it and look. Put screenshots in `shots/`, which is ignored.
+**Browser driver regressions.** When changing `scripts/drive.mjs`, check that failed browser evaluations exit nonzero and successful evaluations still work.
+
+```sh
+node --test scripts/drive.test.mjs
+```
+
**Geometry audit.** For figures with pipes, cables or round parts. It must end `audit passed`, with every failing line at 0.
```sh
diff --git a/scripts/drive.mjs b/scripts/drive.mjs
index ef2c90b..e36c729 100644
--- a/scripts/drive.mjs
+++ b/scripts/drive.mjs
@@ -154,7 +154,13 @@ async function main() {
pending.set(call, done);
socket.send(JSON.stringify({ id: call, method, params }));
});
- const evaluate = async (expression) => (await send("Runtime.evaluate", { expression, awaitPromise: true, returnByValue: true })).result?.result?.value;
+ const evaluate = async (expression) => {
+ const reply = await send("Runtime.evaluate", { expression, awaitPromise: true, returnByValue: true });
+ if (reply.error) throw new Error(reply.error.message);
+ const exception = reply.result?.exceptionDetails;
+ if (exception) throw new Error(exception.exception?.description ?? exception.text);
+ return reply.result?.result?.value;
+ };
const sleep = (ms) => new Promise((done) => setTimeout(done, ms));
await send("Runtime.enable");
await send("Page.enable");
diff --git a/scripts/drive.test.mjs b/scripts/drive.test.mjs
new file mode 100644
index 0000000..101a656
--- /dev/null
+++ b/scripts/drive.test.mjs
@@ -0,0 +1,72 @@
+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);
+
+async function drive(expression, action = "eval") {
+ const directory = await mkdtemp(join(tmpdir(), "anatomy-drive-test-"));
+ try {
+ const page = join(directory, "figure.html");
+ const actions = join(directory, "actions.json");
+ await writeFile(page, '<!doctype html><div class="iso-plate" tabindex="0">Owned figure</div>');
+ await writeFile(actions, JSON.stringify([[action, expression, 200]]));
+ try {
+ return { code: 0, ...await execute(process.execPath, [fileURLToPath(new URL("drive.mjs", import.meta.url)), page, "--actions", actions], { timeout: 30000 }) };
+ } catch (error) {
+ return { code: error.code, stdout: error.stdout, stderr: error.stderr };
+ }
+ } finally {
+ await rm(directory, { recursive: true, force: true });
+ }
+}
+
+test("drive fails when a browser assertion throws", async () => {
+ const result = await drive("(()=>{throw new Error('drive assertion failed')})()");
+ assert.equal(result.code, 1);
+ assert.match(result.stderr, /drive assertion failed/);
+ assert.doesNotMatch(result.stdout, /console: clean/);
+});
+
+test("drive fails when an awaited browser promise rejects", async () => {
+ const result = await drive("Promise.reject(new Error('drive async assertion failed'))");
+ assert.equal(result.code, 1);
+ assert.match(result.stderr, /drive async assertion failed/);
+});
+
+test("drive preserves a successful JSON evaluation", async () => {
+ const result = await drive("({checked: true})");
+ assert.equal(result.code, 0);
+ assert.match(result.stdout, /eval: \{"checked":true\}/);
+ assert.match(result.stdout, /console: clean/);
+});
+
+test("drive preserves a successful undefined evaluation", async () => {
+ const result = await drive("void 0");
+ assert.equal(result.code, 0);
+ assert.match(result.stdout, /eval: undefined/);
+ assert.match(result.stdout, /console: clean/);
+});
+
+test("drive reports a browser evaluation syntax error", async () => {
+ const result = await drive("(()");
+ assert.equal(result.code, 1);
+ assert.match(result.stderr, /SyntaxError/);
+});
+
+test("drive reports an assertion thrown while waiting for a condition", async () => {
+ const result = await drive("(()=>{throw new Error('until assertion failed')})()", "until");
+ assert.equal(result.code, 1);
+ assert.match(result.stderr, /until assertion failed/);
+});
+
+test("drive preserves a successful wait condition", async () => {
+ const result = await drive("document.querySelector('.iso-plate') !== null", "until");
+ assert.equal(result.code, 0);
+ assert.match(result.stdout, /console: clean/);
+});