lynkr 8.0.0 → 9.0.1
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/.lynkr/telemetry.db +0 -0
- package/.lynkr/telemetry.db-shm +0 -0
- package/.lynkr/telemetry.db-wal +0 -0
- package/README.md +196 -322
- package/lynkr-skill.tar.gz +0 -0
- package/package.json +4 -3
- package/src/api/openai-router.js +64 -13
- package/src/api/providers-handler.js +171 -3
- package/src/api/router.js +9 -2
- package/src/clients/circuit-breaker.js +10 -247
- package/src/clients/codex-process.js +342 -0
- package/src/clients/codex-utils.js +143 -0
- package/src/clients/databricks.js +210 -63
- package/src/clients/resilience.js +540 -0
- package/src/clients/retry.js +22 -167
- package/src/clients/standard-tools.js +23 -0
- package/src/config/index.js +77 -0
- package/src/context/compression.js +42 -9
- package/src/context/distill.js +492 -0
- package/src/orchestrator/index.js +48 -8
- package/src/routing/complexity-analyzer.js +258 -5
- package/src/routing/index.js +12 -2
- package/src/routing/latency-tracker.js +148 -0
- package/src/routing/model-tiers.js +2 -0
- package/src/routing/quality-scorer.js +113 -0
- package/src/routing/telemetry.js +464 -0
- package/src/server.js +13 -12
- package/src/tools/code-graph.js +538 -0
- package/src/tools/code-mode.js +304 -0
- package/src/tools/index.js +4 -0
- package/src/tools/lazy-loader.js +18 -0
- package/src/tools/mcp-remote.js +7 -0
- package/src/tools/smart-selection.js +11 -0
- package/src/tools/tinyfish.js +358 -0
- package/src/tools/truncate.js +1 -0
- package/src/utils/payload.js +206 -0
- package/src/utils/perf-timer.js +80 -0
- package/.github/FUNDING.yml +0 -15
- package/.github/workflows/README.md +0 -215
- package/.github/workflows/ci.yml +0 -69
- package/.github/workflows/index.yml +0 -62
- package/.github/workflows/web-tools-tests.yml +0 -56
- package/CITATIONS.bib +0 -6
- package/DEPLOYMENT.md +0 -1001
- package/LYNKR-TUI-PLAN.md +0 -984
- package/PERFORMANCE-REPORT.md +0 -866
- package/PLAN-per-client-model-routing.md +0 -252
- package/docs/42642f749da6234f41b6b425c3bb07c9.txt +0 -1
- package/docs/BingSiteAuth.xml +0 -4
- package/docs/docs-style.css +0 -478
- package/docs/docs.html +0 -198
- package/docs/google5be250e608e6da39.html +0 -1
- package/docs/index.html +0 -577
- package/docs/index.md +0 -584
- package/docs/robots.txt +0 -4
- package/docs/sitemap.xml +0 -44
- package/docs/style.css +0 -1223
- package/docs/toon-integration-spec.md +0 -130
- package/documentation/README.md +0 -101
- package/documentation/api.md +0 -806
- package/documentation/claude-code-cli.md +0 -679
- package/documentation/codex-cli.md +0 -397
- package/documentation/contributing.md +0 -571
- package/documentation/cursor-integration.md +0 -734
- package/documentation/docker.md +0 -874
- package/documentation/embeddings.md +0 -762
- package/documentation/faq.md +0 -713
- package/documentation/features.md +0 -403
- package/documentation/headroom.md +0 -519
- package/documentation/installation.md +0 -758
- package/documentation/memory-system.md +0 -476
- package/documentation/production.md +0 -636
- package/documentation/providers.md +0 -1009
- package/documentation/routing.md +0 -476
- package/documentation/testing.md +0 -629
- package/documentation/token-optimization.md +0 -325
- package/documentation/tools.md +0 -697
- package/documentation/troubleshooting.md +0 -969
- package/final-test.js +0 -33
- package/headroom-sidecar/config.py +0 -93
- package/headroom-sidecar/requirements.txt +0 -14
- package/headroom-sidecar/server.py +0 -451
- package/monitor-agents.sh +0 -31
- package/scripts/audit-log-reader.js +0 -399
- package/scripts/compact-dictionary.js +0 -204
- package/scripts/test-deduplication.js +0 -448
- package/src/db/database.sqlite +0 -0
- package/te +0 -11622
- package/test/README.md +0 -212
- package/test/azure-openai-config.test.js +0 -213
- package/test/azure-openai-error-resilience.test.js +0 -238
- package/test/azure-openai-format-conversion.test.js +0 -354
- package/test/azure-openai-integration.test.js +0 -287
- package/test/azure-openai-routing.test.js +0 -175
- package/test/azure-openai-streaming.test.js +0 -171
- package/test/bedrock-integration.test.js +0 -457
- package/test/comprehensive-test-suite.js +0 -928
- package/test/config-validation.test.js +0 -207
- package/test/cursor-integration.test.js +0 -484
- package/test/format-conversion.test.js +0 -578
- package/test/hybrid-routing-integration.test.js +0 -269
- package/test/hybrid-routing-performance.test.js +0 -428
- package/test/llamacpp-integration.test.js +0 -882
- package/test/lmstudio-integration.test.js +0 -347
- package/test/memory/extractor.test.js +0 -398
- package/test/memory/retriever.test.js +0 -613
- package/test/memory/retriever.test.js.bak +0 -585
- package/test/memory/search.test.js +0 -537
- package/test/memory/search.test.js.bak +0 -389
- package/test/memory/store.test.js +0 -344
- package/test/memory/store.test.js.bak +0 -312
- package/test/memory/surprise.test.js +0 -300
- package/test/memory-performance.test.js +0 -472
- package/test/openai-integration.test.js +0 -683
- package/test/openrouter-error-resilience.test.js +0 -418
- package/test/passthrough-mode.test.js +0 -385
- package/test/performance-benchmark.js +0 -351
- package/test/performance-tests.js +0 -528
- package/test/routing.test.js +0 -225
- package/test/toon-compression.test.js +0 -131
- package/test/web-tools.test.js +0 -329
- package/test-agents-simple.js +0 -43
- package/test-cli-connection.sh +0 -33
- package/test-learning-unit.js +0 -126
- package/test-learning.js +0 -112
- package/test-parallel-agents.sh +0 -124
- package/test-parallel-direct.js +0 -155
- package/test-subagents.sh +0 -117
|
@@ -1,537 +0,0 @@
|
|
|
1
|
-
const assert = require("assert");
|
|
2
|
-
const { describe, it, beforeEach, afterEach } = require("node:test");
|
|
3
|
-
const fs = require("fs");
|
|
4
|
-
const path = require("path");
|
|
5
|
-
|
|
6
|
-
describe("Memory Search", () => {
|
|
7
|
-
let store;
|
|
8
|
-
let search;
|
|
9
|
-
let testDbPath;
|
|
10
|
-
|
|
11
|
-
beforeEach(() => {
|
|
12
|
-
// Create a unique temporary test database
|
|
13
|
-
const timestamp = Date.now();
|
|
14
|
-
const random = Math.floor(Math.random() * 1000000);
|
|
15
|
-
testDbPath = path.join(__dirname, `../../data/test-search-${timestamp}-${random}.db`);
|
|
16
|
-
|
|
17
|
-
// Set test environment to new database (correct env var is SESSION_DB_PATH)
|
|
18
|
-
process.env.SESSION_DB_PATH = testDbPath;
|
|
19
|
-
|
|
20
|
-
// Clear ALL module cache to ensure fresh config is loaded
|
|
21
|
-
delete require.cache[require.resolve("../../src/config")];
|
|
22
|
-
delete require.cache[require.resolve("../../src/db")];
|
|
23
|
-
delete require.cache[require.resolve("../../src/memory/store")];
|
|
24
|
-
delete require.cache[require.resolve("../../src/memory/search")];
|
|
25
|
-
|
|
26
|
-
// Initialize database with schema (this creates a fresh database)
|
|
27
|
-
require("../../src/db");
|
|
28
|
-
|
|
29
|
-
// Load modules
|
|
30
|
-
store = require("../../src/memory/store");
|
|
31
|
-
search = require("../../src/memory/search");
|
|
32
|
-
|
|
33
|
-
// Create test memories
|
|
34
|
-
store.createMemory({
|
|
35
|
-
content: "User prefers Python for data processing and machine learning tasks",
|
|
36
|
-
type: "preference",
|
|
37
|
-
category: "user",
|
|
38
|
-
importance: 0.8
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
store.createMemory({
|
|
42
|
-
content: "This project uses Express.js framework with TypeScript",
|
|
43
|
-
type: "fact",
|
|
44
|
-
category: "project",
|
|
45
|
-
importance: 0.7
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
store.createMemory({
|
|
49
|
-
content: "Decided to implement authentication using JWT tokens",
|
|
50
|
-
type: "decision",
|
|
51
|
-
category: "code",
|
|
52
|
-
importance: 0.9
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
store.createMemory({
|
|
56
|
-
content: "Database uses SQLite with better-sqlite3 driver",
|
|
57
|
-
type: "fact",
|
|
58
|
-
category: "project",
|
|
59
|
-
importance: 0.6
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
store.createMemory({
|
|
63
|
-
content: "UserController class handles user authentication and profile management",
|
|
64
|
-
type: "entity",
|
|
65
|
-
category: "code",
|
|
66
|
-
importance: 0.5
|
|
67
|
-
});
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
afterEach(() => {
|
|
71
|
-
// Close database connection first
|
|
72
|
-
try {
|
|
73
|
-
const db = require("../../src/db");
|
|
74
|
-
if (db && typeof db.close === 'function') {
|
|
75
|
-
db.close();
|
|
76
|
-
}
|
|
77
|
-
} catch (err) {
|
|
78
|
-
// Ignore if already closed
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
// Clear module cache to release all references
|
|
82
|
-
delete require.cache[require.resolve("../../src/db")];
|
|
83
|
-
delete require.cache[require.resolve("../../src/memory/store")];
|
|
84
|
-
delete require.cache[require.resolve("../../src/memory/search")];
|
|
85
|
-
|
|
86
|
-
// Clean up all SQLite files (db, wal, shm)
|
|
87
|
-
try {
|
|
88
|
-
const files = [
|
|
89
|
-
testDbPath,
|
|
90
|
-
`${testDbPath}-wal`,
|
|
91
|
-
`${testDbPath}-shm`,
|
|
92
|
-
`${testDbPath}-journal`
|
|
93
|
-
];
|
|
94
|
-
|
|
95
|
-
for (const file of files) {
|
|
96
|
-
if (fs.existsSync(file)) {
|
|
97
|
-
fs.unlinkSync(file);
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
} catch (err) {
|
|
101
|
-
// Ignore cleanup errors
|
|
102
|
-
}
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
describe("searchMemories()", () => {
|
|
106
|
-
it("should find memories by keyword", () => {
|
|
107
|
-
const results = search.searchMemories({ query: "Python" });
|
|
108
|
-
assert.ok(results.length > 0, "Should find Python memory");
|
|
109
|
-
assert.ok(results[0].content.toLowerCase().includes("python"));
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
it("should find memories with partial matches", () => {
|
|
113
|
-
const results = search.searchMemories({ query: "express" });
|
|
114
|
-
assert.ok(results.length > 0, "Should find Express memory");
|
|
115
|
-
assert.ok(results.some(m => m.content.toLowerCase().includes("express")));
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
it("should support FTS5 phrase search", () => {
|
|
119
|
-
const results = search.searchMemories({ query: "machine learning" });
|
|
120
|
-
assert.ok(results.length > 0, "Should find 'machine learning' phrase");
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
it("should filter by memory type", () => {
|
|
124
|
-
const results = search.searchMemories({
|
|
125
|
-
query: "project",
|
|
126
|
-
types: ["fact"]
|
|
127
|
-
});
|
|
128
|
-
assert.ok(results.length > 0);
|
|
129
|
-
assert.ok(results.every(m => m.type === "fact"), "All results should be facts");
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
it("should filter by category", () => {
|
|
133
|
-
const results = search.searchMemories({
|
|
134
|
-
query: "project",
|
|
135
|
-
categories: ["project"]
|
|
136
|
-
});
|
|
137
|
-
assert.ok(results.length > 0);
|
|
138
|
-
assert.ok(results.every(m => m.category === "project"));
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
it("should filter by session id", () => {
|
|
142
|
-
// Create session-specific memory
|
|
143
|
-
store.createMemory({
|
|
144
|
-
content: "Session-specific memory about testing",
|
|
145
|
-
type: "fact",
|
|
146
|
-
sessionId: null // was: "test-session-123"
|
|
147
|
-
});
|
|
148
|
-
|
|
149
|
-
const results = search.searchMemories({
|
|
150
|
-
query: "testing",
|
|
151
|
-
sessionId: null // was: "test-session-123"
|
|
152
|
-
});
|
|
153
|
-
|
|
154
|
-
assert.ok(results.length > 0);
|
|
155
|
-
assert.ok(results.every(m => m.sessionId === "test-session-123" || m.sessionId === null));
|
|
156
|
-
});
|
|
157
|
-
|
|
158
|
-
it("should filter by minimum importance", () => {
|
|
159
|
-
const results = search.searchMemories({
|
|
160
|
-
query: "project",
|
|
161
|
-
minImportance: 0.7
|
|
162
|
-
});
|
|
163
|
-
|
|
164
|
-
assert.ok(results.length > 0);
|
|
165
|
-
assert.ok(results.every(m => m.importance >= 0.7));
|
|
166
|
-
});
|
|
167
|
-
|
|
168
|
-
it("should respect limit parameter", () => {
|
|
169
|
-
const results = search.searchMemories({ query: "project", limit: 2 });
|
|
170
|
-
assert.ok(results.length <= 2);
|
|
171
|
-
});
|
|
172
|
-
|
|
173
|
-
it("should return empty array for no matches", () => {
|
|
174
|
-
const results = search.searchMemories({ query: "nonexistent-keyword-xyz" });
|
|
175
|
-
assert.strictEqual(results.length, 0);
|
|
176
|
-
});
|
|
177
|
-
|
|
178
|
-
it("should handle special characters in query", () => {
|
|
179
|
-
store.createMemory({
|
|
180
|
-
content: "Uses @nestjs/core package version ^9.0.0",
|
|
181
|
-
type: "fact",
|
|
182
|
-
category: "project"
|
|
183
|
-
});
|
|
184
|
-
|
|
185
|
-
const results = search.searchMemories({ query: "nestjs" });
|
|
186
|
-
assert.ok(results.length > 0);
|
|
187
|
-
});
|
|
188
|
-
|
|
189
|
-
it("should be case-insensitive", () => {
|
|
190
|
-
const lower = search.searchMemories({ query: "python" });
|
|
191
|
-
const upper = search.searchMemories({ query: "PYTHON" });
|
|
192
|
-
const mixed = search.searchMemories({ query: "PyThOn" });
|
|
193
|
-
|
|
194
|
-
assert.ok(lower.length > 0);
|
|
195
|
-
assert.strictEqual(lower.length, upper.length);
|
|
196
|
-
assert.strictEqual(lower.length, mixed.length);
|
|
197
|
-
});
|
|
198
|
-
});
|
|
199
|
-
|
|
200
|
-
describe("searchWithExpansion()", () => {
|
|
201
|
-
it("should expand query and find more results", () => {
|
|
202
|
-
const basicResults = search.searchMemories({ query: "database" });
|
|
203
|
-
const expandedResults = search.searchWithExpansion({ query: "database" });
|
|
204
|
-
|
|
205
|
-
// Expanded search should find at least as many as basic
|
|
206
|
-
assert.ok(expandedResults.length >= basicResults.length);
|
|
207
|
-
});
|
|
208
|
-
|
|
209
|
-
it("should find results with related terms", () => {
|
|
210
|
-
// Should find both "Express.js" and "authentication" memories
|
|
211
|
-
const results = search.searchWithExpansion({ query: "authentication" });
|
|
212
|
-
assert.ok(results.length > 0);
|
|
213
|
-
});
|
|
214
|
-
|
|
215
|
-
it("should handle multi-word queries", () => {
|
|
216
|
-
const results = search.searchWithExpansion({ query: "user authentication system" });
|
|
217
|
-
assert.ok(results.length >= 0); // Should not error
|
|
218
|
-
});
|
|
219
|
-
});
|
|
220
|
-
|
|
221
|
-
describe("extractKeywords()", () => {
|
|
222
|
-
it("should extract meaningful keywords", () => {
|
|
223
|
-
const keywords = search.extractKeywords("User prefers Python for data processing");
|
|
224
|
-
assert.ok(keywords.length > 0);
|
|
225
|
-
assert.ok(keywords.includes("python") || keywords.includes("data"));
|
|
226
|
-
});
|
|
227
|
-
|
|
228
|
-
it("should filter out stop words", () => {
|
|
229
|
-
const keywords = search.extractKeywords("The user is using the database");
|
|
230
|
-
// Should not include common stop words like "the", "is", "using"
|
|
231
|
-
assert.ok(!keywords.includes("the"));
|
|
232
|
-
assert.ok(!keywords.includes("is"));
|
|
233
|
-
});
|
|
234
|
-
|
|
235
|
-
it("should handle empty text", () => {
|
|
236
|
-
const keywords = search.extractKeywords("");
|
|
237
|
-
assert.ok(Array.isArray(keywords));
|
|
238
|
-
assert.strictEqual(keywords.length, 0);
|
|
239
|
-
});
|
|
240
|
-
|
|
241
|
-
it("should extract from technical content", () => {
|
|
242
|
-
const keywords = search.extractKeywords("Using Express.js with TypeScript and JWT authentication");
|
|
243
|
-
assert.ok(keywords.length > 0);
|
|
244
|
-
assert.ok(keywords.some(k => k.includes("express") || k.includes("typescript") || k.includes("jwt")));
|
|
245
|
-
});
|
|
246
|
-
});
|
|
247
|
-
|
|
248
|
-
describe("findSimilar()", () => {
|
|
249
|
-
it("should find memories similar to reference", () => {
|
|
250
|
-
const reference = store.createMemory({
|
|
251
|
-
content: "User likes JavaScript frameworks like React and Vue",
|
|
252
|
-
type: "preference"
|
|
253
|
-
});
|
|
254
|
-
|
|
255
|
-
const similar = search.findSimilar(reference.id, { limit: 3 });
|
|
256
|
-
assert.ok(similar.length >= 0);
|
|
257
|
-
// Should not include the reference memory itself
|
|
258
|
-
assert.ok(!similar.some(m => m.id === reference.id));
|
|
259
|
-
});
|
|
260
|
-
|
|
261
|
-
it("should return empty for no similar memories", () => {
|
|
262
|
-
const unique = store.createMemory({
|
|
263
|
-
content: "Quantum computing with superconducting qubits",
|
|
264
|
-
type: "fact"
|
|
265
|
-
});
|
|
266
|
-
|
|
267
|
-
const similar = search.findSimilar(unique.id, { limit: 5 });
|
|
268
|
-
assert.ok(similar.length >= 0);
|
|
269
|
-
});
|
|
270
|
-
|
|
271
|
-
it("should throw error for non-existent memory id", () => {
|
|
272
|
-
assert.throws(() => {
|
|
273
|
-
search.findSimilar(99999);
|
|
274
|
-
});
|
|
275
|
-
});
|
|
276
|
-
});
|
|
277
|
-
|
|
278
|
-
describe("searchByContent()", () => {
|
|
279
|
-
it("should search by content similarity", () => {
|
|
280
|
-
const results = search.searchByContent("Python programming language");
|
|
281
|
-
assert.ok(results.length > 0);
|
|
282
|
-
assert.ok(results.some(m => m.content.toLowerCase().includes("python")));
|
|
283
|
-
});
|
|
284
|
-
|
|
285
|
-
it("should handle empty content", () => {
|
|
286
|
-
const results = search.searchByContent("");
|
|
287
|
-
assert.strictEqual(results.length, 0);
|
|
288
|
-
});
|
|
289
|
-
|
|
290
|
-
it("should filter by type and category", () => {
|
|
291
|
-
const results = search.searchByContent("project", {
|
|
292
|
-
types: ["fact"],
|
|
293
|
-
categories: ["project"]
|
|
294
|
-
});
|
|
295
|
-
|
|
296
|
-
assert.ok(results.every(m => m.type === "fact" && m.category === "project"));
|
|
297
|
-
});
|
|
298
|
-
});
|
|
299
|
-
|
|
300
|
-
describe("countSearchResults()", () => {
|
|
301
|
-
it("should count matching memories", () => {
|
|
302
|
-
const count = search.countSearchResults({ query: "project" });
|
|
303
|
-
assert.ok(count > 0);
|
|
304
|
-
assert.strictEqual(typeof count, "number");
|
|
305
|
-
});
|
|
306
|
-
|
|
307
|
-
it("should return 0 for no matches", () => {
|
|
308
|
-
const count = search.countSearchResults({ query: "nonexistent-xyz" });
|
|
309
|
-
assert.strictEqual(count, 0);
|
|
310
|
-
});
|
|
311
|
-
|
|
312
|
-
it("should respect filters", () => {
|
|
313
|
-
const totalCount = search.countSearchResults({ query: "project" });
|
|
314
|
-
const factCount = search.countSearchResults({ query: "project", types: ["fact"] });
|
|
315
|
-
|
|
316
|
-
assert.ok(factCount <= totalCount);
|
|
317
|
-
});
|
|
318
|
-
});
|
|
319
|
-
|
|
320
|
-
describe("FTS5 Query Preparation", () => {
|
|
321
|
-
it("should handle AND operator", () => {
|
|
322
|
-
const results = search.searchMemories({ query: "Python AND machine" });
|
|
323
|
-
if (results.length > 0) {
|
|
324
|
-
assert.ok(results[0].content.toLowerCase().includes("python"));
|
|
325
|
-
assert.ok(results[0].content.toLowerCase().includes("machine"));
|
|
326
|
-
}
|
|
327
|
-
});
|
|
328
|
-
|
|
329
|
-
it("should handle OR operator", () => {
|
|
330
|
-
const results = search.searchMemories({ query: "Python OR JavaScript" });
|
|
331
|
-
assert.ok(results.length > 0);
|
|
332
|
-
});
|
|
333
|
-
|
|
334
|
-
it("should handle complex queries", () => {
|
|
335
|
-
// Should not throw error with complex FTS5 syntax
|
|
336
|
-
assert.doesNotThrow(() => {
|
|
337
|
-
search.searchMemories({ query: "(Python OR JavaScript) AND framework" });
|
|
338
|
-
});
|
|
339
|
-
});
|
|
340
|
-
|
|
341
|
-
it("should escape special FTS5 characters", () => {
|
|
342
|
-
// Characters like quotes, parens can break FTS5
|
|
343
|
-
assert.doesNotThrow(() => {
|
|
344
|
-
search.searchMemories({ query: 'test "quoted" (parens)' });
|
|
345
|
-
});
|
|
346
|
-
});
|
|
347
|
-
});
|
|
348
|
-
|
|
349
|
-
describe("Performance", () => {
|
|
350
|
-
it("should handle searches with many results efficiently", () => {
|
|
351
|
-
// Create many memories
|
|
352
|
-
for (let i = 0; i < 100; i++) {
|
|
353
|
-
store.createMemory({
|
|
354
|
-
content: `Test memory number ${i} about Python and JavaScript`,
|
|
355
|
-
type: "fact",
|
|
356
|
-
importance: Math.random()
|
|
357
|
-
});
|
|
358
|
-
}
|
|
359
|
-
|
|
360
|
-
const start = Date.now();
|
|
361
|
-
const results = search.searchMemories({ query: "Python", limit: 10 });
|
|
362
|
-
const duration = Date.now() - start;
|
|
363
|
-
|
|
364
|
-
assert.ok(results.length > 0);
|
|
365
|
-
assert.ok(duration < 100, `Search took ${duration}ms, expected < 100ms`);
|
|
366
|
-
});
|
|
367
|
-
|
|
368
|
-
it("should handle multiple concurrent searches", () => {
|
|
369
|
-
const searches = [
|
|
370
|
-
search.searchMemories({ query: "Python" }),
|
|
371
|
-
search.searchMemories({ query: "Express" }),
|
|
372
|
-
search.searchMemories({ query: "database" }),
|
|
373
|
-
search.searchMemories({ query: "authentication" })
|
|
374
|
-
];
|
|
375
|
-
|
|
376
|
-
// All should complete without errors
|
|
377
|
-
searches.forEach(results => {
|
|
378
|
-
assert.ok(Array.isArray(results));
|
|
379
|
-
});
|
|
380
|
-
});
|
|
381
|
-
});
|
|
382
|
-
|
|
383
|
-
describe("Edge Cases", () => {
|
|
384
|
-
it("should handle very long queries", () => {
|
|
385
|
-
const longQuery = "Python ".repeat(100);
|
|
386
|
-
assert.doesNotThrow(() => {
|
|
387
|
-
search.searchMemories({ query: longQuery });
|
|
388
|
-
});
|
|
389
|
-
});
|
|
390
|
-
|
|
391
|
-
it("should handle queries with only stop words", () => {
|
|
392
|
-
const results = search.searchMemories({ query: "the a an is are" });
|
|
393
|
-
assert.ok(Array.isArray(results));
|
|
394
|
-
});
|
|
395
|
-
|
|
396
|
-
it("should handle numeric queries", () => {
|
|
397
|
-
store.createMemory({
|
|
398
|
-
content: "Server runs on port 3000",
|
|
399
|
-
type: "fact"
|
|
400
|
-
});
|
|
401
|
-
|
|
402
|
-
const results = search.searchMemories({ query: "3000" });
|
|
403
|
-
assert.ok(results.length > 0);
|
|
404
|
-
});
|
|
405
|
-
|
|
406
|
-
it("should handle emoji and unicode", () => {
|
|
407
|
-
store.createMemory({
|
|
408
|
-
content: "User's favorite emoji is 🚀 for deployment",
|
|
409
|
-
type: "preference"
|
|
410
|
-
});
|
|
411
|
-
|
|
412
|
-
const results = search.searchMemories({ query: "emoji" });
|
|
413
|
-
assert.ok(results.length > 0);
|
|
414
|
-
});
|
|
415
|
-
});
|
|
416
|
-
|
|
417
|
-
describe("FTS5 Query Preparation (prepareFTS5Query)", () => {
|
|
418
|
-
it("should strip XML/HTML tags from queries", () => {
|
|
419
|
-
// The exact query that caused the error
|
|
420
|
-
const query = "<tool_use_error>Error: No such tool available: Bash</tool_use_error>";
|
|
421
|
-
const prepared = search.prepareFTS5Query(query);
|
|
422
|
-
|
|
423
|
-
// Should not contain < or >
|
|
424
|
-
assert.ok(!prepared.includes('<'));
|
|
425
|
-
assert.ok(!prepared.includes('>'));
|
|
426
|
-
|
|
427
|
-
// Should still contain the error text
|
|
428
|
-
assert.ok(prepared.includes('Error') || prepared.includes('tool_use_error'));
|
|
429
|
-
});
|
|
430
|
-
|
|
431
|
-
it("should handle XML tags with system reminders", () => {
|
|
432
|
-
const query = "<tool_use_error>Error: No such tool available: Bash</tool_use_error>\n\n<system-reminder>\nCRITICAL: This is a READ-ONLY task. You CANNOT edit, write, or create files.\n</system-reminder>";
|
|
433
|
-
const prepared = search.prepareFTS5Query(query);
|
|
434
|
-
|
|
435
|
-
// Should not contain XML tags
|
|
436
|
-
assert.ok(!prepared.includes('<'));
|
|
437
|
-
assert.ok(!prepared.includes('>'));
|
|
438
|
-
|
|
439
|
-
// Should be a valid FTS5 query (doesn't throw when searching)
|
|
440
|
-
assert.doesNotThrow(() => {
|
|
441
|
-
search.searchMemories({ query: prepared });
|
|
442
|
-
});
|
|
443
|
-
});
|
|
444
|
-
|
|
445
|
-
it("should remove FTS5 special characters", () => {
|
|
446
|
-
const specialChars = [
|
|
447
|
-
"query with * wildcard",
|
|
448
|
-
"query (with parentheses)",
|
|
449
|
-
"query with - minus",
|
|
450
|
-
"query:with:colons",
|
|
451
|
-
"query [with brackets]"
|
|
452
|
-
];
|
|
453
|
-
|
|
454
|
-
for (const query of specialChars) {
|
|
455
|
-
const prepared = search.prepareFTS5Query(query);
|
|
456
|
-
|
|
457
|
-
// Should not throw FTS5 syntax error
|
|
458
|
-
assert.doesNotThrow(() => {
|
|
459
|
-
search.searchMemories({ query: prepared });
|
|
460
|
-
}, `Failed for: ${query}`);
|
|
461
|
-
}
|
|
462
|
-
});
|
|
463
|
-
|
|
464
|
-
it("should preserve AND/OR/NOT operators when present", () => {
|
|
465
|
-
const queries = [
|
|
466
|
-
"Python AND machine learning",
|
|
467
|
-
"JavaScript OR TypeScript",
|
|
468
|
-
"NOT deprecated"
|
|
469
|
-
];
|
|
470
|
-
|
|
471
|
-
for (const query of queries) {
|
|
472
|
-
const prepared = search.prepareFTS5Query(query);
|
|
473
|
-
|
|
474
|
-
// Should preserve operators (not wrapped in quotes)
|
|
475
|
-
assert.ok(!prepared.startsWith('"') || prepared.includes('AND') || prepared.includes('OR') || prepared.includes('NOT'));
|
|
476
|
-
}
|
|
477
|
-
});
|
|
478
|
-
|
|
479
|
-
it("should wrap simple queries in quotes for phrase search", () => {
|
|
480
|
-
const query = "simple text query";
|
|
481
|
-
const prepared = search.prepareFTS5Query(query);
|
|
482
|
-
|
|
483
|
-
// Should be wrapped in quotes
|
|
484
|
-
assert.ok(prepared.startsWith('"'));
|
|
485
|
-
assert.ok(prepared.endsWith('"'));
|
|
486
|
-
});
|
|
487
|
-
|
|
488
|
-
it("should handle queries with existing double quotes", () => {
|
|
489
|
-
const query = 'query with "quoted text" inside';
|
|
490
|
-
const prepared = search.prepareFTS5Query(query);
|
|
491
|
-
|
|
492
|
-
// Should escape quotes (FTS5 uses "" for literal ")
|
|
493
|
-
assert.ok(prepared.includes('""') || !prepared.includes('"quoted text"'));
|
|
494
|
-
|
|
495
|
-
// Should not throw
|
|
496
|
-
assert.doesNotThrow(() => {
|
|
497
|
-
search.searchMemories({ query: prepared });
|
|
498
|
-
});
|
|
499
|
-
});
|
|
500
|
-
|
|
501
|
-
it("should handle empty query after tag removal", () => {
|
|
502
|
-
const query = "<tag></tag><another></another>";
|
|
503
|
-
const prepared = search.prepareFTS5Query(query);
|
|
504
|
-
|
|
505
|
-
// Should return safe fallback
|
|
506
|
-
assert.strictEqual(prepared, '"empty query"');
|
|
507
|
-
});
|
|
508
|
-
|
|
509
|
-
it("should handle queries with multiple special characters", () => {
|
|
510
|
-
const query = "test<>query-with*special:chars()[]";
|
|
511
|
-
const prepared = search.prepareFTS5Query(query);
|
|
512
|
-
|
|
513
|
-
// Should not throw FTS5 error
|
|
514
|
-
assert.doesNotThrow(() => {
|
|
515
|
-
search.searchMemories({ query: prepared });
|
|
516
|
-
});
|
|
517
|
-
});
|
|
518
|
-
|
|
519
|
-
it("should handle real-world error messages", () => {
|
|
520
|
-
const errorQueries = [
|
|
521
|
-
"TypeError: Cannot read property 'length' of undefined",
|
|
522
|
-
"Error: ENOENT: no such file or directory, open '/path/to/file.txt'",
|
|
523
|
-
"SyntaxError: Unexpected token '<' in JSON at position 0",
|
|
524
|
-
"<error>Database connection failed: ETIMEDOUT</error>"
|
|
525
|
-
];
|
|
526
|
-
|
|
527
|
-
for (const query of errorQueries) {
|
|
528
|
-
const prepared = search.prepareFTS5Query(query);
|
|
529
|
-
|
|
530
|
-
// Should not throw FTS5 syntax error
|
|
531
|
-
assert.doesNotThrow(() => {
|
|
532
|
-
search.searchMemories({ query: prepared });
|
|
533
|
-
}, `Failed for: ${query}`);
|
|
534
|
-
}
|
|
535
|
-
});
|
|
536
|
-
});
|
|
537
|
-
});
|