@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.
Files changed (367) hide show
  1. package/.claude/settings.local.json +8 -0
  2. package/.env.example +6 -0
  3. package/.github/workflows/peakinfer.yml +64 -0
  4. package/CHANGELOG.md +31 -0
  5. package/LICENSE +190 -0
  6. package/README.md +335 -0
  7. package/data/inferencemax.json +274 -0
  8. package/dist/agent-analyzer.d.ts +45 -0
  9. package/dist/agent-analyzer.d.ts.map +1 -0
  10. package/dist/agent-analyzer.js +374 -0
  11. package/dist/agent-analyzer.js.map +1 -0
  12. package/dist/agent.d.ts +76 -0
  13. package/dist/agent.d.ts.map +1 -0
  14. package/dist/agent.js +965 -0
  15. package/dist/agent.js.map +1 -0
  16. package/dist/agents/correlation-analyzer.d.ts +34 -0
  17. package/dist/agents/correlation-analyzer.d.ts.map +1 -0
  18. package/dist/agents/correlation-analyzer.js +261 -0
  19. package/dist/agents/correlation-analyzer.js.map +1 -0
  20. package/dist/agents/index.d.ts +91 -0
  21. package/dist/agents/index.d.ts.map +1 -0
  22. package/dist/agents/index.js +111 -0
  23. package/dist/agents/index.js.map +1 -0
  24. package/dist/agents/runtime-analyzer.d.ts +38 -0
  25. package/dist/agents/runtime-analyzer.d.ts.map +1 -0
  26. package/dist/agents/runtime-analyzer.js +244 -0
  27. package/dist/agents/runtime-analyzer.js.map +1 -0
  28. package/dist/analysis-types.d.ts +500 -0
  29. package/dist/analysis-types.d.ts.map +1 -0
  30. package/dist/analysis-types.js +11 -0
  31. package/dist/analysis-types.js.map +1 -0
  32. package/dist/analytics.d.ts +25 -0
  33. package/dist/analytics.d.ts.map +1 -0
  34. package/dist/analytics.js +94 -0
  35. package/dist/analytics.js.map +1 -0
  36. package/dist/analyzer.d.ts +48 -0
  37. package/dist/analyzer.d.ts.map +1 -0
  38. package/dist/analyzer.js +547 -0
  39. package/dist/analyzer.js.map +1 -0
  40. package/dist/artifacts.d.ts +44 -0
  41. package/dist/artifacts.d.ts.map +1 -0
  42. package/dist/artifacts.js +165 -0
  43. package/dist/artifacts.js.map +1 -0
  44. package/dist/benchmarks/index.d.ts +88 -0
  45. package/dist/benchmarks/index.d.ts.map +1 -0
  46. package/dist/benchmarks/index.js +205 -0
  47. package/dist/benchmarks/index.js.map +1 -0
  48. package/dist/cli.d.ts +3 -0
  49. package/dist/cli.d.ts.map +1 -0
  50. package/dist/cli.js +427 -0
  51. package/dist/cli.js.map +1 -0
  52. package/dist/commands/ci.d.ts +19 -0
  53. package/dist/commands/ci.d.ts.map +1 -0
  54. package/dist/commands/ci.js +253 -0
  55. package/dist/commands/ci.js.map +1 -0
  56. package/dist/commands/config.d.ts +16 -0
  57. package/dist/commands/config.d.ts.map +1 -0
  58. package/dist/commands/config.js +249 -0
  59. package/dist/commands/config.js.map +1 -0
  60. package/dist/commands/demo.d.ts +15 -0
  61. package/dist/commands/demo.d.ts.map +1 -0
  62. package/dist/commands/demo.js +106 -0
  63. package/dist/commands/demo.js.map +1 -0
  64. package/dist/commands/export.d.ts +14 -0
  65. package/dist/commands/export.d.ts.map +1 -0
  66. package/dist/commands/export.js +209 -0
  67. package/dist/commands/export.js.map +1 -0
  68. package/dist/commands/history.d.ts +15 -0
  69. package/dist/commands/history.d.ts.map +1 -0
  70. package/dist/commands/history.js +389 -0
  71. package/dist/commands/history.js.map +1 -0
  72. package/dist/commands/template.d.ts +14 -0
  73. package/dist/commands/template.d.ts.map +1 -0
  74. package/dist/commands/template.js +341 -0
  75. package/dist/commands/template.js.map +1 -0
  76. package/dist/commands/validate-map.d.ts +12 -0
  77. package/dist/commands/validate-map.d.ts.map +1 -0
  78. package/dist/commands/validate-map.js +274 -0
  79. package/dist/commands/validate-map.js.map +1 -0
  80. package/dist/commands/whatif.d.ts +17 -0
  81. package/dist/commands/whatif.d.ts.map +1 -0
  82. package/dist/commands/whatif.js +206 -0
  83. package/dist/commands/whatif.js.map +1 -0
  84. package/dist/comparison.d.ts +38 -0
  85. package/dist/comparison.d.ts.map +1 -0
  86. package/dist/comparison.js +223 -0
  87. package/dist/comparison.js.map +1 -0
  88. package/dist/config.d.ts +42 -0
  89. package/dist/config.d.ts.map +1 -0
  90. package/dist/config.js +158 -0
  91. package/dist/config.js.map +1 -0
  92. package/dist/connectors/helicone.d.ts +9 -0
  93. package/dist/connectors/helicone.d.ts.map +1 -0
  94. package/dist/connectors/helicone.js +106 -0
  95. package/dist/connectors/helicone.js.map +1 -0
  96. package/dist/connectors/index.d.ts +37 -0
  97. package/dist/connectors/index.d.ts.map +1 -0
  98. package/dist/connectors/index.js +65 -0
  99. package/dist/connectors/index.js.map +1 -0
  100. package/dist/connectors/langsmith.d.ts +9 -0
  101. package/dist/connectors/langsmith.d.ts.map +1 -0
  102. package/dist/connectors/langsmith.js +122 -0
  103. package/dist/connectors/langsmith.js.map +1 -0
  104. package/dist/connectors/types.d.ts +83 -0
  105. package/dist/connectors/types.d.ts.map +1 -0
  106. package/dist/connectors/types.js +98 -0
  107. package/dist/connectors/types.js.map +1 -0
  108. package/dist/cost-estimator.d.ts +46 -0
  109. package/dist/cost-estimator.d.ts.map +1 -0
  110. package/dist/cost-estimator.js +104 -0
  111. package/dist/cost-estimator.js.map +1 -0
  112. package/dist/costs.d.ts +57 -0
  113. package/dist/costs.d.ts.map +1 -0
  114. package/dist/costs.js +251 -0
  115. package/dist/costs.js.map +1 -0
  116. package/dist/counterfactuals.d.ts +29 -0
  117. package/dist/counterfactuals.d.ts.map +1 -0
  118. package/dist/counterfactuals.js +448 -0
  119. package/dist/counterfactuals.js.map +1 -0
  120. package/dist/enhancement-prompts.d.ts +41 -0
  121. package/dist/enhancement-prompts.d.ts.map +1 -0
  122. package/dist/enhancement-prompts.js +88 -0
  123. package/dist/enhancement-prompts.js.map +1 -0
  124. package/dist/envelopes.d.ts +20 -0
  125. package/dist/envelopes.d.ts.map +1 -0
  126. package/dist/envelopes.js +790 -0
  127. package/dist/envelopes.js.map +1 -0
  128. package/dist/format-normalizer.d.ts +71 -0
  129. package/dist/format-normalizer.d.ts.map +1 -0
  130. package/dist/format-normalizer.js +1331 -0
  131. package/dist/format-normalizer.js.map +1 -0
  132. package/dist/history.d.ts +79 -0
  133. package/dist/history.d.ts.map +1 -0
  134. package/dist/history.js +313 -0
  135. package/dist/history.js.map +1 -0
  136. package/dist/html.d.ts +11 -0
  137. package/dist/html.d.ts.map +1 -0
  138. package/dist/html.js +463 -0
  139. package/dist/html.js.map +1 -0
  140. package/dist/impact.d.ts +42 -0
  141. package/dist/impact.d.ts.map +1 -0
  142. package/dist/impact.js +443 -0
  143. package/dist/impact.js.map +1 -0
  144. package/dist/index.d.ts +26 -0
  145. package/dist/index.d.ts.map +1 -0
  146. package/dist/index.js +34 -0
  147. package/dist/index.js.map +1 -0
  148. package/dist/insights.d.ts +5 -0
  149. package/dist/insights.d.ts.map +1 -0
  150. package/dist/insights.js +271 -0
  151. package/dist/insights.js.map +1 -0
  152. package/dist/joiner.d.ts +9 -0
  153. package/dist/joiner.d.ts.map +1 -0
  154. package/dist/joiner.js +247 -0
  155. package/dist/joiner.js.map +1 -0
  156. package/dist/orchestrator.d.ts +34 -0
  157. package/dist/orchestrator.d.ts.map +1 -0
  158. package/dist/orchestrator.js +827 -0
  159. package/dist/orchestrator.js.map +1 -0
  160. package/dist/pdf.d.ts +26 -0
  161. package/dist/pdf.d.ts.map +1 -0
  162. package/dist/pdf.js +84 -0
  163. package/dist/pdf.js.map +1 -0
  164. package/dist/prediction.d.ts +33 -0
  165. package/dist/prediction.d.ts.map +1 -0
  166. package/dist/prediction.js +316 -0
  167. package/dist/prediction.js.map +1 -0
  168. package/dist/prompts/loader.d.ts +38 -0
  169. package/dist/prompts/loader.d.ts.map +1 -0
  170. package/dist/prompts/loader.js +60 -0
  171. package/dist/prompts/loader.js.map +1 -0
  172. package/dist/renderer.d.ts +64 -0
  173. package/dist/renderer.d.ts.map +1 -0
  174. package/dist/renderer.js +923 -0
  175. package/dist/renderer.js.map +1 -0
  176. package/dist/runid.d.ts +57 -0
  177. package/dist/runid.d.ts.map +1 -0
  178. package/dist/runid.js +199 -0
  179. package/dist/runid.js.map +1 -0
  180. package/dist/runtime.d.ts +29 -0
  181. package/dist/runtime.d.ts.map +1 -0
  182. package/dist/runtime.js +366 -0
  183. package/dist/runtime.js.map +1 -0
  184. package/dist/scanner.d.ts +11 -0
  185. package/dist/scanner.d.ts.map +1 -0
  186. package/dist/scanner.js +426 -0
  187. package/dist/scanner.js.map +1 -0
  188. package/dist/templates.d.ts +120 -0
  189. package/dist/templates.d.ts.map +1 -0
  190. package/dist/templates.js +429 -0
  191. package/dist/templates.js.map +1 -0
  192. package/dist/tools/index.d.ts +153 -0
  193. package/dist/tools/index.d.ts.map +1 -0
  194. package/dist/tools/index.js +177 -0
  195. package/dist/tools/index.js.map +1 -0
  196. package/dist/types.d.ts +3647 -0
  197. package/dist/types.d.ts.map +1 -0
  198. package/dist/types.js +703 -0
  199. package/dist/types.js.map +1 -0
  200. package/dist/version.d.ts +7 -0
  201. package/dist/version.d.ts.map +1 -0
  202. package/dist/version.js +23 -0
  203. package/dist/version.js.map +1 -0
  204. package/docs/demo-guide.md +423 -0
  205. package/docs/events-format.md +295 -0
  206. package/docs/inferencemap-spec.md +344 -0
  207. package/docs/migration-v2.md +293 -0
  208. package/fixtures/demo/precomputed.json +142 -0
  209. package/fixtures/demo-project/README.md +52 -0
  210. package/fixtures/demo-project/ai-service.ts +65 -0
  211. package/fixtures/demo-project/sample-events.jsonl +15 -0
  212. package/fixtures/demo-project/src/ai-service.ts +128 -0
  213. package/fixtures/demo-project/src/llm-client.ts +155 -0
  214. package/package.json +65 -0
  215. package/prompts/agent-analyzer.yaml +47 -0
  216. package/prompts/ci-gate.yaml +98 -0
  217. package/prompts/correlation-analyzer.yaml +178 -0
  218. package/prompts/format-normalizer.yaml +46 -0
  219. package/prompts/peak-performance.yaml +180 -0
  220. package/prompts/pr-comment.yaml +111 -0
  221. package/prompts/runtime-analyzer.yaml +189 -0
  222. package/prompts/unified-analyzer.yaml +241 -0
  223. package/schemas/inference-map.v0.1.json +215 -0
  224. package/scripts/benchmark.ts +394 -0
  225. package/scripts/demo-v1.5.sh +158 -0
  226. package/scripts/sync-from-site.sh +197 -0
  227. package/scripts/validate-sync.sh +178 -0
  228. package/src/agent-analyzer.ts +481 -0
  229. package/src/agent.ts +1232 -0
  230. package/src/agents/correlation-analyzer.ts +353 -0
  231. package/src/agents/index.ts +235 -0
  232. package/src/agents/runtime-analyzer.ts +343 -0
  233. package/src/analysis-types.ts +558 -0
  234. package/src/analytics.ts +100 -0
  235. package/src/analyzer.ts +692 -0
  236. package/src/artifacts.ts +218 -0
  237. package/src/benchmarks/index.ts +309 -0
  238. package/src/cli.ts +503 -0
  239. package/src/commands/ci.ts +336 -0
  240. package/src/commands/config.ts +288 -0
  241. package/src/commands/demo.ts +175 -0
  242. package/src/commands/export.ts +297 -0
  243. package/src/commands/history.ts +425 -0
  244. package/src/commands/template.ts +385 -0
  245. package/src/commands/validate-map.ts +324 -0
  246. package/src/commands/whatif.ts +272 -0
  247. package/src/comparison.ts +283 -0
  248. package/src/config.ts +188 -0
  249. package/src/connectors/helicone.ts +164 -0
  250. package/src/connectors/index.ts +93 -0
  251. package/src/connectors/langsmith.ts +179 -0
  252. package/src/connectors/types.ts +180 -0
  253. package/src/cost-estimator.ts +146 -0
  254. package/src/costs.ts +347 -0
  255. package/src/counterfactuals.ts +516 -0
  256. package/src/enhancement-prompts.ts +118 -0
  257. package/src/envelopes.ts +814 -0
  258. package/src/format-normalizer.ts +1486 -0
  259. package/src/history.ts +400 -0
  260. package/src/html.ts +512 -0
  261. package/src/impact.ts +522 -0
  262. package/src/index.ts +83 -0
  263. package/src/insights.ts +341 -0
  264. package/src/joiner.ts +289 -0
  265. package/src/orchestrator.ts +1015 -0
  266. package/src/pdf.ts +110 -0
  267. package/src/prediction.ts +392 -0
  268. package/src/prompts/loader.ts +88 -0
  269. package/src/renderer.ts +1045 -0
  270. package/src/runid.ts +261 -0
  271. package/src/runtime.ts +450 -0
  272. package/src/scanner.ts +508 -0
  273. package/src/templates.ts +561 -0
  274. package/src/tools/index.ts +214 -0
  275. package/src/types.ts +873 -0
  276. package/src/version.ts +24 -0
  277. package/templates/context-accumulation.yaml +23 -0
  278. package/templates/cost-concentration.yaml +20 -0
  279. package/templates/dead-code.yaml +20 -0
  280. package/templates/latency-explainer.yaml +23 -0
  281. package/templates/optimizations/ab-testing-framework.yaml +74 -0
  282. package/templates/optimizations/api-gateway-optimization.yaml +81 -0
  283. package/templates/optimizations/api-model-routing-strategy.yaml +126 -0
  284. package/templates/optimizations/auto-scaling-optimization.yaml +85 -0
  285. package/templates/optimizations/batch-utilization-diagnostic.yaml +142 -0
  286. package/templates/optimizations/comprehensive-apm.yaml +76 -0
  287. package/templates/optimizations/context-window-optimization.yaml +91 -0
  288. package/templates/optimizations/cost-sensitive-batch-processing.yaml +77 -0
  289. package/templates/optimizations/distributed-training-optimization.yaml +77 -0
  290. package/templates/optimizations/document-analysis-edge.yaml +77 -0
  291. package/templates/optimizations/document-pipeline-optimization.yaml +78 -0
  292. package/templates/optimizations/domain-specific-distillation.yaml +78 -0
  293. package/templates/optimizations/error-handling-optimization.yaml +76 -0
  294. package/templates/optimizations/gptq-4bit-quantization.yaml +96 -0
  295. package/templates/optimizations/long-context-memory-management.yaml +78 -0
  296. package/templates/optimizations/max-tokens-optimization.yaml +76 -0
  297. package/templates/optimizations/memory-bandwidth-optimization.yaml +73 -0
  298. package/templates/optimizations/multi-framework-resilience.yaml +75 -0
  299. package/templates/optimizations/multi-tenant-optimization.yaml +75 -0
  300. package/templates/optimizations/prompt-caching-optimization.yaml +143 -0
  301. package/templates/optimizations/pytorch-to-onnx-migration.yaml +109 -0
  302. package/templates/optimizations/quality-monitoring.yaml +74 -0
  303. package/templates/optimizations/realtime-budget-controls.yaml +74 -0
  304. package/templates/optimizations/realtime-latency-optimization.yaml +74 -0
  305. package/templates/optimizations/sglang-concurrency-optimization.yaml +78 -0
  306. package/templates/optimizations/smart-model-routing.yaml +96 -0
  307. package/templates/optimizations/streaming-batch-selection.yaml +167 -0
  308. package/templates/optimizations/system-prompt-optimization.yaml +75 -0
  309. package/templates/optimizations/tensorrt-llm-performance.yaml +77 -0
  310. package/templates/optimizations/vllm-high-throughput-optimization.yaml +93 -0
  311. package/templates/optimizations/vllm-migration-memory-bound.yaml +78 -0
  312. package/templates/overpowered-extraction.yaml +32 -0
  313. package/templates/overpowered-model.yaml +31 -0
  314. package/templates/prompt-bloat.yaml +24 -0
  315. package/templates/retry-explosion.yaml +28 -0
  316. package/templates/schema/insight.schema.json +113 -0
  317. package/templates/schema/optimization.schema.json +180 -0
  318. package/templates/streaming-drift.yaml +30 -0
  319. package/templates/throughput-gap.yaml +21 -0
  320. package/templates/token-underutilization.yaml +28 -0
  321. package/templates/untested-fallback.yaml +21 -0
  322. package/tests/accuracy/drift-detection.test.ts +184 -0
  323. package/tests/accuracy/false-positives.test.ts +166 -0
  324. package/tests/accuracy/templates.test.ts +205 -0
  325. package/tests/action/commands.test.ts +125 -0
  326. package/tests/action/comments.test.ts +347 -0
  327. package/tests/cli.test.ts +203 -0
  328. package/tests/comparison.test.ts +309 -0
  329. package/tests/correlation-analyzer.test.ts +534 -0
  330. package/tests/counterfactuals.test.ts +347 -0
  331. package/tests/fixtures/events/missing-id.jsonl +1 -0
  332. package/tests/fixtures/events/missing-input.jsonl +1 -0
  333. package/tests/fixtures/events/missing-latency.jsonl +1 -0
  334. package/tests/fixtures/events/missing-model.jsonl +1 -0
  335. package/tests/fixtures/events/missing-output.jsonl +1 -0
  336. package/tests/fixtures/events/missing-provider.jsonl +1 -0
  337. package/tests/fixtures/events/missing-ts.jsonl +1 -0
  338. package/tests/fixtures/events/valid.csv +3 -0
  339. package/tests/fixtures/events/valid.json +1 -0
  340. package/tests/fixtures/events/valid.jsonl +2 -0
  341. package/tests/fixtures/events/with-callsite.jsonl +1 -0
  342. package/tests/fixtures/events/with-intent.jsonl +1 -0
  343. package/tests/fixtures/events/wrong-type.jsonl +1 -0
  344. package/tests/fixtures/repos/empty/.gitkeep +0 -0
  345. package/tests/fixtures/repos/hybrid-router/router.py +35 -0
  346. package/tests/fixtures/repos/saas-anthropic/agent.ts +27 -0
  347. package/tests/fixtures/repos/saas-openai/assistant.js +33 -0
  348. package/tests/fixtures/repos/saas-openai/client.py +26 -0
  349. package/tests/fixtures/repos/self-hosted-vllm/inference.py +22 -0
  350. package/tests/github-action.test.ts +292 -0
  351. package/tests/insights.test.ts +878 -0
  352. package/tests/joiner.test.ts +168 -0
  353. package/tests/performance/action-latency.test.ts +132 -0
  354. package/tests/performance/benchmark.test.ts +189 -0
  355. package/tests/performance/cli-latency.test.ts +102 -0
  356. package/tests/pr-comment.test.ts +313 -0
  357. package/tests/prediction.test.ts +296 -0
  358. package/tests/runtime-analyzer.test.ts +375 -0
  359. package/tests/runtime.test.ts +205 -0
  360. package/tests/scanner.test.ts +122 -0
  361. package/tests/template-conformance.test.ts +526 -0
  362. package/tests/unit/cost-calculator.test.ts +303 -0
  363. package/tests/unit/credits.test.ts +180 -0
  364. package/tests/unit/inference-map.test.ts +276 -0
  365. package/tests/unit/schema.test.ts +300 -0
  366. package/tsconfig.json +20 -0
  367. package/vitest.config.ts +14 -0
@@ -0,0 +1,276 @@
1
+ /**
2
+ * InferenceMap Tests
3
+ * Per Test Cases v1.9.3 - Core Analysis Tests
4
+ */
5
+ import { describe, test, expect } from 'vitest';
6
+
7
+ // InferenceMap types (from inferencemap-spec.md)
8
+ interface InferencePoint {
9
+ id: string;
10
+ file: string;
11
+ line: number;
12
+ function?: string;
13
+ provider: string;
14
+ model: string;
15
+ streaming?: boolean;
16
+ costProfile?: {
17
+ estimatedCostPer1K?: number;
18
+ inputTokens?: number;
19
+ outputTokens?: number;
20
+ };
21
+ }
22
+
23
+ interface Issue {
24
+ id: string;
25
+ severity: 'critical' | 'high' | 'medium' | 'low';
26
+ category: 'cost' | 'latency' | 'throughput' | 'reliability' | 'drift';
27
+ title: string;
28
+ description: string;
29
+ file: string;
30
+ line: number;
31
+ impact?: string;
32
+ fix?: {
33
+ description: string;
34
+ effort?: string;
35
+ code?: string;
36
+ };
37
+ }
38
+
39
+ interface InferenceMap {
40
+ version: string;
41
+ generated: string;
42
+ inferencePoints: InferencePoint[];
43
+ issues: Issue[];
44
+ summary: {
45
+ totalInferencePoints: number;
46
+ providers: string[];
47
+ criticalIssues: number;
48
+ highIssues: number;
49
+ mediumIssues: number;
50
+ lowIssues?: number;
51
+ };
52
+ }
53
+
54
+ // InferenceMap utilities
55
+ function createInferenceMap(
56
+ points: InferencePoint[],
57
+ issues: Issue[]
58
+ ): InferenceMap {
59
+ const providers = [...new Set(points.map(p => p.provider))];
60
+
61
+ return {
62
+ version: '0.1',
63
+ generated: new Date().toISOString(),
64
+ inferencePoints: points,
65
+ issues,
66
+ summary: {
67
+ totalInferencePoints: points.length,
68
+ providers,
69
+ criticalIssues: issues.filter(i => i.severity === 'critical').length,
70
+ highIssues: issues.filter(i => i.severity === 'high').length,
71
+ mediumIssues: issues.filter(i => i.severity === 'medium').length,
72
+ lowIssues: issues.filter(i => i.severity === 'low').length,
73
+ },
74
+ };
75
+ }
76
+
77
+ function mergeInferenceMaps(maps: InferenceMap[]): InferenceMap {
78
+ const allPoints = maps.flatMap(m => m.inferencePoints);
79
+ const allIssues = maps.flatMap(m => m.issues);
80
+ const providers = [...new Set(allPoints.map(p => p.provider))];
81
+
82
+ return {
83
+ version: '0.1',
84
+ generated: new Date().toISOString(),
85
+ inferencePoints: allPoints,
86
+ issues: allIssues,
87
+ summary: {
88
+ totalInferencePoints: allPoints.length,
89
+ providers,
90
+ criticalIssues: allIssues.filter(i => i.severity === 'critical').length,
91
+ highIssues: allIssues.filter(i => i.severity === 'high').length,
92
+ mediumIssues: allIssues.filter(i => i.severity === 'medium').length,
93
+ lowIssues: allIssues.filter(i => i.severity === 'low').length,
94
+ },
95
+ };
96
+ }
97
+
98
+ function filterByFile(map: InferenceMap, file: string): InferenceMap {
99
+ const points = map.inferencePoints.filter(p => p.file === file);
100
+ const issues = map.issues.filter(i => i.file === file);
101
+ return createInferenceMap(points, issues);
102
+ }
103
+
104
+ function filterBySeverity(
105
+ map: InferenceMap,
106
+ minSeverity: 'critical' | 'high' | 'medium' | 'low'
107
+ ): InferenceMap {
108
+ const severityOrder = { critical: 0, high: 1, medium: 2, low: 3 };
109
+ const minLevel = severityOrder[minSeverity];
110
+
111
+ const issues = map.issues.filter(i => severityOrder[i.severity] <= minLevel);
112
+ return createInferenceMap(map.inferencePoints, issues);
113
+ }
114
+
115
+ function filterByCategory(
116
+ map: InferenceMap,
117
+ category: 'cost' | 'latency' | 'throughput' | 'reliability' | 'drift'
118
+ ): InferenceMap {
119
+ const issues = map.issues.filter(i => i.category === category);
120
+ return createInferenceMap(map.inferencePoints, issues);
121
+ }
122
+
123
+ describe('InferenceMap Creation', () => {
124
+ test('Creates valid InferenceMap from points and issues', () => {
125
+ const points: InferencePoint[] = [
126
+ { id: 'ip-1', file: 'src/chat.ts', line: 42, provider: 'anthropic', model: 'claude-sonnet-4-20250514' },
127
+ { id: 'ip-2', file: 'src/embed.ts', line: 15, provider: 'openai', model: 'text-embedding-ada-002' },
128
+ ];
129
+
130
+ const issues: Issue[] = [
131
+ {
132
+ id: 'issue-1',
133
+ severity: 'high',
134
+ category: 'cost',
135
+ title: 'Expensive model',
136
+ description: 'Using expensive model',
137
+ file: 'src/chat.ts',
138
+ line: 42,
139
+ },
140
+ ];
141
+
142
+ const map = createInferenceMap(points, issues);
143
+
144
+ expect(map.version).toBe('0.1');
145
+ expect(map.inferencePoints).toHaveLength(2);
146
+ expect(map.issues).toHaveLength(1);
147
+ expect(map.summary.totalInferencePoints).toBe(2);
148
+ expect(map.summary.providers).toContain('anthropic');
149
+ expect(map.summary.providers).toContain('openai');
150
+ expect(map.summary.highIssues).toBe(1);
151
+ });
152
+
153
+ test('Handles empty inputs', () => {
154
+ const map = createInferenceMap([], []);
155
+
156
+ expect(map.inferencePoints).toHaveLength(0);
157
+ expect(map.issues).toHaveLength(0);
158
+ expect(map.summary.totalInferencePoints).toBe(0);
159
+ expect(map.summary.providers).toHaveLength(0);
160
+ });
161
+
162
+ test('Deduplicates providers in summary', () => {
163
+ const points: InferencePoint[] = [
164
+ { id: 'ip-1', file: 'a.ts', line: 1, provider: 'anthropic', model: 'claude-sonnet-4-20250514' },
165
+ { id: 'ip-2', file: 'b.ts', line: 1, provider: 'anthropic', model: 'claude-haiku-3-20240307' },
166
+ { id: 'ip-3', file: 'c.ts', line: 1, provider: 'openai', model: 'gpt-4' },
167
+ ];
168
+
169
+ const map = createInferenceMap(points, []);
170
+
171
+ expect(map.summary.providers).toHaveLength(2);
172
+ expect(map.summary.providers).toContain('anthropic');
173
+ expect(map.summary.providers).toContain('openai');
174
+ });
175
+ });
176
+
177
+ describe('InferenceMap Merging', () => {
178
+ test('Merges multiple maps', () => {
179
+ const map1 = createInferenceMap(
180
+ [{ id: 'ip-1', file: 'a.ts', line: 1, provider: 'anthropic', model: 'claude-sonnet-4-20250514' }],
181
+ [{ id: 'i-1', severity: 'high', category: 'cost', title: 'T', description: 'D', file: 'a.ts', line: 1 }]
182
+ );
183
+
184
+ const map2 = createInferenceMap(
185
+ [{ id: 'ip-2', file: 'b.ts', line: 1, provider: 'openai', model: 'gpt-4' }],
186
+ [{ id: 'i-2', severity: 'critical', category: 'latency', title: 'T2', description: 'D2', file: 'b.ts', line: 1 }]
187
+ );
188
+
189
+ const merged = mergeInferenceMaps([map1, map2]);
190
+
191
+ expect(merged.inferencePoints).toHaveLength(2);
192
+ expect(merged.issues).toHaveLength(2);
193
+ expect(merged.summary.totalInferencePoints).toBe(2);
194
+ expect(merged.summary.criticalIssues).toBe(1);
195
+ expect(merged.summary.highIssues).toBe(1);
196
+ });
197
+
198
+ test('Handles empty map in merge', () => {
199
+ const map1 = createInferenceMap(
200
+ [{ id: 'ip-1', file: 'a.ts', line: 1, provider: 'anthropic', model: 'claude-sonnet-4-20250514' }],
201
+ []
202
+ );
203
+
204
+ const map2 = createInferenceMap([], []);
205
+
206
+ const merged = mergeInferenceMaps([map1, map2]);
207
+
208
+ expect(merged.inferencePoints).toHaveLength(1);
209
+ expect(merged.issues).toHaveLength(0);
210
+ });
211
+ });
212
+
213
+ describe('InferenceMap Filtering', () => {
214
+ const testMap: InferenceMap = createInferenceMap(
215
+ [
216
+ { id: 'ip-1', file: 'src/chat.ts', line: 10, provider: 'anthropic', model: 'claude-sonnet-4-20250514' },
217
+ { id: 'ip-2', file: 'src/embed.ts', line: 20, provider: 'openai', model: 'ada' },
218
+ { id: 'ip-3', file: 'src/chat.ts', line: 30, provider: 'anthropic', model: 'claude-haiku-3-20240307' },
219
+ ],
220
+ [
221
+ { id: 'i-1', severity: 'critical', category: 'cost', title: 'T1', description: 'D1', file: 'src/chat.ts', line: 10 },
222
+ { id: 'i-2', severity: 'high', category: 'latency', title: 'T2', description: 'D2', file: 'src/embed.ts', line: 20 },
223
+ { id: 'i-3', severity: 'medium', category: 'drift', title: 'T3', description: 'D3', file: 'src/chat.ts', line: 30 },
224
+ ]
225
+ );
226
+
227
+ test('Filters by file', () => {
228
+ const filtered = filterByFile(testMap, 'src/chat.ts');
229
+
230
+ expect(filtered.inferencePoints).toHaveLength(2);
231
+ expect(filtered.issues).toHaveLength(2);
232
+ expect(filtered.inferencePoints.every(p => p.file === 'src/chat.ts')).toBe(true);
233
+ });
234
+
235
+ test('Filters by severity (critical only)', () => {
236
+ const filtered = filterBySeverity(testMap, 'critical');
237
+
238
+ expect(filtered.issues).toHaveLength(1);
239
+ expect(filtered.issues[0].severity).toBe('critical');
240
+ });
241
+
242
+ test('Filters by severity (high and above)', () => {
243
+ const filtered = filterBySeverity(testMap, 'high');
244
+
245
+ expect(filtered.issues).toHaveLength(2);
246
+ expect(filtered.issues.every(i => ['critical', 'high'].includes(i.severity))).toBe(true);
247
+ });
248
+
249
+ test('Filters by category', () => {
250
+ const filtered = filterByCategory(testMap, 'cost');
251
+
252
+ expect(filtered.issues).toHaveLength(1);
253
+ expect(filtered.issues[0].category).toBe('cost');
254
+ });
255
+ });
256
+
257
+ describe('InferenceMap Summary', () => {
258
+ test('Correctly counts issues by severity', () => {
259
+ const issues: Issue[] = [
260
+ { id: 'i-1', severity: 'critical', category: 'cost', title: 'T', description: 'D', file: 'a.ts', line: 1 },
261
+ { id: 'i-2', severity: 'critical', category: 'cost', title: 'T', description: 'D', file: 'a.ts', line: 2 },
262
+ { id: 'i-3', severity: 'high', category: 'cost', title: 'T', description: 'D', file: 'a.ts', line: 3 },
263
+ { id: 'i-4', severity: 'medium', category: 'cost', title: 'T', description: 'D', file: 'a.ts', line: 4 },
264
+ { id: 'i-5', severity: 'medium', category: 'cost', title: 'T', description: 'D', file: 'a.ts', line: 5 },
265
+ { id: 'i-6', severity: 'medium', category: 'cost', title: 'T', description: 'D', file: 'a.ts', line: 6 },
266
+ { id: 'i-7', severity: 'low', category: 'cost', title: 'T', description: 'D', file: 'a.ts', line: 7 },
267
+ ];
268
+
269
+ const map = createInferenceMap([], issues);
270
+
271
+ expect(map.summary.criticalIssues).toBe(2);
272
+ expect(map.summary.highIssues).toBe(1);
273
+ expect(map.summary.mediumIssues).toBe(3);
274
+ expect(map.summary.lowIssues).toBe(1);
275
+ });
276
+ });
@@ -0,0 +1,300 @@
1
+ /**
2
+ * Schema Validation Tests
3
+ * Per Test Cases v1.9.3 - Critical Path Tests
4
+ */
5
+ import { describe, test, expect } from 'vitest';
6
+ import { z } from 'zod';
7
+
8
+ // InferenceMap v0.1 Schema (from docs/inferencemap-spec.md)
9
+ const InferencePointSchema = z.object({
10
+ id: z.string(),
11
+ file: z.string(),
12
+ line: z.number(),
13
+ function: z.string().optional(),
14
+ provider: z.string(),
15
+ model: z.string(),
16
+ streaming: z.boolean().optional(),
17
+ costProfile: z.object({
18
+ estimatedCostPer1K: z.number().optional(),
19
+ inputTokens: z.number().optional(),
20
+ outputTokens: z.number().optional(),
21
+ }).optional(),
22
+ });
23
+
24
+ const IssueSchema = z.object({
25
+ id: z.string(),
26
+ severity: z.enum(['critical', 'high', 'medium', 'low']),
27
+ category: z.enum(['cost', 'latency', 'throughput', 'reliability', 'drift']),
28
+ title: z.string(),
29
+ description: z.string(),
30
+ file: z.string(),
31
+ line: z.number(),
32
+ impact: z.string().optional(),
33
+ fix: z.object({
34
+ description: z.string(),
35
+ effort: z.string().optional(),
36
+ code: z.string().optional(),
37
+ }).optional(),
38
+ });
39
+
40
+ const InferenceMapSchema = z.object({
41
+ version: z.string(),
42
+ generated: z.string(),
43
+ inferencePoints: z.array(InferencePointSchema),
44
+ issues: z.array(IssueSchema),
45
+ summary: z.object({
46
+ totalInferencePoints: z.number(),
47
+ providers: z.array(z.string()),
48
+ criticalIssues: z.number(),
49
+ highIssues: z.number(),
50
+ mediumIssues: z.number(),
51
+ lowIssues: z.number().optional(),
52
+ }),
53
+ });
54
+
55
+ // Runtime Event Schema
56
+ const RuntimeEventSchema = z.object({
57
+ id: z.string(),
58
+ ts: z.string(),
59
+ provider: z.string(),
60
+ model: z.string(),
61
+ input_tokens: z.number(),
62
+ output_tokens: z.number(),
63
+ latency_ms: z.number(),
64
+ intent: z.string().optional(),
65
+ callsite_id: z.string().optional(),
66
+ });
67
+
68
+ describe('InferenceMap Schema', () => {
69
+ test('Valid InferenceMap passes validation', () => {
70
+ const validMap = {
71
+ version: '0.1',
72
+ generated: '2025-12-24T00:00:00.000Z',
73
+ inferencePoints: [
74
+ {
75
+ id: 'ip-1',
76
+ file: 'src/chat.ts',
77
+ line: 42,
78
+ function: 'chat',
79
+ provider: 'anthropic',
80
+ model: 'claude-sonnet-4-20250514',
81
+ streaming: true,
82
+ },
83
+ ],
84
+ issues: [
85
+ {
86
+ id: 'issue-1',
87
+ severity: 'high',
88
+ category: 'cost',
89
+ title: 'Overpowered model',
90
+ description: 'Using expensive model for simple task',
91
+ file: 'src/chat.ts',
92
+ line: 42,
93
+ },
94
+ ],
95
+ summary: {
96
+ totalInferencePoints: 1,
97
+ providers: ['anthropic'],
98
+ criticalIssues: 0,
99
+ highIssues: 1,
100
+ mediumIssues: 0,
101
+ },
102
+ };
103
+
104
+ expect(() => InferenceMapSchema.parse(validMap)).not.toThrow();
105
+ });
106
+
107
+ test('Missing version fails validation', () => {
108
+ const invalidMap = {
109
+ generated: '2025-12-24T00:00:00.000Z',
110
+ inferencePoints: [],
111
+ issues: [],
112
+ summary: {
113
+ totalInferencePoints: 0,
114
+ providers: [],
115
+ criticalIssues: 0,
116
+ highIssues: 0,
117
+ mediumIssues: 0,
118
+ },
119
+ };
120
+
121
+ expect(() => InferenceMapSchema.parse(invalidMap)).toThrow();
122
+ });
123
+
124
+ test('Invalid severity fails validation', () => {
125
+ const invalidMap = {
126
+ version: '0.1',
127
+ generated: '2025-12-24T00:00:00.000Z',
128
+ inferencePoints: [],
129
+ issues: [
130
+ {
131
+ id: 'issue-1',
132
+ severity: 'super-critical', // Invalid
133
+ category: 'cost',
134
+ title: 'Test',
135
+ description: 'Test',
136
+ file: 'test.ts',
137
+ line: 1,
138
+ },
139
+ ],
140
+ summary: {
141
+ totalInferencePoints: 0,
142
+ providers: [],
143
+ criticalIssues: 0,
144
+ highIssues: 0,
145
+ mediumIssues: 0,
146
+ },
147
+ };
148
+
149
+ expect(() => InferenceMapSchema.parse(invalidMap)).toThrow();
150
+ });
151
+
152
+ test('Invalid category fails validation', () => {
153
+ const invalidMap = {
154
+ version: '0.1',
155
+ generated: '2025-12-24T00:00:00.000Z',
156
+ inferencePoints: [],
157
+ issues: [
158
+ {
159
+ id: 'issue-1',
160
+ severity: 'high',
161
+ category: 'performance', // Invalid - should be cost/latency/throughput/reliability/drift
162
+ title: 'Test',
163
+ description: 'Test',
164
+ file: 'test.ts',
165
+ line: 1,
166
+ },
167
+ ],
168
+ summary: {
169
+ totalInferencePoints: 0,
170
+ providers: [],
171
+ criticalIssues: 0,
172
+ highIssues: 0,
173
+ mediumIssues: 0,
174
+ },
175
+ };
176
+
177
+ expect(() => InferenceMapSchema.parse(invalidMap)).toThrow();
178
+ });
179
+
180
+ test('Empty arrays are valid', () => {
181
+ const emptyMap = {
182
+ version: '0.1',
183
+ generated: '2025-12-24T00:00:00.000Z',
184
+ inferencePoints: [],
185
+ issues: [],
186
+ summary: {
187
+ totalInferencePoints: 0,
188
+ providers: [],
189
+ criticalIssues: 0,
190
+ highIssues: 0,
191
+ mediumIssues: 0,
192
+ },
193
+ };
194
+
195
+ expect(() => InferenceMapSchema.parse(emptyMap)).not.toThrow();
196
+ });
197
+ });
198
+
199
+ describe('Runtime Event Schema', () => {
200
+ test('Valid runtime event passes validation', () => {
201
+ const validEvent = {
202
+ id: 'event-1',
203
+ ts: '2025-12-24T00:00:00.000Z',
204
+ provider: 'anthropic',
205
+ model: 'claude-sonnet-4-20250514',
206
+ input_tokens: 100,
207
+ output_tokens: 200,
208
+ latency_ms: 1500,
209
+ };
210
+
211
+ expect(() => RuntimeEventSchema.parse(validEvent)).not.toThrow();
212
+ });
213
+
214
+ test('Missing required fields fail validation', () => {
215
+ const missingId = {
216
+ ts: '2025-12-24T00:00:00.000Z',
217
+ provider: 'anthropic',
218
+ model: 'claude-sonnet-4-20250514',
219
+ input_tokens: 100,
220
+ output_tokens: 200,
221
+ latency_ms: 1500,
222
+ };
223
+
224
+ expect(() => RuntimeEventSchema.parse(missingId)).toThrow();
225
+ });
226
+
227
+ test('Wrong type for latency_ms fails validation', () => {
228
+ const wrongType = {
229
+ id: 'event-1',
230
+ ts: '2025-12-24T00:00:00.000Z',
231
+ provider: 'anthropic',
232
+ model: 'claude-sonnet-4-20250514',
233
+ input_tokens: 100,
234
+ output_tokens: 200,
235
+ latency_ms: '1500', // Should be number
236
+ };
237
+
238
+ expect(() => RuntimeEventSchema.parse(wrongType)).toThrow();
239
+ });
240
+
241
+ test('Optional fields are accepted', () => {
242
+ const withOptional = {
243
+ id: 'event-1',
244
+ ts: '2025-12-24T00:00:00.000Z',
245
+ provider: 'anthropic',
246
+ model: 'claude-sonnet-4-20250514',
247
+ input_tokens: 100,
248
+ output_tokens: 200,
249
+ latency_ms: 1500,
250
+ intent: 'chat',
251
+ callsite_id: 'cs-1',
252
+ };
253
+
254
+ expect(() => RuntimeEventSchema.parse(withOptional)).not.toThrow();
255
+ });
256
+ });
257
+
258
+ describe('Inference Point Schema', () => {
259
+ test('Minimal inference point is valid', () => {
260
+ const minimal = {
261
+ id: 'ip-1',
262
+ file: 'src/chat.ts',
263
+ line: 42,
264
+ provider: 'anthropic',
265
+ model: 'claude-sonnet-4-20250514',
266
+ };
267
+
268
+ expect(() => InferencePointSchema.parse(minimal)).not.toThrow();
269
+ });
270
+
271
+ test('Full inference point is valid', () => {
272
+ const full = {
273
+ id: 'ip-1',
274
+ file: 'src/chat.ts',
275
+ line: 42,
276
+ function: 'chat',
277
+ provider: 'anthropic',
278
+ model: 'claude-sonnet-4-20250514',
279
+ streaming: true,
280
+ costProfile: {
281
+ estimatedCostPer1K: 0.015,
282
+ inputTokens: 500,
283
+ outputTokens: 2000,
284
+ },
285
+ };
286
+
287
+ expect(() => InferencePointSchema.parse(full)).not.toThrow();
288
+ });
289
+
290
+ test('Missing id fails validation', () => {
291
+ const noId = {
292
+ file: 'src/chat.ts',
293
+ line: 42,
294
+ provider: 'anthropic',
295
+ model: 'claude-sonnet-4-20250514',
296
+ };
297
+
298
+ expect(() => InferencePointSchema.parse(noId)).toThrow();
299
+ });
300
+ });
package/tsconfig.json ADDED
@@ -0,0 +1,20 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2022",
4
+ "module": "NodeNext",
5
+ "moduleResolution": "NodeNext",
6
+ "lib": ["ES2022"],
7
+ "outDir": "dist",
8
+ "rootDir": "src",
9
+ "strict": true,
10
+ "esModuleInterop": true,
11
+ "skipLibCheck": true,
12
+ "forceConsistentCasingInFileNames": true,
13
+ "resolveJsonModule": true,
14
+ "declaration": true,
15
+ "declarationMap": true,
16
+ "sourceMap": true
17
+ },
18
+ "include": ["src/**/*"],
19
+ "exclude": ["node_modules", "dist", "**/*.test.ts"]
20
+ }
@@ -0,0 +1,14 @@
1
+ import { defineConfig } from 'vitest/config';
2
+
3
+ export default defineConfig({
4
+ test: {
5
+ globals: true,
6
+ environment: 'node',
7
+ include: ['tests/**/*.test.ts', 'evals/**/*.test.ts'],
8
+ testTimeout: 120000, // 2 minutes for agent-based analysis
9
+ coverage: {
10
+ provider: 'v8',
11
+ reporter: ['text', 'json', 'html'],
12
+ },
13
+ },
14
+ });