@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,185 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Sprint J.9: CFG context accuracy tests.
|
|
3
|
-
*
|
|
4
|
-
* Tests that call sites are correctly annotated with their
|
|
5
|
-
* control-flow context: try/catch, loops, conditionals.
|
|
6
|
-
*/
|
|
7
|
-
import { afterAll, beforeAll, describe, expect, it } from "vitest";
|
|
8
|
-
import { cfgToEdgeFields, extractCFGContext, } from "../intelligence/indexer/cfg-context.js";
|
|
9
|
-
import { detectMutations, mutationsToEdges, } from "../intelligence/indexer/mutation-tracker.js";
|
|
10
|
-
import { registerPlugin } from "../intelligence/indexer/plugin-interface.js";
|
|
11
|
-
import { typescriptPlugin } from "../intelligence/indexer/plugins/typescript.js";
|
|
12
|
-
import { clearParserCache, parseSource, } from "../intelligence/tree-sitter-loader.js";
|
|
13
|
-
beforeAll(() => {
|
|
14
|
-
registerPlugin(typescriptPlugin);
|
|
15
|
-
});
|
|
16
|
-
afterAll(() => {
|
|
17
|
-
clearParserCache();
|
|
18
|
-
});
|
|
19
|
-
async function findCallNodes(source) {
|
|
20
|
-
const tree = await parseSource(source, "tree-sitter-typescript.wasm");
|
|
21
|
-
const calls = [];
|
|
22
|
-
function visit(node) {
|
|
23
|
-
if (node.type === "call_expression") {
|
|
24
|
-
calls.push(node);
|
|
25
|
-
}
|
|
26
|
-
for (const child of node.namedChildren) {
|
|
27
|
-
visit(child);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
visit(tree.rootNode);
|
|
31
|
-
return calls;
|
|
32
|
-
}
|
|
33
|
-
async function findFunctionBody(source, fnName) {
|
|
34
|
-
const tree = await parseSource(source, "tree-sitter-typescript.wasm");
|
|
35
|
-
function visit(node) {
|
|
36
|
-
if (node.type === "function_declaration" ||
|
|
37
|
-
node.type === "method_definition") {
|
|
38
|
-
const name = node.childForFieldName("name");
|
|
39
|
-
if (name?.text === fnName) {
|
|
40
|
-
return node.childForFieldName("body") ?? null;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
for (const child of node.namedChildren) {
|
|
44
|
-
const found = visit(child);
|
|
45
|
-
if (found)
|
|
46
|
-
return found;
|
|
47
|
-
}
|
|
48
|
-
return null;
|
|
49
|
-
}
|
|
50
|
-
return visit(tree.rootNode);
|
|
51
|
-
}
|
|
52
|
-
describe("CFG Context (J.4)", () => {
|
|
53
|
-
it("detects try/catch guarded call", async () => {
|
|
54
|
-
const source = `
|
|
55
|
-
function safe() {
|
|
56
|
-
try {
|
|
57
|
-
dangerousCall();
|
|
58
|
-
} catch (e) {
|
|
59
|
-
handleError(e);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
`;
|
|
63
|
-
const calls = await findCallNodes(source);
|
|
64
|
-
const dangerousCall = calls.find((c) => c.text.includes("dangerousCall"));
|
|
65
|
-
expect(dangerousCall).toBeDefined();
|
|
66
|
-
const cfg = extractCFGContext(dangerousCall);
|
|
67
|
-
expect(cfg.isTryGuarded).toBe(true);
|
|
68
|
-
});
|
|
69
|
-
it("detects loop context", async () => {
|
|
70
|
-
const source = `
|
|
71
|
-
function loopy() {
|
|
72
|
-
for (const item of items) {
|
|
73
|
-
process(item);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
`;
|
|
77
|
-
const calls = await findCallNodes(source);
|
|
78
|
-
const processCall = calls.find((c) => c.text.includes("process"));
|
|
79
|
-
expect(processCall).toBeDefined();
|
|
80
|
-
const cfg = extractCFGContext(processCall);
|
|
81
|
-
expect(cfg.isLoop).toBe(true);
|
|
82
|
-
});
|
|
83
|
-
it("detects conditional context", async () => {
|
|
84
|
-
const source = `
|
|
85
|
-
function conditional(x: boolean) {
|
|
86
|
-
if (x) {
|
|
87
|
-
doSomething();
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
`;
|
|
91
|
-
const calls = await findCallNodes(source);
|
|
92
|
-
const doCall = calls.find((c) => c.text.includes("doSomething"));
|
|
93
|
-
expect(doCall).toBeDefined();
|
|
94
|
-
const cfg = extractCFGContext(doCall);
|
|
95
|
-
expect(cfg.isConditional).toBe(true);
|
|
96
|
-
});
|
|
97
|
-
it("detects error handler context", async () => {
|
|
98
|
-
const source = `
|
|
99
|
-
function handler() {
|
|
100
|
-
try {
|
|
101
|
-
riskyOp();
|
|
102
|
-
} catch (e) {
|
|
103
|
-
logError(e);
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
`;
|
|
107
|
-
const calls = await findCallNodes(source);
|
|
108
|
-
const logCall = calls.find((c) => c.text.includes("logError"));
|
|
109
|
-
expect(logCall).toBeDefined();
|
|
110
|
-
const cfg = extractCFGContext(logCall);
|
|
111
|
-
expect(cfg.isErrorHandler).toBe(true);
|
|
112
|
-
});
|
|
113
|
-
it("detects nested control flow depth", async () => {
|
|
114
|
-
const source = `
|
|
115
|
-
function deep() {
|
|
116
|
-
for (let i = 0; i < 10; i++) {
|
|
117
|
-
if (i > 5) {
|
|
118
|
-
process(i);
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
`;
|
|
123
|
-
const calls = await findCallNodes(source);
|
|
124
|
-
const processCall = calls.find((c) => c.text.includes("process"));
|
|
125
|
-
expect(processCall).toBeDefined();
|
|
126
|
-
const cfg = extractCFGContext(processCall);
|
|
127
|
-
expect(cfg.isLoop).toBe(true);
|
|
128
|
-
expect(cfg.isConditional).toBe(true);
|
|
129
|
-
expect(cfg.nestingDepth).toBeGreaterThanOrEqual(2);
|
|
130
|
-
});
|
|
131
|
-
it("converts CFG to edge fields", () => {
|
|
132
|
-
const cfg = {
|
|
133
|
-
isTryGuarded: true,
|
|
134
|
-
isLoop: true,
|
|
135
|
-
isConditional: false,
|
|
136
|
-
isErrorHandler: false,
|
|
137
|
-
isAsync: true,
|
|
138
|
-
nestingDepth: 2,
|
|
139
|
-
};
|
|
140
|
-
const fields = cfgToEdgeFields(cfg);
|
|
141
|
-
expect(fields.is_try_guarded).toBe(true);
|
|
142
|
-
expect(fields.is_loop).toBe(true);
|
|
143
|
-
expect(fields.is_async).toBe(true);
|
|
144
|
-
expect(fields.nesting_depth).toBe(2);
|
|
145
|
-
expect(fields.is_conditional).toBeUndefined();
|
|
146
|
-
});
|
|
147
|
-
});
|
|
148
|
-
describe("State Mutation Detection (J.5)", () => {
|
|
149
|
-
it("detects this.property mutations", async () => {
|
|
150
|
-
const body = await findFunctionBody(`class Counter {
|
|
151
|
-
count = 0;
|
|
152
|
-
increment() {
|
|
153
|
-
this.count = this.count + 1;
|
|
154
|
-
}
|
|
155
|
-
}`, "increment");
|
|
156
|
-
expect(body).not.toBeNull();
|
|
157
|
-
const mutations = detectMutations(body);
|
|
158
|
-
expect(mutations.length).toBeGreaterThanOrEqual(1);
|
|
159
|
-
expect(mutations[0]?.isThisMutation).toBe(true);
|
|
160
|
-
expect(mutations[0]?.propertyName).toBe("count");
|
|
161
|
-
});
|
|
162
|
-
it("detects object property mutations", async () => {
|
|
163
|
-
const body = await findFunctionBody(`function update(config: any) {
|
|
164
|
-
config.value = 42;
|
|
165
|
-
}`, "update");
|
|
166
|
-
expect(body).not.toBeNull();
|
|
167
|
-
const mutations = detectMutations(body);
|
|
168
|
-
expect(mutations.length).toBeGreaterThanOrEqual(1);
|
|
169
|
-
expect(mutations[0]?.isThisMutation).toBe(false);
|
|
170
|
-
});
|
|
171
|
-
it("converts mutations to writes edges", () => {
|
|
172
|
-
const mutations = [
|
|
173
|
-
{
|
|
174
|
-
target: "this.count",
|
|
175
|
-
isThisMutation: true,
|
|
176
|
-
line: 5,
|
|
177
|
-
propertyName: "count",
|
|
178
|
-
},
|
|
179
|
-
];
|
|
180
|
-
const edges = mutationsToEdges(mutations, "method-key", "counter.ts");
|
|
181
|
-
expect(edges).toHaveLength(1);
|
|
182
|
-
expect(edges[0]?.type).toBe("writes");
|
|
183
|
-
expect(edges[0]?.from_key).toBe("method-key");
|
|
184
|
-
});
|
|
185
|
-
});
|
|
@@ -1,172 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Sprint J.8: Cross-file resolution tests.
|
|
3
|
-
*
|
|
4
|
-
* Tests multi-file scenarios: imports, cross-file calls, barrel files,
|
|
5
|
-
* fan-in/fan-out computation, hub node detection.
|
|
6
|
-
*/
|
|
7
|
-
import { afterAll, beforeAll, describe, expect, it } from "vitest";
|
|
8
|
-
import { applyCentrality, computeCentrality, riskLevel, } from "../intelligence/indexer/centrality.js";
|
|
9
|
-
import { resolveCrossFileEdges } from "../intelligence/indexer/cross-file-resolver.js";
|
|
10
|
-
import { buildExportMap } from "../intelligence/indexer/export-map.js";
|
|
11
|
-
import { registerPlugin } from "../intelligence/indexer/plugin-interface.js";
|
|
12
|
-
import { typescriptPlugin } from "../intelligence/indexer/plugins/typescript.js";
|
|
13
|
-
import { clearParserCache, parseSource, } from "../intelligence/tree-sitter-loader.js";
|
|
14
|
-
beforeAll(() => {
|
|
15
|
-
registerPlugin(typescriptPlugin);
|
|
16
|
-
});
|
|
17
|
-
afterAll(() => {
|
|
18
|
-
clearParserCache();
|
|
19
|
-
});
|
|
20
|
-
const FILE_A = `
|
|
21
|
-
import { fetchUser } from "./user-service";
|
|
22
|
-
import { Logger } from "./logger";
|
|
23
|
-
|
|
24
|
-
export function processOrder(orderId: string) {
|
|
25
|
-
const user = fetchUser(orderId);
|
|
26
|
-
Logger.info("Processing order", orderId);
|
|
27
|
-
return { orderId, user };
|
|
28
|
-
}
|
|
29
|
-
`;
|
|
30
|
-
const FILE_B = `
|
|
31
|
-
export async function fetchUser(id: string): Promise<User> {
|
|
32
|
-
return { id, name: "Test" };
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export interface User {
|
|
36
|
-
id: string;
|
|
37
|
-
name: string;
|
|
38
|
-
}
|
|
39
|
-
`;
|
|
40
|
-
const FILE_BARREL = `
|
|
41
|
-
export { fetchUser } from "./user-service";
|
|
42
|
-
export { processOrder } from "./order-handler";
|
|
43
|
-
`;
|
|
44
|
-
async function extractFile(source, filePath) {
|
|
45
|
-
const tree = await parseSource(source, "tree-sitter-typescript.wasm");
|
|
46
|
-
const extraction = typescriptPlugin.extract(tree, filePath, source);
|
|
47
|
-
const imports = typescriptPlugin.resolveImports(tree, filePath);
|
|
48
|
-
tree.delete();
|
|
49
|
-
return { ...extraction, imports };
|
|
50
|
-
}
|
|
51
|
-
describe("Export Map (J.1)", () => {
|
|
52
|
-
it("builds export map from file results", async () => {
|
|
53
|
-
const fileB = await extractFile(FILE_B, "src/user-service.ts");
|
|
54
|
-
const fileResults = new Map();
|
|
55
|
-
fileResults.set("src/user-service.ts", fileB);
|
|
56
|
-
const exportMap = buildExportMap(fileResults);
|
|
57
|
-
const exports = exportMap.getAllExports("src/user-service.ts");
|
|
58
|
-
expect(exports.length).toBeGreaterThan(0);
|
|
59
|
-
const fetchExport = exports.find((e) => e.name === "fetchUser");
|
|
60
|
-
expect(fetchExport).toBeDefined();
|
|
61
|
-
expect(fetchExport?.kind).toBe("function");
|
|
62
|
-
});
|
|
63
|
-
});
|
|
64
|
-
describe("Cross-File Resolution (J.2)", () => {
|
|
65
|
-
it("resolves imports to entity keys", async () => {
|
|
66
|
-
const fileA = await extractFile(FILE_A, "src/order-handler.ts");
|
|
67
|
-
const fileB = await extractFile(FILE_B, "src/user-service.ts");
|
|
68
|
-
const fileResults = new Map();
|
|
69
|
-
fileResults.set("src/order-handler.ts", fileA);
|
|
70
|
-
fileResults.set("src/user-service.ts", fileB);
|
|
71
|
-
const result = resolveCrossFileEdges(fileResults);
|
|
72
|
-
expect(result.resolvedCount).toBeGreaterThan(0);
|
|
73
|
-
const resolvedCallEdges = result.resolvedEdges.filter((e) => e.type === "calls" && !e.to_key.startsWith("unresolved:"));
|
|
74
|
-
expect(resolvedCallEdges.length).toBeGreaterThan(0);
|
|
75
|
-
});
|
|
76
|
-
it("local calls resolve without imports", async () => {
|
|
77
|
-
const source = `
|
|
78
|
-
function helper() { return 42; }
|
|
79
|
-
export function main() { return helper(); }
|
|
80
|
-
`;
|
|
81
|
-
const file = await extractFile(source, "src/local.ts");
|
|
82
|
-
const fileResults = new Map();
|
|
83
|
-
fileResults.set("src/local.ts", file);
|
|
84
|
-
const result = resolveCrossFileEdges(fileResults);
|
|
85
|
-
const localCalls = result.resolvedEdges.filter((e) => e.type === "calls" && !e.to_key.startsWith("unresolved:"));
|
|
86
|
-
expect(localCalls.length).toBeGreaterThan(0);
|
|
87
|
-
});
|
|
88
|
-
});
|
|
89
|
-
describe("Barrel File Resolution (J.3)", () => {
|
|
90
|
-
it("resolves re-exports through barrel files", async () => {
|
|
91
|
-
const fileB = await extractFile(FILE_B, "src/user-service.ts");
|
|
92
|
-
const fileBarrel = await extractFile(FILE_BARREL, "src/index.ts");
|
|
93
|
-
const fileResults = new Map();
|
|
94
|
-
fileResults.set("src/user-service.ts", fileB);
|
|
95
|
-
fileResults.set("src/index.ts", fileBarrel);
|
|
96
|
-
const exportMap = buildExportMap(fileResults);
|
|
97
|
-
const barrelExports = exportMap.getAllExports("src/index.ts");
|
|
98
|
-
expect(barrelExports.length).toBeGreaterThanOrEqual(0);
|
|
99
|
-
});
|
|
100
|
-
});
|
|
101
|
-
describe("Centrality (J.6 + J.7)", () => {
|
|
102
|
-
it("computes fan-in and fan-out", () => {
|
|
103
|
-
const edges = [
|
|
104
|
-
{
|
|
105
|
-
from_key: "a",
|
|
106
|
-
to_key: "target",
|
|
107
|
-
type: "calls",
|
|
108
|
-
file_path: "f.ts",
|
|
109
|
-
line: 1,
|
|
110
|
-
},
|
|
111
|
-
{
|
|
112
|
-
from_key: "b",
|
|
113
|
-
to_key: "target",
|
|
114
|
-
type: "calls",
|
|
115
|
-
file_path: "f.ts",
|
|
116
|
-
line: 2,
|
|
117
|
-
},
|
|
118
|
-
{
|
|
119
|
-
from_key: "c",
|
|
120
|
-
to_key: "target",
|
|
121
|
-
type: "calls",
|
|
122
|
-
file_path: "f.ts",
|
|
123
|
-
line: 3,
|
|
124
|
-
},
|
|
125
|
-
{
|
|
126
|
-
from_key: "target",
|
|
127
|
-
to_key: "d",
|
|
128
|
-
type: "calls",
|
|
129
|
-
file_path: "f.ts",
|
|
130
|
-
line: 4,
|
|
131
|
-
},
|
|
132
|
-
];
|
|
133
|
-
const result = computeCentrality(edges);
|
|
134
|
-
expect(result.fanIn.get("target")).toBe(3);
|
|
135
|
-
expect(result.fanOut.get("target")).toBe(1);
|
|
136
|
-
});
|
|
137
|
-
it("detects hub nodes at threshold", () => {
|
|
138
|
-
const edges = Array.from({ length: 25 }, (_, i) => ({
|
|
139
|
-
from_key: `caller-${i}`,
|
|
140
|
-
to_key: "hub-entity",
|
|
141
|
-
type: "calls",
|
|
142
|
-
file_path: "f.ts",
|
|
143
|
-
line: i + 1,
|
|
144
|
-
}));
|
|
145
|
-
const result = computeCentrality(edges);
|
|
146
|
-
expect(result.hubNodes).toContain("hub-entity");
|
|
147
|
-
});
|
|
148
|
-
it("assigns correct risk levels", () => {
|
|
149
|
-
expect(riskLevel(0)).toBe("normal");
|
|
150
|
-
expect(riskLevel(5)).toBe("normal");
|
|
151
|
-
expect(riskLevel(10)).toBe("medium");
|
|
152
|
-
expect(riskLevel(20)).toBe("high");
|
|
153
|
-
expect(riskLevel(50)).toBe("critical");
|
|
154
|
-
expect(riskLevel(100)).toBe("critical");
|
|
155
|
-
});
|
|
156
|
-
it("applies centrality to entities", () => {
|
|
157
|
-
const entities = [
|
|
158
|
-
{ key: "target", kind: "function", name: "fn", file_path: "f.ts" },
|
|
159
|
-
];
|
|
160
|
-
const edges = Array.from({ length: 15 }, (_, i) => ({
|
|
161
|
-
from_key: `caller-${i}`,
|
|
162
|
-
to_key: "target",
|
|
163
|
-
type: "calls",
|
|
164
|
-
file_path: "f.ts",
|
|
165
|
-
line: i + 1,
|
|
166
|
-
}));
|
|
167
|
-
const updated = applyCentrality(entities, edges);
|
|
168
|
-
const entity = updated[0];
|
|
169
|
-
expect(entity.fan_in).toBe(15);
|
|
170
|
-
expect(entity.risk_level).toBe("medium");
|
|
171
|
-
});
|
|
172
|
-
});
|
|
@@ -1,245 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Sprint I.10: Indexer extraction accuracy tests.
|
|
3
|
-
*
|
|
4
|
-
* Tests tree-sitter-based entity/edge extraction against known fixtures.
|
|
5
|
-
* Verifies: entity counts, kinds, deterministic keys, edges, imports.
|
|
6
|
-
*/
|
|
7
|
-
import { afterAll, beforeAll, describe, expect, it } from "vitest";
|
|
8
|
-
import { bodyHash, entityKey } from "../intelligence/indexer/entity-key.js";
|
|
9
|
-
import { getPluginForFile, registerPlugin, } from "../intelligence/indexer/plugin-interface.js";
|
|
10
|
-
import { typescriptPlugin } from "../intelligence/indexer/plugins/typescript.js";
|
|
11
|
-
import { clearParserCache, parseSource, } from "../intelligence/tree-sitter-loader.js";
|
|
12
|
-
beforeAll(() => {
|
|
13
|
-
registerPlugin(typescriptPlugin);
|
|
14
|
-
});
|
|
15
|
-
afterAll(() => {
|
|
16
|
-
clearParserCache();
|
|
17
|
-
});
|
|
18
|
-
const FIXTURE_TS = `
|
|
19
|
-
import { readFileSync } from "node:fs";
|
|
20
|
-
import { join } from "node:path";
|
|
21
|
-
import type { Config } from "./types";
|
|
22
|
-
|
|
23
|
-
export const VERSION = "1.0.0";
|
|
24
|
-
|
|
25
|
-
export interface UserOptions {
|
|
26
|
-
name: string;
|
|
27
|
-
age?: number;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export type UserId = string | number;
|
|
31
|
-
|
|
32
|
-
export enum Status {
|
|
33
|
-
Active = "active",
|
|
34
|
-
Inactive = "inactive",
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export function greet(name: string): string {
|
|
38
|
-
return \`Hello, \${name}\`;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export async function fetchUser(id: UserId): Promise<UserOptions> {
|
|
42
|
-
const data = readFileSync(join("data", String(id)), "utf-8");
|
|
43
|
-
return JSON.parse(data);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export class UserService {
|
|
47
|
-
private users: Map<string, UserOptions> = new Map();
|
|
48
|
-
|
|
49
|
-
constructor(private config: Config) {}
|
|
50
|
-
|
|
51
|
-
async getUser(id: string): Promise<UserOptions | null> {
|
|
52
|
-
const cached = this.users.get(id);
|
|
53
|
-
if (cached) return cached;
|
|
54
|
-
const user = await fetchUser(id);
|
|
55
|
-
this.users.set(id, user);
|
|
56
|
-
return user;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
deleteUser(id: string): boolean {
|
|
60
|
-
return this.users.delete(id);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
get count(): number {
|
|
64
|
-
return this.users.size;
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
const processOrder = async (orderId: string) => {
|
|
69
|
-
const user = await fetchUser(orderId);
|
|
70
|
-
return greet(user.name);
|
|
71
|
-
};
|
|
72
|
-
`;
|
|
73
|
-
describe("Entity Key Generation (I.6)", () => {
|
|
74
|
-
it("generates deterministic keys", () => {
|
|
75
|
-
const key1 = entityKey("src/auth.ts", "function", "login", "");
|
|
76
|
-
const key2 = entityKey("src/auth.ts", "function", "login", "");
|
|
77
|
-
expect(key1).toBe(key2);
|
|
78
|
-
expect(key1.length).toBe(16);
|
|
79
|
-
});
|
|
80
|
-
it("generates different keys for different entities", () => {
|
|
81
|
-
const key1 = entityKey("src/auth.ts", "function", "login", "");
|
|
82
|
-
const key2 = entityKey("src/auth.ts", "function", "logout", "");
|
|
83
|
-
expect(key1).not.toBe(key2);
|
|
84
|
-
});
|
|
85
|
-
it("includes scope in key for nested entities", () => {
|
|
86
|
-
const topLevel = entityKey("src/auth.ts", "function", "helper", "");
|
|
87
|
-
const nested = entityKey("src/auth.ts", "function", "helper", "parent-scope");
|
|
88
|
-
expect(topLevel).not.toBe(nested);
|
|
89
|
-
});
|
|
90
|
-
it("generates body hashes", () => {
|
|
91
|
-
const h1 = bodyHash("function foo() { return 42; }");
|
|
92
|
-
const h2 = bodyHash("function foo() { return 42; }");
|
|
93
|
-
const h3 = bodyHash("function foo() { return 43; }");
|
|
94
|
-
expect(h1).toBe(h2);
|
|
95
|
-
expect(h1).not.toBe(h3);
|
|
96
|
-
});
|
|
97
|
-
});
|
|
98
|
-
describe("Plugin Registry (I.2)", () => {
|
|
99
|
-
it("resolves TypeScript plugin for .ts files", () => {
|
|
100
|
-
expect(getPluginForFile("src/auth.ts")).toBe(typescriptPlugin);
|
|
101
|
-
});
|
|
102
|
-
it("resolves TypeScript plugin for .tsx files", () => {
|
|
103
|
-
expect(getPluginForFile("src/App.tsx")).toBe(typescriptPlugin);
|
|
104
|
-
});
|
|
105
|
-
it("resolves TypeScript plugin for .js files", () => {
|
|
106
|
-
expect(getPluginForFile("src/utils.js")).toBe(typescriptPlugin);
|
|
107
|
-
});
|
|
108
|
-
it("returns null for unsupported extensions", () => {
|
|
109
|
-
expect(getPluginForFile("README.md")).toBeNull();
|
|
110
|
-
expect(getPluginForFile("data.json")).toBeNull();
|
|
111
|
-
});
|
|
112
|
-
});
|
|
113
|
-
describe("TypeScript Entity Extraction (I.3)", () => {
|
|
114
|
-
let tree;
|
|
115
|
-
beforeAll(async () => {
|
|
116
|
-
tree = await parseSource(FIXTURE_TS, "tree-sitter-typescript.wasm");
|
|
117
|
-
});
|
|
118
|
-
afterAll(() => {
|
|
119
|
-
tree.delete();
|
|
120
|
-
});
|
|
121
|
-
it("extracts all entity kinds", () => {
|
|
122
|
-
const result = typescriptPlugin.extract(tree, "fixture.ts", FIXTURE_TS);
|
|
123
|
-
const kinds = new Set(result.entities.map((e) => e.kind));
|
|
124
|
-
expect(kinds).toContain("function");
|
|
125
|
-
expect(kinds).toContain("class");
|
|
126
|
-
expect(kinds).toContain("interface");
|
|
127
|
-
expect(kinds).toContain("type");
|
|
128
|
-
expect(kinds).toContain("enum");
|
|
129
|
-
expect(kinds).toContain("variable");
|
|
130
|
-
});
|
|
131
|
-
it("extracts named functions", () => {
|
|
132
|
-
const result = typescriptPlugin.extract(tree, "fixture.ts", FIXTURE_TS);
|
|
133
|
-
const greet = result.entities.find((e) => e.name === "greet");
|
|
134
|
-
expect(greet).toBeDefined();
|
|
135
|
-
expect(greet?.kind).toBe("function");
|
|
136
|
-
expect(greet?.exported).toBe(true);
|
|
137
|
-
expect(greet?.is_async).toBe(false);
|
|
138
|
-
});
|
|
139
|
-
it("extracts async functions", () => {
|
|
140
|
-
const result = typescriptPlugin.extract(tree, "fixture.ts", FIXTURE_TS);
|
|
141
|
-
const fetchUser = result.entities.find((e) => e.name === "fetchUser");
|
|
142
|
-
expect(fetchUser).toBeDefined();
|
|
143
|
-
expect(fetchUser?.is_async).toBe(true);
|
|
144
|
-
});
|
|
145
|
-
it("extracts classes", () => {
|
|
146
|
-
const result = typescriptPlugin.extract(tree, "fixture.ts", FIXTURE_TS);
|
|
147
|
-
const cls = result.entities.find((e) => e.name === "UserService");
|
|
148
|
-
expect(cls).toBeDefined();
|
|
149
|
-
expect(cls?.kind).toBe("class");
|
|
150
|
-
});
|
|
151
|
-
it("extracts methods within classes", () => {
|
|
152
|
-
const result = typescriptPlugin.extract(tree, "fixture.ts", FIXTURE_TS);
|
|
153
|
-
const methods = result.entities.filter((e) => e.kind === "method" || e.kind === "constructor" || e.kind === "getter");
|
|
154
|
-
expect(methods.length).toBeGreaterThanOrEqual(2);
|
|
155
|
-
const getUser = methods.find((e) => e.name === "getUser");
|
|
156
|
-
expect(getUser).toBeDefined();
|
|
157
|
-
});
|
|
158
|
-
it("extracts arrow functions assigned to variables", () => {
|
|
159
|
-
const result = typescriptPlugin.extract(tree, "fixture.ts", FIXTURE_TS);
|
|
160
|
-
const processOrder = result.entities.find((e) => e.name === "processOrder");
|
|
161
|
-
expect(processOrder).toBeDefined();
|
|
162
|
-
expect(processOrder?.kind).toBe("function");
|
|
163
|
-
expect(processOrder?.is_async).toBe(true);
|
|
164
|
-
});
|
|
165
|
-
it("extracts interfaces", () => {
|
|
166
|
-
const result = typescriptPlugin.extract(tree, "fixture.ts", FIXTURE_TS);
|
|
167
|
-
const iface = result.entities.find((e) => e.name === "UserOptions");
|
|
168
|
-
expect(iface).toBeDefined();
|
|
169
|
-
expect(iface?.kind).toBe("interface");
|
|
170
|
-
});
|
|
171
|
-
it("extracts type aliases", () => {
|
|
172
|
-
const result = typescriptPlugin.extract(tree, "fixture.ts", FIXTURE_TS);
|
|
173
|
-
const typeAlias = result.entities.find((e) => e.name === "UserId");
|
|
174
|
-
expect(typeAlias).toBeDefined();
|
|
175
|
-
expect(typeAlias?.kind).toBe("type");
|
|
176
|
-
});
|
|
177
|
-
it("extracts enums", () => {
|
|
178
|
-
const result = typescriptPlugin.extract(tree, "fixture.ts", FIXTURE_TS);
|
|
179
|
-
const enumEntity = result.entities.find((e) => e.name === "Status");
|
|
180
|
-
expect(enumEntity).toBeDefined();
|
|
181
|
-
expect(enumEntity?.kind).toBe("enum");
|
|
182
|
-
});
|
|
183
|
-
it("produces deterministic keys across re-runs", () => {
|
|
184
|
-
const r1 = typescriptPlugin.extract(tree, "fixture.ts", FIXTURE_TS);
|
|
185
|
-
const r2 = typescriptPlugin.extract(tree, "fixture.ts", FIXTURE_TS);
|
|
186
|
-
const keys1 = r1.entities.map((e) => e.key).sort();
|
|
187
|
-
const keys2 = r2.entities.map((e) => e.key).sort();
|
|
188
|
-
expect(keys1).toEqual(keys2);
|
|
189
|
-
});
|
|
190
|
-
});
|
|
191
|
-
describe("TypeScript Edge Extraction (I.4)", () => {
|
|
192
|
-
let tree;
|
|
193
|
-
beforeAll(async () => {
|
|
194
|
-
tree = await parseSource(FIXTURE_TS, "tree-sitter-typescript.wasm");
|
|
195
|
-
});
|
|
196
|
-
afterAll(() => {
|
|
197
|
-
tree.delete();
|
|
198
|
-
});
|
|
199
|
-
it("creates contains edges from class to methods", () => {
|
|
200
|
-
const result = typescriptPlugin.extract(tree, "fixture.ts", FIXTURE_TS);
|
|
201
|
-
const classEntity = result.entities.find((e) => e.name === "UserService");
|
|
202
|
-
const containsEdges = result.edges.filter((e) => e.type === "contains" && e.from_key === classEntity?.key);
|
|
203
|
-
expect(containsEdges.length).toBeGreaterThanOrEqual(2);
|
|
204
|
-
});
|
|
205
|
-
it("creates calls edges for function calls", () => {
|
|
206
|
-
const result = typescriptPlugin.extract(tree, "fixture.ts", FIXTURE_TS);
|
|
207
|
-
const callEdges = result.edges.filter((e) => e.type === "calls");
|
|
208
|
-
expect(callEdges.length).toBeGreaterThan(0);
|
|
209
|
-
});
|
|
210
|
-
it("all edges have valid file_path and line", () => {
|
|
211
|
-
const result = typescriptPlugin.extract(tree, "fixture.ts", FIXTURE_TS);
|
|
212
|
-
for (const edge of result.edges) {
|
|
213
|
-
expect(edge.file_path).toBe("fixture.ts");
|
|
214
|
-
expect(edge.line).toBeGreaterThan(0);
|
|
215
|
-
}
|
|
216
|
-
});
|
|
217
|
-
});
|
|
218
|
-
describe("TypeScript Import Resolution (I.5)", () => {
|
|
219
|
-
let tree;
|
|
220
|
-
beforeAll(async () => {
|
|
221
|
-
tree = await parseSource(FIXTURE_TS, "tree-sitter-typescript.wasm");
|
|
222
|
-
});
|
|
223
|
-
afterAll(() => {
|
|
224
|
-
tree.delete();
|
|
225
|
-
});
|
|
226
|
-
it("extracts named imports", () => {
|
|
227
|
-
const imports = typescriptPlugin.resolveImports(tree, "fixture.ts");
|
|
228
|
-
const fsImport = imports.find((i) => i.source === "node:fs");
|
|
229
|
-
expect(fsImport).toBeDefined();
|
|
230
|
-
expect(fsImport?.symbols).toContain("readFileSync");
|
|
231
|
-
});
|
|
232
|
-
it("extracts type imports", () => {
|
|
233
|
-
const imports = typescriptPlugin.resolveImports(tree, "fixture.ts");
|
|
234
|
-
const typeImport = imports.find((i) => i.source === "./types");
|
|
235
|
-
expect(typeImport).toBeDefined();
|
|
236
|
-
});
|
|
237
|
-
it("resolves import paths", () => {
|
|
238
|
-
const imports = typescriptPlugin.resolveImports(tree, "fixture.ts");
|
|
239
|
-
expect(imports.length).toBeGreaterThanOrEqual(3);
|
|
240
|
-
for (const imp of imports) {
|
|
241
|
-
expect(imp.source).toBeTruthy();
|
|
242
|
-
expect(imp.line).toBeGreaterThan(0);
|
|
243
|
-
}
|
|
244
|
-
});
|
|
245
|
-
});
|