@peakinfer/cli 1.0.133
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/.claude/settings.local.json +8 -0
- package/.env.example +6 -0
- package/.github/workflows/peakinfer.yml +64 -0
- package/CHANGELOG.md +31 -0
- package/LICENSE +190 -0
- package/README.md +335 -0
- package/data/inferencemax.json +274 -0
- package/dist/agent-analyzer.d.ts +45 -0
- package/dist/agent-analyzer.d.ts.map +1 -0
- package/dist/agent-analyzer.js +374 -0
- package/dist/agent-analyzer.js.map +1 -0
- package/dist/agent.d.ts +76 -0
- package/dist/agent.d.ts.map +1 -0
- package/dist/agent.js +965 -0
- package/dist/agent.js.map +1 -0
- package/dist/agents/correlation-analyzer.d.ts +34 -0
- package/dist/agents/correlation-analyzer.d.ts.map +1 -0
- package/dist/agents/correlation-analyzer.js +261 -0
- package/dist/agents/correlation-analyzer.js.map +1 -0
- package/dist/agents/index.d.ts +91 -0
- package/dist/agents/index.d.ts.map +1 -0
- package/dist/agents/index.js +111 -0
- package/dist/agents/index.js.map +1 -0
- package/dist/agents/runtime-analyzer.d.ts +38 -0
- package/dist/agents/runtime-analyzer.d.ts.map +1 -0
- package/dist/agents/runtime-analyzer.js +244 -0
- package/dist/agents/runtime-analyzer.js.map +1 -0
- package/dist/analysis-types.d.ts +500 -0
- package/dist/analysis-types.d.ts.map +1 -0
- package/dist/analysis-types.js +11 -0
- package/dist/analysis-types.js.map +1 -0
- package/dist/analytics.d.ts +25 -0
- package/dist/analytics.d.ts.map +1 -0
- package/dist/analytics.js +94 -0
- package/dist/analytics.js.map +1 -0
- package/dist/analyzer.d.ts +48 -0
- package/dist/analyzer.d.ts.map +1 -0
- package/dist/analyzer.js +547 -0
- package/dist/analyzer.js.map +1 -0
- package/dist/artifacts.d.ts +44 -0
- package/dist/artifacts.d.ts.map +1 -0
- package/dist/artifacts.js +165 -0
- package/dist/artifacts.js.map +1 -0
- package/dist/benchmarks/index.d.ts +88 -0
- package/dist/benchmarks/index.d.ts.map +1 -0
- package/dist/benchmarks/index.js +205 -0
- package/dist/benchmarks/index.js.map +1 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +427 -0
- package/dist/cli.js.map +1 -0
- package/dist/commands/ci.d.ts +19 -0
- package/dist/commands/ci.d.ts.map +1 -0
- package/dist/commands/ci.js +253 -0
- package/dist/commands/ci.js.map +1 -0
- package/dist/commands/config.d.ts +16 -0
- package/dist/commands/config.d.ts.map +1 -0
- package/dist/commands/config.js +249 -0
- package/dist/commands/config.js.map +1 -0
- package/dist/commands/demo.d.ts +15 -0
- package/dist/commands/demo.d.ts.map +1 -0
- package/dist/commands/demo.js +106 -0
- package/dist/commands/demo.js.map +1 -0
- package/dist/commands/export.d.ts +14 -0
- package/dist/commands/export.d.ts.map +1 -0
- package/dist/commands/export.js +209 -0
- package/dist/commands/export.js.map +1 -0
- package/dist/commands/history.d.ts +15 -0
- package/dist/commands/history.d.ts.map +1 -0
- package/dist/commands/history.js +389 -0
- package/dist/commands/history.js.map +1 -0
- package/dist/commands/template.d.ts +14 -0
- package/dist/commands/template.d.ts.map +1 -0
- package/dist/commands/template.js +341 -0
- package/dist/commands/template.js.map +1 -0
- package/dist/commands/validate-map.d.ts +12 -0
- package/dist/commands/validate-map.d.ts.map +1 -0
- package/dist/commands/validate-map.js +274 -0
- package/dist/commands/validate-map.js.map +1 -0
- package/dist/commands/whatif.d.ts +17 -0
- package/dist/commands/whatif.d.ts.map +1 -0
- package/dist/commands/whatif.js +206 -0
- package/dist/commands/whatif.js.map +1 -0
- package/dist/comparison.d.ts +38 -0
- package/dist/comparison.d.ts.map +1 -0
- package/dist/comparison.js +223 -0
- package/dist/comparison.js.map +1 -0
- package/dist/config.d.ts +42 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +158 -0
- package/dist/config.js.map +1 -0
- package/dist/connectors/helicone.d.ts +9 -0
- package/dist/connectors/helicone.d.ts.map +1 -0
- package/dist/connectors/helicone.js +106 -0
- package/dist/connectors/helicone.js.map +1 -0
- package/dist/connectors/index.d.ts +37 -0
- package/dist/connectors/index.d.ts.map +1 -0
- package/dist/connectors/index.js +65 -0
- package/dist/connectors/index.js.map +1 -0
- package/dist/connectors/langsmith.d.ts +9 -0
- package/dist/connectors/langsmith.d.ts.map +1 -0
- package/dist/connectors/langsmith.js +122 -0
- package/dist/connectors/langsmith.js.map +1 -0
- package/dist/connectors/types.d.ts +83 -0
- package/dist/connectors/types.d.ts.map +1 -0
- package/dist/connectors/types.js +98 -0
- package/dist/connectors/types.js.map +1 -0
- package/dist/cost-estimator.d.ts +46 -0
- package/dist/cost-estimator.d.ts.map +1 -0
- package/dist/cost-estimator.js +104 -0
- package/dist/cost-estimator.js.map +1 -0
- package/dist/costs.d.ts +57 -0
- package/dist/costs.d.ts.map +1 -0
- package/dist/costs.js +251 -0
- package/dist/costs.js.map +1 -0
- package/dist/counterfactuals.d.ts +29 -0
- package/dist/counterfactuals.d.ts.map +1 -0
- package/dist/counterfactuals.js +448 -0
- package/dist/counterfactuals.js.map +1 -0
- package/dist/enhancement-prompts.d.ts +41 -0
- package/dist/enhancement-prompts.d.ts.map +1 -0
- package/dist/enhancement-prompts.js +88 -0
- package/dist/enhancement-prompts.js.map +1 -0
- package/dist/envelopes.d.ts +20 -0
- package/dist/envelopes.d.ts.map +1 -0
- package/dist/envelopes.js +790 -0
- package/dist/envelopes.js.map +1 -0
- package/dist/format-normalizer.d.ts +71 -0
- package/dist/format-normalizer.d.ts.map +1 -0
- package/dist/format-normalizer.js +1331 -0
- package/dist/format-normalizer.js.map +1 -0
- package/dist/history.d.ts +79 -0
- package/dist/history.d.ts.map +1 -0
- package/dist/history.js +313 -0
- package/dist/history.js.map +1 -0
- package/dist/html.d.ts +11 -0
- package/dist/html.d.ts.map +1 -0
- package/dist/html.js +463 -0
- package/dist/html.js.map +1 -0
- package/dist/impact.d.ts +42 -0
- package/dist/impact.d.ts.map +1 -0
- package/dist/impact.js +443 -0
- package/dist/impact.js.map +1 -0
- package/dist/index.d.ts +26 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +34 -0
- package/dist/index.js.map +1 -0
- package/dist/insights.d.ts +5 -0
- package/dist/insights.d.ts.map +1 -0
- package/dist/insights.js +271 -0
- package/dist/insights.js.map +1 -0
- package/dist/joiner.d.ts +9 -0
- package/dist/joiner.d.ts.map +1 -0
- package/dist/joiner.js +247 -0
- package/dist/joiner.js.map +1 -0
- package/dist/orchestrator.d.ts +34 -0
- package/dist/orchestrator.d.ts.map +1 -0
- package/dist/orchestrator.js +827 -0
- package/dist/orchestrator.js.map +1 -0
- package/dist/pdf.d.ts +26 -0
- package/dist/pdf.d.ts.map +1 -0
- package/dist/pdf.js +84 -0
- package/dist/pdf.js.map +1 -0
- package/dist/prediction.d.ts +33 -0
- package/dist/prediction.d.ts.map +1 -0
- package/dist/prediction.js +316 -0
- package/dist/prediction.js.map +1 -0
- package/dist/prompts/loader.d.ts +38 -0
- package/dist/prompts/loader.d.ts.map +1 -0
- package/dist/prompts/loader.js +60 -0
- package/dist/prompts/loader.js.map +1 -0
- package/dist/renderer.d.ts +64 -0
- package/dist/renderer.d.ts.map +1 -0
- package/dist/renderer.js +923 -0
- package/dist/renderer.js.map +1 -0
- package/dist/runid.d.ts +57 -0
- package/dist/runid.d.ts.map +1 -0
- package/dist/runid.js +199 -0
- package/dist/runid.js.map +1 -0
- package/dist/runtime.d.ts +29 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/runtime.js +366 -0
- package/dist/runtime.js.map +1 -0
- package/dist/scanner.d.ts +11 -0
- package/dist/scanner.d.ts.map +1 -0
- package/dist/scanner.js +426 -0
- package/dist/scanner.js.map +1 -0
- package/dist/templates.d.ts +120 -0
- package/dist/templates.d.ts.map +1 -0
- package/dist/templates.js +429 -0
- package/dist/templates.js.map +1 -0
- package/dist/tools/index.d.ts +153 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +177 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/types.d.ts +3647 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +703 -0
- package/dist/types.js.map +1 -0
- package/dist/version.d.ts +7 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +23 -0
- package/dist/version.js.map +1 -0
- package/docs/demo-guide.md +423 -0
- package/docs/events-format.md +295 -0
- package/docs/inferencemap-spec.md +344 -0
- package/docs/migration-v2.md +293 -0
- package/fixtures/demo/precomputed.json +142 -0
- package/fixtures/demo-project/README.md +52 -0
- package/fixtures/demo-project/ai-service.ts +65 -0
- package/fixtures/demo-project/sample-events.jsonl +15 -0
- package/fixtures/demo-project/src/ai-service.ts +128 -0
- package/fixtures/demo-project/src/llm-client.ts +155 -0
- package/package.json +65 -0
- package/prompts/agent-analyzer.yaml +47 -0
- package/prompts/ci-gate.yaml +98 -0
- package/prompts/correlation-analyzer.yaml +178 -0
- package/prompts/format-normalizer.yaml +46 -0
- package/prompts/peak-performance.yaml +180 -0
- package/prompts/pr-comment.yaml +111 -0
- package/prompts/runtime-analyzer.yaml +189 -0
- package/prompts/unified-analyzer.yaml +241 -0
- package/schemas/inference-map.v0.1.json +215 -0
- package/scripts/benchmark.ts +394 -0
- package/scripts/demo-v1.5.sh +158 -0
- package/scripts/sync-from-site.sh +197 -0
- package/scripts/validate-sync.sh +178 -0
- package/src/agent-analyzer.ts +481 -0
- package/src/agent.ts +1232 -0
- package/src/agents/correlation-analyzer.ts +353 -0
- package/src/agents/index.ts +235 -0
- package/src/agents/runtime-analyzer.ts +343 -0
- package/src/analysis-types.ts +558 -0
- package/src/analytics.ts +100 -0
- package/src/analyzer.ts +692 -0
- package/src/artifacts.ts +218 -0
- package/src/benchmarks/index.ts +309 -0
- package/src/cli.ts +503 -0
- package/src/commands/ci.ts +336 -0
- package/src/commands/config.ts +288 -0
- package/src/commands/demo.ts +175 -0
- package/src/commands/export.ts +297 -0
- package/src/commands/history.ts +425 -0
- package/src/commands/template.ts +385 -0
- package/src/commands/validate-map.ts +324 -0
- package/src/commands/whatif.ts +272 -0
- package/src/comparison.ts +283 -0
- package/src/config.ts +188 -0
- package/src/connectors/helicone.ts +164 -0
- package/src/connectors/index.ts +93 -0
- package/src/connectors/langsmith.ts +179 -0
- package/src/connectors/types.ts +180 -0
- package/src/cost-estimator.ts +146 -0
- package/src/costs.ts +347 -0
- package/src/counterfactuals.ts +516 -0
- package/src/enhancement-prompts.ts +118 -0
- package/src/envelopes.ts +814 -0
- package/src/format-normalizer.ts +1486 -0
- package/src/history.ts +400 -0
- package/src/html.ts +512 -0
- package/src/impact.ts +522 -0
- package/src/index.ts +83 -0
- package/src/insights.ts +341 -0
- package/src/joiner.ts +289 -0
- package/src/orchestrator.ts +1015 -0
- package/src/pdf.ts +110 -0
- package/src/prediction.ts +392 -0
- package/src/prompts/loader.ts +88 -0
- package/src/renderer.ts +1045 -0
- package/src/runid.ts +261 -0
- package/src/runtime.ts +450 -0
- package/src/scanner.ts +508 -0
- package/src/templates.ts +561 -0
- package/src/tools/index.ts +214 -0
- package/src/types.ts +873 -0
- package/src/version.ts +24 -0
- package/templates/context-accumulation.yaml +23 -0
- package/templates/cost-concentration.yaml +20 -0
- package/templates/dead-code.yaml +20 -0
- package/templates/latency-explainer.yaml +23 -0
- package/templates/optimizations/ab-testing-framework.yaml +74 -0
- package/templates/optimizations/api-gateway-optimization.yaml +81 -0
- package/templates/optimizations/api-model-routing-strategy.yaml +126 -0
- package/templates/optimizations/auto-scaling-optimization.yaml +85 -0
- package/templates/optimizations/batch-utilization-diagnostic.yaml +142 -0
- package/templates/optimizations/comprehensive-apm.yaml +76 -0
- package/templates/optimizations/context-window-optimization.yaml +91 -0
- package/templates/optimizations/cost-sensitive-batch-processing.yaml +77 -0
- package/templates/optimizations/distributed-training-optimization.yaml +77 -0
- package/templates/optimizations/document-analysis-edge.yaml +77 -0
- package/templates/optimizations/document-pipeline-optimization.yaml +78 -0
- package/templates/optimizations/domain-specific-distillation.yaml +78 -0
- package/templates/optimizations/error-handling-optimization.yaml +76 -0
- package/templates/optimizations/gptq-4bit-quantization.yaml +96 -0
- package/templates/optimizations/long-context-memory-management.yaml +78 -0
- package/templates/optimizations/max-tokens-optimization.yaml +76 -0
- package/templates/optimizations/memory-bandwidth-optimization.yaml +73 -0
- package/templates/optimizations/multi-framework-resilience.yaml +75 -0
- package/templates/optimizations/multi-tenant-optimization.yaml +75 -0
- package/templates/optimizations/prompt-caching-optimization.yaml +143 -0
- package/templates/optimizations/pytorch-to-onnx-migration.yaml +109 -0
- package/templates/optimizations/quality-monitoring.yaml +74 -0
- package/templates/optimizations/realtime-budget-controls.yaml +74 -0
- package/templates/optimizations/realtime-latency-optimization.yaml +74 -0
- package/templates/optimizations/sglang-concurrency-optimization.yaml +78 -0
- package/templates/optimizations/smart-model-routing.yaml +96 -0
- package/templates/optimizations/streaming-batch-selection.yaml +167 -0
- package/templates/optimizations/system-prompt-optimization.yaml +75 -0
- package/templates/optimizations/tensorrt-llm-performance.yaml +77 -0
- package/templates/optimizations/vllm-high-throughput-optimization.yaml +93 -0
- package/templates/optimizations/vllm-migration-memory-bound.yaml +78 -0
- package/templates/overpowered-extraction.yaml +32 -0
- package/templates/overpowered-model.yaml +31 -0
- package/templates/prompt-bloat.yaml +24 -0
- package/templates/retry-explosion.yaml +28 -0
- package/templates/schema/insight.schema.json +113 -0
- package/templates/schema/optimization.schema.json +180 -0
- package/templates/streaming-drift.yaml +30 -0
- package/templates/throughput-gap.yaml +21 -0
- package/templates/token-underutilization.yaml +28 -0
- package/templates/untested-fallback.yaml +21 -0
- package/tests/accuracy/drift-detection.test.ts +184 -0
- package/tests/accuracy/false-positives.test.ts +166 -0
- package/tests/accuracy/templates.test.ts +205 -0
- package/tests/action/commands.test.ts +125 -0
- package/tests/action/comments.test.ts +347 -0
- package/tests/cli.test.ts +203 -0
- package/tests/comparison.test.ts +309 -0
- package/tests/correlation-analyzer.test.ts +534 -0
- package/tests/counterfactuals.test.ts +347 -0
- package/tests/fixtures/events/missing-id.jsonl +1 -0
- package/tests/fixtures/events/missing-input.jsonl +1 -0
- package/tests/fixtures/events/missing-latency.jsonl +1 -0
- package/tests/fixtures/events/missing-model.jsonl +1 -0
- package/tests/fixtures/events/missing-output.jsonl +1 -0
- package/tests/fixtures/events/missing-provider.jsonl +1 -0
- package/tests/fixtures/events/missing-ts.jsonl +1 -0
- package/tests/fixtures/events/valid.csv +3 -0
- package/tests/fixtures/events/valid.json +1 -0
- package/tests/fixtures/events/valid.jsonl +2 -0
- package/tests/fixtures/events/with-callsite.jsonl +1 -0
- package/tests/fixtures/events/with-intent.jsonl +1 -0
- package/tests/fixtures/events/wrong-type.jsonl +1 -0
- package/tests/fixtures/repos/empty/.gitkeep +0 -0
- package/tests/fixtures/repos/hybrid-router/router.py +35 -0
- package/tests/fixtures/repos/saas-anthropic/agent.ts +27 -0
- package/tests/fixtures/repos/saas-openai/assistant.js +33 -0
- package/tests/fixtures/repos/saas-openai/client.py +26 -0
- package/tests/fixtures/repos/self-hosted-vllm/inference.py +22 -0
- package/tests/github-action.test.ts +292 -0
- package/tests/insights.test.ts +878 -0
- package/tests/joiner.test.ts +168 -0
- package/tests/performance/action-latency.test.ts +132 -0
- package/tests/performance/benchmark.test.ts +189 -0
- package/tests/performance/cli-latency.test.ts +102 -0
- package/tests/pr-comment.test.ts +313 -0
- package/tests/prediction.test.ts +296 -0
- package/tests/runtime-analyzer.test.ts +375 -0
- package/tests/runtime.test.ts +205 -0
- package/tests/scanner.test.ts +122 -0
- package/tests/template-conformance.test.ts +526 -0
- package/tests/unit/cost-calculator.test.ts +303 -0
- package/tests/unit/credits.test.ts +180 -0
- package/tests/unit/inference-map.test.ts +276 -0
- package/tests/unit/schema.test.ts +300 -0
- package/tsconfig.json +20 -0
- package/vitest.config.ts +14 -0
|
@@ -0,0 +1,313 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PR Comment Tests
|
|
3
|
+
* Per Test Cases v1.9.3 - PR/CI Integration Tests
|
|
4
|
+
*/
|
|
5
|
+
import { describe, test, expect } from 'vitest';
|
|
6
|
+
|
|
7
|
+
// Types for PR comment generation
|
|
8
|
+
interface InferencePoint {
|
|
9
|
+
id: string;
|
|
10
|
+
file: string;
|
|
11
|
+
line: number;
|
|
12
|
+
provider: string;
|
|
13
|
+
model: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
interface Issue {
|
|
17
|
+
id: string;
|
|
18
|
+
severity: 'critical' | 'high' | 'medium' | 'low';
|
|
19
|
+
category: string;
|
|
20
|
+
title: string;
|
|
21
|
+
description: string;
|
|
22
|
+
file: string;
|
|
23
|
+
line: number;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
interface AnalysisResult {
|
|
27
|
+
inferencePoints: InferencePoint[];
|
|
28
|
+
issues: Issue[];
|
|
29
|
+
summary: {
|
|
30
|
+
totalInferencePoints: number;
|
|
31
|
+
criticalIssues: number;
|
|
32
|
+
highIssues: number;
|
|
33
|
+
mediumIssues: number;
|
|
34
|
+
lowIssues: number;
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// PR Comment generator (to be implemented in src/pr-comment.ts)
|
|
39
|
+
function generatePRComment(result: AnalysisResult): string {
|
|
40
|
+
const lines: string[] = [];
|
|
41
|
+
|
|
42
|
+
// Header
|
|
43
|
+
lines.push('## PeakInfer Analysis');
|
|
44
|
+
lines.push('');
|
|
45
|
+
|
|
46
|
+
// Summary
|
|
47
|
+
lines.push(`Found **${result.summary.totalInferencePoints}** inference points`);
|
|
48
|
+
lines.push('');
|
|
49
|
+
|
|
50
|
+
// Issues by severity
|
|
51
|
+
if (result.summary.criticalIssues > 0 || result.summary.highIssues > 0) {
|
|
52
|
+
lines.push('### Issues Found');
|
|
53
|
+
lines.push('');
|
|
54
|
+
|
|
55
|
+
const critical = result.issues.filter(i => i.severity === 'critical');
|
|
56
|
+
const high = result.issues.filter(i => i.severity === 'high');
|
|
57
|
+
|
|
58
|
+
for (const issue of [...critical, ...high].slice(0, 5)) {
|
|
59
|
+
const emoji = issue.severity === 'critical' ? ':red_circle:' : ':orange_circle:';
|
|
60
|
+
lines.push(`${emoji} **${issue.severity.toUpperCase()}**: ${issue.title}`);
|
|
61
|
+
lines.push(` - ${issue.file}:${issue.line}`);
|
|
62
|
+
lines.push(` - ${issue.description}`);
|
|
63
|
+
lines.push('');
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// No issues case
|
|
68
|
+
if (result.issues.length === 0) {
|
|
69
|
+
lines.push(':white_check_mark: No issues found');
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// Footer
|
|
73
|
+
lines.push('---');
|
|
74
|
+
lines.push('*Generated by [PeakInfer](https://peakinfer.dev)*');
|
|
75
|
+
|
|
76
|
+
return lines.join('\n');
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function generateCompactComment(result: AnalysisResult): string {
|
|
80
|
+
const criticalHigh = result.summary.criticalIssues + result.summary.highIssues;
|
|
81
|
+
|
|
82
|
+
if (criticalHigh === 0) {
|
|
83
|
+
return `:white_check_mark: PeakInfer: ${result.summary.totalInferencePoints} inference points, no critical issues`;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return `:warning: PeakInfer: ${result.summary.totalInferencePoints} inference points, ${criticalHigh} critical/high issues`;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function shouldBlockPR(result: AnalysisResult, threshold: 'critical' | 'high' | 'medium'): boolean {
|
|
90
|
+
if (threshold === 'critical') {
|
|
91
|
+
return result.summary.criticalIssues > 0;
|
|
92
|
+
}
|
|
93
|
+
if (threshold === 'high') {
|
|
94
|
+
return result.summary.criticalIssues > 0 || result.summary.highIssues > 0;
|
|
95
|
+
}
|
|
96
|
+
return result.summary.criticalIssues > 0 || result.summary.highIssues > 0 || result.summary.mediumIssues > 0;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
describe('PR Comment Generation', () => {
|
|
100
|
+
test('Generates markdown comment with issues', () => {
|
|
101
|
+
const result: AnalysisResult = {
|
|
102
|
+
inferencePoints: [
|
|
103
|
+
{ id: 'ip-1', file: 'src/chat.ts', line: 42, provider: 'anthropic', model: 'claude-sonnet-4-20250514' },
|
|
104
|
+
],
|
|
105
|
+
issues: [
|
|
106
|
+
{
|
|
107
|
+
id: 'issue-1',
|
|
108
|
+
severity: 'critical',
|
|
109
|
+
category: 'cost',
|
|
110
|
+
title: 'Expensive model for simple task',
|
|
111
|
+
description: 'Using claude-opus for chat completion',
|
|
112
|
+
file: 'src/chat.ts',
|
|
113
|
+
line: 42,
|
|
114
|
+
},
|
|
115
|
+
],
|
|
116
|
+
summary: {
|
|
117
|
+
totalInferencePoints: 1,
|
|
118
|
+
criticalIssues: 1,
|
|
119
|
+
highIssues: 0,
|
|
120
|
+
mediumIssues: 0,
|
|
121
|
+
lowIssues: 0,
|
|
122
|
+
},
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
const comment = generatePRComment(result);
|
|
126
|
+
|
|
127
|
+
expect(comment).toContain('## PeakInfer Analysis');
|
|
128
|
+
expect(comment).toContain('1 inference points');
|
|
129
|
+
expect(comment).toContain('CRITICAL');
|
|
130
|
+
expect(comment).toContain('Expensive model');
|
|
131
|
+
expect(comment).toContain('src/chat.ts:42');
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
test('Generates clean comment when no issues', () => {
|
|
135
|
+
const result: AnalysisResult = {
|
|
136
|
+
inferencePoints: [
|
|
137
|
+
{ id: 'ip-1', file: 'src/chat.ts', line: 42, provider: 'anthropic', model: 'claude-sonnet-4-20250514' },
|
|
138
|
+
],
|
|
139
|
+
issues: [],
|
|
140
|
+
summary: {
|
|
141
|
+
totalInferencePoints: 1,
|
|
142
|
+
criticalIssues: 0,
|
|
143
|
+
highIssues: 0,
|
|
144
|
+
mediumIssues: 0,
|
|
145
|
+
lowIssues: 0,
|
|
146
|
+
},
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
const comment = generatePRComment(result);
|
|
150
|
+
|
|
151
|
+
expect(comment).toContain('No issues found');
|
|
152
|
+
expect(comment).not.toContain('CRITICAL');
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
test('Limits issues to top 5', () => {
|
|
156
|
+
const issues: Issue[] = Array.from({ length: 10 }, (_, i) => ({
|
|
157
|
+
id: `issue-${i}`,
|
|
158
|
+
severity: 'high' as const,
|
|
159
|
+
category: 'cost',
|
|
160
|
+
title: `Issue ${i}`,
|
|
161
|
+
description: 'Test issue',
|
|
162
|
+
file: 'src/chat.ts',
|
|
163
|
+
line: i + 1,
|
|
164
|
+
}));
|
|
165
|
+
|
|
166
|
+
const result: AnalysisResult = {
|
|
167
|
+
inferencePoints: [],
|
|
168
|
+
issues,
|
|
169
|
+
summary: {
|
|
170
|
+
totalInferencePoints: 0,
|
|
171
|
+
criticalIssues: 0,
|
|
172
|
+
highIssues: 10,
|
|
173
|
+
mediumIssues: 0,
|
|
174
|
+
lowIssues: 0,
|
|
175
|
+
},
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
const comment = generatePRComment(result);
|
|
179
|
+
|
|
180
|
+
// Should only show 5 issues max
|
|
181
|
+
const highCount = (comment.match(/HIGH/g) || []).length;
|
|
182
|
+
expect(highCount).toBeLessThanOrEqual(5);
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
test('Includes PeakInfer branding', () => {
|
|
186
|
+
const result: AnalysisResult = {
|
|
187
|
+
inferencePoints: [],
|
|
188
|
+
issues: [],
|
|
189
|
+
summary: {
|
|
190
|
+
totalInferencePoints: 0,
|
|
191
|
+
criticalIssues: 0,
|
|
192
|
+
highIssues: 0,
|
|
193
|
+
mediumIssues: 0,
|
|
194
|
+
lowIssues: 0,
|
|
195
|
+
},
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
const comment = generatePRComment(result);
|
|
199
|
+
|
|
200
|
+
expect(comment).toContain('PeakInfer');
|
|
201
|
+
expect(comment).toContain('peakinfer.dev');
|
|
202
|
+
});
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
describe('Compact Comment', () => {
|
|
206
|
+
test('Shows success for no critical issues', () => {
|
|
207
|
+
const result: AnalysisResult = {
|
|
208
|
+
inferencePoints: [{ id: 'ip-1', file: 'test.ts', line: 1, provider: 'openai', model: 'gpt-4' }],
|
|
209
|
+
issues: [],
|
|
210
|
+
summary: {
|
|
211
|
+
totalInferencePoints: 1,
|
|
212
|
+
criticalIssues: 0,
|
|
213
|
+
highIssues: 0,
|
|
214
|
+
mediumIssues: 0,
|
|
215
|
+
lowIssues: 0,
|
|
216
|
+
},
|
|
217
|
+
};
|
|
218
|
+
|
|
219
|
+
const comment = generateCompactComment(result);
|
|
220
|
+
|
|
221
|
+
expect(comment).toContain(':white_check_mark:');
|
|
222
|
+
expect(comment).toContain('no critical issues');
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
test('Shows warning for critical/high issues', () => {
|
|
226
|
+
const result: AnalysisResult = {
|
|
227
|
+
inferencePoints: [],
|
|
228
|
+
issues: [
|
|
229
|
+
{ id: 'i-1', severity: 'critical', category: 'cost', title: 'Test', description: 'Test', file: 'test.ts', line: 1 },
|
|
230
|
+
],
|
|
231
|
+
summary: {
|
|
232
|
+
totalInferencePoints: 1,
|
|
233
|
+
criticalIssues: 1,
|
|
234
|
+
highIssues: 0,
|
|
235
|
+
mediumIssues: 0,
|
|
236
|
+
lowIssues: 0,
|
|
237
|
+
},
|
|
238
|
+
};
|
|
239
|
+
|
|
240
|
+
const comment = generateCompactComment(result);
|
|
241
|
+
|
|
242
|
+
expect(comment).toContain(':warning:');
|
|
243
|
+
expect(comment).toContain('1 critical/high issues');
|
|
244
|
+
});
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
describe('PR Blocking Logic', () => {
|
|
248
|
+
test('Blocks on critical when threshold is critical', () => {
|
|
249
|
+
const result: AnalysisResult = {
|
|
250
|
+
inferencePoints: [],
|
|
251
|
+
issues: [],
|
|
252
|
+
summary: {
|
|
253
|
+
totalInferencePoints: 0,
|
|
254
|
+
criticalIssues: 1,
|
|
255
|
+
highIssues: 0,
|
|
256
|
+
mediumIssues: 0,
|
|
257
|
+
lowIssues: 0,
|
|
258
|
+
},
|
|
259
|
+
};
|
|
260
|
+
|
|
261
|
+
expect(shouldBlockPR(result, 'critical')).toBe(true);
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
test('Does not block on high when threshold is critical', () => {
|
|
265
|
+
const result: AnalysisResult = {
|
|
266
|
+
inferencePoints: [],
|
|
267
|
+
issues: [],
|
|
268
|
+
summary: {
|
|
269
|
+
totalInferencePoints: 0,
|
|
270
|
+
criticalIssues: 0,
|
|
271
|
+
highIssues: 5,
|
|
272
|
+
mediumIssues: 0,
|
|
273
|
+
lowIssues: 0,
|
|
274
|
+
},
|
|
275
|
+
};
|
|
276
|
+
|
|
277
|
+
expect(shouldBlockPR(result, 'critical')).toBe(false);
|
|
278
|
+
});
|
|
279
|
+
|
|
280
|
+
test('Blocks on high when threshold is high', () => {
|
|
281
|
+
const result: AnalysisResult = {
|
|
282
|
+
inferencePoints: [],
|
|
283
|
+
issues: [],
|
|
284
|
+
summary: {
|
|
285
|
+
totalInferencePoints: 0,
|
|
286
|
+
criticalIssues: 0,
|
|
287
|
+
highIssues: 1,
|
|
288
|
+
mediumIssues: 0,
|
|
289
|
+
lowIssues: 0,
|
|
290
|
+
},
|
|
291
|
+
};
|
|
292
|
+
|
|
293
|
+
expect(shouldBlockPR(result, 'high')).toBe(true);
|
|
294
|
+
});
|
|
295
|
+
|
|
296
|
+
test('Does not block when no issues', () => {
|
|
297
|
+
const result: AnalysisResult = {
|
|
298
|
+
inferencePoints: [],
|
|
299
|
+
issues: [],
|
|
300
|
+
summary: {
|
|
301
|
+
totalInferencePoints: 5,
|
|
302
|
+
criticalIssues: 0,
|
|
303
|
+
highIssues: 0,
|
|
304
|
+
mediumIssues: 0,
|
|
305
|
+
lowIssues: 0,
|
|
306
|
+
},
|
|
307
|
+
};
|
|
308
|
+
|
|
309
|
+
expect(shouldBlockPR(result, 'critical')).toBe(false);
|
|
310
|
+
expect(shouldBlockPR(result, 'high')).toBe(false);
|
|
311
|
+
expect(shouldBlockPR(result, 'medium')).toBe(false);
|
|
312
|
+
});
|
|
313
|
+
});
|
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
import {
|
|
3
|
+
generatePredictions,
|
|
4
|
+
formatPredictionSummary,
|
|
5
|
+
hasHighRiskPredictions,
|
|
6
|
+
} from '../src/prediction.js';
|
|
7
|
+
import type { Callsite, InferenceMap } from '../src/types.js';
|
|
8
|
+
|
|
9
|
+
// =============================================================================
|
|
10
|
+
// TEST FIXTURES
|
|
11
|
+
// =============================================================================
|
|
12
|
+
|
|
13
|
+
function createCallsite(overrides: Partial<Callsite> = {}): Callsite {
|
|
14
|
+
return {
|
|
15
|
+
id: `cs_${Date.now()}_${Math.random().toString(36).slice(2, 6)}`,
|
|
16
|
+
file: 'src/agent.ts',
|
|
17
|
+
line: 42,
|
|
18
|
+
col: 10,
|
|
19
|
+
provider: 'openai',
|
|
20
|
+
model: 'gpt-4o',
|
|
21
|
+
framework: null,
|
|
22
|
+
runtime: null,
|
|
23
|
+
patterns: {},
|
|
24
|
+
confidence: 0.9,
|
|
25
|
+
...overrides,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function createInferenceMap(callsites: Callsite[]): InferenceMap {
|
|
30
|
+
return {
|
|
31
|
+
version: '0.1',
|
|
32
|
+
callsites,
|
|
33
|
+
frameworks: {},
|
|
34
|
+
scanResult: {
|
|
35
|
+
root: '/test',
|
|
36
|
+
files: [],
|
|
37
|
+
summary: { totalFiles: 0, totalLoc: 0, languages: [], totalCandidates: 0 },
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// =============================================================================
|
|
43
|
+
// TESTS
|
|
44
|
+
// =============================================================================
|
|
45
|
+
|
|
46
|
+
describe('prediction', () => {
|
|
47
|
+
describe('generatePredictions', () => {
|
|
48
|
+
it('should generate predictions for callsites', () => {
|
|
49
|
+
const inferenceMap = createInferenceMap([
|
|
50
|
+
createCallsite({ file: 'src/a.ts', line: 10, model: 'gpt-4o' }),
|
|
51
|
+
createCallsite({ file: 'src/b.ts', line: 20, model: 'gpt-4o-mini' }),
|
|
52
|
+
]);
|
|
53
|
+
|
|
54
|
+
const result = generatePredictions(inferenceMap);
|
|
55
|
+
|
|
56
|
+
expect(result.predictions.length).toBe(2);
|
|
57
|
+
expect(result.summary.totalPoints).toBe(2);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it('should assign risk levels based on latency', () => {
|
|
61
|
+
const inferenceMap = createInferenceMap([
|
|
62
|
+
createCallsite({ file: 'src/a.ts', line: 10, model: 'claude-3-opus' }), // high latency
|
|
63
|
+
createCallsite({ file: 'src/b.ts', line: 20, model: 'gemini-1.5-flash' }), // low latency
|
|
64
|
+
]);
|
|
65
|
+
|
|
66
|
+
const result = generatePredictions(inferenceMap);
|
|
67
|
+
|
|
68
|
+
const opusPrediction = result.predictions.find(p => p.model?.includes('opus'));
|
|
69
|
+
const flashPrediction = result.predictions.find(p => p.model?.includes('flash'));
|
|
70
|
+
|
|
71
|
+
expect(opusPrediction?.risk).toBe('high');
|
|
72
|
+
expect(flashPrediction?.risk).toBe('low');
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it('should include prediction factors', () => {
|
|
76
|
+
const inferenceMap = createInferenceMap([
|
|
77
|
+
createCallsite({
|
|
78
|
+
file: 'src/a.ts',
|
|
79
|
+
line: 10,
|
|
80
|
+
model: 'gpt-4o',
|
|
81
|
+
patterns: { streaming: true },
|
|
82
|
+
}),
|
|
83
|
+
]);
|
|
84
|
+
|
|
85
|
+
const result = generatePredictions(inferenceMap);
|
|
86
|
+
|
|
87
|
+
expect(result.predictions[0].factors.length).toBeGreaterThan(0);
|
|
88
|
+
const streamingFactor = result.predictions[0].factors.find(f =>
|
|
89
|
+
f.name.toLowerCase().includes('streaming')
|
|
90
|
+
);
|
|
91
|
+
expect(streamingFactor).toBeDefined();
|
|
92
|
+
expect(streamingFactor?.impact).toBe('positive');
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it('should reduce latency for patterns like batching and caching', () => {
|
|
96
|
+
const baseInferenceMap = createInferenceMap([
|
|
97
|
+
createCallsite({
|
|
98
|
+
file: 'src/a.ts',
|
|
99
|
+
line: 10,
|
|
100
|
+
model: 'gpt-4o',
|
|
101
|
+
patterns: {},
|
|
102
|
+
}),
|
|
103
|
+
]);
|
|
104
|
+
|
|
105
|
+
const optimizedInferenceMap = createInferenceMap([
|
|
106
|
+
createCallsite({
|
|
107
|
+
file: 'src/a.ts',
|
|
108
|
+
line: 10,
|
|
109
|
+
model: 'gpt-4o',
|
|
110
|
+
patterns: { batching: true, caching: true },
|
|
111
|
+
}),
|
|
112
|
+
]);
|
|
113
|
+
|
|
114
|
+
const baseResult = generatePredictions(baseInferenceMap);
|
|
115
|
+
const optimizedResult = generatePredictions(optimizedInferenceMap);
|
|
116
|
+
|
|
117
|
+
expect(optimizedResult.predictions[0].predictedLatency.p95)
|
|
118
|
+
.toBeLessThan(baseResult.predictions[0].predictedLatency.p95);
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
it('should calculate correct summary statistics', () => {
|
|
122
|
+
const inferenceMap = createInferenceMap([
|
|
123
|
+
createCallsite({ file: 'src/a.ts', line: 10, model: 'gpt-4' }), // high
|
|
124
|
+
createCallsite({ file: 'src/b.ts', line: 20, model: 'gpt-4o' }), // medium
|
|
125
|
+
createCallsite({ file: 'src/c.ts', line: 30, model: 'gpt-4o-mini' }), // low
|
|
126
|
+
]);
|
|
127
|
+
|
|
128
|
+
const result = generatePredictions(inferenceMap);
|
|
129
|
+
|
|
130
|
+
expect(result.summary.totalPoints).toBe(3);
|
|
131
|
+
expect(result.summary.highRiskCount).toBeGreaterThanOrEqual(0);
|
|
132
|
+
expect(result.summary.averageP95).toBeGreaterThan(0);
|
|
133
|
+
expect(result.summary.worstP95).toBeGreaterThanOrEqual(result.summary.averageP95);
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
it('should check budget when targetP95 is specified', () => {
|
|
137
|
+
const inferenceMap = createInferenceMap([
|
|
138
|
+
createCallsite({ file: 'src/a.ts', line: 10, model: 'gpt-4' }), // p95 ~5000ms
|
|
139
|
+
]);
|
|
140
|
+
|
|
141
|
+
const withinBudget = generatePredictions(inferenceMap, 0, { targetP95: 10000 });
|
|
142
|
+
const overBudget = generatePredictions(inferenceMap, 0, { targetP95: 1000 });
|
|
143
|
+
|
|
144
|
+
expect(withinBudget.summary.budgetExceeded).toBe(false);
|
|
145
|
+
expect(overBudget.summary.budgetExceeded).toBe(true);
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
it('should handle empty inference map', () => {
|
|
149
|
+
const inferenceMap = createInferenceMap([]);
|
|
150
|
+
|
|
151
|
+
const result = generatePredictions(inferenceMap);
|
|
152
|
+
|
|
153
|
+
expect(result.predictions.length).toBe(0);
|
|
154
|
+
expect(result.summary.totalPoints).toBe(0);
|
|
155
|
+
expect(result.summary.averageP95).toBe(0);
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
it('should handle unknown models with medium confidence when model is set', () => {
|
|
159
|
+
const inferenceMap = createInferenceMap([
|
|
160
|
+
createCallsite({
|
|
161
|
+
file: 'src/a.ts',
|
|
162
|
+
line: 10,
|
|
163
|
+
model: 'custom-fine-tuned-model',
|
|
164
|
+
}),
|
|
165
|
+
]);
|
|
166
|
+
|
|
167
|
+
const result = generatePredictions(inferenceMap);
|
|
168
|
+
|
|
169
|
+
expect(result.predictions.length).toBe(1);
|
|
170
|
+
// When model is set (even unknown), confidence is medium; low only when no model
|
|
171
|
+
expect(result.predictions[0].confidence).toBe('medium');
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
it('should include location in predictions', () => {
|
|
175
|
+
const inferenceMap = createInferenceMap([
|
|
176
|
+
createCallsite({ file: 'src/agent.ts', line: 42 }),
|
|
177
|
+
]);
|
|
178
|
+
|
|
179
|
+
const result = generatePredictions(inferenceMap);
|
|
180
|
+
|
|
181
|
+
expect(result.predictions[0].location).toBe('src/agent.ts:42');
|
|
182
|
+
});
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
describe('formatPredictionSummary', () => {
|
|
186
|
+
it('should format summary with risk counts', () => {
|
|
187
|
+
const inferenceMap = createInferenceMap([
|
|
188
|
+
createCallsite({ file: 'src/a.ts', line: 10, model: 'gpt-4' }),
|
|
189
|
+
createCallsite({ file: 'src/b.ts', line: 20, model: 'gpt-4o-mini' }),
|
|
190
|
+
]);
|
|
191
|
+
|
|
192
|
+
const result = generatePredictions(inferenceMap);
|
|
193
|
+
const summary = formatPredictionSummary(result);
|
|
194
|
+
|
|
195
|
+
expect(summary).toContain('inference points');
|
|
196
|
+
expect(summary).toContain('p95');
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
it('should show budget status when target specified', () => {
|
|
200
|
+
const inferenceMap = createInferenceMap([
|
|
201
|
+
createCallsite({ file: 'src/a.ts', line: 10, model: 'gpt-4' }),
|
|
202
|
+
]);
|
|
203
|
+
|
|
204
|
+
const result = generatePredictions(inferenceMap, 0, { targetP95: 1000 });
|
|
205
|
+
const summary = formatPredictionSummary(result);
|
|
206
|
+
|
|
207
|
+
expect(summary).toContain('Budget exceeded');
|
|
208
|
+
});
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
describe('hasHighRiskPredictions', () => {
|
|
212
|
+
it('should return true when high-risk predictions exist', () => {
|
|
213
|
+
const inferenceMap = createInferenceMap([
|
|
214
|
+
createCallsite({ file: 'src/a.ts', line: 10, model: 'claude-3-opus' }),
|
|
215
|
+
]);
|
|
216
|
+
|
|
217
|
+
const result = generatePredictions(inferenceMap);
|
|
218
|
+
|
|
219
|
+
expect(hasHighRiskPredictions(result)).toBe(true);
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
it('should return false when no high-risk predictions', () => {
|
|
223
|
+
const inferenceMap = createInferenceMap([
|
|
224
|
+
createCallsite({ file: 'src/a.ts', line: 10, model: 'gemini-1.5-flash' }),
|
|
225
|
+
]);
|
|
226
|
+
|
|
227
|
+
const result = generatePredictions(inferenceMap);
|
|
228
|
+
|
|
229
|
+
expect(hasHighRiskPredictions(result)).toBe(false);
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
it('should return false for empty predictions', () => {
|
|
233
|
+
const inferenceMap = createInferenceMap([]);
|
|
234
|
+
|
|
235
|
+
const result = generatePredictions(inferenceMap);
|
|
236
|
+
|
|
237
|
+
expect(hasHighRiskPredictions(result)).toBe(false);
|
|
238
|
+
});
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
describe('model latency estimates', () => {
|
|
242
|
+
it('should estimate higher latency for Claude Opus vs Haiku', () => {
|
|
243
|
+
const opus = createInferenceMap([
|
|
244
|
+
createCallsite({ file: 'src/a.ts', line: 10, model: 'claude-3-opus' }),
|
|
245
|
+
]);
|
|
246
|
+
|
|
247
|
+
const haiku = createInferenceMap([
|
|
248
|
+
createCallsite({ file: 'src/a.ts', line: 10, model: 'claude-3-haiku' }),
|
|
249
|
+
]);
|
|
250
|
+
|
|
251
|
+
const opusResult = generatePredictions(opus);
|
|
252
|
+
const haikuResult = generatePredictions(haiku);
|
|
253
|
+
|
|
254
|
+
// Opus should have higher latency than Haiku
|
|
255
|
+
expect(opusResult.predictions[0].predictedLatency.p95)
|
|
256
|
+
.toBeGreaterThan(haikuResult.predictions[0].predictedLatency.p95);
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
it('should estimate higher latency for o1 models', () => {
|
|
260
|
+
const o1 = createInferenceMap([
|
|
261
|
+
createCallsite({ file: 'src/a.ts', line: 10, model: 'o1-preview' }),
|
|
262
|
+
]);
|
|
263
|
+
|
|
264
|
+
const gpt4 = createInferenceMap([
|
|
265
|
+
createCallsite({ file: 'src/a.ts', line: 10, model: 'gpt-4' }),
|
|
266
|
+
]);
|
|
267
|
+
|
|
268
|
+
const o1Result = generatePredictions(o1);
|
|
269
|
+
const gpt4Result = generatePredictions(gpt4);
|
|
270
|
+
|
|
271
|
+
expect(o1Result.predictions[0].predictedLatency.p95)
|
|
272
|
+
.toBeGreaterThan(gpt4Result.predictions[0].predictedLatency.p95);
|
|
273
|
+
});
|
|
274
|
+
});
|
|
275
|
+
|
|
276
|
+
describe('self-hosted providers', () => {
|
|
277
|
+
it('should identify self-hosted providers as positive factor', () => {
|
|
278
|
+
const inferenceMap = createInferenceMap([
|
|
279
|
+
createCallsite({
|
|
280
|
+
file: 'src/a.ts',
|
|
281
|
+
line: 10,
|
|
282
|
+
provider: 'vllm',
|
|
283
|
+
model: 'llama-3.1-70b',
|
|
284
|
+
}),
|
|
285
|
+
]);
|
|
286
|
+
|
|
287
|
+
const result = generatePredictions(inferenceMap);
|
|
288
|
+
|
|
289
|
+
const selfHostedFactor = result.predictions[0].factors.find(f =>
|
|
290
|
+
f.name.toLowerCase().includes('self-hosted')
|
|
291
|
+
);
|
|
292
|
+
expect(selfHostedFactor).toBeDefined();
|
|
293
|
+
expect(selfHostedFactor?.impact).toBe('positive');
|
|
294
|
+
});
|
|
295
|
+
});
|
|
296
|
+
});
|