claude-flow-novice 2.2.4 โ 2.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +9 -8
- package/scripts/.claude-flow/metrics/agent-metrics.json +1 -0
- package/scripts/.claude-flow/metrics/performance.json +9 -0
- package/scripts/.claude-flow/metrics/task-metrics.json +10 -0
- package/scripts/CLEANUP_OPTIMIZATION_REPORT.json +312 -0
- package/scripts/CLEANUP_PERFORMANCE_OPTIMIZATION.md +387 -0
- package/scripts/CLEANUP_QUICK_START.md +268 -0
- package/scripts/CLEANUP_TEST_RESULTS.md +205 -0
- package/scripts/README.md +339 -0
- package/scripts/ace-query.sh +384 -0
- package/scripts/agent-token-analysis.js +430 -0
- package/scripts/auto-setup.js +332 -0
- package/scripts/build/README.md +167 -0
- package/scripts/build/build-config.js +27 -0
- package/scripts/build/build-prompt-copier.sh +30 -0
- package/scripts/build/performance-monitor.js +869 -0
- package/scripts/build/prepare-publish.js +150 -0
- package/scripts/build/typescript-fixer.js +621 -0
- package/scripts/build/unified-builder.sh +428 -0
- package/scripts/build/update-bin-version.js +32 -0
- package/scripts/build/validate-agents.js +238 -0
- package/scripts/build-index.js +43 -0
- package/scripts/build-orchestrator.js +320 -0
- package/scripts/check-routing-stats.cjs +122 -0
- package/scripts/ci-validation.js +375 -0
- package/scripts/cleanup-blocking-coordination.sh +420 -0
- package/scripts/cleanup-idle-sessions.sh +59 -0
- package/scripts/collect-build-metrics.js +65 -0
- package/scripts/demo/README.md +79 -0
- package/scripts/demo/autoscaling-demo-simplified.js +963 -0
- package/scripts/demo/comprehensive-dashboard-test.js +693 -0
- package/scripts/demo/confidence-log.js +87 -0
- package/scripts/demo/confidence-report.js +82 -0
- package/scripts/demo/demo-multi-swarm-coordination.js +325 -0
- package/scripts/demo/demo-production-deployment.js +399 -0
- package/scripts/demo/demo-visualization-system.js +149 -0
- package/scripts/demo/performance-analysis.cjs +71 -0
- package/scripts/demo/performance-analysis.js +71 -0
- package/scripts/demo/test-autoscaling-demo.js +314 -0
- package/scripts/dependency-optimizer.js +349 -0
- package/scripts/dependency-security-assessment.js +331 -0
- package/scripts/deploy-sdk.sh +176 -0
- package/scripts/deployment-readiness-report.json +179 -0
- package/scripts/dev/README.md +264 -0
- package/scripts/dev/claude-flow-wrapper.sh +35 -0
- package/scripts/dev/claude-monitor.py +419 -0
- package/scripts/dev/claude-sparc.sh +562 -0
- package/scripts/dev/claude-wrapper.sh +17 -0
- package/scripts/dev/demo-phase3-compliance.js +172 -0
- package/scripts/dev/demo-task-system.ts +224 -0
- package/scripts/dev/deployment-validator.js +315 -0
- package/scripts/dev/spawn-claude-terminal.sh +32 -0
- package/scripts/dev/start-portal.sh +506 -0
- package/scripts/dev/start-web-ui.js +15 -0
- package/scripts/dev/stop-portal.sh +311 -0
- package/scripts/dev/validate-examples.ts +288 -0
- package/scripts/dev/validate-phase2.cjs +451 -0
- package/scripts/dev/validate-phase2.js +785 -0
- package/scripts/dev/validate-phase3.cjs +208 -0
- package/scripts/dev/validate-security-remediation.js +1 -0
- package/scripts/ecosystem.config.cjs +90 -0
- package/scripts/fix-js-extensions.js +167 -0
- package/scripts/generate-basic-types.js +73 -0
- package/scripts/generate-changelog.js +318 -0
- package/scripts/git-hooks/pre-commit.sh +143 -0
- package/scripts/health-checks.js +634 -0
- package/scripts/hook-wrapper.sh +54 -0
- package/scripts/install/README.md +375 -0
- package/scripts/install/REDIS_SETUP_VALIDATION.json +245 -0
- package/scripts/install/check-prerequisites.js +303 -0
- package/scripts/install/config-wizard.js +606 -0
- package/scripts/install/dependency-checker.js +385 -0
- package/scripts/install/health-check.js +765 -0
- package/scripts/install/install.js +256 -0
- package/scripts/install/installation-benchmark.js +461 -0
- package/scripts/install/quick-install.js +720 -0
- package/scripts/install/quick-start-wizard.js +295 -0
- package/scripts/install/redis-cli.js +289 -0
- package/scripts/install/redis-install-guides.md +407 -0
- package/scripts/install/redis-setup.js +559 -0
- package/scripts/install/redis-test.js +278 -0
- package/scripts/install/service-manager.js +672 -0
- package/scripts/install/setup.js +832 -0
- package/scripts/install/uninstall.js +526 -0
- package/scripts/install/update.js +461 -0
- package/scripts/install-pre-commit-hook.sh +127 -0
- package/scripts/legacy/README.md +272 -0
- package/scripts/legacy/batch-fix-ts.sh +54 -0
- package/scripts/legacy/build-migration.sh +105 -0
- package/scripts/legacy/build-monitor.js +209 -0
- package/scripts/legacy/build-with-filter.sh +84 -0
- package/scripts/legacy/build-workaround.sh +71 -0
- package/scripts/legacy/fix-ts-advanced.js +358 -0
- package/scripts/legacy/fix-ts-final.sh +50 -0
- package/scripts/legacy/fix-ts-targeted.sh +49 -0
- package/scripts/legacy/fix-typescript-errors.js +305 -0
- package/scripts/legacy/force-build.sh +63 -0
- package/scripts/legacy/optimize-performance.js +400 -0
- package/scripts/legacy/performance-monitor.js +263 -0
- package/scripts/legacy/performance-monitoring.js +532 -0
- package/scripts/legacy/performance-test-runner.js +645 -0
- package/scripts/legacy/quick-fix-ts.js +281 -0
- package/scripts/legacy/safe-build.sh +63 -0
- package/scripts/memory-monitor-coordinator.js +322 -0
- package/scripts/migrate-to-sdk.sh +520 -0
- package/scripts/migration/QUICK-START.md +189 -0
- package/scripts/migration/QUICK-START.md.backup-1760135091363 +189 -0
- package/scripts/migration/README.md +464 -0
- package/scripts/migration/TASK-1.3.2-COMPLETION-REPORT.md +500 -0
- package/scripts/migration/TASK-1.3.2-COMPLETION-REPORT.md.backup-1760135091348 +500 -0
- package/scripts/migration/UPDATE-PATHS-README.md +464 -0
- package/scripts/migration/UPDATE-PATHS-README.md.backup-1760135091337 +464 -0
- package/scripts/migration/example-patterns.json +19 -0
- package/scripts/migration/install-arm64.js +78 -0
- package/scripts/migration/install.js +83 -0
- package/scripts/migration/migrate-hooks.js +173 -0
- package/scripts/migration/migration-examples.ts +318 -0
- package/scripts/migration/reorganize-workspace.js +504 -0
- package/scripts/migration/test-update-paths.js +359 -0
- package/scripts/migration/update-paths.js +664 -0
- package/scripts/migration/validate-migration.js +647 -0
- package/scripts/monitor-loop.sh +65 -0
- package/scripts/monitor-memory.sh +47 -0
- package/scripts/monitor-migration.js +339 -0
- package/scripts/monitor.py +43 -0
- package/scripts/monitoring/README.md +178 -0
- package/scripts/monitoring/alert-monitor.sh +220 -0
- package/scripts/monitoring/analyze-resources.sh +199 -0
- package/scripts/monitoring/dashboards/rate-limiting-dashboard.json +211 -0
- package/scripts/monitoring/dynamic-monitor.sh +85 -0
- package/scripts/monitoring/launch-stability-test.sh +184 -0
- package/scripts/monitoring/monitor-test.sh +93 -0
- package/scripts/monitoring/pre-test-validation.sh +208 -0
- package/scripts/monitoring/quick-test-alerting.sh +118 -0
- package/scripts/monitoring/quick-test-rate-limiting.sh +206 -0
- package/scripts/monitoring/rate-limiting-monitor.sh +380 -0
- package/scripts/monitoring/resource-monitor.sh +126 -0
- package/scripts/monitoring/stability-monitor.js +429 -0
- package/scripts/monitoring/test-monitor-quick.sh +54 -0
- package/scripts/monitoring/view-alerts.sh +307 -0
- package/scripts/npm-metrics-collector.js +482 -0
- package/scripts/npm-package-validation.cjs +299 -0
- package/scripts/optimization/build-optimizer.js +438 -0
- package/scripts/optimization/config-validator.js +761 -0
- package/scripts/optimization/test-optimization.js +432 -0
- package/scripts/optimization/unified-activation.js +839 -0
- package/scripts/optimize-package-swarm.js +54 -0
- package/scripts/performance/ACTIVATION_COMMANDS.md +292 -0
- package/scripts/performance/sqlite-enhanced-activation.sh +583 -0
- package/scripts/performance/test-enhanced-backend.sh +504 -0
- package/scripts/performance-monitor.js +644 -0
- package/scripts/performance-test-runner.js +698 -0
- package/scripts/post-deployment-monitoring.js +350 -0
- package/scripts/post-edit-pipeline.js +2091 -0
- package/scripts/post-install-claude-md.js +78 -0
- package/scripts/postinstall.js +79 -0
- package/scripts/pre-publish-validation.cjs +212 -0
- package/scripts/pre-publish-validation.js +429 -0
- package/scripts/redis-lua/cleanup-blocking-coordination.lua +198 -0
- package/scripts/release-announcement.js +425 -0
- package/scripts/release-notification.js +248 -0
- package/scripts/release-rollback.js +376 -0
- package/scripts/release-validation.js +460 -0
- package/scripts/rollback-sdk.sh +66 -0
- package/scripts/run-production-validation.ts +590 -0
- package/scripts/run-stability-validation.sh +687 -0
- package/scripts/security/README.md +339 -0
- package/scripts/security/deployment-validation.cjs +279 -0
- package/scripts/security/envelope-encryption-confidence-report.cjs +422 -0
- package/scripts/security/install-git-hooks.sh +132 -0
- package/scripts/security/install-git-secrets.sh +295 -0
- package/scripts/security/rotate-api-keys.js +469 -0
- package/scripts/security/ruv-swarm-safe.js +74 -0
- package/scripts/security/security-audit.cjs +538 -0
- package/scripts/security/setup-redis-auth.sh +397 -0
- package/scripts/security/validate-envelope-encryption.cjs +340 -0
- package/scripts/security-scan.js +492 -0
- package/scripts/src/web/frontend/.claude-flow/metrics/agent-metrics.json +1 -0
- package/scripts/src/web/frontend/.claude-flow/metrics/performance.json +9 -0
- package/scripts/src/web/frontend/.claude-flow/metrics/task-metrics.json +10 -0
- package/scripts/switch-api.sh +158 -0
- package/scripts/sync-agents.js +290 -0
- package/scripts/test/50-agent-test.js +625 -0
- package/scripts/test/NEW_STABILITY_TEST_GUIDE.md +407 -0
- package/scripts/test/README.md +236 -0
- package/scripts/test/STABILITY_TEST_EXAMPLE.md +347 -0
- package/scripts/test/STABILITY_TEST_README.md +480 -0
- package/scripts/test/agent-worker.js +309 -0
- package/scripts/test/ai-coordination-test.js +650 -0
- package/scripts/test/ai-mesh-coordination-test.js +416 -0
- package/scripts/test/check-links.ts +274 -0
- package/scripts/test/check-performance-regression.ts +168 -0
- package/scripts/test/cli-agent-coordination-test.js +313 -0
- package/scripts/test/coordinator-multilingual-test.js +396 -0
- package/scripts/test/coordinator-transparency-demo.js +585 -0
- package/scripts/test/coverage-report.ts +692 -0
- package/scripts/test/generate-swarm-tests.js +633 -0
- package/scripts/test/integration-test-validation.cjs +253 -0
- package/scripts/test/load-test-swarm.js +576 -0
- package/scripts/test/mesh-coordination-zero-overlap-test.js +740 -0
- package/scripts/test/multilingual-hello-world-test.js +390 -0
- package/scripts/test/quick-multilingual-demo.js +464 -0
- package/scripts/test/real-agent-test.js +312 -0
- package/scripts/test/run-phase3-compliance-tests.js +427 -0
- package/scripts/test/run-stability-test-examples.sh +292 -0
- package/scripts/test/stability-results/stability-metrics.jsonl +83 -0
- package/scripts/test/stability-results/stability-test-report.json +128 -0
- package/scripts/test/stability-results/stability-test.log +1827 -0
- package/scripts/test/stability-test-50-agents.js +734 -0
- package/scripts/test/test-batch-tasks.ts +29 -0
- package/scripts/test/test-byzantine-resolution.js +246 -0
- package/scripts/test/test-claude-spawn-options.sh +63 -0
- package/scripts/test/test-cli-wizard.js +331 -0
- package/scripts/test/test-comprehensive.js +401 -0
- package/scripts/test/test-coordination-features.ts +238 -0
- package/scripts/test/test-fallback-systems.js +276 -0
- package/scripts/test/test-init-command.ts +302 -0
- package/scripts/test/test-mcp.ts +251 -0
- package/scripts/test/test-runner.ts +568 -0
- package/scripts/test/test-swarm-integration.sh +92 -0
- package/scripts/test/test-swarm.ts +142 -0
- package/scripts/test/validation-summary.ts +408 -0
- package/scripts/test-cleanup-performance.sh +416 -0
- package/scripts/test-dashboard-auth.cjs +203 -0
- package/scripts/test-docker-deployment.sh +207 -0
- package/scripts/test-npm-package.cjs +167 -0
- package/scripts/test-provider-routing.cjs +226 -0
- package/scripts/test-routing-telemetry.cjs +147 -0
- package/scripts/test-runner.cjs +154 -0
- package/scripts/test-zai-10k.cjs +81 -0
- package/scripts/test-zai-api.cjs +191 -0
- package/scripts/test-zai-diagnostic.cjs +151 -0
- package/scripts/test-zai-final.cjs +128 -0
- package/scripts/test-zai-with-env.cjs +85 -0
- package/scripts/utils/README.md +261 -0
- package/scripts/utils/clean-build-artifacts.sh +94 -0
- package/scripts/utils/cleanup-root.sh +69 -0
- package/scripts/utils/fix-cliffy-imports.js +307 -0
- package/scripts/utils/fix-duplicate-imports.js +114 -0
- package/scripts/utils/fix-error-handling.cjs +70 -0
- package/scripts/utils/fix-import-paths.js +104 -0
- package/scripts/utils/fix-imports.js +116 -0
- package/scripts/utils/fix-shebang.js +78 -0
- package/scripts/utils/fix-test-modules.js +27 -0
- package/scripts/utils/fix-timezone-issue-246.js +200 -0
- package/scripts/utils/fix-ts-comprehensive.py +182 -0
- package/scripts/utils/fix-ts-targeted-batch.js +250 -0
- package/scripts/utils/remove-benchmark-conflicts.sh +140 -0
- package/scripts/utils/simple-test-fixer.js +190 -0
- package/scripts/utils/validate-metrics-structure.cjs +144 -0
- package/scripts/validate-agent-hooks.js +506 -0
- package/scripts/validate-changelog.js +241 -0
- package/scripts/validate-coordination-cli.js +69 -0
- package/scripts/validate-coordination-toggle-integration.cjs +501 -0
- package/scripts/validate-docker-infrastructure.sh +502 -0
- package/scripts/validate-entry-points.js +300 -0
- package/scripts/validate-stage3-performance.ts +377 -0
- package/scripts/validate-template-bundling.js +180 -0
- package/scripts/validation/README.md +33 -0
- package/scripts/validation/acl-security-validation.cjs +214 -0
- package/scripts/validation/acl-security-validation.js +402 -0
- package/scripts/validation/byzantine-verification.js +407 -0
- package/scripts/validation/final-phase-2-consensus.cjs +219 -0
- package/scripts/validation/final-security-validation.js +791 -0
- package/scripts/validation/final-wasm-validation.cjs +840 -0
- package/scripts/validation/integration-test-analysis.js +105 -0
- package/scripts/validation/phase-0-comprehensive-validation.js +474 -0
- package/scripts/validation/phase-0-consensus-report.js +139 -0
- package/scripts/validation/phase-0-final-report.js +112 -0
- package/scripts/validation/phase-0-redis-consensus-report.js +129 -0
- package/scripts/validation/phase-0-validation-improved.js +490 -0
- package/scripts/validation/phase-0-validation-test.js +65 -0
- package/scripts/validation/phase-1-consensus-report.cjs +342 -0
- package/scripts/validation/phase-1-consensus-validation.cjs +551 -0
- package/scripts/validation/phase-1-consensus-validation.js +551 -0
- package/scripts/validation/phase-2-consensus-report.cjs +186 -0
- package/scripts/validation/phase-2-validation.cjs +171 -0
- package/scripts/validation/phase-2-validation.js +171 -0
- package/scripts/validation/phase-4-consensus-report.js +181 -0
- package/scripts/validation/phase-4-final-validation.js +351 -0
- package/scripts/validation/phase-5-consensus-report.cjs +113 -0
- package/scripts/validation/phase-5-consensus-report.js +113 -0
- package/scripts/validation/security-analysis.js +49 -0
- package/scripts/validation/security-validation.js +492 -0
- package/scripts/validation/simple-security-validation.js +464 -0
- package/scripts/verify-installation.js +112 -0
- package/scripts/verify-mcp-server.js +86 -0
- package/scripts/verify-sdk-phase1.cjs +293 -0
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Test Provider Routing Telemetry
|
|
3
|
+
*
|
|
4
|
+
* Tests tiered routing with telemetry to measure API calls to:
|
|
5
|
+
* - Z.ai (Tier 2 default)
|
|
6
|
+
* - Anthropic subscription (Tier 1)
|
|
7
|
+
* - Anthropic explicit (Tier 3)
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
const { TelemetrySystem } = require('../.claude-flow-novice/dist/src/observability/telemetry.js');
|
|
11
|
+
const { TieredProviderRouter } = require('../.claude-flow-novice/dist/src/providers/tiered-router.js');
|
|
12
|
+
|
|
13
|
+
async function testRoutingTelemetry() {
|
|
14
|
+
console.log('๐ฌ Testing Provider Routing Telemetry\n');
|
|
15
|
+
|
|
16
|
+
// Initialize telemetry
|
|
17
|
+
const telemetry = new TelemetrySystem({
|
|
18
|
+
enableTracing: true,
|
|
19
|
+
enableMetrics: true,
|
|
20
|
+
enableStructuredLogging: true,
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
telemetry.initialize();
|
|
24
|
+
|
|
25
|
+
// Listen to metric events
|
|
26
|
+
const metricEvents = [];
|
|
27
|
+
telemetry.on('metric:counter', (metric) => {
|
|
28
|
+
if (metric.name === 'provider.request') {
|
|
29
|
+
metricEvents.push(metric);
|
|
30
|
+
console.log(`๐ Metric: ${metric.tags.provider} via ${metric.tags.tier} (agent: ${metric.tags.agentType})`);
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
telemetry.on('metric:gauge', (metric) => {
|
|
35
|
+
if (metric.name === 'subscription.usage') {
|
|
36
|
+
console.log(`๐ Subscription: ${metric.value}/${metric.tags.limit} (${metric.tags.remaining} remaining)`);
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
// Create tiered router with injected telemetry instance
|
|
41
|
+
const router = new TieredProviderRouter(
|
|
42
|
+
undefined, // Use default tier config
|
|
43
|
+
{ used: 0, limit: 5 }, // Mock subscription: 5 requests limit
|
|
44
|
+
undefined, // Use default agents directory
|
|
45
|
+
telemetry // Inject telemetry instance to capture metrics
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
console.log('๐ฏ Test Scenario: Simulate 10 agent requests\n');
|
|
49
|
+
|
|
50
|
+
// Test 1: Default agents (should use Z.ai)
|
|
51
|
+
console.log('--- Test 1: Default agents (Z.ai expected) ---');
|
|
52
|
+
for (let i = 0; i < 3; i++) {
|
|
53
|
+
await router.selectProvider('coder');
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// Test 2: Coordinator agents (should use subscription until exhausted)
|
|
57
|
+
console.log('\n--- Test 2: Coordinator agents (subscription expected) ---');
|
|
58
|
+
for (let i = 0; i < 4; i++) {
|
|
59
|
+
await router.selectProvider('coordinator');
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// Test 3: More coordinator agents (subscription exhausted, fallback to Z.ai)
|
|
63
|
+
console.log('\n--- Test 3: More coordinators (fallback to Z.ai expected) ---');
|
|
64
|
+
for (let i = 0; i < 3; i++) {
|
|
65
|
+
await router.selectProvider('coordinator');
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// Wait for metrics flush
|
|
69
|
+
await new Promise(resolve => setTimeout(resolve, 100));
|
|
70
|
+
|
|
71
|
+
// Analyze results
|
|
72
|
+
console.log('\n๐ === TELEMETRY RESULTS ===\n');
|
|
73
|
+
|
|
74
|
+
const providerBreakdown = {};
|
|
75
|
+
const tierBreakdown = {};
|
|
76
|
+
const sourceBreakdown = {};
|
|
77
|
+
|
|
78
|
+
metricEvents.forEach(metric => {
|
|
79
|
+
const provider = metric.tags.provider;
|
|
80
|
+
const tier = metric.tags.tier;
|
|
81
|
+
const source = metric.tags.source;
|
|
82
|
+
|
|
83
|
+
providerBreakdown[provider] = (providerBreakdown[provider] || 0) + metric.value;
|
|
84
|
+
tierBreakdown[tier] = (tierBreakdown[tier] || 0) + metric.value;
|
|
85
|
+
sourceBreakdown[source] = (sourceBreakdown[source] || 0) + metric.value;
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
console.log('By Provider:');
|
|
89
|
+
Object.entries(providerBreakdown).forEach(([provider, count]) => {
|
|
90
|
+
console.log(` ${provider}: ${count} requests`);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
console.log('\nBy Tier:');
|
|
94
|
+
Object.entries(tierBreakdown).forEach(([tier, count]) => {
|
|
95
|
+
console.log(` ${tier}: ${count} requests`);
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
console.log('\nBy Source:');
|
|
99
|
+
Object.entries(sourceBreakdown).forEach(([source, count]) => {
|
|
100
|
+
console.log(` ${source}: ${count} requests`);
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
// Get subscription usage
|
|
104
|
+
const subUsage = router.getSubscriptionUsage();
|
|
105
|
+
console.log('\n๐ Subscription Usage:');
|
|
106
|
+
console.log(` Used: ${subUsage.used}/${subUsage.limit}`);
|
|
107
|
+
console.log(` Remaining: ${subUsage.limit - subUsage.used}`);
|
|
108
|
+
|
|
109
|
+
// Validate expectations
|
|
110
|
+
console.log('\nโ
=== VALIDATION ===\n');
|
|
111
|
+
|
|
112
|
+
const zaiCount = providerBreakdown['custom'] || 0;
|
|
113
|
+
const anthropicCount = providerBreakdown['anthropic'] || 0;
|
|
114
|
+
|
|
115
|
+
console.log(`Z.ai requests: ${zaiCount} (expected: 5 - 3 coder + 2 fallback)`);
|
|
116
|
+
console.log(`Anthropic requests: ${anthropicCount} (expected: 5 - subscription limit reached)`);
|
|
117
|
+
|
|
118
|
+
if (zaiCount === 5 && anthropicCount === 5) {
|
|
119
|
+
console.log('\nโ
SUCCESS: Telemetry correctly tracked routing decisions!');
|
|
120
|
+
console.log(' - Z.ai received 3 coder requests via profile override');
|
|
121
|
+
console.log(' - Subscription tier consumed all 5 slots for coordinators');
|
|
122
|
+
console.log(' - 2 coordinator requests fell back to Z.ai after limit');
|
|
123
|
+
console.log(' - All 10 requests were measured correctly');
|
|
124
|
+
} else {
|
|
125
|
+
console.log('\nโ UNEXPECTED: Metric counts differ from expected');
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// Query telemetry directly
|
|
129
|
+
console.log('\n๐ === TELEMETRY QUERY ===\n');
|
|
130
|
+
const providerMetrics = telemetry.getMetrics('provider.request');
|
|
131
|
+
console.log(`Total provider.request metrics: ${providerMetrics.length}`);
|
|
132
|
+
|
|
133
|
+
const throughput = telemetry.getThroughputMetrics('provider.request', 60000);
|
|
134
|
+
console.log(`Throughput: ${throughput.requestsPerSecond.toFixed(2)} req/s`);
|
|
135
|
+
console.log(`Success rate: ${(throughput.successRate * 100).toFixed(1)}%`);
|
|
136
|
+
|
|
137
|
+
// Cleanup
|
|
138
|
+
telemetry.shutdown();
|
|
139
|
+
|
|
140
|
+
console.log('\n๐ Test complete!\n');
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// Run test
|
|
144
|
+
testRoutingTelemetry().catch(err => {
|
|
145
|
+
console.error('โ Test failed:', err);
|
|
146
|
+
process.exit(1);
|
|
147
|
+
});
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Intelligent Test Runner
|
|
5
|
+
*
|
|
6
|
+
* Categorizes and runs tests based on type:
|
|
7
|
+
* - unit: Fast, isolated tests (run first)
|
|
8
|
+
* - integration: Component integration tests
|
|
9
|
+
* - e2e: End-to-end workflow tests
|
|
10
|
+
* - performance: Benchmark tests (skip in CI)
|
|
11
|
+
* - chaos: Chaos engineering tests (skip in quick runs)
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
const { execSync } = require('child_process');
|
|
15
|
+
const fs = require('fs');
|
|
16
|
+
const path = require('path');
|
|
17
|
+
|
|
18
|
+
const CATEGORIES = {
|
|
19
|
+
unit: {
|
|
20
|
+
pattern: 'tests/unit/**/*.test.{ts,js}',
|
|
21
|
+
timeout: 30000,
|
|
22
|
+
priority: 1,
|
|
23
|
+
description: 'Unit tests (fast, isolated)'
|
|
24
|
+
},
|
|
25
|
+
integration: {
|
|
26
|
+
pattern: 'tests/integration/**/*.test.{ts,js}',
|
|
27
|
+
timeout: 60000,
|
|
28
|
+
priority: 2,
|
|
29
|
+
description: 'Integration tests'
|
|
30
|
+
},
|
|
31
|
+
e2e: {
|
|
32
|
+
pattern: 'tests/**/e2e/**/*.test.{ts,js}',
|
|
33
|
+
timeout: 120000,
|
|
34
|
+
priority: 3,
|
|
35
|
+
description: 'End-to-end tests'
|
|
36
|
+
},
|
|
37
|
+
uncategorized: {
|
|
38
|
+
pattern: 'tests/*.test.{ts,js}',
|
|
39
|
+
timeout: 30000,
|
|
40
|
+
priority: 4,
|
|
41
|
+
description: 'Uncategorized tests'
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const SKIP_CATEGORIES = {
|
|
46
|
+
chaos: 'tests/chaos/**/*.test.{ts,js}',
|
|
47
|
+
benchmark: 'tests/benchmarks/**/*.test.{ts,js}',
|
|
48
|
+
archived: 'tests/archived/**/*.test.{ts,js}',
|
|
49
|
+
performance: 'tests/performance/**/*.test.{ts,js}'
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
function parseArgs() {
|
|
53
|
+
const args = process.argv.slice(2);
|
|
54
|
+
const options = {
|
|
55
|
+
category: 'all',
|
|
56
|
+
coverage: false,
|
|
57
|
+
watch: false,
|
|
58
|
+
verbose: false,
|
|
59
|
+
quick: false
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
for (const arg of args) {
|
|
63
|
+
if (arg === '--coverage') options.coverage = true;
|
|
64
|
+
else if (arg === '--watch') options.watch = true;
|
|
65
|
+
else if (arg === '--verbose') options.verbose = true;
|
|
66
|
+
else if (arg === '--quick') options.quick = true;
|
|
67
|
+
else if (arg.startsWith('--category=')) {
|
|
68
|
+
options.category = arg.split('=')[1];
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return options;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function runTests(category, pattern, timeout, options) {
|
|
76
|
+
console.log(`\n๐งช Running ${category} tests...`);
|
|
77
|
+
|
|
78
|
+
try {
|
|
79
|
+
// Convert glob pattern to regex for Jest
|
|
80
|
+
const regexPattern = pattern
|
|
81
|
+
.replace(/\*\*/g, '.*')
|
|
82
|
+
.replace(/\*/g, '[^/]*')
|
|
83
|
+
.replace(/\{ts,js\}/g, '(ts|js)');
|
|
84
|
+
|
|
85
|
+
const jestArgs = [
|
|
86
|
+
`--config=config/jest/jest.config.js`,
|
|
87
|
+
`--testPathPatterns="${regexPattern}"`,
|
|
88
|
+
`--testTimeout=${timeout}`,
|
|
89
|
+
`--maxWorkers=2`,
|
|
90
|
+
'--bail',
|
|
91
|
+
options.coverage ? '--coverage' : '',
|
|
92
|
+
options.watch ? '--watch' : '',
|
|
93
|
+
options.verbose ? '--verbose' : ''
|
|
94
|
+
].filter(Boolean).join(' ');
|
|
95
|
+
|
|
96
|
+
const cmd = `NODE_OPTIONS='--experimental-vm-modules --max-old-space-size=8192' jest ${jestArgs}`;
|
|
97
|
+
|
|
98
|
+
execSync(cmd, {
|
|
99
|
+
stdio: 'inherit',
|
|
100
|
+
cwd: path.resolve(__dirname, '..')
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
console.log(`โ
${category} tests passed\n`);
|
|
104
|
+
return true;
|
|
105
|
+
} catch (error) {
|
|
106
|
+
console.error(`โ ${category} tests failed\n`);
|
|
107
|
+
return false;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function main() {
|
|
112
|
+
const options = parseArgs();
|
|
113
|
+
|
|
114
|
+
console.log('๐ฏ Claude Flow Test Runner');
|
|
115
|
+
console.log('โ'.repeat(50));
|
|
116
|
+
|
|
117
|
+
if (options.quick) {
|
|
118
|
+
console.log('โก Quick mode: Running unit tests only');
|
|
119
|
+
const success = runTests('unit', CATEGORIES.unit.pattern, CATEGORIES.unit.timeout, options);
|
|
120
|
+
process.exit(success ? 0 : 1);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
if (options.category !== 'all') {
|
|
124
|
+
const cat = CATEGORIES[options.category];
|
|
125
|
+
if (!cat) {
|
|
126
|
+
console.error(`โ Unknown category: ${options.category}`);
|
|
127
|
+
console.log('Available categories:', Object.keys(CATEGORIES).join(', '));
|
|
128
|
+
process.exit(1);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
const success = runTests(options.category, cat.pattern, cat.timeout, options);
|
|
132
|
+
process.exit(success ? 0 : 1);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// Run all categories in order of priority
|
|
136
|
+
const sortedCategories = Object.entries(CATEGORIES)
|
|
137
|
+
.sort(([, a], [, b]) => a.priority - b.priority);
|
|
138
|
+
|
|
139
|
+
let allPassed = true;
|
|
140
|
+
for (const [name, config] of sortedCategories) {
|
|
141
|
+
const success = runTests(name, config.pattern, config.timeout, options);
|
|
142
|
+
if (!success) allPassed = false;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
if (allPassed) {
|
|
146
|
+
console.log('\nโ
All test categories passed!');
|
|
147
|
+
} else {
|
|
148
|
+
console.log('\nโ Some tests failed');
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
process.exit(allPassed ? 0 : 1);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
main();
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const https = require('https');
|
|
4
|
+
const fs = require('fs');
|
|
5
|
+
const path = require('path');
|
|
6
|
+
|
|
7
|
+
// Load .env
|
|
8
|
+
const envPath = path.join(process.cwd(), '.env');
|
|
9
|
+
if (fs.existsSync(envPath)) {
|
|
10
|
+
fs.readFileSync(envPath, 'utf8').split('\n').forEach(line => {
|
|
11
|
+
const match = line.trim().match(/^([^=]+)=(.*)$/);
|
|
12
|
+
if (match) {
|
|
13
|
+
const key = match[1].trim();
|
|
14
|
+
let value = match[2].trim().replace(/^["']|["']$/g, '');
|
|
15
|
+
process.env[key] = value;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const API_KEY = process.env.ZAI_API_KEY;
|
|
21
|
+
|
|
22
|
+
console.log('\n๐ Z.ai API Test - 10K Max Tokens\n');
|
|
23
|
+
console.log('='.repeat(80) + '\n');
|
|
24
|
+
|
|
25
|
+
const payload = {
|
|
26
|
+
model: 'claude-3-5-sonnet-20241022',
|
|
27
|
+
max_tokens: 10000,
|
|
28
|
+
messages: [
|
|
29
|
+
{ role: 'user', content: 'Write a haiku about AI and coding. Then explain why you chose those words.' }
|
|
30
|
+
]
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const url = new URL('https://api.z.ai/api/anthropic/v1/messages');
|
|
34
|
+
|
|
35
|
+
const options = {
|
|
36
|
+
hostname: url.hostname,
|
|
37
|
+
port: 443,
|
|
38
|
+
path: url.pathname,
|
|
39
|
+
method: 'POST',
|
|
40
|
+
headers: {
|
|
41
|
+
'Content-Type': 'application/json',
|
|
42
|
+
'x-api-key': API_KEY,
|
|
43
|
+
'anthropic-version': '2023-06-01'
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const req = https.request(options, (res) => {
|
|
48
|
+
let body = '';
|
|
49
|
+
res.on('data', chunk => body += chunk);
|
|
50
|
+
res.on('end', () => {
|
|
51
|
+
const result = JSON.parse(body);
|
|
52
|
+
|
|
53
|
+
console.log('โ
Response received!\n');
|
|
54
|
+
console.log('Status:', res.statusCode);
|
|
55
|
+
console.log('Model:', result.model);
|
|
56
|
+
console.log('\nContent:');
|
|
57
|
+
console.log(result.content[0].text);
|
|
58
|
+
console.log('\nToken usage:');
|
|
59
|
+
console.log(' Input:', result.usage.input_tokens);
|
|
60
|
+
console.log(' Output:', result.usage.output_tokens);
|
|
61
|
+
console.log(' Total:', result.usage.input_tokens + result.usage.output_tokens);
|
|
62
|
+
|
|
63
|
+
const cost = (result.usage.input_tokens / 1000 * 0.003) +
|
|
64
|
+
(result.usage.output_tokens / 1000 * 0.015);
|
|
65
|
+
console.log('\nEstimated cost: $' + cost.toFixed(6));
|
|
66
|
+
console.log('\n' + '='.repeat(80) + '\n');
|
|
67
|
+
console.log('โ
Z.ai with 10K max_tokens working correctly!\n');
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
req.on('error', (error) => {
|
|
72
|
+
console.error('โ Error:', error.message);
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
req.setTimeout(45000, () => {
|
|
76
|
+
req.destroy();
|
|
77
|
+
console.error('โ Request timeout');
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
req.write(JSON.stringify(payload));
|
|
81
|
+
req.end();
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Direct Z.ai API Test
|
|
5
|
+
* Tests Z.ai API connectivity and response
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
const https = require('https');
|
|
9
|
+
const http = require('http');
|
|
10
|
+
|
|
11
|
+
const API_KEY = process.env.Z_AI_API_KEY || process.env.ZAI_API_KEY || process.env.ANTHROPIC_AUTH_TOKEN;
|
|
12
|
+
const BASE_URL = 'https://api.z.ai/api/anthropic';
|
|
13
|
+
const DEFAULT_MODEL = 'claude-3-5-sonnet-20241022';
|
|
14
|
+
|
|
15
|
+
function makeRequest(options, data) {
|
|
16
|
+
return new Promise((resolve, reject) => {
|
|
17
|
+
const protocol = options.protocol === 'https:' ? https : http;
|
|
18
|
+
|
|
19
|
+
const req = protocol.request(options, (res) => {
|
|
20
|
+
let body = '';
|
|
21
|
+
|
|
22
|
+
res.on('data', (chunk) => {
|
|
23
|
+
body += chunk;
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
res.on('end', () => {
|
|
27
|
+
if (res.statusCode >= 200 && res.statusCode < 300) {
|
|
28
|
+
try {
|
|
29
|
+
resolve({
|
|
30
|
+
statusCode: res.statusCode,
|
|
31
|
+
headers: res.headers,
|
|
32
|
+
body: JSON.parse(body)
|
|
33
|
+
});
|
|
34
|
+
} catch (e) {
|
|
35
|
+
resolve({
|
|
36
|
+
statusCode: res.statusCode,
|
|
37
|
+
headers: res.headers,
|
|
38
|
+
body: body
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
} else {
|
|
42
|
+
reject(new Error(`HTTP ${res.statusCode}: ${body}`));
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
req.on('error', (error) => {
|
|
48
|
+
reject(error);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
req.setTimeout(30000, () => {
|
|
52
|
+
req.destroy();
|
|
53
|
+
reject(new Error('Request timeout after 30s'));
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
if (data) {
|
|
57
|
+
req.write(data);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
req.end();
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
async function testZaiAPI() {
|
|
65
|
+
console.log('\n๐งช Z.ai API Direct Test\n');
|
|
66
|
+
console.log('='.repeat(80) + '\n');
|
|
67
|
+
|
|
68
|
+
// Check API key
|
|
69
|
+
if (!API_KEY) {
|
|
70
|
+
console.error('โ ERROR: Z_AI_API_KEY or ZAI_API_KEY environment variable not set');
|
|
71
|
+
console.log('\nPlease set your Z.ai API key:');
|
|
72
|
+
console.log(' export ZAI_API_KEY=$YOUR_KEY');
|
|
73
|
+
console.log(' or');
|
|
74
|
+
console.log(' ZAI_API_KEY=$YOUR_KEY node scripts/test-zai-api.cjs\n');
|
|
75
|
+
process.exit(1);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
console.log('โ API Key found:', API_KEY.substring(0, 10) + '...' + API_KEY.substring(API_KEY.length - 4));
|
|
79
|
+
console.log('โ Base URL:', BASE_URL);
|
|
80
|
+
console.log('โ Model:', DEFAULT_MODEL);
|
|
81
|
+
console.log('\n' + '-'.repeat(80) + '\n');
|
|
82
|
+
|
|
83
|
+
// Test payload (Anthropic Messages API format)
|
|
84
|
+
const payload = {
|
|
85
|
+
model: DEFAULT_MODEL,
|
|
86
|
+
max_tokens: 50,
|
|
87
|
+
messages: [
|
|
88
|
+
{
|
|
89
|
+
role: 'user',
|
|
90
|
+
content: 'Say "Hello from Z.ai!" and nothing else.'
|
|
91
|
+
}
|
|
92
|
+
]
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
console.log('๐ค Sending request...\n');
|
|
96
|
+
console.log('Request payload:');
|
|
97
|
+
console.log(JSON.stringify(payload, null, 2));
|
|
98
|
+
console.log('\n' + '-'.repeat(80) + '\n');
|
|
99
|
+
|
|
100
|
+
try {
|
|
101
|
+
const url = new URL(`${BASE_URL}/v1/messages`);
|
|
102
|
+
|
|
103
|
+
const options = {
|
|
104
|
+
hostname: url.hostname,
|
|
105
|
+
port: url.port || 443,
|
|
106
|
+
path: url.pathname,
|
|
107
|
+
method: 'POST',
|
|
108
|
+
protocol: url.protocol,
|
|
109
|
+
headers: {
|
|
110
|
+
'Content-Type': 'application/json',
|
|
111
|
+
'x-api-key': API_KEY,
|
|
112
|
+
'anthropic-version': '2023-06-01'
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
const startTime = Date.now();
|
|
117
|
+
const response = await makeRequest(options, JSON.stringify(payload));
|
|
118
|
+
const duration = Date.now() - startTime;
|
|
119
|
+
|
|
120
|
+
console.log('๐ฅ Response received!\n');
|
|
121
|
+
console.log(`โฑ๏ธ Duration: ${duration}ms`);
|
|
122
|
+
console.log(`๐ Status: ${response.statusCode}`);
|
|
123
|
+
console.log('\n' + '-'.repeat(80) + '\n');
|
|
124
|
+
|
|
125
|
+
if (response.body.content && response.body.content.length > 0) {
|
|
126
|
+
console.log('โ
SUCCESS!\n');
|
|
127
|
+
console.log('Response content:');
|
|
128
|
+
console.log(' ' + response.body.content[0].text);
|
|
129
|
+
console.log('\nModel:', response.body.model);
|
|
130
|
+
console.log('Stop reason:', response.body.stop_reason);
|
|
131
|
+
|
|
132
|
+
if (response.body.usage) {
|
|
133
|
+
console.log('\nToken usage:');
|
|
134
|
+
console.log(' Input tokens: ', response.body.usage.input_tokens);
|
|
135
|
+
console.log(' Output tokens: ', response.body.usage.output_tokens);
|
|
136
|
+
|
|
137
|
+
// Calculate cost (Z.ai pricing: $0.003 per 1K prompt, $0.015 per 1K completion)
|
|
138
|
+
const promptCost = (response.body.usage.input_tokens / 1000) * 0.003;
|
|
139
|
+
const completionCost = (response.body.usage.output_tokens / 1000) * 0.015;
|
|
140
|
+
const totalCost = promptCost + completionCost;
|
|
141
|
+
|
|
142
|
+
console.log('\nEstimated cost:');
|
|
143
|
+
console.log(` Input: $${promptCost.toFixed(6)}`);
|
|
144
|
+
console.log(` Output: $${completionCost.toFixed(6)}`);
|
|
145
|
+
console.log(` Total: $${totalCost.toFixed(6)}`);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
console.log('\n' + '='.repeat(80));
|
|
149
|
+
console.log('\nโ
Z.ai API is working correctly!\n');
|
|
150
|
+
|
|
151
|
+
return {
|
|
152
|
+
success: true,
|
|
153
|
+
response: response.body,
|
|
154
|
+
duration
|
|
155
|
+
};
|
|
156
|
+
} else {
|
|
157
|
+
console.log('โ ๏ธ Warning: Unexpected response format');
|
|
158
|
+
console.log('\nFull response:');
|
|
159
|
+
console.log(JSON.stringify(response.body, null, 2));
|
|
160
|
+
console.log('\n' + '='.repeat(80) + '\n');
|
|
161
|
+
|
|
162
|
+
return {
|
|
163
|
+
success: false,
|
|
164
|
+
error: 'Unexpected response format',
|
|
165
|
+
response: response.body
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
} catch (error) {
|
|
169
|
+
console.error('โ ERROR:\n');
|
|
170
|
+
console.error(error.message);
|
|
171
|
+
|
|
172
|
+
if (error.message.includes('401')) {
|
|
173
|
+
console.log('\n๐ก Tip: Check that your Z_AI_API_KEY is valid');
|
|
174
|
+
} else if (error.message.includes('429')) {
|
|
175
|
+
console.log('\n๐ก Tip: Rate limit exceeded. Wait a moment and try again');
|
|
176
|
+
} else if (error.message.includes('ENOTFOUND') || error.message.includes('ECONNREFUSED')) {
|
|
177
|
+
console.log('\n๐ก Tip: Check your internet connection');
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
console.log('\n' + '='.repeat(80) + '\n');
|
|
181
|
+
process.exit(1);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
// Run test
|
|
186
|
+
testZaiAPI()
|
|
187
|
+
.then(() => process.exit(0))
|
|
188
|
+
.catch((error) => {
|
|
189
|
+
console.error('\nโ Unhandled error:', error);
|
|
190
|
+
process.exit(1);
|
|
191
|
+
});
|