@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.
Files changed (218) hide show
  1. package/README.md +70 -194
  2. package/dist/cli.js +39149 -36991
  3. package/package.json +9 -2
  4. package/dist/__tests__/architecture-guard.test.js +0 -122
  5. package/dist/__tests__/arg-validator.test.js +0 -205
  6. package/dist/__tests__/ast-extractor.test.js +0 -203
  7. package/dist/__tests__/auto-bootstrap.test.js +0 -280
  8. package/dist/__tests__/background-indexer.test.js +0 -228
  9. package/dist/__tests__/blast-radius-engine.test.js +0 -200
  10. package/dist/__tests__/bridge-isolation.test.js +0 -37
  11. package/dist/__tests__/budget-enforcer.test.js +0 -53
  12. package/dist/__tests__/cfg-test-detection-perf.test.js +0 -82
  13. package/dist/__tests__/change-narrative.test.js +0 -190
  14. package/dist/__tests__/check-commit.test.js +0 -258
  15. package/dist/__tests__/checksum.test.js +0 -34
  16. package/dist/__tests__/commit-watcher.test.js +0 -154
  17. package/dist/__tests__/community-detection.test.js +0 -179
  18. package/dist/__tests__/community-tools.test.js +0 -299
  19. package/dist/__tests__/components.test.js +0 -449
  20. package/dist/__tests__/compression-log.test.js +0 -174
  21. package/dist/__tests__/compression-quality-monitor.test.js +0 -40
  22. package/dist/__tests__/config-healer.test.js +0 -165
  23. package/dist/__tests__/context-ledger.test.js +0 -58
  24. package/dist/__tests__/convention-detector.test.js +0 -99
  25. package/dist/__tests__/convention-learner.test.js +0 -86
  26. package/dist/__tests__/correction-detector.test.js +0 -330
  27. package/dist/__tests__/daemon-autostart-install.test.js +0 -283
  28. package/dist/__tests__/daemon-bridge.test.js +0 -222
  29. package/dist/__tests__/daemon-dashboard.test.js +0 -202
  30. package/dist/__tests__/daemon-registry.test.js +0 -240
  31. package/dist/__tests__/daemon-supervisor.test.js +0 -318
  32. package/dist/__tests__/daemon-version-check.test.js +0 -275
  33. package/dist/__tests__/decision-point-detector.test.js +0 -98
  34. package/dist/__tests__/deep-link.test.js +0 -143
  35. package/dist/__tests__/disallowed-tools.test.js +0 -115
  36. package/dist/__tests__/drift-tracker.test.js +0 -582
  37. package/dist/__tests__/durability-scorer.test.js +0 -152
  38. package/dist/__tests__/efficiency-tracker.test.js +0 -65
  39. package/dist/__tests__/enrich.test.js +0 -144
  40. package/dist/__tests__/entity-rewind.test.js +0 -248
  41. package/dist/__tests__/ephemeral.test.js +0 -111
  42. package/dist/__tests__/exploration-cost.test.js +0 -93
  43. package/dist/__tests__/fact-generator.test.js +0 -197
  44. package/dist/__tests__/file-l0-graph.test.js +0 -244
  45. package/dist/__tests__/file-logger.test.js +0 -82
  46. package/dist/__tests__/file-outline.test.js +0 -141
  47. package/dist/__tests__/file-read-protocol.test.js +0 -188
  48. package/dist/__tests__/format-encoder.test.js +0 -233
  49. package/dist/__tests__/git-attribution.test.js +0 -259
  50. package/dist/__tests__/graph-temporal-joiner.test.js +0 -219
  51. package/dist/__tests__/health-grade-enhanced.test.js +0 -138
  52. package/dist/__tests__/health-map-data.test.js +0 -173
  53. package/dist/__tests__/helpers/mcp-harness.js +0 -45
  54. package/dist/__tests__/helpers/mcp-harness.test.js +0 -68
  55. package/dist/__tests__/hook-dedup.test.js +0 -112
  56. package/dist/__tests__/hook-runner.test.js +0 -253
  57. package/dist/__tests__/indexer-cfg.test.js +0 -185
  58. package/dist/__tests__/indexer-cross-file.test.js +0 -172
  59. package/dist/__tests__/indexer-extraction.test.js +0 -245
  60. package/dist/__tests__/indexer-incremental.test.js +0 -232
  61. package/dist/__tests__/indexer-language-expansion.test.js +0 -165
  62. package/dist/__tests__/init-push.test.js +0 -131
  63. package/dist/__tests__/instruction-writer.test.js +0 -179
  64. package/dist/__tests__/intelligence-integration.test.js +0 -217
  65. package/dist/__tests__/intent-correlator.test.js +0 -175
  66. package/dist/__tests__/intent-detector.test.js +0 -235
  67. package/dist/__tests__/intent-encoder.test.js +0 -167
  68. package/dist/__tests__/java-build-tool-detection.test.js +0 -174
  69. package/dist/__tests__/layer3-sprint-q.test.js +0 -160
  70. package/dist/__tests__/layer3-sprint-r.test.js +0 -91
  71. package/dist/__tests__/layer3-sprint-s.test.js +0 -183
  72. package/dist/__tests__/layer3-sprint-t.test.js +0 -201
  73. package/dist/__tests__/layer3-sprint-u.test.js +0 -174
  74. package/dist/__tests__/layer4-sprint-ba2.test.js +0 -354
  75. package/dist/__tests__/layer4-sprint-ba4.test.js +0 -84
  76. package/dist/__tests__/layer4-sprint-vs.test.js +0 -105
  77. package/dist/__tests__/ledger-chains.test.js +0 -162
  78. package/dist/__tests__/lifecycle-machine.test.js +0 -226
  79. package/dist/__tests__/local-chat-provider.test.js +0 -170
  80. package/dist/__tests__/local-convention-detector.test.js +0 -308
  81. package/dist/__tests__/local-embeddings.test.js +0 -422
  82. package/dist/__tests__/local-graph.test.js +0 -540
  83. package/dist/__tests__/local-indexer.test.js +0 -228
  84. package/dist/__tests__/local-intelligence-l3.test.js +0 -332
  85. package/dist/__tests__/local-llm.test.js +0 -253
  86. package/dist/__tests__/local-mode-offline.test.js +0 -187
  87. package/dist/__tests__/local-mode-stats.test.js +0 -273
  88. package/dist/__tests__/local-mode-tui.test.js +0 -343
  89. package/dist/__tests__/local-parse.test.js +0 -199
  90. package/dist/__tests__/log-tailer.test.js +0 -208
  91. package/dist/__tests__/loop-breaker.test.js +0 -276
  92. package/dist/__tests__/loop-miner.test.js +0 -226
  93. package/dist/__tests__/mcp-config.test.js +0 -126
  94. package/dist/__tests__/mcp-content-json.test.js +0 -10
  95. package/dist/__tests__/mcp-envelope.test.js +0 -124
  96. package/dist/__tests__/metrics-store.test.js +0 -223
  97. package/dist/__tests__/native-watcher.test.js +0 -191
  98. package/dist/__tests__/navigation-hooks-agent-aware.test.js +0 -145
  99. package/dist/__tests__/negative-knowledge.test.js +0 -116
  100. package/dist/__tests__/network-boundary.test.js +0 -190
  101. package/dist/__tests__/network-firewall.test.js +0 -112
  102. package/dist/__tests__/nudge-invariants.test.js +0 -160
  103. package/dist/__tests__/nudge-v2.test.js +0 -225
  104. package/dist/__tests__/offline-rewind.test.js +0 -251
  105. package/dist/__tests__/open-threads.test.js +0 -89
  106. package/dist/__tests__/output-compressor.test.js +0 -93
  107. package/dist/__tests__/pending-violations.test.js +0 -112
  108. package/dist/__tests__/persistence-effectiveness.test.js +0 -143
  109. package/dist/__tests__/provider-factory.test.js +0 -42
  110. package/dist/__tests__/providers.test.js +0 -24
  111. package/dist/__tests__/proxy.test.js +0 -314
  112. package/dist/__tests__/query-router.test.js +0 -1018
  113. package/dist/__tests__/reasoning-quality-route.test.js +0 -138
  114. package/dist/__tests__/redactor.test.js +0 -120
  115. package/dist/__tests__/resource-monitor.test.js +0 -57
  116. package/dist/__tests__/response-envelope.test.js +0 -100
  117. package/dist/__tests__/risk-classifier.test.js +0 -101
  118. package/dist/__tests__/risk-signal-scope.test.js +0 -75
  119. package/dist/__tests__/rule-evaluator.test.js +0 -280
  120. package/dist/__tests__/scip-decoder.test.js +0 -49
  121. package/dist/__tests__/scip-downloader.test.js +0 -201
  122. package/dist/__tests__/scip-merger.test.js +0 -103
  123. package/dist/__tests__/search-index.test.js +0 -422
  124. package/dist/__tests__/semantic-enrichment.test.js +0 -360
  125. package/dist/__tests__/session-brief-builder.test.js +0 -187
  126. package/dist/__tests__/session-context.test.js +0 -221
  127. package/dist/__tests__/session-continuity.test.js +0 -144
  128. package/dist/__tests__/session-dedup.test.js +0 -74
  129. package/dist/__tests__/session-event-wiring.test.js +0 -206
  130. package/dist/__tests__/session-events.test.js +0 -149
  131. package/dist/__tests__/session-legend.test.js +0 -20
  132. package/dist/__tests__/session-persistence.test.js +0 -131
  133. package/dist/__tests__/session-resume-block.test.js +0 -107
  134. package/dist/__tests__/session-resume.test.js +0 -97
  135. package/dist/__tests__/session-summary-writer.test.js +0 -134
  136. package/dist/__tests__/shadow-ledger.test.js +0 -203
  137. package/dist/__tests__/shell-classifier.test.js +0 -151
  138. package/dist/__tests__/shell-compression-floor.test.js +0 -189
  139. package/dist/__tests__/shell-compression-v2.test.js +0 -339
  140. package/dist/__tests__/shell-compressor.test.js +0 -35
  141. package/dist/__tests__/shell-hooks.test.js +0 -128
  142. package/dist/__tests__/shell-strategies.test.js +0 -644
  143. package/dist/__tests__/shell-tee.test.js +0 -133
  144. package/dist/__tests__/signal-dedup.test.js +0 -158
  145. package/dist/__tests__/signal-reinforcer.test.js +0 -77
  146. package/dist/__tests__/signal-scorer.test.js +0 -251
  147. package/dist/__tests__/signal-show-store.test.js +0 -108
  148. package/dist/__tests__/smart-truncate.test.js +0 -215
  149. package/dist/__tests__/snapshot-v2.test.js +0 -113
  150. package/dist/__tests__/sprint-l1-local-mode.test.js +0 -130
  151. package/dist/__tests__/sprint-l10-boot.test.js +0 -220
  152. package/dist/__tests__/sprint-l9-offline-commands.test.js +0 -189
  153. package/dist/__tests__/sprint-q-persistent-context.test.js +0 -198
  154. package/dist/__tests__/sprint-s1-wiring.test.js +0 -215
  155. package/dist/__tests__/sprint-s2-wiring.test.js +0 -256
  156. package/dist/__tests__/sprint-s3-wiring.test.js +0 -195
  157. package/dist/__tests__/sprint-s4-wiring.test.js +0 -213
  158. package/dist/__tests__/sprint-s6-hooks.test.js +0 -222
  159. package/dist/__tests__/sprint-s7-persistent.test.js +0 -263
  160. package/dist/__tests__/sprint-s8-value.test.js +0 -167
  161. package/dist/__tests__/sprint-s9-behavioral.test.js +0 -179
  162. package/dist/__tests__/sprint3-intelligence.test.js +0 -297
  163. package/dist/__tests__/sprint5-mcp-server.test.js +0 -136
  164. package/dist/__tests__/startup-display.test.js +0 -302
  165. package/dist/__tests__/startup-log-file.test.js +0 -97
  166. package/dist/__tests__/stash-manager.test.js +0 -229
  167. package/dist/__tests__/state-detector.test.js +0 -92
  168. package/dist/__tests__/status-dashboard.test.js +0 -142
  169. package/dist/__tests__/temporal-facts.test.js +0 -292
  170. package/dist/__tests__/temporal-routes.test.js +0 -142
  171. package/dist/__tests__/test-detector.test.js +0 -174
  172. package/dist/__tests__/theme.test.js +0 -72
  173. package/dist/__tests__/timeline-agents.test.js +0 -122
  174. package/dist/__tests__/timeline-bootstrap.test.js +0 -176
  175. package/dist/__tests__/timeline-filters.test.js +0 -193
  176. package/dist/__tests__/timeline-markers.test.js +0 -151
  177. package/dist/__tests__/timeline-routes.test.js +0 -156
  178. package/dist/__tests__/timeline-store.test.js +0 -171
  179. package/dist/__tests__/token-counter.test.js +0 -86
  180. package/dist/__tests__/token-estimator.test.js +0 -96
  181. package/dist/__tests__/token-flow-api.test.js +0 -239
  182. package/dist/__tests__/token-flow-instrumentation.test.js +0 -437
  183. package/dist/__tests__/token-flow-persistence.test.js +0 -356
  184. package/dist/__tests__/token-flow-routes.test.js +0 -199
  185. package/dist/__tests__/token-flow.test.js +0 -695
  186. package/dist/__tests__/tool-clusters.test.js +0 -177
  187. package/dist/__tests__/transport-mux.test.js +0 -283
  188. package/dist/__tests__/turn-segmenter.test.js +0 -166
  189. package/dist/__tests__/uninstall.test.js +0 -141
  190. package/dist/__tests__/warm-start-policy.test.js +0 -271
  191. package/dist/__tests__/wire-cap-nudge.test.js +0 -77
  192. package/dist/__tests__/worker-pool.test.js +0 -101
  193. package/dist/ui/assets/index-7gl3mIuY.css +0 -1
  194. package/dist/ui/assets/index-CX4FCWGT.js +0 -10
  195. package/dist/ui/assets/rolldown-runtime-S-ySWqyJ.js +0 -1
  196. package/dist/ui/assets/vis-network-NIJHUFI3.js +0 -908
  197. package/dist/ui/fonts/jetbrains-mono-latin-400-normal.woff +0 -0
  198. package/dist/ui/icon-wordmark.png +0 -0
  199. package/dist/ui/icon-wordmark.svg +0 -30
  200. package/dist/ui/icon.png +0 -0
  201. package/dist/ui/icon.svg +0 -25
  202. package/dist/ui/index.html +0 -15
  203. package/dist/ui/prototype-sandbox/index.html +0 -257
  204. package/dist/ui/screenshots/activity.png +0 -0
  205. package/dist/ui/screenshots/code-base-intelligence.png +0 -0
  206. package/dist/ui/screenshots/dashboard.png +0 -0
  207. package/dist/ui/screenshots/project-memory.png +0 -0
  208. package/dist/ui/screenshots/reasoning-quality.png +0 -0
  209. package/dist/ui/screenshots/reasoning-session.png +0 -0
  210. package/dist/ui/screenshots/token-session.png +0 -0
  211. package/dist/ui/screenshots/token-trace-main.png +0 -0
  212. package/dist/ui/screenshots/token-turn.png +0 -0
  213. package/dist/ui/unerr-wordmark.png +0 -0
  214. package/dist/ui/unerr-wordmark.svg +0 -9
  215. package/dist/ui/unerr.png +0 -0
  216. package/dist/ui/unerr.svg +0 -25
  217. package/dist/ui/web-app-manifest-192x192.png +0 -0
  218. package/dist/ui/web-app-manifest-512x512.png +0 -0
@@ -1,213 +0,0 @@
1
- /**
2
- * Sprint S4: Token Accounting & Visibility — Integration Tests.
3
- *
4
- * Verifies:
5
- * - Every MCP response includes _meta.tokens_saved (combined sources)
6
- * - Every MCP response includes _meta.dollar_savings (model-priced)
7
- * - TokenCounter emits to stderr at configurable interval (default: every 5th)
8
- * - EfficiencyTracker accumulates session totals
9
- * - Session summary displays: total tokens saved, dollar savings, efficiency %
10
- */
11
- import { describe, expect, it, vi } from "vitest";
12
- import { createExplorationAccumulator } from "../intelligence/exploration-cost.js";
13
- import { QueryRouter } from "../intelligence/query-router.js";
14
- import { createEfficiencyTracker } from "../proxy/efficiency-tracker.js";
15
- import { calculateDollarSavings } from "../proxy/model-pricing.js";
16
- import { createTokenCounter } from "../proxy/token-counter.js";
17
- function createMockGraph(overrides = {}) {
18
- return {
19
- getEntity: vi.fn().mockReturnValue({
20
- key: "fn1",
21
- name: "fn1",
22
- kind: "function",
23
- file_path: "src/main.ts",
24
- risk_level: "normal",
25
- }),
26
- getBlastRadius: vi.fn().mockReturnValue({
27
- direct_callers: 5,
28
- direct_callees: 2,
29
- transitive_count: 10,
30
- is_chokepoint: false,
31
- summary: "5 callers, 10 transitive dependents",
32
- }),
33
- getBlastRadiusEntities: vi.fn().mockReturnValue(["caller1", "caller2"]),
34
- getConventionsForEntity: vi.fn().mockReturnValue([]),
35
- getCorrections: vi.fn().mockReturnValue([]),
36
- getCommunityForEntity: vi.fn().mockReturnValue(null),
37
- getCrossCommunityEdges: vi.fn().mockReturnValue([]),
38
- getEntitiesByFile: vi.fn().mockReturnValue([]),
39
- queryEntities: vi.fn().mockReturnValue([]),
40
- searchEntities: vi.fn().mockReturnValue([]),
41
- getDriftOverlayEntity: vi.fn().mockReturnValue(null),
42
- getDriftSummary: vi
43
- .fn()
44
- .mockReturnValue({ added: 0, modified: 0, removed: 0, total: 0 }),
45
- getCriticalNodes: vi.fn().mockReturnValue([]),
46
- getCrossBoundaryLinks: vi.fn().mockReturnValue([]),
47
- getCallers: vi.fn().mockReturnValue([]),
48
- getCallersOf: vi.fn().mockReturnValue([]),
49
- getCalleesOf: vi.fn().mockReturnValue([]),
50
- getCallees: vi.fn().mockReturnValue([]),
51
- getImports: vi.fn().mockReturnValue([]),
52
- getRules: vi.fn().mockReturnValue([]),
53
- getJustificationsForEntity: vi.fn().mockReturnValue([]),
54
- getDriftEntitiesForFile: vi.fn().mockReturnValue([]),
55
- close: vi.fn(),
56
- ...overrides,
57
- };
58
- }
59
- describe("Sprint S4: Token Accounting & Visibility Wiring", () => {
60
- describe("S4.1+S4.3: Combined tokens_saved on every response", () => {
61
- it("tracks tokens saved from exploration cost (internal accumulator)", async () => {
62
- const graph = createMockGraph();
63
- const router = new QueryRouter(graph);
64
- const accumulator = createExplorationAccumulator();
65
- const tokenCounter = createTokenCounter({ emitEveryN: 10 });
66
- const efficiencyTracker = createEfficiencyTracker();
67
- router.setExplorationAccumulator(accumulator);
68
- router.setTokenCounter(tokenCounter);
69
- router.setEfficiencyTracker(efficiencyTracker);
70
- await router.execute("get_function", { key: "fn1" });
71
- // Vanity wire fields stripped; verify via internal counter.
72
- expect(tokenCounter.getTotalSaved()).toBeGreaterThan(0);
73
- });
74
- it("feeds savings into token counter and efficiency tracker", async () => {
75
- const graph = createMockGraph();
76
- const router = new QueryRouter(graph);
77
- const accumulator = createExplorationAccumulator();
78
- const tokenCounter = createTokenCounter({ emitEveryN: 100 });
79
- const efficiencyTracker = createEfficiencyTracker();
80
- router.setExplorationAccumulator(accumulator);
81
- router.setTokenCounter(tokenCounter);
82
- router.setEfficiencyTracker(efficiencyTracker);
83
- await router.execute("get_function", { key: "fn1" });
84
- await router.execute("get_function", { key: "fn2" });
85
- expect(tokenCounter.getTotalSaved()).toBeGreaterThan(0);
86
- expect(tokenCounter.getCallCount()).toBe(2);
87
- expect(efficiencyTracker.getSavedTokens()).toBeGreaterThan(0);
88
- });
89
- });
90
- describe("S4.4: Dollar savings tracked internally", () => {
91
- it("derivable from token counter via model pricing", async () => {
92
- const graph = createMockGraph();
93
- const router = new QueryRouter(graph);
94
- const accumulator = createExplorationAccumulator();
95
- const tokenCounter = createTokenCounter({ emitEveryN: 100 });
96
- router.setExplorationAccumulator(accumulator);
97
- router.setTokenCounter(tokenCounter);
98
- await router.execute("get_function", { key: "fn1" });
99
- // Dollar savings stripped from wire to reduce metadata overhead;
100
- // dashboard derives them from the internal token counter.
101
- const tokensSaved = tokenCounter.getTotalSaved();
102
- expect(tokensSaved).toBeGreaterThan(0);
103
- const dollars = calculateDollarSavings(tokensSaved);
104
- expect(dollars).toBeGreaterThan(0);
105
- });
106
- });
107
- describe("S4.5: Stderr live counter at configurable interval", () => {
108
- it("emits to stderr every Nth response (default: 5)", async () => {
109
- const graph = createMockGraph();
110
- const router = new QueryRouter(graph);
111
- const accumulator = createExplorationAccumulator();
112
- const messages = [];
113
- const tokenCounter = createTokenCounter({
114
- emitEveryN: 5,
115
- sink: (msg) => messages.push(msg),
116
- });
117
- const efficiencyTracker = createEfficiencyTracker();
118
- router.setExplorationAccumulator(accumulator);
119
- router.setTokenCounter(tokenCounter);
120
- router.setEfficiencyTracker(efficiencyTracker);
121
- // Make 5 calls to trigger the first emission
122
- for (let i = 0; i < 5; i++) {
123
- await router.execute("get_function", { key: `fn${i}` });
124
- }
125
- expect(messages.length).toBe(1);
126
- expect(messages[0]).toContain("[unerr]");
127
- expect(messages[0]).toContain("tokens saved");
128
- expect(messages[0]).toContain("efficiency");
129
- });
130
- it("does not emit before reaching the interval", async () => {
131
- const graph = createMockGraph();
132
- const router = new QueryRouter(graph);
133
- const accumulator = createExplorationAccumulator();
134
- const messages = [];
135
- const tokenCounter = createTokenCounter({
136
- emitEveryN: 5,
137
- sink: (msg) => messages.push(msg),
138
- });
139
- router.setExplorationAccumulator(accumulator);
140
- router.setTokenCounter(tokenCounter);
141
- // Make 4 calls — should NOT emit
142
- for (let i = 0; i < 4; i++) {
143
- await router.execute("get_function", { key: `fn${i}` });
144
- }
145
- expect(messages.length).toBe(0);
146
- });
147
- });
148
- describe("S4.2: Efficiency tracker session totals", () => {
149
- it("getEfficiencySnapshot returns cumulative data", async () => {
150
- const graph = createMockGraph();
151
- const router = new QueryRouter(graph);
152
- const accumulator = createExplorationAccumulator();
153
- const tokenCounter = createTokenCounter({ emitEveryN: 100 });
154
- const efficiencyTracker = createEfficiencyTracker();
155
- router.setExplorationAccumulator(accumulator);
156
- router.setTokenCounter(tokenCounter);
157
- router.setEfficiencyTracker(efficiencyTracker);
158
- await router.execute("get_function", { key: "fn1" });
159
- await router.execute("get_function", { key: "fn2" });
160
- await router.execute("search_code", { query: "test" });
161
- const snap = router.getEfficiencySnapshot();
162
- expect(snap).not.toBeNull();
163
- expect(snap?.totalCalls).toBe(3);
164
- expect(snap?.savedTokens).toBeGreaterThan(0);
165
- expect(snap?.efficiency).toBeGreaterThan(0);
166
- expect(snap?.efficiency).toBeLessThanOrEqual(100);
167
- });
168
- it("returns null when no efficiency tracker set", () => {
169
- const graph = createMockGraph();
170
- const router = new QueryRouter(graph);
171
- expect(router.getEfficiencySnapshot()).toBeNull();
172
- });
173
- });
174
- describe("S4.6+S4.7: Session summary data", () => {
175
- it("token counter provides formatted summary data", async () => {
176
- const graph = createMockGraph();
177
- const router = new QueryRouter(graph);
178
- const accumulator = createExplorationAccumulator();
179
- const tokenCounter = createTokenCounter({ emitEveryN: 100 });
180
- const efficiencyTracker = createEfficiencyTracker();
181
- router.setExplorationAccumulator(accumulator);
182
- router.setTokenCounter(tokenCounter);
183
- router.setEfficiencyTracker(efficiencyTracker);
184
- for (let i = 0; i < 10; i++) {
185
- await router.execute("get_function", { key: `fn${i}` });
186
- }
187
- // Token counter provides totals for session summary
188
- expect(tokenCounter.getTotalSaved()).toBeGreaterThan(0);
189
- expect(tokenCounter.getTotalProcessed()).toBeGreaterThan(0);
190
- expect(tokenCounter.getEfficiency()).toBeGreaterThan(0);
191
- // Efficiency tracker provides snapshot for session card
192
- const snap = efficiencyTracker.getSnapshot();
193
- expect(snap.totalCalls).toBe(10);
194
- expect(snap.savedTokens).toBeGreaterThan(0);
195
- expect(snap.avgSavingsPerCall).toBeGreaterThan(0);
196
- });
197
- });
198
- describe("S4: Model pricing calculations", () => {
199
- it("calculateDollarSavings returns positive value for saved tokens", () => {
200
- const savings = calculateDollarSavings(10_000);
201
- // Default model is Sonnet 4 at $3/M input tokens
202
- // 10K tokens × $3/M = $0.03
203
- expect(savings).toBeCloseTo(0.03, 4);
204
- });
205
- it("calculateDollarSavings respects model selection", () => {
206
- const sonnet = calculateDollarSavings(10_000, "claude-sonnet-4-20250514");
207
- const opus = calculateDollarSavings(10_000, "claude-opus-4-20250514");
208
- // Opus is 5x more expensive than Sonnet
209
- expect(opus).toBeGreaterThan(sonnet);
210
- expect(opus).toBeCloseTo(0.15, 4);
211
- });
212
- });
213
- });
@@ -1,222 +0,0 @@
1
- /**
2
- * Sprint S6: CLI Hooks Integration — Integration Tests.
3
- *
4
- * Verifies:
5
- * - Auto-detection identifies installed AI tools by directory presence
6
- * - `unerr init` installs Claude Code hook at correct path
7
- * - `unerr init` writes MCP config for detected tools
8
- * - `compress-output` command accepts graph risk map
9
- * - `unerr uninstall` removes hooks cleanly
10
- * - Hook status appears in status output data
11
- * - Existing tests still pass
12
- */
13
- import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
14
- import { tmpdir } from "node:os";
15
- import { join } from "node:path";
16
- import { describe, expect, it } from "vitest";
17
- import { runInit } from "../commands/init.js";
18
- import { installClaudeHook, isClaudeHookInstalled, removeClaudeHook, } from "../config/hook-installer.js";
19
- import { isConfigured, removeMcpConfig, writeMcpConfig, } from "../config/mcp-config-writer.js";
20
- import { detectTools, formatDetectedTools } from "../config/tool-detector.js";
21
- function makeTmpDir() {
22
- const dir = join(tmpdir(), `unerr-s6-${Date.now()}-${Math.random().toString(36).slice(2)}`);
23
- mkdirSync(dir, { recursive: true });
24
- return dir;
25
- }
26
- describe("Sprint S6: CLI Hooks Integration", () => {
27
- describe("S6.1: AI Tool Auto-Detection", () => {
28
- it("detects Claude Code by .claude/ directory", () => {
29
- const cwd = makeTmpDir();
30
- mkdirSync(join(cwd, ".claude"), { recursive: true });
31
- const tools = detectTools(cwd);
32
- expect(tools.some((t) => t.ide === "claude-code")).toBe(true);
33
- });
34
- it("detects Cursor by .cursor/ directory", () => {
35
- const cwd = makeTmpDir();
36
- mkdirSync(join(cwd, ".cursor"), { recursive: true });
37
- const tools = detectTools(cwd);
38
- expect(tools.some((t) => t.ide === "cursor")).toBe(true);
39
- });
40
- it("detects VS Code by .vscode/ directory", () => {
41
- const cwd = makeTmpDir();
42
- mkdirSync(join(cwd, ".vscode"), { recursive: true });
43
- const tools = detectTools(cwd);
44
- expect(tools.some((t) => t.ide === "vscode")).toBe(true);
45
- });
46
- it("detects Windsurf by .windsurf/ directory", () => {
47
- const cwd = makeTmpDir();
48
- mkdirSync(join(cwd, ".windsurf"), { recursive: true });
49
- const tools = detectTools(cwd);
50
- expect(tools.some((t) => t.ide === "windsurf")).toBe(true);
51
- });
52
- it("detects multiple tools simultaneously", () => {
53
- const cwd = makeTmpDir();
54
- mkdirSync(join(cwd, ".claude"), { recursive: true });
55
- mkdirSync(join(cwd, ".cursor"), { recursive: true });
56
- mkdirSync(join(cwd, ".vscode"), { recursive: true });
57
- const tools = detectTools(cwd);
58
- expect(tools.length).toBe(3);
59
- expect(tools.map((t) => t.ide).sort()).toEqual([
60
- "claude-code",
61
- "cursor",
62
- "vscode",
63
- ]);
64
- });
65
- it("returns empty array when no tools found", () => {
66
- const cwd = makeTmpDir();
67
- const tools = detectTools(cwd);
68
- expect(tools).toEqual([]);
69
- });
70
- it("formatDetectedTools returns readable string", () => {
71
- const cwd = makeTmpDir();
72
- mkdirSync(join(cwd, ".claude"), { recursive: true });
73
- mkdirSync(join(cwd, ".cursor"), { recursive: true });
74
- const tools = detectTools(cwd);
75
- const formatted = formatDetectedTools(tools);
76
- expect(formatted).toContain("Claude Code");
77
- expect(formatted).toContain("Cursor");
78
- });
79
- });
80
- describe("S6.2: Hook installation via init", () => {
81
- it("installs Claude Code PostToolUse hook at correct path", () => {
82
- const cwd = makeTmpDir();
83
- mkdirSync(join(cwd, ".claude"), { recursive: true });
84
- const result = runInit(cwd);
85
- const hookPath = join(cwd, ".claude", "hooks", "PostToolUse.sh");
86
- expect(existsSync(hookPath)).toBe(true);
87
- expect(result.hooksInstalled.length).toBeGreaterThan(0);
88
- expect(result.hooksInstalled[0]).toContain("Claude Code hook");
89
- });
90
- it("skips hook if already installed", () => {
91
- const cwd = makeTmpDir();
92
- mkdirSync(join(cwd, ".claude", "hooks"), { recursive: true });
93
- writeFileSync(join(cwd, ".claude", "hooks", "PostToolUse.sh"), "#!/bin/bash\n# existing");
94
- const result = runInit(cwd);
95
- expect(result.skipped.some((s) => s.includes("already installed"))).toBe(true);
96
- });
97
- it("hook content references unerr compress-output", () => {
98
- const cwd = makeTmpDir();
99
- mkdirSync(join(cwd, ".claude"), { recursive: true });
100
- installClaudeHook(cwd);
101
- const hookContent = readFileSync(join(cwd, ".claude", "hooks", "PostToolUse.sh"), "utf-8");
102
- expect(hookContent).toContain("compress-output");
103
- expect(hookContent).toContain("unerr");
104
- });
105
- });
106
- describe("S6.3: MCP config writing via init", () => {
107
- it("writes .cursor/mcp.json for Cursor project", () => {
108
- const cwd = makeTmpDir();
109
- mkdirSync(join(cwd, ".cursor"), { recursive: true });
110
- const result = runInit(cwd);
111
- const configPath = join(cwd, ".cursor", "mcp.json");
112
- expect(existsSync(configPath)).toBe(true);
113
- const config = JSON.parse(readFileSync(configPath, "utf-8"));
114
- expect(config.mcpServers.unerr).toBeDefined();
115
- expect(config.mcpServers.unerr.command).toBe("unerr");
116
- expect(config.mcpServers.unerr.args).toContain("--mcp");
117
- expect(result.configsWritten.length).toBeGreaterThan(0);
118
- });
119
- it("writes .mcp.json for Claude Code project", () => {
120
- const cwd = makeTmpDir();
121
- mkdirSync(join(cwd, ".claude"), { recursive: true });
122
- const result = runInit(cwd);
123
- const configPath = join(cwd, ".mcp.json");
124
- expect(existsSync(configPath)).toBe(true);
125
- const config = JSON.parse(readFileSync(configPath, "utf-8"));
126
- expect(config.mcpServers.unerr).toBeDefined();
127
- });
128
- it("merges into existing config without overwriting", () => {
129
- const cwd = makeTmpDir();
130
- mkdirSync(join(cwd, ".cursor"), { recursive: true });
131
- const existingConfig = {
132
- mcpServers: { other: { command: "other-tool", args: [] } },
133
- };
134
- writeFileSync(join(cwd, ".cursor", "mcp.json"), JSON.stringify(existingConfig));
135
- runInit(cwd);
136
- const config = JSON.parse(readFileSync(join(cwd, ".cursor", "mcp.json"), "utf-8"));
137
- expect(config.mcpServers.other).toBeDefined();
138
- expect(config.mcpServers.unerr).toBeDefined();
139
- });
140
- it("skips if unerr already configured", () => {
141
- const cwd = makeTmpDir();
142
- mkdirSync(join(cwd, ".cursor"), { recursive: true });
143
- const existingConfig = {
144
- mcpServers: {
145
- unerr: { command: "npx", args: ["@unerr/unerr", "--mcp"] },
146
- },
147
- };
148
- writeFileSync(join(cwd, ".cursor", "mcp.json"), JSON.stringify(existingConfig));
149
- const result = runInit(cwd);
150
- expect(result.skipped.some((s) => s.includes("already configured"))).toBe(true);
151
- });
152
- });
153
- describe("S6.4: compress-output uses graph risk map", () => {
154
- it("compressOutput accepts entityRiskMap parameter", async () => {
155
- const { compressOutput } = await import("../proxy/output-compressor.js");
156
- const riskMap = new Map([
157
- [
158
- "src/main.ts",
159
- { riskLevel: "high", fanIn: 10, isChokepoint: true },
160
- ],
161
- ]);
162
- const result = compressOutput("diff --git a/src/main.ts b/src/main.ts\n+++ changed\n- old\n+ new\n", {
163
- tokenBudget: 2000,
164
- entityRiskMap: riskMap,
165
- });
166
- expect(result.output).toBeDefined();
167
- expect(result.originalTokens).toBeGreaterThan(0);
168
- });
169
- it("compressOutput works without entityRiskMap", async () => {
170
- const { compressOutput } = await import("../proxy/output-compressor.js");
171
- const result = compressOutput("test output\nline 2\nline 3", {
172
- tokenBudget: 2000,
173
- });
174
- expect(result.output).toBeDefined();
175
- });
176
- });
177
- describe("S6.5: Hook uninstall", () => {
178
- it("removes Claude Code hook cleanly", () => {
179
- const cwd = makeTmpDir();
180
- mkdirSync(join(cwd, ".claude", "hooks"), { recursive: true });
181
- writeFileSync(join(cwd, ".claude", "hooks", "PostToolUse.sh"), "#!/bin/bash\n");
182
- expect(isClaudeHookInstalled(cwd)).toBe(true);
183
- const removed = removeClaudeHook(cwd);
184
- expect(removed).toBe(true);
185
- expect(isClaudeHookInstalled(cwd)).toBe(false);
186
- });
187
- it("removeMcpConfig removes unerr entry from config", () => {
188
- const cwd = makeTmpDir();
189
- mkdirSync(join(cwd, ".cursor"), { recursive: true });
190
- const config = {
191
- mcpServers: {
192
- unerr: { command: "npx", args: [] },
193
- other: { command: "x", args: [] },
194
- },
195
- };
196
- writeFileSync(join(cwd, ".cursor", "mcp.json"), JSON.stringify(config));
197
- const removed = removeMcpConfig(cwd, "cursor");
198
- expect(removed).toBe(true);
199
- const updated = JSON.parse(readFileSync(join(cwd, ".cursor", "mcp.json"), "utf-8"));
200
- expect(updated.mcpServers.unerr).toBeUndefined();
201
- expect(updated.mcpServers.other).toBeDefined();
202
- });
203
- });
204
- describe("S6.6: Hook status in status output", () => {
205
- it("isClaudeHookInstalled returns true when hook exists", () => {
206
- const cwd = makeTmpDir();
207
- mkdirSync(join(cwd, ".claude", "hooks"), { recursive: true });
208
- writeFileSync(join(cwd, ".claude", "hooks", "PostToolUse.sh"), "#!/bin/bash\n");
209
- expect(isClaudeHookInstalled(cwd)).toBe(true);
210
- });
211
- it("isConfigured returns true when MCP config has unerr entry", () => {
212
- const cwd = makeTmpDir();
213
- mkdirSync(join(cwd, ".cursor"), { recursive: true });
214
- writeMcpConfig(cwd, "cursor");
215
- expect(isConfigured(cwd, "cursor")).toBe(true);
216
- });
217
- it("isConfigured returns false when no config exists", () => {
218
- const cwd = makeTmpDir();
219
- expect(isConfigured(cwd, "cursor")).toBe(false);
220
- });
221
- });
222
- });