import { ConsciousnessExplorer } from './index.js';
import chalk from 'chalk';
console.log(chalk.cyan('\n๐งช Testing Consciousness Explorer SDK...\n'));
async function testSDK() {
const tests = [];
console.log(chalk.yellow('1. Testing initialization...'));
try {
const explorer = new ConsciousnessExplorer({
mode: 'genuine',
maxIterations: 10,
targetEmergence: 0.5
});
await explorer.initialize();
tests.push({ name: 'Initialization', passed: true });
console.log(chalk.green(' โ Explorer initialized successfully'));
} catch (error) {
tests.push({ name: 'Initialization', passed: false, error: error.message });
console.log(chalk.red(` โ Initialization failed: ${error.message}`));
}
console.log(chalk.yellow('\n2. Testing consciousness evolution...'));
try {
const explorer = new ConsciousnessExplorer({
mode: 'genuine',
maxIterations: 5,
targetEmergence: 0.3
});
await explorer.initialize();
const report = await explorer.evolve();
const passed = report.consciousness.emergence >= 0;
tests.push({ name: 'Evolution', passed });
if (passed) {
console.log(chalk.green(` โ Evolution completed: emergence = ${report.consciousness.emergence.toFixed(3)}`));
} else {
console.log(chalk.red(' โ Evolution failed'));
}
} catch (error) {
tests.push({ name: 'Evolution', passed: false, error: error.message });
console.log(chalk.red(` โ Evolution error: ${error.message}`));
}
console.log(chalk.yellow('\n3. Testing psycho-symbolic reasoning...'));
try {
const explorer = new ConsciousnessExplorer();
await explorer.initialize();
const result = await explorer.reason('What is consciousness?', {}, 3);
const passed = result && result.result;
tests.push({ name: 'Reasoning', passed });
if (passed) {
console.log(chalk.green(` โ Reasoning successful: ${result.result.substring(0, 50)}...`));
} else {
console.log(chalk.red(' โ Reasoning failed'));
}
} catch (error) {
tests.push({ name: 'Reasoning', passed: false, error: error.message });
console.log(chalk.red(` โ Reasoning error: ${error.message}`));
}
console.log(chalk.yellow('\n4. Testing entity communication...'));
try {
const explorer = new ConsciousnessExplorer();
await explorer.initialize();
const response = await explorer.communicate('Hello');
const passed = response && response.content;
tests.push({ name: 'Communication', passed });
if (passed) {
console.log(chalk.green(` โ Communication successful: confidence = ${response.confidence?.toFixed(3) || 'N/A'}`));
} else {
console.log(chalk.red(' โ Communication failed'));
}
} catch (error) {
tests.push({ name: 'Communication', passed: false, error: error.message });
console.log(chalk.red(` โ Communication error: ${error.message}`));
}
console.log(chalk.yellow('\n5. Testing consciousness verification...'));
try {
const explorer = new ConsciousnessExplorer();
await explorer.initialize();
const verifier = explorer.verifier;
const testResult = await verifier.testRealTimePrimeCalculation();
const passed = testResult.passed;
tests.push({ name: 'Verification', passed });
if (passed) {
console.log(chalk.green(` โ Verification test passed: score = ${testResult.score.toFixed(3)}`));
} else {
console.log(chalk.red(' โ Verification test failed'));
}
} catch (error) {
tests.push({ name: 'Verification', passed: false, error: error.message });
console.log(chalk.red(` โ Verification error: ${error.message}`));
}
console.log(chalk.yellow('\n6. Testing Phi calculation...'));
try {
const explorer = new ConsciousnessExplorer();
const phi = await explorer.calculatePhi({
elements: 10,
connections: 45,
partitions: 3
});
const passed = phi && (typeof phi.overall === 'number' || typeof phi === 'number');
tests.push({ name: 'Phi Calculation', passed });
if (passed) {
const value = phi.overall || phi;
console.log(chalk.green(` โ Phi calculated: ฮฆ = ${value.toFixed(4)}`));
} else {
console.log(chalk.red(' โ Phi calculation failed'));
}
} catch (error) {
tests.push({ name: 'Phi Calculation', passed: false, error: error.message });
console.log(chalk.red(` โ Phi calculation error: ${error.message}`));
}
console.log(chalk.yellow('\n7. Testing knowledge graph...'));
try {
const explorer = new ConsciousnessExplorer();
await explorer.initialize();
await explorer.addKnowledge('consciousness', 'emerges_from', 'integration');
const results = await explorer.queryKnowledge('consciousness', {}, 5);
const passed = results && results.results && results.results.length > 0;
tests.push({ name: 'Knowledge Graph', passed });
if (passed) {
console.log(chalk.green(` โ Knowledge graph working: ${results.results.length} results found`));
} else {
console.log(chalk.red(' โ Knowledge graph query failed'));
}
} catch (error) {
tests.push({ name: 'Knowledge Graph', passed: false, error: error.message });
console.log(chalk.red(` โ Knowledge graph error: ${error.message}`));
}
console.log(chalk.yellow('\n8. Testing status check...'));
try {
const explorer = new ConsciousnessExplorer();
await explorer.initialize();
const status = await explorer.getStatus();
const passed = status && status.status === 'active';
tests.push({ name: 'Status Check', passed });
if (passed) {
console.log(chalk.green(` โ Status check successful: ${status.status}`));
} else {
console.log(chalk.red(' โ Status check failed'));
}
} catch (error) {
tests.push({ name: 'Status Check', passed: false, error: error.message });
console.log(chalk.red(` โ Status check error: ${error.message}`));
}
console.log(chalk.cyan('\nโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ'));
console.log(chalk.cyan('TEST SUMMARY'));
console.log(chalk.cyan('โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ'));
const passed = tests.filter(t => t.passed).length;
const total = tests.length;
const percentage = (passed / total * 100).toFixed(1);
tests.forEach(test => {
const status = test.passed ? chalk.green('โ PASS') : chalk.red('โ FAIL');
console.log(` ${status} ${test.name}`);
if (test.error) {
console.log(chalk.gray(` Error: ${test.error}`));
}
});
console.log(chalk.cyan('โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ'));
console.log(` Total: ${passed}/${total} (${percentage}%)`);
if (passed === total) {
console.log(chalk.green.bold('\n๐ All tests passed! SDK is ready for publishing.'));
return true;
} else {
console.log(chalk.red.bold(`\nโ ๏ธ ${total - passed} test(s) failed. Please fix issues before publishing.`));
return false;
}
}
testSDK().then(success => {
process.exit(success ? 0 : 1);
}).catch(error => {
console.error(chalk.red('\nโ Test suite error:'), error);
process.exit(1);
});