From be8c01ebee325df7f5ac45b83a31af492dde513b Mon Sep 17 00:00:00 2001 From: FredApps <153173854+FredApps@users.noreply.github.com> Date: Sat, 21 Nov 2026 00:06:15 +0100 Subject: [PATCH] engine: file.print.page's printer route is reachable from a test SonarCloud's new-code coverage was 50%: CI sets PHOTOCRAFT_NO_PRINT for every test, so nothing ran the line after the new off switch. The command now passes printing_disabled() to page_of_printer, and disabled_printing_never_spools also asks it with printing on: off Windows the GDI route answers Unsupported without asking a driver, so the refusal is the route's, not the switch's. Co-Authored-By: Claude Opus 5.5 --- crates/engine/src/cmd/print_cmds.rs | 8 +++++++- crates/engine/src/cmd/print_cmds/tests.rs | 7 +++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/crates/engine/src/cmd/print_cmds.rs b/crates/engine/src/cmd/print_cmds.rs index 3007c0f6498..4b2433b0085 100644 --- a/crates/engine/src/cmd/print_cmds.rs +++ b/crates/engine/src/cmd/print_cmds.rs @@ -1424,6 +1424,12 @@ fn printers(s: &mut Session, _: &Value) -> Result { } fn printer_page(_: &mut Session, p: &Value) -> Result { + page_of_printer(p, printing_disabled()) +} + +/// `file.print.page` with printing turned off or not (`disabled`). A test passes `false` to reach the printer route, +/// which `printing_disabled` never is once a test of the process or CI's `PHOTOCRAFT_NO_PRINT` turned it off. +fn page_of_printer(p: &Value, disabled: bool) -> Result { // Checked before the printer, so a bad value is the error whether or not a printer answers. let landscape = match p.get("orientation").filter(|v| !v.is_null()) { None => None, @@ -1436,7 +1442,7 @@ fn printer_page(_: &mut Session, p: &Value) -> Result { let mut settings = printer_settings(p)?; // A driver query is still a call into a printer driver, which can hang (and holds SPOOLER // while it does), so a process that turned printing off asks no driver here either. - if printing_disabled() { + if disabled { return Err(other("printing is disabled in this process (disable_printing or PHOTOCRAFT_NO_PRINT); file.print.page asks no printer driver")); } let printer = printer_name(p)?; diff --git a/crates/engine/src/cmd/print_cmds/tests.rs b/crates/engine/src/cmd/print_cmds/tests.rs index c704691ecc3..1d35fc3cc40 100644 --- a/crates/engine/src/cmd/print_cmds/tests.rs +++ b/crates/engine/src/cmd/print_cmds/tests.rs @@ -789,6 +789,13 @@ fn disabled_printing_never_spools() { // Bad values are still the error they were, before the check. let e = s.execute("file.print.page", json!({"orientation": "sideways"})).unwrap_err().to_string(); assert!(e.contains("orientation"), "{e}"); + // With printing on the command goes past the switch to the printer route: off Windows the GDI route has no + // printers, so a named printer's page is the route's own refusal (no driver is asked there). + #[cfg(not(windows))] + { + let e = super::page_of_printer(&json!({"printer": "Anything"}), false).unwrap_err().to_string(); + assert!(!e.contains("printing is disabled"), "{e}"); + } // A dry run still renders and reports the command it would have run. let r = s.execute("file.print", json!({"dryRun": true})).unwrap(); assert_eq!(r["sent"], false);