@unerr-ai/unerr 0.1.5 → 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 +39151 -36992
  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-BsMTQdhX.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,273 +0,0 @@
1
- /**
2
- * Sprint L4 Tests: Statistical Proof Engine — LocalModeStats, shutdown summary, cumulative stats.
3
- */
4
- import { mkdirSync, 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 { createLocalModeStats, createSessionStats, formatLocalModeSessionStats, loadCumulativeLocalStats, persistCumulativeLocalStats, recordBlastRadius, recordCommunityContext, recordCorrectionInjection, recordEmbedding, recordGraphQuery, recordIndexingResult, recordLatency, recordSemanticSearch, recordToolCall, recordTruncationSavings, } from "../proxy/session-stats.js";
9
- // ── LocalModeStats Creation ─────────────────────────────────────
10
- describe("createLocalModeStats", () => {
11
- it("initializes all counters to zero", () => {
12
- const lm = createLocalModeStats();
13
- expect(lm.filesIndexed).toBe(0);
14
- expect(lm.entitiesExtracted).toBe(0);
15
- expect(lm.edgesComputed).toBe(0);
16
- expect(lm.indexingTimeMs).toBe(0);
17
- expect(lm.communitiesDetected).toBe(0);
18
- expect(lm.embeddingsComputed).toBe(0);
19
- expect(lm.embeddingTimeMs).toBe(0);
20
- expect(lm.semanticSearches).toBe(0);
21
- expect(lm.tokensSavedByTruncation).toBe(0);
22
- expect(lm.truncatedResponses).toBe(0);
23
- expect(lm.correctionPatternsInjected).toBe(0);
24
- expect(lm.communityContextsInjected).toBe(0);
25
- expect(lm.blastRadiusComputations).toBe(0);
26
- expect(lm.firewallBlockedCount).toBe(0);
27
- expect(lm.graphQueriesByType).toEqual({});
28
- });
29
- });
30
- // ── SessionStats with Local Mode ────────────────────────────────
31
- describe("createSessionStats with isLocalMode", () => {
32
- it("creates localMode=null for standard mode", () => {
33
- const stats = createSessionStats(false);
34
- expect(stats.localMode).toBeNull();
35
- });
36
- it("creates localMode stats for local mode", () => {
37
- const stats = createSessionStats(true);
38
- expect(stats.localMode).not.toBeNull();
39
- expect(stats.localMode?.filesIndexed).toBe(0);
40
- });
41
- });
42
- // ── Recording Functions ─────────────────────────────────────────
43
- describe("LocalModeStats recording functions", () => {
44
- let lm;
45
- beforeEach(() => {
46
- lm = createLocalModeStats();
47
- });
48
- it("recordGraphQuery tracks per-tool counts", () => {
49
- recordGraphQuery(lm, "get_function");
50
- recordGraphQuery(lm, "get_function");
51
- recordGraphQuery(lm, "search_code");
52
- recordGraphQuery(lm, "get_callers");
53
- expect(lm.graphQueriesByType.get_function).toBe(2);
54
- expect(lm.graphQueriesByType.search_code).toBe(1);
55
- expect(lm.graphQueriesByType.get_callers).toBe(1);
56
- });
57
- it("recordTruncationSavings accumulates token savings", () => {
58
- recordTruncationSavings(lm, 10000, 3000); // saved 7000
59
- recordTruncationSavings(lm, 5000, 2000); // saved 3000
60
- recordTruncationSavings(lm, 1000, 1500); // no savings (used > full)
61
- expect(lm.tokensSavedByTruncation).toBe(10000);
62
- expect(lm.truncatedResponses).toBe(2);
63
- });
64
- it("recordIndexingResult sets all indexing fields", () => {
65
- recordIndexingResult(lm, {
66
- fileCount: 500,
67
- entityCount: 2000,
68
- edgeCount: 5000,
69
- elapsedMs: 3200,
70
- communityCount: 25,
71
- });
72
- expect(lm.filesIndexed).toBe(500);
73
- expect(lm.entitiesExtracted).toBe(2000);
74
- expect(lm.edgesComputed).toBe(5000);
75
- expect(lm.indexingTimeMs).toBe(3200);
76
- expect(lm.communitiesDetected).toBe(25);
77
- });
78
- it("recordBlastRadius increments counter", () => {
79
- recordBlastRadius(lm);
80
- recordBlastRadius(lm);
81
- expect(lm.blastRadiusComputations).toBe(2);
82
- });
83
- it("recordCorrectionInjection increments counter", () => {
84
- recordCorrectionInjection(lm);
85
- recordCorrectionInjection(lm);
86
- recordCorrectionInjection(lm);
87
- expect(lm.correctionPatternsInjected).toBe(3);
88
- });
89
- it("recordCommunityContext increments counter", () => {
90
- recordCommunityContext(lm);
91
- expect(lm.communityContextsInjected).toBe(1);
92
- });
93
- it("recordEmbedding accumulates counts and time", () => {
94
- recordEmbedding(lm, 100, 500);
95
- recordEmbedding(lm, 50, 300);
96
- expect(lm.embeddingsComputed).toBe(150);
97
- expect(lm.embeddingTimeMs).toBe(800);
98
- });
99
- it("recordSemanticSearch increments counter", () => {
100
- recordSemanticSearch(lm);
101
- recordSemanticSearch(lm);
102
- expect(lm.semanticSearches).toBe(2);
103
- });
104
- });
105
- // ── Local Mode Shutdown Summary ─────────────────────────────────
106
- describe("formatLocalModeSessionStats", () => {
107
- function makeStats() {
108
- const stats = createSessionStats(true);
109
- // Simulate a session with activity
110
- for (let i = 0; i < 50; i++) {
111
- recordToolCall(stats);
112
- recordLatency(stats.latency, 2 + Math.random() * 3);
113
- }
114
- stats.violationsCaught = 3;
115
- stats.riskWarningsIssued = 1;
116
- stats.events.chokepointWarningsIssued = 2;
117
- const lm = stats.localMode;
118
- recordGraphQuery(lm, "get_function");
119
- recordGraphQuery(lm, "get_function");
120
- recordGraphQuery(lm, "get_class");
121
- recordGraphQuery(lm, "search_code");
122
- recordGraphQuery(lm, "get_callers");
123
- recordBlastRadius(lm);
124
- recordBlastRadius(lm);
125
- recordTruncationSavings(lm, 10000, 3000);
126
- recordCorrectionInjection(lm);
127
- return stats;
128
- }
129
- it("returns null for zero tool calls", () => {
130
- const stats = createSessionStats(true);
131
- expect(formatLocalModeSessionStats(stats)).toBeNull();
132
- });
133
- it("falls back to standard format when localMode is null", () => {
134
- const stats = createSessionStats(false);
135
- recordToolCall(stats);
136
- const result = formatLocalModeSessionStats(stats);
137
- // Should use formatSessionStats (standard mode output)
138
- expect(result).toContain("unerr session");
139
- });
140
- it("renders Local Mode session summary header", () => {
141
- const result = formatLocalModeSessionStats(makeStats());
142
- expect(result).toContain("Local Mode Session Summary");
143
- });
144
- it("includes MCP tool call counts", () => {
145
- const result = formatLocalModeSessionStats(makeStats());
146
- expect(result).toContain("50 (all local)");
147
- });
148
- it("includes latency percentiles", () => {
149
- const result = formatLocalModeSessionStats(makeStats());
150
- expect(result).toContain("(p50)");
151
- expect(result).toContain("(p95)");
152
- });
153
- it("includes graph intelligence section", () => {
154
- const result = formatLocalModeSessionStats(makeStats());
155
- expect(result).toContain("Graph Intelligence:");
156
- expect(result).toContain("Entity lookups:");
157
- expect(result).toContain("Blast radius:");
158
- expect(result).toContain("Search queries:");
159
- expect(result).toContain("Callers/callees:");
160
- });
161
- it("includes token discipline section", () => {
162
- const result = formatLocalModeSessionStats(makeStats());
163
- expect(result).toContain("Token Discipline:");
164
- expect(result).toContain("Tokens saved:");
165
- expect(result).toContain("Responses truncated:");
166
- });
167
- it("includes safety catches section", () => {
168
- const result = formatLocalModeSessionStats(makeStats());
169
- expect(result).toContain("Safety Catches:");
170
- expect(result).toContain("Violations caught:");
171
- expect(result).toContain("Corrections applied:");
172
- });
173
- it("includes network isolation section", () => {
174
- const result = formatLocalModeSessionStats(makeStats());
175
- expect(result).toContain("Network Isolation:");
176
- expect(result).toContain("0 (firewall sealed)");
177
- });
178
- it("omits empty sections", () => {
179
- const stats = createSessionStats(true);
180
- recordToolCall(stats);
181
- recordLatency(stats.latency, 2);
182
- const result = formatLocalModeSessionStats(stats);
183
- expect(result).not.toContain("Graph Intelligence:");
184
- expect(result).not.toContain("Token Discipline:");
185
- expect(result).not.toContain("Safety Catches:");
186
- expect(result).not.toContain("Semantic Intelligence:");
187
- // Network Isolation always shown
188
- expect(result).toContain("Network Isolation:");
189
- });
190
- it("includes semantic intelligence when embeddings computed", () => {
191
- const stats = makeStats();
192
- recordEmbedding(stats.localMode, 100, 500);
193
- recordSemanticSearch(stats.localMode);
194
- const result = formatLocalModeSessionStats(stats);
195
- expect(result).toContain("Semantic Intelligence:");
196
- expect(result).toContain("Embeddings computed:");
197
- expect(result).toContain("Semantic searches:");
198
- });
199
- });
200
- // ── Cumulative Local Stats Persistence ──────────────────────────
201
- describe("CumulativeLocalStats", () => {
202
- let tmpDir;
203
- const originalHome = process.env.HOME;
204
- beforeEach(() => {
205
- tmpDir = join(tmpdir(), `unerr-cumul-test-${Date.now()}`);
206
- mkdirSync(join(tmpDir, ".unerr"), { recursive: true });
207
- process.env.HOME = tmpDir;
208
- });
209
- afterEach(() => {
210
- process.env.HOME = originalHome;
211
- try {
212
- rmSync(tmpDir, { recursive: true, force: true });
213
- }
214
- catch {
215
- /* ignore */
216
- }
217
- });
218
- it("returns empty stats when no file exists", () => {
219
- const cls = loadCumulativeLocalStats();
220
- expect(cls.totalSessions).toBe(0);
221
- expect(cls.totalToolCalls).toBe(0);
222
- expect(cls.totalTokensSaved).toBe(0);
223
- });
224
- it("persists and loads stats across calls", () => {
225
- const stats = createSessionStats(true);
226
- for (let i = 0; i < 10; i++)
227
- recordToolCall(stats);
228
- stats.violationsCaught = 2;
229
- recordTruncationSavings(stats.localMode, 5000, 1000);
230
- recordCorrectionInjection(stats.localMode);
231
- const result = persistCumulativeLocalStats(stats);
232
- expect(result.totalSessions).toBe(1);
233
- expect(result.totalToolCalls).toBe(10);
234
- expect(result.totalTokensSaved).toBe(4000);
235
- expect(result.totalViolationsCaught).toBe(2);
236
- expect(result.totalCorrectionsApplied).toBe(1);
237
- // Second session accumulates
238
- const stats2 = createSessionStats(true);
239
- for (let i = 0; i < 5; i++)
240
- recordToolCall(stats2);
241
- stats2.violationsCaught = 1;
242
- recordTruncationSavings(stats2.localMode, 3000, 1000);
243
- const result2 = persistCumulativeLocalStats(stats2);
244
- expect(result2.totalSessions).toBe(2);
245
- expect(result2.totalToolCalls).toBe(15);
246
- expect(result2.totalTokensSaved).toBe(6000);
247
- expect(result2.totalViolationsCaught).toBe(3);
248
- });
249
- it("resets on new week", () => {
250
- // Write stats with a stale week
251
- const staleStats = {
252
- weekStartDate: "2020-01-06",
253
- totalSessions: 100,
254
- totalToolCalls: 5000,
255
- totalTokensSaved: 999999,
256
- totalViolationsCaught: 50,
257
- totalCorrectionsApplied: 10,
258
- totalFilesIndexed: 200,
259
- totalSemanticSearches: 30,
260
- avgLatencyP50: 2.5,
261
- };
262
- const filePath = join(tmpDir, ".unerr", "cumulative-local-stats.json");
263
- writeFileSync(filePath, JSON.stringify(staleStats));
264
- const loaded = loadCumulativeLocalStats();
265
- expect(loaded.totalSessions).toBe(0);
266
- expect(loaded.totalToolCalls).toBe(0);
267
- });
268
- it("returns existing cumulative when localMode is null", () => {
269
- const stats = createSessionStats(false); // standard mode
270
- const result = persistCumulativeLocalStats(stats);
271
- expect(result.totalSessions).toBe(0);
272
- });
273
- });
@@ -1,343 +0,0 @@
1
- /**
2
- * Tests for Sprint L7 — Local Mode TUI components.
3
- *
4
- * Covers:
5
- * - StartupDisplay Local Mode variant (Three-Act structure)
6
- * - SessionSummaryCard Local Mode variant (proof-of-value shutdown)
7
- * - StartupRenderer local mode methods
8
- * - Latency advantage injection
9
- */
10
- import * as fs from "node:fs";
11
- import * as os from "node:os";
12
- import * as path from "node:path";
13
- import { render } from "ink-testing-library";
14
- import React from "react";
15
- import { afterEach, beforeEach, describe, expect, it } from "vitest";
16
- import { SessionSummaryCard } from "../components/SessionSummaryCard.js";
17
- import { StartupDisplay, } from "../components/StartupDisplay.js";
18
- import { ThemeProvider } from "../components/Theme.js";
19
- import { createLatencyTracker, createLocalModeStats, createSessionEvents, recordLatencyAdvantage, } from "../proxy/session-stats.js";
20
- function renderWithTheme(el) {
21
- return render(React.createElement(ThemeProvider, null, el));
22
- }
23
- function renderStartup(state) {
24
- return renderWithTheme(React.createElement(StartupDisplay, { state }));
25
- }
26
- function makeLocalStats() {
27
- return {
28
- toolCallsLocal: 25,
29
- estimatedTokensSaved: 0,
30
- violationsCaught: 2,
31
- riskWarningsIssued: 1,
32
- sessionStartedAt: Date.now() - 300_000, // 5 min ago
33
- latency: createLatencyTracker(),
34
- events: {
35
- ...createSessionEvents(),
36
- conventionViolationsCaught: 2,
37
- chokepointWarningsIssued: 1,
38
- },
39
- isResumedSession: false,
40
- previousSession: null,
41
- localMode: {
42
- ...createLocalModeStats(),
43
- blastRadiusComputations: 3,
44
- communityContextsInjected: 5,
45
- correctionPatternsInjected: 2,
46
- tokensSavedByTruncation: 12000,
47
- truncatedResponses: 4,
48
- semanticSearches: 7,
49
- cumulativeLatencySavedMs: 4850,
50
- firewallBlockedCount: 0,
51
- },
52
- };
53
- }
54
- // ── StartupDisplay Local Mode ─────────────────────────────────────
55
- describe("StartupDisplay Local Mode (L7.1)", () => {
56
- it("renders locally computed health title instead of First Look", () => {
57
- const { lastFrame } = renderStartup({
58
- steps: [],
59
- firstBoot: false,
60
- ready: false,
61
- localMode: true,
62
- health: {
63
- grade: "B",
64
- totalEntities: 500,
65
- totalEdges: 300,
66
- totalRules: 8,
67
- deadFunctionCount: 5,
68
- highRiskEntities: [],
69
- score: 78,
70
- },
71
- });
72
- const frame = lastFrame() ?? "";
73
- expect(frame).toContain("Health (locally computed)");
74
- expect(frame).not.toContain("First Look");
75
- });
76
- it("shows tool count and zero cloud deps in Act 3", () => {
77
- const { lastFrame } = renderStartup({
78
- steps: [],
79
- firstBoot: false,
80
- ready: true,
81
- localMode: true,
82
- toolCount: 11,
83
- });
84
- const frame = lastFrame() ?? "";
85
- expect(frame).toContain("11 tools ready");
86
- expect(frame).toContain("offline-capable");
87
- });
88
- it("shows agent invitation with entity name in Local Mode", () => {
89
- const { lastFrame } = renderStartup({
90
- steps: [],
91
- firstBoot: false,
92
- ready: true,
93
- localMode: true,
94
- invitationEntity: "processPayment",
95
- });
96
- const frame = lastFrame() ?? "";
97
- expect(frame).toContain("What depends on processPayment?");
98
- });
99
- it("shows default invitation when no entity", () => {
100
- const { lastFrame } = renderStartup({
101
- steps: [],
102
- firstBoot: false,
103
- ready: true,
104
- localMode: true,
105
- });
106
- const frame = lastFrame() ?? "";
107
- expect(frame).toContain("Show me the highest-impact functions in this codebase");
108
- });
109
- it("never shows deep link in Local Mode", () => {
110
- const { lastFrame } = renderStartup({
111
- steps: [],
112
- firstBoot: false,
113
- ready: true,
114
- localMode: true,
115
- deepLink: "https://app.unerr.dev/r/repo_123",
116
- });
117
- // Deep link is in state but Local Mode Act 3 doesn't render it
118
- const frame = lastFrame() ?? "";
119
- expect(frame).not.toContain("Health details");
120
- expect(frame).not.toContain("Proxy ready. Serving MCP on stdio");
121
- });
122
- it("does not show standard Act 3 when in local mode", () => {
123
- const { lastFrame } = renderStartup({
124
- steps: [],
125
- firstBoot: false,
126
- ready: true,
127
- localMode: true,
128
- proxyMode: "full",
129
- });
130
- const frame = lastFrame() ?? "";
131
- expect(frame).not.toContain("Proxy ready");
132
- });
133
- });
134
- // ── SessionSummaryCard Local Mode ─────────────────────────────────
135
- describe("SessionSummaryCard Local Mode (L7.2)", () => {
136
- it("renders all-local tool calls with 100% progress bar", () => {
137
- const stats = makeLocalStats();
138
- const { lastFrame } = renderWithTheme(React.createElement(SessionSummaryCard, { stats }));
139
- const frame = lastFrame() ?? "";
140
- expect(frame).toContain("25 (all local)");
141
- expect(frame).toContain("Local rate");
142
- });
143
- it("shows caught section when violations exist", () => {
144
- const stats = makeLocalStats();
145
- const { lastFrame } = renderWithTheme(React.createElement(SessionSummaryCard, { stats }));
146
- const frame = lastFrame() ?? "";
147
- expect(frame).toContain("Caught:");
148
- expect(frame).toContain("2 convention violations before commit");
149
- expect(frame).toContain("1 chokepoint modification");
150
- });
151
- it("shows Intelligence Applied section", () => {
152
- const stats = makeLocalStats();
153
- const { lastFrame } = renderWithTheme(React.createElement(SessionSummaryCard, { stats }));
154
- const frame = lastFrame() ?? "";
155
- expect(frame).toContain("Intelligence Applied:");
156
- expect(frame).toContain("3 blast radius computations");
157
- expect(frame).toContain("5 community contexts injected");
158
- expect(frame).toContain("2 correction patterns applied");
159
- });
160
- it("shows Token Discipline section", () => {
161
- const stats = makeLocalStats();
162
- const { lastFrame } = renderWithTheme(React.createElement(SessionSummaryCard, { stats }));
163
- const frame = lastFrame() ?? "";
164
- expect(frame).toContain("Token Discipline:");
165
- expect(frame).toContain("12.0k tokens saved via smart truncation");
166
- expect(frame).toContain("4 responses budget-trimmed");
167
- });
168
- it("shows Semantic Intelligence when BYO-LLM used", () => {
169
- const stats = makeLocalStats();
170
- const { lastFrame } = renderWithTheme(React.createElement(SessionSummaryCard, { stats }));
171
- const frame = lastFrame() ?? "";
172
- expect(frame).toContain("Semantic Intelligence:");
173
- expect(frame).toContain("7 queries via local embeddings");
174
- });
175
- it("shows Network Isolation section with firewall sealed", () => {
176
- const stats = makeLocalStats();
177
- const { lastFrame } = renderWithTheme(React.createElement(SessionSummaryCard, { stats }));
178
- const frame = lastFrame() ?? "";
179
- expect(frame).toContain("Network Isolation:");
180
- expect(frame).toContain("Outbound: 0 calls (firewall sealed)");
181
- expect(frame).toContain("Blocked attempts: 0 (clean)");
182
- });
183
- it("shows latency advantage when accumulated and latency samples exist", () => {
184
- const stats = makeLocalStats();
185
- // Populate latency samples so localP is non-null
186
- for (let i = 0; i < 10; i++) {
187
- stats.latency.localSamples[i] = 3.0;
188
- }
189
- stats.latency.localCursor = 10;
190
- stats.latency.localTotalSamples = 10;
191
- const { lastFrame } = renderWithTheme(React.createElement(SessionSummaryCard, { stats }));
192
- const frame = lastFrame() ?? "";
193
- expect(frame).toContain("4.8s saved vs remote");
194
- });
195
- it("never shows dollar savings in Local Mode (TL-19)", () => {
196
- const stats = makeLocalStats();
197
- const { lastFrame } = renderWithTheme(React.createElement(SessionSummaryCard, { stats }));
198
- const frame = lastFrame() ?? "";
199
- expect(frame).not.toContain("$");
200
- expect(frame).not.toContain("Saved:");
201
- });
202
- it("never shows deep link in Local Mode", () => {
203
- const stats = makeLocalStats();
204
- const { lastFrame } = renderWithTheme(React.createElement(SessionSummaryCard, {
205
- stats,
206
- deepLink: "https://app.unerr.dev/r/repo_123",
207
- }));
208
- const frame = lastFrame() ?? "";
209
- expect(frame).not.toContain("Session →");
210
- expect(frame).not.toContain("unerr.dev");
211
- });
212
- it("renders compact line for short sessions (<=10 calls)", () => {
213
- const stats = makeLocalStats();
214
- stats.toolCallsLocal = 5;
215
- const { lastFrame } = renderWithTheme(React.createElement(SessionSummaryCard, { stats }));
216
- const frame = lastFrame() ?? "";
217
- expect(frame).toContain("unerr local session:");
218
- expect(frame).toContain("5 tool calls (all local)");
219
- });
220
- it("renders empty box for zero tool calls", () => {
221
- const stats = makeLocalStats();
222
- stats.toolCallsLocal = 0;
223
- const { lastFrame } = renderWithTheme(React.createElement(SessionSummaryCard, { stats }));
224
- const frame = lastFrame() ?? "";
225
- // Should be basically empty
226
- expect(frame).not.toContain("Tool calls");
227
- expect(frame).not.toContain("unerr local session");
228
- });
229
- it("shows cumulative This week line when >1 session", () => {
230
- const stats = makeLocalStats();
231
- const { lastFrame } = renderWithTheme(React.createElement(SessionSummaryCard, {
232
- stats,
233
- cumulativeLocal: {
234
- weekStartDate: "2026-04-13",
235
- totalSessions: 5,
236
- totalToolCalls: 120,
237
- totalTokensSaved: 45000,
238
- totalViolationsCaught: 8,
239
- totalCorrectionsApplied: 3,
240
- totalFilesIndexed: 200,
241
- totalSemanticSearches: 15,
242
- avgLatencyP50: 2.1,
243
- },
244
- }));
245
- const frame = lastFrame() ?? "";
246
- expect(frame).toContain("This week:");
247
- expect(frame).toContain("5 sessions");
248
- expect(frame).toContain("45k tokens saved");
249
- expect(frame).toContain("8 caught");
250
- });
251
- });
252
- // ── Latency Advantage ─────────────────────────────────────────────
253
- describe("Latency advantage (L7.3)", () => {
254
- it("recordLatencyAdvantage accumulates correctly", () => {
255
- const lm = createLocalModeStats();
256
- recordLatencyAdvantage(lm, 195); // 5ms actual → 195ms saved
257
- recordLatencyAdvantage(lm, 198); // 2ms actual → 198ms saved
258
- expect(lm.cumulativeLatencySavedMs).toBe(393);
259
- });
260
- it("cumulativeLatencySavedMs starts at 0", () => {
261
- const lm = createLocalModeStats();
262
- expect(lm.cumulativeLatencySavedMs).toBe(0);
263
- });
264
- });
265
- // ── StartupRenderer Local Mode ────────────────────────────────────
266
- describe("StartupRenderer Local Mode (L7.4)", () => {
267
- let tmpDir;
268
- let origCwd;
269
- beforeEach(() => {
270
- tmpDir = path.join(os.tmpdir(), `unerr-l7-test-${Date.now()}`);
271
- fs.mkdirSync(path.join(tmpDir, ".unerr", "state"), { recursive: true });
272
- origCwd = process.cwd();
273
- process.chdir(tmpDir);
274
- });
275
- afterEach(() => {
276
- process.chdir(origCwd);
277
- fs.rmSync(tmpDir, { recursive: true, force: true });
278
- });
279
- it("setLocalMode suppresses deep link in setHealth", async () => {
280
- const { StartupRenderer } = await import("../proxy/startup-renderer.js");
281
- const renderer = new StartupRenderer();
282
- renderer.setLocalMode(true);
283
- renderer.setHealth({
284
- grade: "B",
285
- totalEntities: 100,
286
- totalEdges: 50,
287
- totalRules: 5,
288
- deadFunctionCount: 0,
289
- highRiskEntities: [],
290
- score: 80,
291
- }, "repo_test");
292
- // Access internal state to verify no deep link
293
- // @ts-expect-error accessing private for test
294
- expect(renderer.state.deepLink).toBeUndefined();
295
- // @ts-expect-error accessing private for test
296
- expect(renderer.state.localMode).toBe(true);
297
- });
298
- it("setLocalMode suppresses deep link in setReady", async () => {
299
- const { StartupRenderer } = await import("../proxy/startup-renderer.js");
300
- const renderer = new StartupRenderer();
301
- renderer.setLocalMode(true);
302
- // @ts-expect-error accessing private for test
303
- renderer.repoId = "repo_test";
304
- renderer.setReady("local");
305
- // @ts-expect-error accessing private for test
306
- expect(renderer.state.deepLink).toBeUndefined();
307
- });
308
- it("setToolCount sets the tool count", async () => {
309
- const { StartupRenderer } = await import("../proxy/startup-renderer.js");
310
- const renderer = new StartupRenderer();
311
- renderer.setToolCount(11);
312
- // @ts-expect-error accessing private for test
313
- expect(renderer.state.toolCount).toBe(11);
314
- });
315
- it("setByoLlmStatus sets BYO-LLM fields", async () => {
316
- const { StartupRenderer } = await import("../proxy/startup-renderer.js");
317
- const renderer = new StartupRenderer();
318
- renderer.setByoLlmStatus("connected", "ollama", "nomic-embed-text");
319
- // @ts-expect-error accessing private for test
320
- expect(renderer.state.byoLlmStatus).toBe("connected");
321
- // @ts-expect-error accessing private for test
322
- expect(renderer.state.byoLlmProvider).toBe("ollama");
323
- // @ts-expect-error accessing private for test
324
- expect(renderer.state.byoLlmModel).toBe("nomic-embed-text");
325
- });
326
- it("setLocalIndexStats sets indexing stats", async () => {
327
- const { StartupRenderer } = await import("../proxy/startup-renderer.js");
328
- const renderer = new StartupRenderer();
329
- renderer.setLocalIndexStats({
330
- fileCount: 100,
331
- entityCount: 500,
332
- edgeCount: 300,
333
- indexingTimeMs: 1200,
334
- communityCount: 12,
335
- conventionCount: 8,
336
- ruleCount: 5,
337
- });
338
- // @ts-expect-error accessing private for test
339
- expect(renderer.state.localIndexStats?.fileCount).toBe(100);
340
- // @ts-expect-error accessing private for test
341
- expect(renderer.state.localIndexStats?.entityCount).toBe(500);
342
- });
343
- });