@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,259 +0,0 @@
1
- /**
2
- * Tests for Git-Native Attribution — Phase 5.5 §1.5
3
- */
4
- import { mkdirSync, rmSync, writeFileSync } from "node:fs";
5
- import { tmpdir } from "node:os";
6
- import { join } from "node:path";
7
- import { afterEach, beforeEach, describe, expect, it } from "vitest";
8
- import { buildCommitMessageWithTrailers, buildGitNotePayload, readAttributionFromManifest, } from "../tracking/git-attribution.js";
9
- function makeAttribution(overrides) {
10
- return {
11
- sessionId: "sess-abc-123",
12
- ledgerEntryIds: ["entry-1", "entry-2"],
13
- prompt: "Add user authentication",
14
- planSummary: "Implement OAuth2 flow with Google provider",
15
- changeType: "feat",
16
- featureArea: "auth/oauth",
17
- agentModel: "claude-sonnet-4",
18
- agentTool: "cursor",
19
- filesChanged: ["src/auth/oauth.ts", "src/auth/types.ts"],
20
- ...overrides,
21
- };
22
- }
23
- describe("git-attribution", () => {
24
- // ── buildCommitMessageWithTrailers ──────────────────────────
25
- describe("buildCommitMessageWithTrailers", () => {
26
- it("appends session trailer to commit message", () => {
27
- const result = buildCommitMessageWithTrailers("feat: add login", makeAttribution());
28
- expect(result).toContain("Unerr-Session: sess-abc-123");
29
- });
30
- it("includes ledger ID trailer (first entry only)", () => {
31
- const result = buildCommitMessageWithTrailers("feat: add login", makeAttribution());
32
- expect(result).toContain("Unerr-Ledger-Id: entry-1");
33
- expect(result).not.toContain("entry-2");
34
- });
35
- it("includes change type trailer", () => {
36
- const result = buildCommitMessageWithTrailers("feat: add login", makeAttribution());
37
- expect(result).toContain("Unerr-Change-Type: feat");
38
- });
39
- it("includes feature area trailer", () => {
40
- const result = buildCommitMessageWithTrailers("feat: add login", makeAttribution());
41
- expect(result).toContain("Unerr-Feature: auth/oauth");
42
- });
43
- it("includes plan summary trailer", () => {
44
- const result = buildCommitMessageWithTrailers("feat: add login", makeAttribution());
45
- expect(result).toContain("Unerr-Plan: Implement OAuth2 flow with Google provider");
46
- });
47
- it("truncates plan summary to 72 chars", () => {
48
- const longPlan = "A".repeat(100);
49
- const result = buildCommitMessageWithTrailers("feat: add login", makeAttribution({ planSummary: longPlan }));
50
- expect(result).toContain(`Unerr-Plan: ${"A".repeat(69)}...`);
51
- });
52
- it("does not truncate plan exactly 72 chars", () => {
53
- const exactPlan = "B".repeat(72);
54
- const result = buildCommitMessageWithTrailers("feat: add login", makeAttribution({ planSummary: exactPlan }));
55
- expect(result).toContain(`Unerr-Plan: ${"B".repeat(72)}`);
56
- expect(result).not.toContain("...");
57
- });
58
- it("includes agent model and tool trailers", () => {
59
- const result = buildCommitMessageWithTrailers("feat: add login", makeAttribution());
60
- expect(result).toContain("Unerr-Agent-Model: claude-sonnet-4");
61
- expect(result).toContain("Unerr-Agent-Tool: cursor");
62
- });
63
- it("separates trailers from message body with blank line", () => {
64
- const result = buildCommitMessageWithTrailers("feat: add login", makeAttribution());
65
- expect(result).toMatch(/feat: add login\n\nUnerr-Session:/);
66
- });
67
- it("omits optional trailers when values are undefined", () => {
68
- const result = buildCommitMessageWithTrailers("chore: cleanup", makeAttribution({
69
- changeType: undefined,
70
- featureArea: undefined,
71
- planSummary: undefined,
72
- agentModel: undefined,
73
- agentTool: undefined,
74
- }));
75
- expect(result).toContain("Unerr-Session:");
76
- expect(result).toContain("Unerr-Ledger-Id:");
77
- expect(result).not.toContain("Unerr-Change-Type:");
78
- expect(result).not.toContain("Unerr-Feature:");
79
- expect(result).not.toContain("Unerr-Plan:");
80
- expect(result).not.toContain("Unerr-Agent-Model:");
81
- expect(result).not.toContain("Unerr-Agent-Tool:");
82
- });
83
- it("omits ledger ID trailer when no entry IDs", () => {
84
- const result = buildCommitMessageWithTrailers("chore: cleanup", makeAttribution({ ledgerEntryIds: [] }));
85
- expect(result).not.toContain("Unerr-Ledger-Id:");
86
- });
87
- });
88
- // ── buildGitNotePayload ────────────────────────────────────
89
- describe("buildGitNotePayload", () => {
90
- it("returns version 1.0", () => {
91
- const payload = buildGitNotePayload(makeAttribution());
92
- expect(payload.version).toBe("1.0");
93
- });
94
- it("maps attribution fields to snake_case payload", () => {
95
- const payload = buildGitNotePayload(makeAttribution());
96
- expect(payload.session_id).toBe("sess-abc-123");
97
- expect(payload.ledger_entry_ids).toEqual(["entry-1", "entry-2"]);
98
- expect(payload.prompt).toBe("Add user authentication");
99
- expect(payload.plan_summary).toBe("Implement OAuth2 flow with Google provider");
100
- expect(payload.change_type).toBe("feat");
101
- expect(payload.feature_area).toBe("auth/oauth");
102
- expect(payload.agent_model).toBe("claude-sonnet-4");
103
- expect(payload.agent_tool).toBe("cursor");
104
- expect(payload.files_changed).toEqual([
105
- "src/auth/oauth.ts",
106
- "src/auth/types.ts",
107
- ]);
108
- });
109
- it("sets entities_affected to empty array (resolved server-side)", () => {
110
- const payload = buildGitNotePayload(makeAttribution());
111
- expect(payload.entities_affected).toEqual([]);
112
- });
113
- it("includes ISO 8601 created_at timestamp", () => {
114
- const before = new Date().toISOString();
115
- const payload = buildGitNotePayload(makeAttribution());
116
- const after = new Date().toISOString();
117
- expect(payload.created_at >= before).toBe(true);
118
- expect(payload.created_at <= after).toBe(true);
119
- });
120
- it("handles missing optional fields", () => {
121
- const payload = buildGitNotePayload(makeAttribution({
122
- planSummary: undefined,
123
- changeType: undefined,
124
- featureArea: undefined,
125
- agentModel: undefined,
126
- agentTool: undefined,
127
- }));
128
- expect(payload.plan_summary).toBeUndefined();
129
- expect(payload.change_type).toBeUndefined();
130
- expect(payload.feature_area).toBeUndefined();
131
- expect(payload.agent_model).toBeUndefined();
132
- expect(payload.agent_tool).toBeUndefined();
133
- });
134
- it("produces valid JSON when serialized", () => {
135
- const payload = buildGitNotePayload(makeAttribution());
136
- const json = JSON.stringify(payload, null, 2);
137
- const parsed = JSON.parse(json);
138
- expect(parsed).toHaveProperty("version", "1.0");
139
- expect(parsed).toHaveProperty("session_id", "sess-abc-123");
140
- });
141
- });
142
- // ── readAttributionFromManifest ────────────────────────────
143
- describe("readAttributionFromManifest", () => {
144
- let tempDir;
145
- beforeEach(() => {
146
- tempDir = join(tmpdir(), `unerr-test-${Date.now()}-${Math.random().toString(36).slice(2)}`);
147
- mkdirSync(join(tempDir, ".unerr"), { recursive: true });
148
- });
149
- afterEach(() => {
150
- try {
151
- rmSync(tempDir, { recursive: true, force: true });
152
- }
153
- catch {
154
- /* ignore cleanup errors */
155
- }
156
- });
157
- it("returns null when manifest does not exist", () => {
158
- const result = readAttributionFromManifest(join(tmpdir(), "nonexistent"));
159
- expect(result).toBeNull();
160
- });
161
- it("returns null when manifest has no sessionId", () => {
162
- writeFileSync(join(tempDir, ".unerr", "manifest.json"), JSON.stringify({ attributions: [{ prompt: "test" }] }));
163
- expect(readAttributionFromManifest(tempDir)).toBeNull();
164
- });
165
- it("returns null when manifest has no attributions", () => {
166
- writeFileSync(join(tempDir, ".unerr", "manifest.json"), JSON.stringify({ sessionId: "sess-1", attributions: [] }));
167
- expect(readAttributionFromManifest(tempDir)).toBeNull();
168
- });
169
- it("returns null for invalid JSON", () => {
170
- writeFileSync(join(tempDir, ".unerr", "manifest.json"), "not json {{{");
171
- expect(readAttributionFromManifest(tempDir)).toBeNull();
172
- });
173
- it("reads a single attribution", () => {
174
- writeFileSync(join(tempDir, ".unerr", "manifest.json"), JSON.stringify({
175
- sessionId: "sess-xyz",
176
- attributions: [
177
- {
178
- prompt: "Add login",
179
- planSummary: "OAuth flow",
180
- changeType: "feat",
181
- featureArea: "auth",
182
- agentModel: "claude-sonnet-4",
183
- agentTool: "cursor",
184
- filesChanged: ["src/auth.ts"],
185
- ledgerEntryIds: ["le-1"],
186
- },
187
- ],
188
- }));
189
- const result = readAttributionFromManifest(tempDir);
190
- expect(result).not.toBeNull();
191
- expect(result?.sessionId).toBe("sess-xyz");
192
- expect(result?.prompt).toBe("Add login");
193
- expect(result?.planSummary).toBe("OAuth flow");
194
- expect(result?.changeType).toBe("feat");
195
- expect(result?.featureArea).toBe("auth");
196
- expect(result?.agentModel).toBe("claude-sonnet-4");
197
- expect(result?.agentTool).toBe("cursor");
198
- expect(result?.filesChanged).toEqual(["src/auth.ts"]);
199
- expect(result?.ledgerEntryIds).toEqual(["le-1"]);
200
- });
201
- it("merges multiple attributions into a single context", () => {
202
- writeFileSync(join(tempDir, ".unerr", "manifest.json"), JSON.stringify({
203
- sessionId: "sess-multi",
204
- attributions: [
205
- {
206
- prompt: "Add login",
207
- filesChanged: ["src/auth/login.ts"],
208
- ledgerEntryIds: ["le-1"],
209
- changeType: "feat",
210
- },
211
- {
212
- prompt: "Add signup",
213
- filesChanged: ["src/auth/signup.ts", "src/auth/login.ts"],
214
- ledgerEntryIds: ["le-2"],
215
- changeType: "fix",
216
- planSummary: "Fix the signup flow",
217
- },
218
- ],
219
- }));
220
- const result = readAttributionFromManifest(tempDir);
221
- expect(result).not.toBeNull();
222
- expect(result?.sessionId).toBe("sess-multi");
223
- // Prompts joined with arrow
224
- expect(result?.prompt).toBe("Add login → Add signup");
225
- // Files are deduped
226
- expect(result?.filesChanged).toHaveLength(2);
227
- expect(result?.filesChanged).toContain("src/auth/login.ts");
228
- expect(result?.filesChanged).toContain("src/auth/signup.ts");
229
- // Entry IDs are deduped
230
- expect(result?.ledgerEntryIds).toEqual(["le-1", "le-2"]);
231
- // Uses latest attribution's metadata
232
- expect(result?.changeType).toBe("fix");
233
- expect(result?.planSummary).toBe("Fix the signup flow");
234
- });
235
- it("deduplicates ledger entry IDs", () => {
236
- writeFileSync(join(tempDir, ".unerr", "manifest.json"), JSON.stringify({
237
- sessionId: "sess-dedup",
238
- attributions: [
239
- { prompt: "First", ledgerEntryIds: ["le-1", "le-2"] },
240
- { prompt: "Second", ledgerEntryIds: ["le-2", "le-3"] },
241
- ],
242
- }));
243
- const result = readAttributionFromManifest(tempDir);
244
- expect(result?.ledgerEntryIds).toEqual(["le-1", "le-2", "le-3"]);
245
- });
246
- it("handles attributions with missing optional fields", () => {
247
- writeFileSync(join(tempDir, ".unerr", "manifest.json"), JSON.stringify({
248
- sessionId: "sess-minimal",
249
- attributions: [{ prompt: "Just a prompt" }],
250
- }));
251
- const result = readAttributionFromManifest(tempDir);
252
- expect(result).not.toBeNull();
253
- expect(result?.sessionId).toBe("sess-minimal");
254
- expect(result?.prompt).toBe("Just a prompt");
255
- expect(result?.ledgerEntryIds).toEqual([]);
256
- expect(result?.filesChanged).toEqual([]);
257
- });
258
- });
259
- });
@@ -1,219 +0,0 @@
1
- // @ts-nocheck — test file
2
- /**
3
- * GraphTemporalJoiner tests — co-change prediction, hidden coupling detection.
4
- */
5
- import { describe, expect, it, vi } from "vitest";
6
- import { GraphTemporalJoiner } from "../intelligence/graph-temporal-joiner.js";
7
- function createMockGraph(fileEntities, callerMap, calleeMap) {
8
- return {
9
- getEntitiesByFile: vi.fn((filePath) => Promise.resolve(fileEntities[filePath] ?? [])),
10
- getCallersOf: vi.fn((key) => Promise.resolve(callerMap[key] ?? [])),
11
- getCalleesOf: vi.fn((key) => Promise.resolve(calleeMap[key] ?? [])),
12
- };
13
- }
14
- function createMockFactStore(facts) {
15
- return {
16
- recallBySubject: vi.fn((subject) => Promise.resolve(facts.filter((f) => f.subject === subject || f.subject.startsWith(subject)))),
17
- recallByScope: vi.fn((scope) => Promise.resolve(facts.filter((f) => f.scope === scope))),
18
- };
19
- }
20
- describe("GraphTemporalJoiner", () => {
21
- describe("predictCoChanges", () => {
22
- it("returns co-changes from graph structure only", async () => {
23
- const graph = createMockGraph({
24
- "src/a.ts": [{ key: "fnA", file_path: "src/a.ts" }],
25
- }, {
26
- fnA: [
27
- { key: "fnB", file_path: "src/b.ts" },
28
- { key: "fnC", file_path: "src/c.ts" },
29
- ],
30
- }, { fnA: [] });
31
- const joiner = new GraphTemporalJoiner(graph, null);
32
- const results = await joiner.predictCoChanges("src/a.ts");
33
- expect(results.length).toBeGreaterThan(0);
34
- expect(results[0].file_a).toBe("src/a.ts");
35
- expect(results[0].graph_coupling).toBeGreaterThan(0);
36
- expect(results[0].temporal_coupling).toBe(0);
37
- // With no temporal data, combined = 0.4 * graph
38
- expect(results[0].combined_score).toBeGreaterThan(0);
39
- });
40
- it("returns co-changes from temporal data only", async () => {
41
- const graph = createMockGraph({}, {}, {});
42
- const factStore = createMockFactStore([
43
- {
44
- fact_type: "semantic",
45
- scope: "project",
46
- subject: "coupling:src/a.ts↔src/d.ts",
47
- content: "Files co-accessed in 5 sessions",
48
- base_confidence: 0.8,
49
- },
50
- ]);
51
- const joiner = new GraphTemporalJoiner(graph, factStore);
52
- const results = await joiner.predictCoChanges("src/a.ts");
53
- // Temporal-only: combined = 0.6 * 0.8 = 0.48
54
- expect(results.length).toBeGreaterThan(0);
55
- expect(results[0].file_b).toBe("src/d.ts");
56
- expect(results[0].temporal_coupling).toBe(0.8);
57
- expect(results[0].graph_coupling).toBe(0);
58
- expect(results[0].combined_score).toBeCloseTo(0.48, 1);
59
- });
60
- it("combines graph and temporal signals", async () => {
61
- const graph = createMockGraph({
62
- "src/a.ts": [{ key: "fnA", file_path: "src/a.ts" }],
63
- }, {
64
- fnA: [{ key: "fnB", file_path: "src/b.ts" }],
65
- }, { fnA: [] });
66
- const factStore = createMockFactStore([
67
- {
68
- fact_type: "semantic",
69
- scope: "project",
70
- subject: "coupling:src/a.ts↔src/b.ts",
71
- content: "Files co-accessed in 3 sessions",
72
- base_confidence: 0.7,
73
- },
74
- ]);
75
- const joiner = new GraphTemporalJoiner(graph, factStore);
76
- const results = await joiner.predictCoChanges("src/a.ts");
77
- expect(results.length).toBe(1);
78
- expect(results[0].file_b).toBe("src/b.ts");
79
- expect(results[0].graph_coupling).toBeGreaterThan(0);
80
- expect(results[0].temporal_coupling).toBe(0.7);
81
- // Combined should be > either alone
82
- expect(results[0].combined_score).toBeGreaterThan(0.6 * results[0].temporal_coupling);
83
- });
84
- it("filters out low-score noise (< 0.1)", async () => {
85
- const graph = createMockGraph({}, {}, {});
86
- const factStore = createMockFactStore([
87
- {
88
- fact_type: "semantic",
89
- scope: "project",
90
- subject: "coupling:src/a.ts↔src/noise.ts",
91
- content: "1 session",
92
- base_confidence: 0.05,
93
- },
94
- ]);
95
- const joiner = new GraphTemporalJoiner(graph, factStore);
96
- const results = await joiner.predictCoChanges("src/a.ts");
97
- // 0.6 * 0.05 = 0.03 < 0.1 threshold
98
- expect(results).toHaveLength(0);
99
- });
100
- it("returns empty for files with no connections", async () => {
101
- const graph = createMockGraph({}, {}, {});
102
- const joiner = new GraphTemporalJoiner(graph, null);
103
- const results = await joiner.predictCoChanges("src/isolated.ts");
104
- expect(results).toHaveLength(0);
105
- });
106
- it("excludes self-references", async () => {
107
- const graph = createMockGraph({
108
- "src/a.ts": [{ key: "fnA", file_path: "src/a.ts" }],
109
- }, {
110
- fnA: [{ key: "fnA2", file_path: "src/a.ts" }],
111
- }, { fnA: [] });
112
- const joiner = new GraphTemporalJoiner(graph, null);
113
- const results = await joiner.predictCoChanges("src/a.ts");
114
- expect(results.every((r) => r.file_b !== "src/a.ts")).toBe(true);
115
- });
116
- it("sorts results by combined_score descending", async () => {
117
- const graph = createMockGraph({
118
- "src/a.ts": [{ key: "fnA", file_path: "src/a.ts" }],
119
- }, {
120
- fnA: [
121
- { key: "fnB", file_path: "src/b.ts" },
122
- { key: "fnC", file_path: "src/c.ts" },
123
- ],
124
- }, {
125
- fnA: [{ key: "fnD", file_path: "src/b.ts" }],
126
- });
127
- const joiner = new GraphTemporalJoiner(graph, null);
128
- const results = await joiner.predictCoChanges("src/a.ts");
129
- for (let i = 1; i < results.length; i++) {
130
- expect(results[i - 1].combined_score).toBeGreaterThanOrEqual(results[i].combined_score);
131
- }
132
- });
133
- });
134
- describe("detectHiddenCouplings", () => {
135
- it("detects files with temporal coupling but no graph edges", async () => {
136
- const graph = createMockGraph({}, {}, {});
137
- const factStore = createMockFactStore([
138
- {
139
- fact_type: "semantic",
140
- scope: "project",
141
- subject: "coupling:src/config.ts↔src/deploy.ts",
142
- content: "Files co-accessed in 5 sessions",
143
- base_confidence: 0.8,
144
- },
145
- ]);
146
- const joiner = new GraphTemporalJoiner(graph, factStore);
147
- const hidden = await joiner.detectHiddenCouplings();
148
- expect(hidden).toHaveLength(1);
149
- expect(hidden[0].file_a).toBe("src/config.ts");
150
- expect(hidden[0].file_b).toBe("src/deploy.ts");
151
- expect(hidden[0].temporal_coupling).toBe(0.8);
152
- expect(hidden[0].graph_coupling).toBeLessThan(0.1);
153
- expect(hidden[0].sessions_observed).toBe(5);
154
- expect(hidden[0].evidence).toContain("no import/call edges");
155
- });
156
- it("excludes files with structural connections", async () => {
157
- const graph = createMockGraph({
158
- "src/a.ts": [{ key: "fnA", file_path: "src/a.ts" }],
159
- }, { fnA: [{ key: "fnB", file_path: "src/b.ts" }] }, { fnA: [] });
160
- const factStore = createMockFactStore([
161
- {
162
- fact_type: "semantic",
163
- scope: "project",
164
- subject: "coupling:src/a.ts↔src/b.ts",
165
- content: "Files co-accessed in 4 sessions",
166
- base_confidence: 0.7,
167
- },
168
- ]);
169
- const joiner = new GraphTemporalJoiner(graph, factStore);
170
- const hidden = await joiner.detectHiddenCouplings();
171
- // src/a.ts → src/b.ts has a structural connection, so NOT hidden
172
- expect(hidden).toHaveLength(0);
173
- });
174
- it("ignores low-confidence temporal couplings", async () => {
175
- const graph = createMockGraph({}, {}, {});
176
- const factStore = createMockFactStore([
177
- {
178
- fact_type: "semantic",
179
- scope: "project",
180
- subject: "coupling:src/x.ts↔src/y.ts",
181
- content: "1 session",
182
- base_confidence: 0.3, // Below 0.5 threshold
183
- },
184
- ]);
185
- const joiner = new GraphTemporalJoiner(graph, factStore);
186
- const hidden = await joiner.detectHiddenCouplings();
187
- expect(hidden).toHaveLength(0);
188
- });
189
- it("returns empty when no fact store", async () => {
190
- const graph = createMockGraph({}, {}, {});
191
- const joiner = new GraphTemporalJoiner(graph, null);
192
- const hidden = await joiner.detectHiddenCouplings();
193
- expect(hidden).toHaveLength(0);
194
- });
195
- it("sorts by temporal_coupling descending", async () => {
196
- const graph = createMockGraph({}, {}, {});
197
- const factStore = createMockFactStore([
198
- {
199
- fact_type: "semantic",
200
- scope: "project",
201
- subject: "coupling:src/a.ts↔src/b.ts",
202
- content: "3 sessions",
203
- base_confidence: 0.6,
204
- },
205
- {
206
- fact_type: "semantic",
207
- scope: "project",
208
- subject: "coupling:src/c.ts↔src/d.ts",
209
- content: "7 sessions",
210
- base_confidence: 0.9,
211
- },
212
- ]);
213
- const joiner = new GraphTemporalJoiner(graph, factStore);
214
- const hidden = await joiner.detectHiddenCouplings();
215
- expect(hidden.length).toBe(2);
216
- expect(hidden[0].temporal_coupling).toBeGreaterThanOrEqual(hidden[1].temporal_coupling);
217
- });
218
- });
219
- });
@@ -1,138 +0,0 @@
1
- import { describe, expect, it } from "vitest";
2
- import { analyzeFanInDistribution, computeHealthGrade, computeTestCoverageProxy, detectCircularDeps, measureImportDepth, } from "../intelligence/health-grader.js";
3
- import { entityKey } from "../intelligence/indexer/entity-key.js";
4
- function makeEntity(name, filePath) {
5
- return {
6
- key: entityKey(filePath, "function", name, ""),
7
- kind: "function",
8
- name,
9
- file_path: filePath,
10
- start_line: 1,
11
- end_line: 5,
12
- signature: `${name}()`,
13
- body_hash: "h",
14
- exported: true,
15
- parent_key: null,
16
- language: "typescript",
17
- is_async: false,
18
- parameter_count: 0,
19
- doc: null,
20
- };
21
- }
22
- describe("Health Grading (O.1-O.5)", () => {
23
- it("detects circular dependencies", () => {
24
- const edges = [
25
- { from_key: "a", to_key: "b", type: "calls", file_path: "f.ts", line: 1 },
26
- { from_key: "b", to_key: "c", type: "calls", file_path: "f.ts", line: 2 },
27
- { from_key: "c", to_key: "a", type: "calls", file_path: "f.ts", line: 3 },
28
- ];
29
- const cycles = detectCircularDeps(edges);
30
- expect(cycles.length).toBeGreaterThanOrEqual(1);
31
- });
32
- it("no cycles in acyclic graph", () => {
33
- const edges = [
34
- { from_key: "a", to_key: "b", type: "calls", file_path: "f.ts", line: 1 },
35
- { from_key: "b", to_key: "c", type: "calls", file_path: "f.ts", line: 2 },
36
- ];
37
- const cycles = detectCircularDeps(edges);
38
- expect(cycles).toHaveLength(0);
39
- });
40
- it("analyzes fan-in distribution", () => {
41
- const edges = Array.from({ length: 50 }, (_, i) => ({
42
- from_key: `caller${i}`,
43
- to_key: "hub",
44
- type: "calls",
45
- file_path: "f.ts",
46
- line: i,
47
- }));
48
- const analysis = analyzeFanInDistribution(edges);
49
- expect(analysis.maxFanIn).toBe(50);
50
- expect(analysis.avgFanIn).toBe(50);
51
- });
52
- it("measures import depth", () => {
53
- const edges = [
54
- {
55
- from_key: "a",
56
- to_key: "b",
57
- type: "imports",
58
- file_path: "a.ts",
59
- line: 1,
60
- },
61
- {
62
- from_key: "b",
63
- to_key: "c",
64
- type: "imports",
65
- file_path: "b.ts",
66
- line: 1,
67
- },
68
- {
69
- from_key: "c",
70
- to_key: "d",
71
- type: "imports",
72
- file_path: "c.ts",
73
- line: 1,
74
- },
75
- ];
76
- const depth = measureImportDepth(edges);
77
- expect(depth).toBe(3);
78
- });
79
- it("computes test coverage proxy", () => {
80
- const entities = [
81
- makeEntity("fn", "src/auth.ts"),
82
- makeEntity("test", "src/__tests__/auth.test.ts"),
83
- ];
84
- const ratio = computeTestCoverageProxy(entities);
85
- expect(ratio).toBe(1.0);
86
- });
87
- it("computes composite health grade", () => {
88
- const entities = Array.from({ length: 20 }, (_, i) => makeEntity(`fn${i}`, `src/f${i}.ts`));
89
- const edges = [
90
- {
91
- from_key: entities[0].key,
92
- to_key: entities[1].key,
93
- type: "calls",
94
- file_path: "f.ts",
95
- line: 1,
96
- },
97
- ];
98
- const report = computeHealthGrade(entities, edges);
99
- expect(["A", "B", "C", "D", "F"]).toContain(report.grade);
100
- expect(report.score).toBeGreaterThanOrEqual(0);
101
- expect(report.score).toBeLessThanOrEqual(100);
102
- expect(report.factors).toHaveLength(5);
103
- });
104
- it("circular deps penalize health grade", () => {
105
- const entities = [
106
- makeEntity("a", "a.ts"),
107
- makeEntity("b", "b.ts"),
108
- makeEntity("c", "c.ts"),
109
- ];
110
- const cycleEdges = [
111
- {
112
- from_key: entities[0].key,
113
- to_key: entities[1].key,
114
- type: "calls",
115
- file_path: "a.ts",
116
- line: 1,
117
- },
118
- {
119
- from_key: entities[1].key,
120
- to_key: entities[2].key,
121
- type: "calls",
122
- file_path: "b.ts",
123
- line: 1,
124
- },
125
- {
126
- from_key: entities[2].key,
127
- to_key: entities[0].key,
128
- type: "calls",
129
- file_path: "c.ts",
130
- line: 1,
131
- },
132
- ];
133
- const withCycles = computeHealthGrade(entities, cycleEdges);
134
- const noCycles = computeHealthGrade(entities, []);
135
- expect(withCycles.score).toBeLessThan(noCycles.score);
136
- expect(withCycles.circularDeps.length).toBeGreaterThan(0);
137
- });
138
- });