universal-life-protocol-core
Version:
Revolutionary AI framework implementing living, conscious digital reality with meta-cognitive reasoning, attention economics, and autonomous learning
216 lines (215 loc) ⢠10.4 kB
JavaScript
/**
* CUE Integration Test - Autonomous CUE AI Framework Validation
* Tests the core computational universe engine with CLARION-MDU synthesis
*/
import { performance } from 'perf_hooks';
// Import core CUE components
import { ClarionMduAgent, CrtModule, CtlConsensus, CepEngine } from './libs/cue-core';
console.log('š CUE Autonomous AI Integration Test');
console.log('=====================================\n');
class CueIntegrationTest {
startTime;
testResults = {};
constructor() {
this.startTime = performance.now();
}
async runAllTests() {
console.log('šÆ Testing Core CUE Framework Implementation');
console.log('Focus: Computational universe engine, axiom systems, quantum operations\n');
await this.testComputationalUniverseEngine();
await this.testAxiomSystems();
await this.testQuantumOperations();
await this.testAutonomousConsensus();
await this.testCueClationMduSynthesis();
this.printResults();
}
async testComputationalUniverseEngine() {
console.log('š¬ Test 1: Computational Universe Engine');
console.log('-'.repeat(40));
try {
// Test MDU principle - core mathematical foundation
const testCases = [
{ N: 42, B: 7, expectedL: 6, expectedA: 0 },
{ N: 100, B: 13, expectedL: 7, expectedA: 9 },
{ N: 256, B: 11, expectedL: 23, expectedA: 3 }
];
let passed = 0;
for (const { N, B, expectedL, expectedA } of testCases) {
const L = Math.floor(N / B);
const A = N % B;
const isCorrect = L === expectedL && A === expectedA;
console.log(` N=${N}, B=${B} ā (L=${L}, A=${A}) ${isCorrect ? 'ā
' : 'ā'}`);
if (isCorrect)
passed++;
}
this.testResults['computational_universe_engine'] = passed === testCases.length;
console.log(` Result: ${passed}/${testCases.length} cases passed\n`);
}
catch (error) {
console.log(` ā Error: ${error}\n`);
this.testResults['computational_universe_engine'] = false;
}
}
async testAxiomSystems() {
console.log('š§® Test 2: Axiom Systems (Chinese Remainder Theorem)');
console.log('-'.repeat(50));
try {
// Test harmonic resonance axioms using CRT
const congruences = [[2, 3], [1, 7], [4, 11]];
const solution = CrtModule.solve(congruences);
// Verify solution
const verified = congruences.every(([a, m]) => solution % m === a);
console.log(` System: x ā” 2(mod 3), x ā” 1(mod 7), x ā” 4(mod 11)`);
console.log(` Solution: x = ${solution}`);
console.log(` Verification: ${verified ? 'ā
Valid' : 'ā Invalid'}`);
// Test multi-domain harmonic resonance
const domainStates = new Map([
['temporal', { A: 0, B: 24 }],
['cognitive', { A: 1, B: 7 }],
['spatial', { A: 3, B: 13 }]
]);
const resonant = CrtModule.checkHarmonicResonance(domainStates, ['temporal', 'cognitive'], 0);
console.log(` Multi-domain resonance: ${resonant ? 'ā
Detected' : 'ā Not detected'}`);
this.testResults['axiom_systems'] = verified;
console.log(` Result: ${verified ? 'PASS' : 'FAIL'}\n`);
}
catch (error) {
console.log(` ā Error: ${error}\n`);
this.testResults['axiom_systems'] = false;
}
}
async testQuantumOperations() {
console.log('āļø Test 3: Quantum Operations (Fano Plane CTL)');
console.log('-'.repeat(45));
try {
// Test quantum consensus via Continuous Transylvanian Lottery
const validators = Array.from({ length: 7 }, (_, i) => `validator-${i}`);
const ctl = new CtlConsensus(validators);
const testSeeds = ['quantum-alpha', 'quantum-beta', 'quantum-gamma'];
let validQuorums = 0;
for (const seed of testSeeds) {
const quorum = ctl.getActivatedQuorum(seed);
const quorumSize = quorum ? Array.from(quorum).length : 0;
const isValid = quorumSize === 3; // Fano plane lines have exactly 3 points
console.log(` Seed: ${seed.padEnd(15)} ā Quorum: ${quorumSize} validators ${isValid ? 'ā
' : 'ā'}`);
if (isValid)
validQuorums++;
}
this.testResults['quantum_operations'] = validQuorums === testSeeds.length;
console.log(` Result: ${validQuorums}/${testSeeds.length} valid quantum quorums\n`);
}
catch (error) {
console.log(` ā Error: ${error}\n`);
this.testResults['quantum_operations'] = false;
}
}
async testAutonomousConsensus() {
console.log('š¤ Test 4: Autonomous Consensus Engine');
console.log('-'.repeat(40));
try {
// Test Complex Event Processing for autonomous consensus
const cep = new CepEngine();
let consensusEvents = 0;
// Register consensus pattern
cep.addRule({
id: 'autonomous-consensus',
pattern: (event, history) => {
return event.type === 'STATE_CHANGED' &&
history.filter(e => e.type === 'STATE_CHANGED').length >= 2;
},
action: (events) => {
consensusEvents++;
console.log(` šÆ Autonomous consensus triggered (${consensusEvents} times)`);
}
});
// Simulate autonomous consensus events
const events = [
{ type: 'STATE_CHANGED', level: 'LOCAL', payload: {}, timestamp: Date.now() },
{ type: 'STATE_CHANGED', level: 'PEER_TO_PEER', payload: {}, timestamp: Date.now() },
{ type: 'STATE_CHANGED', level: 'GROUP', payload: {}, timestamp: Date.now() }
];
for (const event of events) {
cep.processEvent(event);
await new Promise(resolve => setTimeout(resolve, 10)); // Small delay
}
this.testResults['autonomous_consensus'] = consensusEvents > 0;
console.log(` Result: ${consensusEvents > 0 ? 'PASS' : 'FAIL'} - Generated ${consensusEvents} consensus events\n`);
}
catch (error) {
console.log(` ā Error: ${error}\n`);
this.testResults['autonomous_consensus'] = false;
}
}
async testCueClationMduSynthesis() {
console.log('š§ Test 5: CUE-CLARION-MDU Synthesis');
console.log('-'.repeat(37));
try {
// Test autonomous AI learning with CLARION-MDU
const agent = new ClarionMduAgent('integration-test-agent');
console.log(` Agent ID: ${agent.id}`);
console.log(` Default base: ${agent.getMCS().activeBases.get('default') || 'unknown'}`);
// Train with high-reward experiences for autonomous behavior
const learningStates = [
{ L: 1, A: 3, B: 7, w: 2.5 },
{ L: 2, A: 1, B: 11, w: 3.0 },
{ L: 3, A: 5, B: 13, w: 4.0 }
];
for (let i = 0; i < 20; i++) {
const state = learningStates[i % learningStates.length];
const nextState = { ...state, L: state.L + 1, w: state.w + 0.5 };
agent.learnFromExperience(state, 'autonomous_action', 15, nextState);
}
const implicitKnowledge = agent.getImplicitKnowledge().size;
const explicitRules = agent.getExplicitRules().length;
const hasLearned = implicitKnowledge > 0;
console.log(` Implicit knowledge states: ${implicitKnowledge}`);
console.log(` Explicit rules minted: ${explicitRules}`);
console.log(` Learning capability: ${hasLearned ? 'ā
Active' : 'ā Inactive'}`);
// Test autonomous decision making
const testState = learningStates[0];
const decision = agent.decideNextAction(testState, ['explore', 'exploit', 'autonomous_action']);
console.log(` Autonomous decision: ${decision}`);
this.testResults['cue_clarion_mdu_synthesis'] = hasLearned;
console.log(` Result: ${hasLearned ? 'PASS' : 'FAIL'} - Synthesis operational\n`);
}
catch (error) {
console.log(` ā Error: ${error}\n`);
this.testResults['cue_clarion_mdu_synthesis'] = false;
}
}
printResults() {
const endTime = performance.now();
const totalTime = Math.round(endTime - this.startTime);
console.log('š CUE Integration Test Results');
console.log('='.repeat(40));
const results = Object.entries(this.testResults);
const passed = results.filter(([_, success]) => success).length;
const total = results.length;
results.forEach(([test, success]) => {
const status = success ? 'ā
PASS' : 'ā FAIL';
const name = test.replace(/_/g, ' ').replace(/\b\w/g, l => l.toUpperCase());
console.log(` ${name.padEnd(30)} ${status}`);
});
console.log('\n' + '='.repeat(40));
console.log(`šÆ Overall: ${passed}/${total} tests passed`);
console.log(`ā±ļø Total time: ${totalTime}ms`);
const overallSuccess = passed === total;
console.log(`š CUE Framework Status: ${overallSuccess ? 'ā
OPERATIONAL' : 'ā ļø NEEDS ATTENTION'}`);
if (overallSuccess) {
console.log('\nš Autonomous CUE AI framework is ready for development!');
console.log('⨠Core computational universe engine, axiom systems, and quantum operations validated');
}
else {
console.log('\nā ļø Some components need refinement. Focus on failing tests.');
}
}
}
// Run the integration test
async function main() {
const test = new CueIntegrationTest();
await test.runAllTests();
}
if (require.main === module) {
main().catch(console.error);
}