@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,540 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Phase 10b TEST-01: CozoDB rules/patterns integration tests.
|
|
3
|
-
*/
|
|
4
|
-
import { beforeEach, describe, expect, it, vi, } from "vitest";
|
|
5
|
-
import { CozoGraphStore } from "../intelligence/local-graph.js";
|
|
6
|
-
function createInMemoryDb() {
|
|
7
|
-
// Minimal CozoDB mock using in-memory maps
|
|
8
|
-
const relations = new Map();
|
|
9
|
-
return {
|
|
10
|
-
async run(query, params) {
|
|
11
|
-
// Handle :create statements
|
|
12
|
-
if (query.includes(":create ")) {
|
|
13
|
-
const match = query.match(/:create\s+(\w+)/);
|
|
14
|
-
if (match) {
|
|
15
|
-
relations.set(match[1], new Map());
|
|
16
|
-
}
|
|
17
|
-
return Promise.resolve({ rows: [] });
|
|
18
|
-
}
|
|
19
|
-
// Handle :put statements
|
|
20
|
-
if (query.includes(":put ")) {
|
|
21
|
-
const match = query.match(/:put\s+(\w+)/);
|
|
22
|
-
if (match) {
|
|
23
|
-
const relation = relations.get(match[1]);
|
|
24
|
-
if (relation && params) {
|
|
25
|
-
const key = params.key ??
|
|
26
|
-
params.token ??
|
|
27
|
-
params.fp ??
|
|
28
|
-
`${params.from}-${params.to}-${params.type}`;
|
|
29
|
-
relation.set(key, Object.values(params));
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
return Promise.resolve({ rows: [] });
|
|
33
|
-
}
|
|
34
|
-
// Handle queries for rules
|
|
35
|
-
if (query.includes("*rules[") && query.includes("enabled = true")) {
|
|
36
|
-
const rulesRelation = relations.get("rules");
|
|
37
|
-
if (!rulesRelation)
|
|
38
|
-
return Promise.resolve({ rows: [] });
|
|
39
|
-
return Promise.resolve({
|
|
40
|
-
rows: Array.from(rulesRelation.values()).filter((row) => {
|
|
41
|
-
// Check enabled field (index 8)
|
|
42
|
-
return row[8] === true;
|
|
43
|
-
}),
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
if (query.includes("*rules[") && query.includes(":limit 1")) {
|
|
47
|
-
const rulesRelation = relations.get("rules");
|
|
48
|
-
if (!rulesRelation || rulesRelation.size === 0)
|
|
49
|
-
return Promise.resolve({ rows: [] });
|
|
50
|
-
return Promise.resolve({
|
|
51
|
-
rows: [Array.from(rulesRelation.values())[0]],
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
// Handle queries for patterns
|
|
55
|
-
if (query.includes("*patterns[")) {
|
|
56
|
-
const patternsRelation = relations.get("patterns");
|
|
57
|
-
if (!patternsRelation)
|
|
58
|
-
return Promise.resolve({ rows: [] });
|
|
59
|
-
return Promise.resolve({ rows: Array.from(patternsRelation.values()) });
|
|
60
|
-
}
|
|
61
|
-
// Handle entity queries
|
|
62
|
-
if (query.includes("*entities{") && params?.key) {
|
|
63
|
-
const entitiesRelation = relations.get("entities");
|
|
64
|
-
if (!entitiesRelation)
|
|
65
|
-
return Promise.resolve({ rows: [] });
|
|
66
|
-
const entry = entitiesRelation.get(params.key);
|
|
67
|
-
return Promise.resolve({ rows: entry ? [entry] : [] });
|
|
68
|
-
}
|
|
69
|
-
// Handle file_index queries
|
|
70
|
-
if (query.includes("*file_index[") && params?.fp) {
|
|
71
|
-
const fileIndexRelation = relations.get("file_index");
|
|
72
|
-
if (!fileIndexRelation)
|
|
73
|
-
return Promise.resolve({ rows: [] });
|
|
74
|
-
const matching = [];
|
|
75
|
-
for (const [, value] of fileIndexRelation) {
|
|
76
|
-
if (value[0] === params.fp) {
|
|
77
|
-
// Return entity data
|
|
78
|
-
const entityKey = value[1];
|
|
79
|
-
const entitiesRelation = relations.get("entities");
|
|
80
|
-
if (entitiesRelation) {
|
|
81
|
-
const entity = entitiesRelation.get(entityKey);
|
|
82
|
-
if (entity)
|
|
83
|
-
matching.push(entity);
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
return Promise.resolve({ rows: matching });
|
|
88
|
-
}
|
|
89
|
-
// Handle :rm statements (no-op in mock)
|
|
90
|
-
if (query.includes(":rm ")) {
|
|
91
|
-
return Promise.resolve({ rows: [] });
|
|
92
|
-
}
|
|
93
|
-
// Handle drift_overlay full scan (getAllDriftEntities)
|
|
94
|
-
if (query.includes("*drift_overlay[")) {
|
|
95
|
-
const driftRelation = relations.get("drift_overlay");
|
|
96
|
-
if (!driftRelation)
|
|
97
|
-
return Promise.resolve({ rows: [] });
|
|
98
|
-
return Promise.resolve({ rows: Array.from(driftRelation.values()) });
|
|
99
|
-
}
|
|
100
|
-
// Handle entity lookup by key (getEntity inside applyDelta overlay expiry)
|
|
101
|
-
if (query.includes("*entities{") &&
|
|
102
|
-
query.includes("key = $key") &&
|
|
103
|
-
params?.key) {
|
|
104
|
-
const entitiesRelation = relations.get("entities");
|
|
105
|
-
if (!entitiesRelation)
|
|
106
|
-
return Promise.resolve({ rows: [] });
|
|
107
|
-
const entry = entitiesRelation.get(params.key);
|
|
108
|
-
return Promise.resolve({ rows: entry ? [entry] : [] });
|
|
109
|
-
}
|
|
110
|
-
// Default: return empty
|
|
111
|
-
return Promise.resolve({ rows: [] });
|
|
112
|
-
},
|
|
113
|
-
};
|
|
114
|
-
}
|
|
115
|
-
describe("CozoGraphStore — Rules & Patterns (Phase 10b)", () => {
|
|
116
|
-
let db;
|
|
117
|
-
let store;
|
|
118
|
-
beforeEach(async () => {
|
|
119
|
-
db = createInMemoryDb();
|
|
120
|
-
store = await CozoGraphStore.create(db);
|
|
121
|
-
});
|
|
122
|
-
describe("hasRules", () => {
|
|
123
|
-
it("returns false when no rules loaded", async () => {
|
|
124
|
-
expect(await store.hasRules()).toBe(false);
|
|
125
|
-
});
|
|
126
|
-
it("returns true after loading rules", async () => {
|
|
127
|
-
const rules = [
|
|
128
|
-
{
|
|
129
|
-
key: "rule-1",
|
|
130
|
-
name: "No console.log",
|
|
131
|
-
scope: "repo",
|
|
132
|
-
severity: "warn",
|
|
133
|
-
engine: "structural",
|
|
134
|
-
query: "call_expression",
|
|
135
|
-
message: "Avoid console.log in production",
|
|
136
|
-
file_glob: "**/*.ts",
|
|
137
|
-
enabled: true,
|
|
138
|
-
repo_id: "repo-1",
|
|
139
|
-
},
|
|
140
|
-
];
|
|
141
|
-
await store.loadRules(rules);
|
|
142
|
-
expect(await store.hasRules()).toBe(true);
|
|
143
|
-
});
|
|
144
|
-
});
|
|
145
|
-
describe("loadRules + getRules", () => {
|
|
146
|
-
it("loads and retrieves rules", async () => {
|
|
147
|
-
const rules = [
|
|
148
|
-
{
|
|
149
|
-
key: "rule-1",
|
|
150
|
-
name: "No console.log",
|
|
151
|
-
scope: "repo",
|
|
152
|
-
severity: "warn",
|
|
153
|
-
engine: "structural",
|
|
154
|
-
query: "call_expression",
|
|
155
|
-
message: "Avoid console.log",
|
|
156
|
-
file_glob: "",
|
|
157
|
-
enabled: true,
|
|
158
|
-
repo_id: "repo-1",
|
|
159
|
-
},
|
|
160
|
-
{
|
|
161
|
-
key: "rule-2",
|
|
162
|
-
name: "PascalCase classes",
|
|
163
|
-
scope: "org",
|
|
164
|
-
severity: "error",
|
|
165
|
-
engine: "naming",
|
|
166
|
-
query: "^[a-z]",
|
|
167
|
-
message: "Classes must be PascalCase",
|
|
168
|
-
file_glob: "**/*.ts",
|
|
169
|
-
enabled: true,
|
|
170
|
-
repo_id: "repo-1",
|
|
171
|
-
},
|
|
172
|
-
];
|
|
173
|
-
await store.loadRules(rules);
|
|
174
|
-
const result = await store.getRules();
|
|
175
|
-
expect(result.length).toBe(2);
|
|
176
|
-
});
|
|
177
|
-
it("filters by file glob", async () => {
|
|
178
|
-
const rules = [
|
|
179
|
-
{
|
|
180
|
-
key: "rule-ts",
|
|
181
|
-
name: "TS only",
|
|
182
|
-
scope: "repo",
|
|
183
|
-
severity: "warn",
|
|
184
|
-
engine: "structural",
|
|
185
|
-
query: "call_expression",
|
|
186
|
-
message: "TS rule",
|
|
187
|
-
file_glob: "**/*.ts",
|
|
188
|
-
enabled: true,
|
|
189
|
-
repo_id: "repo-1",
|
|
190
|
-
},
|
|
191
|
-
{
|
|
192
|
-
key: "rule-py",
|
|
193
|
-
name: "Python only",
|
|
194
|
-
scope: "repo",
|
|
195
|
-
severity: "warn",
|
|
196
|
-
engine: "structural",
|
|
197
|
-
query: "function_definition",
|
|
198
|
-
message: "Python rule",
|
|
199
|
-
file_glob: "**/*.py",
|
|
200
|
-
enabled: true,
|
|
201
|
-
repo_id: "repo-1",
|
|
202
|
-
},
|
|
203
|
-
];
|
|
204
|
-
await store.loadRules(rules);
|
|
205
|
-
const tsRules = await store.getRules("src/index.ts");
|
|
206
|
-
expect(tsRules.length).toBe(1);
|
|
207
|
-
expect(tsRules[0]?.key).toBe("rule-ts");
|
|
208
|
-
});
|
|
209
|
-
it("excludes disabled rules", async () => {
|
|
210
|
-
const rules = [
|
|
211
|
-
{
|
|
212
|
-
key: "rule-disabled",
|
|
213
|
-
name: "Disabled",
|
|
214
|
-
scope: "repo",
|
|
215
|
-
severity: "warn",
|
|
216
|
-
engine: "structural",
|
|
217
|
-
query: "call_expression",
|
|
218
|
-
message: "Disabled",
|
|
219
|
-
file_glob: "",
|
|
220
|
-
enabled: false,
|
|
221
|
-
repo_id: "repo-1",
|
|
222
|
-
},
|
|
223
|
-
];
|
|
224
|
-
await store.loadRules(rules);
|
|
225
|
-
const result = await store.getRules();
|
|
226
|
-
expect(result.length).toBe(0);
|
|
227
|
-
});
|
|
228
|
-
});
|
|
229
|
-
describe("loadPatterns + getPatterns", () => {
|
|
230
|
-
it("loads and retrieves patterns", async () => {
|
|
231
|
-
const patterns = [
|
|
232
|
-
{
|
|
233
|
-
key: "pattern-1",
|
|
234
|
-
name: "Error Boundary",
|
|
235
|
-
kind: "structural",
|
|
236
|
-
frequency: 15,
|
|
237
|
-
confidence: 0.85,
|
|
238
|
-
exemplar_keys: ["file1:10", "file2:20"],
|
|
239
|
-
promoted_rule_key: "",
|
|
240
|
-
},
|
|
241
|
-
];
|
|
242
|
-
await store.loadPatterns(patterns);
|
|
243
|
-
const result = await store.getPatterns();
|
|
244
|
-
expect(result.length).toBe(1);
|
|
245
|
-
expect(result[0]?.name).toBe("Error Boundary");
|
|
246
|
-
expect(result[0]?.exemplar_keys).toEqual(["file1:10", "file2:20"]);
|
|
247
|
-
});
|
|
248
|
-
});
|
|
249
|
-
describe("loadSnapshot with v2 envelope", () => {
|
|
250
|
-
it("loads rules and patterns from v2 envelope", async () => {
|
|
251
|
-
const envelope = {
|
|
252
|
-
version: 2,
|
|
253
|
-
repoId: "repo-1",
|
|
254
|
-
orgId: "org-1",
|
|
255
|
-
entities: [
|
|
256
|
-
{
|
|
257
|
-
key: "fn1",
|
|
258
|
-
kind: "function",
|
|
259
|
-
name: "doStuff",
|
|
260
|
-
file_path: "src/index.ts",
|
|
261
|
-
start_line: 10,
|
|
262
|
-
end_line: 0,
|
|
263
|
-
signature: "doStuff()",
|
|
264
|
-
body: "return 42",
|
|
265
|
-
},
|
|
266
|
-
],
|
|
267
|
-
edges: [{ from_key: "fn1", to_key: "fn2", type: "calls" }],
|
|
268
|
-
rules: [
|
|
269
|
-
{
|
|
270
|
-
key: "rule-1",
|
|
271
|
-
name: "Test Rule",
|
|
272
|
-
scope: "repo",
|
|
273
|
-
severity: "warn",
|
|
274
|
-
engine: "structural",
|
|
275
|
-
query: "call_expression",
|
|
276
|
-
message: "Test message",
|
|
277
|
-
file_glob: "",
|
|
278
|
-
enabled: true,
|
|
279
|
-
repo_id: "repo-1",
|
|
280
|
-
},
|
|
281
|
-
],
|
|
282
|
-
patterns: [
|
|
283
|
-
{
|
|
284
|
-
key: "pattern-1",
|
|
285
|
-
name: "Test Pattern",
|
|
286
|
-
kind: "structural",
|
|
287
|
-
frequency: 5,
|
|
288
|
-
confidence: 0.9,
|
|
289
|
-
exemplar_keys: ["ex1"],
|
|
290
|
-
promoted_rule_key: "",
|
|
291
|
-
},
|
|
292
|
-
],
|
|
293
|
-
generatedAt: new Date().toISOString(),
|
|
294
|
-
};
|
|
295
|
-
await store.loadSnapshot(envelope);
|
|
296
|
-
expect(await store.hasRules()).toBe(true);
|
|
297
|
-
expect((await store.getRules()).length).toBe(1);
|
|
298
|
-
expect((await store.getPatterns()).length).toBe(1);
|
|
299
|
-
});
|
|
300
|
-
it("loads v1 envelope without rules/patterns", async () => {
|
|
301
|
-
const envelope = {
|
|
302
|
-
version: 1,
|
|
303
|
-
repoId: "repo-1",
|
|
304
|
-
orgId: "org-1",
|
|
305
|
-
entities: [],
|
|
306
|
-
edges: [],
|
|
307
|
-
generatedAt: new Date().toISOString(),
|
|
308
|
-
};
|
|
309
|
-
await store.loadSnapshot(envelope);
|
|
310
|
-
expect(await store.hasRules()).toBe(false);
|
|
311
|
-
expect((await store.getPatterns()).length).toBe(0);
|
|
312
|
-
});
|
|
313
|
-
});
|
|
314
|
-
// ── Task 6.9: Overlay Expiry After Delta ─────────────────────────
|
|
315
|
-
describe("applyDelta — overlay expiry (Task 6.9)", () => {
|
|
316
|
-
const emptyDelta = {
|
|
317
|
-
entities: { added: [], updated: [], deletedKeys: [] },
|
|
318
|
-
edges: { added: [], removed: [] },
|
|
319
|
-
justifications: { updated: [] },
|
|
320
|
-
};
|
|
321
|
-
it("prunes overlay entry when base matches after delta", async () => {
|
|
322
|
-
// Spy on the store methods to control overlay/entity data
|
|
323
|
-
const driftEntities = [
|
|
324
|
-
{
|
|
325
|
-
key: "fn-1",
|
|
326
|
-
name: "doStuff",
|
|
327
|
-
kind: "function",
|
|
328
|
-
signature: "doStuff(): void",
|
|
329
|
-
body: "function doStuff() { return 1; }",
|
|
330
|
-
file_path: "src/a.ts",
|
|
331
|
-
line_start: 1,
|
|
332
|
-
line_end: 5,
|
|
333
|
-
content_hash: "abc",
|
|
334
|
-
drift_status: "modified",
|
|
335
|
-
intent_id: "",
|
|
336
|
-
modified_at: new Date().toISOString(),
|
|
337
|
-
origin: "human",
|
|
338
|
-
previous_body: "",
|
|
339
|
-
previous_signature: "",
|
|
340
|
-
},
|
|
341
|
-
];
|
|
342
|
-
vi.spyOn(store, "getAllDriftEntities").mockResolvedValue(driftEntities);
|
|
343
|
-
vi.spyOn(store, "getEntity").mockResolvedValue({
|
|
344
|
-
key: "fn-1",
|
|
345
|
-
kind: "function",
|
|
346
|
-
name: "doStuff",
|
|
347
|
-
file_path: "src/a.ts",
|
|
348
|
-
start_line: 1,
|
|
349
|
-
end_line: 0,
|
|
350
|
-
signature: "doStuff(): void",
|
|
351
|
-
body: "function doStuff() { return 1; }",
|
|
352
|
-
fan_in: 0,
|
|
353
|
-
fan_out: 0,
|
|
354
|
-
risk_level: "normal",
|
|
355
|
-
community: -1,
|
|
356
|
-
});
|
|
357
|
-
const removeSpy = vi
|
|
358
|
-
.spyOn(store, "removeDriftEntity")
|
|
359
|
-
.mockResolvedValue(undefined);
|
|
360
|
-
const result = await store.applyDelta(emptyDelta);
|
|
361
|
-
expect(result.overlayExpired).toBe(1);
|
|
362
|
-
expect(removeSpy).toHaveBeenCalledWith("fn-1");
|
|
363
|
-
vi.restoreAllMocks();
|
|
364
|
-
});
|
|
365
|
-
it("does not prune overlay when base body differs", async () => {
|
|
366
|
-
vi.spyOn(store, "getAllDriftEntities").mockResolvedValue([
|
|
367
|
-
{
|
|
368
|
-
key: "fn-2",
|
|
369
|
-
name: "calc",
|
|
370
|
-
kind: "function",
|
|
371
|
-
signature: "calc(): number",
|
|
372
|
-
body: "function calc() { return 2; }",
|
|
373
|
-
file_path: "src/b.ts",
|
|
374
|
-
line_start: 1,
|
|
375
|
-
line_end: 3,
|
|
376
|
-
content_hash: "xyz",
|
|
377
|
-
drift_status: "modified",
|
|
378
|
-
intent_id: "",
|
|
379
|
-
modified_at: new Date().toISOString(),
|
|
380
|
-
origin: "ai",
|
|
381
|
-
previous_body: "",
|
|
382
|
-
previous_signature: "",
|
|
383
|
-
},
|
|
384
|
-
]);
|
|
385
|
-
vi.spyOn(store, "getEntity").mockResolvedValue({
|
|
386
|
-
key: "fn-2",
|
|
387
|
-
kind: "function",
|
|
388
|
-
name: "calc",
|
|
389
|
-
file_path: "src/b.ts",
|
|
390
|
-
start_line: 1,
|
|
391
|
-
end_line: 0,
|
|
392
|
-
signature: "calc(): number",
|
|
393
|
-
body: "function calc() { return 999; }",
|
|
394
|
-
fan_in: 0,
|
|
395
|
-
fan_out: 0,
|
|
396
|
-
risk_level: "normal",
|
|
397
|
-
community: -1,
|
|
398
|
-
});
|
|
399
|
-
const removeSpy = vi
|
|
400
|
-
.spyOn(store, "removeDriftEntity")
|
|
401
|
-
.mockResolvedValue(undefined);
|
|
402
|
-
const result = await store.applyDelta(emptyDelta);
|
|
403
|
-
expect(result.overlayExpired).toBe(0);
|
|
404
|
-
expect(removeSpy).not.toHaveBeenCalled();
|
|
405
|
-
vi.restoreAllMocks();
|
|
406
|
-
});
|
|
407
|
-
it("skips non-modified overlay entries (added/deleted)", async () => {
|
|
408
|
-
vi.spyOn(store, "getAllDriftEntities").mockResolvedValue([
|
|
409
|
-
{
|
|
410
|
-
key: "fn-3",
|
|
411
|
-
name: "newFn",
|
|
412
|
-
kind: "function",
|
|
413
|
-
signature: "newFn(): void",
|
|
414
|
-
body: "function newFn() {}",
|
|
415
|
-
file_path: "src/c.ts",
|
|
416
|
-
line_start: 1,
|
|
417
|
-
line_end: 1,
|
|
418
|
-
content_hash: "h",
|
|
419
|
-
drift_status: "added",
|
|
420
|
-
intent_id: "",
|
|
421
|
-
modified_at: new Date().toISOString(),
|
|
422
|
-
origin: "human",
|
|
423
|
-
previous_body: "",
|
|
424
|
-
previous_signature: "",
|
|
425
|
-
},
|
|
426
|
-
{
|
|
427
|
-
key: "fn-4",
|
|
428
|
-
name: "oldFn",
|
|
429
|
-
kind: "function",
|
|
430
|
-
signature: "oldFn(): void",
|
|
431
|
-
body: "function oldFn() {}",
|
|
432
|
-
file_path: "src/d.ts",
|
|
433
|
-
line_start: 1,
|
|
434
|
-
line_end: 1,
|
|
435
|
-
content_hash: "h2",
|
|
436
|
-
drift_status: "deleted",
|
|
437
|
-
intent_id: "",
|
|
438
|
-
modified_at: new Date().toISOString(),
|
|
439
|
-
origin: "human",
|
|
440
|
-
previous_body: "",
|
|
441
|
-
previous_signature: "",
|
|
442
|
-
},
|
|
443
|
-
]);
|
|
444
|
-
const removeSpy = vi
|
|
445
|
-
.spyOn(store, "removeDriftEntity")
|
|
446
|
-
.mockResolvedValue(undefined);
|
|
447
|
-
const result = await store.applyDelta(emptyDelta);
|
|
448
|
-
expect(result.overlayExpired).toBe(0);
|
|
449
|
-
expect(removeSpy).not.toHaveBeenCalled();
|
|
450
|
-
vi.restoreAllMocks();
|
|
451
|
-
});
|
|
452
|
-
it("prunes selectively — only matching entries expire", async () => {
|
|
453
|
-
vi.spyOn(store, "getAllDriftEntities").mockResolvedValue([
|
|
454
|
-
{
|
|
455
|
-
key: "fn-a",
|
|
456
|
-
name: "alpha",
|
|
457
|
-
kind: "function",
|
|
458
|
-
signature: "alpha(): void",
|
|
459
|
-
body: "SAME_BODY",
|
|
460
|
-
file_path: "src/a.ts",
|
|
461
|
-
line_start: 1,
|
|
462
|
-
line_end: 1,
|
|
463
|
-
content_hash: "h",
|
|
464
|
-
drift_status: "modified",
|
|
465
|
-
intent_id: "",
|
|
466
|
-
modified_at: new Date().toISOString(),
|
|
467
|
-
origin: "human",
|
|
468
|
-
previous_body: "",
|
|
469
|
-
previous_signature: "",
|
|
470
|
-
},
|
|
471
|
-
{
|
|
472
|
-
key: "fn-b",
|
|
473
|
-
name: "beta",
|
|
474
|
-
kind: "function",
|
|
475
|
-
signature: "beta(): void",
|
|
476
|
-
body: "DIFFERENT_LOCAL",
|
|
477
|
-
file_path: "src/b.ts",
|
|
478
|
-
line_start: 1,
|
|
479
|
-
line_end: 1,
|
|
480
|
-
content_hash: "h2",
|
|
481
|
-
drift_status: "modified",
|
|
482
|
-
intent_id: "",
|
|
483
|
-
modified_at: new Date().toISOString(),
|
|
484
|
-
origin: "ai",
|
|
485
|
-
previous_body: "",
|
|
486
|
-
previous_signature: "",
|
|
487
|
-
},
|
|
488
|
-
]);
|
|
489
|
-
vi.spyOn(store, "getEntity").mockImplementation(async (key) => {
|
|
490
|
-
if (key === "fn-a") {
|
|
491
|
-
return {
|
|
492
|
-
key: "fn-a",
|
|
493
|
-
kind: "function",
|
|
494
|
-
name: "alpha",
|
|
495
|
-
file_path: "src/a.ts",
|
|
496
|
-
start_line: 1,
|
|
497
|
-
end_line: 0,
|
|
498
|
-
signature: "alpha(): void",
|
|
499
|
-
body: "SAME_BODY",
|
|
500
|
-
fan_in: 0,
|
|
501
|
-
fan_out: 0,
|
|
502
|
-
risk_level: "normal",
|
|
503
|
-
community: -1,
|
|
504
|
-
};
|
|
505
|
-
}
|
|
506
|
-
if (key === "fn-b") {
|
|
507
|
-
return {
|
|
508
|
-
key: "fn-b",
|
|
509
|
-
kind: "function",
|
|
510
|
-
name: "beta",
|
|
511
|
-
file_path: "src/b.ts",
|
|
512
|
-
start_line: 1,
|
|
513
|
-
end_line: 0,
|
|
514
|
-
signature: "beta(): void",
|
|
515
|
-
body: "DIFFERENT_BASE",
|
|
516
|
-
fan_in: 0,
|
|
517
|
-
fan_out: 0,
|
|
518
|
-
risk_level: "normal",
|
|
519
|
-
community: -1,
|
|
520
|
-
};
|
|
521
|
-
}
|
|
522
|
-
return null;
|
|
523
|
-
});
|
|
524
|
-
const removeSpy = vi
|
|
525
|
-
.spyOn(store, "removeDriftEntity")
|
|
526
|
-
.mockResolvedValue(undefined);
|
|
527
|
-
const result = await store.applyDelta(emptyDelta);
|
|
528
|
-
expect(result.overlayExpired).toBe(1);
|
|
529
|
-
expect(removeSpy).toHaveBeenCalledWith("fn-a");
|
|
530
|
-
expect(removeSpy).not.toHaveBeenCalledWith("fn-b");
|
|
531
|
-
vi.restoreAllMocks();
|
|
532
|
-
});
|
|
533
|
-
it("returns overlayExpired: 0 when no overlay entries exist", async () => {
|
|
534
|
-
vi.spyOn(store, "getAllDriftEntities").mockResolvedValue([]);
|
|
535
|
-
const result = await store.applyDelta(emptyDelta);
|
|
536
|
-
expect(result.overlayExpired).toBe(0);
|
|
537
|
-
vi.restoreAllMocks();
|
|
538
|
-
});
|
|
539
|
-
});
|
|
540
|
-
});
|