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(turn-check): reject empty orbit sampling
Rudy Celeklic834095d5e84
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.ymlindex bf7b18d..70f72a3 100644--- a/.github/workflows/ci.yml+++ b/.github/workflows/ci.yml@@ -25,6 +25,9 @@ jobs:with:node-version: 22+ - name: Orbit sampling regressions+ run: node --test scripts/orbit-sampling.test.mjs+- name: Dial indicatorrun: |node examples/dial-indicator/build.mjsdiff --git a/CHANGELOG.md b/CHANGELOG.mdindex 8152ae2..c4e2829 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+- Orbit checks reject invalid sampling steps and empty pose lists before a zero-state sweep can pass.+- `examples/test-rig/` drew its glass button dark in the light theme. `stretch.css` now has light values for its own colours.### Changeddiff --git a/scripts/orbit-sampling.test.mjs b/scripts/orbit-sampling.test.mjsnew file mode 100644index 0000000..33af2cd--- /dev/null+++ b/scripts/orbit-sampling.test.mjs@@ -0,0 +1,50 @@+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 test from "node:test";++const execute = promisify(execFile);+const page = "examples/turning-dial/turning-dial-verify-light.html";+async function run(args) {+ try { return { code: 0, ...await execute(process.execPath, ["scripts/turn-check.mjs", page, ...args], { timeout: 60000 }) }; }+ catch (error) { return { code: error.code, stdout: error.stdout, stderr: error.stderr }; }+}+for (const step of ["NaN", "Infinity", "-1", "721"])+ test(`rejects orbit step ${step} instead of passing an empty sweep`, async () => {+ const result = await run(["--order", "--step", step]);+ assert.equal(result.code, 1);+ assert.match(result.stderr, /--step must be a finite number/);+ assert.doesNotMatch(result.stdout, /turn check passed/);+ });+test("rejects an empty explicit pose list instead of auditing zero states", async () => {+ const directory = await mkdtemp(join(tmpdir(), "anatomy-orbit-states-"));+ try {+ const file = join(directory, "states.json"); await writeFile(file, "[]");+ const result = await run(["--order", "--states", file]);+ assert.equal(result.code, 1); assert.match(result.stderr, /nonempty JSON list/);+ assert.doesNotMatch(result.stdout, /turn check passed/);+ } finally { await rm(directory, { recursive: true, force: true }); }+});+test("rejects a nonfinite fine step instead of silently skipping the second difference", async () => {+ const result = await run(["--pops", "--step", "360", "--fine", "NaN"]);+ assert.equal(result.code, 1); assert.match(result.stderr, /--fine must be a finite number/);+ assert.doesNotMatch(result.stdout, /turn check passed/);+});+test("preserves a valid native orbit sweep and its planted control", async () => {+ const result = await run(["--order", "--step", "360"]);+ assert.equal(result.code, 0); assert.match(result.stdout, /order: 1 states/);+ assert.match(result.stdout, /order control.*fails as it should/); assert.match(result.stdout, /turn check passed/);+});++test("preserves a nonempty explicit pose list and its planted control", async () => {+ const directory = await mkdtemp(join(tmpdir(), "anatomy-orbit-states-"));+ try {+ const file = join(directory, "states.json"); await writeFile(file, "[0,90]");+ const result = await run(["--order", "--states", file]);+ assert.equal(result.code, 0); assert.match(result.stdout, /order: 2 states/);+ assert.match(result.stdout, /order control.*fails as it should/); assert.match(result.stdout, /turn check passed/);+ } finally { await rm(directory, { recursive: true, force: true }); }+});diff --git a/scripts/turn-check.mjs b/scripts/turn-check.mjsindex 6dc3bdc..ad8f6e6 100644--- a/scripts/turn-check.mjs+++ b/scripts/turn-check.mjs@@ -505,9 +505,13 @@ async function main() {}const options = { width: Number(value("--width", 1440)), height: Number(value("--height", 1100)), scale: Number(value("--scale", argv.includes("--perf") ? (Number(value("--width", 1440)) < 600 ? 3 : 2) : 1)), throttle: Number(value("--throttle", 1)), noWebgl: argv.includes("--no-webgl") };const step = Number(value("--step", 1));+ if (!Number.isFinite(step) || step <= 0 || step > 360) throw new Error("--step must be a finite number greater than 0 and at most 360 degrees");+ const fine = Number(value("--fine", 0.1));+ if (argv.includes("--pops") && (!Number.isFinite(fine) || fine <= 0 || fine > 180)) throw new Error("--fine must be a finite number greater than 0 and at most 180 degrees");const out = value("--out", null);const statesFile = value("--states", null);const states = statesFile ? JSON.parse(readFileSync(statesFile, "utf8")) : null;+ if (statesFile && (!Array.isArray(states) || !states.length)) throw new Error("--states must contain a nonempty JSON list of poses");const page = await browser(target, options);const labelOf = (state, index) => (typeof state === "number" ? `${state.toFixed(3)}°` : `state ${index}`);try {@@ -576,7 +580,6 @@ async function main() {if (!states) {let cores = 0;const small = [];- const fine = Number(value("--fine", 0.1));for (let x = 0; x + 2 * fine <= 360 + 1e-9; x += fine) {const r = await page.evaluate(`window.__tc.pops.second(${x.toFixed(4)}, ${(x + fine).toFixed(4)}, ${(x + 2 * fine).toFixed(4)})`);if (r.n >= 6) {