@unerr-ai/unerr 0.1.6 → 0.1.8

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 +79 -196
  2. package/dist/cli.js +19821 -16589
  3. package/package.json +17 -3
  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,200 +0,0 @@
1
- /**
2
- * Sprint N.7-N.8: Blast radius accuracy + performance tests.
3
- */
4
- import { describe, expect, it } from "vitest";
5
- import { buildReverseAdjacency, computeBlastRadius, computeFileBlastRadius, } from "../intelligence/blast-radius.js";
6
- import { entityKey } from "../intelligence/indexer/entity-key.js";
7
- function makeEntity(name, filePath) {
8
- return {
9
- key: entityKey(filePath, "function", name, ""),
10
- kind: "function",
11
- name,
12
- file_path: filePath,
13
- start_line: 1,
14
- end_line: 5,
15
- signature: `${name}()`,
16
- body_hash: "h",
17
- exported: true,
18
- parent_key: null,
19
- language: "typescript",
20
- is_async: false,
21
- parameter_count: 0,
22
- doc: null,
23
- community: 0,
24
- risk_level: "normal",
25
- };
26
- }
27
- describe("Blast Radius Engine (N.1-N.5)", () => {
28
- it("returns all direct callers at hop=1", () => {
29
- const target = makeEntity("target", "src/core.ts");
30
- const callers = Array.from({ length: 10 }, (_, i) => makeEntity(`caller${i}`, `src/caller${i}.ts`));
31
- const entities = new Map([
32
- [target.key, target],
33
- ...callers.map((c) => [c.key, c]),
34
- ]);
35
- const edges = callers.map((c) => ({
36
- from_key: c.key,
37
- to_key: target.key,
38
- type: "calls",
39
- file_path: c.file_path,
40
- line: 1,
41
- }));
42
- const adj = buildReverseAdjacency(edges);
43
- const result = computeBlastRadius(target.key, entities, adj);
44
- expect(result.totalAffected).toBe(10);
45
- expect(result.hops.get(1)?.length).toBe(10);
46
- });
47
- it("traverses 3 hops transitively", () => {
48
- const a = makeEntity("a", "src/a.ts");
49
- const b = makeEntity("b", "src/b.ts");
50
- const c = makeEntity("c", "src/c.ts");
51
- const d = makeEntity("d", "src/d.ts");
52
- const entities = new Map([
53
- [a.key, a],
54
- [b.key, b],
55
- [c.key, c],
56
- [d.key, d],
57
- ]);
58
- const edges = [
59
- {
60
- from_key: b.key,
61
- to_key: a.key,
62
- type: "calls",
63
- file_path: "b.ts",
64
- line: 1,
65
- },
66
- {
67
- from_key: c.key,
68
- to_key: b.key,
69
- type: "calls",
70
- file_path: "c.ts",
71
- line: 1,
72
- },
73
- {
74
- from_key: d.key,
75
- to_key: c.key,
76
- type: "calls",
77
- file_path: "d.ts",
78
- line: 1,
79
- },
80
- ];
81
- const adj = buildReverseAdjacency(edges);
82
- const result = computeBlastRadius(a.key, entities, adj, { maxHops: 3 });
83
- expect(result.hops.get(1)?.length).toBe(1);
84
- expect(result.hops.get(2)?.length).toBe(1);
85
- expect(result.hops.get(3)?.length).toBe(1);
86
- expect(result.totalAffected).toBe(3);
87
- });
88
- it("generates suggestions for critical entities", () => {
89
- const target = makeEntity("hub", "src/hub.ts");
90
- const critical = {
91
- ...makeEntity("crit", "src/crit.ts"),
92
- risk_level: "critical",
93
- };
94
- const entities = new Map([
95
- [target.key, target],
96
- [critical.key, critical],
97
- ]);
98
- const edges = [
99
- {
100
- from_key: critical.key,
101
- to_key: target.key,
102
- type: "calls",
103
- file_path: "crit.ts",
104
- line: 1,
105
- },
106
- ];
107
- const adj = buildReverseAdjacency(edges);
108
- const result = computeBlastRadius(target.key, entities, adj);
109
- expect(result.riskSummary.critical).toBe(1);
110
- expect(result.suggestions.some((s) => s.includes("overload") || s.includes("adapter"))).toBe(true);
111
- });
112
- it("file-level blast radius returns entities in other files", () => {
113
- const internal1 = makeEntity("fn1", "src/target.ts");
114
- const internal2 = makeEntity("fn2", "src/target.ts");
115
- const external = makeEntity("caller", "src/other.ts");
116
- const entities = new Map([
117
- [internal1.key, internal1],
118
- [internal2.key, internal2],
119
- [external.key, external],
120
- ]);
121
- const edges = [
122
- {
123
- from_key: external.key,
124
- to_key: internal1.key,
125
- type: "calls",
126
- file_path: "other.ts",
127
- line: 1,
128
- },
129
- ];
130
- const adj = buildReverseAdjacency(edges);
131
- const result = computeFileBlastRadius("src/target.ts", entities, adj);
132
- expect(result.totalAffected).toBe(1);
133
- expect(result.affectedFiles).toContain("src/other.ts");
134
- expect(result.affectedFiles).not.toContain("src/target.ts");
135
- });
136
- it("handles entity with no callers", () => {
137
- const target = makeEntity("isolated", "src/isolated.ts");
138
- const entities = new Map([[target.key, target]]);
139
- const adj = buildReverseAdjacency([]);
140
- const result = computeBlastRadius(target.key, entities, adj);
141
- expect(result.totalAffected).toBe(0);
142
- expect(result.hops.size).toBe(0);
143
- });
144
- it("respects maxResults limit", () => {
145
- const target = makeEntity("popular", "src/pop.ts");
146
- const callers = Array.from({ length: 600 }, (_, i) => makeEntity(`c${i}`, `src/c${i}.ts`));
147
- const entities = new Map([
148
- [target.key, target],
149
- ...callers.map((c) => [c.key, c]),
150
- ]);
151
- const edges = callers.map((c) => ({
152
- from_key: c.key,
153
- to_key: target.key,
154
- type: "calls",
155
- file_path: c.file_path,
156
- line: 1,
157
- }));
158
- const adj = buildReverseAdjacency(edges);
159
- const result = computeBlastRadius(target.key, entities, adj, {
160
- maxResults: 100,
161
- });
162
- expect(result.totalAffected).toBeLessThanOrEqual(100);
163
- });
164
- it("completes in <5ms for large graphs", () => {
165
- const target = makeEntity("center", "src/center.ts");
166
- const allEntities = [target];
167
- const allEdges = [];
168
- for (let i = 0; i < 200; i++) {
169
- const hop1 = makeEntity(`h1_${i}`, `src/h1_${i}.ts`);
170
- allEntities.push(hop1);
171
- allEdges.push({
172
- from_key: hop1.key,
173
- to_key: target.key,
174
- type: "calls",
175
- file_path: hop1.file_path,
176
- line: 1,
177
- });
178
- for (let j = 0; j < 5; j++) {
179
- const hop2 = makeEntity(`h2_${i}_${j}`, `src/h2_${i}_${j}.ts`);
180
- allEntities.push(hop2);
181
- allEdges.push({
182
- from_key: hop2.key,
183
- to_key: hop1.key,
184
- type: "calls",
185
- file_path: hop2.file_path,
186
- line: 1,
187
- });
188
- }
189
- }
190
- const entities = new Map(allEntities.map((e) => [e.key, e]));
191
- const adj = buildReverseAdjacency(allEdges);
192
- const start = performance.now();
193
- const result = computeBlastRadius(target.key, entities, adj, {
194
- maxHops: 3,
195
- });
196
- const elapsed = performance.now() - start;
197
- expect(result.totalAffected).toBeGreaterThan(100);
198
- expect(elapsed).toBeLessThan(5);
199
- });
200
- });
@@ -1,37 +0,0 @@
1
- /**
2
- * Layer 12 DM-0 invariant: `src/proxy/bridge.ts` must remain a pure stdio↔UDS
3
- * relay. It owns no intelligence — the per-repo `unerr` process does.
4
- *
5
- * Static-analysis test: re-grepping the bridge source on every CI run is the
6
- * cheapest, hardest-to-cheat guard against accidental re-entanglement.
7
- */
8
- import { readFileSync, statSync } from "node:fs";
9
- import { resolve } from "node:path";
10
- import { describe, expect, it } from "vitest";
11
- const BRIDGE_PATH = resolve(__dirname, "../proxy/bridge.ts");
12
- describe("bridge isolation (DM-0)", () => {
13
- const source = readFileSync(BRIDGE_PATH, "utf-8");
14
- it("imports nothing from src/intelligence/", () => {
15
- // Match both static and dynamic imports at any depth of relative path.
16
- const intelligence = /(?:from|import\()\s*["'][^"']*\/intelligence\//;
17
- expect(source).not.toMatch(intelligence);
18
- });
19
- it("imports nothing from src/behaviors/", () => {
20
- const behaviors = /(?:from|import\()\s*["'][^"']*\/behaviors\//;
21
- expect(source).not.toMatch(behaviors);
22
- });
23
- it("imports nothing from src/tracking/", () => {
24
- // Tier-2 modules (shadow ledger, token flow, persistence effectiveness)
25
- // also belong on the per-repo side, not in the bridge.
26
- const tracking = /(?:from|import\()\s*["'][^"']*\/tracking\//;
27
- expect(source).not.toMatch(tracking);
28
- });
29
- it("stays under the 200-LOC budget", () => {
30
- const lines = source.split("\n").length;
31
- expect(lines).toBeLessThanOrEqual(200);
32
- });
33
- it("file is small (sanity: a relay should be a few KB, not megabytes)", () => {
34
- const { size } = statSync(BRIDGE_PATH);
35
- expect(size).toBeLessThan(20_000); // 20 KB ceiling
36
- });
37
- });
@@ -1,53 +0,0 @@
1
- import { describe, expect, it } from "vitest";
2
- import { enforceBudget, isStructuredContent, } from "../proxy/budget-enforcer.js";
3
- describe("enforceBudget", () => {
4
- it("passes through content within budget", () => {
5
- const content = "short content";
6
- const result = enforceBudget(content, 1000);
7
- expect(result.content).toBe(content);
8
- expect(result.truncated).toBe(false);
9
- expect(result.deliveredTokens).toBe(result.originalTokens);
10
- });
11
- it("truncates content exceeding budget", () => {
12
- const content = Array.from({ length: 500 }, (_, i) => `Line ${i}: some content here that takes up space`).join("\n");
13
- const result = enforceBudget(content, 200);
14
- expect(result.truncated).toBe(true);
15
- expect(result.deliveredTokens).toBeLessThan(result.originalTokens);
16
- expect(result.content).toContain("[...");
17
- expect(result.content).toContain("truncated");
18
- });
19
- it("preserves head and tail of truncated content", () => {
20
- const lines = Array.from({ length: 100 }, (_, i) => `Line ${i}`);
21
- const content = lines.join("\n");
22
- const result = enforceBudget(content, 100);
23
- expect(result.content).toContain("Line 0");
24
- expect(result.content).toContain("Line 99");
25
- });
26
- it("uses default budget of 4000 tokens", () => {
27
- const small = "hello world";
28
- const result = enforceBudget(small);
29
- expect(result.truncated).toBe(false);
30
- });
31
- it("reports original and delivered token counts", () => {
32
- const content = Array.from({ length: 200 }, (_, i) => `Data line ${i} with some padding text`).join("\n");
33
- const result = enforceBudget(content, 100);
34
- expect(result.originalTokens).toBeGreaterThan(100);
35
- expect(result.deliveredTokens).toBeLessThanOrEqual(result.originalTokens);
36
- });
37
- });
38
- describe("isStructuredContent", () => {
39
- it("returns true for JSON objects", () => {
40
- expect(isStructuredContent('{"key": "value"}')).toBe(true);
41
- });
42
- it("returns true for non-string values", () => {
43
- expect(isStructuredContent({ key: "value" })).toBe(true);
44
- expect(isStructuredContent(42)).toBe(true);
45
- expect(isStructuredContent(null)).toBe(true);
46
- });
47
- it("returns false for plain text", () => {
48
- expect(isStructuredContent("hello world")).toBe(false);
49
- });
50
- it("returns false for invalid JSON", () => {
51
- expect(isStructuredContent("{not valid json}")).toBe(false);
52
- });
53
- });
@@ -1,82 +0,0 @@
1
- /**
2
- * Performance benchmark: Rust #[cfg(test)] detection overhead.
3
- *
4
- * Verifies that AST-level test scope detection adds <50ms overhead
5
- * for a representative Rust project (1000 entities across multiple files).
6
- */
7
- import { describe, expect, it } from "vitest";
8
- import { extractEntities } from "../intelligence/ast-extractor.js";
9
- /**
10
- * Generate a synthetic Rust file with N functions, some inside #[cfg(test)] modules.
11
- */
12
- function generateRustFile(fnCount, withCfgTest) {
13
- const lines = [];
14
- const prodCount = Math.floor(fnCount * 0.7);
15
- const testCount = fnCount - prodCount;
16
- // Production functions
17
- for (let i = 0; i < prodCount; i++) {
18
- lines.push(`pub fn prod_fn_${i}(x: i32) -> i32 {`);
19
- lines.push(` x + ${i}`);
20
- lines.push("}");
21
- lines.push("");
22
- }
23
- if (withCfgTest) {
24
- lines.push("#[cfg(test)]");
25
- lines.push("mod tests {");
26
- for (let i = 0; i < testCount; i++) {
27
- lines.push(" #[test]");
28
- lines.push(` fn test_fn_${i}() {`);
29
- lines.push(` assert_eq!(prod_fn_${i}(1), ${i + 1});`);
30
- lines.push(" }");
31
- lines.push("");
32
- }
33
- lines.push("}");
34
- }
35
- return lines.join("\n");
36
- }
37
- describe("Rust #[cfg(test)] detection performance", () => {
38
- it("extracts entities from 50 Rust files (1000+ entities) in <50ms", () => {
39
- // Generate 50 files × 20 functions each = 1000 entities
40
- const files = [];
41
- for (let i = 0; i < 50; i++) {
42
- files.push({
43
- content: generateRustFile(20, i % 2 === 0), // Half have cfg(test)
44
- path: `src/module_${i}.rs`,
45
- });
46
- }
47
- const start = performance.now();
48
- let totalEntities = 0;
49
- let testEntities = 0;
50
- for (const file of files) {
51
- const entities = extractEntities(file.content, file.path);
52
- totalEntities += entities.length;
53
- testEntities += entities.filter((e) => e.is_test).length;
54
- }
55
- const elapsed = performance.now() - start;
56
- // Should extract a meaningful number of entities
57
- expect(totalEntities).toBeGreaterThan(500);
58
- // Performance: regex extraction of 1000+ entities must be <50ms
59
- expect(elapsed).toBeLessThan(50);
60
- // Verify test detection works (files with cfg(test) modules produce test entities via regex)
61
- // Note: regex-based extraction doesn't detect cfg(test) — only tree-sitter AST does.
62
- // The regex path relies on file-level isTestFile() for is_test marking.
63
- // This benchmark validates that regex extraction overhead is negligible.
64
- console.error(` Extracted ${totalEntities} entities (${testEntities} marked test) from ${files.length} files in ${elapsed.toFixed(2)}ms`);
65
- });
66
- it("regex extraction adds negligible overhead for is_test field", () => {
67
- const content = generateRustFile(100, true);
68
- // Warm up
69
- extractEntities(content, "src/lib.rs");
70
- // Benchmark: 100 iterations
71
- const iterations = 100;
72
- const start = performance.now();
73
- for (let i = 0; i < iterations; i++) {
74
- extractEntities(content, `src/mod_${i}.rs`);
75
- }
76
- const elapsed = performance.now() - start;
77
- const perFile = elapsed / iterations;
78
- // Each file extraction should be <0.5ms (regex is fast)
79
- expect(perFile).toBeLessThan(0.5);
80
- console.error(` Per-file extraction: ${perFile.toFixed(3)}ms (${iterations} iterations, ${elapsed.toFixed(2)}ms total)`);
81
- });
82
- });
@@ -1,190 +0,0 @@
1
- /**
2
- * BA-3.5: Change Impact Narrative + Agent-as-LLM Bridge tests.
3
- *
4
- * Verifies:
5
- * - Narrative includes all behavior signals
6
- * - Markdown well-formed
7
- * - Risk level computed correctly
8
- * - Counterfactual framing always present
9
- * - Agent-as-LLM templates, timeout, budget, follow-through
10
- */
11
- import { describe, expect, it } from "vitest";
12
- import { AgentLlmBridge } from "../behaviors/agent-llm-bridge.js";
13
- import { ChangeNarrativeBehavior } from "../behaviors/change-narrative.js";
14
- function makeCtx() {
15
- return {
16
- toolName: "__session_end__",
17
- args: {},
18
- sessionId: "test-session",
19
- };
20
- }
21
- // ── Change Narrative Tests ─────────────────────────────────────
22
- describe("Change Impact Narrative (BA-3.2)", () => {
23
- describe("Behavior Identity", () => {
24
- it("has correct id and hooks", () => {
25
- const narrative = new ChangeNarrativeBehavior();
26
- expect(narrative.id).toBe("change_narrative");
27
- expect(narrative.hooks).toContain("session_end");
28
- expect(narrative.defaultLevel).toBe("suggestion");
29
- });
30
- });
31
- describe("Empty Session", () => {
32
- it("returns null when no behaviors have data", async () => {
33
- const narrative = new ChangeNarrativeBehavior();
34
- const output = await narrative.onSessionEnd(makeCtx());
35
- expect(output).toBeNull();
36
- });
37
- });
38
- describe("Risk Level Computation", () => {
39
- it("returns low risk for clean session", async () => {
40
- const narrative = new ChangeNarrativeBehavior();
41
- const output = await narrative.onSessionEnd(makeCtx());
42
- expect(output).toBeNull();
43
- });
44
- });
45
- describe("Counterfactual Framing", () => {
46
- it("produces counterfactual for clean sessions (no issues)", async () => {
47
- const narrative = new ChangeNarrativeBehavior();
48
- const output = await narrative.onSessionEnd(makeCtx());
49
- if (output) {
50
- const ctx = output._context?.change_narrative;
51
- expect(ctx.counterfactual).toContain("Clean session");
52
- }
53
- });
54
- });
55
- describe("Markdown Output", () => {
56
- it("generates well-formed markdown when behaviors have data", async () => {
57
- const narrative = new ChangeNarrativeBehavior();
58
- const output = await narrative.onSessionEnd(makeCtx());
59
- if (output) {
60
- const ctx = output._context?.change_narrative;
61
- expect(ctx.markdown).toContain("## Change Impact");
62
- }
63
- });
64
- });
65
- });
66
- // ── Agent-as-LLM Bridge Tests ──────────────────────────────────
67
- describe("Agent-as-LLM Bridge (BA-3.3)", () => {
68
- describe("Template System", () => {
69
- it("lists all available templates", () => {
70
- const templates = AgentLlmBridge.getTemplates();
71
- expect(templates).toContain("session_resume");
72
- expect(templates).toContain("doc_generation");
73
- expect(templates).toContain("loop_diagnosis");
74
- expect(templates).toContain("convention_fix");
75
- expect(templates).toContain("cascade_fix");
76
- expect(templates).toContain("architecture_alternative");
77
- expect(templates.length).toBeGreaterThanOrEqual(7);
78
- });
79
- it("returns template definition with prefix and maxTokens", () => {
80
- const def = AgentLlmBridge.getTemplateDefinition("loop_diagnosis");
81
- expect(def.prefix).toContain("Analyze why");
82
- expect(def.maxTokens).toBe(500);
83
- expect(def.priority).toBe("high");
84
- });
85
- it("creates prompt with template prefix and context", () => {
86
- const bridge = new AgentLlmBridge();
87
- const prompt = bridge.createPrompt("doc_generation", "Function processPayment(amount: number, currency: string): Promise<Receipt>");
88
- expect(prompt.template).toBe("doc_generation");
89
- expect(prompt.content).toContain("Generate documentation");
90
- expect(prompt.content).toContain("processPayment");
91
- expect(prompt.priority).toBe("low");
92
- });
93
- });
94
- describe("Timeout Handling", () => {
95
- it("defaults to 5000ms timeout", () => {
96
- const bridge = new AgentLlmBridge();
97
- const prompt = bridge.createPrompt("session_resume", "test context");
98
- expect(prompt.timeoutMs).toBe(5000);
99
- });
100
- it("accepts custom timeout", () => {
101
- const bridge = new AgentLlmBridge();
102
- const prompt = bridge.createPrompt("session_resume", "test context", {
103
- timeoutMs: 3000,
104
- });
105
- expect(prompt.timeoutMs).toBe(3000);
106
- });
107
- });
108
- describe("Fallback Handling", () => {
109
- it("stores fallback content", () => {
110
- const bridge = new AgentLlmBridge();
111
- const prompt = bridge.createPrompt("doc_generation", "test", {
112
- fallback: "AST-based docs only",
113
- });
114
- expect(prompt.fallbackContent).toBe("AST-based docs only");
115
- });
116
- it("fallback is null by default", () => {
117
- const bridge = new AgentLlmBridge();
118
- const prompt = bridge.createPrompt("doc_generation", "test");
119
- expect(prompt.fallbackContent).toBeNull();
120
- });
121
- });
122
- describe("Injection and Budget", () => {
123
- it("injects prompt and tracks it", () => {
124
- const bridge = new AgentLlmBridge();
125
- const prompt = bridge.createPrompt("loop_diagnosis", "4 failed attempts on processPayment");
126
- const injected = bridge.inject(prompt);
127
- expect(injected).toContain("Analyze why");
128
- expect(bridge.getStats().totalInjected).toBe(1);
129
- });
130
- it("respects per-call prompt budget", () => {
131
- const bridge = new AgentLlmBridge();
132
- for (let i = 0; i < 5; i++) {
133
- const prompt = bridge.createPrompt("loop_diagnosis", "x".repeat(2000));
134
- bridge.inject(prompt);
135
- }
136
- const overBudget = bridge.createPrompt("doc_generation", "x".repeat(2000));
137
- const result = bridge.inject(overBudget);
138
- expect(result).toBe("");
139
- });
140
- it("resets budget between calls", () => {
141
- const bridge = new AgentLlmBridge();
142
- const longContext = "x".repeat(3800);
143
- const prompt1 = bridge.createPrompt("loop_diagnosis", longContext);
144
- bridge.inject(prompt1);
145
- bridge.resetCallBudget();
146
- const prompt2 = bridge.createPrompt("doc_generation", "short context");
147
- const result = bridge.inject(prompt2);
148
- expect(result.length).toBeGreaterThan(0);
149
- });
150
- });
151
- describe("Follow-Through Tracking", () => {
152
- it("starts with 0% follow-through rate", () => {
153
- const bridge = new AgentLlmBridge();
154
- expect(bridge.getFollowThroughRate()).toBe(0);
155
- });
156
- it("tracks follow-through when recorded", () => {
157
- const bridge = new AgentLlmBridge();
158
- const prompt = bridge.createPrompt("doc_generation", "test");
159
- bridge.inject(prompt);
160
- const injectionId = bridge.getLastInjectionId();
161
- expect(injectionId).toBeTruthy();
162
- bridge.recordFollowThrough(injectionId);
163
- expect(bridge.getStats().followedThrough).toBe(1);
164
- });
165
- it("computes follow-through rate correctly", () => {
166
- const bridge = new AgentLlmBridge();
167
- const p1 = bridge.createPrompt("doc_generation", "test1");
168
- bridge.inject(p1);
169
- const id1 = bridge.getLastInjectionId();
170
- bridge.recordFollowThrough(id1);
171
- bridge.resetCallBudget();
172
- const p2 = bridge.createPrompt("convention_fix", "test2");
173
- bridge.inject(p2);
174
- expect(bridge.getFollowThroughRate()).toBe(0.5);
175
- });
176
- });
177
- describe("Stats", () => {
178
- it("tracks injections by template type", () => {
179
- const bridge = new AgentLlmBridge();
180
- bridge.inject(bridge.createPrompt("doc_generation", "a"));
181
- bridge.resetCallBudget();
182
- bridge.inject(bridge.createPrompt("doc_generation", "b"));
183
- bridge.resetCallBudget();
184
- bridge.inject(bridge.createPrompt("loop_diagnosis", "c"));
185
- const stats = bridge.getStats();
186
- expect(stats.byTemplate.doc_generation).toBe(2);
187
- expect(stats.byTemplate.loop_diagnosis).toBe(1);
188
- });
189
- });
190
- });