@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,112 +0,0 @@
1
- /**
2
- * Sprint 7.3: Pending Violation Store tests.
3
- */
4
- import { describe, expect, it } from "vitest";
5
- import { PendingViolationStore } from "../tracking/pending-violations.js";
6
- function makeViolation(file, rule, message, line) {
7
- return {
8
- ruleKey: `rule-${rule}`,
9
- ruleName: rule,
10
- severity: "warning",
11
- message,
12
- filePath: file,
13
- line,
14
- };
15
- }
16
- describe("PendingViolationStore", () => {
17
- it("starts empty", () => {
18
- const store = new PendingViolationStore();
19
- expect(store.hasPending).toBe(false);
20
- expect(store.count).toBe(0);
21
- expect(store.drain()).toBeUndefined();
22
- });
23
- it("stores and drains violations", () => {
24
- const store = new PendingViolationStore();
25
- store.addViolations("src/a.ts", [
26
- makeViolation("src/a.ts", "naming", "bad name", 10),
27
- ]);
28
- expect(store.hasPending).toBe(true);
29
- expect(store.count).toBe(1);
30
- const drained = store.drain();
31
- expect(drained).toBeDefined();
32
- expect(drained).toHaveLength(1);
33
- expect(drained?.[0]?.file).toBe("src/a.ts");
34
- expect(drained?.[0]?.rule).toBe("naming");
35
- expect(drained?.[0]?.message).toBe("bad name");
36
- expect(drained?.[0]?.line).toBe(10);
37
- // After drain, empty
38
- expect(store.hasPending).toBe(false);
39
- expect(store.drain()).toBeUndefined();
40
- });
41
- it("replaces violations for same file", () => {
42
- const store = new PendingViolationStore();
43
- store.addViolations("src/a.ts", [
44
- makeViolation("src/a.ts", "naming", "v1"),
45
- ]);
46
- store.addViolations("src/a.ts", [
47
- makeViolation("src/a.ts", "naming", "v2"),
48
- makeViolation("src/a.ts", "structure", "v3"),
49
- ]);
50
- expect(store.count).toBe(2);
51
- const drained = store.drain();
52
- expect(drained).toHaveLength(2);
53
- expect(drained?.[0]?.message).toBe("v2");
54
- });
55
- it("removes file entry when adding empty violations", () => {
56
- const store = new PendingViolationStore();
57
- store.addViolations("src/a.ts", [
58
- makeViolation("src/a.ts", "naming", "v1"),
59
- ]);
60
- store.addViolations("src/a.ts", []);
61
- expect(store.hasPending).toBe(false);
62
- expect(store.count).toBe(0);
63
- });
64
- it("aggregates violations across multiple files", () => {
65
- const store = new PendingViolationStore();
66
- store.addViolations("src/a.ts", [
67
- makeViolation("src/a.ts", "naming", "a1"),
68
- ]);
69
- store.addViolations("src/b.ts", [
70
- makeViolation("src/b.ts", "naming", "b1"),
71
- makeViolation("src/b.ts", "structure", "b2"),
72
- ]);
73
- expect(store.count).toBe(3);
74
- const drained = store.drain();
75
- expect(drained).toHaveLength(3);
76
- });
77
- it("drains for specific files only", () => {
78
- const store = new PendingViolationStore();
79
- store.addViolations("src/a.ts", [
80
- makeViolation("src/a.ts", "naming", "a1"),
81
- ]);
82
- store.addViolations("src/b.ts", [
83
- makeViolation("src/b.ts", "naming", "b1"),
84
- ]);
85
- const drained = store.drainForFiles(["src/a.ts"]);
86
- expect(drained).toHaveLength(1);
87
- expect(drained?.[0]?.file).toBe("src/a.ts");
88
- // src/b.ts should still be pending
89
- expect(store.hasPending).toBe(true);
90
- expect(store.count).toBe(1);
91
- });
92
- it("drainForFiles returns undefined when no matching files", () => {
93
- const store = new PendingViolationStore();
94
- store.addViolations("src/a.ts", [
95
- makeViolation("src/a.ts", "naming", "a1"),
96
- ]);
97
- expect(store.drainForFiles(["src/b.ts"])).toBeUndefined();
98
- expect(store.hasPending).toBe(true);
99
- });
100
- it("clear removes everything", () => {
101
- const store = new PendingViolationStore();
102
- store.addViolations("src/a.ts", [
103
- makeViolation("src/a.ts", "naming", "a1"),
104
- ]);
105
- store.addViolations("src/b.ts", [
106
- makeViolation("src/b.ts", "naming", "b1"),
107
- ]);
108
- store.clear();
109
- expect(store.hasPending).toBe(false);
110
- expect(store.count).toBe(0);
111
- });
112
- });
@@ -1,143 +0,0 @@
1
- import { mkdirSync, rmSync } from "node:fs";
2
- import os from "node:os";
3
- import { join } from "node:path";
4
- import { afterEach, beforeEach, describe, expect, it } from "vitest";
5
- import { PersistenceEffectivenessTracker } from "../tracking/persistence-effectiveness.js";
6
- import { TokenFlowWriter, readTokenFlowEvents, } from "../tracking/token-flow.js";
7
- function verdicts(unerrDir) {
8
- return readTokenFlowEvents(unerrDir)
9
- .filter((e) => e.mechanism === "persistent_memory")
10
- .map((e) => (e.detail ?? {}));
11
- }
12
- describe("PersistenceEffectivenessTracker", () => {
13
- let tmpDir;
14
- let unerrDir;
15
- let writer;
16
- let tracker;
17
- beforeEach(() => {
18
- tmpDir = join(os.tmpdir(), `unerr-eff-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`);
19
- unerrDir = join(tmpDir, ".unerr");
20
- mkdirSync(unerrDir, { recursive: true });
21
- writer = new TokenFlowWriter(unerrDir, "test-session");
22
- tracker = new PersistenceEffectivenessTracker(writer, { windowTurns: 5 });
23
- });
24
- afterEach(() => {
25
- rmSync(tmpDir, { recursive: true, force: true });
26
- });
27
- it("emits a fired verdict when a signal first fires", () => {
28
- tracker.recordSignalFired({
29
- kind: "fact_injected",
30
- signal_id: "fact-1",
31
- entity_key: "EntityA",
32
- turn: 1,
33
- });
34
- const v = verdicts(unerrDir);
35
- expect(v).toHaveLength(1);
36
- expect(v[0]?.kind).toBe("fact_injected");
37
- expect(v[0]?.verdict).toBe("fired");
38
- expect(v[0]?.signal_id).toBe("fact-1");
39
- });
40
- it("re-firing within window counts as a reinforcement, not a new fired event", () => {
41
- tracker.recordSignalFired({
42
- kind: "fact_injected",
43
- signal_id: "fact-1",
44
- entity_key: "EntityA",
45
- turn: 1,
46
- });
47
- tracker.recordSignalFired({
48
- kind: "fact_injected",
49
- signal_id: "fact-1",
50
- entity_key: "EntityA",
51
- turn: 2,
52
- });
53
- const fired = verdicts(unerrDir).filter((v) => v.verdict === "fired");
54
- expect(fired).toHaveLength(1);
55
- });
56
- it("classifies a re-fired signal with no correction as reinforced on close", () => {
57
- tracker.recordSignalFired({
58
- kind: "fact_injected",
59
- signal_id: "fact-1",
60
- entity_key: "EntityA",
61
- turn: 1,
62
- });
63
- tracker.recordSignalFired({
64
- kind: "fact_injected",
65
- signal_id: "fact-1",
66
- entity_key: "EntityA",
67
- turn: 2,
68
- });
69
- tracker.closeWindow(7);
70
- const resolved = verdicts(unerrDir).find((v) => v.verdict === "reinforced");
71
- expect(resolved?.signal_id).toBe("fact-1");
72
- });
73
- it("classifies as acted_on when entity received an edit and no correction", () => {
74
- tracker.recordSignalFired({
75
- kind: "convention_injected",
76
- signal_id: "conv-1",
77
- entity_key: "EntityB",
78
- turn: 1,
79
- });
80
- tracker.recordEdit("EntityB");
81
- tracker.closeWindow(7);
82
- const resolved = verdicts(unerrDir).find((v) => v.verdict === "acted_on");
83
- expect(resolved?.signal_id).toBe("conv-1");
84
- });
85
- it("classifies as corrected when a correction fires for the entity", () => {
86
- tracker.recordSignalFired({
87
- kind: "convention_injected",
88
- signal_id: "conv-2",
89
- entity_key: "EntityC",
90
- turn: 1,
91
- });
92
- tracker.recordEdit("EntityC");
93
- tracker.recordCorrection("EntityC", "circuit_breaker");
94
- tracker.closeWindow(7);
95
- const resolved = verdicts(unerrDir).find((v) => v.verdict === "corrected");
96
- expect(resolved?.signal_id).toBe("conv-2");
97
- });
98
- it("classifies negative_warned with no correction as caught", () => {
99
- tracker.recordSignalFired({
100
- kind: "negative_warned",
101
- signal_id: "neg-1",
102
- entity_key: "EntityD",
103
- turn: 1,
104
- });
105
- tracker.closeWindow(7);
106
- const resolved = verdicts(unerrDir).find((v) => v.verdict === "caught");
107
- expect(resolved?.signal_id).toBe("neg-1");
108
- });
109
- it("classifies as ignored when nothing happens in the window", () => {
110
- tracker.recordSignalFired({
111
- kind: "fact_injected",
112
- signal_id: "fact-99",
113
- entity_key: "EntityZ",
114
- turn: 1,
115
- });
116
- tracker.closeWindow(7);
117
- const resolved = verdicts(unerrDir).find((v) => v.verdict === "ignored");
118
- expect(resolved?.signal_id).toBe("fact-99");
119
- });
120
- it("does not close windows still inside the K-turn observation period", () => {
121
- tracker.recordSignalFired({
122
- kind: "fact_injected",
123
- signal_id: "fact-young",
124
- entity_key: null,
125
- turn: 5,
126
- });
127
- tracker.closeWindow(7); // delta 2 < 5
128
- expect(tracker.openCount()).toBe(1);
129
- expect(verdicts(unerrDir).filter((v) => v.verdict !== "fired")).toHaveLength(0);
130
- });
131
- it("closeAll forces verdicts regardless of turn distance", () => {
132
- tracker.recordSignalFired({
133
- kind: "resume_injected",
134
- signal_id: "session-X",
135
- entity_key: null,
136
- turn: 50,
137
- });
138
- tracker.closeAll(50);
139
- expect(tracker.openCount()).toBe(0);
140
- const resolved = verdicts(unerrDir).filter((v) => v.signal_id === "session-X" && v.verdict !== "fired");
141
- expect(resolved).toHaveLength(1);
142
- });
143
- });
@@ -1,42 +0,0 @@
1
- import { describe, expect, it } from "vitest";
2
- import { resolveProviderConfig } from "../core/provider-factory.js";
3
- describe("resolveProviderConfig", () => {
4
- it("defaults to anthropic with claude-sonnet-4-20250514", () => {
5
- const config = resolveProviderConfig({});
6
- expect(config.provider).toBe("anthropic");
7
- expect(config.model).toBe("claude-sonnet-4-20250514");
8
- });
9
- it("resolves openai provider with gpt-4o default model", () => {
10
- const config = resolveProviderConfig({ provider: "openai" });
11
- expect(config.provider).toBe("openai");
12
- expect(config.model).toBe("gpt-4o");
13
- });
14
- it("resolves google provider with gemini default model", () => {
15
- const config = resolveProviderConfig({ provider: "google" });
16
- expect(config.provider).toBe("google");
17
- expect(config.model).toBe("gemini-2.0-flash");
18
- });
19
- it("resolves ollama with llama3 default", () => {
20
- const config = resolveProviderConfig({ provider: "ollama" });
21
- expect(config.provider).toBe("ollama");
22
- expect(config.model).toBe("llama3");
23
- });
24
- it("passes through custom model and apiKey", () => {
25
- const config = resolveProviderConfig({
26
- provider: "openai",
27
- model: "gpt-4-turbo",
28
- apiKey: "sk-test",
29
- });
30
- expect(config.model).toBe("gpt-4-turbo");
31
- expect(config.apiKey).toBe("sk-test");
32
- });
33
- it("passes through baseUrl for openai-compatible", () => {
34
- const config = resolveProviderConfig({
35
- provider: "openai-compatible",
36
- model: "mistral-7b",
37
- baseUrl: "http://localhost:8080/v1",
38
- });
39
- expect(config.provider).toBe("openai-compatible");
40
- expect(config.baseUrl).toBe("http://localhost:8080/v1");
41
- });
42
- });
@@ -1,24 +0,0 @@
1
- import { describe, expect, it } from "vitest";
2
- import { SUPPORTED_PROVIDERS } from "../core/providers.js";
3
- describe("Provider Registry", () => {
4
- it("lists all supported providers", () => {
5
- expect(SUPPORTED_PROVIDERS).toContain("anthropic");
6
- expect(SUPPORTED_PROVIDERS).toContain("openai");
7
- expect(SUPPORTED_PROVIDERS).toContain("google");
8
- expect(SUPPORTED_PROVIDERS).toContain("ollama");
9
- expect(SUPPORTED_PROVIDERS).toContain("openai-compatible");
10
- expect(SUPPORTED_PROVIDERS).toHaveLength(5);
11
- });
12
- it("provider names are string literals", () => {
13
- const names = [
14
- "anthropic",
15
- "openai",
16
- "google",
17
- "ollama",
18
- "openai-compatible",
19
- ];
20
- for (const name of names) {
21
- expect(SUPPORTED_PROVIDERS).toContain(name);
22
- }
23
- });
24
- });
@@ -1,314 +0,0 @@
1
- /**
2
- * P10-TEST-01: Proxy Lifecycle Tests
3
- *
4
- * Tests PID lock, session stats, health grade computation.
5
- * Note: Full MCP server integration tests require cozo-node and stdio — kept as
6
- * focused unit tests for the core proxy subsystems.
7
- */
8
- import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync, } from "node:fs";
9
- import { tmpdir } from "node:os";
10
- import { join } from "node:path";
11
- import { afterEach, beforeEach, describe, expect, it } from "vitest";
12
- import { PidLock } from "../proxy/pid-lock.js";
13
- import { computePercentiles, createSessionStats, formatSessionStats, recordLatency, recordRiskWarning, recordToolCall, recordViolation, } from "../proxy/session-stats.js";
14
- let tempDir;
15
- beforeEach(() => {
16
- tempDir = join(tmpdir(), `unerr-proxy-test-${Date.now()}-${Math.random().toString(36).slice(2)}`);
17
- mkdirSync(tempDir, { recursive: true });
18
- });
19
- afterEach(() => {
20
- try {
21
- rmSync(tempDir, { recursive: true, force: true });
22
- }
23
- catch {
24
- /* ignore */
25
- }
26
- });
27
- // ── PID Lock Tests ────────────────────────────────────────────────
28
- describe("PidLock", () => {
29
- it("acquires lock when no PID file exists", async () => {
30
- const lock = new PidLock(tempDir);
31
- const result = await lock.acquire();
32
- expect(result.acquired).toBe(true);
33
- expect(result.outcome).toBe("primary");
34
- expect(existsSync(join(tempDir, "proxy.pid"))).toBe(true);
35
- lock.release();
36
- });
37
- it("writes JSON PID data to file", async () => {
38
- const lock = new PidLock(tempDir);
39
- await lock.acquire();
40
- const content = readFileSync(join(tempDir, "proxy.pid"), "utf-8").trim();
41
- const data = JSON.parse(content);
42
- expect(data.pid).toBe(process.pid);
43
- expect(data.startedAt).toBeTruthy();
44
- expect(typeof data.healthPort).toBe("number");
45
- expect(data.healthPort).toBeGreaterThan(0);
46
- lock.release();
47
- });
48
- it("rejects second lock when PID is alive", async () => {
49
- const lock1 = new PidLock(tempDir);
50
- await lock1.acquire();
51
- const lock2 = new PidLock(tempDir);
52
- const result = await lock2.acquire();
53
- expect(result.acquired).toBe(false);
54
- expect(result.outcome).toBe("secondary");
55
- expect(result.existingPid).toBe(process.pid);
56
- lock1.release();
57
- });
58
- it("cleans up stale PID (legacy format) and acquires lock", async () => {
59
- // Write a dead PID in legacy plain number format
60
- writeFileSync(join(tempDir, "proxy.pid"), "9999999", "utf-8");
61
- const lock = new PidLock(tempDir);
62
- const result = await lock.acquire();
63
- expect(result.acquired).toBe(true);
64
- expect(result.outcome).toBe("stale_recovered");
65
- lock.release();
66
- });
67
- it("cleans up stale PID (JSON format) and acquires lock", async () => {
68
- // Write a dead PID in JSON format
69
- writeFileSync(join(tempDir, "proxy.pid"), JSON.stringify({
70
- pid: 9999999,
71
- startedAt: new Date().toISOString(),
72
- healthPort: 0,
73
- }), "utf-8");
74
- const lock = new PidLock(tempDir);
75
- const result = await lock.acquire();
76
- expect(result.acquired).toBe(true);
77
- expect(result.outcome).toBe("stale_recovered");
78
- lock.release();
79
- });
80
- it("release removes PID file", async () => {
81
- const lock = new PidLock(tempDir);
82
- await lock.acquire();
83
- expect(existsSync(join(tempDir, "proxy.pid"))).toBe(true);
84
- lock.release();
85
- expect(existsSync(join(tempDir, "proxy.pid"))).toBe(false);
86
- });
87
- it("release only removes own PID", () => {
88
- // Write someone else's PID in JSON format
89
- writeFileSync(join(tempDir, "proxy.pid"), JSON.stringify({ pid: 1, startedAt: "", healthPort: 0 }), "utf-8");
90
- const lock = new PidLock(tempDir);
91
- // Don't acquire — just try to release
92
- lock.release();
93
- // File should still exist (PID 1 is not our PID)
94
- expect(existsSync(join(tempDir, "proxy.pid"))).toBe(true);
95
- });
96
- it("isLocked reports correctly", async () => {
97
- const lock = new PidLock(tempDir);
98
- expect(lock.isLocked().locked).toBe(false);
99
- await lock.acquire();
100
- expect(lock.isLocked().locked).toBe(true);
101
- expect(lock.isLocked().pid).toBe(process.pid);
102
- expect(lock.isLocked().healthPort).toBeGreaterThan(0);
103
- lock.release();
104
- expect(lock.isLocked().locked).toBe(false);
105
- });
106
- it("health endpoint responds with status", async () => {
107
- const lock = new PidLock(tempDir);
108
- const result = await lock.acquire();
109
- expect(result.healthPort).toBeGreaterThan(0);
110
- lock.recordToolCall();
111
- lock.recordToolCall();
112
- lock.setMode("local");
113
- const res = await fetch(`http://127.0.0.1:${result.healthPort}/health`);
114
- expect(res.ok).toBe(true);
115
- const body = (await res.json());
116
- expect(body.status).toBe("ok");
117
- expect(body.tool_calls).toBe(2);
118
- expect(body.mode).toBe("local");
119
- expect(body.pid).toBe(process.pid);
120
- lock.release();
121
- });
122
- it("readPidFile returns data for running process", async () => {
123
- const lock = new PidLock(tempDir);
124
- await lock.acquire();
125
- const data = PidLock.readPidFile(tempDir);
126
- expect(data).not.toBeNull();
127
- expect(data?.pid).toBe(process.pid);
128
- expect(data?.healthPort).toBeGreaterThan(0);
129
- lock.release();
130
- });
131
- });
132
- // ── Session Stats Tests ───────────────────────────────────────────
133
- describe("SessionStats", () => {
134
- it("creates stats with zero counters", () => {
135
- const stats = createSessionStats();
136
- expect(stats.toolCallsLocal).toBe(0);
137
- expect(stats.estimatedTokensSaved).toBe(0);
138
- expect(stats.violationsCaught).toBe(0);
139
- expect(stats.riskWarningsIssued).toBe(0);
140
- });
141
- it("increments local tool calls", () => {
142
- const stats = createSessionStats();
143
- recordToolCall(stats);
144
- recordToolCall(stats);
145
- expect(stats.toolCallsLocal).toBe(2);
146
- expect(stats.estimatedTokensSaved).toBeGreaterThan(0);
147
- });
148
- it("tracks violations and risk warnings", () => {
149
- const stats = createSessionStats();
150
- recordViolation(stats);
151
- recordViolation(stats);
152
- recordRiskWarning(stats);
153
- expect(stats.violationsCaught).toBe(2);
154
- expect(stats.riskWarningsIssued).toBe(1);
155
- });
156
- it("returns null format when no calls made", () => {
157
- const stats = createSessionStats();
158
- expect(formatSessionStats(stats)).toBeNull();
159
- });
160
- it("formats stats with local percentage and savings", () => {
161
- const stats = createSessionStats();
162
- recordToolCall(stats);
163
- recordToolCall(stats);
164
- recordToolCall(stats);
165
- const output = formatSessionStats(stats);
166
- expect(output).not.toBeNull();
167
- expect(output).toContain("3 (all local)");
168
- expect(output).toContain("Tokens saved");
169
- });
170
- it("includes violations and risk warnings in output", () => {
171
- const stats = createSessionStats();
172
- recordToolCall(stats);
173
- recordViolation(stats);
174
- recordRiskWarning(stats);
175
- const output = formatSessionStats(stats);
176
- expect(output).toContain("Violations");
177
- expect(output).toContain("Risk warnings");
178
- });
179
- });
180
- // ── Latency Tracking Tests ────────────────────────────────────────
181
- describe("LatencyTracker", () => {
182
- it("records latency samples and computes percentiles", () => {
183
- const stats = createSessionStats();
184
- // Simulate 100 local tool calls with increasing latency
185
- for (let i = 1; i <= 100; i++) {
186
- recordLatency(stats.latency, i * 0.05); // 0.05ms to 5.0ms
187
- }
188
- const p = computePercentiles(stats.latency.localSamples, stats.latency.localTotalSamples);
189
- expect(p).not.toBeNull();
190
- expect(p?.count).toBe(100);
191
- expect(p?.min).toBeCloseTo(0.05, 1);
192
- expect(p?.max).toBeCloseTo(5.0, 1);
193
- expect(p?.p50).toBeGreaterThan(0);
194
- expect(p?.p95).toBeGreaterThan(p.p50);
195
- expect(p?.p99).toBeGreaterThanOrEqual(p.p95);
196
- });
197
- it("records all samples as local", () => {
198
- const stats = createSessionStats();
199
- recordLatency(stats.latency, 1.5);
200
- recordLatency(stats.latency, 1.8);
201
- recordLatency(stats.latency, 2.5);
202
- expect(stats.latency.localTotalSamples).toBe(3);
203
- expect(stats.latency.totalSamples).toBe(3);
204
- const localP = computePercentiles(stats.latency.localSamples, stats.latency.localTotalSamples);
205
- expect(localP?.max).toBeLessThan(5);
206
- });
207
- it("returns null percentiles for zero samples", () => {
208
- const stats = createSessionStats();
209
- const p = computePercentiles(stats.latency.localSamples, 0);
210
- expect(p).toBeNull();
211
- });
212
- it("circular buffer wraps correctly at capacity", () => {
213
- const stats = createSessionStats();
214
- // Fill past capacity (1000) — buffer should wrap
215
- for (let i = 0; i < 1200; i++) {
216
- recordLatency(stats.latency, i < 1000 ? 1.0 : 50.0);
217
- }
218
- expect(stats.latency.localTotalSamples).toBe(1200);
219
- // Percentiles should reflect the circular nature
220
- // Buffer has 200 samples of 50ms + 800 samples of 1ms
221
- const p = computePercentiles(stats.latency.localSamples, stats.latency.localTotalSamples);
222
- expect(p?.count).toBe(1200);
223
- // p50 should be 1.0ms (800/1000 are 1ms)
224
- expect(p?.p50).toBe(1.0);
225
- });
226
- it("formatSessionStats includes latency section", () => {
227
- const stats = createSessionStats();
228
- recordToolCall(stats);
229
- recordLatency(stats.latency, 2.3);
230
- recordToolCall(stats);
231
- recordLatency(stats.latency, 280);
232
- const output = formatSessionStats(stats);
233
- expect(output).toContain("Latency");
234
- expect(output).toContain("p50=");
235
- expect(output).toContain("p95=");
236
- expect(output).toContain("p99=");
237
- });
238
- });
239
- // ── Health Grade Tests ────────────────────────────────────────────
240
- describe("HealthGrade", () => {
241
- it("computeHealthGrade works with mock CozoDB", async () => {
242
- const { computeHealthGrade } = await import("../intelligence/health-grade.js");
243
- // Mock CozoDB that returns empty results
244
- const mockDb = {
245
- run: async (query) => {
246
- if (query.includes("count(key)") && query.includes("entities"))
247
- return { rows: [[50]] };
248
- if (query.includes("count(from_key)"))
249
- return { rows: [[100]] };
250
- if (query.includes("count(key)") && query.includes("rules"))
251
- return { rows: [[5]] };
252
- if (query.includes("fan_in == 0"))
253
- return { rows: [] };
254
- if (query.includes('risk_level == "high"'))
255
- return { rows: [] };
256
- return { rows: [] };
257
- },
258
- };
259
- const result = await computeHealthGrade(mockDb);
260
- expect(result.grade).toBeDefined();
261
- expect(result.totalEntities).toBe(50);
262
- expect(result.totalEdges).toBe(100);
263
- expect(result.totalRules).toBe(5);
264
- expect(result.score).toBeGreaterThan(0);
265
- });
266
- it("formatHealthGrade produces readable output", async () => {
267
- const { formatHealthGrade } = await import("../intelligence/health-grade.js");
268
- const result = {
269
- grade: "B+",
270
- totalEntities: 250,
271
- totalEdges: 800,
272
- totalRules: 12,
273
- deadFunctionCount: 15,
274
- highRiskEntities: [
275
- {
276
- name: "processPayment",
277
- kind: "function",
278
- file_path: "src/billing.ts",
279
- fan_in: 23,
280
- fan_out: 8,
281
- },
282
- ],
283
- score: 82,
284
- };
285
- const output = formatHealthGrade(result);
286
- expect(output).toContain("B+");
287
- expect(output).toContain("82/100");
288
- expect(output).toContain("250");
289
- expect(output).toContain("processPayment");
290
- expect(output).toContain("23 callers");
291
- });
292
- it("assigns correct grades for edge scores", async () => {
293
- const { computeHealthGrade } = await import("../intelligence/health-grade.js");
294
- // High score (few entities, no dead, no risk, has rules)
295
- const goodDb = {
296
- run: async (query) => {
297
- if (query.includes("count(key)") && query.includes("entities"))
298
- return { rows: [[30]] };
299
- if (query.includes("count(from_key)"))
300
- return { rows: [[50]] };
301
- if (query.includes("count(key)") && query.includes("rules"))
302
- return { rows: [[3]] };
303
- if (query.includes("fan_in == 0"))
304
- return { rows: [] };
305
- if (query.includes('risk_level == "high"'))
306
- return { rows: [] };
307
- return { rows: [] };
308
- },
309
- };
310
- const good = await computeHealthGrade(goodDb);
311
- expect(good.score).toBeGreaterThanOrEqual(85);
312
- expect(["A", "B+"]).toContain(good.grade);
313
- });
314
- });