@unerr-ai/unerr 0.1.6 → 0.1.7
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/README.md +70 -194
- package/dist/cli.js +39149 -36991
- package/package.json +9 -2
- package/dist/__tests__/architecture-guard.test.js +0 -122
- package/dist/__tests__/arg-validator.test.js +0 -205
- package/dist/__tests__/ast-extractor.test.js +0 -203
- package/dist/__tests__/auto-bootstrap.test.js +0 -280
- package/dist/__tests__/background-indexer.test.js +0 -228
- package/dist/__tests__/blast-radius-engine.test.js +0 -200
- package/dist/__tests__/bridge-isolation.test.js +0 -37
- package/dist/__tests__/budget-enforcer.test.js +0 -53
- package/dist/__tests__/cfg-test-detection-perf.test.js +0 -82
- package/dist/__tests__/change-narrative.test.js +0 -190
- package/dist/__tests__/check-commit.test.js +0 -258
- package/dist/__tests__/checksum.test.js +0 -34
- package/dist/__tests__/commit-watcher.test.js +0 -154
- package/dist/__tests__/community-detection.test.js +0 -179
- package/dist/__tests__/community-tools.test.js +0 -299
- package/dist/__tests__/components.test.js +0 -449
- package/dist/__tests__/compression-log.test.js +0 -174
- package/dist/__tests__/compression-quality-monitor.test.js +0 -40
- package/dist/__tests__/config-healer.test.js +0 -165
- package/dist/__tests__/context-ledger.test.js +0 -58
- package/dist/__tests__/convention-detector.test.js +0 -99
- package/dist/__tests__/convention-learner.test.js +0 -86
- package/dist/__tests__/correction-detector.test.js +0 -330
- package/dist/__tests__/daemon-autostart-install.test.js +0 -283
- package/dist/__tests__/daemon-bridge.test.js +0 -222
- package/dist/__tests__/daemon-dashboard.test.js +0 -202
- package/dist/__tests__/daemon-registry.test.js +0 -240
- package/dist/__tests__/daemon-supervisor.test.js +0 -318
- package/dist/__tests__/daemon-version-check.test.js +0 -275
- package/dist/__tests__/decision-point-detector.test.js +0 -98
- package/dist/__tests__/deep-link.test.js +0 -143
- package/dist/__tests__/disallowed-tools.test.js +0 -115
- package/dist/__tests__/drift-tracker.test.js +0 -582
- package/dist/__tests__/durability-scorer.test.js +0 -152
- package/dist/__tests__/efficiency-tracker.test.js +0 -65
- package/dist/__tests__/enrich.test.js +0 -144
- package/dist/__tests__/entity-rewind.test.js +0 -248
- package/dist/__tests__/ephemeral.test.js +0 -111
- package/dist/__tests__/exploration-cost.test.js +0 -93
- package/dist/__tests__/fact-generator.test.js +0 -197
- package/dist/__tests__/file-l0-graph.test.js +0 -244
- package/dist/__tests__/file-logger.test.js +0 -82
- package/dist/__tests__/file-outline.test.js +0 -141
- package/dist/__tests__/file-read-protocol.test.js +0 -188
- package/dist/__tests__/format-encoder.test.js +0 -233
- package/dist/__tests__/git-attribution.test.js +0 -259
- package/dist/__tests__/graph-temporal-joiner.test.js +0 -219
- package/dist/__tests__/health-grade-enhanced.test.js +0 -138
- package/dist/__tests__/health-map-data.test.js +0 -173
- package/dist/__tests__/helpers/mcp-harness.js +0 -45
- package/dist/__tests__/helpers/mcp-harness.test.js +0 -68
- package/dist/__tests__/hook-dedup.test.js +0 -112
- package/dist/__tests__/hook-runner.test.js +0 -253
- package/dist/__tests__/indexer-cfg.test.js +0 -185
- package/dist/__tests__/indexer-cross-file.test.js +0 -172
- package/dist/__tests__/indexer-extraction.test.js +0 -245
- package/dist/__tests__/indexer-incremental.test.js +0 -232
- package/dist/__tests__/indexer-language-expansion.test.js +0 -165
- package/dist/__tests__/init-push.test.js +0 -131
- package/dist/__tests__/instruction-writer.test.js +0 -179
- package/dist/__tests__/intelligence-integration.test.js +0 -217
- package/dist/__tests__/intent-correlator.test.js +0 -175
- package/dist/__tests__/intent-detector.test.js +0 -235
- package/dist/__tests__/intent-encoder.test.js +0 -167
- package/dist/__tests__/java-build-tool-detection.test.js +0 -174
- package/dist/__tests__/layer3-sprint-q.test.js +0 -160
- package/dist/__tests__/layer3-sprint-r.test.js +0 -91
- package/dist/__tests__/layer3-sprint-s.test.js +0 -183
- package/dist/__tests__/layer3-sprint-t.test.js +0 -201
- package/dist/__tests__/layer3-sprint-u.test.js +0 -174
- package/dist/__tests__/layer4-sprint-ba2.test.js +0 -354
- package/dist/__tests__/layer4-sprint-ba4.test.js +0 -84
- package/dist/__tests__/layer4-sprint-vs.test.js +0 -105
- package/dist/__tests__/ledger-chains.test.js +0 -162
- package/dist/__tests__/lifecycle-machine.test.js +0 -226
- package/dist/__tests__/local-chat-provider.test.js +0 -170
- package/dist/__tests__/local-convention-detector.test.js +0 -308
- package/dist/__tests__/local-embeddings.test.js +0 -422
- package/dist/__tests__/local-graph.test.js +0 -540
- package/dist/__tests__/local-indexer.test.js +0 -228
- package/dist/__tests__/local-intelligence-l3.test.js +0 -332
- package/dist/__tests__/local-llm.test.js +0 -253
- package/dist/__tests__/local-mode-offline.test.js +0 -187
- package/dist/__tests__/local-mode-stats.test.js +0 -273
- package/dist/__tests__/local-mode-tui.test.js +0 -343
- package/dist/__tests__/local-parse.test.js +0 -199
- package/dist/__tests__/log-tailer.test.js +0 -208
- package/dist/__tests__/loop-breaker.test.js +0 -276
- package/dist/__tests__/loop-miner.test.js +0 -226
- package/dist/__tests__/mcp-config.test.js +0 -126
- package/dist/__tests__/mcp-content-json.test.js +0 -10
- package/dist/__tests__/mcp-envelope.test.js +0 -124
- package/dist/__tests__/metrics-store.test.js +0 -223
- package/dist/__tests__/native-watcher.test.js +0 -191
- package/dist/__tests__/navigation-hooks-agent-aware.test.js +0 -145
- package/dist/__tests__/negative-knowledge.test.js +0 -116
- package/dist/__tests__/network-boundary.test.js +0 -190
- package/dist/__tests__/network-firewall.test.js +0 -112
- package/dist/__tests__/nudge-invariants.test.js +0 -160
- package/dist/__tests__/nudge-v2.test.js +0 -225
- package/dist/__tests__/offline-rewind.test.js +0 -251
- package/dist/__tests__/open-threads.test.js +0 -89
- package/dist/__tests__/output-compressor.test.js +0 -93
- package/dist/__tests__/pending-violations.test.js +0 -112
- package/dist/__tests__/persistence-effectiveness.test.js +0 -143
- package/dist/__tests__/provider-factory.test.js +0 -42
- package/dist/__tests__/providers.test.js +0 -24
- package/dist/__tests__/proxy.test.js +0 -314
- package/dist/__tests__/query-router.test.js +0 -1018
- package/dist/__tests__/reasoning-quality-route.test.js +0 -138
- package/dist/__tests__/redactor.test.js +0 -120
- package/dist/__tests__/resource-monitor.test.js +0 -57
- package/dist/__tests__/response-envelope.test.js +0 -100
- package/dist/__tests__/risk-classifier.test.js +0 -101
- package/dist/__tests__/risk-signal-scope.test.js +0 -75
- package/dist/__tests__/rule-evaluator.test.js +0 -280
- package/dist/__tests__/scip-decoder.test.js +0 -49
- package/dist/__tests__/scip-downloader.test.js +0 -201
- package/dist/__tests__/scip-merger.test.js +0 -103
- package/dist/__tests__/search-index.test.js +0 -422
- package/dist/__tests__/semantic-enrichment.test.js +0 -360
- package/dist/__tests__/session-brief-builder.test.js +0 -187
- package/dist/__tests__/session-context.test.js +0 -221
- package/dist/__tests__/session-continuity.test.js +0 -144
- package/dist/__tests__/session-dedup.test.js +0 -74
- package/dist/__tests__/session-event-wiring.test.js +0 -206
- package/dist/__tests__/session-events.test.js +0 -149
- package/dist/__tests__/session-legend.test.js +0 -20
- package/dist/__tests__/session-persistence.test.js +0 -131
- package/dist/__tests__/session-resume-block.test.js +0 -107
- package/dist/__tests__/session-resume.test.js +0 -97
- package/dist/__tests__/session-summary-writer.test.js +0 -134
- package/dist/__tests__/shadow-ledger.test.js +0 -203
- package/dist/__tests__/shell-classifier.test.js +0 -151
- package/dist/__tests__/shell-compression-floor.test.js +0 -189
- package/dist/__tests__/shell-compression-v2.test.js +0 -339
- package/dist/__tests__/shell-compressor.test.js +0 -35
- package/dist/__tests__/shell-hooks.test.js +0 -128
- package/dist/__tests__/shell-strategies.test.js +0 -644
- package/dist/__tests__/shell-tee.test.js +0 -133
- package/dist/__tests__/signal-dedup.test.js +0 -158
- package/dist/__tests__/signal-reinforcer.test.js +0 -77
- package/dist/__tests__/signal-scorer.test.js +0 -251
- package/dist/__tests__/signal-show-store.test.js +0 -108
- package/dist/__tests__/smart-truncate.test.js +0 -215
- package/dist/__tests__/snapshot-v2.test.js +0 -113
- package/dist/__tests__/sprint-l1-local-mode.test.js +0 -130
- package/dist/__tests__/sprint-l10-boot.test.js +0 -220
- package/dist/__tests__/sprint-l9-offline-commands.test.js +0 -189
- package/dist/__tests__/sprint-q-persistent-context.test.js +0 -198
- package/dist/__tests__/sprint-s1-wiring.test.js +0 -215
- package/dist/__tests__/sprint-s2-wiring.test.js +0 -256
- package/dist/__tests__/sprint-s3-wiring.test.js +0 -195
- package/dist/__tests__/sprint-s4-wiring.test.js +0 -213
- package/dist/__tests__/sprint-s6-hooks.test.js +0 -222
- package/dist/__tests__/sprint-s7-persistent.test.js +0 -263
- package/dist/__tests__/sprint-s8-value.test.js +0 -167
- package/dist/__tests__/sprint-s9-behavioral.test.js +0 -179
- package/dist/__tests__/sprint3-intelligence.test.js +0 -297
- package/dist/__tests__/sprint5-mcp-server.test.js +0 -136
- package/dist/__tests__/startup-display.test.js +0 -302
- package/dist/__tests__/startup-log-file.test.js +0 -97
- package/dist/__tests__/stash-manager.test.js +0 -229
- package/dist/__tests__/state-detector.test.js +0 -92
- package/dist/__tests__/status-dashboard.test.js +0 -142
- package/dist/__tests__/temporal-facts.test.js +0 -292
- package/dist/__tests__/temporal-routes.test.js +0 -142
- package/dist/__tests__/test-detector.test.js +0 -174
- package/dist/__tests__/theme.test.js +0 -72
- package/dist/__tests__/timeline-agents.test.js +0 -122
- package/dist/__tests__/timeline-bootstrap.test.js +0 -176
- package/dist/__tests__/timeline-filters.test.js +0 -193
- package/dist/__tests__/timeline-markers.test.js +0 -151
- package/dist/__tests__/timeline-routes.test.js +0 -156
- package/dist/__tests__/timeline-store.test.js +0 -171
- package/dist/__tests__/token-counter.test.js +0 -86
- package/dist/__tests__/token-estimator.test.js +0 -96
- package/dist/__tests__/token-flow-api.test.js +0 -239
- package/dist/__tests__/token-flow-instrumentation.test.js +0 -437
- package/dist/__tests__/token-flow-persistence.test.js +0 -356
- package/dist/__tests__/token-flow-routes.test.js +0 -199
- package/dist/__tests__/token-flow.test.js +0 -695
- package/dist/__tests__/tool-clusters.test.js +0 -177
- package/dist/__tests__/transport-mux.test.js +0 -283
- package/dist/__tests__/turn-segmenter.test.js +0 -166
- package/dist/__tests__/uninstall.test.js +0 -141
- package/dist/__tests__/warm-start-policy.test.js +0 -271
- package/dist/__tests__/wire-cap-nudge.test.js +0 -77
- package/dist/__tests__/worker-pool.test.js +0 -101
- package/dist/ui/assets/index-7gl3mIuY.css +0 -1
- package/dist/ui/assets/index-CX4FCWGT.js +0 -10
- package/dist/ui/assets/rolldown-runtime-S-ySWqyJ.js +0 -1
- package/dist/ui/assets/vis-network-NIJHUFI3.js +0 -908
- package/dist/ui/fonts/jetbrains-mono-latin-400-normal.woff +0 -0
- package/dist/ui/icon-wordmark.png +0 -0
- package/dist/ui/icon-wordmark.svg +0 -30
- package/dist/ui/icon.png +0 -0
- package/dist/ui/icon.svg +0 -25
- package/dist/ui/index.html +0 -15
- package/dist/ui/prototype-sandbox/index.html +0 -257
- package/dist/ui/screenshots/activity.png +0 -0
- package/dist/ui/screenshots/code-base-intelligence.png +0 -0
- package/dist/ui/screenshots/dashboard.png +0 -0
- package/dist/ui/screenshots/project-memory.png +0 -0
- package/dist/ui/screenshots/reasoning-quality.png +0 -0
- package/dist/ui/screenshots/reasoning-session.png +0 -0
- package/dist/ui/screenshots/token-session.png +0 -0
- package/dist/ui/screenshots/token-trace-main.png +0 -0
- package/dist/ui/screenshots/token-turn.png +0 -0
- package/dist/ui/unerr-wordmark.png +0 -0
- package/dist/ui/unerr-wordmark.svg +0 -9
- package/dist/ui/unerr.png +0 -0
- package/dist/ui/unerr.svg +0 -25
- package/dist/ui/web-app-manifest-192x192.png +0 -0
- package/dist/ui/web-app-manifest-512x512.png +0 -0
|
@@ -1,160 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Layer 3 Sprint Q: Output Compression & Budget Enforcement tests.
|
|
3
|
-
*
|
|
4
|
-
* Tests: compression stats, quality monitor, skills, performance.
|
|
5
|
-
*/
|
|
6
|
-
import { describe, expect, it } from "vitest";
|
|
7
|
-
import { enforceBudget } from "../proxy/budget-enforcer.js";
|
|
8
|
-
import { createCompressionQualityMonitor, } from "../proxy/compression-quality-monitor.js";
|
|
9
|
-
import { createCompressionStatsCollector } from "../proxy/compression-stats.js";
|
|
10
|
-
import { compressOutput, } from "../proxy/output-compressor.js";
|
|
11
|
-
import { LOCAL_SKILLS, getSkill, getSkillsContext, } from "../skills/local-pack.js";
|
|
12
|
-
describe("Compression Stats (Q.6)", () => {
|
|
13
|
-
it("records compression events", () => {
|
|
14
|
-
const stats = createCompressionStatsCollector();
|
|
15
|
-
const id = stats.record({
|
|
16
|
-
contentType: "git_diff",
|
|
17
|
-
originalTokens: 5000,
|
|
18
|
-
compressedTokens: 1500,
|
|
19
|
-
sectionsPreserved: 3,
|
|
20
|
-
sectionsOmitted: 7,
|
|
21
|
-
annotationsAdded: 2,
|
|
22
|
-
durationMs: 3.5,
|
|
23
|
-
});
|
|
24
|
-
expect(id).toBeTruthy();
|
|
25
|
-
const event = stats.getEvent(id);
|
|
26
|
-
expect(event).not.toBeNull();
|
|
27
|
-
expect(event?.originalTokens).toBe(5000);
|
|
28
|
-
expect(event?.compressedTokens).toBe(1500);
|
|
29
|
-
});
|
|
30
|
-
it("computes session-level stats", () => {
|
|
31
|
-
const stats = createCompressionStatsCollector();
|
|
32
|
-
stats.record({
|
|
33
|
-
contentType: "git_diff",
|
|
34
|
-
originalTokens: 5000,
|
|
35
|
-
compressedTokens: 1500,
|
|
36
|
-
sectionsPreserved: 3,
|
|
37
|
-
sectionsOmitted: 7,
|
|
38
|
-
annotationsAdded: 2,
|
|
39
|
-
durationMs: 3,
|
|
40
|
-
});
|
|
41
|
-
stats.record({
|
|
42
|
-
contentType: "test_output",
|
|
43
|
-
originalTokens: 3000,
|
|
44
|
-
compressedTokens: 1000,
|
|
45
|
-
sectionsPreserved: 2,
|
|
46
|
-
sectionsOmitted: 5,
|
|
47
|
-
annotationsAdded: 0,
|
|
48
|
-
durationMs: 2,
|
|
49
|
-
});
|
|
50
|
-
const session = stats.getSessionStats();
|
|
51
|
-
expect(session.totalEvents).toBe(2);
|
|
52
|
-
expect(session.totalOriginalTokens).toBe(8000);
|
|
53
|
-
expect(session.totalCompressedTokens).toBe(2500);
|
|
54
|
-
expect(session.totalSaved).toBe(5500);
|
|
55
|
-
expect(session.avgCompressionRatio).toBeCloseTo(0.69, 1);
|
|
56
|
-
expect(session.byContentType.git_diff?.count).toBe(1);
|
|
57
|
-
});
|
|
58
|
-
it("returns recent events", () => {
|
|
59
|
-
const stats = createCompressionStatsCollector();
|
|
60
|
-
for (let i = 0; i < 5; i++) {
|
|
61
|
-
stats.record({
|
|
62
|
-
contentType: "generic",
|
|
63
|
-
originalTokens: 100,
|
|
64
|
-
compressedTokens: 50,
|
|
65
|
-
sectionsPreserved: 1,
|
|
66
|
-
sectionsOmitted: 1,
|
|
67
|
-
annotationsAdded: 0,
|
|
68
|
-
durationMs: 1,
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
expect(stats.getRecentEvents(3)).toHaveLength(3);
|
|
72
|
-
});
|
|
73
|
-
});
|
|
74
|
-
describe("Compression Quality Monitor (Q.13)", () => {
|
|
75
|
-
it("starts with default retention values", () => {
|
|
76
|
-
const monitor = createCompressionQualityMonitor();
|
|
77
|
-
expect(monitor.getRetention("git_diff")).toBeGreaterThanOrEqual(0.4);
|
|
78
|
-
expect(monitor.getRetention("test_output")).toBeGreaterThanOrEqual(0.4);
|
|
79
|
-
});
|
|
80
|
-
it("records compression events without error", () => {
|
|
81
|
-
const monitor = createCompressionQualityMonitor();
|
|
82
|
-
monitor.recordCompression("comp-1", "git_diff", 0.7);
|
|
83
|
-
expect(monitor.getSignalCount()).toBe(0);
|
|
84
|
-
});
|
|
85
|
-
it("detects over-compression when agent retries", () => {
|
|
86
|
-
const monitor = createCompressionQualityMonitor();
|
|
87
|
-
monitor.recordCompression("comp-1", "git_diff", 0.8);
|
|
88
|
-
monitor.recordAgentAction("entity-x", true, false);
|
|
89
|
-
expect(monitor.getSignalCount()).toBeGreaterThan(0);
|
|
90
|
-
});
|
|
91
|
-
it("increases retention after 3+ over-compression signals", () => {
|
|
92
|
-
const monitor = createCompressionQualityMonitor();
|
|
93
|
-
const initialRetention = monitor.getRetention("git_diff");
|
|
94
|
-
for (let i = 0; i < 4; i++) {
|
|
95
|
-
monitor.recordCompression(`comp-${i}`, "git_diff", 0.8);
|
|
96
|
-
monitor.recordAgentAction("entity-x", true, false);
|
|
97
|
-
}
|
|
98
|
-
const newRetention = monitor.getRetention("git_diff");
|
|
99
|
-
expect(newRetention).toBeGreaterThanOrEqual(initialRetention);
|
|
100
|
-
});
|
|
101
|
-
it("never drops below 40% hard floor", () => {
|
|
102
|
-
const monitor = createCompressionQualityMonitor();
|
|
103
|
-
const retention = monitor.getRetention("generic");
|
|
104
|
-
expect(retention).toBeGreaterThanOrEqual(0.4);
|
|
105
|
-
});
|
|
106
|
-
it("provides adaptive config with confidence", () => {
|
|
107
|
-
const monitor = createCompressionQualityMonitor();
|
|
108
|
-
const config = monitor.getAdaptiveConfig();
|
|
109
|
-
expect(config.minRetention).toBeDefined();
|
|
110
|
-
expect(config.adaptedRetention).toBeDefined();
|
|
111
|
-
expect(config.confidence).toBeGreaterThanOrEqual(0);
|
|
112
|
-
});
|
|
113
|
-
});
|
|
114
|
-
describe("Skills Pack (Q.11-Q.12)", () => {
|
|
115
|
-
it("has token-efficient skill", () => {
|
|
116
|
-
const skill = getSkill("token-efficient");
|
|
117
|
-
expect(skill).not.toBeNull();
|
|
118
|
-
expect(skill?.category).toBe("behavior");
|
|
119
|
-
expect(skill?.instructions).toContain("bullet points");
|
|
120
|
-
});
|
|
121
|
-
it("has graph-first navigation skill", () => {
|
|
122
|
-
const skill = getSkill("graph-first-navigation");
|
|
123
|
-
expect(skill).not.toBeNull();
|
|
124
|
-
expect(skill?.category).toBe("navigation");
|
|
125
|
-
expect(skill?.instructions).toContain("get_references");
|
|
126
|
-
expect(skill?.instructions).toContain("direction:callees");
|
|
127
|
-
expect(skill?.instructions).toContain("search_code");
|
|
128
|
-
});
|
|
129
|
-
it("getSkillsContext returns always-on skills", () => {
|
|
130
|
-
const context = getSkillsContext();
|
|
131
|
-
const skills = context["dev.unerr/active_skills"];
|
|
132
|
-
// Only always-on skills are injected into active context
|
|
133
|
-
expect(skills.length).toBe(5);
|
|
134
|
-
expect(skills.map((s) => s.id)).toContain("token-efficient");
|
|
135
|
-
expect(skills.map((s) => s.id)).toContain("graph-first-navigation");
|
|
136
|
-
expect(skills.map((s) => s.id)).toContain("understand-before-modify");
|
|
137
|
-
expect(skills.map((s) => s.id)).toContain("file-read-protocol");
|
|
138
|
-
expect(skills.map((s) => s.id)).toContain("turn-discipline");
|
|
139
|
-
});
|
|
140
|
-
it("LOCAL_SKILLS has correct count", () => {
|
|
141
|
-
expect(LOCAL_SKILLS).toHaveLength(12);
|
|
142
|
-
});
|
|
143
|
-
});
|
|
144
|
-
describe("Compression + Budget Pipeline (Q.7)", () => {
|
|
145
|
-
it("compresses first, then enforces budget", () => {
|
|
146
|
-
const largeInput = Array.from({ length: 200 }, (_, i) => `Line ${i}: some content that takes up space in the output`).join("\n");
|
|
147
|
-
const compressed = compressOutput(largeInput, { tokenBudget: 500 });
|
|
148
|
-
const enforced = enforceBudget(compressed.output, 300);
|
|
149
|
-
expect(enforced.deliveredTokens).toBeLessThanOrEqual(enforced.originalTokens);
|
|
150
|
-
});
|
|
151
|
-
});
|
|
152
|
-
describe("Performance (Q.10)", () => {
|
|
153
|
-
it("100KB input compressed in <10ms", () => {
|
|
154
|
-
const bigInput = "x".repeat(100 * 1024);
|
|
155
|
-
const start = performance.now();
|
|
156
|
-
compressOutput(bigInput, { tokenBudget: 2000 });
|
|
157
|
-
const elapsed = performance.now() - start;
|
|
158
|
-
expect(elapsed).toBeLessThan(10);
|
|
159
|
-
});
|
|
160
|
-
});
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Layer 3 Sprint R: CLI Hooks & Auto-Configuration tests.
|
|
3
|
-
*/
|
|
4
|
-
import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync, } from "node:fs";
|
|
5
|
-
import { tmpdir } from "node:os";
|
|
6
|
-
import { join } from "node:path";
|
|
7
|
-
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
|
8
|
-
import { installClaudeHook, isClaudeHookInstalled, removeClaudeHook, } from "../config/hook-installer.js";
|
|
9
|
-
import { isConfigured, removeMcpConfig, writeMcpConfig, } from "../config/mcp-config-writer.js";
|
|
10
|
-
let tempDir;
|
|
11
|
-
beforeEach(() => {
|
|
12
|
-
tempDir = join(tmpdir(), `unerr-r-${Date.now()}-${Math.random().toString(36).slice(2)}`);
|
|
13
|
-
mkdirSync(tempDir, { recursive: true });
|
|
14
|
-
});
|
|
15
|
-
afterEach(() => {
|
|
16
|
-
rmSync(tempDir, { recursive: true, force: true });
|
|
17
|
-
});
|
|
18
|
-
describe("MCP Config Writer (R.3 + R.7)", () => {
|
|
19
|
-
it("creates config for Cursor", () => {
|
|
20
|
-
const result = writeMcpConfig(tempDir, "cursor");
|
|
21
|
-
expect(result.action).toBe("created");
|
|
22
|
-
expect(existsSync(result.path)).toBe(true);
|
|
23
|
-
const config = JSON.parse(readFileSync(result.path, "utf-8"));
|
|
24
|
-
expect(config.mcpServers.unerr).toBeDefined();
|
|
25
|
-
expect(config.mcpServers.unerr.command).toBe("unerr");
|
|
26
|
-
});
|
|
27
|
-
it("creates config for Claude Code", () => {
|
|
28
|
-
const result = writeMcpConfig(tempDir, "claude-code");
|
|
29
|
-
expect(result.action).toBe("created");
|
|
30
|
-
expect(result.path).toContain(".mcp.json");
|
|
31
|
-
});
|
|
32
|
-
it("creates config for VS Code", () => {
|
|
33
|
-
const result = writeMcpConfig(tempDir, "vscode");
|
|
34
|
-
expect(result.action).toBe("created");
|
|
35
|
-
expect(result.path).toContain(".vscode");
|
|
36
|
-
});
|
|
37
|
-
it("is idempotent (skip on second run)", () => {
|
|
38
|
-
writeMcpConfig(tempDir, "cursor");
|
|
39
|
-
const result = writeMcpConfig(tempDir, "cursor");
|
|
40
|
-
expect(result.action).toBe("skipped");
|
|
41
|
-
});
|
|
42
|
-
it("merges into existing config without overwriting", () => {
|
|
43
|
-
const configPath = join(tempDir, ".cursor", "mcp.json");
|
|
44
|
-
mkdirSync(join(tempDir, ".cursor"), { recursive: true });
|
|
45
|
-
writeFileSync(configPath, JSON.stringify({
|
|
46
|
-
mcpServers: { "other-tool": { command: "other", args: [] } },
|
|
47
|
-
}), "utf-8");
|
|
48
|
-
const result = writeMcpConfig(tempDir, "cursor");
|
|
49
|
-
expect(result.action).toBe("updated");
|
|
50
|
-
const config = JSON.parse(readFileSync(configPath, "utf-8"));
|
|
51
|
-
expect(config.mcpServers["other-tool"]).toBeDefined();
|
|
52
|
-
expect(config.mcpServers.unerr).toBeDefined();
|
|
53
|
-
});
|
|
54
|
-
it("isConfigured returns correct state", () => {
|
|
55
|
-
expect(isConfigured(tempDir, "cursor")).toBe(false);
|
|
56
|
-
writeMcpConfig(tempDir, "cursor");
|
|
57
|
-
expect(isConfigured(tempDir, "cursor")).toBe(true);
|
|
58
|
-
});
|
|
59
|
-
it("removeMcpConfig removes unerr entry", () => {
|
|
60
|
-
writeMcpConfig(tempDir, "cursor");
|
|
61
|
-
const removed = removeMcpConfig(tempDir, "cursor");
|
|
62
|
-
expect(removed).toBe(true);
|
|
63
|
-
expect(isConfigured(tempDir, "cursor")).toBe(false);
|
|
64
|
-
});
|
|
65
|
-
});
|
|
66
|
-
describe("Hook Installer (R.4)", () => {
|
|
67
|
-
it("installs Claude hook with correct permissions", () => {
|
|
68
|
-
const result = installClaudeHook(tempDir);
|
|
69
|
-
expect(result.action).toBe("installed");
|
|
70
|
-
expect(existsSync(result.path)).toBe(true);
|
|
71
|
-
const content = readFileSync(result.path, "utf-8");
|
|
72
|
-
expect(content).toContain("#!/bin/bash");
|
|
73
|
-
expect(content).toContain("compress-output");
|
|
74
|
-
});
|
|
75
|
-
it("reports already_exists on second install", () => {
|
|
76
|
-
installClaudeHook(tempDir);
|
|
77
|
-
const result = installClaudeHook(tempDir);
|
|
78
|
-
expect(result.action).toBe("already_exists");
|
|
79
|
-
});
|
|
80
|
-
it("isClaudeHookInstalled returns correct state", () => {
|
|
81
|
-
expect(isClaudeHookInstalled(tempDir)).toBe(false);
|
|
82
|
-
installClaudeHook(tempDir);
|
|
83
|
-
expect(isClaudeHookInstalled(tempDir)).toBe(true);
|
|
84
|
-
});
|
|
85
|
-
it("removeClaudeHook removes the hook", () => {
|
|
86
|
-
installClaudeHook(tempDir);
|
|
87
|
-
const removed = removeClaudeHook(tempDir);
|
|
88
|
-
expect(removed).toBe(true);
|
|
89
|
-
expect(isClaudeHookInstalled(tempDir)).toBe(false);
|
|
90
|
-
});
|
|
91
|
-
});
|
|
@@ -1,183 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Layer 3 Sprint S: Proactive Injection & Session Intelligence tests.
|
|
3
|
-
*/
|
|
4
|
-
import { describe, expect, it } from "vitest";
|
|
5
|
-
import { suggestApproach, suggestApproachesForFile, } from "../intelligence/approach-suggester.js";
|
|
6
|
-
import { createSessionContext } from "../intelligence/exploration-pattern-tracker.js";
|
|
7
|
-
import { assembleFileIntelligence } from "../intelligence/file-intelligence.js";
|
|
8
|
-
import { createSubgraphCache } from "../intelligence/subgraph-cache.js";
|
|
9
|
-
describe("File Intelligence (S.1)", () => {
|
|
10
|
-
it("assembles intelligence for a file", () => {
|
|
11
|
-
const entities = [
|
|
12
|
-
{
|
|
13
|
-
key: "k1",
|
|
14
|
-
name: "processPayment",
|
|
15
|
-
kind: "function",
|
|
16
|
-
file_path: "src/pay.ts",
|
|
17
|
-
risk_level: "high",
|
|
18
|
-
fan_in: 25,
|
|
19
|
-
community: 1,
|
|
20
|
-
},
|
|
21
|
-
{
|
|
22
|
-
key: "k2",
|
|
23
|
-
name: "validateCard",
|
|
24
|
-
kind: "function",
|
|
25
|
-
file_path: "src/pay.ts",
|
|
26
|
-
risk_level: "normal",
|
|
27
|
-
fan_in: 5,
|
|
28
|
-
community: 1,
|
|
29
|
-
},
|
|
30
|
-
{
|
|
31
|
-
key: "k3",
|
|
32
|
-
name: "logError",
|
|
33
|
-
kind: "function",
|
|
34
|
-
file_path: "src/utils.ts",
|
|
35
|
-
risk_level: "normal",
|
|
36
|
-
fan_in: 2,
|
|
37
|
-
community: 0,
|
|
38
|
-
},
|
|
39
|
-
];
|
|
40
|
-
const intel = assembleFileIntelligence("src/pay.ts", entities);
|
|
41
|
-
expect(intel.entityCount).toBe(2);
|
|
42
|
-
expect(intel.topRiskEntities).toHaveLength(1);
|
|
43
|
-
expect(intel.topRiskEntities[0]?.name).toBe("processPayment");
|
|
44
|
-
expect(intel.totalBlastRadius).toBe(30);
|
|
45
|
-
expect(intel.dominantCommunity).toBe(1);
|
|
46
|
-
expect(intel.fileRiskLevel).toBe("high");
|
|
47
|
-
});
|
|
48
|
-
it("handles file with no entities", () => {
|
|
49
|
-
const intel = assembleFileIntelligence("empty.ts", []);
|
|
50
|
-
expect(intel.entityCount).toBe(0);
|
|
51
|
-
expect(intel.fileRiskLevel).toBe("normal");
|
|
52
|
-
expect(intel.totalBlastRadius).toBe(0);
|
|
53
|
-
});
|
|
54
|
-
it("ranks entities by fan_in", () => {
|
|
55
|
-
const entities = [
|
|
56
|
-
{ key: "a", name: "low", kind: "function", file_path: "f.ts", fan_in: 2 },
|
|
57
|
-
{
|
|
58
|
-
key: "b",
|
|
59
|
-
name: "high",
|
|
60
|
-
kind: "function",
|
|
61
|
-
file_path: "f.ts",
|
|
62
|
-
fan_in: 50,
|
|
63
|
-
},
|
|
64
|
-
{
|
|
65
|
-
key: "c",
|
|
66
|
-
name: "mid",
|
|
67
|
-
kind: "function",
|
|
68
|
-
file_path: "f.ts",
|
|
69
|
-
fan_in: 15,
|
|
70
|
-
},
|
|
71
|
-
];
|
|
72
|
-
const intel = assembleFileIntelligence("f.ts", entities);
|
|
73
|
-
expect(intel.entities[0]?.name).toBe("high");
|
|
74
|
-
expect(intel.entities[1]?.name).toBe("mid");
|
|
75
|
-
});
|
|
76
|
-
});
|
|
77
|
-
describe("Subgraph Cache (S.3)", () => {
|
|
78
|
-
it("warms directory on first access", () => {
|
|
79
|
-
const cache = createSubgraphCache();
|
|
80
|
-
cache.warmDirectory("src/auth", ["src/auth/login.ts", "src/auth/logout.ts"], (f) => ({ file: f }));
|
|
81
|
-
expect(cache.has("src/auth/login.ts")).toBe(true);
|
|
82
|
-
expect(cache.has("src/auth/logout.ts")).toBe(true);
|
|
83
|
-
expect(cache.size()).toBe(2);
|
|
84
|
-
});
|
|
85
|
-
it("skips already-warmed directories", () => {
|
|
86
|
-
const cache = createSubgraphCache();
|
|
87
|
-
let loadCount = 0;
|
|
88
|
-
const loader = (f) => {
|
|
89
|
-
loadCount++;
|
|
90
|
-
return f;
|
|
91
|
-
};
|
|
92
|
-
cache.warmDirectory("src/auth", ["src/auth/a.ts"], loader);
|
|
93
|
-
cache.warmDirectory("src/auth", ["src/auth/b.ts"], loader);
|
|
94
|
-
expect(loadCount).toBe(1);
|
|
95
|
-
});
|
|
96
|
-
it("invalidates directory entries", () => {
|
|
97
|
-
const cache = createSubgraphCache();
|
|
98
|
-
cache.warmDirectory("src/auth", ["src/auth/a.ts", "src/auth/b.ts"], (f) => f);
|
|
99
|
-
cache.invalidateDirectory("src/auth");
|
|
100
|
-
expect(cache.has("src/auth/a.ts")).toBe(false);
|
|
101
|
-
});
|
|
102
|
-
it("respects TTL", () => {
|
|
103
|
-
const cache = createSubgraphCache();
|
|
104
|
-
cache.warmDirectory("src/x", ["src/x/a.ts"], (f) => f);
|
|
105
|
-
expect(cache.get("src/x/a.ts")).not.toBeNull();
|
|
106
|
-
});
|
|
107
|
-
});
|
|
108
|
-
describe("Approach Suggestions (S.4)", () => {
|
|
109
|
-
it("suggests overload for critical fan_in", () => {
|
|
110
|
-
const suggestion = suggestApproach("k1", "processPayment", "critical", 55, "function");
|
|
111
|
-
expect(suggestion).not.toBeNull();
|
|
112
|
-
expect(suggestion?.pattern).toBe("overload-adapter");
|
|
113
|
-
expect(suggestion?.suggestion).toContain("55 callers");
|
|
114
|
-
});
|
|
115
|
-
it("suggests feature flag for high fan_in", () => {
|
|
116
|
-
const suggestion = suggestApproach("k2", "validateInput", "high", 35, "function");
|
|
117
|
-
expect(suggestion).not.toBeNull();
|
|
118
|
-
expect(suggestion?.pattern).toBe("feature-flag");
|
|
119
|
-
});
|
|
120
|
-
it("suggests test-first for high risk without extreme fan_in", () => {
|
|
121
|
-
const suggestion = suggestApproach("k3", "helperFn", "high", 10, "function");
|
|
122
|
-
expect(suggestion).not.toBeNull();
|
|
123
|
-
expect(suggestion?.pattern).toBe("test-first");
|
|
124
|
-
});
|
|
125
|
-
it("returns null for low-risk entities", () => {
|
|
126
|
-
expect(suggestApproach("k4", "simpleUtil", "normal", 3, "function")).toBeNull();
|
|
127
|
-
});
|
|
128
|
-
it("generates suggestions for file", () => {
|
|
129
|
-
const entities = [
|
|
130
|
-
{
|
|
131
|
-
key: "k1",
|
|
132
|
-
name: "hub",
|
|
133
|
-
risk_level: "critical",
|
|
134
|
-
fan_in: 60,
|
|
135
|
-
kind: "function",
|
|
136
|
-
},
|
|
137
|
-
{
|
|
138
|
-
key: "k2",
|
|
139
|
-
name: "simple",
|
|
140
|
-
risk_level: "normal",
|
|
141
|
-
fan_in: 2,
|
|
142
|
-
kind: "function",
|
|
143
|
-
},
|
|
144
|
-
];
|
|
145
|
-
const suggestions = suggestApproachesForFile(entities);
|
|
146
|
-
expect(suggestions).toHaveLength(1);
|
|
147
|
-
expect(suggestions[0]?.entityName).toBe("hub");
|
|
148
|
-
});
|
|
149
|
-
});
|
|
150
|
-
describe("Session Context (S.5)", () => {
|
|
151
|
-
it("tracks exploration patterns", () => {
|
|
152
|
-
const ctx = createSessionContext();
|
|
153
|
-
ctx.recordQuery("src/auth/login.ts", "k1");
|
|
154
|
-
ctx.recordQuery("src/auth/logout.ts", "k2");
|
|
155
|
-
ctx.recordQuery("src/auth/validate.ts");
|
|
156
|
-
const pattern = ctx.getPattern();
|
|
157
|
-
expect(pattern.queryCount).toBe(3);
|
|
158
|
-
expect(pattern.directories.get("src/auth")).toBe(3);
|
|
159
|
-
});
|
|
160
|
-
it("detects active directory", () => {
|
|
161
|
-
const ctx = createSessionContext();
|
|
162
|
-
ctx.recordQuery("src/auth/a.ts");
|
|
163
|
-
ctx.recordQuery("src/auth/b.ts");
|
|
164
|
-
ctx.recordQuery("src/payments/c.ts");
|
|
165
|
-
ctx.recordQuery("src/auth/d.ts");
|
|
166
|
-
expect(ctx.getActiveDirectory()).toBe("src/auth");
|
|
167
|
-
});
|
|
168
|
-
it("predicts next files from active directory", () => {
|
|
169
|
-
const ctx = createSessionContext();
|
|
170
|
-
ctx.recordQuery("src/auth/login.ts");
|
|
171
|
-
ctx.recordQuery("src/auth/logout.ts");
|
|
172
|
-
ctx.recordQuery("src/auth/validate.ts");
|
|
173
|
-
const predicted = ctx.predictNextFiles(3);
|
|
174
|
-
expect(predicted.length).toBeGreaterThan(0);
|
|
175
|
-
expect(predicted.every((f) => f.startsWith("src/auth"))).toBe(true);
|
|
176
|
-
});
|
|
177
|
-
it("resets cleanly", () => {
|
|
178
|
-
const ctx = createSessionContext();
|
|
179
|
-
ctx.recordQuery("src/a.ts");
|
|
180
|
-
ctx.reset();
|
|
181
|
-
expect(ctx.getPattern().queryCount).toBe(0);
|
|
182
|
-
});
|
|
183
|
-
});
|
|
@@ -1,201 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Layer 3 Sprint T: Token Accounting & Visibility tests.
|
|
3
|
-
*/
|
|
4
|
-
import { mkdirSync, rmSync } from "node:fs";
|
|
5
|
-
import { tmpdir } from "node:os";
|
|
6
|
-
import { join } from "node:path";
|
|
7
|
-
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
|
8
|
-
import { calculateDollarSavings, formatDollars, formatSavingsSummary, getAllModelRates, getModelRate, } from "../proxy/model-pricing.js";
|
|
9
|
-
import { buildTaskCostSummaries } from "../proxy/task-token-display.js";
|
|
10
|
-
import { aggregateStats, appendSessionHistory, getWeeklyStats, readSessionHistory, } from "../tracking/session-history.js";
|
|
11
|
-
let tempDir;
|
|
12
|
-
beforeEach(() => {
|
|
13
|
-
tempDir = join(tmpdir(), `unerr-t-${Date.now()}`);
|
|
14
|
-
mkdirSync(tempDir, { recursive: true });
|
|
15
|
-
});
|
|
16
|
-
afterEach(() => {
|
|
17
|
-
rmSync(tempDir, { recursive: true, force: true });
|
|
18
|
-
});
|
|
19
|
-
describe("Model Pricing (T.2-T.3)", () => {
|
|
20
|
-
it("returns Claude Sonnet rate by default", () => {
|
|
21
|
-
const rate = getModelRate();
|
|
22
|
-
expect(rate.inputPerMillion).toBe(3);
|
|
23
|
-
expect(rate.name).toBe("Claude Sonnet 4");
|
|
24
|
-
});
|
|
25
|
-
it("returns correct rates for known models", () => {
|
|
26
|
-
expect(getModelRate("gpt-4o").inputPerMillion).toBe(2.5);
|
|
27
|
-
expect(getModelRate("ollama").inputPerMillion).toBe(0);
|
|
28
|
-
});
|
|
29
|
-
it("falls back to default for unknown models", () => {
|
|
30
|
-
const rate = getModelRate("unknown-model");
|
|
31
|
-
expect(rate.inputPerMillion).toBe(3);
|
|
32
|
-
});
|
|
33
|
-
it("calculates dollar savings correctly", () => {
|
|
34
|
-
const savings = calculateDollarSavings(1_000_000, "claude-sonnet-4-20250514");
|
|
35
|
-
expect(savings).toBe(3.0);
|
|
36
|
-
});
|
|
37
|
-
it("calculates zero savings for Ollama", () => {
|
|
38
|
-
expect(calculateDollarSavings(1_000_000, "ollama")).toBe(0);
|
|
39
|
-
});
|
|
40
|
-
it("formats dollars correctly", () => {
|
|
41
|
-
expect(formatDollars(1.5)).toBe("$1.50");
|
|
42
|
-
expect(formatDollars(0.27)).toBe("$0.27");
|
|
43
|
-
expect(formatDollars(0.003)).toBe("$0.003");
|
|
44
|
-
});
|
|
45
|
-
it("formats complete savings summary", () => {
|
|
46
|
-
const summary = formatSavingsSummary(45200);
|
|
47
|
-
expect(summary).toContain("45.2K");
|
|
48
|
-
expect(summary).toContain("$");
|
|
49
|
-
expect(summary).toContain("Claude Sonnet");
|
|
50
|
-
});
|
|
51
|
-
it("lists all supported models", () => {
|
|
52
|
-
const rates = getAllModelRates();
|
|
53
|
-
expect(rates.length).toBeGreaterThanOrEqual(7);
|
|
54
|
-
});
|
|
55
|
-
});
|
|
56
|
-
describe("Session History (T.8)", () => {
|
|
57
|
-
it("appends and reads session entries", () => {
|
|
58
|
-
const entry = {
|
|
59
|
-
sessionId: "s1",
|
|
60
|
-
startedAt: new Date().toISOString(),
|
|
61
|
-
endedAt: new Date().toISOString(),
|
|
62
|
-
durationMs: 60000,
|
|
63
|
-
toolCalls: 47,
|
|
64
|
-
tokensSaved: 23400,
|
|
65
|
-
tokensProcessed: 35000,
|
|
66
|
-
efficiency: 67,
|
|
67
|
-
dollarsSaved: 0.07,
|
|
68
|
-
modelId: "claude-sonnet-4-20250514",
|
|
69
|
-
entityCount: 847,
|
|
70
|
-
};
|
|
71
|
-
appendSessionHistory(tempDir, entry);
|
|
72
|
-
const history = readSessionHistory(tempDir);
|
|
73
|
-
expect(history).toHaveLength(1);
|
|
74
|
-
expect(history[0]?.sessionId).toBe("s1");
|
|
75
|
-
expect(history[0]?.tokensSaved).toBe(23400);
|
|
76
|
-
});
|
|
77
|
-
it("handles missing history file", () => {
|
|
78
|
-
expect(readSessionHistory(tempDir)).toHaveLength(0);
|
|
79
|
-
});
|
|
80
|
-
it("aggregates stats correctly", () => {
|
|
81
|
-
const entries = [
|
|
82
|
-
{
|
|
83
|
-
sessionId: "s1",
|
|
84
|
-
startedAt: new Date().toISOString(),
|
|
85
|
-
endedAt: new Date().toISOString(),
|
|
86
|
-
durationMs: 60000,
|
|
87
|
-
toolCalls: 40,
|
|
88
|
-
tokensSaved: 20000,
|
|
89
|
-
tokensProcessed: 30000,
|
|
90
|
-
efficiency: 67,
|
|
91
|
-
dollarsSaved: 0.06,
|
|
92
|
-
modelId: "claude-sonnet-4-20250514",
|
|
93
|
-
entityCount: 500,
|
|
94
|
-
},
|
|
95
|
-
{
|
|
96
|
-
sessionId: "s2",
|
|
97
|
-
startedAt: new Date().toISOString(),
|
|
98
|
-
endedAt: new Date().toISOString(),
|
|
99
|
-
durationMs: 120000,
|
|
100
|
-
toolCalls: 80,
|
|
101
|
-
tokensSaved: 40000,
|
|
102
|
-
tokensProcessed: 60000,
|
|
103
|
-
efficiency: 67,
|
|
104
|
-
dollarsSaved: 0.12,
|
|
105
|
-
modelId: "claude-sonnet-4-20250514",
|
|
106
|
-
entityCount: 500,
|
|
107
|
-
},
|
|
108
|
-
];
|
|
109
|
-
const stats = aggregateStats(entries, "Test");
|
|
110
|
-
expect(stats.sessions).toBe(2);
|
|
111
|
-
expect(stats.tokensSaved).toBe(60000);
|
|
112
|
-
expect(stats.totalToolCalls).toBe(120);
|
|
113
|
-
expect(stats.avgEfficiency).toBe(67);
|
|
114
|
-
});
|
|
115
|
-
it("getWeeklyStats returns empty for fresh dir", () => {
|
|
116
|
-
const stats = getWeeklyStats(tempDir);
|
|
117
|
-
expect(stats.sessions).toBe(0);
|
|
118
|
-
});
|
|
119
|
-
});
|
|
120
|
-
describe("Task Token Display (T.12)", () => {
|
|
121
|
-
it("builds task cost summaries from intent groups", () => {
|
|
122
|
-
const groups = [
|
|
123
|
-
{
|
|
124
|
-
intentId: "i1",
|
|
125
|
-
prompt: "Add currency param",
|
|
126
|
-
toolCalls: 12,
|
|
127
|
-
tokensConsumed: 5000,
|
|
128
|
-
tokensSaved: 12000,
|
|
129
|
-
entitiesModified: ["processPayment"],
|
|
130
|
-
outcome: "completed",
|
|
131
|
-
},
|
|
132
|
-
{
|
|
133
|
-
intentId: "i2",
|
|
134
|
-
prompt: "Fix auth tests",
|
|
135
|
-
toolCalls: 8,
|
|
136
|
-
tokensConsumed: 3000,
|
|
137
|
-
tokensSaved: 6000,
|
|
138
|
-
entitiesModified: ["authService"],
|
|
139
|
-
outcome: "completed",
|
|
140
|
-
},
|
|
141
|
-
{
|
|
142
|
-
intentId: "i3",
|
|
143
|
-
prompt: "Update README",
|
|
144
|
-
toolCalls: 3,
|
|
145
|
-
tokensConsumed: 800,
|
|
146
|
-
tokensSaved: 400,
|
|
147
|
-
entitiesModified: [],
|
|
148
|
-
outcome: "completed",
|
|
149
|
-
},
|
|
150
|
-
];
|
|
151
|
-
const result = buildTaskCostSummaries(groups);
|
|
152
|
-
expect(result.tasks).toHaveLength(3);
|
|
153
|
-
expect(result.totalCalls).toBe(23);
|
|
154
|
-
expect(result.formattedLines.length).toBeGreaterThan(0);
|
|
155
|
-
expect(result.formattedLines[0]).toContain("Tasks this session");
|
|
156
|
-
});
|
|
157
|
-
it("sorts by most expensive first", () => {
|
|
158
|
-
const groups = [
|
|
159
|
-
{
|
|
160
|
-
intentId: "i1",
|
|
161
|
-
prompt: "Cheap",
|
|
162
|
-
toolCalls: 2,
|
|
163
|
-
tokensConsumed: 100,
|
|
164
|
-
tokensSaved: 50,
|
|
165
|
-
entitiesModified: [],
|
|
166
|
-
outcome: "completed",
|
|
167
|
-
},
|
|
168
|
-
{
|
|
169
|
-
intentId: "i2",
|
|
170
|
-
prompt: "Expensive",
|
|
171
|
-
toolCalls: 20,
|
|
172
|
-
tokensConsumed: 50000,
|
|
173
|
-
tokensSaved: 30000,
|
|
174
|
-
entitiesModified: [],
|
|
175
|
-
outcome: "completed",
|
|
176
|
-
},
|
|
177
|
-
];
|
|
178
|
-
const result = buildTaskCostSummaries(groups);
|
|
179
|
-
expect(result.tasks[0]?.taskDescription).toBe("Expensive");
|
|
180
|
-
});
|
|
181
|
-
it("computes efficiency correctly", () => {
|
|
182
|
-
const groups = [
|
|
183
|
-
{
|
|
184
|
-
intentId: "i1",
|
|
185
|
-
prompt: "Task",
|
|
186
|
-
toolCalls: 5,
|
|
187
|
-
tokensConsumed: 3000,
|
|
188
|
-
tokensSaved: 7000,
|
|
189
|
-
entitiesModified: [],
|
|
190
|
-
outcome: "completed",
|
|
191
|
-
},
|
|
192
|
-
];
|
|
193
|
-
const result = buildTaskCostSummaries(groups);
|
|
194
|
-
expect(result.tasks[0]?.efficiency).toBe(70);
|
|
195
|
-
});
|
|
196
|
-
it("handles empty groups", () => {
|
|
197
|
-
const result = buildTaskCostSummaries([]);
|
|
198
|
-
expect(result.tasks).toHaveLength(0);
|
|
199
|
-
expect(result.totalCalls).toBe(0);
|
|
200
|
-
});
|
|
201
|
-
});
|