aien-sovereign-core
Autonomous sovereign intelligence engine and runtime core for NVIDIA DGX Spark
Brought by drakestapleton
aien-sovereign-core / crates / spark-inquisitor / tests / constitutional_rules.rs
| 1 | use spark_inquisitor::audit::DiffAuditor; |
| 2 | |
| 3 | #[test] |
| 4 | fn test_em_dash_detected_in_code_comments() { |
| 5 | let diff = "diff --git a/src/lib.rs b/src/lib.rs\n+// Important note \u{2014} do not delete this function\npub fn keep() {}"; |
| 6 | let report = DiffAuditor::audit_text(diff); |
| 7 | assert!(!report.clean); |
| 8 | assert!(report.unslop_violations.iter().any(|u| u.contains("Em/En dash detected"))); |
| 9 | } |
| 10 | |
| 11 | #[test] |
| 12 | fn test_em_dash_detected_in_string_literals() { |
| 13 | let diff = "diff --git a/src/lib.rs b/src/lib.rs\n+pub const SLOGAN: &str = \"speed \u{2014} power\";"; |
| 14 | let report = DiffAuditor::audit_text(diff); |
| 15 | assert!(!report.clean); |
| 16 | assert!(report.unslop_violations.iter().any(|u| u.contains("Em/En dash detected"))); |
| 17 | } |
| 18 | |
| 19 | #[test] |
| 20 | fn test_em_dash_detected_in_markdown() { |
| 21 | let diff = "diff --git a/README.md b/README.md\n+- Core Feature \u{2014} high throughput engine"; |
| 22 | let report = DiffAuditor::audit_text(diff); |
| 23 | assert!(!report.clean); |
| 24 | assert!(report.unslop_violations.iter().any(|u| u.contains("Em/En dash detected"))); |
| 25 | } |
| 26 | |
| 27 | #[test] |
| 28 | fn test_en_dash_detected_in_code_comments() { |
| 29 | let diff = "diff --git a/src/lib.rs b/src/lib.rs\n+// Range 10\u{2013}20 items"; |
| 30 | let report = DiffAuditor::audit_text(diff); |
| 31 | assert!(!report.clean); |
| 32 | assert!(report.unslop_violations.iter().any(|u| u.contains("Em/En dash detected"))); |
| 33 | } |
| 34 | |
| 35 | #[test] |
| 36 | fn test_en_dash_detected_in_string_literals() { |
| 37 | let diff = "diff --git a/src/lib.rs b/src/lib.rs\n+let header = \"Version 1.0\u{2013}beta\";"; |
| 38 | let report = DiffAuditor::audit_text(diff); |
| 39 | assert!(!report.clean); |
| 40 | assert!(report.unslop_violations.iter().any(|u| u.contains("Em/En dash detected"))); |
| 41 | } |
| 42 | |
| 43 | #[test] |
| 44 | fn test_en_dash_detected_in_markdown() { |
| 45 | let diff = "diff --git a/DOCS.md b/DOCS.md\n+Pages 5\u{2013}10 contain benchmarks."; |
| 46 | let report = DiffAuditor::audit_text(diff); |
| 47 | assert!(!report.clean); |
| 48 | assert!(report.unslop_violations.iter().any(|u| u.contains("Em/En dash detected"))); |
| 49 | } |
| 50 | |
| 51 | #[test] |
| 52 | fn test_banned_buzzword_delve() { |
| 53 | let diff = "diff --git a/src/main.rs b/src/main.rs\n+// Let us delve into the architecture"; |
| 54 | let report = DiffAuditor::audit_text(diff); |
| 55 | assert!(!report.clean); |
| 56 | assert!(report.unslop_violations.iter().any(|u| u.contains("delve"))); |
| 57 | } |
| 58 | |
| 59 | #[test] |
| 60 | fn test_banned_buzzword_tapestry() { |
| 61 | let diff = "diff --git a/src/main.rs b/src/main.rs\n+// A rich tapestry of microservices"; |
| 62 | let report = DiffAuditor::audit_text(diff); |
| 63 | assert!(!report.clean); |
| 64 | assert!(report.unslop_violations.iter().any(|u| u.contains("tapestry"))); |
| 65 | } |
| 66 | |
| 67 | #[test] |
| 68 | fn test_banned_buzzword_testament() { |
| 69 | let diff = "diff --git a/src/main.rs b/src/main.rs\n+// This code is a testament to our engineering"; |
| 70 | let report = DiffAuditor::audit_text(diff); |
| 71 | assert!(!report.clean); |
| 72 | assert!(report.unslop_violations.iter().any(|u| u.contains("testament"))); |
| 73 | } |
| 74 | |
| 75 | #[test] |
| 76 | fn test_banned_buzzword_beacon_trope() { |
| 77 | let diff = "diff --git a/src/main.rs b/src/main.rs\n+// Standing as a beacon of hope for open source"; |
| 78 | let report = DiffAuditor::audit_text(diff); |
| 79 | assert!(!report.clean); |
| 80 | assert!(report.unslop_violations.iter().any(|u| u.contains("beacon"))); |
| 81 | } |
| 82 | |
| 83 | #[test] |
| 84 | fn test_beacon_hardware_term_allowed() { |
| 85 | let diff = "diff --git a/src/net.rs b/src/net.rs\n+fn parse_ble_beacon_packet(frame: &[u8]) -> bool { true }"; |
| 86 | let report = DiffAuditor::audit_text(diff); |
| 87 | assert!(report.clean); |
| 88 | } |
| 89 | |
| 90 | #[test] |
| 91 | fn test_banned_buzzword_crucial() { |
| 92 | let diff = "diff --git a/src/main.rs b/src/main.rs\n+// It is crucial to preserve cache coherence"; |
| 93 | let report = DiffAuditor::audit_text(diff); |
| 94 | assert!(!report.clean); |
| 95 | assert!(report.unslop_violations.iter().any(|u| u.contains("crucial"))); |
| 96 | } |
| 97 | |
| 98 | #[test] |
| 99 | fn test_banned_buzzword_pivotal() { |
| 100 | let diff = "diff --git a/src/main.rs b/src/main.rs\n+// A pivotal refactor for the memory engine"; |
| 101 | let report = DiffAuditor::audit_text(diff); |
| 102 | assert!(!report.clean); |
| 103 | assert!(report.unslop_violations.iter().any(|u| u.contains("pivotal"))); |
| 104 | } |
| 105 | |
| 106 | #[test] |
| 107 | fn test_banned_buzzword_elevate() { |
| 108 | let diff = "diff --git a/src/main.rs b/src/main.rs\n+// Designed to elevate the computing experience"; |
| 109 | let report = DiffAuditor::audit_text(diff); |
| 110 | assert!(!report.clean); |
| 111 | assert!(report.unslop_violations.iter().any(|u| u.contains("elevate"))); |
| 112 | } |
| 113 | |
| 114 | #[test] |
| 115 | fn test_elevate_flag_allowed() { |
| 116 | let diff = "diff --git a/src/cli.rs b/src/cli.rs\n+let flag = \"--elevate-privileges\";"; |
| 117 | let report = DiffAuditor::audit_text(diff); |
| 118 | assert!(report.clean); |
| 119 | } |
| 120 | |
| 121 | #[test] |
| 122 | fn test_banned_buzzword_game_changer() { |
| 123 | let diff = "diff --git a/src/main.rs b/src/main.rs\n+// The new allocator is a game-changer"; |
| 124 | let report = DiffAuditor::audit_text(diff); |
| 125 | assert!(!report.clean); |
| 126 | assert!(report.unslop_violations.iter().any(|u| u.contains("game-changer"))); |
| 127 | } |
| 128 | |
| 129 | #[test] |
| 130 | fn test_banned_buzzword_unleash() { |
| 131 | let diff = "diff --git a/src/main.rs b/src/main.rs\n+// Unleash the power of local silicon"; |
| 132 | let report = DiffAuditor::audit_text(diff); |
| 133 | assert!(!report.clean); |
| 134 | assert!(report.unslop_violations.iter().any(|u| u.contains("unleash"))); |
| 135 | } |
| 136 | |
| 137 | #[test] |
| 138 | fn test_unleash_flag_allowed() { |
| 139 | let diff = "diff --git a/src/args.rs b/src/args.rs\n+if args.contains(&\"--unleash-features\".to_string()) {}"; |
| 140 | let report = DiffAuditor::audit_text(diff); |
| 141 | assert!(report.clean); |
| 142 | } |
| 143 | |
| 144 | #[test] |
| 145 | fn test_banned_buzzword_harness_verb() { |
| 146 | let diff = "diff --git a/src/main.rs b/src/main.rs\n+// We can harness the full throughput of GPU nodes"; |
| 147 | let report = DiffAuditor::audit_text(diff); |
| 148 | assert!(!report.clean); |
| 149 | assert!(report.unslop_violations.iter().any(|u| u.contains("harness"))); |
| 150 | } |
| 151 | |
| 152 | #[test] |
| 153 | fn test_harness_noun_and_test_harness_allowed() { |
| 154 | let diff = "diff --git a/src/harness.rs b/src/harness.rs\n+// Verification test harness runner\npub struct TestHarness;"; |
| 155 | let report = DiffAuditor::audit_text(diff); |
| 156 | assert!(report.clean); |
| 157 | } |
| 158 | |
| 159 | #[test] |
| 160 | fn test_banned_buzzword_seamlessly() { |
| 161 | let diff = "diff --git a/src/main.rs b/src/main.rs\n+// Coordinates seamlessly across all instances"; |
| 162 | let report = DiffAuditor::audit_text(diff); |
| 163 | assert!(!report.clean); |
| 164 | assert!(report.unslop_violations.iter().any(|u| u.contains("seamlessly"))); |
| 165 | } |
| 166 | |
| 167 | #[test] |
| 168 | fn test_antithesis_trope_not_x_but_y() { |
| 169 | let diff = "diff --git a/src/main.rs b/src/main.rs\n+// It is not speed, but correctness that matters"; |
| 170 | let report = DiffAuditor::audit_text(diff); |
| 171 | assert!(!report.clean); |
| 172 | assert!(report.unslop_violations.iter().any(|u| u.contains("antithesis trope"))); |
| 173 | } |
| 174 | |
| 175 | #[test] |
| 176 | fn test_antithesis_trope_not_only_x_but_y() { |
| 177 | let diff = "diff --git a/src/main.rs b/src/main.rs\n+// Not only fast, but completely reliable across all tests"; |
| 178 | let report = DiffAuditor::audit_text(diff); |
| 179 | assert!(!report.clean); |
| 180 | assert!(report.unslop_violations.iter().any(|u| u.contains("antithesis trope"))); |
| 181 | } |
| 182 | |
| 183 | #[test] |
| 184 | fn test_plaintext_secret_aws_access_key() { |
| 185 | let diff = "diff --git a/src/vault.rs b/src/vault.rs\n+let aws_key = \"AKIA1234567890ABCDEF\";"; |
| 186 | let report = DiffAuditor::audit_text(diff); |
| 187 | assert!(!report.clean); |
| 188 | assert!(report.secret_violations.iter().any(|s| s.contains("AWS Access Key"))); |
| 189 | } |
| 190 | |
| 191 | #[test] |
| 192 | fn test_plaintext_secret_github_pat() { |
| 193 | let diff = "diff --git a/src/auth.rs b/src/auth.rs\n+let token = \"ghp_ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789\";"; |
| 194 | let report = DiffAuditor::audit_text(diff); |
| 195 | assert!(!report.clean); |
| 196 | assert!(report.secret_violations.iter().any(|s| s.contains("GitHub Personal Access Token"))); |
| 197 | } |
| 198 | |
| 199 | #[test] |
| 200 | fn test_plaintext_secret_github_fine_grained_pat() { |
| 201 | let diff = "diff --git a/src/auth.rs b/src/auth.rs\n+let token = \"github_pat_11AAAAAAA01234567890abcdefghijklmnopqrstuvwxyz_01234567890abcdef\";"; |
| 202 | let report = DiffAuditor::audit_text(diff); |
| 203 | assert!(!report.clean); |
| 204 | assert!(report.secret_violations.iter().any(|s| s.contains("GitHub Personal Access Token"))); |
| 205 | } |
| 206 | |
| 207 | #[test] |
| 208 | fn test_plaintext_secret_rsa_private_key() { |
| 209 | let diff = "diff --git a/src/crypto.rs b/src/crypto.rs\n+const KEY: &str = \"-----BEGIN RSA PRIVATE KEY-----\\nMIIEowIBAAKCAQEA...\";"; |
| 210 | let report = DiffAuditor::audit_text(diff); |
| 211 | assert!(!report.clean); |
| 212 | assert!(report.secret_violations.iter().any(|s| s.contains("Private Key header"))); |
| 213 | } |
| 214 | |
| 215 | #[test] |
| 216 | fn test_plaintext_secret_generic_private_key() { |
| 217 | let diff = "diff --git a/src/crypto.rs b/src/crypto.rs\n+const KEY: &str = \"-----BEGIN PRIVATE KEY-----\\nMIIEowIBAAKCAQEA...\";"; |
| 218 | let report = DiffAuditor::audit_text(diff); |
| 219 | assert!(!report.clean); |
| 220 | assert!(report.secret_violations.iter().any(|s| s.contains("Private Key header"))); |
| 221 | } |
| 222 | |
| 223 | #[test] |
| 224 | fn test_env_file_addition_root() { |
| 225 | let diff = "diff --git a/.env b/.env\nnew file mode 100644\n--- /dev/null\n+++ b/.env\n@@ -0,0 +1,2 @@\n+PORT=8080\n+HOST=127.0.0.1"; |
| 226 | let report = DiffAuditor::audit_text(diff); |
| 227 | assert!(!report.clean); |
| 228 | assert!(report.violations.iter().any(|v| v.contains(".env"))); |
| 229 | } |
| 230 | |
| 231 | #[test] |
| 232 | fn test_env_file_addition_nested() { |
| 233 | let diff = "diff --git a/crates/backend/.env.production b/crates/backend/.env.production\nnew file mode 100644\n--- /dev/null\n+++ b/crates/backend/.env.production\n@@ -0,0 +1,1 @@\n+NODE_ENV=production"; |
| 234 | let report = DiffAuditor::audit_text(diff); |
| 235 | assert!(!report.clean); |
| 236 | assert!(report.violations.iter().any(|v| v.contains(".env"))); |
| 237 | } |
| 238 | |
| 239 | #[test] |
| 240 | fn test_false_positive_markdown_lists() { |
| 241 | let diff = "diff --git a/docs/README.md b/docs/README.md\n+- First item in checklist\n+- Second item in checklist\n+* Third item in checklist"; |
| 242 | let report = DiffAuditor::audit_text(diff); |
| 243 | assert!(report.clean); |
| 244 | } |
| 245 | |
| 246 | #[test] |
| 247 | fn test_false_positive_negative_numbers_and_subtraction() { |
| 248 | let diff = "diff --git a/src/calc.rs b/src/calc.rs\n+let delta = a - b;\n+let temp = -40;\n+let offset = x - y - z;"; |
| 249 | let report = DiffAuditor::audit_text(diff); |
| 250 | assert!(report.clean); |
| 251 | } |
| 252 | |
| 253 | #[test] |
| 254 | fn test_false_positive_standard_hyphenated_words() { |
| 255 | let diff = "diff --git a/src/arch.rs b/src/arch.rs\n+// Zero-telemetry multi-threaded aarch64-unknown-linux-gnu runtime\npub const TARGET: &str = \"aarch64-unknown-linux-gnu\";"; |
| 256 | let report = DiffAuditor::audit_text(diff); |
| 257 | assert!(report.clean); |
| 258 | } |