stellavault 0.1.0
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/.env.example +12 -0
- package/CLAUDE.md +39 -0
- package/CONTRIBUTING.md +65 -0
- package/LICENSE +21 -0
- package/README.md +182 -0
- package/memory/MEMORY.md +25 -0
- package/package.json +33 -0
- package/packages/cli/bin/ekh.js +2 -0
- package/packages/cli/bin/stellavault.js +2 -0
- package/packages/cli/dist/commands/brief-cmd.d.ts +2 -0
- package/packages/cli/dist/commands/brief-cmd.d.ts.map +1 -0
- package/packages/cli/dist/commands/brief-cmd.js +82 -0
- package/packages/cli/dist/commands/brief-cmd.js.map +1 -0
- package/packages/cli/dist/commands/capture-cmd.d.ts +7 -0
- package/packages/cli/dist/commands/capture-cmd.d.ts.map +1 -0
- package/packages/cli/dist/commands/capture-cmd.js +31 -0
- package/packages/cli/dist/commands/capture-cmd.js.map +1 -0
- package/packages/cli/dist/commands/card-cmd.d.ts +4 -0
- package/packages/cli/dist/commands/card-cmd.d.ts.map +1 -0
- package/packages/cli/dist/commands/card-cmd.js +26 -0
- package/packages/cli/dist/commands/card-cmd.js.map +1 -0
- package/packages/cli/dist/commands/clip-cmd.d.ts +4 -0
- package/packages/cli/dist/commands/clip-cmd.d.ts.map +1 -0
- package/packages/cli/dist/commands/clip-cmd.js +151 -0
- package/packages/cli/dist/commands/clip-cmd.js.map +1 -0
- package/packages/cli/dist/commands/cloud-cmd.d.ts +4 -0
- package/packages/cli/dist/commands/cloud-cmd.d.ts.map +1 -0
- package/packages/cli/dist/commands/cloud-cmd.js +64 -0
- package/packages/cli/dist/commands/cloud-cmd.js.map +1 -0
- package/packages/cli/dist/commands/contradictions-cmd.d.ts +2 -0
- package/packages/cli/dist/commands/contradictions-cmd.d.ts.map +1 -0
- package/packages/cli/dist/commands/contradictions-cmd.js +34 -0
- package/packages/cli/dist/commands/contradictions-cmd.js.map +1 -0
- package/packages/cli/dist/commands/decay-cmd.d.ts +2 -0
- package/packages/cli/dist/commands/decay-cmd.d.ts.map +1 -0
- package/packages/cli/dist/commands/decay-cmd.js +48 -0
- package/packages/cli/dist/commands/decay-cmd.js.map +1 -0
- package/packages/cli/dist/commands/digest-cmd.d.ts +4 -0
- package/packages/cli/dist/commands/digest-cmd.d.ts.map +1 -0
- package/packages/cli/dist/commands/digest-cmd.js +79 -0
- package/packages/cli/dist/commands/digest-cmd.js.map +1 -0
- package/packages/cli/dist/commands/duplicates-cmd.d.ts +4 -0
- package/packages/cli/dist/commands/duplicates-cmd.d.ts.map +1 -0
- package/packages/cli/dist/commands/duplicates-cmd.js +30 -0
- package/packages/cli/dist/commands/duplicates-cmd.js.map +1 -0
- package/packages/cli/dist/commands/federate-cmd.d.ts +5 -0
- package/packages/cli/dist/commands/federate-cmd.d.ts.map +1 -0
- package/packages/cli/dist/commands/federate-cmd.js +217 -0
- package/packages/cli/dist/commands/federate-cmd.js.map +1 -0
- package/packages/cli/dist/commands/gaps-cmd.d.ts +2 -0
- package/packages/cli/dist/commands/gaps-cmd.d.ts.map +1 -0
- package/packages/cli/dist/commands/gaps-cmd.js +33 -0
- package/packages/cli/dist/commands/gaps-cmd.js.map +1 -0
- package/packages/cli/dist/commands/graph-cmd.d.ts +2 -0
- package/packages/cli/dist/commands/graph-cmd.d.ts.map +1 -0
- package/packages/cli/dist/commands/graph-cmd.js +77 -0
- package/packages/cli/dist/commands/graph-cmd.js.map +1 -0
- package/packages/cli/dist/commands/index-cmd.d.ts +2 -0
- package/packages/cli/dist/commands/index-cmd.d.ts.map +1 -0
- package/packages/cli/dist/commands/index-cmd.js +57 -0
- package/packages/cli/dist/commands/index-cmd.js.map +1 -0
- package/packages/cli/dist/commands/init-cmd.d.ts +2 -0
- package/packages/cli/dist/commands/init-cmd.d.ts.map +1 -0
- package/packages/cli/dist/commands/init-cmd.js +123 -0
- package/packages/cli/dist/commands/init-cmd.js.map +1 -0
- package/packages/cli/dist/commands/learn-cmd.d.ts +2 -0
- package/packages/cli/dist/commands/learn-cmd.d.ts.map +1 -0
- package/packages/cli/dist/commands/learn-cmd.js +48 -0
- package/packages/cli/dist/commands/learn-cmd.js.map +1 -0
- package/packages/cli/dist/commands/pack-cmd.d.ts +15 -0
- package/packages/cli/dist/commands/pack-cmd.d.ts.map +1 -0
- package/packages/cli/dist/commands/pack-cmd.js +93 -0
- package/packages/cli/dist/commands/pack-cmd.js.map +1 -0
- package/packages/cli/dist/commands/review-cmd.d.ts +4 -0
- package/packages/cli/dist/commands/review-cmd.d.ts.map +1 -0
- package/packages/cli/dist/commands/review-cmd.js +107 -0
- package/packages/cli/dist/commands/review-cmd.js.map +1 -0
- package/packages/cli/dist/commands/search-cmd.d.ts +4 -0
- package/packages/cli/dist/commands/search-cmd.d.ts.map +1 -0
- package/packages/cli/dist/commands/search-cmd.js +38 -0
- package/packages/cli/dist/commands/search-cmd.js.map +1 -0
- package/packages/cli/dist/commands/serve-cmd.d.ts +2 -0
- package/packages/cli/dist/commands/serve-cmd.d.ts.map +1 -0
- package/packages/cli/dist/commands/serve-cmd.js +14 -0
- package/packages/cli/dist/commands/serve-cmd.js.map +1 -0
- package/packages/cli/dist/commands/status-cmd.d.ts +2 -0
- package/packages/cli/dist/commands/status-cmd.d.ts.map +1 -0
- package/packages/cli/dist/commands/status-cmd.js +33 -0
- package/packages/cli/dist/commands/status-cmd.js.map +1 -0
- package/packages/cli/dist/commands/sync-cmd.d.ts +5 -0
- package/packages/cli/dist/commands/sync-cmd.d.ts.map +1 -0
- package/packages/cli/dist/commands/sync-cmd.js +62 -0
- package/packages/cli/dist/commands/sync-cmd.js.map +1 -0
- package/packages/cli/dist/commands/vault-cmd.d.ts +10 -0
- package/packages/cli/dist/commands/vault-cmd.d.ts.map +1 -0
- package/packages/cli/dist/commands/vault-cmd.js +54 -0
- package/packages/cli/dist/commands/vault-cmd.js.map +1 -0
- package/packages/cli/dist/index.d.ts +2 -0
- package/packages/cli/dist/index.d.ts.map +1 -0
- package/packages/cli/dist/index.js +156 -0
- package/packages/cli/dist/index.js.map +1 -0
- package/packages/cli/package.json +24 -0
- package/packages/cli/src/commands/brief-cmd.ts +87 -0
- package/packages/cli/src/commands/capture-cmd.ts +34 -0
- package/packages/cli/src/commands/card-cmd.ts +29 -0
- package/packages/cli/src/commands/clip-cmd.ts +172 -0
- package/packages/cli/src/commands/cloud-cmd.ts +75 -0
- package/packages/cli/src/commands/contradictions-cmd.ts +41 -0
- package/packages/cli/src/commands/decay-cmd.ts +57 -0
- package/packages/cli/src/commands/digest-cmd.ts +89 -0
- package/packages/cli/src/commands/duplicates-cmd.ts +38 -0
- package/packages/cli/src/commands/federate-cmd.ts +236 -0
- package/packages/cli/src/commands/gaps-cmd.ts +40 -0
- package/packages/cli/src/commands/graph-cmd.ts +88 -0
- package/packages/cli/src/commands/index-cmd.ts +65 -0
- package/packages/cli/src/commands/init-cmd.ts +145 -0
- package/packages/cli/src/commands/learn-cmd.ts +56 -0
- package/packages/cli/src/commands/pack-cmd.ts +121 -0
- package/packages/cli/src/commands/review-cmd.ts +125 -0
- package/packages/cli/src/commands/search-cmd.ts +45 -0
- package/packages/cli/src/commands/serve-cmd.ts +17 -0
- package/packages/cli/src/commands/status-cmd.ts +37 -0
- package/packages/cli/src/commands/sync-cmd.ts +68 -0
- package/packages/cli/src/commands/vault-cmd.ts +64 -0
- package/packages/cli/src/index.ts +187 -0
- package/packages/core/package.json +40 -0
- package/packages/core/src/api/dashboard.ts +138 -0
- package/packages/core/src/api/graph-data.ts +286 -0
- package/packages/core/src/api/pwa.ts +82 -0
- package/packages/core/src/api/server.ts +660 -0
- package/packages/core/src/capture/voice.ts +168 -0
- package/packages/core/src/cloud/index.ts +2 -0
- package/packages/core/src/cloud/sync.ts +167 -0
- package/packages/core/src/config.ts +82 -0
- package/packages/core/src/federation/credits.ts +80 -0
- package/packages/core/src/federation/hyperswarm.d.ts +19 -0
- package/packages/core/src/federation/identity.ts +90 -0
- package/packages/core/src/federation/index.ts +8 -0
- package/packages/core/src/federation/node.ts +235 -0
- package/packages/core/src/federation/privacy.ts +52 -0
- package/packages/core/src/federation/reputation.ts +202 -0
- package/packages/core/src/federation/search.ts +129 -0
- package/packages/core/src/federation/sharing.ts +165 -0
- package/packages/core/src/federation/trust.ts +76 -0
- package/packages/core/src/federation/types.ts +25 -0
- package/packages/core/src/i18n/index.ts +85 -0
- package/packages/core/src/index.ts +133 -0
- package/packages/core/src/indexer/chunker.ts +180 -0
- package/packages/core/src/indexer/embedder.ts +9 -0
- package/packages/core/src/indexer/index.ts +113 -0
- package/packages/core/src/indexer/local-embedder.ts +35 -0
- package/packages/core/src/indexer/scanner.ts +142 -0
- package/packages/core/src/indexer/watcher.ts +62 -0
- package/packages/core/src/intelligence/contradiction-detector.ts +134 -0
- package/packages/core/src/intelligence/decay-engine.ts +229 -0
- package/packages/core/src/intelligence/duplicate-detector.ts +71 -0
- package/packages/core/src/intelligence/fsrs.ts +79 -0
- package/packages/core/src/intelligence/gap-detector.ts +109 -0
- package/packages/core/src/intelligence/learning-path.ts +86 -0
- package/packages/core/src/intelligence/notifications.ts +106 -0
- package/packages/core/src/intelligence/predictive-gaps.ts +94 -0
- package/packages/core/src/intelligence/semantic-versioning.ts +97 -0
- package/packages/core/src/intelligence/types.ts +28 -0
- package/packages/core/src/mcp/custom-tools.ts +97 -0
- package/packages/core/src/mcp/index.ts +1 -0
- package/packages/core/src/mcp/server.ts +142 -0
- package/packages/core/src/mcp/tools/agentic-graph.ts +96 -0
- package/packages/core/src/mcp/tools/brief.ts +49 -0
- package/packages/core/src/mcp/tools/decay.ts +40 -0
- package/packages/core/src/mcp/tools/decision-journal.ts +95 -0
- package/packages/core/src/mcp/tools/export.ts +72 -0
- package/packages/core/src/mcp/tools/federated-search.ts +43 -0
- package/packages/core/src/mcp/tools/generate-claude-md.ts +130 -0
- package/packages/core/src/mcp/tools/get-document.ts +26 -0
- package/packages/core/src/mcp/tools/get-related.ts +41 -0
- package/packages/core/src/mcp/tools/learning-path.ts +52 -0
- package/packages/core/src/mcp/tools/list-topics.ts +20 -0
- package/packages/core/src/mcp/tools/search.ts +35 -0
- package/packages/core/src/mcp/tools/snapshot.ts +98 -0
- package/packages/core/src/multi-vault/index.ts +118 -0
- package/packages/core/src/pack/creator.ts +127 -0
- package/packages/core/src/pack/exporter.ts +21 -0
- package/packages/core/src/pack/importer.ts +82 -0
- package/packages/core/src/pack/index.ts +5 -0
- package/packages/core/src/pack/marketplace.ts +103 -0
- package/packages/core/src/pack/pii-masker.ts +38 -0
- package/packages/core/src/pack/types.ts +39 -0
- package/packages/core/src/plugins/index.ts +100 -0
- package/packages/core/src/plugins/webhooks.ts +110 -0
- package/packages/core/src/search/bm25.ts +16 -0
- package/packages/core/src/search/index.ts +83 -0
- package/packages/core/src/search/rrf.ts +31 -0
- package/packages/core/src/search/semantic.ts +15 -0
- package/packages/core/src/store/index.ts +2 -0
- package/packages/core/src/store/sqlite-vec.ts +290 -0
- package/packages/core/src/store/types.ts +22 -0
- package/packages/core/src/team/index.ts +126 -0
- package/packages/core/src/types/chunk.ts +25 -0
- package/packages/core/src/types/document.ts +24 -0
- package/packages/core/src/types/graph.ts +44 -0
- package/packages/core/src/types/index.ts +15 -0
- package/packages/core/src/types/search.ts +38 -0
- package/packages/core/src/utils/retry.ts +85 -0
- package/packages/core/tests/api-card.test.ts +60 -0
- package/packages/core/tests/api-routes.test.ts +98 -0
- package/packages/core/tests/bm25.test.ts +87 -0
- package/packages/core/tests/chunker.test.ts +48 -0
- package/packages/core/tests/cluster.test.ts +75 -0
- package/packages/core/tests/constellation.test.ts +77 -0
- package/packages/core/tests/export-utils.test.ts +97 -0
- package/packages/core/tests/fsrs.test.ts +96 -0
- package/packages/core/tests/gesture-detector.test.ts +45 -0
- package/packages/core/tests/graph-data.test.ts +87 -0
- package/packages/core/tests/layout.test.ts +83 -0
- package/packages/core/tests/mcp.test.ts +148 -0
- package/packages/core/tests/pack.test.ts +127 -0
- package/packages/core/tests/pii-masker.test.ts +42 -0
- package/packages/core/tests/profile-card.test.ts +62 -0
- package/packages/core/tests/rrf.test.ts +29 -0
- package/packages/core/tests/search-integration.test.ts +139 -0
- package/packages/core/tests/store.test.ts +80 -0
- package/packages/graph/click-result.png +0 -0
- package/packages/graph/index.html +17 -0
- package/packages/graph/package.json +32 -0
- package/packages/graph/src/App.tsx +7 -0
- package/packages/graph/src/api/client.ts +39 -0
- package/packages/graph/src/components/ClusterFilter.tsx +73 -0
- package/packages/graph/src/components/ConstellationView.tsx +232 -0
- package/packages/graph/src/components/ExportPanel.tsx +177 -0
- package/packages/graph/src/components/Graph3D.tsx +230 -0
- package/packages/graph/src/components/GraphEdges.tsx +100 -0
- package/packages/graph/src/components/GraphNodes.tsx +386 -0
- package/packages/graph/src/components/HealthDashboard.tsx +173 -0
- package/packages/graph/src/components/Layout.tsx +214 -0
- package/packages/graph/src/components/MotionOverlay.tsx +81 -0
- package/packages/graph/src/components/MotionToggle.tsx +33 -0
- package/packages/graph/src/components/MultiverseView.tsx +286 -0
- package/packages/graph/src/components/NodeDetail.tsx +232 -0
- package/packages/graph/src/components/PulseParticle.tsx +232 -0
- package/packages/graph/src/components/SearchBar.tsx +107 -0
- package/packages/graph/src/components/StarField.tsx +197 -0
- package/packages/graph/src/components/StatusBar.tsx +53 -0
- package/packages/graph/src/components/Timeline.tsx +148 -0
- package/packages/graph/src/components/ToolsPanel.tsx +512 -0
- package/packages/graph/src/components/Tooltip.tsx +100 -0
- package/packages/graph/src/components/TypeFilter.tsx +131 -0
- package/packages/graph/src/embed/EmbedGraph.tsx +144 -0
- package/packages/graph/src/hooks/useConstellationLOD.ts +76 -0
- package/packages/graph/src/hooks/useDecay.ts +37 -0
- package/packages/graph/src/hooks/useExport.ts +165 -0
- package/packages/graph/src/hooks/useGraph.ts +69 -0
- package/packages/graph/src/hooks/useKeyboardNav.ts +122 -0
- package/packages/graph/src/hooks/useLayout.ts +45 -0
- package/packages/graph/src/hooks/useMotion.ts +120 -0
- package/packages/graph/src/hooks/usePulse.ts +58 -0
- package/packages/graph/src/hooks/useSearch.ts +71 -0
- package/packages/graph/src/lib/constellation.ts +107 -0
- package/packages/graph/src/lib/export-utils.ts +48 -0
- package/packages/graph/src/lib/gesture-detector.ts +123 -0
- package/packages/graph/src/lib/layout.worker.ts +153 -0
- package/packages/graph/src/lib/motion-controller.ts +83 -0
- package/packages/graph/src/lib/profile-card.ts +122 -0
- package/packages/graph/src/main.tsx +4 -0
- package/packages/graph/src/stores/graph-store.ts +155 -0
- package/packages/graph/success.png +0 -0
- package/packages/graph/test-click.mjs +49 -0
- package/packages/graph/test-explore.mjs +102 -0
- package/packages/graph/test-final.mjs +61 -0
- package/packages/graph/test-graph.mjs +139 -0
- package/packages/graph/test-hover.mjs +48 -0
- package/packages/graph/test-pulse.mjs +68 -0
- package/packages/graph/test-screenshot.mjs +56 -0
- package/packages/graph/test-v2.mjs +97 -0
- package/packages/graph/vite.config.ts +15 -0
- package/packages/sync/.env.example +11 -0
- package/packages/sync/.sync-state.json +317 -0
- package/packages/sync/.upload-state.json +1009 -0
- package/packages/sync/create-stella-network-notion.mjs +151 -0
- package/packages/sync/create-stellavault-project-notion.mjs +322 -0
- package/packages/sync/logs/sync-2026-03-28.log +6 -0
- package/packages/sync/logs/sync-2026-03-29.log +12 -0
- package/packages/sync/logs/sync-2026-03-30.log +6 -0
- package/packages/sync/logs/sync-2026-03-31.log +6 -0
- package/packages/sync/logs/sync-2026-04-01.log +6 -0
- package/packages/sync/logs/sync-2026-04-02.log +6 -0
- package/packages/sync/package-lock.json +373 -0
- package/packages/sync/package.json +16 -0
- package/packages/sync/run-sync.bat +18 -0
- package/packages/sync/run-sync.mjs +46 -0
- package/packages/sync/setup-scheduler.mjs +119 -0
- package/packages/sync/structured-sync.mjs +187 -0
- package/packages/sync/sync-to-obsidian.mjs +264 -0
- package/packages/sync/upload-pdca-to-notion.mjs +495 -0
- package/tsconfig.base.json +18 -0
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
import { handleSearch, searchToolDef } from '../src/mcp/tools/search.js';
|
|
3
|
+
import { handleGetDocument, getDocumentToolDef } from '../src/mcp/tools/get-document.js';
|
|
4
|
+
import { handleListTopics, listTopicsToolDef } from '../src/mcp/tools/list-topics.js';
|
|
5
|
+
import { handleGetRelated, getRelatedToolDef } from '../src/mcp/tools/get-related.js';
|
|
6
|
+
import type { VectorStore } from '../src/store/types.js';
|
|
7
|
+
import type { SearchEngine } from '../src/search/index.js';
|
|
8
|
+
import type { Document } from '../src/types/document.js';
|
|
9
|
+
|
|
10
|
+
// Mock data
|
|
11
|
+
const mockDoc: Document = {
|
|
12
|
+
id: 'doc1', filePath: 'test.md', title: 'Test Document',
|
|
13
|
+
content: 'Test content about React patterns',
|
|
14
|
+
frontmatter: { category: 'tech' }, tags: ['react', 'test'],
|
|
15
|
+
lastModified: '2026-01-01', contentHash: 'abc123',
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
function createMockStore(): VectorStore {
|
|
19
|
+
return {
|
|
20
|
+
getDocument: async (id: string) => id === 'doc1' ? mockDoc : null,
|
|
21
|
+
getChunk: async () => null,
|
|
22
|
+
getTopics: async () => [
|
|
23
|
+
{ topic: 'react', count: 5, recentDocuments: [{ id: 'doc1', title: 'Test' }] },
|
|
24
|
+
{ topic: 'security', count: 3, recentDocuments: [] },
|
|
25
|
+
],
|
|
26
|
+
getStats: async () => ({
|
|
27
|
+
documentCount: 10, chunkCount: 50, dbSizeBytes: 1024, lastIndexed: '2026-01-01',
|
|
28
|
+
}),
|
|
29
|
+
initialize: async () => {},
|
|
30
|
+
close: async () => {},
|
|
31
|
+
upsertDocument: async () => {},
|
|
32
|
+
upsertChunks: async () => {},
|
|
33
|
+
deleteByDocumentId: async () => {},
|
|
34
|
+
searchSemantic: async () => [],
|
|
35
|
+
searchKeyword: async () => [],
|
|
36
|
+
getAllDocumentHashes: async () => new Map(),
|
|
37
|
+
} as VectorStore;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function createMockSearchEngine(): SearchEngine {
|
|
41
|
+
return {
|
|
42
|
+
search: async ({ query, limit }) => [{
|
|
43
|
+
chunk: {
|
|
44
|
+
id: 'doc1#0', documentId: 'doc1', content: 'React patterns content',
|
|
45
|
+
heading: 'Patterns', startLine: 1, endLine: 3, tokenCount: 5,
|
|
46
|
+
},
|
|
47
|
+
document: mockDoc,
|
|
48
|
+
score: 0.85,
|
|
49
|
+
highlights: ['React patterns content'],
|
|
50
|
+
}].slice(0, limit ?? 5),
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
describe('MCP Tool Definitions', () => {
|
|
55
|
+
it('search tool schema 유효', () => {
|
|
56
|
+
expect(searchToolDef.name).toBe('search');
|
|
57
|
+
expect(searchToolDef.inputSchema.required).toContain('query');
|
|
58
|
+
expect(searchToolDef.inputSchema.properties.query).toBeDefined();
|
|
59
|
+
expect(searchToolDef.inputSchema.properties.limit).toBeDefined();
|
|
60
|
+
expect(searchToolDef.inputSchema.properties.tags).toBeDefined();
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it('get-document tool schema 유효', () => {
|
|
64
|
+
expect(getDocumentToolDef.name).toBe('get-document');
|
|
65
|
+
expect(getDocumentToolDef.inputSchema.required).toContain('id');
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it('list-topics tool schema 유효', () => {
|
|
69
|
+
expect(listTopicsToolDef.name).toBe('list-topics');
|
|
70
|
+
expect(listTopicsToolDef.inputSchema.properties).toBeDefined();
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it('get-related tool schema 유효', () => {
|
|
74
|
+
expect(getRelatedToolDef.name).toBe('get-related');
|
|
75
|
+
expect(getRelatedToolDef.inputSchema.required).toContain('id');
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
describe('handleSearch', () => {
|
|
80
|
+
it('검색 결과를 올바른 형식으로 반환', async () => {
|
|
81
|
+
const engine = createMockSearchEngine();
|
|
82
|
+
const results = await handleSearch(engine, { query: 'React' });
|
|
83
|
+
|
|
84
|
+
expect(results.length).toBeGreaterThan(0);
|
|
85
|
+
const r = results[0];
|
|
86
|
+
expect(r.title).toBe('Test Document');
|
|
87
|
+
expect(r.filePath).toBe('test.md');
|
|
88
|
+
expect(r.heading).toBe('Patterns');
|
|
89
|
+
expect(r.content).toBe('React patterns content');
|
|
90
|
+
expect(r.score).toBe(0.85);
|
|
91
|
+
expect(r.tags).toEqual(['react', 'test']);
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
it('limit 전달', async () => {
|
|
95
|
+
const engine = createMockSearchEngine();
|
|
96
|
+
const results = await handleSearch(engine, { query: 'React', limit: 1 });
|
|
97
|
+
expect(results.length).toBeLessThanOrEqual(1);
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
describe('handleGetDocument', () => {
|
|
102
|
+
it('존재하는 문서 반환', async () => {
|
|
103
|
+
const store = createMockStore();
|
|
104
|
+
const result = await handleGetDocument(store, { id: 'doc1' });
|
|
105
|
+
|
|
106
|
+
expect(result).not.toHaveProperty('error');
|
|
107
|
+
expect((result as any).title).toBe('Test Document');
|
|
108
|
+
expect((result as any).filePath).toBe('test.md');
|
|
109
|
+
expect((result as any).content).toBe('Test content about React patterns');
|
|
110
|
+
expect((result as any).tags).toEqual(['react', 'test']);
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
it('존재하지 않는 문서는 error 반환', async () => {
|
|
114
|
+
const store = createMockStore();
|
|
115
|
+
const result = await handleGetDocument(store, { id: 'nonexistent' });
|
|
116
|
+
expect(result).toHaveProperty('error');
|
|
117
|
+
});
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
describe('handleListTopics', () => {
|
|
121
|
+
it('토픽 목록과 통계 반환', async () => {
|
|
122
|
+
const store = createMockStore();
|
|
123
|
+
const result = await handleListTopics(store);
|
|
124
|
+
|
|
125
|
+
expect(result.topics).toHaveLength(2);
|
|
126
|
+
expect(result.topics[0].topic).toBe('react');
|
|
127
|
+
expect(result.totalDocuments).toBe(10);
|
|
128
|
+
expect(result.totalChunks).toBe(50);
|
|
129
|
+
});
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
describe('handleGetRelated', () => {
|
|
133
|
+
it('관련 문서 반환 (자기 자신 제외)', async () => {
|
|
134
|
+
const store = createMockStore();
|
|
135
|
+
const engine = createMockSearchEngine();
|
|
136
|
+
const results = await handleGetRelated(store, engine, { id: 'doc1' });
|
|
137
|
+
|
|
138
|
+
// doc1 자체는 필터링되므로 빈 결과 가능
|
|
139
|
+
expect(Array.isArray(results)).toBe(true);
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
it('존재하지 않는 문서 ID는 error 반환', async () => {
|
|
143
|
+
const store = createMockStore();
|
|
144
|
+
const engine = createMockSearchEngine();
|
|
145
|
+
const result = await handleGetRelated(store, engine, { id: 'nonexistent' });
|
|
146
|
+
expect(result).toHaveProperty('error');
|
|
147
|
+
});
|
|
148
|
+
});
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
|
|
2
|
+
import { createSqliteVecStore } from '../src/store/sqlite-vec.js';
|
|
3
|
+
import { createSearchEngine } from '../src/search/index.js';
|
|
4
|
+
import { createPack, exportPack, importPack } from '../src/pack/index.js';
|
|
5
|
+
import type { VectorStore } from '../src/store/types.js';
|
|
6
|
+
import type { Embedder } from '../src/indexer/embedder.js';
|
|
7
|
+
import { join } from 'node:path';
|
|
8
|
+
import { tmpdir } from 'node:os';
|
|
9
|
+
import { existsSync, unlinkSync } from 'node:fs';
|
|
10
|
+
|
|
11
|
+
const DIMS = 4;
|
|
12
|
+
let store: VectorStore;
|
|
13
|
+
let embedder: Embedder;
|
|
14
|
+
|
|
15
|
+
function mockEmbedder(): Embedder {
|
|
16
|
+
return {
|
|
17
|
+
dimensions: DIMS, modelName: 'test-model',
|
|
18
|
+
initialize: async () => {},
|
|
19
|
+
embed: async (text) => {
|
|
20
|
+
const h = text.length;
|
|
21
|
+
return [h % 3 / 3, h % 5 / 5, h % 7 / 7, h % 11 / 11];
|
|
22
|
+
},
|
|
23
|
+
embedBatch: async (texts) => texts.map(t => {
|
|
24
|
+
const h = t.length;
|
|
25
|
+
return [h % 3 / 3, h % 5 / 5, h % 7 / 7, h % 11 / 11];
|
|
26
|
+
}),
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
beforeEach(async () => {
|
|
31
|
+
store = createSqliteVecStore(':memory:', DIMS);
|
|
32
|
+
await store.initialize();
|
|
33
|
+
embedder = mockEmbedder();
|
|
34
|
+
|
|
35
|
+
await store.upsertDocument({
|
|
36
|
+
id: 'doc1', filePath: '08_Patterns/auth.md', title: 'Auth Pattern',
|
|
37
|
+
content: 'OAuth patterns for authentication. Contact admin@test.com',
|
|
38
|
+
frontmatter: {}, tags: ['auth'], lastModified: '2026-01-01', contentHash: 'h1',
|
|
39
|
+
});
|
|
40
|
+
await store.upsertChunks([{
|
|
41
|
+
id: 'doc1#0', documentId: 'doc1',
|
|
42
|
+
content: 'OAuth patterns for authentication. Contact admin@test.com',
|
|
43
|
+
heading: 'Auth Pattern', startLine: 1, endLine: 1, tokenCount: 8,
|
|
44
|
+
embedding: [0.5, 0.5, 0.5, 0.5],
|
|
45
|
+
}]);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
afterEach(async () => { await store.close(); });
|
|
49
|
+
|
|
50
|
+
describe('Knowledge Pack', () => {
|
|
51
|
+
it('검색 기반 팩 생성', async () => {
|
|
52
|
+
const searchEngine = createSearchEngine({ store, embedder });
|
|
53
|
+
const { pack, piiReport } = await createPack(store, searchEngine, embedder, {
|
|
54
|
+
name: 'auth-patterns',
|
|
55
|
+
fromSearch: 'OAuth',
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
expect(pack.name).toBe('auth-patterns');
|
|
59
|
+
expect(pack.chunks.length).toBeGreaterThan(0);
|
|
60
|
+
expect(pack.embeddingModel).toBe('test-model');
|
|
61
|
+
expect(pack.schemaVersion).toBe('1.0');
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it('PII 자동 마스킹', async () => {
|
|
65
|
+
const searchEngine = createSearchEngine({ store, embedder });
|
|
66
|
+
const { pack, piiReport } = await createPack(store, searchEngine, embedder, {
|
|
67
|
+
name: 'test-pii',
|
|
68
|
+
fromSearch: 'OAuth',
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
// 이메일이 마스킹되어야 함
|
|
72
|
+
for (const chunk of pack.chunks) {
|
|
73
|
+
expect(chunk.content).not.toContain('admin@test.com');
|
|
74
|
+
}
|
|
75
|
+
expect(piiReport.redactedCount).toBeGreaterThan(0);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it('내보내기 + 가져오기 라운드트립', async () => {
|
|
79
|
+
const searchEngine = createSearchEngine({ store, embedder });
|
|
80
|
+
const { pack } = await createPack(store, searchEngine, embedder, {
|
|
81
|
+
name: 'roundtrip-test',
|
|
82
|
+
fromSearch: 'OAuth',
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
const tmpPath = join(tmpdir(), 'test-roundtrip.sv-pack');
|
|
86
|
+
exportPack(pack, tmpPath);
|
|
87
|
+
expect(existsSync(tmpPath)).toBe(true);
|
|
88
|
+
|
|
89
|
+
// 새 store에 import
|
|
90
|
+
const store2 = createSqliteVecStore(':memory:', DIMS);
|
|
91
|
+
await store2.initialize();
|
|
92
|
+
|
|
93
|
+
const result = await importPack(store2, embedder, tmpPath);
|
|
94
|
+
expect(result.imported).toBeGreaterThan(0);
|
|
95
|
+
expect(result.modelMismatch).toBe(false);
|
|
96
|
+
|
|
97
|
+
// import된 청크 검색 가능
|
|
98
|
+
const stats = await store2.getStats();
|
|
99
|
+
expect(stats.chunkCount).toBeGreaterThan(0);
|
|
100
|
+
|
|
101
|
+
await store2.close();
|
|
102
|
+
try { unlinkSync(tmpPath); } catch {}
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
it('모델 불일치 시 재임베딩', async () => {
|
|
106
|
+
const searchEngine = createSearchEngine({ store, embedder });
|
|
107
|
+
const { pack } = await createPack(store, searchEngine, embedder, {
|
|
108
|
+
name: 'mismatch-test',
|
|
109
|
+
fromSearch: 'OAuth',
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
const tmpPath = join(tmpdir(), 'test-mismatch.sv-pack');
|
|
113
|
+
exportPack(pack, tmpPath);
|
|
114
|
+
|
|
115
|
+
// 다른 모델명의 embedder로 import
|
|
116
|
+
const otherEmbedder = { ...mockEmbedder(), modelName: 'other-model' };
|
|
117
|
+
const store2 = createSqliteVecStore(':memory:', DIMS);
|
|
118
|
+
await store2.initialize();
|
|
119
|
+
|
|
120
|
+
const result = await importPack(store2, otherEmbedder, tmpPath);
|
|
121
|
+
expect(result.modelMismatch).toBe(true);
|
|
122
|
+
expect(result.reEmbedded).toBeGreaterThan(0);
|
|
123
|
+
|
|
124
|
+
await store2.close();
|
|
125
|
+
try { unlinkSync(tmpPath); } catch {}
|
|
126
|
+
});
|
|
127
|
+
});
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
import { maskPII } from '../src/pack/pii-masker.js';
|
|
3
|
+
|
|
4
|
+
describe('PII Masker', () => {
|
|
5
|
+
it('이메일 마스킹', () => {
|
|
6
|
+
const { masked, redactedCount } = maskPII('Contact user@example.com for help');
|
|
7
|
+
expect(masked).not.toContain('user@example.com');
|
|
8
|
+
expect(masked).toContain('[REDACTED:email]');
|
|
9
|
+
expect(redactedCount).toBe(1);
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
it('API 키 마스킹', () => {
|
|
13
|
+
const { masked } = maskPII('Use sk_live_1234567890abcdefghij for auth');
|
|
14
|
+
expect(masked).toContain('[REDACTED:api_key]');
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it('AWS 키 마스킹', () => {
|
|
18
|
+
const { masked } = maskPII('AWS key: AKIAIOSFODNN7EXAMPLE');
|
|
19
|
+
expect(masked).toContain('[REDACTED:aws_key]');
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it('JWT 마스킹', () => {
|
|
23
|
+
const { masked } = maskPII('token: eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIxMjM0NTY3ODkwIn0.dozjgNryP4J3jVmNHl0w5N_XgL0n3I9PlFUP0THsR8U');
|
|
24
|
+
expect(masked).toContain('[REDACTED:jwt]');
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it('PII 없으면 변경 없음', () => {
|
|
28
|
+
const text = 'React 컴포넌트 패턴에 대한 가이드';
|
|
29
|
+
const { masked, redactedCount } = maskPII(text);
|
|
30
|
+
expect(masked).toBe(text);
|
|
31
|
+
expect(redactedCount).toBe(0);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it('복수 PII 동시 마스킹', () => {
|
|
35
|
+
const { masked, redactedCount, redactedTypes } = maskPII(
|
|
36
|
+
'admin@test.com has key sk_test_abcdefghijklmnopqrstuvwxyz1234'
|
|
37
|
+
);
|
|
38
|
+
expect(redactedCount).toBeGreaterThanOrEqual(2);
|
|
39
|
+
expect(redactedTypes).toContain('email');
|
|
40
|
+
expect(redactedTypes).toContain('api_key');
|
|
41
|
+
});
|
|
42
|
+
});
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
|
|
3
|
+
// profile-card SVG 생성 로직 검증
|
|
4
|
+
// 실제 함수는 graph 패키지이므로 SVG 구조 검증용 단위 테스트
|
|
5
|
+
|
|
6
|
+
function generateSimpleSVG(data: {
|
|
7
|
+
documentCount: number;
|
|
8
|
+
clusterCount: number;
|
|
9
|
+
edgeCount: number;
|
|
10
|
+
clusters: Array<{ label: string; nodeCount: number; color: string }>;
|
|
11
|
+
tags: Array<{ tag: string; count: number }>;
|
|
12
|
+
}): string {
|
|
13
|
+
const W = 800, H = 420;
|
|
14
|
+
const esc = (s: string) => s.replace(/&/g, '&').replace(/</g, '<');
|
|
15
|
+
return `<svg xmlns="http://www.w3.org/2000/svg" width="${W}" height="${H}">
|
|
16
|
+
<text>${data.documentCount} docs</text>
|
|
17
|
+
${data.clusters.map(c => `<circle fill="${c.color}"/>`).join('')}
|
|
18
|
+
${data.tags.map(t => `<text>#${esc(t.tag)}</text>`).join('')}
|
|
19
|
+
</svg>`;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
describe('Profile Card SVG', () => {
|
|
23
|
+
it('유효한 SVG 생성', () => {
|
|
24
|
+
const svg = generateSimpleSVG({
|
|
25
|
+
documentCount: 100, clusterCount: 5, edgeCount: 200,
|
|
26
|
+
clusters: [{ label: 'AI', nodeCount: 50, color: '#6366f1' }],
|
|
27
|
+
tags: [{ tag: 'react', count: 10 }],
|
|
28
|
+
});
|
|
29
|
+
expect(svg).toContain('<svg');
|
|
30
|
+
expect(svg).toContain('100 docs');
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it('클러스터 컬러 포함', () => {
|
|
34
|
+
const svg = generateSimpleSVG({
|
|
35
|
+
documentCount: 10, clusterCount: 2, edgeCount: 5,
|
|
36
|
+
clusters: [
|
|
37
|
+
{ label: 'A', nodeCount: 5, color: '#ff0000' },
|
|
38
|
+
{ label: 'B', nodeCount: 5, color: '#00ff00' },
|
|
39
|
+
],
|
|
40
|
+
tags: [],
|
|
41
|
+
});
|
|
42
|
+
expect(svg).toContain('#ff0000');
|
|
43
|
+
expect(svg).toContain('#00ff00');
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it('태그 이스케이프', () => {
|
|
47
|
+
const svg = generateSimpleSVG({
|
|
48
|
+
documentCount: 1, clusterCount: 1, edgeCount: 0,
|
|
49
|
+
clusters: [], tags: [{ tag: '<script>', count: 1 }],
|
|
50
|
+
});
|
|
51
|
+
expect(svg).not.toContain('<script>');
|
|
52
|
+
expect(svg).toContain('<script');
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it('빈 데이터도 에러 없이 생성', () => {
|
|
56
|
+
const svg = generateSimpleSVG({
|
|
57
|
+
documentCount: 0, clusterCount: 0, edgeCount: 0,
|
|
58
|
+
clusters: [], tags: [],
|
|
59
|
+
});
|
|
60
|
+
expect(svg).toContain('<svg');
|
|
61
|
+
});
|
|
62
|
+
});
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
import { rrfFusion } from '../src/search/rrf.js';
|
|
3
|
+
|
|
4
|
+
describe('rrfFusion', () => {
|
|
5
|
+
it('양쪽 리스트에 있는 항목이 상위', () => {
|
|
6
|
+
const listA = [{ chunkId: 'a', score: 0.9 }, { chunkId: 'b', score: 0.8 }];
|
|
7
|
+
const listB = [{ chunkId: 'b', score: 0.95 }, { chunkId: 'c', score: 0.7 }];
|
|
8
|
+
const result = rrfFusion(listA, listB, 60, 10);
|
|
9
|
+
expect(result[0].chunkId).toBe('b'); // 양쪽 모두 등장
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
it('limit 적용', () => {
|
|
13
|
+
const listA = [{ chunkId: 'a', score: 1 }, { chunkId: 'b', score: 0.9 }, { chunkId: 'c', score: 0.8 }];
|
|
14
|
+
const result = rrfFusion(listA, [], 60, 2);
|
|
15
|
+
expect(result.length).toBe(2);
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it('빈 리스트 처리', () => {
|
|
19
|
+
const result = rrfFusion([], [], 60, 10);
|
|
20
|
+
expect(result).toEqual([]);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it('k 값에 따라 점수 변동', () => {
|
|
24
|
+
const list = [{ chunkId: 'a', score: 1 }];
|
|
25
|
+
const r1 = rrfFusion(list, [], 10, 10); // 1/(10+1) = 0.0909
|
|
26
|
+
const r2 = rrfFusion(list, [], 60, 10); // 1/(60+1) = 0.0164
|
|
27
|
+
expect(r1[0].score).toBeGreaterThan(r2[0].score);
|
|
28
|
+
});
|
|
29
|
+
});
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
|
|
2
|
+
import { createSqliteVecStore } from '../src/store/sqlite-vec.js';
|
|
3
|
+
import { createSearchEngine } from '../src/search/index.js';
|
|
4
|
+
import type { VectorStore } from '../src/store/types.js';
|
|
5
|
+
import type { Embedder } from '../src/indexer/embedder.js';
|
|
6
|
+
|
|
7
|
+
const DIMS = 4;
|
|
8
|
+
|
|
9
|
+
// 고정 벡터를 반환하는 테스트용 embedder
|
|
10
|
+
function createMockEmbedder(): Embedder {
|
|
11
|
+
return {
|
|
12
|
+
modelName: 'test-mock',
|
|
13
|
+
dimensions: DIMS,
|
|
14
|
+
embed: async (text: string) => {
|
|
15
|
+
// 간단한 결정적 벡터 생성: 텍스트 길이 기반
|
|
16
|
+
const len = text.length;
|
|
17
|
+
return [len % 3 / 3, len % 5 / 5, len % 7 / 7, len % 11 / 11];
|
|
18
|
+
},
|
|
19
|
+
embedBatch: async (texts: string[]) => {
|
|
20
|
+
return Promise.all(texts.map(t => {
|
|
21
|
+
const len = t.length;
|
|
22
|
+
return [len % 3 / 3, len % 5 / 5, len % 7 / 7, len % 11 / 11];
|
|
23
|
+
}));
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
let store: VectorStore;
|
|
29
|
+
let embedder: Embedder;
|
|
30
|
+
|
|
31
|
+
beforeEach(async () => {
|
|
32
|
+
store = createSqliteVecStore(':memory:', DIMS);
|
|
33
|
+
await store.initialize();
|
|
34
|
+
embedder = createMockEmbedder();
|
|
35
|
+
|
|
36
|
+
// 테스트 문서 3개 삽입
|
|
37
|
+
await store.upsertDocument({
|
|
38
|
+
id: 'doc-react', filePath: 'react-patterns.md', title: 'React 상태관리 패턴',
|
|
39
|
+
content: 'React 상태관리 패턴에 대한 종합 가이드', frontmatter: {},
|
|
40
|
+
tags: ['react', 'frontend'], lastModified: '2026-01-01', contentHash: 'r1',
|
|
41
|
+
});
|
|
42
|
+
await store.upsertChunks([{
|
|
43
|
+
id: 'doc-react#0', documentId: 'doc-react',
|
|
44
|
+
content: 'React useState useReducer 패턴 비교 분석',
|
|
45
|
+
heading: 'React 상태관리', startLine: 1, endLine: 5, tokenCount: 10,
|
|
46
|
+
embedding: [0.9, 0.1, 0.2, 0.1],
|
|
47
|
+
}]);
|
|
48
|
+
|
|
49
|
+
await store.upsertDocument({
|
|
50
|
+
id: 'doc-auth', filePath: 'auth-design.md', title: 'OAuth 인증 설계',
|
|
51
|
+
content: 'OAuth 2.0 인증 흐름 설계 문서', frontmatter: {},
|
|
52
|
+
tags: ['auth', 'security'], lastModified: '2026-01-02', contentHash: 'a1',
|
|
53
|
+
});
|
|
54
|
+
await store.upsertChunks([{
|
|
55
|
+
id: 'doc-auth#0', documentId: 'doc-auth',
|
|
56
|
+
content: 'OAuth 2.0 Authorization Code Flow with PKCE',
|
|
57
|
+
heading: 'OAuth 인증', startLine: 1, endLine: 5, tokenCount: 8,
|
|
58
|
+
embedding: [0.1, 0.9, 0.1, 0.2],
|
|
59
|
+
}]);
|
|
60
|
+
|
|
61
|
+
await store.upsertDocument({
|
|
62
|
+
id: 'doc-deploy', filePath: 'deploy-lessons.md', title: '배포 실패 교훈',
|
|
63
|
+
content: '프로덕션 배포 중 발생한 장애 회고', frontmatter: {},
|
|
64
|
+
tags: ['devops', 'lessons'], lastModified: '2026-01-03', contentHash: 'd1',
|
|
65
|
+
});
|
|
66
|
+
await store.upsertChunks([{
|
|
67
|
+
id: 'doc-deploy#0', documentId: 'doc-deploy',
|
|
68
|
+
content: '배포 실패 롤백 전략과 카나리 배포 교훈',
|
|
69
|
+
heading: '배포 교훈', startLine: 1, endLine: 5, tokenCount: 12,
|
|
70
|
+
embedding: [0.2, 0.1, 0.9, 0.1],
|
|
71
|
+
}]);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
afterEach(async () => {
|
|
75
|
+
await store.close();
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
describe('Search Integration (BM25 + Semantic + RRF)', () => {
|
|
79
|
+
it('자연어 쿼리로 결과 반환', async () => {
|
|
80
|
+
const engine = createSearchEngine({ store, embedder });
|
|
81
|
+
const results = await engine.search({ query: 'React 상태관리', limit: 5 });
|
|
82
|
+
|
|
83
|
+
expect(results.length).toBeGreaterThan(0);
|
|
84
|
+
// 각 결과에 필수 필드 존재
|
|
85
|
+
for (const r of results) {
|
|
86
|
+
expect(r.chunk).toBeDefined();
|
|
87
|
+
expect(r.document).toBeDefined();
|
|
88
|
+
expect(r.score).toBeGreaterThan(0);
|
|
89
|
+
expect(r.highlights).toBeDefined();
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it('태그 필터링 동작', async () => {
|
|
94
|
+
const engine = createSearchEngine({ store, embedder });
|
|
95
|
+
const results = await engine.search({
|
|
96
|
+
query: 'React 상태관리 OAuth 배포',
|
|
97
|
+
limit: 10,
|
|
98
|
+
tags: ['auth'],
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
// auth 태그가 있는 문서만 반환
|
|
102
|
+
for (const r of results) {
|
|
103
|
+
expect(r.document.tags).toContain('auth');
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it('limit 제한 동작', async () => {
|
|
108
|
+
const engine = createSearchEngine({ store, embedder });
|
|
109
|
+
const results = await engine.search({ query: 'React OAuth 배포', limit: 1 });
|
|
110
|
+
expect(results.length).toBeLessThanOrEqual(1);
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
it('빈 쿼리도 에러 없이 처리', async () => {
|
|
114
|
+
const engine = createSearchEngine({ store, embedder });
|
|
115
|
+
const results = await engine.search({ query: '', limit: 5 });
|
|
116
|
+
expect(Array.isArray(results)).toBe(true);
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
it('결과에 highlights 포함', async () => {
|
|
120
|
+
const engine = createSearchEngine({ store, embedder });
|
|
121
|
+
const results = await engine.search({ query: 'React', limit: 5 });
|
|
122
|
+
|
|
123
|
+
const withHighlights = results.filter(r => r.highlights.length > 0);
|
|
124
|
+
// BM25가 매칭하면 highlights가 있어야 함
|
|
125
|
+
if (results.length > 0) {
|
|
126
|
+
expect(withHighlights.length).toBeGreaterThanOrEqual(0);
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
it('존재하지 않는 태그 필터 시 빈 결과', async () => {
|
|
131
|
+
const engine = createSearchEngine({ store, embedder });
|
|
132
|
+
const results = await engine.search({
|
|
133
|
+
query: 'React',
|
|
134
|
+
limit: 10,
|
|
135
|
+
tags: ['nonexistent-tag'],
|
|
136
|
+
});
|
|
137
|
+
expect(results).toEqual([]);
|
|
138
|
+
});
|
|
139
|
+
});
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
|
|
2
|
+
import { createSqliteVecStore } from '../src/store/sqlite-vec.js';
|
|
3
|
+
import type { VectorStore } from '../src/store/types.js';
|
|
4
|
+
|
|
5
|
+
let store: VectorStore;
|
|
6
|
+
|
|
7
|
+
beforeEach(async () => {
|
|
8
|
+
store = createSqliteVecStore(':memory:', 4); // 4차원 (테스트용)
|
|
9
|
+
await store.initialize();
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
afterEach(async () => {
|
|
13
|
+
await store.close();
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
describe('VectorStore', () => {
|
|
17
|
+
it('초기 상태 비어있음', async () => {
|
|
18
|
+
const stats = await store.getStats();
|
|
19
|
+
expect(stats.documentCount).toBe(0);
|
|
20
|
+
expect(stats.chunkCount).toBe(0);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it('document + chunk upsert 및 조회', async () => {
|
|
24
|
+
await store.upsertDocument({
|
|
25
|
+
id: 'doc1', filePath: 'test.md', title: 'Test', content: 'Hello',
|
|
26
|
+
frontmatter: {}, tags: ['test'], lastModified: '2026-01-01', contentHash: 'abc',
|
|
27
|
+
});
|
|
28
|
+
await store.upsertChunks([{
|
|
29
|
+
id: 'doc1#0', documentId: 'doc1', content: 'Hello world',
|
|
30
|
+
heading: 'Test', startLine: 1, endLine: 2, tokenCount: 3,
|
|
31
|
+
embedding: [0.1, 0.2, 0.3, 0.4],
|
|
32
|
+
}]);
|
|
33
|
+
|
|
34
|
+
const doc = await store.getDocument('doc1');
|
|
35
|
+
expect(doc).not.toBeNull();
|
|
36
|
+
expect(doc!.title).toBe('Test');
|
|
37
|
+
|
|
38
|
+
const chunk = await store.getChunk('doc1#0');
|
|
39
|
+
expect(chunk).not.toBeNull();
|
|
40
|
+
expect(chunk!.content).toBe('Hello world');
|
|
41
|
+
|
|
42
|
+
const stats = await store.getStats();
|
|
43
|
+
expect(stats.documentCount).toBe(1);
|
|
44
|
+
expect(stats.chunkCount).toBe(1);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it('semantic search', async () => {
|
|
48
|
+
await store.upsertDocument({
|
|
49
|
+
id: 'doc1', filePath: 'a.md', title: 'A', content: 'A',
|
|
50
|
+
frontmatter: {}, tags: [], lastModified: '2026-01-01', contentHash: 'a',
|
|
51
|
+
});
|
|
52
|
+
await store.upsertChunks([{
|
|
53
|
+
id: 'doc1#0', documentId: 'doc1', content: 'Content A',
|
|
54
|
+
heading: 'A', startLine: 1, endLine: 1, tokenCount: 2,
|
|
55
|
+
embedding: [1.0, 0.0, 0.0, 0.0],
|
|
56
|
+
}]);
|
|
57
|
+
|
|
58
|
+
const results = await store.searchSemantic([1.0, 0.0, 0.0, 0.0], 5);
|
|
59
|
+
expect(results.length).toBe(1);
|
|
60
|
+
expect(results[0].chunkId).toBe('doc1#0');
|
|
61
|
+
expect(results[0].score).toBeGreaterThan(0);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it('deleteByDocumentId', async () => {
|
|
65
|
+
await store.upsertDocument({
|
|
66
|
+
id: 'doc1', filePath: 'a.md', title: 'A', content: 'A',
|
|
67
|
+
frontmatter: {}, tags: [], lastModified: '2026-01-01', contentHash: 'a',
|
|
68
|
+
});
|
|
69
|
+
await store.upsertChunks([{
|
|
70
|
+
id: 'doc1#0', documentId: 'doc1', content: 'Content',
|
|
71
|
+
heading: 'A', startLine: 1, endLine: 1, tokenCount: 1,
|
|
72
|
+
embedding: [0.1, 0.2, 0.3, 0.4],
|
|
73
|
+
}]);
|
|
74
|
+
|
|
75
|
+
await store.deleteByDocumentId('doc1');
|
|
76
|
+
expect(await store.getDocument('doc1')).toBeNull();
|
|
77
|
+
const stats = await store.getStats();
|
|
78
|
+
expect(stats.chunkCount).toBe(0);
|
|
79
|
+
});
|
|
80
|
+
});
|
|
Binary file
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="ko">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8" />
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
6
|
+
<title>Evan Knowledge Hub — 3D Knowledge Graph</title>
|
|
7
|
+
<style>
|
|
8
|
+
* { margin: 0; padding: 0; box-sizing: border-box; }
|
|
9
|
+
html, body, #root { width: 100%; height: 100%; overflow: hidden; }
|
|
10
|
+
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; background: #0a0a0f; color: #e0e0e0; }
|
|
11
|
+
</style>
|
|
12
|
+
</head>
|
|
13
|
+
<body>
|
|
14
|
+
<div id="root"></div>
|
|
15
|
+
<script type="module" src="/src/main.tsx"></script>
|
|
16
|
+
</body>
|
|
17
|
+
</html>
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@stellavault/graph",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Stellavault — 3D Neural Knowledge Graph Visualization",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"private": true,
|
|
7
|
+
"scripts": {
|
|
8
|
+
"dev": "vite",
|
|
9
|
+
"build": "tsc -b && vite build",
|
|
10
|
+
"preview": "vite preview"
|
|
11
|
+
},
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"@mediapipe/camera_utils": "^0.3.1675466862",
|
|
14
|
+
"@mediapipe/drawing_utils": "^0.3.1675466124",
|
|
15
|
+
"@mediapipe/hands": "^0.4.1675469240",
|
|
16
|
+
"@react-three/drei": "^10.0.0",
|
|
17
|
+
"@react-three/fiber": "^9.0.0",
|
|
18
|
+
"react": "^19.0.0",
|
|
19
|
+
"react-dom": "^19.0.0",
|
|
20
|
+
"react-markdown": "^10.0.0",
|
|
21
|
+
"three": "^0.170.0",
|
|
22
|
+
"zustand": "^5.0.0"
|
|
23
|
+
},
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"@types/react": "^19.0.0",
|
|
26
|
+
"@types/react-dom": "^19.0.0",
|
|
27
|
+
"@types/three": "^0.170.0",
|
|
28
|
+
"@vitejs/plugin-react": "^4.0.0",
|
|
29
|
+
"typescript": "^5.7.0",
|
|
30
|
+
"vite": "^6.0.0"
|
|
31
|
+
}
|
|
32
|
+
}
|