Files
wehub-resource-sync 23f7624596
ADR-166 MCP Bridge Security Lock / Static-source security lock (push) Failing after 0s
ADR-166 MCP Bridge Security Lock / Compose default binds loopback + Mongo has auth (push) Failing after 2s
CodeQL Advanced / Analyze (rust) (push) Failing after 0s
ADR-166 MCP Bridge Security Lock / plugin-agent-federation bindHost default (push) Failing after 1s
ADR-166 MCP Bridge Security Lock / Runtime behavior — 401 + terminal gate + fail-closed (push) Failing after 4s
business-pods-smoke / smoke (push) Failing after 1s
all-plugins-smoke / smoke-all (push) Failing after 2s
CI/CD Pipeline / Security & Code Quality (push) Failing after 1s
CI/CD Pipeline / Test Suite (ubuntu-latest) (push) Failing after 1s
CI/CD Pipeline / Build & Package (macos-latest) (push) Has been skipped
CI/CD Pipeline / Build & Package (ubuntu-latest) (push) Has been skipped
CI/CD Pipeline / Build & Package (windows-latest) (push) Has been skipped
CI/CD Pipeline / Documentation & Examples (push) Failing after 1s
Clone Tracker (14-day rolling) / Snapshot clones for ruflo ecosystem (push) Failing after 1s
CodeQL Advanced / Analyze (actions) (push) Failing after 1s
CodeQL Advanced / Analyze (javascript-typescript) (push) Failing after 1s
federation-peer-rust / stable-noop (push) Failing after 1s
metaharness-ci / score (push) Failing after 1s
metaharness-ci / router-compat (push) Failing after 0s
metaharness-ci / similarity-tests (push) Failing after 0s
no-agentbbs-smoke / smoke-without-agentbbs (push) Failing after 1s
V3 CI/CD Pipeline / Build V3 (windows-latest) (push) Has been skipped
codex-integration-audit / Codex integration audit (push) Failing after 1s
helpers-manifest-guard / guard (push) Failing after 1s
🔗 Cross-Agent Integration Tests / 🤝 Agent Coordination Tests (push) Has been skipped
🔗 Cross-Agent Integration Tests / 🧠 Memory Sharing Integration (push) Has been skipped
🔗 Cross-Agent Integration Tests / 🛡️ Fault Tolerance Tests (push) Has been skipped
🔗 Cross-Agent Integration Tests / ⚡ Performance Integration Tests (push) Has been skipped
metaharness-ci / mcp-scan (push) Failing after 1s
metaharness-ci / eject-dryrun (push) Failing after 1s
metaharness-ci / metaharness-real-data (push) Failing after 0s
no-cli-optdep-bloat-2561 / guard (push) Failing after 1s
no-metaharness-smoke / smoke-without-metaharness (push) Failing after 1s
no-phantom-agentic-flow-subpath / guard (push) Failing after 1s
🔄 Automated Rollback Manager / 🚨 Failure Detection (push) Failing after 1s
V3 CI/CD Pipeline / Plugin hooks smoke / ubuntu-latest / Node 22 (push) Failing after 1s
V3 CI/CD Pipeline / ruflo-graph-intelligence build + test smoke (#2044, ADR-123) (push) Failing after 1s
CVE Audit Gate / Audit root (critical-blocking) (push) Failing after 2s
cost-tracker-smoke / smoke (push) Failing after 3s
oia-audit-weekly / audit (push) Failing after 2s
ruflo-agent-smoke / ruflo-agent structural smoke (push) Failing after 1s
📊 Status Badges Update / 📊 Update Status Badges (push) Failing after 1s
V3 CI/CD Pipeline / Static regression guards (#2267 YAML + (push) Failing after 1s
V3 CI/CD Pipeline / Test V3 Packages (push) Failing after 0s
V3 CI/CD Pipeline / agent_execute provider routing smoke (#2042) (push) Failing after 0s
CVE Audit Gate / Audit v3 (critical-blocking) (push) Failing after 1s
federation-peer-rust / stable-native (push) Failing after 2s
🔗 Cross-Agent Integration Tests / 🚀 Integration Test Setup (push) Failing after 2s
neural-trader-smoke / runtime-smoke (push) Failing after 1s
V3 CI/CD Pipeline / Build V3 (macos-latest) (push) Has been skipped
V3 CI/CD Pipeline / Build V3 (ubuntu-latest) (push) Has been skipped
V3 CI/CD Pipeline / Type Check V3 (push) Failing after 1s
V3 CI/CD Pipeline / Smoke (no better-sqlite3) / ubuntu-latest / Node 24 (push) Failing after 1s
V3 CI/CD Pipeline / Smoke (no better-sqlite3) / ubuntu-latest / Node 22 (push) Failing after 2s
V3 CI/CD Pipeline / browser rvf create flag smoke (#2015) (push) Failing after 0s
V3 CI/CD Pipeline / Dependency review (#2046) (push) Has been skipped
V3 CI/CD Pipeline / Supply-chain audit (#2046) (push) Failing after 0s
V3 CI/CD Pipeline / witness marker drift smoke (#2021) (push) Failing after 1s
V3 CI/CD Pipeline / neural-trader portfolio CG smoke (#2068, ADR-126 Phase 3) (push) Failing after 1s
V3 CI/CD Pipeline / neural-trader backtest signing smoke (#2068, ADR-126 Phase 4) (push) Failing after 1s
V3 CI/CD Pipeline / kg-extract type-import classification smoke (#2049) (push) Failing after 0s
V3 CI/CD Pipeline / witness verify precondition smoke (#1880) (push) Failing after 2s
V3 CI/CD Pipeline / neural-trader pipeline risk-gate smoke (#2068, ADR-126 Phase 5) (push) Failing after 0s
V3 CI/CD Pipeline / neural-trader feature attribution smoke (#2068, ADR-126 Phase 6) (push) Failing after 0s
V3 CI/CD Pipeline / plugin-registry signature verification smoke (#1922, CWE-347) (push) Failing after 4s
V3 CI/CD Pipeline / memory stats legacy-DB smoke (#2120) (push) Failing after 4s
V3 CI/CD Pipeline / github deprecated actions smoke (#2089, ADR-127 Phase 3) (push) Failing after 1s
V3 CI/CD Pipeline / graph query + pathfinder smoke (ADR-130 P2+P5) (push) Has been skipped
V3 CI/CD Pipeline / graph trajectory hooks smoke (ADR-130 P3) (push) Has been skipped
V3 CI/CD Pipeline / graph plugin adapter smoke (ADR-130 P4) (push) Has been skipped
V3 CI/CD Pipeline / graph benchmark (ADR-130 P6) (push) Has been skipped
V3 CI/CD Pipeline / statusline generator delegation smoke (#2195) (push) Failing after 1s
V3 CI/CD Pipeline / wizard init regression guard (#2206 (push) Failing after 1s
V3 CI/CD Pipeline / memory no-stray-db smoke (ADR-125 P7) (push) Failing after 1s
V3 CI/CD Pipeline / github-safe injection smoke (#2089, ADR-127 Phase 1) (push) Failing after 1s
V3 CI/CD Pipeline / github actions pin smoke (#2089, ADR-127 Phase 1) (push) Failing after 1s
V3 CI/CD Pipeline / github attribution opt-in smoke (#2089, ADR-127 Phase 4) (push) Failing after 1s
V3 CI/CD Pipeline / pre-bash hook safety smoke (#2017) (push) Failing after 1s
V3 CI/CD Pipeline / Memory import smoke / ubuntu-latest (push) Failing after 0s
V3 CI/CD Pipeline / MCP protocol smoke / ubuntu-latest (push) Failing after 2s
V3 CI/CD Pipeline / ruvllm WASM auto-init smoke (#2086) (push) Failing after 4s
V3 CI/CD Pipeline / MCP paired-tool round-trip smoke (#1889) (push) Failing after 1s
V3 CI/CD Pipeline / Plugin package install-safety (#1902/#1903/#1904) (push) Failing after 1s
V3 CI/CD Pipeline / Tool description discoverability (ADR-112) (push) Failing after 3s
V3 CI/CD Pipeline / CLI npx-install smoke (#1147 / (22) (push) Failing after 1s
V3 CI/CD Pipeline / CLI npx-install smoke (#1147 / (24) (push) Failing after 1s
V3 CI/CD Pipeline / Windows hook shim smoke (#2132) / ubuntu-latest (push) Failing after 2s
V3 CI/CD Pipeline / Windows hook execution smoke (#2132) / ubuntu-latest (push) Failing after 1s
V3 CI/CD Pipeline / Windows init hooks smoke (#2132) / ubuntu-latest (push) Failing after 1s
V3 CI/CD Pipeline / Vector-index dimension audit (#1947) (push) Failing after 0s
V3 CI/CD Pipeline / Hook-command install safety (#1921) (push) Failing after 1s
V3 CI/CD Pipeline / ToolOutputGuardrail smoke (ADR-131, (push) Failing after 1s
V3 CI/CD Pipeline / init-bundle invariants smoke (#2095, ADR-128 Phase 5) (push) Failing after 1s
V3 CI/CD Pipeline / wasm provider bridge smoke (ADR-129 P1) (push) Failing after 2s
V3 CI/CD Pipeline / wasm gallery CRUD smoke (ADR-129 P3) (push) Failing after 1s
V3 CI/CD Pipeline / wasm plugin bridge smoke (ADR-129 P4) (push) Failing after 0s
V3 CI/CD Pipeline / wasm compose smoke (ADR-129 P2) (push) Failing after 4s
V3 CI/CD Pipeline / graph schema smoke (ADR-130 P1) (push) Failing after 0s
Validate Marketplace / validate (push) Failing after 1s
🔍 Verification Pipeline / 🚀 Setup Verification (push) Failing after 1s
🔍 Verification Pipeline / 🛡️ Security Verification (push) Has been skipped
🔍 Verification Pipeline / 📝 Code Quality (push) Has been skipped
🔍 Verification Pipeline / 🧪 Test Verification (${{ matrix.os }}, Node ${{ matrix.node }}) (push) Has been skipped
🔍 Verification Pipeline / 🏗️ Build Verification (push) Has been skipped
🔍 Verification Pipeline / 📚 Documentation Verification (push) Has been skipped
CVE Audit Gate / High-severity report (warn only) (push) Has been cancelled
🔄 Automated Rollback Manager / 🔄 Execute Rollback (push) Has been cancelled
🔄 Automated Rollback Manager / ✅ Post-Rollback Verification (push) Has been cancelled
🔄 Automated Rollback Manager / 📊 Rollback Monitoring (push) Has been cancelled
V3 CI/CD Pipeline / Windows init hooks smoke (#2132) / windows-latest (push) Has been cancelled
V3 CI/CD Pipeline / Windows hook execution smoke (#2132) / macos-latest (push) Has been cancelled
V3 CI/CD Pipeline / Windows hook execution smoke (#2132) / windows-latest (push) Has been cancelled
🔄 Automated Rollback Manager / ⏳ Manual Rollback Approval (push) Has been cancelled
V3 CI/CD Pipeline / MCP protocol smoke / macos-latest (push) Has been cancelled
V3 CI/CD Pipeline / Memory import smoke / macos-latest (push) Has been cancelled
V3 CI/CD Pipeline / Windows hook shim smoke (#2132) / macos-latest (push) Has been cancelled
V3 CI/CD Pipeline / Windows hook shim smoke (#2132) / windows-latest (push) Has been cancelled
V3 CI/CD Pipeline / Windows init hooks smoke (#2132) / macos-latest (push) Has been cancelled
V3 CI/CD Pipeline / Witness verify (signed manifest) / macos-latest (push) Has been cancelled
V3 CI/CD Pipeline / Witness verify (signed manifest) / ubuntu-latest (push) Has been cancelled
V3 CI/CD Pipeline / Witness verify (signed manifest) / windows-latest (push) Has been cancelled
V3 CI/CD Pipeline / Publish to npm (alpha) (push) Has been cancelled
V3 CI/CD Pipeline / Smoke (no better-sqlite3) / macos-latest / Node 22 (push) Has been cancelled
V3 CI/CD Pipeline / Plugin hooks smoke / macos-latest / Node 22 (push) Has been cancelled
CI/CD Pipeline / Deploy & Release (push) Has been cancelled
CI/CD Pipeline / CI Status (push) Has been cancelled
🔗 Cross-Agent Integration Tests / 📊 Integration Test Report (push) Has been cancelled
🔄 Automated Rollback Manager / 🔍 Pre-Rollback Validation (push) Has been cancelled
🔍 Verification Pipeline / ⚡ Performance Verification (push) Has been cancelled
🔍 Verification Pipeline / 📊 Verification Report (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:02:19 +08:00

781 lines
22 KiB
TypeScript

/**
* Prime Radiant Plugin Lifecycle Tests
*
* Tests for the prime-radiant plugin initialization, configuration,
* WASM loading, and health check functionality.
*/
import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest';
// ============================================================================
// Mock Types
// ============================================================================
interface PluginMetadata {
name: string;
version: string;
description?: string;
author?: string;
license?: string;
wasmSize?: string;
dependencies?: string[];
tags?: string[];
}
interface PluginContext {
config: {
enabled: boolean;
priority: number;
settings: Record<string, unknown>;
};
eventBus: {
emit: (event: string, data?: unknown) => void;
on: (event: string, handler: (data: unknown) => void) => () => void;
off: (event: string, handler: (data: unknown) => void) => void;
};
logger: {
debug: (msg: string, ...args: unknown[]) => void;
info: (msg: string, ...args: unknown[]) => void;
warn: (msg: string, ...args: unknown[]) => void;
error: (msg: string, ...args: unknown[]) => void;
};
services: Map<string, unknown>;
coreVersion: string;
dataDir: string;
}
interface MCPToolDefinition {
name: string;
description: string;
inputSchema: Record<string, unknown>;
handler: (input: unknown) => Promise<{ content: Array<{ type: string; text: string }> }>;
}
interface HookDefinition {
name: string;
event: string;
priority: 'low' | 'normal' | 'high' | 'critical';
handler: (context: unknown) => Promise<{ success: boolean }>;
}
type PluginState = 'uninitialized' | 'initializing' | 'initialized' | 'error' | 'shutdown';
// ============================================================================
// Mock Engine Interface
// ============================================================================
interface Engine {
name: string;
ready: boolean;
compute: (input: unknown) => Promise<unknown>;
}
// ============================================================================
// Mock Plugin Implementation
// ============================================================================
class MockPrimeRadiantPlugin {
public metadata: PluginMetadata;
public state: PluginState = 'uninitialized';
private context?: PluginContext;
private tools: MCPToolDefinition[] = [];
private hooks: HookDefinition[] = [];
private engines: Map<string, Engine> = new Map();
private wasmLoaded = false;
constructor(metadata: Partial<PluginMetadata> = {}) {
this.metadata = Object.freeze({
name: 'prime-radiant',
version: '0.1.3',
description: 'Mathematical AI interpretability plugin',
author: 'rUv',
license: 'MIT',
wasmSize: '92KB',
dependencies: ['@claude-flow/memory', '@claude-flow/security', '@claude-flow/coordination'],
tags: [
'sheaf-cohomology',
'causal-inference',
'quantum-topology',
'ai-interpretability',
],
...metadata,
});
}
async initialize(context: PluginContext): Promise<void> {
if (this.state === 'initialized') {
throw new Error('Plugin already initialized');
}
this.state = 'initializing';
this.context = context;
try {
// Load WASM
await this.loadWasm();
// Initialize engines
await this.initializeEngines();
// Register tools
this.tools = this.createTools();
// Register hooks
this.hooks = this.createHooks();
this.state = 'initialized';
context.logger.info(`${this.metadata.name} initialized successfully`);
} catch (error) {
this.state = 'error';
throw error;
}
}
async shutdown(): Promise<void> {
if (this.state !== 'initialized') {
return;
}
// Cleanup engines
for (const engine of this.engines.values()) {
// Would call engine.dispose() in real implementation
}
this.engines.clear();
// Clear tools and hooks
this.tools = [];
this.hooks = [];
this.wasmLoaded = false;
this.state = 'shutdown';
this.context?.logger.info(`${this.metadata.name} shut down`);
}
async healthCheck(): Promise<{
healthy: boolean;
status: string;
checks: Record<string, { healthy: boolean; message?: string }>;
}> {
const checks: Record<string, { healthy: boolean; message?: string }> = {
state: {
healthy: this.state === 'initialized',
message: `Plugin state: ${this.state}`,
},
wasm: {
healthy: this.wasmLoaded,
message: this.wasmLoaded ? 'WASM loaded' : 'WASM not loaded',
},
engines: {
healthy: this.engines.size === 6,
message: `${this.engines.size}/6 engines ready`,
},
tools: {
healthy: this.tools.length > 0,
message: `${this.tools.length} tools registered`,
},
};
const healthy = Object.values(checks).every((c) => c.healthy);
return {
healthy,
status: healthy ? 'healthy' : 'unhealthy',
checks,
};
}
registerMCPTools(): MCPToolDefinition[] {
return this.tools;
}
registerHooks(): HookDefinition[] {
return this.hooks;
}
getEngine(name: string): Engine | undefined {
return this.engines.get(name);
}
isWasmLoaded(): boolean {
return this.wasmLoaded;
}
getConfig(): Record<string, unknown> {
return this.context?.config.settings ?? {};
}
private async loadWasm(): Promise<void> {
// Mock WASM loading - in real implementation would load prime-radiant-advanced-wasm
await new Promise((resolve) => setTimeout(resolve, 10)); // Simulate load time
this.wasmLoaded = true;
}
private async initializeEngines(): Promise<void> {
const engineNames = [
'cohomology',
'spectral',
'causal',
'quantum',
'category',
'hott',
];
for (const name of engineNames) {
this.engines.set(name, {
name,
ready: true,
compute: async (input) => ({ result: `${name} computation result` }),
});
}
}
private createTools(): MCPToolDefinition[] {
return [
{
name: 'pr_coherence_check',
description: 'Check coherence of vectors using Sheaf Laplacian energy',
inputSchema: {
type: 'object',
properties: {
vectors: { type: 'array', items: { type: 'array' } },
threshold: { type: 'number', default: 0.3 },
},
required: ['vectors'],
},
handler: async (input) => ({
content: [{ type: 'text', text: JSON.stringify({ coherent: true, energy: 0.1 }) }],
}),
},
{
name: 'pr_spectral_analyze',
description: 'Analyze stability using spectral graph theory',
inputSchema: {
type: 'object',
properties: {
adjacencyMatrix: { type: 'array' },
analyzeType: { type: 'string', enum: ['stability', 'clustering', 'connectivity'] },
},
required: ['adjacencyMatrix'],
},
handler: async (input) => ({
content: [{ type: 'text', text: JSON.stringify({ stable: true, spectralGap: 0.25 }) }],
}),
},
{
name: 'pr_causal_infer',
description: 'Perform causal inference using do-calculus',
inputSchema: {
type: 'object',
properties: {
treatment: { type: 'string' },
outcome: { type: 'string' },
graph: { type: 'object' },
},
required: ['treatment', 'outcome', 'graph'],
},
handler: async (input) => ({
content: [{ type: 'text', text: JSON.stringify({ causalEffect: -0.35 }) }],
}),
},
{
name: 'pr_consensus_verify',
description: 'Verify multi-agent consensus mathematically',
inputSchema: {
type: 'object',
properties: {
agentStates: { type: 'array' },
consensusThreshold: { type: 'number', default: 0.8 },
},
required: ['agentStates'],
},
handler: async (input) => ({
content: [{ type: 'text', text: JSON.stringify({ consensusAchieved: true }) }],
}),
},
{
name: 'pr_quantum_topology',
description: 'Compute quantum topology features',
inputSchema: {
type: 'object',
properties: {
points: { type: 'array' },
maxDimension: { type: 'number', default: 2 },
},
required: ['points'],
},
handler: async (input) => ({
content: [{ type: 'text', text: JSON.stringify({ bettiNumbers: [1, 2, 0] }) }],
}),
},
{
name: 'pr_memory_gate',
description: 'Pre-storage coherence gate for memory entries',
inputSchema: {
type: 'object',
properties: {
entry: { type: 'object' },
contextEmbeddings: { type: 'array' },
thresholds: { type: 'object' },
},
required: ['entry'],
},
handler: async (input) => ({
content: [{ type: 'text', text: JSON.stringify({ action: 'allow' }) }],
}),
},
];
}
private createHooks(): HookDefinition[] {
return [
{
name: 'pr/pre-memory-store',
event: 'pre-memory-store',
priority: 'high',
handler: async () => ({ success: true }),
},
{
name: 'pr/pre-consensus',
event: 'pre-consensus',
priority: 'high',
handler: async () => ({ success: true }),
},
{
name: 'pr/post-swarm-task',
event: 'post-task',
priority: 'normal',
handler: async () => ({ success: true }),
},
{
name: 'pr/pre-rag-retrieval',
event: 'pre-rag-retrieval',
priority: 'high',
handler: async () => ({ success: true }),
},
];
}
}
// ============================================================================
// Test Helpers
// ============================================================================
function createMockContext(overrides: Partial<PluginContext> = {}): PluginContext {
return {
config: {
enabled: true,
priority: 50,
settings: {
coherence: {
warnThreshold: 0.3,
rejectThreshold: 0.7,
cacheEnabled: true,
},
spectral: {
stabilityThreshold: 0.1,
maxMatrixSize: 1000,
},
causal: {
maxBackdoorPaths: 10,
confidenceThreshold: 0.8,
},
},
},
eventBus: {
emit: vi.fn(),
on: vi.fn(() => vi.fn()),
off: vi.fn(),
},
logger: {
debug: vi.fn(),
info: vi.fn(),
warn: vi.fn(),
error: vi.fn(),
},
services: new Map(),
coreVersion: '3.0.0',
dataDir: '/tmp/prime-radiant',
...overrides,
};
}
// ============================================================================
// Tests
// ============================================================================
describe('PrimeRadiantPlugin', () => {
let plugin: MockPrimeRadiantPlugin;
let context: PluginContext;
beforeEach(() => {
plugin = new MockPrimeRadiantPlugin();
context = createMockContext();
});
afterEach(async () => {
if (plugin.state === 'initialized') {
await plugin.shutdown();
}
});
describe('metadata', () => {
it('should have correct plugin name', () => {
expect(plugin.metadata.name).toBe('prime-radiant');
});
it('should have correct version', () => {
expect(plugin.metadata.version).toBe('0.1.3');
});
it('should specify WASM size', () => {
expect(plugin.metadata.wasmSize).toBe('92KB');
});
it('should have required dependencies', () => {
expect(plugin.metadata.dependencies).toContain('@claude-flow/memory');
expect(plugin.metadata.dependencies).toContain('@claude-flow/security');
expect(plugin.metadata.dependencies).toContain('@claude-flow/coordination');
});
it('should have expected tags', () => {
expect(plugin.metadata.tags).toContain('sheaf-cohomology');
expect(plugin.metadata.tags).toContain('causal-inference');
expect(plugin.metadata.tags).toContain('ai-interpretability');
});
it('should freeze metadata', () => {
expect(Object.isFrozen(plugin.metadata)).toBe(true);
});
});
describe('initialization', () => {
it('should start in uninitialized state', () => {
expect(plugin.state).toBe('uninitialized');
});
it('should initialize successfully with valid context', async () => {
await plugin.initialize(context);
expect(plugin.state).toBe('initialized');
});
it('should log initialization success', async () => {
await plugin.initialize(context);
expect(context.logger.info).toHaveBeenCalledWith(
expect.stringContaining('initialized successfully')
);
});
it('should reject double initialization', async () => {
await plugin.initialize(context);
await expect(plugin.initialize(context)).rejects.toThrow('already initialized');
});
it('should load WASM during initialization', async () => {
expect(plugin.isWasmLoaded()).toBe(false);
await plugin.initialize(context);
expect(plugin.isWasmLoaded()).toBe(true);
});
it('should initialize all 6 engines', async () => {
await plugin.initialize(context);
expect(plugin.getEngine('cohomology')).toBeDefined();
expect(plugin.getEngine('spectral')).toBeDefined();
expect(plugin.getEngine('causal')).toBeDefined();
expect(plugin.getEngine('quantum')).toBeDefined();
expect(plugin.getEngine('category')).toBeDefined();
expect(plugin.getEngine('hott')).toBeDefined();
});
it('should mark all engines as ready', async () => {
await plugin.initialize(context);
for (const engineName of ['cohomology', 'spectral', 'causal', 'quantum', 'category', 'hott']) {
const engine = plugin.getEngine(engineName);
expect(engine?.ready).toBe(true);
}
});
});
describe('shutdown', () => {
it('should shutdown gracefully', async () => {
await plugin.initialize(context);
await plugin.shutdown();
expect(plugin.state).toBe('shutdown');
});
it('should clear engines on shutdown', async () => {
await plugin.initialize(context);
await plugin.shutdown();
expect(plugin.getEngine('cohomology')).toBeUndefined();
});
it('should unload WASM on shutdown', async () => {
await plugin.initialize(context);
await plugin.shutdown();
expect(plugin.isWasmLoaded()).toBe(false);
});
it('should be safe to call shutdown multiple times', async () => {
await plugin.initialize(context);
await plugin.shutdown();
await plugin.shutdown(); // Should not throw
expect(plugin.state).toBe('shutdown');
});
it('should be safe to shutdown uninitialized plugin', async () => {
await plugin.shutdown(); // Should not throw
expect(plugin.state).toBe('uninitialized');
});
});
describe('health check', () => {
it('should report healthy when initialized', async () => {
await plugin.initialize(context);
const health = await plugin.healthCheck();
expect(health.healthy).toBe(true);
expect(health.status).toBe('healthy');
});
it('should report unhealthy when not initialized', async () => {
const health = await plugin.healthCheck();
expect(health.healthy).toBe(false);
expect(health.status).toBe('unhealthy');
});
it('should include WASM check', async () => {
await plugin.initialize(context);
const health = await plugin.healthCheck();
expect(health.checks.wasm.healthy).toBe(true);
expect(health.checks.wasm.message).toContain('WASM loaded');
});
it('should include engines check', async () => {
await plugin.initialize(context);
const health = await plugin.healthCheck();
expect(health.checks.engines.healthy).toBe(true);
expect(health.checks.engines.message).toContain('6/6');
});
it('should include tools check', async () => {
await plugin.initialize(context);
const health = await plugin.healthCheck();
expect(health.checks.tools.healthy).toBe(true);
});
});
describe('MCP tools', () => {
it('should register MCP tools after initialization', async () => {
await plugin.initialize(context);
const tools = plugin.registerMCPTools();
expect(tools.length).toBeGreaterThan(0);
});
it('should include coherence_check tool', async () => {
await plugin.initialize(context);
const tools = plugin.registerMCPTools();
const tool = tools.find((t) => t.name === 'pr_coherence_check');
expect(tool).toBeDefined();
expect(tool?.description).toContain('Sheaf Laplacian');
});
it('should include spectral_analyze tool', async () => {
await plugin.initialize(context);
const tools = plugin.registerMCPTools();
const tool = tools.find((t) => t.name === 'pr_spectral_analyze');
expect(tool).toBeDefined();
expect(tool?.description).toContain('spectral');
});
it('should include causal_infer tool', async () => {
await plugin.initialize(context);
const tools = plugin.registerMCPTools();
const tool = tools.find((t) => t.name === 'pr_causal_infer');
expect(tool).toBeDefined();
expect(tool?.description).toContain('causal');
});
it('should include consensus_verify tool', async () => {
await plugin.initialize(context);
const tools = plugin.registerMCPTools();
const tool = tools.find((t) => t.name === 'pr_consensus_verify');
expect(tool).toBeDefined();
});
it('should include quantum_topology tool', async () => {
await plugin.initialize(context);
const tools = plugin.registerMCPTools();
const tool = tools.find((t) => t.name === 'pr_quantum_topology');
expect(tool).toBeDefined();
});
it('should include memory_gate tool', async () => {
await plugin.initialize(context);
const tools = plugin.registerMCPTools();
const tool = tools.find((t) => t.name === 'pr_memory_gate');
expect(tool).toBeDefined();
});
it('should have valid input schemas', async () => {
await plugin.initialize(context);
const tools = plugin.registerMCPTools();
for (const tool of tools) {
expect(tool.inputSchema).toBeDefined();
expect(tool.inputSchema.type).toBe('object');
expect(tool.inputSchema.properties).toBeDefined();
}
});
it('should have working handlers', async () => {
await plugin.initialize(context);
const tools = plugin.registerMCPTools();
const tool = tools[0];
const result = await tool.handler({ vectors: [[0.1, 0.2]] });
expect(result.content).toBeDefined();
expect(result.content[0].type).toBe('text');
});
});
describe('hooks', () => {
it('should register hooks after initialization', async () => {
await plugin.initialize(context);
const hooks = plugin.registerHooks();
expect(hooks.length).toBeGreaterThan(0);
});
it('should include pre-memory-store hook', async () => {
await plugin.initialize(context);
const hooks = plugin.registerHooks();
const hook = hooks.find((h) => h.name === 'pr/pre-memory-store');
expect(hook).toBeDefined();
expect(hook?.event).toBe('pre-memory-store');
expect(hook?.priority).toBe('high');
});
it('should include pre-consensus hook', async () => {
await plugin.initialize(context);
const hooks = plugin.registerHooks();
const hook = hooks.find((h) => h.name === 'pr/pre-consensus');
expect(hook).toBeDefined();
});
it('should include post-swarm-task hook', async () => {
await plugin.initialize(context);
const hooks = plugin.registerHooks();
const hook = hooks.find((h) => h.name === 'pr/post-swarm-task');
expect(hook).toBeDefined();
expect(hook?.event).toBe('post-task');
});
it('should include pre-rag-retrieval hook', async () => {
await plugin.initialize(context);
const hooks = plugin.registerHooks();
const hook = hooks.find((h) => h.name === 'pr/pre-rag-retrieval');
expect(hook).toBeDefined();
});
});
describe('configuration', () => {
it('should access plugin settings', async () => {
await plugin.initialize(context);
const config = plugin.getConfig();
expect(config.coherence).toBeDefined();
expect((config.coherence as any).warnThreshold).toBe(0.3);
expect((config.coherence as any).rejectThreshold).toBe(0.7);
});
it('should access spectral settings', async () => {
await plugin.initialize(context);
const config = plugin.getConfig();
expect(config.spectral).toBeDefined();
expect((config.spectral as any).stabilityThreshold).toBe(0.1);
});
it('should access causal settings', async () => {
await plugin.initialize(context);
const config = plugin.getConfig();
expect(config.causal).toBeDefined();
expect((config.causal as any).maxBackdoorPaths).toBe(10);
});
});
});
describe('PrimeRadiantPlugin WASM Loading', () => {
it('should handle WASM load failure gracefully', async () => {
// This would test error handling for WASM load failure
// In the mock, WASM always loads successfully
const plugin = new MockPrimeRadiantPlugin();
const context = createMockContext();
// Mock would need to be modified to test failure scenarios
await plugin.initialize(context);
expect(plugin.isWasmLoaded()).toBe(true);
});
it('should load WASM within performance target', async () => {
const plugin = new MockPrimeRadiantPlugin();
const context = createMockContext();
const startTime = performance.now();
await plugin.initialize(context);
const duration = performance.now() - startTime;
// Target: <50ms for WASM load
expect(duration).toBeLessThan(100); // Allow some margin for mock
});
});