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(turning): reject missing or ambiguous group names
Rudy Celekli35de93f9c1e4
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.ymlindex bf7b18d..60fef83 100644--- a/.github/workflows/ci.yml+++ b/.github/workflows/ci.yml@@ -25,6 +25,9 @@ jobs:with:node-version: 22+ - name: Group reference regressions+ run: node --test scripts/turn-group-reference.test.mjs+- name: Dial indicatorrun: |node examples/dial-indicator/build.mjsdiff --git a/CHANGELOG.md b/CHANGELOG.mdindex 8152ae2..250f863 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+- Turning builders now reject missing named part/parent groups and duplicate group names before authored motions silently become static or alias one value.+- `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/kit/turn-build.mjs b/kit/turn-build.mjsindex b92c8cd..90afa88 100644--- a/kit/turn-build.mjs+++ b/kit/turn-build.mjs@@ -293,11 +293,18 @@ function thinCloud(points, most = 64) {export function turning(P, { recorder = null, scale = 1 } = {}) {const T = { P, R: recorder, scale, groups: [], layers: [], order: [], parts: [], built: null };- const groupOf = (g) => (g === undefined || g === null ? null : typeof g === "string" ? T.groups.find((x) => x.name === g) : g);+ const groupOf = (g) => {+ if (g === undefined || g === null) return null;+ if (typeof g !== "string") return g;+ const group = T.groups.find((x) => x.name === g);+ if (!group) throw new Error(`turning: unknown group ${g}`);+ return group;+ };const layerOf = (l) => (typeof l === "string" ? T.layers.find((x) => x.name === l) : l);const origin = (group) => (group ? group.origin : [0, 0, 0]);const local = (group, p) => sub3(p, origin(group));T.group = (name, options = {}) => {+ if (T.groups.some((group) => group.name === name)) throw new Error(`turning: duplicate group ${name}`);const parent = groupOf(options.parent);const po = origin(parent);let kind;diff --git a/scripts/turn-group-reference.test.mjs b/scripts/turn-group-reference.test.mjsnew file mode 100644index 0000000..4f3ca63--- /dev/null+++ b/scripts/turn-group-reference.test.mjs@@ -0,0 +1,40 @@+import assert from "node:assert/strict";+import test from "node:test";+import { turning } from "../kit/turn-build.mjs";+import { identity } from "./turn-fidelity.mjs";+const P = { origin: [0, 0], scale: 1, azimuth: 45, elevation: 30 };+const fixture = () => { const T = turning(P); T.layer("parts"); return T; };+const prism = (T, group) => T.prism({ name: "pointer", group, plan: { x: 0, y: 0, w: 4, d: 2, r: 0 }, z: 0, h: 1 });+test("missing named part groups cannot silently pass as static geometry", () => {+ const T = fixture(); T.group("dial", { turn: {} });+ assert.throws(() => { prism(T, "dail"); T.build(); identity(T, P, [0, 90]); }, /turning: unknown group dail/);+ assert.equal(T.parts.length, 0);+});+test("missing named parent groups cannot silently root nested motion", () => {+ const T = fixture(); T.group("dial", { turn: {} });+ assert.throws(() => T.group("slide", { parent: "dail", slide: { direction: [1, 0, 0], travel: 5 } }), /turning: unknown group dail/);+ assert.equal(T.groups.length, 1);+});+test("duplicate group names cannot alias incompatible motion values", () => {+ const T = fixture(); T.group("dial", { turn: {} });+ assert.throws(() => T.group("dial", { slide: { direction: [1, 0, 0], travel: 5 } }), /turning: duplicate group dial/);+ assert.equal(T.groups.length, 1);+});+test("existing named and object group references retain native fidelity", () => {+ for (const named of [false, true]) {+ const T = fixture(); const group = T.group("dial", { turn: {} });+ const part = prism(T, named ? "dial" : group);+ const child = T.group("slide", { parent: named ? "dial" : group, slide: { direction: [1, 0, 0], travel: 5 } });+ assert.equal(part.group, group); assert.equal(child.parent, group);+ T.build(); const result = identity(T, P, [0, 90]);+ assert.equal(result.pass, true);+ assert.match(result.text, /over [1-9]\d* faces/);+ }+});+test("omitted and explicit null groups keep supported static geometry", () => {+ for (const group of [undefined, null]) {+ const T = fixture(); const part = prism(T, group);+ assert.equal(part.group, null);+ T.build(); assert.equal(T.parts.length, 1);+ }+});