Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/spark-inquisitor/blob/main/tests/diff_auditor_edge_cases.rs # spark-inquisitor Ultra-fast compiled native Rust gatekeeper and automated code reviewer Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `spark-inquisitor / tests / diff_auditor_edge_cases.rs` 177 lines · 6487 bytes Raw Blame History 1 use spark_inquisitor::audit::DiffAuditor; 2 3 #[test] 4 fn test_empty_diff_returns_clean() { 5 let report = DiffAuditor::audit_text(""); 6 assert!(report.clean); 7 assert!(report.violations.is_empty()); 8 assert!(report.unslop_violations.is_empty()); 9 assert!(report.secret_violations.is_empty()); 10 assert!(!report.telemetry_detected); 11 } 12 13 #[test] 14 fn test_whitespace_only_diff_returns_clean() { 15 let text = " \n\n\t \r\n \n"; 16 let report = DiffAuditor::audit_text(text); 17 assert!(report.clean); 18 assert!(report.violations.is_empty()); 19 assert!(report.unslop_violations.is_empty()); 20 } 21 22 #[test] 23 fn test_malformed_diff_headers_no_panic() { 24 let malformed_inputs = [ 25 "diff --git ", 26 "diff --git a/only_one", 27 "diff --git \n\n+++ b/test.rs\n+fn test() {}", 28 "@@ -0,0 +1,5 @@\n+fn test() {}", 29 "--- a/broken\n+++ b/broken\n@@ malformed @@\n+let x = 1;", 30 "diff --git a/file1 b/file2 extra tokens here\n+let y = 2;", 31 "diff --git\n+++\n---\n+valid_line();", 32 ]; 33 34 for input in malformed_inputs { 35 let report = DiffAuditor::audit_text(input); 36 assert!(report.clean); 37 } 38 } 39 40 #[test] 41 fn test_malformed_chunk_headers() { 42 let diff = "diff --git a/src/lib.rs b/src/lib.rs\n@@ corrupted chunk @@\n+pub fn foo() {}"; 43 let report = DiffAuditor::audit_text(diff); 44 assert!(report.clean); 45 } 46 47 #[test] 48 fn test_diff_without_plus_minus_headers() { 49 let diff = "diff --git a/file.rs b/file.rs\n+pub fn bar() {}"; 50 let report = DiffAuditor::audit_text(diff); 51 assert!(report.clean); 52 } 53 54 #[test] 55 fn test_binary_file_addition_clean() { 56 let diff = "diff --git a/assets/icon.png b/assets/icon.png\nnew file mode 100644\nindex `0000000`..`d1e2f3a`\nBinary files /dev/null and b/assets/icon.png differ"; 57 let report = DiffAuditor::audit_text(diff); 58 assert!(report.clean); 59 assert!(report.violations.is_empty()); 60 } 61 62 #[test] 63 fn test_binary_file_deletion_clean() { 64 let diff = "diff --git a/assets/old.bin b/assets/old.bin\ndeleted file mode 100644\nindex `d1e2f3a`..`0000000`\nBinary files a/assets/old.bin and /dev/null differ"; 65 let report = DiffAuditor::audit_text(diff); 66 assert!(report.clean); 67 assert!(report.violations.is_empty()); 68 } 69 70 #[test] 71 fn test_binary_file_modification_clean() { 72 let diff = "diff --git a/assets/font.woff2 b/assets/font.woff2\nindex `1111111`..`2222222` 100644\nBinary files a/assets/font.woff2 and b/assets/font.woff2 differ"; 73 let report = DiffAuditor::audit_text(diff); 74 assert!(report.clean); 75 } 76 77 #[test] 78 fn test_git_binary_patch_clean() { 79 let diff = "diff --git a/weights/model.bin b/weights/model.bin\nGIT binary patch\nliteral 32\nzc$}~|`00000000000000000000000000000000`"; 80 let report = DiffAuditor::audit_text(diff); 81 assert!(report.clean); 82 } 83 84 #[test] 85 fn test_binary_file_env_detected() { 86 let diff = 87 "diff --git a/.env b/.env\nnew file mode 100644\nBinary files /dev/null and b/.env differ"; 88 let report = DiffAuditor::audit_text(diff); 89 assert!(!report.clean); 90 assert!(report.violations.iter().any(|v| v.contains(".env"))); 91 } 92 93 #[test] 94 fn test_large_diff_over_5000_lines_clean() { 95 let mut diff = String::with_capacity(5500 * 45); 96 diff.push_str("diff --git a/src/generated.rs b/src/generated.rs\n--- a/src/generated.rs\n+++ b/src/generated.rs\n@@ -1,1 +1,6000 @@\n"); 97 for i in 0..5500 { 98 if i % 3 == 0 { 99 diff.push_str(&format!("+ pub const CONST_{}: usize = {};\n", i, i)); 100 } else if i % 3 == 1 { 101 diff.push_str(&format!("- // old comment {}\n", i)); 102 } else { 103 diff.push_str(&format!(" // context line {}\n", i)); 104 } 105 } 106 107 let report = DiffAuditor::audit_text(&diff); 108 assert!(report.clean); 109 assert!(report.violations.is_empty()); 110 assert!(report.unslop_violations.is_empty()); 111 } 112 113 #[test] 114 fn test_large_diff_with_telemetry_violation() { 115 let mut diff = String::with_capacity(5200 * 45); 116 diff.push_str("diff --git a/src/huge.rs b/src/huge.rs\n--- a/src/huge.rs\n+++ b/src/huge.rs\n@@ -1,1 +1,5200 @@\n"); 117 for i in 0..5000 { 118 if i == 4800 { 119 diff.push_str("+ let _ = report_telemetry(\"https://datadog.com\");\n"); 120 } else { 121 diff.push_str(&format!("+ let val_{} = {};\n", i, i)); 122 } 123 } 124 125 let report = DiffAuditor::audit_text(&diff); 126 assert!(!report.clean); 127 assert!(report.telemetry_detected); 128 assert!(report.violations.iter().any(|v| v.contains("datadog"))); 129 } 130 131 #[test] 132 fn test_large_diff_with_unslop_violation() { 133 let mut diff = String::with_capacity(5200 * 45); 134 diff.push_str("diff --git a/src/huge.rs b/src/huge.rs\n--- a/src/huge.rs\n+++ b/src/huge.rs\n@@ -1,1 +1,5200 @@\n"); 135 for i in 0..5000 { 136 if i == 3500 { 137 diff.push_str("+ // This is crucial for optimal performance\n"); 138 } else { 139 diff.push_str(&format!("+ let val_{} = {};\n", i, i)); 140 } 141 } 142 143 let report = DiffAuditor::audit_text(&diff); 144 assert!(!report.clean); 145 assert!(report 146 .unslop_violations 147 .iter() 148 .any(|u| u.contains("crucial"))); 149 } 150 151 #[test] 152 fn test_filenames_with_spaces() { 153 let diff = "diff --git \"a/crates/my service/src/main.rs\" \"b/crates/my service/src/main.rs\"\n--- \"a/crates/my service/src/main.rs\"\n+++ \"b/crates/my service/src/main.rs\"\n@@ -1,2 +1,3 @@\n+pub fn service_fn() -> bool { true }"; 154 let report = DiffAuditor::audit_text(diff); 155 assert!(report.clean); 156 } 157 158 #[test] 159 fn test_filenames_with_unicode() { 160 let diff = "diff --git a/src/föö_bäz/🦀.rs b/src/föö_bäz/🦀.rs\n--- a/src/föö_bäz/🦀.rs\n+++ b/src/föö_bäz/🦀.rs\n@@ -1,2 +1,3 @@\n+pub fn ferris_fn() -> &'static str { \"rust\" }"; 161 let report = DiffAuditor::audit_text(diff); 162 assert!(report.clean); 163 } 164 165 #[test] 166 fn test_filenames_with_unusual_paths() { 167 let diff = "diff --git a/../../deep/nested/path.rs b/../../deep/nested/path.rs\n--- a/../../deep/nested/path.rs\n+++ b/../../deep/nested/path.rs\n@@ -1,1 +1,2 @@\n+pub fn path_check() {}"; 168 let report = DiffAuditor::audit_text(diff); 169 assert!(report.clean); 170 } 171 172 #[test] 173 fn test_hidden_directory_paths() { 174 let diff = "diff --git a/.github/workflows/gate.yml b/.github/workflows/gate.yml\n--- a/.github/workflows/gate.yml\n+++ b/.github/workflows/gate.yml\n@@ -1,1 +1,2 @@\n+name: Constitutional Gate"; 175 let report = DiffAuditor::audit_text(diff); 176 assert!(report.clean); 177 }