aien-sovereign-core-mv
AienOS host runtime: inference scheduling, paged KV state, the aien CLI and Spark verification tooling. Its inference engine is in alpha testing (DGX Spark GB10); Omega is the implementation destination.
Brought by drakestapleton
aien-sovereign-core-mv / crates / spark-adapters / tests / challenger_m1_sanitizer_adversarial.rs
| 1 | // SPDX-License-Identifier: Apache-2.0 |
| 2 | // Copyright 2026 Drake Stapleton (AIEN / aien-dev) |
| 3 | // |
| 4 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | // you may not use this file except in compliance with the License. |
| 6 | // You may obtain a copy of the License at |
| 7 | // |
| 8 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | // |
| 10 | // Unless required by applicable law or agreed to in writing, software |
| 11 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | // See the License for the specific language governing permissions and |
| 14 | // limitations under the License. |
| 15 | |
| 16 | // Challenger Milestone 1 Adversarial Stress Suite: |
| 17 | // Operator Name Sanitization, Hostname Boundaries, Secret Redaction, and System Prompt Leakage |
| 18 | // Strictly adheres to sovereign unslop invariants: zero em dashes, zero en dashes. |
| 19 | |
| 20 | use spark_adapters::models::{DistillTask, TaskType, VerificationStrategy}; |
| 21 | use spark_adapters::vault::{register_test_secret, sanitize_outbound_prompt}; |
| 22 | |
| 23 | // ============================================================================ |
| 24 | // Challenge 1: Operator Name Boundaries and False Positive Resistance |
| 25 | // ============================================================================ |
| 26 | |
| 27 | #[test] |
| 28 | fn test_challenge1_operator_case_and_whitespace_variants() { |
| 29 | let variants = [ |
| 30 | "Drake Stapleton", |
| 31 | "drake stapleton", |
| 32 | "DRAKE STAPLETON", |
| 33 | "Drake Stapleton", |
| 34 | "Drake\tStapleton", |
| 35 | "Michael Drake Ballentine", |
| 36 | "michael drake ballentine", |
| 37 | "Drake Ballentine", |
| 38 | "Michael Ballentine", |
| 39 | "Ballentine", |
| 40 | "drakestapleton", |
| 41 | "drake.stapleton", |
| 42 | "drake.stapleton@example.com", |
| 43 | "aien@aienos.com", |
| 44 | ]; |
| 45 | |
| 46 | for variant in variants { |
| 47 | let input = format!("Task submitted by {}", variant); |
| 48 | let cleaned = sanitize_outbound_prompt(&input); |
| 49 | assert!( |
| 50 | !cleaned.contains(variant), |
| 51 | "Variant '{}' was not scrubbed in output: '{}'", |
| 52 | variant, |
| 53 | cleaned |
| 54 | ); |
| 55 | assert!( |
| 56 | cleaned.contains("<OPERATOR>"), |
| 57 | "Variant '{}' did not produce <OPERATOR> tag in output: '{}'", |
| 58 | variant, |
| 59 | cleaned |
| 60 | ); |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | #[test] |
| 65 | fn test_challenge1_operator_punctuation_and_delimiter_wrapping() { |
| 66 | let inputs = [ |
| 67 | ("Assignee: (Drake Stapleton)", "Assignee: (<OPERATOR>)"), |
| 68 | ( |
| 69 | "Contact: [drake.stapleton@example.com]", |
| 70 | "Contact: [<OPERATOR>]", |
| 71 | ), |
| 72 | ("Author: 'Drake Stapleton';", "Author: '<OPERATOR>';"), |
| 73 | ( |
| 74 | "Sign-off by \"Michael Drake Ballentine\".", |
| 75 | "Sign-off by \"<OPERATOR>\".", |
| 76 | ), |
| 77 | ( |
| 78 | "User <drakestapleton> authorized run", |
| 79 | "User <<OPERATOR>> authorized run", |
| 80 | ), |
| 81 | ]; |
| 82 | |
| 83 | for (raw, expected) in inputs { |
| 84 | let cleaned = sanitize_outbound_prompt(raw); |
| 85 | assert_eq!( |
| 86 | cleaned, expected, |
| 87 | "Punctuation wrapping mismatch for raw input '{}'", |
| 88 | raw |
| 89 | ); |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | #[test] |
| 94 | fn test_challenge1_operator_negative_preservation() { |
| 95 | // English terms and technical nouns containing substrings must never be corrupted |
| 96 | let benign_texts = [ |
| 97 | "The Drake equation calculates extraterrestrial communications probability", |
| 98 | "Use a heavy-duty staple to bind the document bundle", |
| 99 | "The stapler is located on the desk beside the printer", |
| 100 | "Botanical specimens include mandrake roots and wildflowers", |
| 101 | "The ballistics report confirmed the trajectory", |
| 102 | ]; |
| 103 | |
| 104 | for text in benign_texts { |
| 105 | let cleaned = sanitize_outbound_prompt(text); |
| 106 | assert_eq!( |
| 107 | cleaned, text, |
| 108 | "Benign text must not be corrupted by operator regex: '{}' -> '{}'", |
| 109 | text, cleaned |
| 110 | ); |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | // ============================================================================ |
| 115 | // Challenge 2: Hostname and Network Isolation Boundaries |
| 116 | // ============================================================================ |
| 117 | |
| 118 | #[test] |
| 119 | fn test_challenge2_hostname_and_url_variations() { |
| 120 | let cases = [ |
| 121 | ( |
| 122 | "Connect to http://spark:8080/api/v1", |
| 123 | "Connect to http://<LOCAL_HOST>:8080/api/v1", |
| 124 | ), |
| 125 | ( |
| 126 | "Access grpc endpoint at spark.local:18080", |
| 127 | "Access grpc endpoint at <LOCAL_HOST>:18080", |
| 128 | ), |
| 129 | ( |
| 130 | "Target machine is spark-1a2b:18095", |
| 131 | "Target machine is <LOCAL_HOST>:18095", |
| 132 | ), |
| 133 | ( |
| 134 | "Local binding on http://localhost:3000", |
| 135 | "Local binding on http://<LOCAL_HOST>:3000", |
| 136 | ), |
| 137 | ( |
| 138 | "Remote execution via ssh drakestapleton@spark", |
| 139 | "Remote execution via ssh <OPERATOR>@<LOCAL_HOST>", |
| 140 | ), |
| 141 | ( |
| 142 | "Connecting to spark-1a2b.local now", |
| 143 | "Connecting to <LOCAL_HOST> now", |
| 144 | ), |
| 145 | ]; |
| 146 | |
| 147 | for (raw, expected) in cases { |
| 148 | let cleaned = sanitize_outbound_prompt(raw); |
| 149 | assert_eq!( |
| 150 | cleaned, expected, |
| 151 | "Hostname scrubbing mismatch for input '{}': got '{}'", |
| 152 | raw, cleaned |
| 153 | ); |
| 154 | } |
| 155 | } |
| 156 | |
| 157 | #[test] |
| 158 | fn test_challenge2_preserve_compound_identifiers() { |
| 159 | // System crates and names starting with 'spark' or containing 'spark' must remain untouched |
| 160 | let compound_terms = [ |
| 161 | "Update crates/spark-adapters/src/vault.rs", |
| 162 | "Execute spark-distill crawl --track systems", |
| 163 | "Module spark-mask provides mask generation", |
| 164 | "Background services: spark-supervisor, spark-hive, spark-dream", |
| 165 | "Inspect spark-cockpit-rs dashboard", |
| 166 | "Enjoying a glass of sparkling water while compiling", |
| 167 | ]; |
| 168 | |
| 169 | for term in compound_terms { |
| 170 | let cleaned = sanitize_outbound_prompt(term); |
| 171 | assert_eq!( |
| 172 | cleaned, term, |
| 173 | "Compound term must not be corrupted: '{}' -> '{}'", |
| 174 | term, cleaned |
| 175 | ); |
| 176 | } |
| 177 | } |
| 178 | |
| 179 | #[test] |
| 180 | fn test_challenge2_private_ip_and_path_scrubbing() { |
| 181 | let input = "Download model from 10.0.1.20 and 192.168.0.50 to /home/alice/models/weights.bin on 127.0.0.1"; |
| 182 | let cleaned = sanitize_outbound_prompt(input); |
| 183 | |
| 184 | assert!(!cleaned.contains("10.0.1.20")); |
| 185 | assert!(!cleaned.contains("192.168.0.50")); |
| 186 | assert!(!cleaned.contains("127.0.0.1")); |
| 187 | assert!(!cleaned.contains("/home/alice")); |
| 188 | assert!(cleaned.contains("<LOCAL_HOST>")); |
| 189 | assert!(cleaned.contains("<WORKSPACE_PATH>")); |
| 190 | } |
| 191 | |
| 192 | // ============================================================================ |
| 193 | // Challenge 3: In-Memory Dynamic Secrets and Multiline Keys |
| 194 | // ============================================================================ |
| 195 | |
| 196 | #[test] |
| 197 | fn test_challenge3_dynamic_vault_secret_registration() { |
| 198 | let secret_val = "quantum_crypto_dynamic_pass_77182"; |
| 199 | register_test_secret("M1_CHALLENGE_SECRET", secret_val); |
| 200 | |
| 201 | let prompt = format!( |
| 202 | "Execute query with authorization header Bearer {}", |
| 203 | secret_val |
| 204 | ); |
| 205 | let cleaned = sanitize_outbound_prompt(&prompt); |
| 206 | |
| 207 | assert!( |
| 208 | !cleaned.contains(secret_val), |
| 209 | "Dynamic secret must be scrubbed: '{}'", |
| 210 | cleaned |
| 211 | ); |
| 212 | assert!( |
| 213 | cleaned.contains("[REDACTED_BY_ATLAS_VAULT]"), |
| 214 | "Dynamic secret must be replaced with [REDACTED_BY_ATLAS_VAULT]" |
| 215 | ); |
| 216 | } |
| 217 | |
| 218 | #[test] |
| 219 | fn test_challenge3_multiline_pem_and_signature_patterns() { |
| 220 | let pem = |
| 221 | "-----BEGIN RSA PRIVATE KEY-----\nMIIEowIBAAKCAQEA0\nXYZ789\n-----END RSA PRIVATE KEY-----"; |
| 222 | let prompt = format!("Deploy server certificate and key:\n{}", pem); |
| 223 | let cleaned = sanitize_outbound_prompt(&prompt); |
| 224 | |
| 225 | assert!(!cleaned.contains("MIIEowIBAAKCAQEA0")); |
| 226 | assert!(cleaned.contains("[REDACTED_BY_ATLAS_VAULT]")); |
| 227 | } |
| 228 | |
| 229 | // ============================================================================ |
| 230 | // Challenge 4: System Prompt and Distill Task Verification |
| 231 | // ============================================================================ |
| 232 | |
| 233 | #[test] |
| 234 | fn test_challenge4_system_prompt_sanitization_in_distill_messages() { |
| 235 | let sys = "System instructions for host spark-1a2b running under /home/alice/workspace for Drake Stapleton"; |
| 236 | let cleaned = sanitize_outbound_prompt(sys); |
| 237 | |
| 238 | assert!(!cleaned.contains("spark-1a2b")); |
| 239 | assert!(!cleaned.contains("/home/alice")); |
| 240 | assert!(!cleaned.contains("Drake Stapleton")); |
| 241 | assert!(cleaned.contains("<LOCAL_HOST>")); |
| 242 | assert!(cleaned.contains("<WORKSPACE_PATH>")); |
| 243 | assert!(cleaned.contains("<OPERATOR>")); |
| 244 | } |
| 245 | |
| 246 | #[test] |
| 247 | fn test_challenge4_distill_task_struct_scrubbing_simulation() { |
| 248 | let task = DistillTask { |
| 249 | id: "m1-challenger-task-01".to_string(), |
| 250 | task_type: TaskType::CodeSynthesis, |
| 251 | prompt: "Run benchmark on 192.168.0.5 for drakestapleton".to_string(), |
| 252 | system_prompt: Some("You are an assistant located on spark:18080".to_string()), |
| 253 | teacher_model: "mock-teacher".to_string(), |
| 254 | student_model: None, |
| 255 | verification_strategy: VerificationStrategy::UnslopStrict, |
| 256 | commit_to_cortex: false, |
| 257 | }; |
| 258 | |
| 259 | let scrubbed_user = sanitize_outbound_prompt(&task.prompt); |
| 260 | let scrubbed_sys = task |
| 261 | .system_prompt |
| 262 | .as_ref() |
| 263 | .map(|s| sanitize_outbound_prompt(s)); |
| 264 | |
| 265 | assert!(!scrubbed_user.contains("192.168.0.5")); |
| 266 | assert!(!scrubbed_user.contains("drakestapleton")); |
| 267 | assert!(scrubbed_user.contains("<LOCAL_HOST>")); |
| 268 | assert!(scrubbed_user.contains("<OPERATOR>")); |
| 269 | |
| 270 | let sys_str = scrubbed_sys.unwrap(); |
| 271 | assert!(!sys_str.contains("spark:18080")); |
| 272 | assert!(sys_str.contains("<LOCAL_HOST>:18080")); |
| 273 | } |