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): await asynchronous until conditions
aakash-kharb4522a81c9c7d
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 89ba272..921a84e 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -13,6 +13,8 @@ All notable changes to Anatomy are recorded here. The format follows [Keep a Cha### Fixed+- Await asynchronous `until` conditions without treating the promise itself as success, while enforcing the wait deadline.+- Preserve configured pipe clearances in broad-phase solid and pipe sampling.- Observe replacement and late-mounted DOM targets through useInView.- Check texture line attachments against rounded rectangle corners, including separate radii, SVG clamping and transformed outlines.diff --git a/scripts/drive-async-until.test.mjs b/scripts/drive-async-until.test.mjsnew file mode 100644index 0000000..932513b--- /dev/null+++ b/scripts/drive-async-until.test.mjs@@ -0,0 +1,53 @@+import assert from "node:assert/strict";+import { execFile } from "node:child_process";+import { mkdtemp, rm, writeFile, access } 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);+async function run(actions, script = "") {+ const directory = await mkdtemp(join(tmpdir(), "anatomy-driver-regression-"));+ try {+ const page = join(directory, "figure.html");+ const file = join(directory, "actions.json");+ const output = join(directory, "orbit.png");+ await writeFile(page, `<!doctype html><div class="iso-plate" style="width:240px;height:120px"><span data-readout>rest</span></div><script>${script}</script>`);+ await writeFile(file, JSON.stringify(typeof actions === "function" ? actions(output) : actions));+ let result;+ try { result = { code: 0, ...await execute(process.execPath, ["scripts/drive.mjs", page, "--actions", file], { timeout: 15000 }) }; }+ catch (error) { result = { code: error.code, stdout: error.stdout, stderr: error.stderr }; }+ result.hasImage = await access(output).then(() => true, () => false);+ console.log(JSON.stringify(result));+ return result;+ } finally { await rm(directory, { recursive: true, force: true }); }+}++for (const expression of ["false", "Promise.resolve(false)", "new Promise(()=>{})"])+ test(`until times out and stops after ${expression}`, async () => {+ const result = await run([["until", expression, 100], ["eval", "'AFTER_FAILED_WAIT'"]]);+ assert.equal(result.code, 1);+ assert.match(result.stderr, /until: timed out/);+ assert.doesNotMatch(result.stdout, /AFTER_FAILED_WAIT/);+ });++test("until awaits a delayed asynchronous condition", async () => {+ const result = await run([["until", "new Promise(resolve=>setTimeout(()=>{window.ready=true;resolve(true)},100))", 1000], ["eval", "window.ready"]]);+ assert.equal(result.code, 0);+ assert.match(result.stdout, /eval: true/);+});++test("until propagates a rejected asynchronous condition", async () => {+ const result = await run([["until", "Promise.reject(new Error('async condition failed'))", 1000], ["eval", "'AFTER_REJECTION'"]]);+ assert.equal(result.code, 1);+ assert.match(result.stderr, /async condition failed/);+ assert.doesNotMatch(result.stdout, /AFTER_REJECTION/);+});++for (const expression of ["true", "({ready:true})", "(()=>{})", "Promise.resolve({ready:true})"])+ test(`until preserves truthiness of ${expression}`, async () => {+ const result = await run([["until", expression, 1000], ["eval", "'AFTER_SUCCESS'"]]);+ assert.equal(result.code, 0);+ assert.match(result.stdout, /AFTER_SUCCESS/);+ });diff --git a/scripts/drive.mjs b/scripts/drive.mjsindex e8d60af..872c625 100644--- a/scripts/drive.mjs+++ b/scripts/drive.mjs@@ -234,10 +234,16 @@ async function main() {const limit = Date.now() + (args[1] ?? 10000);let ok = false;while (Date.now() < limit) {- if (await evaluate(`Boolean(${args[0]})`)) {- ok = true;- break;+ let timer;+ try {+ ok = await Promise.race([+ evaluate(`Promise.resolve(${args[0]}).then(Boolean)`),+ new Promise((done) => { timer = setTimeout(() => done(false), Math.max(0, limit - Date.now())); }),+ ]);+ } finally {+ clearTimeout(timer);}+ if (ok) break;await sleep(25);}if (!ok) throw new Error(`until: timed out waiting for ${args[0]}`);