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 / tier3_cross_feature.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 | // Tier 3: Cross-Feature Combinations and Subsystem Interaction Tests |
| 17 | // Strictly adheres to sovereign unslop invariants: zero em dashes, zero en dashes. |
| 18 | |
| 19 | use spark_adapters::curriculum::{CurriculumEngine, CurriculumTrack}; |
| 20 | use spark_adapters::models::{ChatMessage, ProviderType, VerificationStrategy}; |
| 21 | use spark_adapters::providers::format_openai_payload; |
| 22 | use spark_adapters::router::AdapterRouter; |
| 23 | use spark_adapters::vault::{resolve_secret, sanitize_outbound_prompt}; |
| 24 | use spark_adapters::verifier::Verifier; |
| 25 | use std::fs; |
| 26 | use std::io::Write; |
| 27 | use std::process::Command; |
| 28 | |
| 29 | #[test] |
| 30 | fn test_t3_01_sanitizer_router_dispatch_interaction() { |
| 31 | let raw_prompt = "Load /home/alice/workspace/main.rs from 10.0.0.5 for drakestapleton with sk-proj-12345678901234567890"; |
| 32 | let clean_prompt = sanitize_outbound_prompt(raw_prompt); |
| 33 | |
| 34 | assert!(!clean_prompt.contains("/home/alice")); |
| 35 | assert!(!clean_prompt.contains("10.0.0.5")); |
| 36 | assert!(!clean_prompt.contains("drakestapleton")); |
| 37 | assert!(!clean_prompt.contains("sk-proj-")); |
| 38 | |
| 39 | let router = AdapterRouter::new(); |
| 40 | let (provider, endpoint, model, key) = router.resolve_route("atlas-lightning-omni"); |
| 41 | assert_eq!(provider, ProviderType::LocalSeat); |
| 42 | assert_eq!(endpoint, "http://127.0.0.1:18006/v1/chat/completions"); |
| 43 | assert_eq!(model, "atlas-lightning-omni"); |
| 44 | assert!(key.is_none()); |
| 45 | |
| 46 | let msgs = vec![ChatMessage { |
| 47 | role: "user".to_string(), |
| 48 | content: clean_prompt.clone(), |
| 49 | reasoning: None, |
| 50 | }]; |
| 51 | let payload = format_openai_payload(&model, &msgs, Some(0.7), false); |
| 52 | assert_eq!(payload["messages"][0]["content"], clean_prompt); |
| 53 | } |
| 54 | |
| 55 | #[test] |
| 56 | fn test_t3_02_verifier_consensus_cortex_qualification_gate() { |
| 57 | let teacher = "pub fn sum_slice(s: &[i32]) -> i32 { s.iter().sum() }"; |
| 58 | let student = "pub fn sum_slice(arr: &[i32]) -> i32 { arr.iter().sum() }"; |
| 59 | |
| 60 | let sim = Verifier::hybrid_consensus(teacher, student); |
| 61 | assert!( |
| 62 | sim > 0.60, |
| 63 | "Consensus similarity between semantically equivalent code must exceed 0.60" |
| 64 | ); |
| 65 | |
| 66 | let t_verif = Verifier::verify(teacher, VerificationStrategy::CompilerCheck); |
| 67 | assert!(t_verif.passed); |
| 68 | assert_eq!(t_verif.score, 1.0); |
| 69 | |
| 70 | let s_verif = Verifier::verify(student, VerificationStrategy::CompilerCheck); |
| 71 | assert!(s_verif.passed); |
| 72 | assert_eq!(s_verif.score, 1.0); |
| 73 | |
| 74 | let qualifies_for_cortex = t_verif.passed && t_verif.score >= 0.85; |
| 75 | assert!( |
| 76 | qualifies_for_cortex, |
| 77 | "Verified high-scoring solution must qualify for Cortex storage" |
| 78 | ); |
| 79 | } |
| 80 | |
| 81 | #[test] |
| 82 | fn test_t3_03_crawler_curriculum_dataset_emission_pipeline() { |
| 83 | let tasks = CurriculumEngine::generate_tasks( |
| 84 | CurriculumTrack::NativeSystemsAndGpu, |
| 85 | 2, |
| 86 | "anthropic/claude-3-7-sonnet", |
| 87 | Some("atlas-lightning-omni"), |
| 88 | false, |
| 89 | ); |
| 90 | assert_eq!(tasks.len(), 2); |
| 91 | |
| 92 | let temp_dir = |
| 93 | std::env::temp_dir().join(format!("test_crawl_emission_{}", uuid::Uuid::new_v4())); |
| 94 | fs::create_dir_all(&temp_dir).expect("create temp dataset dir"); |
| 95 | |
| 96 | let sft_file = temp_dir.join("sft.jsonl"); |
| 97 | let dpo_file = temp_dir.join("dpo.jsonl"); |
| 98 | |
| 99 | let mut sft_writer = fs::OpenOptions::new() |
| 100 | .create(true) |
| 101 | .append(true) |
| 102 | .open(&sft_file) |
| 103 | .unwrap(); |
| 104 | let mut dpo_writer = fs::OpenOptions::new() |
| 105 | .create(true) |
| 106 | .append(true) |
| 107 | .open(&dpo_file) |
| 108 | .unwrap(); |
| 109 | |
| 110 | for task in &tasks { |
| 111 | let chosen = "pub fn execute() -> bool { true }"; |
| 112 | let rejected = "pub fn execute() -> bool { false }"; |
| 113 | let delta = 0.30; |
| 114 | |
| 115 | let sft_obj = serde_json::json!({ |
| 116 | "task_id": task.id, |
| 117 | "timestamp": chrono::Utc::now().to_rfc3339(), |
| 118 | "messages": [ |
| 119 | { "role": "system", "content": task.system_prompt }, |
| 120 | { "role": "user", "content": task.prompt }, |
| 121 | { "role": "assistant", "content": chosen } |
| 122 | ] |
| 123 | }); |
| 124 | writeln!(sft_writer, "{}", serde_json::to_string(&sft_obj).unwrap()).unwrap(); |
| 125 | |
| 126 | if delta > 0.0 && chosen != rejected { |
| 127 | let dpo_obj = serde_json::json!({ |
| 128 | "task_id": task.id, |
| 129 | "prompt": task.prompt, |
| 130 | "chosen": chosen, |
| 131 | "rejected": rejected, |
| 132 | "timestamp": chrono::Utc::now().to_rfc3339() |
| 133 | }); |
| 134 | writeln!(dpo_writer, "{}", serde_json::to_string(&dpo_obj).unwrap()).unwrap(); |
| 135 | } |
| 136 | } |
| 137 | |
| 138 | let sft_content = fs::read_to_string(&sft_file).unwrap(); |
| 139 | let dpo_content = fs::read_to_string(&dpo_file).unwrap(); |
| 140 | |
| 141 | assert_eq!(sft_content.lines().count(), 2); |
| 142 | assert_eq!(dpo_content.lines().count(), 2); |
| 143 | |
| 144 | fs::remove_dir_all(&temp_dir).unwrap(); |
| 145 | } |
| 146 | |
| 147 | #[test] |
| 148 | fn test_t3_04_vault_token_cortex_http_dispatch() { |
| 149 | let token_opt = resolve_secret("CORTEX_TOKEN"); |
| 150 | if std::env::var("CI").is_ok() && token_opt.is_none() { |
| 151 | return; |
| 152 | } |
| 153 | assert!( |
| 154 | token_opt.is_some(), |
| 155 | "CORTEX_TOKEN must resolve via vault or environment" |
| 156 | ); |
| 157 | let token = token_opt.unwrap(); |
| 158 | assert!(!token.trim().is_empty()); |
| 159 | |
| 160 | let auth_header = format!("Bearer {}", token); |
| 161 | let output = Command::new("curl") |
| 162 | .args([ |
| 163 | "-s", |
| 164 | "-o", |
| 165 | "/dev/null", |
| 166 | "-w", |
| 167 | "%{http_code}", |
| 168 | "-H", |
| 169 | &format!("Authorization: {}", auth_header), |
| 170 | "http://127.0.0.1:18080/api/status", |
| 171 | ]) |
| 172 | .output() |
| 173 | .expect("curl cortex status"); |
| 174 | |
| 175 | let code = String::from_utf8_lossy(&output.stdout).trim().to_string(); |
| 176 | assert!( |
| 177 | !code.is_empty(), |
| 178 | "Cortex status check must return HTTP status code" |
| 179 | ); |
| 180 | } |
| 181 | |
| 182 | #[test] |
| 183 | fn test_t3_05_verifier_rustc_unslop_sft_pipeline() { |
| 184 | let dirty_solution = "This is fast \u{2014} implementation.\n```rust\npub fn ok() {}\n```"; |
| 185 | let dirty_outcome = Verifier::verify(dirty_solution, VerificationStrategy::CompilerCheck); |
| 186 | assert!(dirty_outcome |
| 187 | .rule_violations |
| 188 | .iter() |
| 189 | .any(|v| v.contains("em dash"))); |
| 190 | assert!(dirty_outcome.score < 1.0, "Em dash must penalize score"); |
| 191 | |
| 192 | let clean_solution = "Pure Rust implementation.\n```rust\npub fn run_fast() -> i32 { 42 }\n```"; |
| 193 | let clean_outcome = Verifier::verify(clean_solution, VerificationStrategy::CompilerCheck); |
| 194 | assert!( |
| 195 | clean_outcome.passed, |
| 196 | "Clean solution must pass compiler and unslop checks" |
| 197 | ); |
| 198 | assert_eq!(clean_outcome.score, 1.0); |
| 199 | |
| 200 | let sft_entry = serde_json::json!({ |
| 201 | "messages": [ |
| 202 | { "role": "user", "content": "Write fast function" }, |
| 203 | { "role": "assistant", "content": clean_solution } |
| 204 | ] |
| 205 | }); |
| 206 | let sft_str = serde_json::to_string(&sft_entry).unwrap(); |
| 207 | assert!(!sft_str.contains('\u{2014}')); |
| 208 | } |