Skip to content

Commit 115eb76

Browse files
prosdevclaude
andcommitted
refactor(core): remove LanceDB + @xenova/transformers, fix all tests
Part 1.4 of antfly migration: Removed: - @lancedb/lancedb and @xenova/transformers from core + dev-agent deps - LanceDBVectorStore (store.ts) and TransformersEmbedder (embedder.ts) - Old vector tests (store.test.ts, embedder.test.ts, vector.test.ts) - LanceDB/@xenova externals from tsup.config.ts Added: - VectorStorage mock (__mocks__/index.ts) for tests not needing antfly - vi.mock for vector module in indexer, subagent, and CLI tests Fixed: - All test files that created real VectorStorage now use mock - Explorer error handling test uses explicit mock instead of close() - Fetcher test repo name (lytics → prosdevlab) Result: 1935 tests passing, 0 failures. No @lancedb or @xenova/transformers references remain in source. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent d682a00 commit 115eb76

18 files changed

Lines changed: 266 additions & 1714 deletions

File tree

packages/cli/src/commands/commands.test.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,38 @@ import * as fs from 'node:fs/promises';
22
import * as os from 'node:os';
33
import * as path from 'node:path';
44
import { Command } from 'commander';
5+
6+
// Mock VectorStorage to avoid needing antfly server
7+
vi.mock('../../../core/src/vector/index', async (importOriginal) => {
8+
const actual = await importOriginal();
9+
return {
10+
...actual,
11+
VectorStorage: class MockVectorStorage {
12+
async initialize() {}
13+
async addDocuments() {}
14+
async search() {
15+
return [];
16+
}
17+
async searchByDocumentId() {
18+
return [];
19+
}
20+
async getAll() {
21+
return [];
22+
}
23+
async getDocument() {
24+
return null;
25+
}
26+
async deleteDocuments() {}
27+
async clear() {}
28+
async getStats() {
29+
return { totalDocuments: 0, storageSize: 0, dimension: 384, modelName: 'mock' };
30+
}
31+
async optimize() {}
32+
async close() {}
33+
},
34+
};
35+
});
36+
537
import { afterAll, beforeAll, describe, expect, it, vi } from 'vitest';
638
import { cleanCommand } from './clean';
739
import { indexCommand } from './index';

packages/core/package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,8 @@
3838
},
3939
"dependencies": {
4040
"@antfly/sdk": "0.0.14",
41-
"@lancedb/lancedb": "^0.22.3",
4241
"@prosdevlab/dev-agent-types": "workspace:*",
4342
"@prosdevlab/kero": "workspace:*",
44-
"@xenova/transformers": "^2.17.2",
4543
"better-sqlite3": "^12.5.0",
4644
"globby": "^16.0.0",
4745
"remark": "^15.0.1",

packages/core/src/indexer/__tests__/detailed-stats.integration.test.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import * as fs from 'node:fs/promises';
22
import * as os from 'node:os';
33
import * as path from 'node:path';
4-
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
4+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
5+
6+
// Use mock VectorStorage (no antfly server needed)
7+
vi.mock('../../vector/index');
8+
59
import { RepositoryIndexer } from '../index';
610
import type { DetailedIndexStats } from '../types';
711

packages/core/src/indexer/__tests__/indexer-edge.test.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22
import * as fs from 'node:fs/promises';
33
import * as os from 'node:os';
44
import * as path from 'node:path';
5-
import { afterAll, beforeAll, describe, expect, it } from 'vitest';
5+
import { afterAll, beforeAll, describe, expect, it, vi } from 'vitest';
6+
7+
// Use mock VectorStorage (no antfly server needed)
8+
vi.mock('../../vector/index');
9+
610
import { RepositoryIndexer } from '../index';
711

812
/**

packages/core/src/indexer/__tests__/indexer.test.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import * as fs from 'node:fs/promises';
22
import * as os from 'node:os';
33
import * as path from 'node:path';
4-
import { afterAll, beforeAll, describe, expect, it } from 'vitest';
4+
import { afterAll, beforeAll, describe, expect, it, vi } from 'vitest';
5+
6+
// Use mock VectorStorage (no antfly server needed)
7+
vi.mock('../../vector/index');
8+
59
import { RepositoryIndexer } from '../index';
610
import type { IndexProgress } from '../types';
711

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
/**
2+
* Mock VectorStorage for tests that don't need a real antfly server.
3+
*
4+
* Used by indexer, subagent, and CLI tests that test their own logic,
5+
* not vector storage behavior. The real antfly tests are in antfly-store.test.ts.
6+
*/
7+
8+
import { vi } from 'vitest';
9+
10+
export { type AntflyStoreConfig, AntflyVectorStore } from '../antfly-store.js';
11+
// Re-export real types
12+
export * from '../types.js';
13+
14+
// In-memory document store for mock
15+
const docs = new Map<string, { text: string; metadata: Record<string, unknown> }>();
16+
17+
export class VectorStorage {
18+
private initialized = false;
19+
20+
constructor(_config: { storePath: string; embeddingModel?: string; dimension?: number }) {
21+
// No-op — mock doesn't connect to anything
22+
}
23+
24+
async initialize(_options?: { skipEmbedder?: boolean }): Promise<void> {
25+
this.initialized = true;
26+
}
27+
28+
async addDocuments(
29+
documents: Array<{ id: string; text: string; metadata: Record<string, unknown> }>
30+
): Promise<void> {
31+
for (const doc of documents) {
32+
docs.set(doc.id, { text: doc.text, metadata: doc.metadata });
33+
}
34+
}
35+
36+
async search(
37+
_query: string,
38+
options?: { limit?: number; scoreThreshold?: number }
39+
): Promise<Array<{ id: string; score: number; metadata: Record<string, unknown> }>> {
40+
const limit = options?.limit ?? 10;
41+
const results = Array.from(docs.entries())
42+
.slice(0, limit)
43+
.map(([id, doc]) => ({
44+
id,
45+
score: 0.85,
46+
metadata: doc.metadata,
47+
}));
48+
return results;
49+
}
50+
51+
async searchByDocumentId(
52+
documentId: string,
53+
options?: { limit?: number }
54+
): Promise<Array<{ id: string; score: number; metadata: Record<string, unknown> }>> {
55+
return this.search(documentId, options);
56+
}
57+
58+
async getAll(options?: {
59+
limit?: number;
60+
}): Promise<Array<{ id: string; score: number; metadata: Record<string, unknown> }>> {
61+
const limit = options?.limit ?? 10000;
62+
return Array.from(docs.entries())
63+
.slice(0, limit)
64+
.map(([id, doc]) => ({
65+
id,
66+
score: 1,
67+
metadata: doc.metadata,
68+
}));
69+
}
70+
71+
async getDocument(
72+
id: string
73+
): Promise<{ id: string; text: string; metadata: Record<string, unknown> } | null> {
74+
const doc = docs.get(id);
75+
if (!doc) return null;
76+
return { id, ...doc };
77+
}
78+
79+
async deleteDocuments(ids: string[]): Promise<void> {
80+
for (const id of ids) {
81+
docs.delete(id);
82+
}
83+
}
84+
85+
async clear(): Promise<void> {
86+
docs.clear();
87+
}
88+
89+
async getStats(): Promise<{
90+
totalDocuments: number;
91+
storageSize: number;
92+
dimension: number;
93+
modelName: string;
94+
}> {
95+
return {
96+
totalDocuments: docs.size,
97+
storageSize: 0,
98+
dimension: 384,
99+
modelName: 'BAAI/bge-small-en-v1.5',
100+
};
101+
}
102+
103+
async optimize(): Promise<void> {
104+
// no-op
105+
}
106+
107+
async close(): Promise<void> {
108+
this.initialized = false;
109+
}
110+
}

packages/core/src/vector/__tests__/embedder.test.ts

Lines changed: 0 additions & 145 deletions
This file was deleted.

0 commit comments

Comments
 (0)