mirror of
https://github.com/pbakaus/impeccable.git
synced 2026-09-13 06:36:26 +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
94 lines
3.4 KiB
Rust
94 lines
3.4 KiB
Rust
//! The engine must never panic on any input: truncated fixtures, garbage,
|
|
//! and pathological nesting.
|
|
|
|
use impeccable_html::{detect_html_source, DetectHtmlOptions};
|
|
use std::path::{Path, PathBuf};
|
|
|
|
/// The repo root: this workspace is the public repo. `IMPECCABLE_PUBLIC_REPO`
|
|
/// overrides it for an out-of-tree checkout.
|
|
fn repo_root() -> PathBuf {
|
|
if let Ok(p) = std::env::var("IMPECCABLE_PUBLIC_REPO") {
|
|
return PathBuf::from(p);
|
|
}
|
|
Path::new(env!("CARGO_MANIFEST_DIR")).join("../..")
|
|
}
|
|
|
|
fn fixtures() -> Option<PathBuf> {
|
|
let p = repo_root().join("tests/fixtures/antipatterns");
|
|
p.is_dir().then_some(p)
|
|
}
|
|
|
|
fn scan(html: &str) -> usize {
|
|
let opts = DetectHtmlOptions::default();
|
|
detect_html_source(html, Path::new("/nonexistent/dir/x.html"), &opts).len()
|
|
}
|
|
|
|
#[test]
|
|
fn truncated_fixtures_do_not_panic() {
|
|
let Some(dir) = fixtures() else {
|
|
eprintln!("fixtures not found; skipping");
|
|
return;
|
|
};
|
|
let mut files: Vec<PathBuf> = std::fs::read_dir(&dir)
|
|
.unwrap()
|
|
.filter_map(|e| e.ok().map(|e| e.path()))
|
|
.filter(|p| p.extension().is_some_and(|e| e == "html"))
|
|
.collect();
|
|
files.sort();
|
|
for f in files.iter().take(12) {
|
|
let src = String::from_utf8_lossy(&std::fs::read(f).unwrap()).into_owned();
|
|
let n = src.len();
|
|
let mut cut = 0usize;
|
|
while cut < n {
|
|
let mut end = cut;
|
|
while end < n && !src.is_char_boundary(end) {
|
|
end += 1;
|
|
}
|
|
let _ = scan(&src[..end]);
|
|
cut += (n / 23).max(7);
|
|
}
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn garbage_and_edge_inputs_do_not_panic() {
|
|
let cases = [
|
|
"",
|
|
"<",
|
|
"<!DOCTYPE html>",
|
|
"<html",
|
|
"<style>",
|
|
"<style>a{color:</style>",
|
|
"<style>:root{--a:var(--a)} p{color:var(--a)}</style><p>x</p>",
|
|
"<div style=\"color\">x</div>",
|
|
"<div style=\"background: ; border: 5px solid; font-size: em\">text longer than twenty chars</div>",
|
|
"<template><p>t</p></template><table><tr><td>a</td></table>",
|
|
"<link rel=stylesheet href=''><link rel=stylesheet href='?x'><link rel=stylesheet href='//cdn/x.css'>",
|
|
"<p>\u{FEFF}\u{2028}\u{200B}\u{1F600}</p><h1 style='letter-spacing:-1em'>\u{1F600}\u{1F600}\u{1F600}\u{1F600}\u{1F600}\u{1F600}\u{1F600}\u{1F600}\u{1F600}\u{1F600}\u{1F600}</h1>",
|
|
"<html><body data-impeccable-ignore><h1>x</h1><h3>y</h3></body></html>",
|
|
"<svg><linearGradient id='g'></linearGradient><foreignObject><div>hi there</div></foreignObject></svg>",
|
|
"<style>a::before{content:'';width:20px;height:2px;background:#f00} .x:hover{color:red} .y:focus{color:blue} @media(min-width:1px){.z{color:red}} @keyframes k{from{color:red}}</style><a>l</a>",
|
|
"<img><img src=''><img src='#'>",
|
|
];
|
|
for c in cases {
|
|
let _ = scan(c);
|
|
}
|
|
let deep = format!(
|
|
"<html><body>{}{}</body></html>",
|
|
"<div style='padding:1px'>".repeat(800),
|
|
"</div>".repeat(800)
|
|
);
|
|
let _ = scan(&deep);
|
|
let wide = format!(
|
|
"<html><body>{}</body></html>",
|
|
"<p style='color:#777'>text of some length here</p>".repeat(1000)
|
|
);
|
|
let _ = scan(&wide);
|
|
let noise: String = (0..4000u32)
|
|
.map(|i| char::from_u32(0x20 + (i * 7919) % 0x2fff).unwrap_or(' '))
|
|
.collect();
|
|
let _ = scan(&format!(
|
|
"<html><body><p>{noise}</p><style>{noise}</style></body></html>"
|
|
));
|
|
}
|