@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,253 +0,0 @@
1
- /**
2
- * Sprint L3.1 Tests: BYO-LLM Adapter Factory — adapter creation, embedding, health check.
3
- */
4
- import { beforeEach, describe, expect, it, vi } from "vitest";
5
- import { createAndVerifyAdapter, createLocalLlmAdapter, } from "../intelligence/local-llm.js";
6
- // ── Adapter Factory ─────────────────────────────────────────
7
- describe("createLocalLlmAdapter", () => {
8
- it("returns null when config is undefined", () => {
9
- expect(createLocalLlmAdapter(undefined)).toBeNull();
10
- });
11
- it("creates Ollama adapter with defaults", () => {
12
- const config = {
13
- provider: "ollama",
14
- embeddingModel: "nomic-embed-text",
15
- chatModel: "llama3",
16
- maxConcurrency: 2,
17
- embeddingDimensions: 384,
18
- };
19
- const adapter = createLocalLlmAdapter(config);
20
- expect(adapter).not.toBeNull();
21
- expect(adapter?.provider).toBe("ollama");
22
- expect(adapter?.baseUrl).toBe("http://localhost:11434");
23
- expect(adapter?.embeddingModel).toBe("nomic-embed-text");
24
- expect(adapter?.embeddingDimensions).toBe(384);
25
- expect(adapter?.maxConcurrency).toBe(2);
26
- });
27
- it("creates LM Studio adapter with custom baseUrl", () => {
28
- const config = {
29
- provider: "lm-studio",
30
- baseUrl: "http://localhost:5555",
31
- embeddingModel: "all-MiniLM-L6-v2",
32
- chatModel: "llama3",
33
- maxConcurrency: 4,
34
- embeddingDimensions: 384,
35
- };
36
- const adapter = createLocalLlmAdapter(config);
37
- expect(adapter?.provider).toBe("lm-studio");
38
- expect(adapter?.baseUrl).toBe("http://localhost:5555");
39
- });
40
- it("creates OpenAI-compatible adapter", () => {
41
- const config = {
42
- provider: "openai-compatible",
43
- baseUrl: "http://localhost:8080",
44
- embeddingModel: "text-embedding-3-small",
45
- chatModel: "gpt-4o",
46
- apiKey: "sk-test",
47
- maxConcurrency: 2,
48
- embeddingDimensions: 1536,
49
- };
50
- const adapter = createLocalLlmAdapter(config);
51
- expect(adapter?.provider).toBe("openai-compatible");
52
- });
53
- it("creates Anthropic-direct adapter", () => {
54
- const config = {
55
- provider: "anthropic-direct",
56
- embeddingModel: "nomic-embed-text",
57
- chatModel: "claude-sonnet-4-20250514",
58
- maxConcurrency: 2,
59
- embeddingDimensions: 384,
60
- };
61
- const adapter = createLocalLlmAdapter(config);
62
- expect(adapter?.provider).toBe("anthropic-direct");
63
- expect(adapter?.baseUrl).toBe("https://api.anthropic.com");
64
- });
65
- });
66
- // ── Embed Method ────────────────────────────────────────────
67
- describe("adapter.embed", () => {
68
- let adapter;
69
- beforeEach(() => {
70
- adapter = createLocalLlmAdapter({
71
- provider: "ollama",
72
- embeddingModel: "nomic-embed-text",
73
- chatModel: "llama3",
74
- maxConcurrency: 2,
75
- embeddingDimensions: 384,
76
- });
77
- });
78
- it("returns empty result for empty input", async () => {
79
- const result = await adapter.embed([]);
80
- expect(result.embeddings).toEqual([]);
81
- expect(result.totalTokens).toBe(0);
82
- });
83
- it("calls /v1/embeddings with correct payload", async () => {
84
- const mockResponse = {
85
- data: [
86
- { embedding: [0.1, 0.2, 0.3], index: 0 },
87
- { embedding: [0.4, 0.5, 0.6], index: 1 },
88
- ],
89
- model: "nomic-embed-text",
90
- usage: { prompt_tokens: 10, total_tokens: 10 },
91
- };
92
- const fetchSpy = vi
93
- .spyOn(globalThis, "fetch")
94
- .mockResolvedValue(new Response(JSON.stringify(mockResponse), { status: 200 }));
95
- const result = await adapter.embed(["hello", "world"]);
96
- expect(fetchSpy).toHaveBeenCalledOnce();
97
- const call = fetchSpy.mock.calls[0];
98
- const [url, init] = call ?? [];
99
- expect(url).toBe("http://localhost:11434/v1/embeddings");
100
- expect(init?.method).toBe("POST");
101
- const body = JSON.parse(init?.body);
102
- expect(body.model).toBe("nomic-embed-text");
103
- expect(body.input).toEqual(["hello", "world"]);
104
- expect(result.embeddings).toHaveLength(2);
105
- expect(result.embeddings[0]).toEqual([0.1, 0.2, 0.3]);
106
- expect(result.embeddings[1]).toEqual([0.4, 0.5, 0.6]);
107
- expect(result.totalTokens).toBe(10);
108
- fetchSpy.mockRestore();
109
- });
110
- it("sorts response by index to preserve order", async () => {
111
- const mockResponse = {
112
- data: [
113
- { embedding: [0.4, 0.5], index: 1 },
114
- { embedding: [0.1, 0.2], index: 0 },
115
- ],
116
- model: "nomic-embed-text",
117
- usage: { prompt_tokens: 5, total_tokens: 5 },
118
- };
119
- const fetchSpy = vi
120
- .spyOn(globalThis, "fetch")
121
- .mockResolvedValue(new Response(JSON.stringify(mockResponse), { status: 200 }));
122
- const result = await adapter.embed(["first", "second"]);
123
- expect(result.embeddings[0]).toEqual([0.1, 0.2]);
124
- expect(result.embeddings[1]).toEqual([0.4, 0.5]);
125
- fetchSpy.mockRestore();
126
- });
127
- it("throws on non-200 response", async () => {
128
- const fetchSpy = vi.spyOn(globalThis, "fetch").mockResolvedValue(new Response("model not found", {
129
- status: 404,
130
- statusText: "Not Found",
131
- }));
132
- await expect(adapter.embed(["test"])).rejects.toThrow("404 Not Found");
133
- fetchSpy.mockRestore();
134
- });
135
- it("includes Authorization header when apiKey is set", async () => {
136
- const adapterWithKey = createLocalLlmAdapter({
137
- provider: "openai-compatible",
138
- baseUrl: "http://localhost:8080",
139
- embeddingModel: "test-model",
140
- chatModel: "test",
141
- apiKey: "sk-secret",
142
- maxConcurrency: 2,
143
- embeddingDimensions: 384,
144
- });
145
- const mockResponse = {
146
- data: [{ embedding: [0.1], index: 0 }],
147
- model: "test-model",
148
- usage: { prompt_tokens: 1, total_tokens: 1 },
149
- };
150
- const fetchSpy = vi
151
- .spyOn(globalThis, "fetch")
152
- .mockResolvedValue(new Response(JSON.stringify(mockResponse), { status: 200 }));
153
- await adapterWithKey.embed(["test"]);
154
- const headers = fetchSpy.mock.calls[0]?.[1]?.headers;
155
- expect(headers.Authorization).toBe("Bearer sk-secret");
156
- fetchSpy.mockRestore();
157
- });
158
- });
159
- // ── Health Check ────────────────────────────────────────────
160
- describe("adapter.isAvailable", () => {
161
- it("returns true when endpoint responds 200", async () => {
162
- const adapter = createLocalLlmAdapter({
163
- provider: "ollama",
164
- embeddingModel: "nomic-embed-text",
165
- chatModel: "llama3",
166
- maxConcurrency: 2,
167
- embeddingDimensions: 384,
168
- });
169
- const fetchSpy = vi
170
- .spyOn(globalThis, "fetch")
171
- .mockResolvedValue(new Response(JSON.stringify({ models: [] }), { status: 200 }));
172
- expect(await adapter.isAvailable()).toBe(true);
173
- // Ollama uses /api/tags
174
- expect(fetchSpy.mock.calls[0]?.[0]).toBe("http://localhost:11434/api/tags");
175
- fetchSpy.mockRestore();
176
- });
177
- it("returns false when endpoint is unreachable", async () => {
178
- const adapter = createLocalLlmAdapter({
179
- provider: "ollama",
180
- embeddingModel: "nomic-embed-text",
181
- chatModel: "llama3",
182
- maxConcurrency: 2,
183
- embeddingDimensions: 384,
184
- });
185
- const fetchSpy = vi
186
- .spyOn(globalThis, "fetch")
187
- .mockRejectedValue(new Error("ECONNREFUSED"));
188
- expect(await adapter.isAvailable()).toBe(false);
189
- fetchSpy.mockRestore();
190
- });
191
- it("LM Studio uses /v1/models endpoint", async () => {
192
- const adapter = createLocalLlmAdapter({
193
- provider: "lm-studio",
194
- embeddingModel: "test",
195
- chatModel: "test",
196
- maxConcurrency: 2,
197
- embeddingDimensions: 384,
198
- });
199
- const fetchSpy = vi
200
- .spyOn(globalThis, "fetch")
201
- .mockResolvedValue(new Response(JSON.stringify({ data: [] }), { status: 200 }));
202
- await adapter.isAvailable();
203
- expect(fetchSpy.mock.calls[0]?.[0]).toBe("http://localhost:1234/v1/models");
204
- fetchSpy.mockRestore();
205
- });
206
- });
207
- // ── createAndVerifyAdapter ──────────────────────────────────
208
- describe("createAndVerifyAdapter", () => {
209
- it("returns null for undefined config", async () => {
210
- expect(await createAndVerifyAdapter(undefined)).toBeNull();
211
- });
212
- it("logs available status to stderr", async () => {
213
- const stderrSpy = vi.spyOn(process.stderr, "write").mockReturnValue(true);
214
- const fetchSpy = vi
215
- .spyOn(globalThis, "fetch")
216
- .mockResolvedValue(new Response(JSON.stringify({ models: [] }), { status: 200 }));
217
- const adapter = await createAndVerifyAdapter({
218
- provider: "ollama",
219
- embeddingModel: "nomic-embed-text",
220
- chatModel: "llama3",
221
- maxConcurrency: 2,
222
- embeddingDimensions: 384,
223
- });
224
- expect(adapter).not.toBeNull();
225
- const output = stderrSpy.mock.calls.map((c) => c[0]).join("");
226
- expect(output).toContain("BYO-LLM");
227
- expect(output).toContain("ollama");
228
- // API key should NEVER appear in stderr
229
- expect(output).not.toContain("sk-");
230
- stderrSpy.mockRestore();
231
- fetchSpy.mockRestore();
232
- });
233
- it("logs unavailable status without leaking apiKey", async () => {
234
- const stderrSpy = vi.spyOn(process.stderr, "write").mockReturnValue(true);
235
- const fetchSpy = vi
236
- .spyOn(globalThis, "fetch")
237
- .mockRejectedValue(new Error("ECONNREFUSED"));
238
- await createAndVerifyAdapter({
239
- provider: "openai-compatible",
240
- baseUrl: "http://localhost:9999",
241
- embeddingModel: "test",
242
- chatModel: "test",
243
- apiKey: "sk-supersecret-key",
244
- maxConcurrency: 2,
245
- embeddingDimensions: 384,
246
- });
247
- const output = stderrSpy.mock.calls.map((c) => c[0]).join("");
248
- expect(output).toContain("not reachable");
249
- expect(output).not.toContain("sk-supersecret-key");
250
- stderrSpy.mockRestore();
251
- fetchSpy.mockRestore();
252
- });
253
- });
@@ -1,187 +0,0 @@
1
- /**
2
- * Sprint L5.1 — Offline Integration Test Suite
3
- *
4
- * Proves that Local Mode makes exactly zero outbound network calls
5
- * under all code paths. Boots a mock QueryRouter in Local Mode,
6
- * exercises every local MCP tool, and asserts zero non-localhost fetch calls.
7
- *
8
- * CONTRACT: TL-1, TL-12, TL-15
9
- */
10
- import { afterAll, afterEach, beforeAll, describe, expect, it, vi, } from "vitest";
11
- import { getBlockedCount, resetBlockedCount, seal, unseal, } from "../proxy/network-firewall.js";
12
- const networkCallLog = [];
13
- let originalFetch;
14
- function extractHostname(url) {
15
- try {
16
- return new URL(url).hostname;
17
- }
18
- catch {
19
- return null;
20
- }
21
- }
22
- const LOCALHOST_NAMES = new Set(["localhost", "127.0.0.1", "::1", "0.0.0.0"]);
23
- function isLocalhostUrl(hostname) {
24
- if (!hostname)
25
- return false;
26
- return LOCALHOST_NAMES.has(hostname) || hostname.endsWith(".local");
27
- }
28
- function getNonLocalhostCalls() {
29
- return networkCallLog.filter((c) => !isLocalhostUrl(c.hostname));
30
- }
31
- // ── Mock Graph + Router ────────────────────────────────────────────
32
- function createMockLocalGraph() {
33
- const mockEntity = {
34
- key: "fn::test",
35
- kind: "function",
36
- name: "testFn",
37
- file_path: "src/test.ts",
38
- start_line: 1,
39
- end_line: 10,
40
- signature: "(): void",
41
- body: "function testFn() {}",
42
- fan_in: 2,
43
- fan_out: 1,
44
- risk_level: "normal",
45
- };
46
- const mockDb = {
47
- run: vi.fn((_query) => ({
48
- rows: [],
49
- })),
50
- };
51
- return {
52
- db: mockDb,
53
- getEntity: vi.fn().mockReturnValue(mockEntity),
54
- getCallersOf: vi.fn().mockReturnValue([]),
55
- getCalleesOf: vi.fn().mockReturnValue([]),
56
- getEntitiesByFile: vi.fn().mockReturnValue([mockEntity]),
57
- searchEntities: vi.fn().mockReturnValue([mockEntity]),
58
- getImports: vi.fn().mockReturnValue([]),
59
- hasRules: vi.fn().mockReturnValue(true),
60
- getRules: vi.fn().mockReturnValue([]),
61
- getPatterns: vi
62
- .fn()
63
- .mockReturnValue([
64
- { name: "test-pattern", type: "naming", adherence: 0.9 },
65
- ]),
66
- hasJustifications: vi.fn().mockReturnValue(true),
67
- getBusinessContext: vi.fn().mockReturnValue(null),
68
- getConventions: vi.fn().mockReturnValue([]),
69
- getCrossBoundaryLinks: vi.fn().mockReturnValue([]),
70
- getCriticalNodes: vi.fn().mockReturnValue([]),
71
- getDriftEntitiesForFile: vi.fn().mockReturnValue([]),
72
- upsertDriftEntity: vi.fn(),
73
- removeDriftEntity: vi.fn(),
74
- clearDriftOverlay: vi.fn(),
75
- getDriftSummary: vi
76
- .fn()
77
- .mockReturnValue({ added: 0, modified: 0, deleted: 0, total: 0 }),
78
- healthCheck: vi.fn().mockReturnValue({ status: "ok", latencyMs: 1 }),
79
- isLoaded: vi.fn().mockReturnValue(true),
80
- loadSnapshot: vi.fn(),
81
- loadRules: vi.fn(),
82
- loadPatterns: vi.fn(),
83
- loadJustifications: vi.fn(),
84
- applyDelta: vi.fn().mockReturnValue({
85
- applied: 0,
86
- deleted: 0,
87
- edges: 0,
88
- justifications: 0,
89
- overlayExpired: 0,
90
- }),
91
- getLocalProjectStats: vi.fn().mockReturnValue({
92
- fileCount: 100,
93
- entityCount: 500,
94
- edgeCount: 1200,
95
- communityCount: 10,
96
- ruleCount: 5,
97
- }),
98
- getDeepDiveProjectState: vi.fn().mockReturnValue("none"),
99
- persistCorrections: vi.fn(),
100
- getRuleHealthSummary: vi.fn().mockReturnValue(null),
101
- getRuleExceptions: vi.fn().mockReturnValue([]),
102
- };
103
- }
104
- // ── Test Suite ─────────────────────────────────────────────────────
105
- describe("Local Mode — Zero Network Leakage (L5.1)", () => {
106
- beforeAll(() => {
107
- originalFetch = globalThis.fetch;
108
- globalThis.fetch = ((input, init) => {
109
- const url = typeof input === "string"
110
- ? input
111
- : input instanceof URL
112
- ? input.toString()
113
- : input.url;
114
- const hostname = extractHostname(url);
115
- networkCallLog.push({
116
- url,
117
- method: init?.method ?? "GET",
118
- hostname,
119
- });
120
- if (hostname && !isLocalhostUrl(hostname)) {
121
- return Promise.reject(new Error(`[TEST GUARD] Outbound network call detected to ${hostname}: ${url}`));
122
- }
123
- return originalFetch(input, init);
124
- });
125
- });
126
- afterAll(() => {
127
- globalThis.fetch = originalFetch;
128
- });
129
- afterEach(() => {
130
- unseal();
131
- resetBlockedCount();
132
- networkCallLog.length = 0;
133
- });
134
- it("NetworkFirewall blocks outbound calls with zero leakage", async () => {
135
- seal();
136
- expect(getBlockedCount()).toBe(0);
137
- const externalUrls = [
138
- "https://app.unerr.dev/api/health",
139
- "https://api.anthropic.com/v1/messages",
140
- "https://cloud.example.com/sync",
141
- ];
142
- for (const url of externalUrls) {
143
- const result = await globalThis.fetch(url).catch((e) => e);
144
- expect(result).toBeInstanceOf(Error);
145
- expect(result.message).toContain("[NetworkFirewall]");
146
- }
147
- expect(getBlockedCount()).toBe(3);
148
- });
149
- it("all 14+ local MCP tools respond without network calls via QueryRouter", async () => {
150
- seal();
151
- networkCallLog.length = 0;
152
- const { QueryRouter } = await import("../intelligence/query-router.js");
153
- const graph = createMockLocalGraph();
154
- const router = new QueryRouter(graph);
155
- router.setMode("local", "Local Mode");
156
- const localTools = [
157
- { name: "get_function", args: { key: "fn::test" } },
158
- { name: "get_class", args: { key: "cls::test" } },
159
- { name: "get_file", args: { key: "src/test.ts" } },
160
- { name: "get_callers", args: { key: "fn::test" } },
161
- { name: "get_callees", args: { key: "fn::test" } },
162
- { name: "get_imports", args: { file_path: "src/test.ts" } },
163
- { name: "search_code", args: { query: "test" } },
164
- { name: "get_rules", args: {} },
165
- { name: "get_business_context", args: { key: "fn::test" } },
166
- { name: "get_conventions", args: {} },
167
- { name: "get_cross_boundary_links", args: {} },
168
- { name: "get_critical_nodes", args: {} },
169
- ];
170
- for (const tool of localTools) {
171
- const result = await router.execute(tool.name, tool.args);
172
- expect(result._meta.source).toBe("local");
173
- }
174
- expect(getNonLocalhostCalls().length).toBe(0);
175
- expect(getBlockedCount()).toBe(0);
176
- });
177
- it("aggregate: zero non-localhost calls across full Local Mode exercise", () => {
178
- seal();
179
- networkCallLog.length = 0;
180
- const stderrSpy = vi.spyOn(process.stderr, "write").mockReturnValue(true);
181
- void globalThis.fetch("http://localhost:11434/api/tags").catch(() => { });
182
- void globalThis.fetch("http://127.0.0.1:8080/health").catch(() => { });
183
- expect(getNonLocalhostCalls().length).toBe(0);
184
- expect(getBlockedCount()).toBe(0);
185
- stderrSpy.mockRestore();
186
- });
187
- });