File size: 5,698 Bytes
0a93d9c | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 | // Copyright 2026 Bel Esprit D'Accord Irrevocable Trust (EIN: 42-697643)
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// OR
//
// Licensed under the GNU Affero General Public License, Version 3.0
// (the "AGPL"); you may not use this file except in compliance with the AGPL.
// You may obtain a copy of the AGPL at
//
// https://www.gnu.org/licenses/agpl-3.0.html
//! 10,000-Epoch Simulation Test for AutomatedOperator
//!
//! This test validates the core invariants under extended operation:
//! - P2: Entropy bound never exceeded
//! - P4: Determinism (same seed → same sequence)
//! - P6: Sovereign compliance enforced
//! - P7: No mode collapse (novelty > 0.30)
use automated_operator::{AutomatedOperator, Ed25519PublicKey, ScoreWeights, ENTROPY_BOUND};
#[test]
fn execute_10k_operator_simulation() {
let anchor = Ed25519PublicKey([0xFF; 32]);
let seed = [42u8; 32];
let mut operator = AutomatedOperator::new(seed, anchor, ScoreWeights::DEFAULT);
let total_iterations = 10_000;
let mut entropy_violations = 0;
let mut null_generations = 0;
let mut novelties = Vec::with_capacity(total_iterations);
for epoch in 0..total_iterations {
// Phase 1 & 2: Generate, Score, and Select
if let Some(obj) = operator.next_objective() {
// Invariant Check: P2 (Entropy Bound)
if operator.state().entropy_budget < 0.0 || operator.state().entropy_budget > ENTROPY_BOUND {
entropy_violations += 1;
}
// Invariant Check: P6 (Sovereign Compliance)
assert_eq!(
obj.target_space_hash[0],
anchor.0[0],
"Sovereign compliance violation at epoch {}", epoch
);
// Track novelty to prove P7 (Non-Triviality / No Mode Collapse)
let novelty = operator.novelty_estimate(&obj);
novelties.push(novelty);
// Phase 3 & 4: Simulate Engine Result Pipeline
let mock_result_hash = [epoch as u8; 32];
let mock_proof_hash = [0xAA; 32];
operator.receive_result(mock_result_hash, mock_proof_hash);
} else {
// Null generation occurs if entropy budget requires relaxing
null_generations += 1;
}
}
// --- Simulation Diagnostics ---
let avg_novelty: f32 = novelties.iter().sum::<f32>() / novelties.len() as f32;
let min_novelty = novelties.iter().fold(f32::INFINITY, |a, &b| a.min(b));
let max_novelty = novelties.iter().fold(f32::NEG_INFINITY, |a, &b| a.max(b));
println!("========================================");
println!("AUTOMATED OPERATOR: 10K SIMULATION RUN");
println!("========================================");
println!("Total Epochs: {}", total_iterations);
println!("Valid Objectives: {}", novelties.len());
println!("Null Generations: {} (Budget Relaxations)", null_generations);
println!("Entropy Violations: {}", entropy_violations);
println!("----------------------------------------");
println!("Novelty Distribution:");
println!(" Average: {:.4}", avg_novelty);
println!(" Minimum: {:.4}", min_novelty);
println!(" Maximum: {:.4}", max_novelty);
println!("========================================");
// Hard Assertions for CI Pipeline
assert_eq!(entropy_violations, 0, "FATAL: Entropy budget was breached.");
assert!(avg_novelty > 0.30, "FATAL: Mode collapse detected. Novelty too low: {}", avg_novelty);
assert!(novelties.len() > 9000, "FATAL: Too many null generations, operator stalled.");
}
#[test]
fn test_determinism_same_seed_same_sequence() {
let seed = [42u8; 32];
let anchor = Ed25519PublicKey([1u8; 32]);
let mut op1 = AutomatedOperator::new(seed, anchor, ScoreWeights::DEFAULT);
let mut op2 = AutomatedOperator::new(seed, anchor, ScoreWeights::DEFAULT);
for epoch in 0..100 {
let o1 = op1.next_objective();
let o2 = op2.next_objective();
assert_eq!(o1, o2, "Determinism violated at epoch {}", epoch);
if o1.is_some() {
op1.receive_result([1u8; 32], [2u8; 32]);
op2.receive_result([1u8; 32], [2u8; 32]);
}
}
}
#[test]
fn test_sovereign_compliance_enforced() {
let anchor = Ed25519PublicKey([0xFFu8; 32]);
let mut op = AutomatedOperator::new([0u8; 32], anchor, ScoreWeights::DEFAULT);
for epoch in 0..1000 {
if let Some(obj) = op.next_objective() {
assert_eq!(obj.target_space_hash[0], 0xFF, "Sovereign compliance violation at epoch {}", epoch);
op.receive_result([1u8; 32], [2u8; 32]);
}
}
}
#[test]
fn test_novelty_increases_over_time() {
let mut op = AutomatedOperator::new([0u8; 32], Ed25519PublicKey([0xFF; 32]), ScoreWeights::DEFAULT);
let mut novelties = Vec::new();
for _ in 0..50 {
if let Some(obj) = op.next_objective() {
let novelty = op.novelty_estimate(&obj);
novelties.push(novelty);
op.receive_result([1u8; 32], [2u8; 32]);
}
}
let avg_novelty: f32 = novelties.iter().sum::<f32>() / novelties.len() as f32;
println!("Average novelty over 50 epochs: {:.4}", avg_novelty);
assert!(avg_novelty > 0.30, "Average novelty too low: {}", avg_novelty);
} |