mirror of
https://github.com/ruvnet/RuView
synced 2026-08-02 19:11:46 +00:00
feat: vendor midstream and sublinear-time-solver libraries
Add ruvnet/midstream (AIMDS real-time inference) and ruvnet/sublinear-time-solver (sublinear optimization algorithms) as vendored dependencies under vendor/. Co-Authored-By: claude-flow <ruv@ruv.net>
This commit is contained in:
+255
@@ -0,0 +1,255 @@
|
||||
#!/usr/bin/env tsx
|
||||
/**
|
||||
* Load Testing Script for AIMDS Gateway
|
||||
*
|
||||
* Simulates realistic load patterns and measures performance metrics
|
||||
*/
|
||||
|
||||
import http from 'http';
|
||||
import { performance } from 'perf_hooks';
|
||||
|
||||
interface LoadTestConfig {
|
||||
baseUrl: string;
|
||||
totalRequests: number;
|
||||
concurrency: number;
|
||||
rampUpSeconds: number;
|
||||
}
|
||||
|
||||
interface RequestResult {
|
||||
success: boolean;
|
||||
latency: number;
|
||||
statusCode?: number;
|
||||
error?: string;
|
||||
}
|
||||
|
||||
interface LoadTestResults {
|
||||
totalRequests: number;
|
||||
successfulRequests: number;
|
||||
failedRequests: number;
|
||||
totalDuration: number;
|
||||
requestsPerSecond: number;
|
||||
latencyStats: {
|
||||
min: number;
|
||||
max: number;
|
||||
mean: number;
|
||||
p50: number;
|
||||
p95: number;
|
||||
p99: number;
|
||||
};
|
||||
}
|
||||
|
||||
class LoadTester {
|
||||
private config: LoadTestConfig;
|
||||
private results: RequestResult[] = [];
|
||||
|
||||
constructor(config: LoadTestConfig) {
|
||||
this.config = config;
|
||||
}
|
||||
|
||||
async run(): Promise<LoadTestResults> {
|
||||
console.log('🚀 Starting load test...');
|
||||
console.log(` Target: ${this.config.baseUrl}`);
|
||||
console.log(` Total requests: ${this.config.totalRequests}`);
|
||||
console.log(` Concurrency: ${this.config.concurrency}`);
|
||||
console.log(` Ramp-up: ${this.config.rampUpSeconds}s\n`);
|
||||
|
||||
const startTime = performance.now();
|
||||
|
||||
await this.executeLoadTest();
|
||||
|
||||
const endTime = performance.now();
|
||||
const totalDuration = endTime - startTime;
|
||||
|
||||
return this.calculateResults(totalDuration);
|
||||
}
|
||||
|
||||
private async executeLoadTest(): Promise<void> {
|
||||
const batchSize = this.config.concurrency;
|
||||
const numBatches = Math.ceil(this.config.totalRequests / batchSize);
|
||||
const delayBetweenBatches = (this.config.rampUpSeconds * 1000) / numBatches;
|
||||
|
||||
for (let batch = 0; batch < numBatches; batch++) {
|
||||
const batchRequests = Math.min(
|
||||
batchSize,
|
||||
this.config.totalRequests - batch * batchSize
|
||||
);
|
||||
|
||||
const promises: Promise<RequestResult>[] = [];
|
||||
|
||||
for (let i = 0; i < batchRequests; i++) {
|
||||
const requestType = Math.random();
|
||||
|
||||
if (requestType < 0.95) {
|
||||
// 95% fast path requests
|
||||
promises.push(this.makeRequest({
|
||||
action: { type: 'read', resource: '/api/users', method: 'GET' },
|
||||
source: { ip: '192.168.1.1' },
|
||||
}));
|
||||
} else {
|
||||
// 5% deep path requests
|
||||
promises.push(this.makeRequest({
|
||||
action: { type: 'complex_operation' },
|
||||
source: { ip: '192.168.1.1' },
|
||||
behaviorSequence: this.generateBehaviorSequence(),
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
const batchResults = await Promise.all(promises);
|
||||
this.results.push(...batchResults);
|
||||
|
||||
const progress = ((batch + 1) / numBatches * 100).toFixed(1);
|
||||
process.stdout.write(`\r Progress: ${progress}% (${this.results.length}/${this.config.totalRequests} requests)`);
|
||||
|
||||
if (batch < numBatches - 1) {
|
||||
await this.sleep(delayBetweenBatches);
|
||||
}
|
||||
}
|
||||
|
||||
console.log('\n');
|
||||
}
|
||||
|
||||
private async makeRequest(payload: any): Promise<RequestResult> {
|
||||
const startTime = performance.now();
|
||||
|
||||
return new Promise((resolve) => {
|
||||
const data = JSON.stringify(payload);
|
||||
|
||||
const options = {
|
||||
hostname: 'localhost',
|
||||
port: 3000,
|
||||
path: '/api/v1/defend',
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Content-Length': data.length,
|
||||
},
|
||||
};
|
||||
|
||||
const req = http.request(options, (res) => {
|
||||
let responseData = '';
|
||||
|
||||
res.on('data', (chunk) => {
|
||||
responseData += chunk;
|
||||
});
|
||||
|
||||
res.on('end', () => {
|
||||
const latency = performance.now() - startTime;
|
||||
resolve({
|
||||
success: res.statusCode === 200,
|
||||
latency,
|
||||
statusCode: res.statusCode,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
req.on('error', (error) => {
|
||||
const latency = performance.now() - startTime;
|
||||
resolve({
|
||||
success: false,
|
||||
latency,
|
||||
error: error.message,
|
||||
});
|
||||
});
|
||||
|
||||
req.write(data);
|
||||
req.end();
|
||||
});
|
||||
}
|
||||
|
||||
private generateBehaviorSequence(): number[] {
|
||||
const length = 5;
|
||||
return Array.from({ length }, () => Math.random());
|
||||
}
|
||||
|
||||
private calculateResults(totalDuration: number): LoadTestResults {
|
||||
const successful = this.results.filter(r => r.success);
|
||||
const latencies = successful.map(r => r.latency).sort((a, b) => a - b);
|
||||
|
||||
const sum = latencies.reduce((a, b) => a + b, 0);
|
||||
const mean = sum / latencies.length;
|
||||
|
||||
return {
|
||||
totalRequests: this.results.length,
|
||||
successfulRequests: successful.length,
|
||||
failedRequests: this.results.length - successful.length,
|
||||
totalDuration,
|
||||
requestsPerSecond: (this.results.length / totalDuration) * 1000,
|
||||
latencyStats: {
|
||||
min: latencies[0] || 0,
|
||||
max: latencies[latencies.length - 1] || 0,
|
||||
mean,
|
||||
p50: latencies[Math.floor(latencies.length * 0.5)] || 0,
|
||||
p95: latencies[Math.floor(latencies.length * 0.95)] || 0,
|
||||
p99: latencies[Math.floor(latencies.length * 0.99)] || 0,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
private sleep(ms: number): Promise<void> {
|
||||
return new Promise(resolve => setTimeout(resolve, ms));
|
||||
}
|
||||
}
|
||||
|
||||
function printResults(results: LoadTestResults): void {
|
||||
console.log('📊 Load Test Results\n');
|
||||
console.log('Overall:');
|
||||
console.log(` Total requests: ${results.totalRequests}`);
|
||||
console.log(` Successful: ${results.successfulRequests} (${(results.successfulRequests / results.totalRequests * 100).toFixed(1)}%)`);
|
||||
console.log(` Failed: ${results.failedRequests} (${(results.failedRequests / results.totalRequests * 100).toFixed(1)}%)`);
|
||||
console.log(` Total duration: ${results.totalDuration.toFixed(0)}ms`);
|
||||
console.log(` Throughput: ${results.requestsPerSecond.toFixed(0)} req/s`);
|
||||
console.log('');
|
||||
console.log('Latency (ms):');
|
||||
console.log(` Min: ${results.latencyStats.min.toFixed(2)}`);
|
||||
console.log(` Mean: ${results.latencyStats.mean.toFixed(2)}`);
|
||||
console.log(` p50: ${results.latencyStats.p50.toFixed(2)}`);
|
||||
console.log(` p95: ${results.latencyStats.p95.toFixed(2)}`);
|
||||
console.log(` p99: ${results.latencyStats.p99.toFixed(2)}`);
|
||||
console.log(` Max: ${results.latencyStats.max.toFixed(2)}`);
|
||||
console.log('');
|
||||
|
||||
// Performance targets
|
||||
console.log('Target Validation:');
|
||||
const throughputOk = results.requestsPerSecond >= 10000;
|
||||
const p95Ok = results.latencyStats.p95 < 35;
|
||||
const p99Ok = results.latencyStats.p99 < 100;
|
||||
const errorRateOk = (results.failedRequests / results.totalRequests) < 0.01;
|
||||
|
||||
console.log(` Throughput ≥10,000 req/s: ${throughputOk ? '✅' : '❌'} (${results.requestsPerSecond.toFixed(0)})`);
|
||||
console.log(` p95 latency <35ms: ${p95Ok ? '✅' : '❌'} (${results.latencyStats.p95.toFixed(2)}ms)`);
|
||||
console.log(` p99 latency <100ms: ${p99Ok ? '✅' : '❌'} (${results.latencyStats.p99.toFixed(2)}ms)`);
|
||||
console.log(` Error rate <1%: ${errorRateOk ? '✅' : '❌'} (${(results.failedRequests / results.totalRequests * 100).toFixed(2)}%)`);
|
||||
}
|
||||
|
||||
// Main execution
|
||||
async function main() {
|
||||
const config: LoadTestConfig = {
|
||||
baseUrl: 'http://localhost:3000',
|
||||
totalRequests: parseInt(process.env.LOAD_TEST_REQUESTS || '1000'),
|
||||
concurrency: parseInt(process.env.LOAD_TEST_CONCURRENCY || '50'),
|
||||
rampUpSeconds: parseInt(process.env.LOAD_TEST_RAMP_UP || '5'),
|
||||
};
|
||||
|
||||
const tester = new LoadTester(config);
|
||||
const results = await tester.run();
|
||||
printResults(results);
|
||||
|
||||
// Exit with error code if targets not met
|
||||
const allTargetsMet =
|
||||
results.requestsPerSecond >= 10000 &&
|
||||
results.latencyStats.p95 < 35 &&
|
||||
results.latencyStats.p99 < 100 &&
|
||||
(results.failedRequests / results.totalRequests) < 0.01;
|
||||
|
||||
process.exit(allTargetsMet ? 0 : 1);
|
||||
}
|
||||
|
||||
if (require.main === module) {
|
||||
main().catch(error => {
|
||||
console.error('❌ Load test failed:', error);
|
||||
process.exit(1);
|
||||
});
|
||||
}
|
||||
|
||||
export { LoadTester, LoadTestConfig, LoadTestResults };
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
#!/bin/bash
|
||||
mkdir -p /workspaces/midstream/AIMDS/crates/aimds-{analysis,response}/src
|
||||
mkdir -p /workspaces/midstream/AIMDS/{src/{gateway,agentdb,lean-agentic,monitoring},docker,k8s,benches,tests}
|
||||
touch /workspaces/midstream/AIMDS/crates/aimds-analysis/src/{lib.rs,behavioral.rs,policy_verifier.rs,ltl_checker.rs}
|
||||
touch /workspaces/midstream/AIMDS/crates/aimds-response/src/{lib.rs,meta_learning.rs,adaptive.rs,mitigations.rs}
|
||||
touch /workspaces/midstream/AIMDS/src/index.ts
|
||||
touch /workspaces/midstream/AIMDS/src/gateway/{server.ts,router.ts,middleware.ts}
|
||||
touch /workspaces/midstream/AIMDS/src/agentdb/{client.ts,vector-search.ts,reflexion.ts}
|
||||
touch /workspaces/midstream/AIMDS/src/lean-agentic/{verifier.ts,hash-cons.ts,theorem-prover.ts}
|
||||
touch /workspaces/midstream/AIMDS/src/monitoring/{metrics.ts,telemetry.ts}
|
||||
touch /workspaces/midstream/AIMDS/docker/{Dockerfile.rust,Dockerfile.node,Dockerfile.gateway,prometheus.yml}
|
||||
touch /workspaces/midstream/AIMDS/k8s/{deployment.yaml,service.yaml,configmap.yaml}
|
||||
touch /workspaces/midstream/AIMDS/benches/{detection_bench.rs,analysis_bench.rs,response_bench.rs}
|
||||
touch /workspaces/midstream/AIMDS/{README.md,tsconfig.json,.dockerignore,.gitignore}
|
||||
@@ -0,0 +1,260 @@
|
||||
#!/bin/bash
|
||||
# AIMDS Security Verification Script
|
||||
# Run this after applying security fixes to verify compliance
|
||||
|
||||
set -e
|
||||
|
||||
echo "================================================================================"
|
||||
echo "AIMDS Security Verification"
|
||||
echo "================================================================================"
|
||||
echo ""
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
PROJECT_DIR="$(dirname "$SCRIPT_DIR")"
|
||||
cd "$PROJECT_DIR"
|
||||
|
||||
PASSED=0
|
||||
FAILED=0
|
||||
WARNINGS=0
|
||||
|
||||
# Colors
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
check_pass() {
|
||||
echo -e "${GREEN}✅ PASS${NC}: $1"
|
||||
((PASSED++))
|
||||
}
|
||||
|
||||
check_fail() {
|
||||
echo -e "${RED}❌ FAIL${NC}: $1"
|
||||
((FAILED++))
|
||||
}
|
||||
|
||||
check_warn() {
|
||||
echo -e "${YELLOW}⚠️ WARN${NC}: $1"
|
||||
((WARNINGS++))
|
||||
}
|
||||
|
||||
echo "================================================================================"
|
||||
echo "1. CHECKING FOR HARDCODED SECRETS"
|
||||
echo "================================================================================"
|
||||
echo ""
|
||||
|
||||
# Check if .env exists
|
||||
if [ -f ".env" ]; then
|
||||
check_warn ".env file exists (should not be in git)"
|
||||
|
||||
# Check if .env contains real secrets
|
||||
if grep -q "sk-" .env 2>/dev/null; then
|
||||
check_fail "Found API keys in .env file"
|
||||
else
|
||||
check_pass "No obvious API keys in .env"
|
||||
fi
|
||||
else
|
||||
check_pass ".env file not found (good)"
|
||||
fi
|
||||
|
||||
# Check git status
|
||||
if git ls-files --error-unmatch .env 2>/dev/null; then
|
||||
check_fail ".env is tracked in git - MUST REMOVE"
|
||||
else
|
||||
check_pass ".env is not tracked in git"
|
||||
fi
|
||||
|
||||
# Check .gitignore
|
||||
if grep -q "^\.env$" .gitignore 2>/dev/null; then
|
||||
check_pass ".env is in .gitignore"
|
||||
else
|
||||
check_fail ".env NOT in .gitignore"
|
||||
fi
|
||||
|
||||
# Check for hardcoded secrets in source code
|
||||
echo ""
|
||||
echo "Checking source code for hardcoded secrets..."
|
||||
SECRET_PATTERNS="sk-|AKIA|ghp_|xox[baprs]-|AIza"
|
||||
if grep -rn "$SECRET_PATTERNS" src/ crates/ 2>/dev/null | grep -v ".md:" | grep -v "test" | grep -v "example"; then
|
||||
check_fail "Found potential secrets in source code"
|
||||
else
|
||||
check_pass "No obvious secrets in source code"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "================================================================================"
|
||||
echo "2. CHECKING COMPILATION"
|
||||
echo "================================================================================"
|
||||
echo ""
|
||||
|
||||
# Check Rust compilation
|
||||
echo "Compiling Rust crates..."
|
||||
if cargo build --release --quiet 2>&1 | grep -q "error"; then
|
||||
check_fail "Rust compilation failed"
|
||||
cargo build 2>&1 | grep "error" | head -5
|
||||
else
|
||||
check_pass "Rust compilation successful"
|
||||
fi
|
||||
|
||||
# Check for clippy warnings
|
||||
echo ""
|
||||
echo "Running clippy..."
|
||||
CLIPPY_OUTPUT=$(cargo clippy --all-targets --all-features -- -D warnings 2>&1)
|
||||
if echo "$CLIPPY_OUTPUT" | grep -q "error"; then
|
||||
check_fail "Clippy found errors"
|
||||
echo "$CLIPPY_OUTPUT" | grep "error" | head -5
|
||||
else
|
||||
check_pass "Clippy check passed"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "================================================================================"
|
||||
echo "3. CHECKING DEPENDENCIES"
|
||||
echo "================================================================================"
|
||||
echo ""
|
||||
|
||||
# NPM audit
|
||||
echo "Running npm audit..."
|
||||
if [ -f "package.json" ]; then
|
||||
NPM_AUDIT=$(npm audit --json 2>/dev/null || echo "{}")
|
||||
VULNERABILITIES=$(echo "$NPM_AUDIT" | jq -r '.metadata.vulnerabilities.total // 0' 2>/dev/null || echo "0")
|
||||
CRITICAL=$(echo "$NPM_AUDIT" | jq -r '.metadata.vulnerabilities.critical // 0' 2>/dev/null || echo "0")
|
||||
HIGH=$(echo "$NPM_AUDIT" | jq -r '.metadata.vulnerabilities.high // 0' 2>/dev/null || echo "0")
|
||||
|
||||
if [ "$CRITICAL" -gt 0 ] || [ "$HIGH" -gt 0 ]; then
|
||||
check_fail "Found $CRITICAL critical, $HIGH high vulnerabilities"
|
||||
elif [ "$VULNERABILITIES" -gt 0 ]; then
|
||||
check_warn "Found $VULNERABILITIES moderate/low vulnerabilities"
|
||||
else
|
||||
check_pass "No npm vulnerabilities found"
|
||||
fi
|
||||
fi
|
||||
|
||||
# Cargo audit (if installed)
|
||||
echo ""
|
||||
echo "Checking cargo dependencies..."
|
||||
if command -v cargo-audit &> /dev/null; then
|
||||
if cargo audit 2>&1 | grep -q "error"; then
|
||||
check_fail "Cargo audit found vulnerabilities"
|
||||
else
|
||||
check_pass "No cargo vulnerabilities found"
|
||||
fi
|
||||
else
|
||||
check_warn "cargo-audit not installed (run: cargo install cargo-audit)"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "================================================================================"
|
||||
echo "4. CHECKING SECURITY CONFIGURATION"
|
||||
echo "================================================================================"
|
||||
echo ""
|
||||
|
||||
# Check for TLS configuration
|
||||
if grep -q "https.createServer" src/gateway/server.ts; then
|
||||
check_pass "HTTPS configuration found"
|
||||
else
|
||||
check_fail "No HTTPS configuration found"
|
||||
fi
|
||||
|
||||
# Check for authentication middleware
|
||||
if grep -q "authMiddleware\|authenticate\|verifyApiKey" src/gateway/server.ts; then
|
||||
check_pass "Authentication middleware found"
|
||||
else
|
||||
check_fail "No authentication middleware found"
|
||||
fi
|
||||
|
||||
# Check for proper CORS config
|
||||
if grep -q "cors({" src/gateway/server.ts; then
|
||||
check_pass "CORS configuration found"
|
||||
else
|
||||
check_warn "CORS not configured (using defaults)"
|
||||
fi
|
||||
|
||||
# Check for rate limiting
|
||||
if grep -q "rateLimit" src/gateway/server.ts; then
|
||||
check_pass "Rate limiting configured"
|
||||
else
|
||||
check_fail "Rate limiting not found"
|
||||
fi
|
||||
|
||||
# Check for helmet
|
||||
if grep -q "helmet" src/gateway/server.ts; then
|
||||
check_pass "Helmet security headers enabled"
|
||||
else
|
||||
check_fail "Helmet not configured"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "================================================================================"
|
||||
echo "5. RUNNING TESTS"
|
||||
echo "================================================================================"
|
||||
echo ""
|
||||
|
||||
# Rust tests
|
||||
echo "Running Rust tests..."
|
||||
if cargo test --quiet 2>&1 | grep -q "FAILED"; then
|
||||
check_fail "Rust tests failed"
|
||||
else
|
||||
check_pass "Rust tests passed"
|
||||
fi
|
||||
|
||||
# TypeScript tests
|
||||
echo ""
|
||||
echo "Running TypeScript tests..."
|
||||
if [ -f "package.json" ]; then
|
||||
if npm test 2>&1 | grep -q "FAIL"; then
|
||||
check_fail "TypeScript tests failed"
|
||||
else
|
||||
check_pass "TypeScript tests passed"
|
||||
fi
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "================================================================================"
|
||||
echo "6. CHECKING CODE QUALITY"
|
||||
echo "================================================================================"
|
||||
echo ""
|
||||
|
||||
# Check for mock implementations
|
||||
if grep -rn "Hash-based embedding for demo\|TODO:\|FIXME:\|HACK:" src/ crates/ | grep -v ".md:"; then
|
||||
check_warn "Found TODOs/FIXMEs or mock implementations"
|
||||
else
|
||||
check_pass "No obvious mock implementations or TODOs"
|
||||
fi
|
||||
|
||||
# Check for proper error handling
|
||||
if grep -q "\.expect(\|\.unwrap(" crates/*/src/*.rs; then
|
||||
check_warn "Found .expect()/.unwrap() calls (consider proper error handling)"
|
||||
else
|
||||
check_pass "No .expect()/.unwrap() calls found"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "================================================================================"
|
||||
echo "FINAL SCORE"
|
||||
echo "================================================================================"
|
||||
echo ""
|
||||
|
||||
TOTAL=$((PASSED + FAILED + WARNINGS))
|
||||
SCORE=$(( (PASSED * 100) / TOTAL ))
|
||||
|
||||
echo -e "Passed: ${GREEN}$PASSED${NC}"
|
||||
echo -e "Failed: ${RED}$FAILED${NC}"
|
||||
echo -e "Warnings: ${YELLOW}$WARNINGS${NC}"
|
||||
echo ""
|
||||
echo -e "Security Score: ${SCORE}/100"
|
||||
echo ""
|
||||
|
||||
if [ $FAILED -eq 0 ] && [ $SCORE -ge 80 ]; then
|
||||
echo -e "${GREEN}✅ READY FOR PRODUCTION DEPLOYMENT${NC}"
|
||||
exit 0
|
||||
elif [ $FAILED -eq 0 ]; then
|
||||
echo -e "${YELLOW}⚠️ ACCEPTABLE - Some improvements needed${NC}"
|
||||
exit 0
|
||||
else
|
||||
echo -e "${RED}❌ NOT READY - Critical issues must be fixed${NC}"
|
||||
echo ""
|
||||
echo "See SECURITY_AUDIT_REPORT.md for detailed findings"
|
||||
echo "See CRITICAL_FIXES_REQUIRED.md for fix instructions"
|
||||
exit 1
|
||||
fi
|
||||
Reference in New Issue
Block a user