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.

drive.mjs: time until conditions inside the page, so a true condition never loses to the round trip

R.6c22cdeda89b
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 75242ae..890127b 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` `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.
- Resolve the current React readout target on every write so replaced readouts and anchors do not leave updates on detached elements.
- Reject drive `turn` and `orbit` actions when the page has no callable 3D turn controller, instead of reporting an unchanged figure as a successful turn.
diff --git a/scripts/drive.mjs b/scripts/drive.mjs
index deb1b69..5e702dc 100644
--- a/scripts/drive.mjs
+++ b/scripts/drive.mjs
@@ -236,15 +236,7 @@ async function main() {
const limit = Date.now() + (args[1] ?? 10000);
let ok = false;
while (Date.now() < limit) {
- 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);
- }
+ ok = await evaluate(`Promise.race([Promise.resolve(${args[0]}).then(Boolean), new Promise((done) => setTimeout(() => done(false), ${Math.max(0, limit - Date.now())}))])`);
if (ok) break;
await sleep(25);
}
diff --git a/scripts/drive.test.mjs b/scripts/drive.test.mjs
index 101a656..676094c 100644
--- a/scripts/drive.test.mjs
+++ b/scripts/drive.test.mjs
@@ -65,6 +65,20 @@ test("drive reports an assertion thrown while waiting for a condition", async ()
assert.match(result.stderr, /until assertion failed/);
});
+test("drive accepts a condition that is already true however short the wait", async () => {
+ 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([["until", "true", 1], ["until", "Promise.resolve(1)", 1]]));
+ const result = await execute(process.execPath, [fileURLToPath(new URL("drive.mjs", import.meta.url)), page, "--actions", actions], { timeout: 30000 });
+ assert.match(result.stdout, /console: clean/);
+ } finally {
+ await rm(directory, { recursive: true, force: true });
+ }
+});
+
test("drive preserves a successful wait condition", async () => {
const result = await drive("document.querySelector('.iso-plate') !== null", "until");
assert.equal(result.code, 0);