Skip to content

Commit ba4c062

Browse files
committed
Add sources schema and sourceConfig tests
1 parent 33782ea commit ba4c062

2 files changed

Lines changed: 131 additions & 0 deletions

File tree

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import { describe, it, expect, beforeEach } from 'bun:test';
2+
import {
3+
clearConfigCache,
4+
getAvailableSourcesFromConfig,
5+
getBookConfig,
6+
getSourceConfig,
7+
loadSourcesConfig,
8+
} from '../src/utils/sourceConfig';
9+
import { DocumentSource } from '../src/types';
10+
11+
describe('sourceConfig', () => {
12+
beforeEach(() => {
13+
clearConfigCache();
14+
});
15+
16+
it('loads sources.json and exposes known sources', () => {
17+
const config = loadSourcesConfig();
18+
const cairoConfig = config.sources[DocumentSource.CAIRO_BOOK];
19+
20+
expect(cairoConfig).toBeDefined();
21+
expect(cairoConfig.name).toBeTruthy();
22+
expect(cairoConfig.config.fileExtensions).toBeInstanceOf(Array);
23+
});
24+
25+
it('returns per-source config and book config helpers', () => {
26+
const config = loadSourcesConfig();
27+
const sourceConfig = getSourceConfig(DocumentSource.CAIRO_BOOK);
28+
const bookConfig = getBookConfig(DocumentSource.CAIRO_BOOK);
29+
30+
expect(sourceConfig).toEqual(config.sources[DocumentSource.CAIRO_BOOK]);
31+
expect(bookConfig).toEqual(config.sources[DocumentSource.CAIRO_BOOK].config);
32+
});
33+
34+
it('returns all available sources from config', () => {
35+
const sources = getAvailableSourcesFromConfig().slice().sort();
36+
const expected = Object.values(DocumentSource).slice().sort();
37+
38+
expect(sources).toEqual(expected);
39+
});
40+
41+
it('caches config between loads and can be cleared', () => {
42+
const first = loadSourcesConfig();
43+
const second = loadSourcesConfig();
44+
45+
expect(first).toBe(second);
46+
47+
clearConfigCache();
48+
const third = loadSourcesConfig();
49+
50+
expect(third).not.toBe(first);
51+
});
52+
});
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
{
2+
"$schema": "https://json-schema.org/draft-07/schema#",
3+
"title": "Cairo Coder Sources Config",
4+
"type": "object",
5+
"additionalProperties": false,
6+
"required": ["sources"],
7+
"properties": {
8+
"sources": {
9+
"type": "object",
10+
"additionalProperties": {
11+
"$ref": "#/definitions/sourceConfig"
12+
}
13+
}
14+
},
15+
"definitions": {
16+
"sourceConfig": {
17+
"type": "object",
18+
"additionalProperties": false,
19+
"required": ["name", "description", "ingesterClass", "config"],
20+
"properties": {
21+
"name": {
22+
"type": "string"
23+
},
24+
"description": {
25+
"type": "string"
26+
},
27+
"ingesterClass": {
28+
"type": "string"
29+
},
30+
"config": {
31+
"$ref": "#/definitions/bookConfig"
32+
}
33+
}
34+
},
35+
"bookConfig": {
36+
"type": "object",
37+
"additionalProperties": false,
38+
"required": [
39+
"repoOwner",
40+
"repoName",
41+
"fileExtensions",
42+
"chunkSize",
43+
"chunkOverlap",
44+
"baseUrl",
45+
"urlSuffix",
46+
"useUrlMapping"
47+
],
48+
"properties": {
49+
"repoOwner": {
50+
"type": "string"
51+
},
52+
"repoName": {
53+
"type": "string"
54+
},
55+
"fileExtensions": {
56+
"type": "array",
57+
"items": {
58+
"type": "string"
59+
}
60+
},
61+
"chunkSize": {
62+
"type": "integer"
63+
},
64+
"chunkOverlap": {
65+
"type": "integer"
66+
},
67+
"baseUrl": {
68+
"type": "string"
69+
},
70+
"urlSuffix": {
71+
"type": "string"
72+
},
73+
"useUrlMapping": {
74+
"type": "boolean"
75+
}
76+
}
77+
}
78+
}
79+
}

0 commit comments

Comments
 (0)