PdfCraft: An open-source PDF reader and editor written by scratch in pure Rust
feat(oracle): make a missing external oracle loud instead of a silent pass
Tanish Manku0754740fd9c9
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.ymlindex 8249dcf0c..5ac7bdeaf 100644--- a/.github/workflows/ci.yml+++ b/.github/workflows/ci.yml@@ -48,13 +48,22 @@ jobs:echo "CRAFT_FONTS_DIR=$GITHUB_WORKSPACE/craft-fonts" >> "$GITHUB_ENV"echo "CRAFT_FONTS_REQUIRED=1" >> "$GITHUB_ENV"- - name: Install Linux system dependencies (egui/winit/rfd)+ - name: Install Linux system dependencies (egui/winit/rfd) and the oraclesif: runner.os == 'Linux'run: |sudo apt-get updatesudo apt-get install -y --no-install-recommends \libxkbcommon-dev libwayland-dev libx11-dev libxrandr-dev libxi-dev \- libgl1-mesa-dev libgtk-3-dev+ libgl1-mesa-dev libgtk-3-dev \+ qpdf++ # The independent oracles (crates/oracle) are only worth having when they run. With this+ # set, a missing one fails the job instead of printing a skip notice that reads as a pass.+ # Only the tools the job actually uses are installed above; a test that needs another one+ # (Poppler, for the pixel comparison in crates/organize) stays `#[ignore]`d until then.+ - name: Require the oracles (Linux)+ if: runner.os == 'Linux'+ run: echo "PDFCRAFT_ORACLES_REQUIRED=1" >> "$GITHUB_ENV"- uses: dtolnay/rust-toolchain@686976e191b89faba57d3206551f0f330d8cb249 # stablewith:diff --git a/Cargo.lock b/Cargo.lockindex f2acd78dc..2984a688f 100644--- a/Cargo.lock+++ b/Cargo.lock@@ -3983,6 +3983,7 @@ dependencies = ["hayro-syntax","pdfcraft-crypt","pdfcraft-filters",+ "pdfcraft-oracle","proptest","serde_json","thiserror 2.0.21",@@ -4160,6 +4161,10 @@ dependencies = ["thiserror 2.0.21",]+[[package]]+name = "pdfcraft-oracle"+version = "0.8.0"+[[package]]name = "pdfcraft-organize"version = "0.8.0"@@ -4167,6 +4172,7 @@ dependencies = ["hayro-syntax","pdfcraft-content","pdfcraft-cos",+ "pdfcraft-oracle","thiserror 2.0.21",]@@ -7946,6 +7952,7 @@ version = "0.1.0"dependencies = ["anyhow","lopdf",+ "pdfcraft-oracle","png 0.18.1","serde","serde_json",diff --git a/Cargo.toml b/Cargo.tomlindex 87422986d..6940b9acb 100644--- a/Cargo.toml+++ b/Cargo.toml@@ -34,6 +34,7 @@ pdfcraft-xfdf = { path = "crates/xfdf", version = "0.8.0" }pdfcraft-sign = { path = "crates/sign", version = "0.8.0" }pdfcraft-optimize = { path = "crates/optimize", version = "0.8.0" }pdfcraft-a11y = { path = "crates/a11y", version = "0.8.0" }+pdfcraft-oracle = { path = "crates/oracle", version = "0.8.0" }pdfcraft-ocr = { path = "crates/ocr", version = "0.8.0" }pdfcraft-js = { path = "crates/js", version = "0.8.0" }pdfcraft-compare = { path = "crates/compare", version = "0.8.0" }diff --git a/README.md b/README.mdindex b20179fff..86f7d7643 100644--- a/README.md+++ b/README.md@@ -172,7 +172,7 @@ Open **Organize pages** to see every page at once:**Saves you can trust:**- *Incremental:* the original bytes stay byte-for-byte intact.- *Atomic:* the file is written to a temporary copy, then swapped in.-- *Verified:* independently checked with qpdf.+- *Verified:* independently checked with qpdf, on every CI run.When open documents exceed the window width, scroll over the tab strip with the mouse wheel or trackpad, or use its horizontal scrollbar. Opening or switching to a document brings its tab into view.@@ -365,7 +365,8 @@ On top of those, two corpus sweeps run over real-world files:- **Opening and rendering:** of the 983 pdf.js test files, 963 open and render cleanly, with 0 crashes.- **Open, edit and save round trips:** 958 succeed.-The output is verified with independent tools: hayro, qpdf and poppler.+The output is verified against independent implementations: hayro and qpdf on every CI run, and+poppler over the corpus on demand (`cargo xtask text-oracle`).PdfCraft is a clean-room implementation. Its behaviour comes from the ISO 32000 specification and black-box observation, never from anyone else's code. Every icon, font and image is openly licensed and listed in [ATTRIBUTION.md](ATTRIBUTION.md).diff --git a/crates/cos/Cargo.toml b/crates/cos/Cargo.tomlindex f02f63c52..1be1561e6 100644--- a/crates/cos/Cargo.toml+++ b/crates/cos/Cargo.toml@@ -14,6 +14,7 @@ pdfcraft-filters = { workspace = true }thiserror = { workspace = true }[dev-dependencies]+pdfcraft-oracle = { workspace = true }serde_json = { workspace = true }proptest = { workspace = true }hayro-syntax = { workspace = true }diff --git a/crates/cos/tests/encryption.rs b/crates/cos/tests/encryption.rsindex 6868a6dc2..cf519df67 100644--- a/crates/cos/tests/encryption.rs+++ b/crates/cos/tests/encryption.rs@@ -202,24 +202,23 @@ fn unencrypted_metadata_is_left_readable() {let _ = ObjRef::new(1, 0);}-/// Second independent oracle when qpdf is installed: it must accept both passwords, identify-/// the owner password, and find no structural errors.+/// The second independent oracle: qpdf must accept both passwords, identify the owner password,+/// and find no structural errors. For R2-R4 this is the *only* check of owner-password+/// authentication (Algorithm 7) that does not go through our own code, so it is the one place a+/// silent skip would cost the most -- see `pdfcraft-oracle`, which makes absence loud.#[test]fn qpdf_agrees() {- if std::process::Command::new("qpdf").arg("--version").output().is_err() {- eprintln!("qpdf not installed; skipping");- return;- }+ let qpdf = pdfcraft_oracle::or_skip!(pdfcraft_oracle::qpdf());let dir = std::env::temp_dir().join(format!("pdfcraft-enc-{}", std::process::id()));std::fs::create_dir_all(&dir).unwrap();for alg in ALL {let path = dir.join(format!("{alg:?}.pdf"));std::fs::write(&path, protect(alg, "user", "owner", -1)).unwrap();for (pw, expect) in [("user", "user password"), ("owner", "owner password")] {- let out = std::process::Command::new("qpdf").arg(format!("--password={pw}")).arg("--show-encryption").arg(&path).output().unwrap();+ let out = qpdf.command().arg(format!("--password={pw}")).arg("--show-encryption").arg(&path).output().unwrap();let text = String::from_utf8_lossy(&out.stdout);assert!(text.contains(&format!("Supplied password is {expect}")), "{alg:?}/{pw}: {text}");- let check = std::process::Command::new("qpdf").arg(format!("--password={pw}")).arg("--check").arg(&path).output().unwrap();+ let check = qpdf.command().arg(format!("--password={pw}")).arg("--check").arg(&path).output().unwrap();assert!(check.status.success(), "{alg:?}/{pw}: {}", String::from_utf8_lossy(&check.stdout));}}diff --git a/crates/cos/tests/writer.rs b/crates/cos/tests/writer.rsindex b7514cc05..87462f467 100644--- a/crates/cos/tests/writer.rs+++ b/crates/cos/tests/writer.rs@@ -159,18 +159,14 @@ fn classic_table() -> Vec<u8> {bytes}-fn qpdf_check(bytes: &[u8]) -> Option<std::process::Output> {- let Ok(version) = std::process::Command::new("qpdf").arg("--version").output() else {- return None;- };- assert!(version.status.success());+fn qpdf_check(qpdf: &pdfcraft_oracle::Oracle, bytes: &[u8]) -> std::process::Output {static NEXT: std::sync::atomic::AtomicU64 = std::sync::atomic::AtomicU64::new(0);let n = NEXT.fetch_add(1, std::sync::atomic::Ordering::Relaxed);let path = std::env::temp_dir().join(format!("pdfcraft-xref-{}-{n}.pdf", std::process::id()));std::fs::write(&path, bytes).unwrap();- let check = std::process::Command::new("qpdf").arg("--check").arg(&path).output().unwrap();+ let check = qpdf.command().arg("--check").arg(&path).output().unwrap();let _ = std::fs::remove_file(&path);- Some(check)+ check}fn page(doc: &Document) -> Dict {@@ -181,10 +177,8 @@ fn page(doc: &Document) -> Dict {}fn assert_qpdf_clean(bytes: &[u8]) {- let Some(check) = qpdf_check(bytes) else {- eprintln!("qpdf not installed: skipped");- return;- };+ let qpdf = pdfcraft_oracle::or_skip!(pdfcraft_oracle::qpdf());+ let check = qpdf_check(&qpdf, bytes);let report = format!("{}{}", String::from_utf8_lossy(&check.stdout), String::from_utf8_lossy(&check.stderr));assert!(check.status.success() && !report.contains("WARNING"), "{report}");}@@ -247,16 +241,12 @@ fn incremental_save_keeps_a_trailer_only_edit() {#[test]fn qpdf_accepts_object_stream_output() {- let Ok(out) = std::process::Command::new("qpdf").arg("--version").output() else {- eprintln!("qpdf not installed: skipped");- return;- };- assert!(out.status.success());+ let qpdf = pdfcraft_oracle::or_skip!(pdfcraft_oracle::qpdf());let doc = Document::open(Arc::new(fixture())).unwrap();let packed = write_full(&doc, &SaveOptions::default()).unwrap();let path = std::env::temp_dir().join(format!("pdfcraft-objstm-{}.pdf", std::process::id()));std::fs::write(&path, &packed).unwrap();- let check = std::process::Command::new("qpdf").arg("--check").arg(&path).output().unwrap();+ let check = qpdf.command().arg("--check").arg(&path).output().unwrap();let _ = std::fs::remove_file(&path);let report = String::from_utf8_lossy(&check.stdout);assert!(check.status.success() && report.contains("No syntax or stream encoding errors"), "{report}");diff --git a/crates/oracle/Cargo.toml b/crates/oracle/Cargo.tomlnew file mode 100644index 000000000..45b27f5d9--- /dev/null+++ b/crates/oracle/Cargo.toml@@ -0,0 +1,11 @@+[package]+name = "pdfcraft-oracle"+description = "External oracle processes PdfCraft checks its own output against, and the rule that a missing one is loud"+version.workspace = true+edition.workspace = true+license.workspace = true++[lints]+workspace = true++[dependencies]diff --git a/crates/oracle/README.md b/crates/oracle/README.mdnew file mode 100644index 000000000..d02f5b5f9--- /dev/null+++ b/crates/oracle/README.md@@ -0,0 +1,70 @@+# pdfcraft-oracle++The external programs PdfCraft checks its own output against, and one rule: **a missing oracle is+either a declared skip or a failure, never a silent pass.**++- **Layer:** test support (`Class::Testkit` in `xtask/src/layers.rs`). A dev-dependency only, never+ compiled into the product, and so usable even from the standalone crates (`cos`, `geom`,+ `filters`, `crypt`, `arlington`) whose own tests need it.+- No panicking path of its own. The `or_skip!` macro expands its `assert!` into the caller, which+ is test code.++## Why it exists++Every test that wanted an oracle used to probe for it by hand and decide on its own what to do when+it was missing. The common choice — print a line and return — reports as a **pass**, so a suite+with no oracles installed looked exactly like one in which every oracle agreed.++That was not hypothetical. No CI runner installed `qpdf`, so `cos/tests/encryption.rs::qpdf_agrees`+had never executed on a runner, while `README.md` said saved output was "independently checked with+qpdf". For R2–R4 that test is the *only* check of owner-password authentication (Algorithm 7) that+does not go through our own code.++## API++```rust+// In a test: bind the oracle, or return after saying why it was skipped.+let qpdf = pdfcraft_oracle::or_skip!(pdfcraft_oracle::qpdf());+let out = qpdf.command().arg("--check").arg(&path).output()?;++// Elsewhere (xtask), handle the absence yourself.+match pdfcraft_oracle::pdftotext() {+ Ok(tool) => { /* tool.command() */ }+ Err(absent) => bail!("{absent}"),+}+```++| Probe | Tool | Used for |+|---|---|---|+| `qpdf()` | qpdf | `--check` structural validation; the independent owner-password oracle |+| `pdftoppm()` | Poppler | page pixels, for comparing against our own raster output |+| `pdftotext()` | Poppler | text extraction (`cargo xtask text-oracle` scores word F1 against it) |++Each returns `Result<Oracle, Absent>`. `Oracle::command()` hands back a fresh `Command`;+`Absent` renders as an actionable sentence naming the install command.++## The gate++`PDFCRAFT_ORACLES_REQUIRED` (any value, including `0` — the same convention as+`CRAFT_FONTS_REQUIRED`) turns absence from a skip into a failure. CI sets it on the runners that+install the tools, so a skip notice there becomes a red build.++```+$ cargo test -p pdfcraft-cos --test encryption qpdf_agrees+test result: ok. 1 passed # qpdf absent: skipped, with a notice on stderr++$ PDFCRAFT_ORACLES_REQUIRED=1 cargo test -p pdfcraft-cos --test encryption qpdf_agrees+oracle `qpdf` is required but is not on PATH (program not found): PDFCRAFT_ORACLES_REQUIRED is+set, so this is a failure rather than a skip (apt install qpdf / brew install qpdf)+test result: FAILED. 1 failed+```++`or_skip!` expands to a `return`, so it belongs in a test returning `()`; a test returning `Result`+should match on the probe directly.++## Still to do++- CI installs only `qpdf`, the one tool the test job uses. The Poppler pixel comparison in+ `crates/organize` stays `#[ignore]`d until a change turns it on and verifies it there.+- Oracles that are not external processes (hayro, `lopdf`) are ordinary dev-dependencies and are+ not routed through this crate.diff --git a/crates/oracle/src/lib.rs b/crates/oracle/src/lib.rsnew file mode 100644index 000000000..440fb6e0f--- /dev/null+++ b/crates/oracle/src/lib.rs@@ -0,0 +1,246 @@+//! External oracle processes: independent implementations PdfCraft checks its own output against.+//!+//! An oracle is only worth having when it runs. Before this crate every test that wanted one+//! probed for it by hand and decided on its own what to do when it was missing, and the common+//! choice — print a line and return — reports as a **pass**. A suite with no oracles installed+//! therefore looked exactly like one in which every oracle agreed, and on this repository's CI,+//! where none of them were installed, that is precisely what was happening: `qpdf` is the only+//! independent check of owner-password authentication for R2–R4, and it had never executed on a+//! runner while `README.md` said the output was "independently checked with qpdf".+//!+//! So the rule here is one line of policy: **a missing oracle is either a declared skip or a+//! failure, never a silent pass.** [`REQUIRED_VAR`] decides which. CI sets it, so absence breaks+//! the build; a contributor's laptop usually does not, so absence prints why and skips.+//!+//! ```no_run+//! # fn main() {+//! let qpdf = pdfcraft_oracle::or_skip!(pdfcraft_oracle::qpdf());+//! let out = qpdf.command().arg("--check").arg("f.pdf").output();+//! # let _ = out;+//! # }+//! ```+//!+//! This crate is test scaffolding (`Class::Testkit` in `xtask/src/layers.rs`): a dev-dependency+//! only, never compiled into the product.++use std::fmt;+use std::process::Command;++/// Setting this environment variable to any value turns a missing oracle from a skip into a+/// failure. CI sets it on the runners that install the tools.+///+/// Any value counts, including `0` — the same convention as `CRAFT_FONTS_REQUIRED`, which this+/// deliberately mirrors. The surprising half of that convention errs toward *requiring* an oracle,+/// which is the safe direction for a gate whose whole purpose is to stop absence passing quietly.+pub const REQUIRED_VAR: &str = "PDFCRAFT_ORACLES_REQUIRED";++/// An external program found on `PATH`, ready to run.+#[derive(Debug, Clone, PartialEq, Eq)]+pub struct Oracle {+ program: &'static str,+ version: String,+}++impl Oracle {+ /// A fresh [`Command`] for the program. Callers add their own arguments.+ pub fn command(&self) -> Command {+ Command::new(self.program)+ }++ /// The program name, as it is looked up on `PATH`.+ pub fn program(&self) -> &'static str {+ self.program+ }++ /// The first line the program printed when asked for its version, for test output. Empty when+ /// it printed nothing recognisable; presence of the binary is what decides availability, not+ /// whether its version could be parsed.+ pub fn version(&self) -> &str {+ &self.version+ }+}++/// An oracle that could not be used, and whether that is fatal.+#[derive(Debug, Clone, PartialEq, Eq)]+pub struct Absent {+ program: &'static str,+ cause: String,+ required: bool,+}++impl Absent {+ /// Whether this absence must fail the run rather than skip it, i.e. whether [`REQUIRED_VAR`]+ /// was set when the probe ran.+ pub fn required(&self) -> bool {+ self.required+ }++ /// The program that was looked for.+ pub fn program(&self) -> &'static str {+ self.program+ }++ /// How to install it, so a skip notice tells the reader what to do about it.+ fn install_hint(program: &str) -> &'static str {+ match program {+ "qpdf" => "apt install qpdf / brew install qpdf",+ "pdftoppm" | "pdftotext" => "apt install poppler-utils / brew install poppler",+ _ => "install it and put it on PATH",+ }+ }+}++impl fmt::Display for Absent {+ /// Reads as an instruction either way: required absences are failures and name the gate that+ /// made them one, optional absences name the install command.+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {+ if self.required {+ write!(+ f,+ "oracle `{}` is required but {}: {} is set, so this is a failure rather than a skip ({})",+ self.program,+ self.cause,+ REQUIRED_VAR,+ Self::install_hint(self.program),+ )+ } else {+ write!(+ f,+ "skipping: oracle `{}` {} ({}); set {} to make this a failure instead",+ self.program,+ self.cause,+ Self::install_hint(self.program),+ REQUIRED_VAR,+ )+ }+ }+}++/// Look for `program` on `PATH`, asking it for its version to confirm it runs.+///+/// Presence is decided by whether the program could be started at all, not by its exit status: a+/// tool that runs but reports its version oddly is still an oracle.+pub fn find(program: &'static str, version_arg: &str) -> Result<Oracle, Absent> {+ let required = std::env::var_os(REQUIRED_VAR).is_some();+ match Command::new(program).arg(version_arg).output() {+ Ok(out) => {+ // Poppler's tools print their version to stderr, qpdf to stdout.+ let text = if out.stdout.is_empty() { &out.stderr } else { &out.stdout };+ let version = String::from_utf8_lossy(text).lines().next().unwrap_or_default().trim().to_owned();+ Ok(Oracle { program, version })+ }+ Err(e) => Err(Absent { program, cause: format!("is not on PATH ({e})"), required }),+ }+}++/// qpdf: structural validation (`--check`) and the independent owner-password oracle.+pub fn qpdf() -> Result<Oracle, Absent> {+ find("qpdf", "--version")+}++/// Poppler's `pdftoppm`: renders a page to pixels, for comparing against our own raster output.+pub fn pdftoppm() -> Result<Oracle, Absent> {+ find("pdftoppm", "-v")+}++/// Poppler's `pdftotext`: the text-extraction oracle (`cargo xtask text-oracle` scores word F1+/// against it over the corpus).+pub fn pdftotext() -> Result<Oracle, Absent> {+ find("pdftotext", "-v")+}++/// Binds an oracle, or returns from the calling test after saying on stderr why it was skipped.+///+/// When [`REQUIRED_VAR`] is set the absence fails the test instead. The panic is deliberate and is+/// how a test reports failure; it expands into the caller, which is test code, so the workspace's+/// never-panic rule is not weakened — this crate itself contains no panicking path.+///+/// The macro expands to a `return`, so it belongs in a test function returning `()`. A test that+/// returns `Result` should match on the probe itself.+#[macro_export]+macro_rules! or_skip {+ ($probe:expr) => {+ match $probe {+ ::core::result::Result::Ok(oracle) => oracle,+ ::core::result::Result::Err(absent) => {+ let absent: $crate::Absent = absent;+ ::core::assert!(!$crate::Absent::required(&absent), "{absent}");+ ::std::eprintln!("{absent}");+ return;+ }+ }+ };+}++#[cfg(test)]+mod tests {+ use super::*;++ /// The one behaviour the crate exists for: absence is never silent, and which of the two loud+ /// forms it takes is decided by the environment variable.+ #[test]+ fn a_missing_oracle_is_fatal_exactly_when_it_is_required() {+ let optional = Absent { program: "qpdf", cause: "is not on PATH".into(), required: false };+ let required = Absent { required: true, ..optional.clone() };++ assert!(!optional.required());+ assert!(required.required());++ // Both say what is wrong and how to fix it; only the required one calls itself a failure.+ let (opt, req) = (optional.to_string(), required.to_string());+ assert!(opt.contains("skipping"), "{opt}");+ assert!(opt.contains("apt install qpdf"), "{opt}");+ assert!(opt.contains(REQUIRED_VAR), "{opt}");+ assert!(req.contains("required"), "{req}");+ assert!(req.contains("failure"), "{req}");+ assert!(!req.contains("skipping"), "{req}");+ }++ /// A tool that does not exist is reported as absent rather than hanging or panicking, and the+ /// reason names the program.+ #[test]+ fn a_program_that_does_not_exist_is_absent_with_a_reason() {+ let Err(absent) = find("pdfcraft-no-such-oracle-binary", "--version") else {+ panic!("a nonexistent program must not be reported as present");+ };+ assert_eq!(absent.program(), "pdfcraft-no-such-oracle-binary");+ let text = absent.to_string();+ assert!(text.contains("pdfcraft-no-such-oracle-binary"), "{text}");+ assert!(text.contains("not on PATH"), "{text}");+ }++ /// Hostile and odd program names must not panic, hang or be mistaken for a working oracle.+ #[test]+ fn hostile_program_names_are_absent_not_a_panic() {+ for name in ["", " ", "\0bad", "../../etc/passwd", &"x".repeat(4096)] {+ // `find` takes a 'static str; leak the generated ones, which is fine in a test.+ let name: &'static str = Box::leak(name.to_owned().into_boxed_str());+ let found = find(name, "--version");+ if let Ok(o) = found {+ // Nothing by these names should run; if one somehow does, it must still be sane.+ assert_eq!(o.program(), name);+ }+ }+ }++ /// The install hint is specific per tool, so a skip notice is actionable.+ #[test]+ fn every_known_oracle_has_an_install_hint() {+ for p in ["qpdf", "pdftoppm", "pdftotext"] {+ let hint = Absent::install_hint(p);+ assert!(hint.contains("install"), "{p}: {hint}");+ assert_ne!(hint, Absent::install_hint("something-else"), "{p} needs its own hint");+ }+ }++ /// Probing is read-only and repeatable: asking twice gives the same answer.+ #[test]+ fn probing_is_stable() {+ let a = qpdf().map(|o| o.program());+ let b = qpdf().map(|o| o.program());+ assert_eq!(a.is_ok(), b.is_ok());+ if let (Ok(a), Ok(b)) = (a, b) {+ assert_eq!(a, b);+ }+ }+}diff --git a/crates/organize/Cargo.toml b/crates/organize/Cargo.tomlindex e759a322d..78507197a 100644--- a/crates/organize/Cargo.toml+++ b/crates/organize/Cargo.toml@@ -14,4 +14,5 @@ pdfcraft-cos = { workspace = true }thiserror = { workspace = true }[dev-dependencies]+pdfcraft-oracle = { workspace = true }hayro-syntax = { workspace = true }diff --git a/crates/organize/src/tests.rs b/crates/organize/src/tests.rsindex e07af72a1..a612587d2 100644--- a/crates/organize/src/tests.rs+++ b/crates/organize/src/tests.rs@@ -2025,9 +2025,12 @@ fn extract_still_prunes_separate_resources_when_many_pages_share_a_type3_font()assert_eq!(xobject_names(&part, 0), [b"ImA".to_vec()], "one shared font's direct resource graph is protected once");}+// Stays ignored until CI installs Poppler: the pixel comparison has never run on a runner, so+// un-ignoring it here would turn an unverified test loose on everyone. See crates/oracle.#[test]#[ignore = "requires the external Poppler pdftoppm oracle"]fn extract_type3_shared_xobjects_matches_poppler_pixels() {+ let pdftoppm = pdfcraft_oracle::or_skip!(pdfcraft_oracle::pdftoppm());let dir = std::env::temp_dir().join(format!("pdfcraft-type3-extract-{}", std::process::id()));std::fs::create_dir_all(&dir).unwrap();let fixtures = [@@ -2042,7 +2045,7 @@ fn extract_type3_shared_xobjects_matches_poppler_pixels() {let render = |doc: &Document, name: &str| {let path = dir.join(format!("{i}-{name}.pdf"));std::fs::write(&path, write_full(doc, &SaveOptions::default()).unwrap()).unwrap();- let output = std::process::Command::new("pdftoppm").args(["-singlefile", "-r", "72", "-gray"]).arg(path).output().unwrap();+ let output = pdftoppm.command().args(["-singlefile", "-r", "72", "-gray"]).arg(path).output().unwrap();assert!(output.status.success(), "{}", String::from_utf8_lossy(&output.stderr));assert!(output.stderr.is_empty(), "{}", String::from_utf8_lossy(&output.stderr));output.stdoutdiff --git a/parity/acrobat-features.toml b/parity/acrobat-features.tomlindex 359a71e9a..3f56e207a 100644--- a/parity/acrobat-features.toml+++ b/parity/acrobat-features.toml@@ -335,7 +335,7 @@ status = "shipped"commands = []tools = []evidence = ["crates/cos/tests/encryption.rs::qpdf_agrees", "crates/cos/tests/writer.rs::qpdf_accepts_object_stream_output"]-notes = "skipped when qpdf is absent"+notes = "qpdf is installed on the Linux CI runner and PDFCRAFT_ORACLES_REQUIRED makes its absence a failure, so these run on every CI run rather than skipping; on a machine without qpdf they skip with a notice (crates/oracle)"[[feature]]id = "core.deterministic-save"diff --git a/xtask/Cargo.toml b/xtask/Cargo.tomlindex def0fe755..1171dfc56 100644--- a/xtask/Cargo.toml+++ b/xtask/Cargo.toml@@ -6,6 +6,7 @@ publish = falselicense.workspace = true[dependencies]+pdfcraft-oracle = { workspace = true }anyhow = "1"lopdf = "0.45"png = "0.18"diff --git a/xtask/src/gates.rs b/xtask/src/gates.rsindex 4406a957c..cf3d164ce 100644--- a/xtask/src/gates.rs+++ b/xtask/src/gates.rs@@ -200,9 +200,10 @@ pub fn check(args: &[String]) -> anyhow::Result<()> {/// median. Plan target (M2): median ≥ 0.97.pub fn text_oracle(args: &[String]) -> anyhow::Result<()> {let limit: usize = args.iter().position(|a| a == "--limit").and_then(|i| args.get(i + 1)).and_then(|v| v.parse().ok()).unwrap_or(usize::MAX);- if Command::new("pdftotext").arg("-v").output().is_err() {- bail!("pdftotext (poppler) not found; install it to run the text oracle (brew install poppler / apt install poppler-utils)");- }+ let pdftotext = match pdfcraft_oracle::pdftotext() {+ Ok(o) => o,+ Err(absent) => bail!("{absent}"),+ };run_args(&["build", "--release", "-p", "pdfcraft-cli"])?;let corpus = root().join("corpus/pdfjs/test/pdfs");let mut files: Vec<PathBuf> =@@ -213,7 +214,7 @@ pub fn text_oracle(args: &[String]) -> anyhow::Result<()> {let mut worst: Vec<(f64, String)> = Vec::new();for f in files.iter().take(limit) {let ours = run_capture(Command::new(&cli).arg("text").arg(f), 20);- let theirs = run_capture(Command::new("pdftotext").arg("-q").arg(f).arg("-"), 20);+ let theirs = run_capture(pdftotext.command().arg("-q").arg(f).arg("-"), 20);let (Some(ours), Some(theirs)) = (ours, theirs) else { continue };let (a, b) = (words(&ours), words(&theirs));if b.len() < 20 {