mirror of
https://github.com/pbakaus/impeccable.git
synced 2026-09-17 08:36:25 +03:00
The engine no longer lives in a separate repo. `crates/` is a snapshot of the
open crates (foundation, core, common, context, live, hook, skills, comp,
comp-verbs, html, browser, detect, cli) plus `Cargo.lock`, taken as a git
archive of the engine repo at the commit that finished the boundary split.
None of that repo's history comes with it, and none of it should: the closed
half stays private.
The closed half is the rule engine. It ships as a prebuilt native archive per
target, `libimpeccable_detector.a`, published as a `detector-v<X>` GitHub
Release on this repo. `crates/core/build.rs` resolves and links it three ways:
`IMPECCABLE_DETECTOR_LIB=<dir>` for a local detector build, else the
`~/.impeccable/detector/<version>/<target>/` cache, else a download verified
against its `.sha256` sidecar. `crates/core` is a thin shim over a three-symbol
C ABI; nothing above it knows the boundary exists.
What changed versus the engine repo copy:
- Every crate manifest moves from `license-file.workspace` to
`license.workspace` (this workspace declares Apache-2.0), and the workspace
gains the `postcard` dependency the boundary encoding needs.
- The launcher contract test reads `skill/scripts/impeccable{,.cmd}` instead of
a sibling `launcher/` dir, and `engine_binary` downloads from
`github.com/pbakaus/impeccable/releases/download/engine-v<version>/` instead
of the retired dist repo. No oracle golden carried the old URL, so no
re-recording was owed.
- The tests that hunted for a public repo through `IMPECCABLE_PUBLIC_REPO`,
`../impeccable-second` or a hardcoded home directory now resolve the root as
`CARGO_MANIFEST_DIR/../..`, because they are in it. The env var stays as an
override for an out-of-tree checkout.
- The in-page bundle (`detect-antipatterns-browser.js`, 2 MB of generated wasm
glue) is no longer tracked. `crates/core/build.rs` resolves it beside the
archive, hands the path to `impeccable_core::browser::IN_PAGE_BUNDLE_JS`, and
live mode serves that. `scripts/check-detector-release.mjs` now requires it
and its `.sha256` in a detector release.
- The live crate embeds `skill/scripts/live-browser*.js` and
`modern-screenshot.umd.js` directly rather than through vendored copies, so
the binary and the installed skill cannot drift.
- `crates/browser/assets/` (an unused second copy of the bundle) is gone.
- `tests/lib/engine-bin.mjs` also accepts `target/release/impeccable`, so a
plain `cargo build --release -p impeccable` is enough to run `bun run test`.
Verified with the archive from a local detector build: `cargo test --workspace`
267 pass, oracle 795 pass / 0 fail / 0 missing, `bun run build` clean, the
default suite green, and the launcher's `engine-probe` handshake answering
through `skill/scripts/impeccable`.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vau2X53xGTjjTCXWMVBoNY
99 lines
4.1 KiB
Rust
99 lines
4.1 KiB
Rust
//! Parity checks for the deterministic (non-browser) comp-verb logic. The
|
|
//! expected numbers were produced by the original JS scripts (run from git
|
|
//! history) against the same `crates/comp/tests/fixtures` PNGs and confirmed
|
|
//! byte-identical to this port's output during the Node-free swap.
|
|
|
|
use std::path::PathBuf;
|
|
|
|
use impeccable_comp::png_io;
|
|
use impeccable_comp::raster::Image;
|
|
use impeccable_comp_verbs::comp_diff;
|
|
use impeccable_comp_verbs::comp_spec;
|
|
use serde_json::{json, Value};
|
|
|
|
fn fixtures() -> PathBuf {
|
|
// comp-verbs shares the comp crate's fixtures.
|
|
PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("../comp/tests/fixtures")
|
|
}
|
|
|
|
fn load(name: &str) -> Image {
|
|
let buf = std::fs::read(fixtures().join(name)).unwrap();
|
|
png_io::decode_png(&buf).unwrap().image
|
|
}
|
|
|
|
#[test]
|
|
fn comp_diff_scores_match_js() {
|
|
// JS: comp-diff.mjs --comp comp.png --build build_flat.png (no spec).
|
|
let comp = load("comp.png");
|
|
let build = load("build_flat.png");
|
|
let res = comp_diff::compare(&comp, &build, None, "top", "", None);
|
|
let w = &res.whole;
|
|
assert_eq!(w.overall, 0.8374, "overall");
|
|
assert_eq!(w.structure, 0.9846, "structure");
|
|
assert_eq!(w.color, 0.8306, "color");
|
|
assert_eq!(w.detail, 0.5407, "detail");
|
|
assert_eq!(comp_diff::verdict_for(w, None), "match");
|
|
}
|
|
|
|
#[test]
|
|
fn grid_to_box_matches_js() {
|
|
// JS: gridToBox on a 10x10 grid.
|
|
assert_eq!(comp_spec::grid_to_box("E2:J4").unwrap(), (0.4, 0.2, 0.6, 0.3));
|
|
assert_eq!(comp_spec::grid_to_box("A0:J0").unwrap(), (0.0, 0.0, 1.0, 0.1));
|
|
assert_eq!(comp_spec::grid_to_box("a0:a0").unwrap(), (0.0, 0.0, 0.1, 0.1));
|
|
// reversed spans normalize the same way
|
|
assert_eq!(comp_spec::grid_to_box("J4:E2").unwrap(), (0.4, 0.2, 0.6, 0.3));
|
|
assert!(comp_spec::grid_to_box("Z9:A0").is_err());
|
|
assert!(comp_spec::grid_to_box("E2-J4").is_err());
|
|
}
|
|
|
|
#[test]
|
|
fn measure_regions_shape_matches_js() {
|
|
// A raster region gets a plate path + raster medium; a text region snaps
|
|
// to ink and is measured semantic. `allowUncovered` lets the busy comp pass.
|
|
let comp = load("comp.png");
|
|
let input: Value = json!({
|
|
"allowUncovered": true,
|
|
"regions": [
|
|
{ "id": "art", "kind": "plate", "grid": "E2:J4", "note": "an exploded illustration drawing" },
|
|
{ "id": "body", "kind": "text", "grid": "A5:D8", "note": "a paragraph of body text content" }
|
|
]
|
|
});
|
|
let spec = comp_spec::measure_regions(&comp, &input, "comp.png").unwrap();
|
|
let regions = spec.get("regions").and_then(Value::as_array).unwrap();
|
|
assert_eq!(regions.len(), 2);
|
|
let art = ®ions[0];
|
|
assert_eq!(art.get("medium").and_then(Value::as_str), Some("raster"));
|
|
assert_eq!(art.get("plate").and_then(Value::as_str), Some("assets/plates/art.png"));
|
|
let body = ®ions[1];
|
|
assert_eq!(body.get("medium").and_then(Value::as_str), Some("semantic"));
|
|
assert!(body.get("plate").unwrap().is_null());
|
|
// spec-level fields
|
|
assert_eq!(spec.get("tool").and_then(Value::as_str), Some("comp-spec"));
|
|
assert_eq!(spec.pointer("/compSize/width").and_then(Value::as_i64), Some(comp.width as i64));
|
|
}
|
|
|
|
#[test]
|
|
fn measure_regions_refuses_painted_note_under_code_kind() {
|
|
// JS: a text/control/chrome region whose note names painted material is
|
|
// refused at the spec unless codeDrawn is set.
|
|
let comp = load("comp.png");
|
|
let input: Value = json!({
|
|
"allowUncovered": true,
|
|
"regions": [ { "id": "x", "kind": "chrome", "grid": "A0:B1", "note": "an exploded diagram illustration" } ]
|
|
});
|
|
let err = comp_spec::measure_regions(&comp, &input, "comp.png").unwrap_err();
|
|
assert!(err.contains("describes painted material"), "got: {err}");
|
|
}
|
|
|
|
#[test]
|
|
fn measure_regions_refuses_oversized_code_region() {
|
|
let comp = load("comp.png");
|
|
let input: Value = json!({
|
|
"allowUncovered": true,
|
|
"regions": [ { "id": "col", "kind": "chrome", "grid": "A0:J9", "note": "a big column of things" } ]
|
|
});
|
|
let err = comp_spec::measure_regions(&comp, &input, "comp.png").unwrap_err();
|
|
assert!(err.contains("covers 100% of the comp") || err.contains("% of the comp"), "got: {err}");
|
|
}
|