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 orbit and sheet arguments that yield no frames or never end
Rudy Celekli3f6ab38b3d83
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 8c9e657..66cc18b 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -14,6 +14,7 @@ All notable changes to Anatomy are recorded here. The format follows [Keep a Cha### Fixed+- `drive.mjs` rejects an `orbit` whose step is zero or points away from its end angle, and a `sheet` whose count is not a whole number of at least 1, before Chrome starts. A zero step used to capture frames without ever finishing; the others died with `Cannot read properties of undefined (reading 'width')`.- `capture.mjs` waits for the page to load before it touches it, even with `--wait 0`, and gives up with an error when Chrome leaves a request unanswered for 60 s instead of hanging.- `drive.mjs` `until` times a condition inside the page, so one that is already true passes however short the wait, even on a slow machine; a promise that never settles still times out.- Start headless Chrome on Windows from an elevated terminal: `capture.mjs`, `drive.mjs` and `turn-check.mjs` pass `--do-not-de-elevate` there. Chrome otherwise relaunches itself without the elevation, the process the script started exits with code 0, and the check stops with `Chrome exited before startup: 0` while the relaunched browser stays running.diff --git a/scripts/drive-actions.test.mjs b/scripts/drive-actions.test.mjsindex 6888a4b..253c4ef 100644--- a/scripts/drive-actions.test.mjs+++ b/scripts/drive-actions.test.mjs@@ -44,3 +44,31 @@ test("an invalid later action fails before earlier actions execute", async () =>assert.equal(result.code, 1);assert.doesNotMatch(result.stdout, /shouldNotRun/);});++test("orbit rejects a step that never reaches its end angle", async () => {+ for (const action of [["orbit", "out.png", 90, 0, 0], ["orbit", "out.png", 0, 90, -10], ["orbit", "out.png", 0, 90, "10"]]) {+ const result = await run([action]);+ assert.equal(result.code, 1, JSON.stringify(action));+ assert.match(result.stderr, /orbit needs numeric from, to and a nonzero step/);+ }+});++test("sheet rejects a count that yields no frames", async () => {+ for (const action of [["sheet", "out.png", 50, 0], ["sheet", "out.png", 50, 2.5], ["sheet", "out.png", -1, 3]]) {+ const result = await run([action]);+ assert.equal(result.code, 1, JSON.stringify(action));+ assert.match(result.stderr, /sheet needs a non-negative every/);+ }+});++test("a valid orbit and sheet still pass validation", async () => {+ const orbit = join(tmpdir(), `anatomy-orbit-${process.pid}.png`);+ const sheet = join(tmpdir(), `anatomy-sheet-${process.pid}.png`);+ try {+ const result = await run([["eval", "window.__isoTurn={set(){}}"], ["orbit", orbit, 0, 20, 10], ["sheet", sheet, 10, 2]]);+ assert.equal(result.code, 0, result.stderr);+ } finally {+ await rm(orbit, { force: true });+ await rm(sheet, { force: true });+ }+});diff --git a/scripts/drive.mjs b/scripts/drive.mjsindex 5e702dc..4d66d27 100644--- a/scripts/drive.mjs+++ b/scripts/drive.mjs@@ -109,6 +109,14 @@ async function main() {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}`);+ if (action[0] === "orbit") {+ const [, , from, to, step] = action;+ if (![from, to, step].every(Number.isFinite) || step === 0 || (step > 0 ? from > to : from < to)) throw new Error(`orbit needs numeric from, to and a nonzero step that moves from ${from} toward ${to}, got step ${step}`);+ }+ if (action[0] === "sheet") {+ const [, , every, count] = action;+ if (!Number.isFinite(every) || every < 0 || !Number.isInteger(count) || count < 1) throw new Error(`sheet needs a non-negative every and a whole count of at least 1, got every ${every} and count ${count}`);+ }}const url = /^https?:|^file:/.test(target) ? target : pathToFileURL(resolve(target)).href;const binary = chromePath();