Skip to content

Commit a89dd2a

Browse files
hyperpolymathtanush5800claude
authored
style: apply cargo fmt to satisfy Test (fmt --check) gate (#27)
Pre-existing formatting drift was failing the Test job's `cargo fmt --check` step on every PR (incl. all open dependabot bumps). Pure rustfmt, no logic changes. Co-authored-by: Jonathan D.A. Jewell <67598845+hyperpolymath@users.noreply.github.com> Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 300d7b5 commit a89dd2a

24 files changed

Lines changed: 232 additions & 187 deletions

File tree

crates/presswerk-app/src/pages/add_printer.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,7 @@ pub fn AddPrinter() -> Element {
165165

166166
/// Probe a printer by attempting Get-Printer-Attributes.
167167
async fn probe_printer(uri: &str) -> Result<(), String> {
168-
let client = presswerk_print::ipp_client::IppClient::new(uri)
169-
.map_err(|e| e.to_string())?;
168+
let client = presswerk_print::ipp_client::IppClient::new(uri).map_err(|e| e.to_string())?;
170169
client
171170
.get_printer_attributes()
172171
.await

crates/presswerk-app/src/services/app_services.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -269,20 +269,15 @@ impl AppServices {
269269
Ok(remote_id) => {
270270
info!(job_id = %job_id, remote_id, "print job accepted");
271271
if let Ok(queue) = services.job_queue.lock() {
272-
let _ =
273-
queue.update_status(&job_id, JobStatus::Completed, None);
272+
let _ = queue.update_status(&job_id, JobStatus::Completed, None);
274273
}
275274
services.audit("print_completed", &hash, true, None);
276275
}
277276
Err(e) => {
278277
error!(job_id = %job_id, error = %e, "print job failed");
279278
let msg = e.to_string();
280279
if let Ok(queue) = services.job_queue.lock() {
281-
let _ = queue.update_status(
282-
&job_id,
283-
JobStatus::Failed,
284-
Some(&msg),
285-
);
280+
let _ = queue.update_status(&job_id, JobStatus::Failed, Some(&msg));
286281
}
287282
services.audit("print_failed", &hash, false, Some(&msg));
288283
}

crates/presswerk-bridge/src/android/mod.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,7 +1025,6 @@ fn get_authority(env: &mut JNIEnv<'_>, activity: &JObject<'_>) -> Result<String>
10251025
Ok(format!("{pkg}.fileprovider"))
10261026
}
10271027

1028-
10291028
// ---------------------------------------------------------------------------
10301029
// Stub implementations for connection types not yet wired to Android APIs
10311030
// ---------------------------------------------------------------------------
@@ -1095,7 +1094,12 @@ impl NativeThunderboltPrint for AndroidBridge {
10951094
Err(PresswerkError::PlatformUnavailable)
10961095
}
10971096

1098-
fn print_thunderbolt(&self, _device_id: &str, _document: &[u8], _mime_type: &str) -> Result<()> {
1097+
fn print_thunderbolt(
1098+
&self,
1099+
_device_id: &str,
1100+
_document: &[u8],
1101+
_mime_type: &str,
1102+
) -> Result<()> {
10991103
Err(PresswerkError::PlatformUnavailable)
11001104
}
11011105
}
@@ -1151,7 +1155,12 @@ impl NativeUsbDrivePrint for AndroidBridge {
11511155
Err(PresswerkError::PlatformUnavailable)
11521156
}
11531157

1154-
fn copy_to_usb_drive(&self, _drive_id: &str, _document: &[u8], _filename: &str) -> Result<String> {
1158+
fn copy_to_usb_drive(
1159+
&self,
1160+
_drive_id: &str,
1161+
_document: &[u8],
1162+
_filename: &str,
1163+
) -> Result<String> {
11551164
Err(PresswerkError::PlatformUnavailable)
11561165
}
11571166
}

crates/presswerk-bridge/src/ios/mod.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -879,7 +879,6 @@ impl NativeShare for IosBridge {
879879
// Tests
880880
// ---------------------------------------------------------------------------
881881

882-
883882
// ---------------------------------------------------------------------------
884883
// Stub implementations for connection types not yet wired to iOS APIs
885884
// ---------------------------------------------------------------------------
@@ -949,7 +948,12 @@ impl NativeThunderboltPrint for IosBridge {
949948
Err(PresswerkError::PlatformUnavailable)
950949
}
951950

952-
fn print_thunderbolt(&self, _device_id: &str, _document: &[u8], _mime_type: &str) -> Result<()> {
951+
fn print_thunderbolt(
952+
&self,
953+
_device_id: &str,
954+
_document: &[u8],
955+
_mime_type: &str,
956+
) -> Result<()> {
953957
Err(PresswerkError::PlatformUnavailable)
954958
}
955959
}
@@ -1005,7 +1009,12 @@ impl NativeUsbDrivePrint for IosBridge {
10051009
Err(PresswerkError::PlatformUnavailable)
10061010
}
10071011

1008-
fn copy_to_usb_drive(&self, _drive_id: &str, _document: &[u8], _filename: &str) -> Result<String> {
1012+
fn copy_to_usb_drive(
1013+
&self,
1014+
_drive_id: &str,
1015+
_document: &[u8],
1016+
_filename: &str,
1017+
) -> Result<String> {
10091018
Err(PresswerkError::PlatformUnavailable)
10101019
}
10111020
}

crates/presswerk-bridge/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ pub mod android;
2121
pub mod stub;
2222

2323
/// Retrieves the singleton bridge implementation for the target operating system.
24-
///
24+
///
2525
/// RETURNS: A boxed trait object (`dyn PlatformBridge`) that abstracts away
2626
/// the underlying native SDK details.
2727
pub fn platform_bridge() -> Box<dyn traits::PlatformBridge> {

crates/presswerk-core/benches/core_bench.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,8 @@
44
// Benchmarks for presswerk-core critical operations.
55
// Run with: cargo bench -p presswerk-core
66

7-
use criterion::{black_box, criterion_group, criterion_main, Criterion};
8-
use presswerk_core::{
9-
AppConfig, DocumentType, PrintJob, PrintSettings, JobSource,
10-
};
7+
use criterion::{Criterion, black_box, criterion_group, criterion_main};
8+
use presswerk_core::{AppConfig, DocumentType, JobSource, PrintJob, PrintSettings};
119

1210
fn bench_config_creation(c: &mut Criterion) {
1311
c.bench_function("config_default", |b| {
@@ -41,8 +39,7 @@ fn bench_config_serialization(c: &mut Criterion) {
4139

4240
c.bench_function("config_deserialize_json", |b| {
4341
b.iter(|| {
44-
let _config: AppConfig =
45-
serde_json::from_str(&black_box(&json)).expect("deserialize");
42+
let _config: AppConfig = serde_json::from_str(&black_box(&json)).expect("deserialize");
4643
})
4744
});
4845
}
@@ -101,8 +98,7 @@ fn bench_job_serialization(c: &mut Criterion) {
10198

10299
c.bench_function("job_deserialize_json", |b| {
103100
b.iter(|| {
104-
let _job: PrintJob =
105-
serde_json::from_str(&black_box(&json)).expect("deserialize");
101+
let _job: PrintJob = serde_json::from_str(&black_box(&json)).expect("deserialize");
106102
})
107103
});
108104
}

crates/presswerk-core/src/human_errors.rs

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -208,14 +208,19 @@ fn humanize_ipp_error(detail: &str) -> HumanError {
208208
} else if lower.contains("server-error") {
209209
HumanError {
210210
message: "The printer reported an internal error.".into(),
211-
suggestion: "Try turning the printer off, waiting 10 seconds, and turning it back on.".into(),
211+
suggestion: "Try turning the printer off, waiting 10 seconds, and turning it back on."
212+
.into(),
212213
retriable: true,
213214
severity: Severity::Transient,
214215
}
215-
} else if lower.contains("client-error-not-possible") || lower.contains("client-error-attributes") {
216+
} else if lower.contains("client-error-not-possible")
217+
|| lower.contains("client-error-attributes")
218+
{
216219
HumanError {
217220
message: "The printer can't handle those settings.".into(),
218-
suggestion: "Try changing the print settings (paper size, duplex, colour) and print again.".into(),
221+
suggestion:
222+
"Try changing the print settings (paper size, duplex, colour) and print again."
223+
.into(),
219224
retriable: false,
220225
severity: Severity::ActionRequired,
221226
}
@@ -229,7 +234,8 @@ fn humanize_ipp_error(detail: &str) -> HumanError {
229234
} else if lower.contains("invalid uri") || lower.contains("invalid url") {
230235
HumanError {
231236
message: "The printer address doesn't look right.".into(),
232-
suggestion: "Check the printer address and try again. It should look like 192.168.1.100.".into(),
237+
suggestion:
238+
"Check the printer address and try again. It should look like 192.168.1.100.".into(),
233239
retriable: false,
234240
severity: Severity::ActionRequired,
235241
}
@@ -240,7 +246,10 @@ fn humanize_ipp_error(detail: &str) -> HumanError {
240246
retriable: false,
241247
severity: Severity::ActionRequired,
242248
}
243-
} else if lower.contains("toner-empty") || lower.contains("ink") || lower.contains("marker-supply") {
249+
} else if lower.contains("toner-empty")
250+
|| lower.contains("ink")
251+
|| lower.contains("marker-supply")
252+
{
244253
HumanError {
245254
message: "The printer needs new ink or toner.".into(),
246255
suggestion: "You'll need to buy a replacement cartridge. Check your printer's model number and search online for the right one.".into(),
@@ -265,7 +274,9 @@ fn humanize_ipp_error(detail: &str) -> HumanError {
265274
// Generic IPP error fallback
266275
HumanError {
267276
message: "The printer had a problem.".into(),
268-
suggestion: format!("Try again. If this keeps happening, try turning the printer off and on again. (Detail: {detail})"),
277+
suggestion: format!(
278+
"Try again. If this keeps happening, try turning the printer off and on again. (Detail: {detail})"
279+
),
269280
retriable: true,
270281
severity: Severity::Transient,
271282
}

crates/presswerk-core/src/types.rs

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -368,17 +368,29 @@ mod tests {
368368
#[test]
369369
fn test_document_type_extensions() {
370370
assert_eq!(DocumentType::from_extension("pdf"), Some(DocumentType::Pdf));
371-
assert_eq!(DocumentType::from_extension("jpg"), Some(DocumentType::Jpeg));
372-
assert_eq!(DocumentType::from_extension("jpeg"), Some(DocumentType::Jpeg));
371+
assert_eq!(
372+
DocumentType::from_extension("jpg"),
373+
Some(DocumentType::Jpeg)
374+
);
375+
assert_eq!(
376+
DocumentType::from_extension("jpeg"),
377+
Some(DocumentType::Jpeg)
378+
);
373379
assert_eq!(DocumentType::from_extension("png"), Some(DocumentType::Png));
374-
assert_eq!(DocumentType::from_extension("txt"), Some(DocumentType::PlainText));
380+
assert_eq!(
381+
DocumentType::from_extension("txt"),
382+
Some(DocumentType::PlainText)
383+
);
375384
assert_eq!(DocumentType::from_extension("unknown"), None);
376385
}
377386

378387
#[test]
379388
fn test_document_type_case_insensitive() {
380389
assert_eq!(DocumentType::from_extension("PDF"), Some(DocumentType::Pdf));
381-
assert_eq!(DocumentType::from_extension("JPG"), Some(DocumentType::Jpeg));
390+
assert_eq!(
391+
DocumentType::from_extension("JPG"),
392+
Some(DocumentType::Jpeg)
393+
);
382394
assert_eq!(DocumentType::from_extension("Pdf"), Some(DocumentType::Pdf));
383395
}
384396

@@ -410,8 +422,14 @@ mod tests {
410422
#[test]
411423
fn test_duplex_mode_keywords() {
412424
assert_eq!(DuplexMode::Simplex.ipp_sides_keyword(), "one-sided");
413-
assert_eq!(DuplexMode::LongEdge.ipp_sides_keyword(), "two-sided-long-edge");
414-
assert_eq!(DuplexMode::ShortEdge.ipp_sides_keyword(), "two-sided-short-edge");
425+
assert_eq!(
426+
DuplexMode::LongEdge.ipp_sides_keyword(),
427+
"two-sided-long-edge"
428+
);
429+
assert_eq!(
430+
DuplexMode::ShortEdge.ipp_sides_keyword(),
431+
"two-sided-short-edge"
432+
);
415433
}
416434

417435
#[test]

crates/presswerk-core/tests/aspect_test.rs

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// Tests security properties, invariants, and edge cases.
66

77
use presswerk_core::{
8-
AppConfig, DocumentType, PrintJob, PrintSettings, JobSource, PageRange, PaperSize,
8+
AppConfig, DocumentType, JobSource, PageRange, PaperSize, PrintJob, PrintSettings,
99
};
1010

1111
// ============================================================================
@@ -34,8 +34,11 @@ fn aspect_html_injection_in_document_name() {
3434
for name in malicious_names {
3535
// These should be detected as suspicious by the application
3636
assert!(
37-
name.contains('<') || name.contains('>') || name.contains('\'')
38-
|| name.contains('/') || name.contains('.'),
37+
name.contains('<')
38+
|| name.contains('>')
39+
|| name.contains('\'')
40+
|| name.contains('/')
41+
|| name.contains('.'),
3942
"Potential injection in: {}",
4043
name
4144
);
@@ -55,7 +58,11 @@ fn aspect_path_traversal_prevention() {
5558
// Check for path traversal indicators
5659
let has_traversal = path.contains("../") || path.contains("..\\") || path.starts_with('/');
5760
if should_be_suspicious {
58-
assert!(has_traversal, "Path traversal pattern should be detected in: {}", path);
61+
assert!(
62+
has_traversal,
63+
"Path traversal pattern should be detected in: {}",
64+
path
65+
);
5966
}
6067
}
6168
}
@@ -90,7 +97,10 @@ fn aspect_page_count_validation() {
9097
"hash".to_string(),
9198
);
9299

93-
job.settings.page_range = Some(PageRange { start: 100, end: 50 });
100+
job.settings.page_range = Some(PageRange {
101+
start: 100,
102+
end: 50,
103+
});
94104

95105
// Invalid range: start > end should be detected
96106
if let Some(range) = &job.settings.page_range {
@@ -113,7 +123,11 @@ fn aspect_invalid_dpi_detection() {
113123
const MAX_DPI: u32 = 1200;
114124

115125
for dpi in valid_dpis {
116-
assert!(dpi >= MIN_DPI && dpi <= MAX_DPI, "DPI {} should be valid", dpi);
126+
assert!(
127+
dpi >= MIN_DPI && dpi <= MAX_DPI,
128+
"DPI {} should be valid",
129+
dpi
130+
);
117131
}
118132

119133
for dpi in invalid_dpis {
@@ -177,7 +191,10 @@ fn aspect_error_message_sanitization() {
177191
// Check for common sensitive patterns
178192
let contains_password = msg.contains("password");
179193
let contains_ip = msg.contains("192.168");
180-
assert!(contains_password || contains_ip, "Error message should contain sensitive data (for testing)");
194+
assert!(
195+
contains_password || contains_ip,
196+
"Error message should contain sensitive data (for testing)"
197+
);
181198
// In production, these should be redacted
182199
}
183200
}
@@ -246,7 +263,10 @@ fn aspect_max_copies_limit() {
246263

247264
// Beyond practical limits would need manual override
248265
let excessive_copies = 10_000u32;
249-
assert!(excessive_copies > MAX_COPIES, "Excessive copies should be detectable");
266+
assert!(
267+
excessive_copies > MAX_COPIES,
268+
"Excessive copies should be detectable"
269+
);
250270
}
251271

252272
#[test]

crates/presswerk-core/tests/e2e_test.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
// Tests the complete workflows: configuration, job creation, serialization.
66

77
use presswerk_core::{
8-
AppConfig, DocumentType, DuplexMode, Orientation, PaperSize, PageRange,
9-
PrintJob, PrintSettings, JobSource, JobStatus, ErrorClass,
8+
AppConfig, DocumentType, DuplexMode, ErrorClass, JobSource, JobStatus, Orientation, PageRange,
9+
PaperSize, PrintJob, PrintSettings,
1010
};
1111

1212
#[test]
@@ -164,8 +164,14 @@ fn e2e_paper_size_ipp_mapping() {
164164
#[test]
165165
fn e2e_duplex_mode_ipp_mapping() {
166166
assert_eq!(DuplexMode::Simplex.ipp_sides_keyword(), "one-sided");
167-
assert_eq!(DuplexMode::LongEdge.ipp_sides_keyword(), "two-sided-long-edge");
168-
assert_eq!(DuplexMode::ShortEdge.ipp_sides_keyword(), "two-sided-short-edge");
167+
assert_eq!(
168+
DuplexMode::LongEdge.ipp_sides_keyword(),
169+
"two-sided-long-edge"
170+
);
171+
assert_eq!(
172+
DuplexMode::ShortEdge.ipp_sides_keyword(),
173+
"two-sided-short-edge"
174+
);
169175
}
170176

171177
#[test]

0 commit comments

Comments
 (0)