@kanopi/wp-ai-indexer 1.0.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/.circleci/README.md +41 -0
- package/.circleci/config.yml +43 -0
- package/.circleci/install-dependencies.sh +319 -0
- package/.circleci/security-audit-npm.sh +264 -0
- package/.circleci/setup-node.sh +223 -0
- package/.circleci/test-package.sh +247 -0
- package/.eslintrc.js +52 -0
- package/.prettierrc +10 -0
- package/LICENSE +21 -0
- package/README.md +479 -0
- package/bin/wp-ai-indexer.js +25 -0
- package/package.json +71 -0
- package/tests/helpers/test-config.ts +36 -0
- package/tests/mocks/fixtures/settings.json +13 -0
- package/tests/mocks/fixtures/wordpress-posts.json +42 -0
- package/tests/mocks/openai.mock.ts +52 -0
- package/tests/mocks/pinecone.mock.ts +76 -0
- package/tests/setup.ts +20 -0
- package/vitest.config.ts +29 -0
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { vi } from 'vitest';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Mock OpenAI client
|
|
5
|
+
*/
|
|
6
|
+
export const createMockOpenAI = () => {
|
|
7
|
+
return {
|
|
8
|
+
embeddings: {
|
|
9
|
+
create: vi.fn().mockResolvedValue({
|
|
10
|
+
data: [{ embedding: new Array(1536).fill(0.1) }],
|
|
11
|
+
}),
|
|
12
|
+
},
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Mock batch embeddings response
|
|
18
|
+
*/
|
|
19
|
+
export const createMockBatchEmbeddings = (count: number) => {
|
|
20
|
+
return {
|
|
21
|
+
data: Array(count).fill(null).map(() => ({
|
|
22
|
+
embedding: new Array(1536).fill(0.1),
|
|
23
|
+
})),
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Mock rate limit error
|
|
29
|
+
*/
|
|
30
|
+
export const createRateLimitError = () => {
|
|
31
|
+
const error: any = new Error('Rate limit exceeded');
|
|
32
|
+
error.status = 429;
|
|
33
|
+
return error;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Mock server error
|
|
38
|
+
*/
|
|
39
|
+
export const createServerError = () => {
|
|
40
|
+
const error: any = new Error('Internal server error');
|
|
41
|
+
error.status = 500;
|
|
42
|
+
return error;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Mock network error
|
|
47
|
+
*/
|
|
48
|
+
export const createNetworkError = () => {
|
|
49
|
+
const error: any = new Error('Connection reset');
|
|
50
|
+
error.code = 'ECONNRESET';
|
|
51
|
+
return error;
|
|
52
|
+
};
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { vi } from 'vitest';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Mock Pinecone client
|
|
5
|
+
*/
|
|
6
|
+
export const createMockPinecone = () => {
|
|
7
|
+
const mockNamespace = {
|
|
8
|
+
upsert: vi.fn().mockResolvedValue({}),
|
|
9
|
+
deleteMany: vi.fn().mockResolvedValue({}),
|
|
10
|
+
fetch: vi.fn().mockResolvedValue({ records: {} }),
|
|
11
|
+
listPaginated: vi.fn().mockResolvedValue({ vectors: [] }),
|
|
12
|
+
query: vi.fn().mockResolvedValue({ matches: [] }),
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
const mockIndex = {
|
|
16
|
+
namespace: vi.fn().mockReturnValue(mockNamespace),
|
|
17
|
+
describeIndexStats: vi.fn().mockResolvedValue({
|
|
18
|
+
namespaces: {},
|
|
19
|
+
dimension: 1536,
|
|
20
|
+
indexFullness: 0,
|
|
21
|
+
totalVectorCount: 0,
|
|
22
|
+
}),
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
return {
|
|
26
|
+
index: vi.fn().mockReturnValue(mockIndex),
|
|
27
|
+
_mockIndex: mockIndex,
|
|
28
|
+
_mockNamespace: mockNamespace,
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Mock vector data
|
|
34
|
+
*/
|
|
35
|
+
export const createMockVector = (id: string, postId: number, chunkIndex: number) => {
|
|
36
|
+
return {
|
|
37
|
+
id,
|
|
38
|
+
values: new Array(1536).fill(0.1),
|
|
39
|
+
metadata: {
|
|
40
|
+
post_id: postId,
|
|
41
|
+
post_type: 'post',
|
|
42
|
+
title: 'Test Post',
|
|
43
|
+
url: 'https://example.com/test',
|
|
44
|
+
chunk: 'Test content',
|
|
45
|
+
domain: 'example.com',
|
|
46
|
+
schema_version: 1,
|
|
47
|
+
post_date: '2024-01-01',
|
|
48
|
+
post_modified: '2024-01-01',
|
|
49
|
+
author_id: 1,
|
|
50
|
+
chunk_index: chunkIndex,
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Mock list response with pagination
|
|
57
|
+
*/
|
|
58
|
+
export const createMockListResponse = (vectorIds: string[], hasNext: boolean = false) => {
|
|
59
|
+
return {
|
|
60
|
+
vectors: vectorIds.map(id => ({ id })),
|
|
61
|
+
pagination: hasNext ? { next: 'next-token' } : undefined,
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Mock fetch response
|
|
67
|
+
*/
|
|
68
|
+
export const createMockFetchResponse = (vectors: any[]) => {
|
|
69
|
+
const records: Record<string, any> = {};
|
|
70
|
+
|
|
71
|
+
vectors.forEach(vector => {
|
|
72
|
+
records[vector.id] = vector;
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
return { records };
|
|
76
|
+
};
|
package/tests/setup.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { beforeAll, afterAll, afterEach } from 'vitest';
|
|
2
|
+
import nock from 'nock';
|
|
3
|
+
import dotenv from 'dotenv';
|
|
4
|
+
|
|
5
|
+
// Load test environment
|
|
6
|
+
dotenv.config({ path: '.env.test' });
|
|
7
|
+
|
|
8
|
+
// Clean nock after each test
|
|
9
|
+
afterEach(() => {
|
|
10
|
+
nock.cleanAll();
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
// Prevent real HTTP calls
|
|
14
|
+
beforeAll(() => {
|
|
15
|
+
nock.disableNetConnect();
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
afterAll(() => {
|
|
19
|
+
nock.enableNetConnect();
|
|
20
|
+
});
|
package/vitest.config.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { defineConfig } from 'vitest/config';
|
|
2
|
+
|
|
3
|
+
export default defineConfig({
|
|
4
|
+
test: {
|
|
5
|
+
globals: true,
|
|
6
|
+
environment: 'node',
|
|
7
|
+
setupFiles: ['./tests/setup.ts'],
|
|
8
|
+
coverage: {
|
|
9
|
+
provider: 'v8',
|
|
10
|
+
reporter: ['text', 'json', 'html', 'lcov'],
|
|
11
|
+
exclude: [
|
|
12
|
+
'node_modules/',
|
|
13
|
+
'dist/',
|
|
14
|
+
'tests/',
|
|
15
|
+
'**/*.test.ts',
|
|
16
|
+
'**/*.config.ts',
|
|
17
|
+
'bin/',
|
|
18
|
+
],
|
|
19
|
+
thresholds: {
|
|
20
|
+
statements: 80,
|
|
21
|
+
branches: 75,
|
|
22
|
+
functions: 85,
|
|
23
|
+
lines: 80,
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
include: ['tests/**/*.test.ts'],
|
|
27
|
+
testTimeout: 10000,
|
|
28
|
+
},
|
|
29
|
+
});
|