@unerr-ai/unerr 0.1.5 → 0.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (218) hide show
  1. package/README.md +70 -194
  2. package/dist/cli.js +39151 -36992
  3. package/package.json +9 -2
  4. package/dist/__tests__/architecture-guard.test.js +0 -122
  5. package/dist/__tests__/arg-validator.test.js +0 -205
  6. package/dist/__tests__/ast-extractor.test.js +0 -203
  7. package/dist/__tests__/auto-bootstrap.test.js +0 -280
  8. package/dist/__tests__/background-indexer.test.js +0 -228
  9. package/dist/__tests__/blast-radius-engine.test.js +0 -200
  10. package/dist/__tests__/bridge-isolation.test.js +0 -37
  11. package/dist/__tests__/budget-enforcer.test.js +0 -53
  12. package/dist/__tests__/cfg-test-detection-perf.test.js +0 -82
  13. package/dist/__tests__/change-narrative.test.js +0 -190
  14. package/dist/__tests__/check-commit.test.js +0 -258
  15. package/dist/__tests__/checksum.test.js +0 -34
  16. package/dist/__tests__/commit-watcher.test.js +0 -154
  17. package/dist/__tests__/community-detection.test.js +0 -179
  18. package/dist/__tests__/community-tools.test.js +0 -299
  19. package/dist/__tests__/components.test.js +0 -449
  20. package/dist/__tests__/compression-log.test.js +0 -174
  21. package/dist/__tests__/compression-quality-monitor.test.js +0 -40
  22. package/dist/__tests__/config-healer.test.js +0 -165
  23. package/dist/__tests__/context-ledger.test.js +0 -58
  24. package/dist/__tests__/convention-detector.test.js +0 -99
  25. package/dist/__tests__/convention-learner.test.js +0 -86
  26. package/dist/__tests__/correction-detector.test.js +0 -330
  27. package/dist/__tests__/daemon-autostart-install.test.js +0 -283
  28. package/dist/__tests__/daemon-bridge.test.js +0 -222
  29. package/dist/__tests__/daemon-dashboard.test.js +0 -202
  30. package/dist/__tests__/daemon-registry.test.js +0 -240
  31. package/dist/__tests__/daemon-supervisor.test.js +0 -318
  32. package/dist/__tests__/daemon-version-check.test.js +0 -275
  33. package/dist/__tests__/decision-point-detector.test.js +0 -98
  34. package/dist/__tests__/deep-link.test.js +0 -143
  35. package/dist/__tests__/disallowed-tools.test.js +0 -115
  36. package/dist/__tests__/drift-tracker.test.js +0 -582
  37. package/dist/__tests__/durability-scorer.test.js +0 -152
  38. package/dist/__tests__/efficiency-tracker.test.js +0 -65
  39. package/dist/__tests__/enrich.test.js +0 -144
  40. package/dist/__tests__/entity-rewind.test.js +0 -248
  41. package/dist/__tests__/ephemeral.test.js +0 -111
  42. package/dist/__tests__/exploration-cost.test.js +0 -93
  43. package/dist/__tests__/fact-generator.test.js +0 -197
  44. package/dist/__tests__/file-l0-graph.test.js +0 -244
  45. package/dist/__tests__/file-logger.test.js +0 -82
  46. package/dist/__tests__/file-outline.test.js +0 -141
  47. package/dist/__tests__/file-read-protocol.test.js +0 -188
  48. package/dist/__tests__/format-encoder.test.js +0 -233
  49. package/dist/__tests__/git-attribution.test.js +0 -259
  50. package/dist/__tests__/graph-temporal-joiner.test.js +0 -219
  51. package/dist/__tests__/health-grade-enhanced.test.js +0 -138
  52. package/dist/__tests__/health-map-data.test.js +0 -173
  53. package/dist/__tests__/helpers/mcp-harness.js +0 -45
  54. package/dist/__tests__/helpers/mcp-harness.test.js +0 -68
  55. package/dist/__tests__/hook-dedup.test.js +0 -112
  56. package/dist/__tests__/hook-runner.test.js +0 -253
  57. package/dist/__tests__/indexer-cfg.test.js +0 -185
  58. package/dist/__tests__/indexer-cross-file.test.js +0 -172
  59. package/dist/__tests__/indexer-extraction.test.js +0 -245
  60. package/dist/__tests__/indexer-incremental.test.js +0 -232
  61. package/dist/__tests__/indexer-language-expansion.test.js +0 -165
  62. package/dist/__tests__/init-push.test.js +0 -131
  63. package/dist/__tests__/instruction-writer.test.js +0 -179
  64. package/dist/__tests__/intelligence-integration.test.js +0 -217
  65. package/dist/__tests__/intent-correlator.test.js +0 -175
  66. package/dist/__tests__/intent-detector.test.js +0 -235
  67. package/dist/__tests__/intent-encoder.test.js +0 -167
  68. package/dist/__tests__/java-build-tool-detection.test.js +0 -174
  69. package/dist/__tests__/layer3-sprint-q.test.js +0 -160
  70. package/dist/__tests__/layer3-sprint-r.test.js +0 -91
  71. package/dist/__tests__/layer3-sprint-s.test.js +0 -183
  72. package/dist/__tests__/layer3-sprint-t.test.js +0 -201
  73. package/dist/__tests__/layer3-sprint-u.test.js +0 -174
  74. package/dist/__tests__/layer4-sprint-ba2.test.js +0 -354
  75. package/dist/__tests__/layer4-sprint-ba4.test.js +0 -84
  76. package/dist/__tests__/layer4-sprint-vs.test.js +0 -105
  77. package/dist/__tests__/ledger-chains.test.js +0 -162
  78. package/dist/__tests__/lifecycle-machine.test.js +0 -226
  79. package/dist/__tests__/local-chat-provider.test.js +0 -170
  80. package/dist/__tests__/local-convention-detector.test.js +0 -308
  81. package/dist/__tests__/local-embeddings.test.js +0 -422
  82. package/dist/__tests__/local-graph.test.js +0 -540
  83. package/dist/__tests__/local-indexer.test.js +0 -228
  84. package/dist/__tests__/local-intelligence-l3.test.js +0 -332
  85. package/dist/__tests__/local-llm.test.js +0 -253
  86. package/dist/__tests__/local-mode-offline.test.js +0 -187
  87. package/dist/__tests__/local-mode-stats.test.js +0 -273
  88. package/dist/__tests__/local-mode-tui.test.js +0 -343
  89. package/dist/__tests__/local-parse.test.js +0 -199
  90. package/dist/__tests__/log-tailer.test.js +0 -208
  91. package/dist/__tests__/loop-breaker.test.js +0 -276
  92. package/dist/__tests__/loop-miner.test.js +0 -226
  93. package/dist/__tests__/mcp-config.test.js +0 -126
  94. package/dist/__tests__/mcp-content-json.test.js +0 -10
  95. package/dist/__tests__/mcp-envelope.test.js +0 -124
  96. package/dist/__tests__/metrics-store.test.js +0 -223
  97. package/dist/__tests__/native-watcher.test.js +0 -191
  98. package/dist/__tests__/navigation-hooks-agent-aware.test.js +0 -145
  99. package/dist/__tests__/negative-knowledge.test.js +0 -116
  100. package/dist/__tests__/network-boundary.test.js +0 -190
  101. package/dist/__tests__/network-firewall.test.js +0 -112
  102. package/dist/__tests__/nudge-invariants.test.js +0 -160
  103. package/dist/__tests__/nudge-v2.test.js +0 -225
  104. package/dist/__tests__/offline-rewind.test.js +0 -251
  105. package/dist/__tests__/open-threads.test.js +0 -89
  106. package/dist/__tests__/output-compressor.test.js +0 -93
  107. package/dist/__tests__/pending-violations.test.js +0 -112
  108. package/dist/__tests__/persistence-effectiveness.test.js +0 -143
  109. package/dist/__tests__/provider-factory.test.js +0 -42
  110. package/dist/__tests__/providers.test.js +0 -24
  111. package/dist/__tests__/proxy.test.js +0 -314
  112. package/dist/__tests__/query-router.test.js +0 -1018
  113. package/dist/__tests__/reasoning-quality-route.test.js +0 -138
  114. package/dist/__tests__/redactor.test.js +0 -120
  115. package/dist/__tests__/resource-monitor.test.js +0 -57
  116. package/dist/__tests__/response-envelope.test.js +0 -100
  117. package/dist/__tests__/risk-classifier.test.js +0 -101
  118. package/dist/__tests__/risk-signal-scope.test.js +0 -75
  119. package/dist/__tests__/rule-evaluator.test.js +0 -280
  120. package/dist/__tests__/scip-decoder.test.js +0 -49
  121. package/dist/__tests__/scip-downloader.test.js +0 -201
  122. package/dist/__tests__/scip-merger.test.js +0 -103
  123. package/dist/__tests__/search-index.test.js +0 -422
  124. package/dist/__tests__/semantic-enrichment.test.js +0 -360
  125. package/dist/__tests__/session-brief-builder.test.js +0 -187
  126. package/dist/__tests__/session-context.test.js +0 -221
  127. package/dist/__tests__/session-continuity.test.js +0 -144
  128. package/dist/__tests__/session-dedup.test.js +0 -74
  129. package/dist/__tests__/session-event-wiring.test.js +0 -206
  130. package/dist/__tests__/session-events.test.js +0 -149
  131. package/dist/__tests__/session-legend.test.js +0 -20
  132. package/dist/__tests__/session-persistence.test.js +0 -131
  133. package/dist/__tests__/session-resume-block.test.js +0 -107
  134. package/dist/__tests__/session-resume.test.js +0 -97
  135. package/dist/__tests__/session-summary-writer.test.js +0 -134
  136. package/dist/__tests__/shadow-ledger.test.js +0 -203
  137. package/dist/__tests__/shell-classifier.test.js +0 -151
  138. package/dist/__tests__/shell-compression-floor.test.js +0 -189
  139. package/dist/__tests__/shell-compression-v2.test.js +0 -339
  140. package/dist/__tests__/shell-compressor.test.js +0 -35
  141. package/dist/__tests__/shell-hooks.test.js +0 -128
  142. package/dist/__tests__/shell-strategies.test.js +0 -644
  143. package/dist/__tests__/shell-tee.test.js +0 -133
  144. package/dist/__tests__/signal-dedup.test.js +0 -158
  145. package/dist/__tests__/signal-reinforcer.test.js +0 -77
  146. package/dist/__tests__/signal-scorer.test.js +0 -251
  147. package/dist/__tests__/signal-show-store.test.js +0 -108
  148. package/dist/__tests__/smart-truncate.test.js +0 -215
  149. package/dist/__tests__/snapshot-v2.test.js +0 -113
  150. package/dist/__tests__/sprint-l1-local-mode.test.js +0 -130
  151. package/dist/__tests__/sprint-l10-boot.test.js +0 -220
  152. package/dist/__tests__/sprint-l9-offline-commands.test.js +0 -189
  153. package/dist/__tests__/sprint-q-persistent-context.test.js +0 -198
  154. package/dist/__tests__/sprint-s1-wiring.test.js +0 -215
  155. package/dist/__tests__/sprint-s2-wiring.test.js +0 -256
  156. package/dist/__tests__/sprint-s3-wiring.test.js +0 -195
  157. package/dist/__tests__/sprint-s4-wiring.test.js +0 -213
  158. package/dist/__tests__/sprint-s6-hooks.test.js +0 -222
  159. package/dist/__tests__/sprint-s7-persistent.test.js +0 -263
  160. package/dist/__tests__/sprint-s8-value.test.js +0 -167
  161. package/dist/__tests__/sprint-s9-behavioral.test.js +0 -179
  162. package/dist/__tests__/sprint3-intelligence.test.js +0 -297
  163. package/dist/__tests__/sprint5-mcp-server.test.js +0 -136
  164. package/dist/__tests__/startup-display.test.js +0 -302
  165. package/dist/__tests__/startup-log-file.test.js +0 -97
  166. package/dist/__tests__/stash-manager.test.js +0 -229
  167. package/dist/__tests__/state-detector.test.js +0 -92
  168. package/dist/__tests__/status-dashboard.test.js +0 -142
  169. package/dist/__tests__/temporal-facts.test.js +0 -292
  170. package/dist/__tests__/temporal-routes.test.js +0 -142
  171. package/dist/__tests__/test-detector.test.js +0 -174
  172. package/dist/__tests__/theme.test.js +0 -72
  173. package/dist/__tests__/timeline-agents.test.js +0 -122
  174. package/dist/__tests__/timeline-bootstrap.test.js +0 -176
  175. package/dist/__tests__/timeline-filters.test.js +0 -193
  176. package/dist/__tests__/timeline-markers.test.js +0 -151
  177. package/dist/__tests__/timeline-routes.test.js +0 -156
  178. package/dist/__tests__/timeline-store.test.js +0 -171
  179. package/dist/__tests__/token-counter.test.js +0 -86
  180. package/dist/__tests__/token-estimator.test.js +0 -96
  181. package/dist/__tests__/token-flow-api.test.js +0 -239
  182. package/dist/__tests__/token-flow-instrumentation.test.js +0 -437
  183. package/dist/__tests__/token-flow-persistence.test.js +0 -356
  184. package/dist/__tests__/token-flow-routes.test.js +0 -199
  185. package/dist/__tests__/token-flow.test.js +0 -695
  186. package/dist/__tests__/tool-clusters.test.js +0 -177
  187. package/dist/__tests__/transport-mux.test.js +0 -283
  188. package/dist/__tests__/turn-segmenter.test.js +0 -166
  189. package/dist/__tests__/uninstall.test.js +0 -141
  190. package/dist/__tests__/warm-start-policy.test.js +0 -271
  191. package/dist/__tests__/wire-cap-nudge.test.js +0 -77
  192. package/dist/__tests__/worker-pool.test.js +0 -101
  193. package/dist/ui/assets/index-7gl3mIuY.css +0 -1
  194. package/dist/ui/assets/index-BsMTQdhX.js +0 -10
  195. package/dist/ui/assets/rolldown-runtime-S-ySWqyJ.js +0 -1
  196. package/dist/ui/assets/vis-network-NIJHUFI3.js +0 -908
  197. package/dist/ui/fonts/jetbrains-mono-latin-400-normal.woff +0 -0
  198. package/dist/ui/icon-wordmark.png +0 -0
  199. package/dist/ui/icon-wordmark.svg +0 -30
  200. package/dist/ui/icon.png +0 -0
  201. package/dist/ui/icon.svg +0 -25
  202. package/dist/ui/index.html +0 -15
  203. package/dist/ui/prototype-sandbox/index.html +0 -257
  204. package/dist/ui/screenshots/activity.png +0 -0
  205. package/dist/ui/screenshots/code-base-intelligence.png +0 -0
  206. package/dist/ui/screenshots/dashboard.png +0 -0
  207. package/dist/ui/screenshots/project-memory.png +0 -0
  208. package/dist/ui/screenshots/reasoning-quality.png +0 -0
  209. package/dist/ui/screenshots/reasoning-session.png +0 -0
  210. package/dist/ui/screenshots/token-session.png +0 -0
  211. package/dist/ui/screenshots/token-trace-main.png +0 -0
  212. package/dist/ui/screenshots/token-turn.png +0 -0
  213. package/dist/ui/unerr-wordmark.png +0 -0
  214. package/dist/ui/unerr-wordmark.svg +0 -9
  215. package/dist/ui/unerr.png +0 -0
  216. package/dist/ui/unerr.svg +0 -25
  217. package/dist/ui/web-app-manifest-192x192.png +0 -0
  218. package/dist/ui/web-app-manifest-512x512.png +0 -0
@@ -1,220 +0,0 @@
1
- /**
2
- * Sprint L10: Unified Boot State Machine & Session Logging Tests
3
- *
4
- * Tests:
5
- * 1. Session logger — file creation, NDJSON format, cleanup, module loggers
6
- * 2. Preflight — lm:false denial, lm:true proceed, field absent, timeout, zero logs
7
- * 3. Setup wizard — WizardResult types, config file generation, repo ID generation
8
- * 4. Command visibility — only chat/status/debug shown in help
9
- */
10
- import { existsSync, mkdirSync, readFileSync, readdirSync, rmSync, writeFileSync, } from "node:fs";
11
- import { tmpdir } from "node:os";
12
- import { join } from "node:path";
13
- import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
14
- let tempDir;
15
- beforeEach(() => {
16
- tempDir = join(tmpdir(), `unerr-l10-test-${Date.now()}-${Math.random().toString(36).slice(2)}`);
17
- mkdirSync(tempDir, { recursive: true });
18
- });
19
- afterEach(async () => {
20
- // Give pino async transport time to flush before removing temp dir
21
- await new Promise((resolve) => setTimeout(resolve, 150));
22
- try {
23
- rmSync(tempDir, { recursive: true, force: true });
24
- }
25
- catch {
26
- /* ignore */
27
- }
28
- });
29
- // ── 1. Session Logger ─────────────────────────────────────────────
30
- describe("Session Logger", () => {
31
- it("creates log file in .unerr/logs/ with NDJSON format", async () => {
32
- // Reset module state for fresh logger
33
- vi.resetModules();
34
- const { initSessionLogger, getSessionLogPath, flushSessionLogger } = await import("../utils/session-logger.js");
35
- const logger = initSessionLogger({ cwd: tempDir, level: "info" });
36
- logger.info({ module: "test", msg: "hello world" });
37
- flushSessionLogger();
38
- // Give pino async transport a moment to flush
39
- await new Promise((resolve) => setTimeout(resolve, 100));
40
- const logPath = getSessionLogPath();
41
- expect(logPath).toBeTruthy();
42
- expect(existsSync(logPath)).toBe(true);
43
- // Verify path is under .unerr/logs/
44
- expect(logPath).toContain(join(".unerr", "logs", "session-"));
45
- expect(logPath).toMatch(/\.log$/);
46
- // Verify NDJSON format — each line is valid JSON
47
- const content = readFileSync(logPath, "utf-8").trim();
48
- const lines = content.split("\n").filter((l) => l.trim());
49
- expect(lines.length).toBeGreaterThanOrEqual(1);
50
- for (const line of lines) {
51
- const parsed = JSON.parse(line);
52
- expect(parsed).toHaveProperty("level");
53
- expect(parsed).toHaveProperty("session_id");
54
- }
55
- });
56
- it("returns same logger instance on repeated init calls", async () => {
57
- vi.resetModules();
58
- const { initSessionLogger } = await import("../utils/session-logger.js");
59
- const logger1 = initSessionLogger({ cwd: tempDir });
60
- const logger2 = initSessionLogger({ cwd: tempDir });
61
- expect(logger1).toBe(logger2);
62
- });
63
- it("createSessionModuleLogger produces child with module field", async () => {
64
- vi.resetModules();
65
- const { initSessionLogger, createSessionModuleLogger, getSessionLogPath, flushSessionLogger, } = await import("../utils/session-logger.js");
66
- initSessionLogger({ cwd: tempDir, level: "info" });
67
- const modLog = createSessionModuleLogger("boot");
68
- modLog.info({ msg: "boot started" });
69
- flushSessionLogger();
70
- await new Promise((resolve) => setTimeout(resolve, 100));
71
- const logPath = getSessionLogPath();
72
- const content = readFileSync(logPath, "utf-8").trim();
73
- const lines = content.split("\n").filter((l) => l.trim());
74
- const bootLine = lines.find((l) => {
75
- const parsed = JSON.parse(l);
76
- return parsed.tag === "boot" && parsed.msg.includes("boot started");
77
- });
78
- expect(bootLine).toBeTruthy();
79
- });
80
- it("getSessionId returns a UUID-format string", async () => {
81
- vi.resetModules();
82
- const { getSessionId } = await import("../utils/session-logger.js");
83
- const id = getSessionId();
84
- expect(id).toMatch(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/);
85
- });
86
- it("cleanup removes files older than retention period", async () => {
87
- vi.resetModules();
88
- // Create fake old log files
89
- const logsDir = join(tempDir, ".unerr", "logs");
90
- mkdirSync(logsDir, { recursive: true });
91
- // Create 12 fake log files (exceeds MAX_FILES of 10)
92
- for (let i = 0; i < 12; i++) {
93
- const fakePath = join(logsDir, `session-2020-01-${String(i + 1).padStart(2, "0")}-120000.log`);
94
- writeFileSync(fakePath, `{"level":"info","msg":"old"}\n`);
95
- // Set mtime to 60 days ago
96
- const oldTime = new Date(Date.now() - 60 * 24 * 60 * 60 * 1000);
97
- const { utimesSync } = await import("node:fs");
98
- utimesSync(fakePath, oldTime, oldTime);
99
- }
100
- // Init logger triggers cleanup
101
- const { initSessionLogger, flushSessionLogger } = await import("../utils/session-logger.js");
102
- initSessionLogger({ cwd: tempDir });
103
- flushSessionLogger();
104
- await new Promise((resolve) => setTimeout(resolve, 100));
105
- // Old files should be cleaned up (>30 days)
106
- const remaining = readdirSync(logsDir).filter((f) => f.startsWith("session-") && f.endsWith(".log"));
107
- // Should have at most MAX_FILES (10) + 1 new session log, but old ones (>30 days) deleted
108
- // The 12 old files are all >30 days, so they get deleted. Only the new session log remains.
109
- expect(remaining.length).toBeLessThanOrEqual(2); // new session + maybe 1 surviving
110
- });
111
- });
112
- // ── 3. Setup Wizard Types & Config Generation ─────────────────────
113
- describe("Setup Wizard", () => {
114
- it("exports wizard functions", async () => {
115
- const mod = await import("../commands/setup-wizard.js");
116
- expect(typeof mod.enterLocalModeSetup).toBe("function");
117
- expect(typeof mod.promptLocalOrExit).toBe("function");
118
- });
119
- it("generates deterministic local repo ID from cwd", async () => {
120
- // The wizard uses createHash("sha256").update(identifier).digest("hex").slice(0,12)
121
- // with "local-" prefix. Verify the pattern.
122
- const { createHash } = await import("node:crypto");
123
- const testPath = "/tmp/test-repo";
124
- const hash = createHash("sha256")
125
- .update(testPath)
126
- .digest("hex")
127
- .slice(0, 12);
128
- const repoId = `local-${hash}`;
129
- expect(repoId).toMatch(/^local-[0-9a-f]{12}$/);
130
- // Same input → same output
131
- const hash2 = createHash("sha256")
132
- .update(testPath)
133
- .digest("hex")
134
- .slice(0, 12);
135
- expect(`local-${hash2}`).toBe(repoId);
136
- });
137
- it("config.json written by wizard has expected shape", () => {
138
- // Simulate what enterLocalModeSetup writes
139
- const configDir = join(tempDir, ".unerr");
140
- mkdirSync(configDir, { recursive: true });
141
- const config = { repoId: "local-abc123def456" };
142
- writeFileSync(join(configDir, "config.json"), `${JSON.stringify(config, null, 2)}\n`);
143
- const parsed = JSON.parse(readFileSync(join(configDir, "config.json"), "utf-8"));
144
- expect(parsed.repoId).toMatch(/^local-/);
145
- });
146
- it("settings.json written by wizard has expected shape", () => {
147
- const configDir = join(tempDir, ".unerr");
148
- mkdirSync(configDir, { recursive: true });
149
- const settings = {
150
- localLlm: {
151
- provider: "ollama",
152
- baseUrl: "http://localhost:11434",
153
- embeddingModel: "nomic-embed-text",
154
- chatModel: "llama3",
155
- },
156
- };
157
- writeFileSync(join(configDir, "settings.json"), `${JSON.stringify(settings, null, 2)}\n`);
158
- const parsed = JSON.parse(readFileSync(join(configDir, "settings.json"), "utf-8"));
159
- expect(parsed.localLlm.provider).toBe("ollama");
160
- expect(parsed.localLlm.baseUrl).toBe("http://localhost:11434");
161
- });
162
- });
163
- // ── 4. Command Visibility ─────────────────────────────────────────
164
- describe("Command Visibility", () => {
165
- it("only chat, status, debug are visible in Commander", async () => {
166
- // We test this by importing Commander and checking _hidden flags
167
- // The cli.ts module calls program.parse() on import, so we test the logic directly
168
- const { Command } = await import("commander");
169
- // Simulate the visibility logic from cli.ts
170
- const program = new Command();
171
- program.command("chat").description("Chat");
172
- program.command("status").description("Status");
173
- program.command("debug").description("Debug");
174
- program.command("auth").description("Auth");
175
- program.command("push").description("Push");
176
- program.command("pull").description("Pull");
177
- program.command("sync").description("Sync");
178
- program.command("init").description("Init");
179
- const visibleCommands = new Set(["chat", "status", "debug"]);
180
- for (const cmd of program.commands) {
181
- if (!visibleCommands.has(cmd.name())) {
182
- cmd._hidden = true;
183
- }
184
- }
185
- // Verify visible commands
186
- const visible = program.commands.filter((cmd) => !cmd._hidden);
187
- const hidden = program.commands.filter((cmd) => cmd._hidden);
188
- expect(visible.map((c) => c.name()).sort()).toEqual(["chat", "debug", "status"].sort());
189
- expect(hidden.length).toBe(5); // auth, push, pull, sync, init
190
- expect(hidden.every((c) => !visibleCommands.has(c.name()))).toBe(true);
191
- });
192
- it("hidden commands are still registered and callable", async () => {
193
- const { Command } = await import("commander");
194
- const program = new Command();
195
- program.command("auth").description("Auth");
196
- program.commands[0]._hidden = true;
197
- // The command still exists even though hidden
198
- const authCmd = program.commands.find((c) => c.name() === "auth");
199
- expect(authCmd).toBeTruthy();
200
- });
201
- });
202
- // ── 5. Boot State Machine Logic ───────────────────────────────────
203
- describe("Boot State Machine", () => {
204
- it("readLocalConfig returns null when no .unerr/config.json exists", async () => {
205
- // Test the logic from cli.ts — config detection
206
- const configPath = join(tempDir, ".unerr", "config.json");
207
- expect(existsSync(configPath)).toBe(false);
208
- });
209
- it("readLocalConfig returns parsed config when .unerr/config.json exists", () => {
210
- const configDir = join(tempDir, ".unerr");
211
- mkdirSync(configDir, { recursive: true });
212
- const config = { repoId: "local-abc123" };
213
- writeFileSync(join(configDir, "config.json"), JSON.stringify(config));
214
- // Replicate readLocalConfig logic
215
- const configPath = join(tempDir, ".unerr", "config.json");
216
- expect(existsSync(configPath)).toBe(true);
217
- const parsed = JSON.parse(readFileSync(configPath, "utf-8"));
218
- expect(parsed.repoId).toBe("local-abc123");
219
- });
220
- });
@@ -1,189 +0,0 @@
1
- /**
2
- * Tests for Sprint L9 — Offline Command Replacements.
3
- *
4
- * L9.1: unerr branches local implementation
5
- * L9.2: unerr timeline local implementation
6
- * L9.3: RewindReconciler explicit Local Mode guard
7
- * L9.4: sync_local_diff drift overlay writes (tested via QueryRouter integration)
8
- */
9
- import { mkdtempSync, writeFileSync } from "node:fs";
10
- import { tmpdir } from "node:os";
11
- import { join } from "node:path";
12
- import { describe, expect, it } from "vitest";
13
- // ── L9.2: Timeline Tests ────────────────────────────────────────
14
- // Note: We mirror formatRelativeTime and readShadowLedger here to avoid
15
- // importing timeline.ts which transitively imports auth.ts (esbuild issue).
16
- import { existsSync, readFileSync } from "node:fs";
17
- function formatRelativeTime(isoTs) {
18
- const diff = Date.now() - new Date(isoTs).getTime();
19
- const seconds = Math.floor(diff / 1000);
20
- if (seconds < 60)
21
- return `${seconds}s ago`;
22
- const minutes = Math.floor(seconds / 60);
23
- if (minutes < 60)
24
- return `${minutes} min ago`;
25
- const hours = Math.floor(minutes / 60);
26
- if (hours < 24)
27
- return `${hours}h ago`;
28
- const days = Math.floor(hours / 24);
29
- return `${days}d ago`;
30
- }
31
- function readShadowLedger(ledgerPath) {
32
- if (!existsSync(ledgerPath))
33
- return [];
34
- try {
35
- const raw = readFileSync(ledgerPath, "utf-8");
36
- const entries = [];
37
- for (const line of raw.split("\n")) {
38
- const trimmed = line.trim();
39
- if (!trimmed)
40
- continue;
41
- try {
42
- entries.push(JSON.parse(trimmed));
43
- }
44
- catch {
45
- // Skip malformed lines
46
- }
47
- }
48
- return entries;
49
- }
50
- catch {
51
- return [];
52
- }
53
- }
54
- describe("formatRelativeTime (L9.2)", () => {
55
- it("formats seconds ago", () => {
56
- const ts = new Date(Date.now() - 30_000).toISOString();
57
- expect(formatRelativeTime(ts)).toBe("30s ago");
58
- });
59
- it("formats minutes ago", () => {
60
- const ts = new Date(Date.now() - 5 * 60_000).toISOString();
61
- expect(formatRelativeTime(ts)).toBe("5 min ago");
62
- });
63
- it("formats hours ago", () => {
64
- const ts = new Date(Date.now() - 3 * 3600_000).toISOString();
65
- expect(formatRelativeTime(ts)).toBe("3h ago");
66
- });
67
- it("formats days ago", () => {
68
- const ts = new Date(Date.now() - 2 * 86400_000).toISOString();
69
- expect(formatRelativeTime(ts)).toBe("2d ago");
70
- });
71
- });
72
- describe("readShadowLedger (L9.2)", () => {
73
- it("reads JSONL entries from ledger file", () => {
74
- const dir = mkdtempSync(join(tmpdir(), "unerr-l9-"));
75
- const ledgerPath = join(dir, "shadow.jsonl");
76
- const entries = [
77
- {
78
- id: "abc123",
79
- ts: "2025-01-01T10:00:00Z",
80
- tool: "get_function",
81
- args_summary: { key: "processPayment" },
82
- result_summary: { found: true },
83
- branch: "main",
84
- head_sha: "deadbeef",
85
- session_id: "sess1",
86
- correlation_id: null,
87
- },
88
- {
89
- id: "def456",
90
- ts: "2025-01-01T10:05:00Z",
91
- tool: "check_rules",
92
- args_summary: { file_path: "src/payment.ts" },
93
- result_summary: { violations: 0 },
94
- branch: "main",
95
- head_sha: "deadbeef",
96
- session_id: "sess1",
97
- correlation_id: "abc123",
98
- },
99
- ];
100
- writeFileSync(ledgerPath, entries.map((e) => JSON.stringify(e)).join("\n"));
101
- const result = readShadowLedger(ledgerPath);
102
- expect(result).toHaveLength(2);
103
- expect(result[0]?.tool).toBe("get_function");
104
- expect(result[1]?.tool).toBe("check_rules");
105
- expect(result[0]?.branch).toBe("main");
106
- });
107
- it("returns empty array for missing file", () => {
108
- const result = readShadowLedger("/nonexistent/path/shadow.jsonl");
109
- expect(result).toHaveLength(0);
110
- });
111
- it("skips malformed lines", () => {
112
- const dir = mkdtempSync(join(tmpdir(), "unerr-l9-"));
113
- const ledgerPath = join(dir, "shadow.jsonl");
114
- writeFileSync(ledgerPath, [
115
- JSON.stringify({
116
- id: "abc",
117
- ts: "2025-01-01T10:00:00Z",
118
- tool: "get_function",
119
- args_summary: {},
120
- result_summary: {},
121
- branch: "main",
122
- head_sha: "abc",
123
- session_id: "s1",
124
- correlation_id: null,
125
- }),
126
- "not json",
127
- JSON.stringify({
128
- id: "def",
129
- ts: "2025-01-01T10:01:00Z",
130
- tool: "get_class",
131
- args_summary: {},
132
- result_summary: {},
133
- branch: "main",
134
- head_sha: "def",
135
- session_id: "s1",
136
- correlation_id: null,
137
- }),
138
- ].join("\n"));
139
- const result = readShadowLedger(ledgerPath);
140
- expect(result).toHaveLength(2);
141
- expect(result[0]?.id).toBe("abc");
142
- expect(result[1]?.id).toBe("def");
143
- });
144
- it("supports branch filter pattern", () => {
145
- const dir = mkdtempSync(join(tmpdir(), "unerr-l9-"));
146
- const ledgerPath = join(dir, "shadow.jsonl");
147
- const entries = [
148
- {
149
- id: "a1",
150
- ts: "2025-01-01T10:00:00Z",
151
- tool: "get_function",
152
- args_summary: {},
153
- result_summary: {},
154
- branch: "main",
155
- head_sha: "a",
156
- session_id: "s1",
157
- correlation_id: null,
158
- },
159
- {
160
- id: "b1",
161
- ts: "2025-01-01T10:01:00Z",
162
- tool: "get_class",
163
- args_summary: {},
164
- result_summary: {},
165
- branch: "feature/auth",
166
- head_sha: "b",
167
- session_id: "s1",
168
- correlation_id: null,
169
- },
170
- {
171
- id: "c1",
172
- ts: "2025-01-01T10:02:00Z",
173
- tool: "check_rules",
174
- args_summary: {},
175
- result_summary: {},
176
- branch: "main",
177
- head_sha: "c",
178
- session_id: "s1",
179
- correlation_id: null,
180
- },
181
- ];
182
- writeFileSync(ledgerPath, entries.map((e) => JSON.stringify(e)).join("\n"));
183
- const all = readShadowLedger(ledgerPath);
184
- const mainOnly = all.filter((e) => e.branch === "main");
185
- expect(mainOnly).toHaveLength(2);
186
- expect(mainOnly[0]?.id).toBe("a1");
187
- expect(mainOnly[1]?.id).toBe("c1");
188
- });
189
- });
@@ -1,198 +0,0 @@
1
- /**
2
- * Sprint Q: Persistent Context & Causal Intelligence tests.
3
- *
4
- * Tests the complete persistent intelligence loop:
5
- * Q.1: Causal bridge, Q.2: Auto-snapshots, Q.3: Convention learning,
6
- * Q.4: Session resume, Q.5: Timeline forks, Q.6: Prompt durability,
7
- * Q.9: Session health + exploration cost
8
- */
9
- import { describe, expect, it } from "vitest";
10
- describe("Q.1: Causal Bridge Query Engine", () => {
11
- it("assembles causal chain from entity interactions", async () => {
12
- const { assembleCausalChain } = await import("../tracking/causal-bridge.js");
13
- const entries = [
14
- {
15
- id: "e1",
16
- ts: "2026-05-01T10:00:00Z",
17
- tool: "sync_local_diff",
18
- args_summary: {
19
- files: ["src/auth.ts"],
20
- prompt: "Add login validation",
21
- },
22
- result_summary: {},
23
- session_id: "s1",
24
- head_sha: "abc",
25
- },
26
- {
27
- id: "e2",
28
- ts: "2026-05-01T10:05:00Z",
29
- tool: "sync_local_diff",
30
- args_summary: {
31
- files: ["src/auth.ts"],
32
- prompt: "Fix validation edge case",
33
- },
34
- result_summary: { commit_sha: "def" },
35
- session_id: "s1",
36
- head_sha: "def",
37
- },
38
- ];
39
- const chain = assembleCausalChain("src/auth.ts", entries);
40
- expect(chain.entityKey).toBe("src/auth.ts");
41
- expect(chain.interactions.length).toBeGreaterThanOrEqual(1);
42
- });
43
- it("computes durability from survival data", async () => {
44
- const { computeDurability } = await import("../tracking/causal-bridge.js");
45
- const interactions = [
46
- { survived: true, survivalMs: 86400000 },
47
- { survived: true, survivalMs: 86400000 },
48
- { survived: false, survivalMs: 3600000 },
49
- ];
50
- const durability = computeDurability(interactions);
51
- expect(durability).toBeGreaterThan(0.5);
52
- expect(durability).toBeLessThanOrEqual(1.0);
53
- });
54
- });
55
- describe("Q.2: Auto-Snapshot Triggers", () => {
56
- it("detects test pass commands", async () => {
57
- const { isTestCommand } = await import("../tracking/auto-snapshot-triggers.js");
58
- expect(isTestCommand("pnpm test:run")).toBe(true);
59
- expect(isTestCommand("vitest run")).toBe(true);
60
- expect(isTestCommand("jest --coverage")).toBe(true);
61
- expect(isTestCommand("pytest -v")).toBe(true);
62
- expect(isTestCommand("git status")).toBe(false);
63
- expect(isTestCommand("ls -la")).toBe(false);
64
- });
65
- it("triggers snapshot on test pass", async () => {
66
- const { shouldAutoSnapshot } = await import("../tracking/auto-snapshot-triggers.js");
67
- const trigger = shouldAutoSnapshot("bash", { command: "pnpm test:run" }, { exitCode: 0 });
68
- expect(trigger).not.toBeNull();
69
- expect(trigger?.type).toBe("test_pass");
70
- });
71
- it("does not trigger on test failure", async () => {
72
- const { shouldAutoSnapshot } = await import("../tracking/auto-snapshot-triggers.js");
73
- const trigger = shouldAutoSnapshot("bash", { command: "pnpm test:run" }, { exitCode: 1 });
74
- expect(trigger).toBeNull();
75
- });
76
- });
77
- describe("Q.5: Timeline Branching on Rewind", () => {
78
- it("creates timeline fork with abandoned + new branches", async () => {
79
- const { createTimelineFork } = await import("../tracking/timeline-fork.js");
80
- const fork = createTimelineFork("snapshot-123", ["src/auth.ts::login", "src/auth.ts::validate"], ["Add optional param to login", "Fix validate edge case"], "Broke 3 downstream callers");
81
- expect(fork.forkPoint).toBe("snapshot-123");
82
- expect(fork.abandonedBranch.entityChanges).toHaveLength(2);
83
- expect(fork.abandonedBranch.promptsTried).toHaveLength(2);
84
- expect(fork.abandonedBranch.failureReason).toContain("Broke");
85
- expect(fork.newBranch.timelineId).toBeGreaterThan(fork.abandonedBranch.timelineId);
86
- });
87
- });
88
- describe("Q.6: Prompt Durability Ranking", () => {
89
- it("extracts action types from prompts", async () => {
90
- const { extractActionType } = await import("../tracking/prompt-durability.js");
91
- expect(extractActionType("Add a new helper function")).toBe("add");
92
- expect(extractActionType("Fix the authentication bug")).toBe("fix");
93
- expect(extractActionType("Refactor the payment module")).toBe("refactor");
94
- expect(extractActionType("Modify the user service")).toBe("modify");
95
- expect(extractActionType("Delete unused imports")).toBe("delete");
96
- expect(extractActionType("Do something complex")).toBe("other");
97
- });
98
- it("computes durability profiles", async () => {
99
- const { computePromptDurabilityProfiles } = await import("../tracking/prompt-durability.js");
100
- const entries = [
101
- {
102
- prompt: "Add helper function",
103
- files: ["src/utils.ts"],
104
- survived: true,
105
- riskLevel: "low",
106
- },
107
- {
108
- prompt: "Add another helper",
109
- files: ["src/utils.ts"],
110
- survived: true,
111
- riskLevel: "low",
112
- },
113
- {
114
- prompt: "Modify critical service",
115
- files: ["src/core.ts"],
116
- survived: false,
117
- riskLevel: "critical",
118
- },
119
- ];
120
- const profiles = computePromptDurabilityProfiles(entries);
121
- expect(profiles.length).toBeGreaterThanOrEqual(1);
122
- const addProfile = profiles.find((p) => p.actionType === "add");
123
- if (addProfile) {
124
- expect(addProfile.durability).toBe(1.0);
125
- }
126
- });
127
- });
128
- describe("Q.9: Session Health Monitor", () => {
129
- it("starts healthy", async () => {
130
- const { createSessionHealthMonitor } = await import("../intelligence/session-health-monitor.js");
131
- const monitor = createSessionHealthMonitor();
132
- const health = monitor.getHealth();
133
- expect(health.health).toBe(1.0);
134
- expect(health.recommendation).toBe("continue");
135
- expect(health.signals).toHaveLength(0);
136
- });
137
- it("detects repeated queries as degradation", async () => {
138
- const { createSessionHealthMonitor } = await import("../intelligence/session-health-monitor.js");
139
- const monitor = createSessionHealthMonitor();
140
- for (let i = 0; i < 5; i++) {
141
- monitor.recordToolCall("get_function", "entity-x");
142
- }
143
- const health = monitor.getHealth();
144
- expect(health.health).toBeLessThan(1.0);
145
- const repeated = health.signals.find((s) => s.type === "repeated_query");
146
- expect(repeated).toBeDefined();
147
- });
148
- it("detects convention violation spikes", async () => {
149
- const { createSessionHealthMonitor } = await import("../intelligence/session-health-monitor.js");
150
- const monitor = createSessionHealthMonitor();
151
- for (let i = 0; i < 6; i++) {
152
- monitor.recordConventionViolation();
153
- }
154
- const health = monitor.getHealth();
155
- const spike = health.signals.find((s) => s.type === "convention_violation_spike");
156
- expect(spike).toBeDefined();
157
- });
158
- });
159
- describe("Q.9: Exploration Cost Estimator", () => {
160
- it("estimates counterfactual for blast_radius query", async () => {
161
- const { estimateExplorationCost } = await import("../intelligence/exploration-cost.js");
162
- const estimate = estimateExplorationCost("blast_radius", 500, 10);
163
- expect(estimate.tokensWithout).toBeGreaterThan(estimate.tokensUsed);
164
- expect(estimate.counterfactualMethod).toBeTruthy();
165
- expect(estimate.explanation).toBeTruthy();
166
- });
167
- it("accumulates session savings", async () => {
168
- const { createExplorationAccumulator, estimateExplorationCost } = await import("../intelligence/exploration-cost.js");
169
- const acc = createExplorationAccumulator();
170
- acc.record(estimateExplorationCost("blast_radius", 500, 10));
171
- acc.record(estimateExplorationCost("find_callers", 200, 5));
172
- const total = acc.getTotal();
173
- expect(total.saved).toBeGreaterThan(0);
174
- expect(total.ratio).toBeGreaterThan(0);
175
- });
176
- });
177
- describe("Q: Intent Token Tracker", () => {
178
- it("tracks tokens per intent group", async () => {
179
- const { createIntentTokenTracker } = await import("../tracking/intent-token-tracker.js");
180
- const tracker = createIntentTokenTracker();
181
- tracker.recordToolCall("intent-1", 500, 200, "entity-a");
182
- tracker.recordToolCall("intent-1", 300, 100, "entity-b");
183
- const group = tracker.getGroup("intent-1");
184
- expect(group).not.toBeNull();
185
- expect(group?.toolCalls).toBe(2);
186
- expect(group?.tokensConsumed).toBe(800);
187
- expect(group?.tokensSaved).toBe(300);
188
- expect(group?.entitiesModified).toContain("entity-a");
189
- });
190
- it("marks outcomes", async () => {
191
- const { createIntentTokenTracker } = await import("../tracking/intent-token-tracker.js");
192
- const tracker = createIntentTokenTracker();
193
- tracker.recordToolCall("intent-2", 100, 50);
194
- tracker.markOutcome("intent-2", "completed");
195
- const group = tracker.getGroup("intent-2");
196
- expect(group?.outcome).toBe("completed");
197
- });
198
- });