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(capture): reject option values it cannot use
Rudy Celeklicccecd5fb943
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 8c9e657..0dead4a 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+- `capture.mjs` rejects option values it cannot use (`--zoom` without four numbers, `--hover` without two, a non-numeric `--width`, `--scale`, `--wait` or `--times`, a `--theme` other than dark or light) before Chrome starts, instead of saving a shot as if they had been honoured.- `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/capture.mjs b/scripts/capture.mjsindex 287eb47..644283c 100644--- a/scripts/capture.mjs+++ b/scripts/capture.mjs@@ -62,6 +62,17 @@ function parse(argv) {return options;}+function problemWith(options) {+ const positive = (value) => Number.isFinite(value) && value > 0;+ const numbers = (list, count) => list.length === count && list.every(Number.isFinite);+ for (const name of ["width", "height", "scale", "zoomScale"]) if (!positive(options[name])) return `--${name === "zoomScale" ? "zoom-scale" : name} needs a number above 0`;+ if (!Number.isFinite(options.wait) || options.wait < 0) return "--wait needs a number of milliseconds, 0 or more";+ if (options.zoom && !(numbers(options.zoom, 4) && options.zoom[2] > 0 && options.zoom[3] > 0)) return "--zoom needs x,y,w,h in CSS px, with a width and height above 0";+ if (options.hover && !numbers(options.hover, 2)) return "--hover needs fx,fy, two fractions like 0.6,0.5";+ if (!options.times.every((delay) => Number.isFinite(delay) && delay >= 0)) return "--times needs milliseconds, 0 or more, comma separated";+ if (options.theme !== undefined && options.theme !== "dark" && options.theme !== "light") return "--theme must be dark or light";+}+function chromePath() {const candidates = [process.env.CHROME_PATH,@@ -93,6 +104,11 @@ async function main() {usage();process.exit(options.help ? 0 : 1);}+ const problem = problemWith(options);+ if (problem) {+ console.error(`capture: ${problem}`);+ process.exit(1);+ }const url = /^https?:|^file:/.test(options.target) ? options.target : pathToFileURL(resolve(options.target)).href;const out = resolve(options.out ?? "capture.png");const binary = chromePath();diff --git a/scripts/capture.test.mjs b/scripts/capture.test.mjsindex f489748..fc92ca8 100644--- a/scripts/capture.test.mjs+++ b/scripts/capture.test.mjs@@ -40,3 +40,21 @@ test("capture retains existing-directory output", async () => {await rm(directory, { recursive: true, force: true });}});++test("capture rejects option values that would be ignored or break the clip", async () => {+ const directory = await mkdtemp(join(tmpdir(), "anatomy-capture-"));+ try {+ const page = join(directory, "figure.html");+ const output = join(directory, "figure.png");+ await writeFile(page, '<!doctype html><div class="iso-plate">Figure</div>');+ const cases = [["--zoom", "1,2", /--zoom needs x,y,w,h/], ["--zoom", "1,2,0,5", /--zoom needs x,y,w,h/], ["--hover", "0.5", /--hover needs fx,fy/], ["--times", "fast", /--times needs milliseconds/], ["--width", "wide", /--width needs a number above 0/], ["--scale", "0", /--scale needs a number above 0/], ["--wait", "abc", /--wait needs a number/], ["--theme", "sepia", /--theme must be dark or light/]];+ for (const [flag, value, message] of cases) {+ const error = await execute(process.execPath, [capture, page, "--out", output, flag, value], { timeout: 30000 }).then(() => null, (failure) => failure);+ assert.equal(error?.code, 1, `${flag} ${value}`);+ assert.match(error.stderr, message);+ }+ await assert.rejects(readFile(output));+ } finally {+ await rm(directory, { recursive: true, force: true });+ }+});