@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.
- package/README.md +70 -194
- package/dist/cli.js +39149 -36991
- package/package.json +9 -2
- package/dist/__tests__/architecture-guard.test.js +0 -122
- package/dist/__tests__/arg-validator.test.js +0 -205
- package/dist/__tests__/ast-extractor.test.js +0 -203
- package/dist/__tests__/auto-bootstrap.test.js +0 -280
- package/dist/__tests__/background-indexer.test.js +0 -228
- package/dist/__tests__/blast-radius-engine.test.js +0 -200
- package/dist/__tests__/bridge-isolation.test.js +0 -37
- package/dist/__tests__/budget-enforcer.test.js +0 -53
- package/dist/__tests__/cfg-test-detection-perf.test.js +0 -82
- package/dist/__tests__/change-narrative.test.js +0 -190
- package/dist/__tests__/check-commit.test.js +0 -258
- package/dist/__tests__/checksum.test.js +0 -34
- package/dist/__tests__/commit-watcher.test.js +0 -154
- package/dist/__tests__/community-detection.test.js +0 -179
- package/dist/__tests__/community-tools.test.js +0 -299
- package/dist/__tests__/components.test.js +0 -449
- package/dist/__tests__/compression-log.test.js +0 -174
- package/dist/__tests__/compression-quality-monitor.test.js +0 -40
- package/dist/__tests__/config-healer.test.js +0 -165
- package/dist/__tests__/context-ledger.test.js +0 -58
- package/dist/__tests__/convention-detector.test.js +0 -99
- package/dist/__tests__/convention-learner.test.js +0 -86
- package/dist/__tests__/correction-detector.test.js +0 -330
- package/dist/__tests__/daemon-autostart-install.test.js +0 -283
- package/dist/__tests__/daemon-bridge.test.js +0 -222
- package/dist/__tests__/daemon-dashboard.test.js +0 -202
- package/dist/__tests__/daemon-registry.test.js +0 -240
- package/dist/__tests__/daemon-supervisor.test.js +0 -318
- package/dist/__tests__/daemon-version-check.test.js +0 -275
- package/dist/__tests__/decision-point-detector.test.js +0 -98
- package/dist/__tests__/deep-link.test.js +0 -143
- package/dist/__tests__/disallowed-tools.test.js +0 -115
- package/dist/__tests__/drift-tracker.test.js +0 -582
- package/dist/__tests__/durability-scorer.test.js +0 -152
- package/dist/__tests__/efficiency-tracker.test.js +0 -65
- package/dist/__tests__/enrich.test.js +0 -144
- package/dist/__tests__/entity-rewind.test.js +0 -248
- package/dist/__tests__/ephemeral.test.js +0 -111
- package/dist/__tests__/exploration-cost.test.js +0 -93
- package/dist/__tests__/fact-generator.test.js +0 -197
- package/dist/__tests__/file-l0-graph.test.js +0 -244
- package/dist/__tests__/file-logger.test.js +0 -82
- package/dist/__tests__/file-outline.test.js +0 -141
- package/dist/__tests__/file-read-protocol.test.js +0 -188
- package/dist/__tests__/format-encoder.test.js +0 -233
- package/dist/__tests__/git-attribution.test.js +0 -259
- package/dist/__tests__/graph-temporal-joiner.test.js +0 -219
- package/dist/__tests__/health-grade-enhanced.test.js +0 -138
- package/dist/__tests__/health-map-data.test.js +0 -173
- package/dist/__tests__/helpers/mcp-harness.js +0 -45
- package/dist/__tests__/helpers/mcp-harness.test.js +0 -68
- package/dist/__tests__/hook-dedup.test.js +0 -112
- package/dist/__tests__/hook-runner.test.js +0 -253
- package/dist/__tests__/indexer-cfg.test.js +0 -185
- package/dist/__tests__/indexer-cross-file.test.js +0 -172
- package/dist/__tests__/indexer-extraction.test.js +0 -245
- package/dist/__tests__/indexer-incremental.test.js +0 -232
- package/dist/__tests__/indexer-language-expansion.test.js +0 -165
- package/dist/__tests__/init-push.test.js +0 -131
- package/dist/__tests__/instruction-writer.test.js +0 -179
- package/dist/__tests__/intelligence-integration.test.js +0 -217
- package/dist/__tests__/intent-correlator.test.js +0 -175
- package/dist/__tests__/intent-detector.test.js +0 -235
- package/dist/__tests__/intent-encoder.test.js +0 -167
- package/dist/__tests__/java-build-tool-detection.test.js +0 -174
- package/dist/__tests__/layer3-sprint-q.test.js +0 -160
- package/dist/__tests__/layer3-sprint-r.test.js +0 -91
- package/dist/__tests__/layer3-sprint-s.test.js +0 -183
- package/dist/__tests__/layer3-sprint-t.test.js +0 -201
- package/dist/__tests__/layer3-sprint-u.test.js +0 -174
- package/dist/__tests__/layer4-sprint-ba2.test.js +0 -354
- package/dist/__tests__/layer4-sprint-ba4.test.js +0 -84
- package/dist/__tests__/layer4-sprint-vs.test.js +0 -105
- package/dist/__tests__/ledger-chains.test.js +0 -162
- package/dist/__tests__/lifecycle-machine.test.js +0 -226
- package/dist/__tests__/local-chat-provider.test.js +0 -170
- package/dist/__tests__/local-convention-detector.test.js +0 -308
- package/dist/__tests__/local-embeddings.test.js +0 -422
- package/dist/__tests__/local-graph.test.js +0 -540
- package/dist/__tests__/local-indexer.test.js +0 -228
- package/dist/__tests__/local-intelligence-l3.test.js +0 -332
- package/dist/__tests__/local-llm.test.js +0 -253
- package/dist/__tests__/local-mode-offline.test.js +0 -187
- package/dist/__tests__/local-mode-stats.test.js +0 -273
- package/dist/__tests__/local-mode-tui.test.js +0 -343
- package/dist/__tests__/local-parse.test.js +0 -199
- package/dist/__tests__/log-tailer.test.js +0 -208
- package/dist/__tests__/loop-breaker.test.js +0 -276
- package/dist/__tests__/loop-miner.test.js +0 -226
- package/dist/__tests__/mcp-config.test.js +0 -126
- package/dist/__tests__/mcp-content-json.test.js +0 -10
- package/dist/__tests__/mcp-envelope.test.js +0 -124
- package/dist/__tests__/metrics-store.test.js +0 -223
- package/dist/__tests__/native-watcher.test.js +0 -191
- package/dist/__tests__/navigation-hooks-agent-aware.test.js +0 -145
- package/dist/__tests__/negative-knowledge.test.js +0 -116
- package/dist/__tests__/network-boundary.test.js +0 -190
- package/dist/__tests__/network-firewall.test.js +0 -112
- package/dist/__tests__/nudge-invariants.test.js +0 -160
- package/dist/__tests__/nudge-v2.test.js +0 -225
- package/dist/__tests__/offline-rewind.test.js +0 -251
- package/dist/__tests__/open-threads.test.js +0 -89
- package/dist/__tests__/output-compressor.test.js +0 -93
- package/dist/__tests__/pending-violations.test.js +0 -112
- package/dist/__tests__/persistence-effectiveness.test.js +0 -143
- package/dist/__tests__/provider-factory.test.js +0 -42
- package/dist/__tests__/providers.test.js +0 -24
- package/dist/__tests__/proxy.test.js +0 -314
- package/dist/__tests__/query-router.test.js +0 -1018
- package/dist/__tests__/reasoning-quality-route.test.js +0 -138
- package/dist/__tests__/redactor.test.js +0 -120
- package/dist/__tests__/resource-monitor.test.js +0 -57
- package/dist/__tests__/response-envelope.test.js +0 -100
- package/dist/__tests__/risk-classifier.test.js +0 -101
- package/dist/__tests__/risk-signal-scope.test.js +0 -75
- package/dist/__tests__/rule-evaluator.test.js +0 -280
- package/dist/__tests__/scip-decoder.test.js +0 -49
- package/dist/__tests__/scip-downloader.test.js +0 -201
- package/dist/__tests__/scip-merger.test.js +0 -103
- package/dist/__tests__/search-index.test.js +0 -422
- package/dist/__tests__/semantic-enrichment.test.js +0 -360
- package/dist/__tests__/session-brief-builder.test.js +0 -187
- package/dist/__tests__/session-context.test.js +0 -221
- package/dist/__tests__/session-continuity.test.js +0 -144
- package/dist/__tests__/session-dedup.test.js +0 -74
- package/dist/__tests__/session-event-wiring.test.js +0 -206
- package/dist/__tests__/session-events.test.js +0 -149
- package/dist/__tests__/session-legend.test.js +0 -20
- package/dist/__tests__/session-persistence.test.js +0 -131
- package/dist/__tests__/session-resume-block.test.js +0 -107
- package/dist/__tests__/session-resume.test.js +0 -97
- package/dist/__tests__/session-summary-writer.test.js +0 -134
- package/dist/__tests__/shadow-ledger.test.js +0 -203
- package/dist/__tests__/shell-classifier.test.js +0 -151
- package/dist/__tests__/shell-compression-floor.test.js +0 -189
- package/dist/__tests__/shell-compression-v2.test.js +0 -339
- package/dist/__tests__/shell-compressor.test.js +0 -35
- package/dist/__tests__/shell-hooks.test.js +0 -128
- package/dist/__tests__/shell-strategies.test.js +0 -644
- package/dist/__tests__/shell-tee.test.js +0 -133
- package/dist/__tests__/signal-dedup.test.js +0 -158
- package/dist/__tests__/signal-reinforcer.test.js +0 -77
- package/dist/__tests__/signal-scorer.test.js +0 -251
- package/dist/__tests__/signal-show-store.test.js +0 -108
- package/dist/__tests__/smart-truncate.test.js +0 -215
- package/dist/__tests__/snapshot-v2.test.js +0 -113
- package/dist/__tests__/sprint-l1-local-mode.test.js +0 -130
- package/dist/__tests__/sprint-l10-boot.test.js +0 -220
- package/dist/__tests__/sprint-l9-offline-commands.test.js +0 -189
- package/dist/__tests__/sprint-q-persistent-context.test.js +0 -198
- package/dist/__tests__/sprint-s1-wiring.test.js +0 -215
- package/dist/__tests__/sprint-s2-wiring.test.js +0 -256
- package/dist/__tests__/sprint-s3-wiring.test.js +0 -195
- package/dist/__tests__/sprint-s4-wiring.test.js +0 -213
- package/dist/__tests__/sprint-s6-hooks.test.js +0 -222
- package/dist/__tests__/sprint-s7-persistent.test.js +0 -263
- package/dist/__tests__/sprint-s8-value.test.js +0 -167
- package/dist/__tests__/sprint-s9-behavioral.test.js +0 -179
- package/dist/__tests__/sprint3-intelligence.test.js +0 -297
- package/dist/__tests__/sprint5-mcp-server.test.js +0 -136
- package/dist/__tests__/startup-display.test.js +0 -302
- package/dist/__tests__/startup-log-file.test.js +0 -97
- package/dist/__tests__/stash-manager.test.js +0 -229
- package/dist/__tests__/state-detector.test.js +0 -92
- package/dist/__tests__/status-dashboard.test.js +0 -142
- package/dist/__tests__/temporal-facts.test.js +0 -292
- package/dist/__tests__/temporal-routes.test.js +0 -142
- package/dist/__tests__/test-detector.test.js +0 -174
- package/dist/__tests__/theme.test.js +0 -72
- package/dist/__tests__/timeline-agents.test.js +0 -122
- package/dist/__tests__/timeline-bootstrap.test.js +0 -176
- package/dist/__tests__/timeline-filters.test.js +0 -193
- package/dist/__tests__/timeline-markers.test.js +0 -151
- package/dist/__tests__/timeline-routes.test.js +0 -156
- package/dist/__tests__/timeline-store.test.js +0 -171
- package/dist/__tests__/token-counter.test.js +0 -86
- package/dist/__tests__/token-estimator.test.js +0 -96
- package/dist/__tests__/token-flow-api.test.js +0 -239
- package/dist/__tests__/token-flow-instrumentation.test.js +0 -437
- package/dist/__tests__/token-flow-persistence.test.js +0 -356
- package/dist/__tests__/token-flow-routes.test.js +0 -199
- package/dist/__tests__/token-flow.test.js +0 -695
- package/dist/__tests__/tool-clusters.test.js +0 -177
- package/dist/__tests__/transport-mux.test.js +0 -283
- package/dist/__tests__/turn-segmenter.test.js +0 -166
- package/dist/__tests__/uninstall.test.js +0 -141
- package/dist/__tests__/warm-start-policy.test.js +0 -271
- package/dist/__tests__/wire-cap-nudge.test.js +0 -77
- package/dist/__tests__/worker-pool.test.js +0 -101
- package/dist/ui/assets/index-7gl3mIuY.css +0 -1
- package/dist/ui/assets/index-CX4FCWGT.js +0 -10
- package/dist/ui/assets/rolldown-runtime-S-ySWqyJ.js +0 -1
- package/dist/ui/assets/vis-network-NIJHUFI3.js +0 -908
- package/dist/ui/fonts/jetbrains-mono-latin-400-normal.woff +0 -0
- package/dist/ui/icon-wordmark.png +0 -0
- package/dist/ui/icon-wordmark.svg +0 -30
- package/dist/ui/icon.png +0 -0
- package/dist/ui/icon.svg +0 -25
- package/dist/ui/index.html +0 -15
- package/dist/ui/prototype-sandbox/index.html +0 -257
- package/dist/ui/screenshots/activity.png +0 -0
- package/dist/ui/screenshots/code-base-intelligence.png +0 -0
- package/dist/ui/screenshots/dashboard.png +0 -0
- package/dist/ui/screenshots/project-memory.png +0 -0
- package/dist/ui/screenshots/reasoning-quality.png +0 -0
- package/dist/ui/screenshots/reasoning-session.png +0 -0
- package/dist/ui/screenshots/token-session.png +0 -0
- package/dist/ui/screenshots/token-trace-main.png +0 -0
- package/dist/ui/screenshots/token-turn.png +0 -0
- package/dist/ui/unerr-wordmark.png +0 -0
- package/dist/ui/unerr-wordmark.svg +0 -9
- package/dist/ui/unerr.png +0 -0
- package/dist/ui/unerr.svg +0 -25
- package/dist/ui/web-app-manifest-192x192.png +0 -0
- package/dist/ui/web-app-manifest-512x512.png +0 -0
|
@@ -1,226 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ST-3a: Loop miner — file rereads + repeated search_code queries.
|
|
3
|
-
*/
|
|
4
|
-
import { describe, expect, it } from "vitest";
|
|
5
|
-
import { detectFileReadLoops, detectLoops, detectQueryLoops, } from "../timeline/loop-miner.js";
|
|
6
|
-
let idCounter = 0;
|
|
7
|
-
function entry(overrides) {
|
|
8
|
-
idCounter += 1;
|
|
9
|
-
return {
|
|
10
|
-
id: `e${idCounter}`,
|
|
11
|
-
ts: overrides.ts,
|
|
12
|
-
tool: overrides.tool,
|
|
13
|
-
args_summary: overrides.args_summary ?? {},
|
|
14
|
-
result_summary: overrides.result_summary ?? {},
|
|
15
|
-
branch: "main",
|
|
16
|
-
head_sha: "abc",
|
|
17
|
-
session_id: overrides.session_id ?? "s1",
|
|
18
|
-
correlation_id: overrides.correlation_id ?? null,
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
const t = (offsetSec) => new Date(Date.parse("2026-05-12T10:00:00Z") + offsetSec * 1000).toISOString();
|
|
22
|
-
describe("detectFileReadLoops", () => {
|
|
23
|
-
it("flags ≥5 reads of the same file with no edit in between", () => {
|
|
24
|
-
const entries = [
|
|
25
|
-
entry({
|
|
26
|
-
tool: "file_read",
|
|
27
|
-
args_summary: { file_path: "auth.ts" },
|
|
28
|
-
ts: t(0),
|
|
29
|
-
}),
|
|
30
|
-
entry({
|
|
31
|
-
tool: "file_read",
|
|
32
|
-
args_summary: { file_path: "auth.ts" },
|
|
33
|
-
ts: t(10),
|
|
34
|
-
}),
|
|
35
|
-
entry({
|
|
36
|
-
tool: "file_read",
|
|
37
|
-
args_summary: { file_path: "auth.ts" },
|
|
38
|
-
ts: t(30),
|
|
39
|
-
}),
|
|
40
|
-
entry({
|
|
41
|
-
tool: "file_read",
|
|
42
|
-
args_summary: { file_path: "auth.ts" },
|
|
43
|
-
ts: t(60),
|
|
44
|
-
}),
|
|
45
|
-
entry({
|
|
46
|
-
tool: "file_read",
|
|
47
|
-
args_summary: { file_path: "auth.ts" },
|
|
48
|
-
ts: t(90),
|
|
49
|
-
}),
|
|
50
|
-
];
|
|
51
|
-
const loops = detectFileReadLoops(entries);
|
|
52
|
-
expect(loops).toHaveLength(1);
|
|
53
|
-
expect(loops[0]).toMatchObject({
|
|
54
|
-
kind: "file_reread",
|
|
55
|
-
file_path: "auth.ts",
|
|
56
|
-
count: 5,
|
|
57
|
-
session_id: "s1",
|
|
58
|
-
});
|
|
59
|
-
});
|
|
60
|
-
it("an edit between reads resets the run", () => {
|
|
61
|
-
const entries = [
|
|
62
|
-
entry({
|
|
63
|
-
tool: "file_read",
|
|
64
|
-
args_summary: { file_path: "a.ts" },
|
|
65
|
-
ts: t(0),
|
|
66
|
-
}),
|
|
67
|
-
entry({
|
|
68
|
-
tool: "file_read",
|
|
69
|
-
args_summary: { file_path: "a.ts" },
|
|
70
|
-
ts: t(10),
|
|
71
|
-
}),
|
|
72
|
-
entry({ tool: "Edit", args_summary: { file_path: "a.ts" }, ts: t(20) }),
|
|
73
|
-
entry({
|
|
74
|
-
tool: "file_read",
|
|
75
|
-
args_summary: { file_path: "a.ts" },
|
|
76
|
-
ts: t(30),
|
|
77
|
-
}),
|
|
78
|
-
entry({
|
|
79
|
-
tool: "file_read",
|
|
80
|
-
args_summary: { file_path: "a.ts" },
|
|
81
|
-
ts: t(40),
|
|
82
|
-
}),
|
|
83
|
-
];
|
|
84
|
-
expect(detectFileReadLoops(entries)).toEqual([]);
|
|
85
|
-
});
|
|
86
|
-
it("isolates loops per session", () => {
|
|
87
|
-
const entries = [];
|
|
88
|
-
for (let i = 0; i < 5; i++) {
|
|
89
|
-
entries.push(entry({
|
|
90
|
-
tool: "file_read",
|
|
91
|
-
args_summary: { file_path: "a.ts" },
|
|
92
|
-
ts: t(i * 10),
|
|
93
|
-
session_id: "s1",
|
|
94
|
-
}));
|
|
95
|
-
entries.push(entry({
|
|
96
|
-
tool: "file_read",
|
|
97
|
-
args_summary: { file_path: "a.ts" },
|
|
98
|
-
ts: t(i * 10 + 1),
|
|
99
|
-
session_id: "s2",
|
|
100
|
-
}));
|
|
101
|
-
}
|
|
102
|
-
const loops = detectFileReadLoops(entries);
|
|
103
|
-
const sessions = new Set(loops.map((l) => l.session_id));
|
|
104
|
-
expect(sessions).toEqual(new Set(["s1", "s2"]));
|
|
105
|
-
expect(loops).toHaveLength(2);
|
|
106
|
-
});
|
|
107
|
-
it("ignores entries outside the time window", () => {
|
|
108
|
-
const entries = [];
|
|
109
|
-
for (let i = 0; i < 5; i++) {
|
|
110
|
-
entries.push(entry({
|
|
111
|
-
tool: "file_read",
|
|
112
|
-
args_summary: { file_path: "a.ts" },
|
|
113
|
-
ts: t(i * 10),
|
|
114
|
-
}));
|
|
115
|
-
}
|
|
116
|
-
// Force "now" to be far in the future
|
|
117
|
-
const loops = detectFileReadLoops(entries, {
|
|
118
|
-
nowMs: Date.parse(t(0)) + 30 * 60_000, // 30 min after
|
|
119
|
-
readWindowMs: 60_000, // 1 min window
|
|
120
|
-
});
|
|
121
|
-
expect(loops).toEqual([]);
|
|
122
|
-
});
|
|
123
|
-
it("does not flag under the threshold", () => {
|
|
124
|
-
const entries = [
|
|
125
|
-
entry({
|
|
126
|
-
tool: "file_read",
|
|
127
|
-
args_summary: { file_path: "a.ts" },
|
|
128
|
-
ts: t(0),
|
|
129
|
-
}),
|
|
130
|
-
entry({
|
|
131
|
-
tool: "file_read",
|
|
132
|
-
args_summary: { file_path: "a.ts" },
|
|
133
|
-
ts: t(10),
|
|
134
|
-
}),
|
|
135
|
-
entry({
|
|
136
|
-
tool: "file_read",
|
|
137
|
-
args_summary: { file_path: "a.ts" },
|
|
138
|
-
ts: t(20),
|
|
139
|
-
}),
|
|
140
|
-
];
|
|
141
|
-
expect(detectFileReadLoops(entries)).toEqual([]);
|
|
142
|
-
});
|
|
143
|
-
});
|
|
144
|
-
describe("detectQueryLoops", () => {
|
|
145
|
-
it("flags ≥3 same search_code queries", () => {
|
|
146
|
-
const entries = [
|
|
147
|
-
entry({
|
|
148
|
-
tool: "search_code",
|
|
149
|
-
args_summary: { query: "validateToken" },
|
|
150
|
-
ts: t(0),
|
|
151
|
-
}),
|
|
152
|
-
entry({
|
|
153
|
-
tool: "search_code",
|
|
154
|
-
args_summary: { query: "validateToken" },
|
|
155
|
-
ts: t(120),
|
|
156
|
-
}),
|
|
157
|
-
entry({
|
|
158
|
-
tool: "search_code",
|
|
159
|
-
args_summary: { query: "validateToken" },
|
|
160
|
-
ts: t(300),
|
|
161
|
-
}),
|
|
162
|
-
];
|
|
163
|
-
const loops = detectQueryLoops(entries);
|
|
164
|
-
expect(loops).toHaveLength(1);
|
|
165
|
-
expect(loops[0]).toMatchObject({
|
|
166
|
-
kind: "search_repeat",
|
|
167
|
-
query: "validateToken",
|
|
168
|
-
count: 3,
|
|
169
|
-
});
|
|
170
|
-
});
|
|
171
|
-
it("different queries don't merge", () => {
|
|
172
|
-
const entries = [
|
|
173
|
-
entry({ tool: "search_code", args_summary: { query: "a" }, ts: t(0) }),
|
|
174
|
-
entry({ tool: "search_code", args_summary: { query: "b" }, ts: t(10) }),
|
|
175
|
-
entry({ tool: "search_code", args_summary: { query: "a" }, ts: t(20) }),
|
|
176
|
-
entry({ tool: "search_code", args_summary: { query: "b" }, ts: t(30) }),
|
|
177
|
-
];
|
|
178
|
-
expect(detectQueryLoops(entries)).toEqual([]);
|
|
179
|
-
});
|
|
180
|
-
it("non-search_code entries are ignored", () => {
|
|
181
|
-
const entries = [
|
|
182
|
-
entry({ tool: "file_read", args_summary: { query: "foo" }, ts: t(0) }),
|
|
183
|
-
entry({ tool: "file_read", args_summary: { query: "foo" }, ts: t(10) }),
|
|
184
|
-
entry({ tool: "file_read", args_summary: { query: "foo" }, ts: t(20) }),
|
|
185
|
-
];
|
|
186
|
-
expect(detectQueryLoops(entries)).toEqual([]);
|
|
187
|
-
});
|
|
188
|
-
});
|
|
189
|
-
describe("detectLoops (union)", () => {
|
|
190
|
-
it("returns both detections sorted by last_ts desc", () => {
|
|
191
|
-
const entries = [
|
|
192
|
-
entry({
|
|
193
|
-
tool: "file_read",
|
|
194
|
-
args_summary: { file_path: "a.ts" },
|
|
195
|
-
ts: t(0),
|
|
196
|
-
}),
|
|
197
|
-
entry({
|
|
198
|
-
tool: "file_read",
|
|
199
|
-
args_summary: { file_path: "a.ts" },
|
|
200
|
-
ts: t(10),
|
|
201
|
-
}),
|
|
202
|
-
entry({
|
|
203
|
-
tool: "file_read",
|
|
204
|
-
args_summary: { file_path: "a.ts" },
|
|
205
|
-
ts: t(20),
|
|
206
|
-
}),
|
|
207
|
-
entry({
|
|
208
|
-
tool: "file_read",
|
|
209
|
-
args_summary: { file_path: "a.ts" },
|
|
210
|
-
ts: t(30),
|
|
211
|
-
}),
|
|
212
|
-
entry({
|
|
213
|
-
tool: "file_read",
|
|
214
|
-
args_summary: { file_path: "a.ts" },
|
|
215
|
-
ts: t(40),
|
|
216
|
-
}),
|
|
217
|
-
entry({ tool: "search_code", args_summary: { query: "X" }, ts: t(100) }),
|
|
218
|
-
entry({ tool: "search_code", args_summary: { query: "X" }, ts: t(200) }),
|
|
219
|
-
entry({ tool: "search_code", args_summary: { query: "X" }, ts: t(300) }),
|
|
220
|
-
];
|
|
221
|
-
const loops = detectLoops(entries);
|
|
222
|
-
expect(loops).toHaveLength(2);
|
|
223
|
-
expect(loops[0]?.kind).toBe("search_repeat");
|
|
224
|
-
expect(loops[1]?.kind).toBe("file_reread");
|
|
225
|
-
});
|
|
226
|
-
});
|
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Tests for MCP local proxy config (Task 0.4).
|
|
3
|
-
*/
|
|
4
|
-
import { mkdirSync, readFileSync, 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
|
-
describe("MCP Local Proxy Configuration", () => {
|
|
9
|
-
let tempDir;
|
|
10
|
-
beforeEach(() => {
|
|
11
|
-
tempDir = join(tmpdir(), `unerr-test-mcp-${Date.now()}`);
|
|
12
|
-
mkdirSync(tempDir, { recursive: true });
|
|
13
|
-
});
|
|
14
|
-
afterEach(() => {
|
|
15
|
-
rmSync(tempDir, { recursive: true, force: true });
|
|
16
|
-
});
|
|
17
|
-
it("generates correct local proxy config for Cursor", () => {
|
|
18
|
-
const mcpConfig = {
|
|
19
|
-
mcpServers: {
|
|
20
|
-
unerr: {
|
|
21
|
-
command: "npx",
|
|
22
|
-
args: ["@unerr/unerr"],
|
|
23
|
-
env: {},
|
|
24
|
-
},
|
|
25
|
-
},
|
|
26
|
-
};
|
|
27
|
-
const configPath = join(tempDir, "mcp.json");
|
|
28
|
-
writeFileSync(configPath, JSON.stringify(mcpConfig, null, 2));
|
|
29
|
-
const parsed = JSON.parse(readFileSync(configPath, "utf-8"));
|
|
30
|
-
const unerr = parsed.mcpServers.unerr;
|
|
31
|
-
expect(unerr.command).toBe("npx");
|
|
32
|
-
expect(unerr.args).toEqual(["@unerr/unerr"]);
|
|
33
|
-
// Must NOT have a url property (local proxy, not remote)
|
|
34
|
-
expect(unerr.url).toBeUndefined();
|
|
35
|
-
});
|
|
36
|
-
it("detects remote URL config needing migration", () => {
|
|
37
|
-
const cloudConfig = {
|
|
38
|
-
mcpServers: {
|
|
39
|
-
unerr: {
|
|
40
|
-
url: "https://app.unerr.dev/mcp/org-123",
|
|
41
|
-
},
|
|
42
|
-
},
|
|
43
|
-
};
|
|
44
|
-
const unerr = cloudConfig.mcpServers.unerr;
|
|
45
|
-
// Remote config has url but no command — needs migration
|
|
46
|
-
const needsMigration = !!unerr.url && !("command" in unerr);
|
|
47
|
-
expect(needsMigration).toBe(true);
|
|
48
|
-
});
|
|
49
|
-
it("local proxy config does NOT need migration", () => {
|
|
50
|
-
const localConfig = {
|
|
51
|
-
mcpServers: {
|
|
52
|
-
unerr: {
|
|
53
|
-
command: "npx",
|
|
54
|
-
args: ["@unerr/unerr"],
|
|
55
|
-
},
|
|
56
|
-
},
|
|
57
|
-
};
|
|
58
|
-
const unerr = localConfig.mcpServers.unerr;
|
|
59
|
-
const needsMigration = !!("url" in unerr) && !("command" in unerr);
|
|
60
|
-
expect(needsMigration).toBe(false);
|
|
61
|
-
});
|
|
62
|
-
it("preserves existing MCP servers when adding unerr", () => {
|
|
63
|
-
const existing = {
|
|
64
|
-
mcpServers: {
|
|
65
|
-
"other-server": {
|
|
66
|
-
command: "node",
|
|
67
|
-
args: ["other-server.js"],
|
|
68
|
-
},
|
|
69
|
-
},
|
|
70
|
-
};
|
|
71
|
-
// Simulate upsert
|
|
72
|
-
const updated = {
|
|
73
|
-
...existing,
|
|
74
|
-
mcpServers: {
|
|
75
|
-
...existing.mcpServers,
|
|
76
|
-
unerr: {
|
|
77
|
-
command: "npx",
|
|
78
|
-
args: ["@unerr/unerr"],
|
|
79
|
-
env: {},
|
|
80
|
-
},
|
|
81
|
-
},
|
|
82
|
-
};
|
|
83
|
-
expect(updated.mcpServers["other-server"]).toBeDefined();
|
|
84
|
-
expect(updated.mcpServers.unerr).toBeDefined();
|
|
85
|
-
expect(Object.keys(updated.mcpServers)).toHaveLength(2);
|
|
86
|
-
});
|
|
87
|
-
it("config-verify repair writes local proxy config", async () => {
|
|
88
|
-
// Create a mock IDE config directory
|
|
89
|
-
const ideDir = join(tempDir, ".cursor");
|
|
90
|
-
mkdirSync(ideDir, { recursive: true });
|
|
91
|
-
// Write a remote config that needs migration
|
|
92
|
-
const configPath = join(ideDir, "mcp.json");
|
|
93
|
-
writeFileSync(configPath, JSON.stringify({
|
|
94
|
-
mcpServers: {
|
|
95
|
-
unerr: { url: "https://app.unerr.dev/mcp/org-123" },
|
|
96
|
-
},
|
|
97
|
-
}));
|
|
98
|
-
// Simulate repair by writing local proxy config
|
|
99
|
-
const config = JSON.parse(readFileSync(configPath, "utf-8"));
|
|
100
|
-
config.mcpServers.unerr = {
|
|
101
|
-
command: "npx",
|
|
102
|
-
args: ["@unerr/unerr"],
|
|
103
|
-
env: {},
|
|
104
|
-
};
|
|
105
|
-
writeFileSync(configPath, `${JSON.stringify(config, null, 2)}\n`);
|
|
106
|
-
// Verify repair result
|
|
107
|
-
const repaired = JSON.parse(readFileSync(configPath, "utf-8"));
|
|
108
|
-
expect(repaired.mcpServers.unerr?.command).toBe("npx");
|
|
109
|
-
expect(repaired.mcpServers.unerr?.url).toBeUndefined();
|
|
110
|
-
});
|
|
111
|
-
it("VS Code config uses mcpServers key in settings.json", () => {
|
|
112
|
-
const vscodeConfig = {
|
|
113
|
-
"editor.fontSize": 14,
|
|
114
|
-
mcpServers: {
|
|
115
|
-
unerr: {
|
|
116
|
-
command: "npx",
|
|
117
|
-
args: ["@unerr/unerr"],
|
|
118
|
-
env: {},
|
|
119
|
-
},
|
|
120
|
-
},
|
|
121
|
-
};
|
|
122
|
-
// VS Code settings.json has mixed keys — mcpServers lives alongside editor settings
|
|
123
|
-
expect(vscodeConfig.mcpServers.unerr.command).toBe("npx");
|
|
124
|
-
expect(vscodeConfig["editor.fontSize"]).toBe(14);
|
|
125
|
-
});
|
|
126
|
-
});
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "vitest";
|
|
2
|
-
import { stringifyMcpToolJson } from "../utils/mcp-content-json.js";
|
|
3
|
-
describe("stringifyMcpToolJson (Layer 6 Phase 1)", () => {
|
|
4
|
-
it("emits compact JSON without indentation whitespace", () => {
|
|
5
|
-
const obj = { a: 1, b: { c: "x\ny" } };
|
|
6
|
-
const compact = stringifyMcpToolJson(obj);
|
|
7
|
-
expect(compact).not.toContain("\n ");
|
|
8
|
-
expect(compact).toBe(JSON.stringify(obj));
|
|
9
|
-
});
|
|
10
|
-
});
|
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* C.6: MCP Integration Test — Full Envelope Cycle
|
|
3
|
-
*
|
|
4
|
-
* Uses the MCP harness from A.6 to set up a server with a tool that
|
|
5
|
-
* returns an envelope-wrapped response, then verifies the client
|
|
6
|
-
* receives _meta + _context fields.
|
|
7
|
-
*/
|
|
8
|
-
import { CallToolRequestSchema, ListToolsRequestSchema, } from "@modelcontextprotocol/sdk/types.js";
|
|
9
|
-
import { describe, expect, it } from "vitest";
|
|
10
|
-
import { createEnvelopePipeline, estimateTokens, } from "../proxy/response-envelope.js";
|
|
11
|
-
import { createSessionDedup } from "../proxy/session-dedup.js";
|
|
12
|
-
import { createTokenCounter } from "../proxy/token-counter.js";
|
|
13
|
-
import { createMcpHarness } from "./helpers/mcp-harness.js";
|
|
14
|
-
describe("MCP Envelope Integration", () => {
|
|
15
|
-
it("full pipeline: envelope + injector + dedup + token counter", async () => {
|
|
16
|
-
const messages = [];
|
|
17
|
-
const tokenCounter = createTokenCounter({
|
|
18
|
-
emitEveryN: 1,
|
|
19
|
-
sink: (msg) => messages.push(msg),
|
|
20
|
-
});
|
|
21
|
-
const dedup = createSessionDedup();
|
|
22
|
-
const testInjector = {
|
|
23
|
-
key: "test",
|
|
24
|
-
inject: ({ toolArgs }) => {
|
|
25
|
-
if (toolArgs.key) {
|
|
26
|
-
return { "dev.unerr/test_context": { entity: toolArgs.key } };
|
|
27
|
-
}
|
|
28
|
-
return null;
|
|
29
|
-
},
|
|
30
|
-
};
|
|
31
|
-
const pipeline = createEnvelopePipeline([testInjector]);
|
|
32
|
-
const harness = await createMcpHarness({
|
|
33
|
-
setupServer: (server) => {
|
|
34
|
-
server.setRequestHandler(ListToolsRequestSchema, async () => ({
|
|
35
|
-
tools: [
|
|
36
|
-
{
|
|
37
|
-
name: "test_tool",
|
|
38
|
-
description: "A test tool with envelope wrapping",
|
|
39
|
-
inputSchema: {
|
|
40
|
-
type: "object",
|
|
41
|
-
properties: { key: { type: "string" } },
|
|
42
|
-
required: ["key"],
|
|
43
|
-
},
|
|
44
|
-
},
|
|
45
|
-
],
|
|
46
|
-
}));
|
|
47
|
-
server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
48
|
-
const args = (request.params.arguments ?? {});
|
|
49
|
-
const start = performance.now();
|
|
50
|
-
const rawContent = { found: true, name: "testEntity", fan_in: 5 };
|
|
51
|
-
const latencyMs = performance.now() - start;
|
|
52
|
-
const originalTokens = estimateTokens(args);
|
|
53
|
-
const envelope = await pipeline.wrapResponse(rawContent, latencyMs, request.params.name, args, originalTokens);
|
|
54
|
-
const entityKey = String(args.key ?? "");
|
|
55
|
-
let context = envelope._context ?? {};
|
|
56
|
-
if (Object.keys(context).length > 0) {
|
|
57
|
-
context = dedup.filter(entityKey, context);
|
|
58
|
-
}
|
|
59
|
-
tokenCounter.record(envelope._meta["dev.unerr/tokens_saved"], estimateTokens(rawContent));
|
|
60
|
-
const responseText = JSON.stringify({
|
|
61
|
-
...rawContent,
|
|
62
|
-
_meta: envelope._meta,
|
|
63
|
-
...(Object.keys(context).length > 0 ? { _context: context } : {}),
|
|
64
|
-
}, null, 2);
|
|
65
|
-
return {
|
|
66
|
-
content: [{ type: "text", text: responseText }],
|
|
67
|
-
};
|
|
68
|
-
});
|
|
69
|
-
},
|
|
70
|
-
});
|
|
71
|
-
const result = await harness.callTool("test_tool", {
|
|
72
|
-
key: "src/auth.ts::login",
|
|
73
|
-
});
|
|
74
|
-
const content = result.content;
|
|
75
|
-
expect(content).toHaveLength(1);
|
|
76
|
-
const parsed = JSON.parse(content[0].text);
|
|
77
|
-
expect(parsed._meta).toBeDefined();
|
|
78
|
-
expect(parsed._meta["dev.unerr/version"]).toBe("0.1.0");
|
|
79
|
-
expect(typeof parsed._meta["dev.unerr/latency_ms"]).toBe("number");
|
|
80
|
-
expect(typeof parsed._meta["dev.unerr/tokens_saved"]).toBe("number");
|
|
81
|
-
expect(parsed._context).toBeDefined();
|
|
82
|
-
expect(parsed._context["dev.unerr/test_context"]).toBeDefined();
|
|
83
|
-
expect(parsed._context["dev.unerr/test_context"].entity).toBe("src/auth.ts::login");
|
|
84
|
-
expect(tokenCounter.getCallCount()).toBe(1);
|
|
85
|
-
expect(messages).toHaveLength(1);
|
|
86
|
-
const result2 = await harness.callTool("test_tool", {
|
|
87
|
-
key: "src/auth.ts::login",
|
|
88
|
-
});
|
|
89
|
-
const parsed2 = JSON.parse(result2.content[0].text);
|
|
90
|
-
expect(parsed2._context).toBeUndefined();
|
|
91
|
-
expect(dedup.hasDelivered("src/auth.ts::login", "dev.unerr/test_context")).toBe(true);
|
|
92
|
-
await harness.close();
|
|
93
|
-
});
|
|
94
|
-
it("envelope works without any injectors", async () => {
|
|
95
|
-
const pipeline = createEnvelopePipeline();
|
|
96
|
-
const harness = await createMcpHarness({
|
|
97
|
-
setupServer: (server) => {
|
|
98
|
-
server.setRequestHandler(ListToolsRequestSchema, async () => ({
|
|
99
|
-
tools: [
|
|
100
|
-
{
|
|
101
|
-
name: "simple_tool",
|
|
102
|
-
description: "No injectors",
|
|
103
|
-
inputSchema: { type: "object", properties: {} },
|
|
104
|
-
},
|
|
105
|
-
],
|
|
106
|
-
}));
|
|
107
|
-
server.setRequestHandler(CallToolRequestSchema, async () => {
|
|
108
|
-
const envelope = await pipeline.wrapResponse({ result: "ok" }, 0.5);
|
|
109
|
-
return {
|
|
110
|
-
content: [
|
|
111
|
-
{ type: "text", text: JSON.stringify(envelope) },
|
|
112
|
-
],
|
|
113
|
-
};
|
|
114
|
-
});
|
|
115
|
-
},
|
|
116
|
-
});
|
|
117
|
-
const result = await harness.callTool("simple_tool", {});
|
|
118
|
-
const content = result.content;
|
|
119
|
-
const parsed = JSON.parse(content[0].text);
|
|
120
|
-
expect(parsed._meta["dev.unerr/version"]).toBe("0.1.0");
|
|
121
|
-
expect(parsed._context).toBeUndefined();
|
|
122
|
-
await harness.close();
|
|
123
|
-
});
|
|
124
|
-
});
|