Lines 1-36javascript
3 * cli-selftest.js — guards the TOOL CONTRACTS of the kit's Node entry points.
5 * selftest.js guards what the diff *measures*; this guards how the tools *behave at their
6 * edges* — the Claude Code tool-contract properties: validate input, bound output, fail
7 * loudly with a self-describing, actionable message (never a raw stack), and use stable
8 * exit codes. Each assertion here is a bug we fixed; this file keeps it fixed.
10 * Runs against the real pixel-diff CLI (child process) and the pure, exported guards of
11 * serve.js / sink.js (no sockets). Exit 0 = green.
14const fs = require("fs");
15const os = require("os");
16const path = require("path");
17const cp = require("child_process");
18
HighChild Process
Package source references child process execution.
tools/cli-selftest.jsView on unpkg · L16 19const PD = path.join(__dirname, "pixel-diff.js");
20const { resolvePath } = require("../harness/serve.js");
HighCross File Remote Execution Context
Source spawns a local helper that also contains network and dynamic execution context; review data flow before blocking.
tools/cli-selftest.jsView on unpkg · L7 21const { classifyBody, sanitizeName } = require("./sink.js");
24const ok = (cond, msg) => { if (cond) console.log(` ✓ ${msg}`); else { failed++; console.log(` ✗ ${msg}`); } };
26// scratch dir in the OS temp area (hermetic)
27const dir = fs.mkdtempSync(path.join(os.tmpdir(), "pingfusi-cli-"));
28process.on("exit", () => { try { fs.rmSync(dir, { recursive: true, force: true }); } catch (e) {} });
29const w = (f, s) => { const p = path.join(dir, f); fs.writeFileSync(p, s); return p; };
30const snap = JSON.stringify({ viewport: { width: 1728 }, elements: { logo: { present: true, rect: { x: 0, y: 0, w: 10, h: 10, top: 0, right: 10, bottom: 10, fromRight: 0 } } } });
31const run = (args) => { const r = cp.spawnSync(process.execPath, [PD, ...args], { encoding: "utf8" }); return { code: r.status, out: (r.stdout || "") + (r.stderr || "") }; };
33const a = w("a.json", snap), b = w("b.json", snap);
35console.log("cli-selftest — tool contracts (validate input, self-describing errors, exit codes)");