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-rsi-mv/blob/main/tests/test_soak_run.rs # spark-rsi-mv Native Rust recursive self-improvement engine with paired bootstrap evaluation and cryptographic ledger 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-rsi-mv / tests / test_soak_run.rs` 189 lines ยท 7089 bytes Raw Blame History 1 use p256::ecdsa::SigningKey; 2 use spark_rsi::ledger::ImprovementLedger; 3 use spark_rsi::soak::{ 4 AdmittedMetaCandidate, CycleCandidateRecord, CycleRecord, EngineNSnapshot, 5 HypothesisQuarantineTracker, SoakConfig, SoakRunManifest, SoakRunner, ThermalSnapshot, 6 }; 7 use std::fs; 8 9 #[test] 10 fn test_hypothesis_quarantine_exhaustion_after_3_failures() { 11 let mut tracker = HypothesisQuarantineTracker::new(); 12 let node = "Propose"; 13 let problem = "High latency on Propose: betweenness centrality bottleneck"; 14 15 assert!(!tracker.is_exhausted(node, problem)); 16 17 // Failure 1 18 let newly_exhausted_1 = tracker.record_failure(node, problem, "Compilation error in Jail 1"); 19 assert!(!newly_exhausted_1); 20 assert!(!tracker.is_exhausted(node, problem)); 21 22 // Failure 2 23 let newly_exhausted_2 = tracker.record_failure(node, problem, "Invariants failed"); 24 assert!(!newly_exhausted_2); 25 assert!(!tracker.is_exhausted(node, problem)); 26 27 // Failure 3: Triggers quarantine exhaustion 28 let newly_exhausted_3 = 29 tracker.record_failure(node, problem, "Blind judge non-inferiority exceeded"); 30 assert!(newly_exhausted_3); 31 assert!(tracker.is_exhausted(node, problem)); 32 33 let exhausted = tracker.exhausted_list(); 34 assert_eq!(exhausted.len(), 1); 35 36 // Success resets exhaustion 37 tracker.record_success(node, problem); 38 assert!(!tracker.is_exhausted(node, problem)); 39 assert!(tracker.exhausted_list().is_empty()); 40 } 41 42 #[test] 43 fn test_thermal_snapshot_and_engine_snapshot() { 44 let thermal = ThermalSnapshot::capture(); 45 if let Some(ref t) = thermal { 46 assert!(!t.timestamp.is_empty()); 47 } 48 49 let engine_n = EngineNSnapshot { 50 commit_sha: "`abc123def456`".to_string(), 51 evaluator_version: "0.1.0".to_string(), 52 holdout_bundle_digest: "sha256:holdouts-bundle-v1".to_string(), 53 builder_digest: "sha256:spark-rsi-builder-pinned".to_string(), 54 model_id: "atlas-lightning-omni".to_string(), 55 cortex_snapshot_ref: "2026-09-19T00:00:00Z".to_string(), 56 operator_verifying_key: Some("`04aabbcc`...".to_string()), 57 }; 58 59 assert_eq!(engine_n.commit_sha, "`abc123def456`"); 60 assert_eq!(engine_n.model_id, "atlas-lightning-omni"); 61 } 62 63 #[test] 64 fn test_soak_manifest_serialization_and_roundtrip() { 65 let tmp = tempfile::tempdir().unwrap(); 66 let manifest_path = tmp.path().join("soak_manifest.json"); 67 68 let engine_n = EngineNSnapshot { 69 commit_sha: "test-sha".to_string(), 70 evaluator_version: "0.1.0".to_string(), 71 holdout_bundle_digest: "digest-1".to_string(), 72 builder_digest: "digest-2".to_string(), 73 model_id: "atlas-lightning-omni".to_string(), 74 cortex_snapshot_ref: "now".to_string(), 75 operator_verifying_key: None, 76 }; 77 78 let manifest = SoakRunManifest { 79 manifest_version: "1.0.0".to_string(), 80 run_id: "soak-test-01".to_string(), 81 started_at: "2026-09-19T20:00:00Z".to_string(), 82 completed_at: "2026-09-19T20:30:00Z".to_string(), 83 engine_n_snapshot: engine_n, 84 cycles: vec![CycleRecord { 85 cycle_index: 1, 86 cycle_id: "soak-c01".to_string(), 87 bottleneck_node: "Propose".to_string(), 88 hypothesis_id: "hypo-01".to_string(), 89 hypothesis_problem: "High latency".to_string(), 90 candidates: vec![CycleCandidateRecord { 91 candidate_id: "cand-01".to_string(), 92 candidate_index: 1, 93 target_file: "src/propose/hypothesis.rs".to_string(), 94 proposed_patch_digest: "digest".to_string(), 95 compilation_passed: true, 96 invariants_passed: true, 97 judge_admitted: true, 98 primary_metric_name: "latency_delta_pct".to_string(), 99 primary_metric_value: -5.2, 100 rejection_reason: None, 101 ledger_block_hash: Some("blockhash01".to_string()), 102 }], 103 winning_candidate_id: Some("cand-01".to_string()), 104 merkle_checkpoint_hash: Some("merkleroot01".to_string()), 105 thermal_before: None, 106 thermal_after: None, 107 cortex_receipt_id: Some("receipt-01".to_string()), 108 status: "COMPLETED".to_string(), 109 }], 110 admitted_candidates: vec![AdmittedMetaCandidate { 111 candidate_id: "cand-01".to_string(), 112 ledger_block_hash: "blockhash01".to_string(), 113 staging_dir: ".rsi/admitted/blockhash01".to_string(), 114 patch_digest: "patchdigest01".to_string(), 115 criteria_1_novel_discovery: true, 116 criteria_2_self_capability_gain: true, 117 classification: "META_CANDIDATE".to_string(), 118 }], 119 exhausted_hypotheses: vec![], 120 final_merkle_checkpoint: Some("merkleroot01".to_string()), 121 total_candidates_evaluated: 1, 122 total_candidates_admitted: 1, 123 preflight_passed: true, 124 overall_status: "SUCCESS".to_string(), 125 }; 126 127 manifest 128 .save_to_file(&manifest_path) 129 .expect("Failed to save manifest"); 130 assert!(manifest_path.exists()); 131 132 let raw = fs::read_to_string(&manifest_path).unwrap(); 133 let loaded: SoakRunManifest = serde_json::from_str(&raw).unwrap(); 134 assert_eq!(loaded.run_id, "soak-test-01"); 135 assert_eq!(loaded.cycles.len(), 1); 136 assert_eq!(loaded.admitted_candidates.len(), 1); 137 assert_eq!(loaded.overall_status, "SUCCESS"); 138 } 139 140 #[tokio::test] 141 async fn test_soak_preflight_fails_closed_without_valid_key() { 142 let tmp = tempfile::tempdir().unwrap(); 143 let rsi_dir = tmp.path().join(".rsi"); 144 fs::create_dir_all(&rsi_dir).unwrap(); 145 146 let mut config = SoakConfig::default(); 147 config.target_repo = tmp.path().display().to_string(); 148 config.rsi_root = ".rsi".to_string(); 149 config.signing_key_hex = None; 150 151 let res = SoakRunner::run_batch(&config).await; 152 assert!(res.is_err()); 153 let err = res.unwrap_err(); 154 assert!(err.contains("signing_key_hex")); 155 } 156 157 #[tokio::test] 158 async fn test_soak_preflight_fails_closed_missing_holdouts() { 159 let tmp = tempfile::tempdir().unwrap(); 160 let rsi_dir = tmp.path().join(".rsi"); 161 fs::create_dir_all(&rsi_dir).unwrap(); 162 fs::write( 163 tmp.path().join("Cargo.toml"), 164 "[package]\nname = \"test\"\nversion = \"0.1.0\"\nedition = \"2021\"\n", 165 ) 166 .unwrap(); 167 168 let _ledger = ImprovementLedger::open(&rsi_dir).unwrap(); 169 170 let sk = SigningKey::from_bytes(&[77u8; 32].into()).unwrap(); 171 let sk_hex = hex::encode(sk.to_bytes()); 172 173 let mut config = SoakConfig::default(); 174 config.target_repo = tmp.path().display().to_string(); 175 config.rsi_root = ".rsi".to_string(); 176 config.signing_key_hex = Some(sk_hex); 177 config.holdouts_dir = Some( 178 tmp.path() 179 .join("non_existent_holdouts") 180 .display() 181 .to_string(), 182 ); 183 184 let res = SoakRunner::run_batch(&config).await; 185 assert!(res.is_err()); 186 let err = res.unwrap_err(); 187 assert!(err.contains("Preflight")); 188 assert!(err.contains("holdouts")); 189 }