@ordis-dev/ordis 0.1.1 → 0.4.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/README.md +47 -0
- package/dist/cli.js +20 -4
- package/dist/cli.js.map +1 -1
- package/dist/core/error-formatter.d.ts +35 -0
- package/dist/core/error-formatter.d.ts.map +1 -0
- package/dist/core/error-formatter.js +319 -0
- package/dist/core/error-formatter.js.map +1 -0
- package/dist/core/index.d.ts +3 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +1 -0
- package/dist/core/index.js.map +1 -1
- package/dist/core/pipeline.d.ts.map +1 -1
- package/dist/core/pipeline.js +17 -3
- package/dist/core/pipeline.js.map +1 -1
- package/dist/core/preprocessor.d.ts +35 -0
- package/dist/core/preprocessor.d.ts.map +1 -0
- package/dist/core/preprocessor.js +297 -0
- package/dist/core/preprocessor.js.map +1 -0
- package/dist/core/types.d.ts +24 -1
- package/dist/core/types.d.ts.map +1 -1
- package/dist/core/validator.d.ts +3 -1
- package/dist/core/validator.d.ts.map +1 -1
- package/dist/core/validator.js.map +1 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/llm/client.d.ts.map +1 -1
- package/dist/llm/client.js +23 -3
- package/dist/llm/client.js.map +1 -1
- package/dist/llm/types.d.ts +2 -0
- package/dist/llm/types.d.ts.map +1 -1
- package/dist/schemas/types.d.ts +3 -1
- package/dist/schemas/types.d.ts.map +1 -1
- package/package.json +4 -1
- package/dist/__tests__/api.test.d.ts +0 -5
- package/dist/__tests__/api.test.d.ts.map +0 -1
- package/dist/__tests__/api.test.js +0 -95
- package/dist/__tests__/api.test.js.map +0 -1
- package/dist/__tests__/cli.test.d.ts +0 -6
- package/dist/__tests__/cli.test.d.ts.map +0 -1
- package/dist/__tests__/cli.test.js +0 -103
- package/dist/__tests__/cli.test.js.map +0 -1
- package/dist/cli/__tests__/cli.test.d.ts +0 -5
- package/dist/cli/__tests__/cli.test.d.ts.map +0 -1
- package/dist/cli/__tests__/cli.test.js +0 -13
- package/dist/cli/__tests__/cli.test.js.map +0 -1
- package/dist/core/__tests__/pipeline.test.d.ts +0 -5
- package/dist/core/__tests__/pipeline.test.d.ts.map +0 -1
- package/dist/core/__tests__/pipeline.test.js +0 -334
- package/dist/core/__tests__/pipeline.test.js.map +0 -1
- package/dist/core/__tests__/validator.test.d.ts +0 -5
- package/dist/core/__tests__/validator.test.d.ts.map +0 -1
- package/dist/core/__tests__/validator.test.js +0 -124
- package/dist/core/__tests__/validator.test.js.map +0 -1
- package/dist/llm/__tests__/client.test.d.ts +0 -5
- package/dist/llm/__tests__/client.test.d.ts.map +0 -1
- package/dist/llm/__tests__/client.test.js +0 -350
- package/dist/llm/__tests__/client.test.js.map +0 -1
- package/dist/llm/__tests__/prompt-builder.test.d.ts +0 -5
- package/dist/llm/__tests__/prompt-builder.test.d.ts.map +0 -1
- package/dist/llm/__tests__/prompt-builder.test.js +0 -171
- package/dist/llm/__tests__/prompt-builder.test.js.map +0 -1
- package/dist/llm/__tests__/retry.test.d.ts +0 -5
- package/dist/llm/__tests__/retry.test.d.ts.map +0 -1
- package/dist/llm/__tests__/retry.test.js +0 -350
- package/dist/llm/__tests__/retry.test.js.map +0 -1
- package/dist/llm/__tests__/token-counter.test.d.ts +0 -5
- package/dist/llm/__tests__/token-counter.test.d.ts.map +0 -1
- package/dist/llm/__tests__/token-counter.test.js +0 -166
- package/dist/llm/__tests__/token-counter.test.js.map +0 -1
- package/dist/schemas/__tests__/integration.test.d.ts +0 -5
- package/dist/schemas/__tests__/integration.test.d.ts.map +0 -1
- package/dist/schemas/__tests__/integration.test.js +0 -366
- package/dist/schemas/__tests__/integration.test.js.map +0 -1
- package/dist/schemas/__tests__/loader.test.d.ts +0 -5
- package/dist/schemas/__tests__/loader.test.d.ts.map +0 -1
- package/dist/schemas/__tests__/loader.test.js +0 -271
- package/dist/schemas/__tests__/loader.test.js.map +0 -1
- package/dist/schemas/__tests__/validator.test.d.ts +0 -5
- package/dist/schemas/__tests__/validator.test.d.ts.map +0 -1
- package/dist/schemas/__tests__/validator.test.js +0 -592
- package/dist/schemas/__tests__/validator.test.js.map +0 -1
|
@@ -1,166 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Token counter tests
|
|
3
|
-
*/
|
|
4
|
-
import { describe, test, expect } from 'vitest';
|
|
5
|
-
import { estimateTokens, TokenCounter } from '../token-counter.js';
|
|
6
|
-
describe('estimateTokens', () => {
|
|
7
|
-
test('returns 0 for empty string', () => {
|
|
8
|
-
expect(estimateTokens('')).toBe(0);
|
|
9
|
-
});
|
|
10
|
-
test('estimates tokens using 4 chars per token', () => {
|
|
11
|
-
// 20 characters = 5 tokens
|
|
12
|
-
expect(estimateTokens('12345678901234567890')).toBe(5);
|
|
13
|
-
});
|
|
14
|
-
test('rounds up for partial tokens', () => {
|
|
15
|
-
// 21 characters = 6 tokens (5.25 rounded up)
|
|
16
|
-
expect(estimateTokens('123456789012345678901')).toBe(6);
|
|
17
|
-
});
|
|
18
|
-
test('handles longer text', () => {
|
|
19
|
-
const text = 'The quick brown fox jumps over the lazy dog. '.repeat(10);
|
|
20
|
-
const tokens = estimateTokens(text);
|
|
21
|
-
expect(tokens).toBeGreaterThan(0);
|
|
22
|
-
// 45 chars * 10 = 450 chars = ~113 tokens
|
|
23
|
-
expect(tokens).toBeCloseTo(113, 0);
|
|
24
|
-
});
|
|
25
|
-
});
|
|
26
|
-
describe('TokenCounter', () => {
|
|
27
|
-
describe('calculateUsage', () => {
|
|
28
|
-
test('calculates token usage correctly', () => {
|
|
29
|
-
const counter = new TokenCounter({
|
|
30
|
-
maxContextTokens: 4096,
|
|
31
|
-
tokenBudget: {
|
|
32
|
-
system: 1000,
|
|
33
|
-
input: 2000,
|
|
34
|
-
output: 1000,
|
|
35
|
-
},
|
|
36
|
-
});
|
|
37
|
-
// 400 chars = 100 tokens, 800 chars = 200 tokens
|
|
38
|
-
const system = 'a'.repeat(400);
|
|
39
|
-
const input = 'b'.repeat(800);
|
|
40
|
-
const usage = counter.calculateUsage(system, input);
|
|
41
|
-
expect(usage.systemTokens).toBe(100);
|
|
42
|
-
expect(usage.inputTokens).toBe(200);
|
|
43
|
-
expect(usage.outputTokens).toBe(1000);
|
|
44
|
-
expect(usage.totalTokens).toBe(1300);
|
|
45
|
-
expect(usage.maxContextTokens).toBe(4096);
|
|
46
|
-
expect(usage.usagePercent).toBeCloseTo(31.7, 1);
|
|
47
|
-
});
|
|
48
|
-
test('handles empty strings', () => {
|
|
49
|
-
const counter = new TokenCounter();
|
|
50
|
-
const usage = counter.calculateUsage('', '');
|
|
51
|
-
expect(usage.systemTokens).toBe(0);
|
|
52
|
-
expect(usage.inputTokens).toBe(0);
|
|
53
|
-
expect(usage.totalTokens).toBe(1000); // just output tokens
|
|
54
|
-
});
|
|
55
|
-
});
|
|
56
|
-
describe('exceedsLimit', () => {
|
|
57
|
-
test('returns true when total exceeds max', () => {
|
|
58
|
-
const counter = new TokenCounter({ maxContextTokens: 100 });
|
|
59
|
-
const usage = counter.calculateUsage('a'.repeat(400), 'b'.repeat(400));
|
|
60
|
-
// 100 + 100 + 1000 = 1200 > 100
|
|
61
|
-
expect(counter.exceedsLimit(usage)).toBe(true);
|
|
62
|
-
});
|
|
63
|
-
test('returns false when under limit', () => {
|
|
64
|
-
const counter = new TokenCounter({ maxContextTokens: 4096 });
|
|
65
|
-
const usage = counter.calculateUsage('a'.repeat(400), 'b'.repeat(400));
|
|
66
|
-
// 100 + 100 + 1000 = 1200 < 4096
|
|
67
|
-
expect(counter.exceedsLimit(usage)).toBe(false);
|
|
68
|
-
});
|
|
69
|
-
test('returns false when exactly at limit', () => {
|
|
70
|
-
const counter = new TokenCounter({ maxContextTokens: 1200 });
|
|
71
|
-
const usage = counter.calculateUsage('a'.repeat(400), 'b'.repeat(400));
|
|
72
|
-
// 100 + 100 + 1000 = 1200 === 1200
|
|
73
|
-
expect(counter.exceedsLimit(usage)).toBe(false);
|
|
74
|
-
});
|
|
75
|
-
});
|
|
76
|
-
describe('shouldWarn', () => {
|
|
77
|
-
test('returns true when usage exceeds warn threshold', () => {
|
|
78
|
-
const counter = new TokenCounter({
|
|
79
|
-
maxContextTokens: 1000,
|
|
80
|
-
warnThreshold: 90,
|
|
81
|
-
});
|
|
82
|
-
// 360 + 360 + 1000 = 1720 tokens = 172% (way over)
|
|
83
|
-
const usage = counter.calculateUsage('a'.repeat(1440), 'b'.repeat(1440));
|
|
84
|
-
expect(counter.shouldWarn(usage)).toBe(true);
|
|
85
|
-
});
|
|
86
|
-
test('returns false when under warn threshold', () => {
|
|
87
|
-
const counter = new TokenCounter({
|
|
88
|
-
maxContextTokens: 4096,
|
|
89
|
-
warnThreshold: 90,
|
|
90
|
-
});
|
|
91
|
-
// 100 + 100 + 1000 = 1200 = ~29%
|
|
92
|
-
const usage = counter.calculateUsage('a'.repeat(400), 'b'.repeat(400));
|
|
93
|
-
expect(counter.shouldWarn(usage)).toBe(false);
|
|
94
|
-
});
|
|
95
|
-
test('uses 90% default threshold', () => {
|
|
96
|
-
const counter = new TokenCounter({ maxContextTokens: 1000 });
|
|
97
|
-
// Need 900+ tokens to trigger warning
|
|
98
|
-
// 200 + 200 + 1000 = 1400 = 140%
|
|
99
|
-
const usage = counter.calculateUsage('a'.repeat(800), 'b'.repeat(800));
|
|
100
|
-
expect(counter.shouldWarn(usage)).toBe(true);
|
|
101
|
-
});
|
|
102
|
-
});
|
|
103
|
-
describe('formatUsage', () => {
|
|
104
|
-
test('formats usage information', () => {
|
|
105
|
-
const counter = new TokenCounter({ maxContextTokens: 4096 });
|
|
106
|
-
const usage = counter.calculateUsage('a'.repeat(400), 'b'.repeat(800));
|
|
107
|
-
const formatted = counter.formatUsage(usage);
|
|
108
|
-
expect(formatted).toContain('Token usage:');
|
|
109
|
-
expect(formatted).toContain('1300/4096');
|
|
110
|
-
expect(formatted).toContain('System prompt: 100 tokens');
|
|
111
|
-
expect(formatted).toContain('Input: 200 tokens');
|
|
112
|
-
expect(formatted).toContain('Reserved for output: 1000 tokens');
|
|
113
|
-
});
|
|
114
|
-
});
|
|
115
|
-
describe('getErrorMessage', () => {
|
|
116
|
-
test('provides detailed error message when limit exceeded', () => {
|
|
117
|
-
const counter = new TokenCounter({ maxContextTokens: 1000 });
|
|
118
|
-
const usage = counter.calculateUsage('a'.repeat(1000), 'b'.repeat(2000));
|
|
119
|
-
// 250 + 500 + 1000 = 1750 tokens
|
|
120
|
-
const message = counter.getErrorMessage(usage);
|
|
121
|
-
expect(message).toContain('Token budget exceeded');
|
|
122
|
-
expect(message).toContain('1750/1000');
|
|
123
|
-
expect(message).toContain('750 over limit');
|
|
124
|
-
expect(message).toContain('System prompt: 250 tokens');
|
|
125
|
-
expect(message).toContain('Input: 500 tokens');
|
|
126
|
-
expect(message).toContain('Suggestions:');
|
|
127
|
-
});
|
|
128
|
-
});
|
|
129
|
-
describe('getWarningMessage', () => {
|
|
130
|
-
test('provides warning message when approaching limit', () => {
|
|
131
|
-
const counter = new TokenCounter({ maxContextTokens: 1000 });
|
|
132
|
-
const usage = counter.calculateUsage('a'.repeat(800), 'b'.repeat(800));
|
|
133
|
-
const message = counter.getWarningMessage(usage);
|
|
134
|
-
expect(message).toContain('⚠');
|
|
135
|
-
expect(message).toContain('Approaching token budget limit');
|
|
136
|
-
expect(message).toContain('System:');
|
|
137
|
-
expect(message).toContain('Input:');
|
|
138
|
-
expect(message).toContain('Output:');
|
|
139
|
-
});
|
|
140
|
-
});
|
|
141
|
-
describe('configuration', () => {
|
|
142
|
-
test('uses default values when not specified', () => {
|
|
143
|
-
const counter = new TokenCounter();
|
|
144
|
-
const usage = counter.calculateUsage('', '');
|
|
145
|
-
expect(usage.maxContextTokens).toBe(4096);
|
|
146
|
-
expect(usage.outputTokens).toBe(1000);
|
|
147
|
-
});
|
|
148
|
-
test('respects custom maxContextTokens', () => {
|
|
149
|
-
const counter = new TokenCounter({ maxContextTokens: 8192 });
|
|
150
|
-
const usage = counter.calculateUsage('', '');
|
|
151
|
-
expect(usage.maxContextTokens).toBe(8192);
|
|
152
|
-
});
|
|
153
|
-
test('respects custom token budget', () => {
|
|
154
|
-
const counter = new TokenCounter({
|
|
155
|
-
tokenBudget: {
|
|
156
|
-
system: 500,
|
|
157
|
-
input: 1500,
|
|
158
|
-
output: 2000,
|
|
159
|
-
},
|
|
160
|
-
});
|
|
161
|
-
const usage = counter.calculateUsage('', '');
|
|
162
|
-
expect(usage.outputTokens).toBe(2000);
|
|
163
|
-
});
|
|
164
|
-
});
|
|
165
|
-
});
|
|
166
|
-
//# sourceMappingURL=token-counter.test.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"token-counter.test.js","sourceRoot":"","sources":["../../../src/llm/__tests__/token-counter.test.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChD,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAEnE,QAAQ,CAAC,gBAAgB,EAAE,GAAG,EAAE;IAC5B,IAAI,CAAC,4BAA4B,EAAE,GAAG,EAAE;QACpC,MAAM,CAAC,cAAc,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACvC,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,0CAA0C,EAAE,GAAG,EAAE;QAClD,2BAA2B;QAC3B,MAAM,CAAC,cAAc,CAAC,sBAAsB,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAC3D,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,8BAA8B,EAAE,GAAG,EAAE;QACtC,6CAA6C;QAC7C,MAAM,CAAC,cAAc,CAAC,uBAAuB,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAC5D,CAAC,CAAC,CAAC;I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C,MAAM,OAAO,GAAG,IAAI,YAAY,CAAC,EAAE,gBAAgB,EAAE,IAAI,EAAE,CAAC,CAAC;YAC7D,MAAM,KAAK,GAAG,OAAO,CAAC,cAAc,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;YAE7C,MAAM,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC9C,CAAC,CAAC,CAAC;QAEH,IAAI,CAAC,8BAA8B,EAAE,GAAG,EAAE;YACtC,MAAM,OAAO,GAAG,IAAI,YAAY,CAAC;gBAC7B,WAAW,EAAE;oBACT,MAAM,EAAE,GAAG;oBACX,KAAK,EAAE,IAAI;oBACX,MAAM,EAAE,IAAI;iBACf;aACJ,CAAC,CAAC;YACH,MAAM,KAAK,GAAG,OAAO,CAAC,cAAc,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;YAE7C,MAAM,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC1C,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"integration.test.d.ts","sourceRoot":"","sources":["../../../src/schemas/__tests__/integration.test.ts"],"names":[],"mappings":"AAAA;;GAEG"}
|
|
@@ -1,366 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Integration tests for schema system
|
|
3
|
-
*/
|
|
4
|
-
import { describe, it, expect } from 'vitest';
|
|
5
|
-
import { parseSchema } from '../loader.js';
|
|
6
|
-
import { SchemaValidationError, ErrorCodes } from '../errors.js';
|
|
7
|
-
describe('Schema System Integration', () => {
|
|
8
|
-
describe('End-to-end validation', () => {
|
|
9
|
-
it('should successfully parse and validate complete invoice schema', () => {
|
|
10
|
-
const schemaJson = `{
|
|
11
|
-
"fields": {
|
|
12
|
-
"invoice_id": {
|
|
13
|
-
"type": "string",
|
|
14
|
-
"description": "Unique invoice identifier"
|
|
15
|
-
},
|
|
16
|
-
"amount": {
|
|
17
|
-
"type": "number",
|
|
18
|
-
"description": "Total invoice amount"
|
|
19
|
-
},
|
|
20
|
-
"currency": {
|
|
21
|
-
"type": "enum",
|
|
22
|
-
"enum": ["USD", "SGD", "EUR"],
|
|
23
|
-
"description": "Currency code"
|
|
24
|
-
},
|
|
25
|
-
"date": {
|
|
26
|
-
"type": "date",
|
|
27
|
-
"optional": true,
|
|
28
|
-
"description": "Invoice date"
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
}`;
|
|
32
|
-
const schema = parseSchema(schemaJson);
|
|
33
|
-
expect(schema.fields).toBeDefined();
|
|
34
|
-
expect(Object.keys(schema.fields)).toHaveLength(4);
|
|
35
|
-
expect(schema.fields.invoice_id.type).toBe('string');
|
|
36
|
-
expect(schema.fields.amount.type).toBe('number');
|
|
37
|
-
expect(schema.fields.currency.enum).toEqual(['USD', 'SGD', 'EUR']);
|
|
38
|
-
expect(schema.fields.date.optional).toBe(true);
|
|
39
|
-
});
|
|
40
|
-
it('should catch multiple validation errors in order', () => {
|
|
41
|
-
// Test that validation stops at first error (fail-fast approach)
|
|
42
|
-
const invalidSchemas = [
|
|
43
|
-
'{ "notFields": {} }', // Missing fields
|
|
44
|
-
'{ "fields": {} }', // Empty fields
|
|
45
|
-
'{ "fields": { "": { "type": "string" } } }', // Empty field name
|
|
46
|
-
'{ "fields": { "123": { "type": "string" } } }', // Invalid field name
|
|
47
|
-
'{ "fields": { "name": {} } }', // Missing type
|
|
48
|
-
'{ "fields": { "name": { "type": "invalid" } } }', // Invalid type
|
|
49
|
-
];
|
|
50
|
-
invalidSchemas.forEach((schemaJson) => {
|
|
51
|
-
expect(() => parseSchema(schemaJson)).toThrow(SchemaValidationError);
|
|
52
|
-
});
|
|
53
|
-
});
|
|
54
|
-
it('should validate complex nested constraints', () => {
|
|
55
|
-
const schemaJson = `{
|
|
56
|
-
"fields": {
|
|
57
|
-
"price": {
|
|
58
|
-
"type": "number",
|
|
59
|
-
"min": 0.01,
|
|
60
|
-
"max": 999999.99
|
|
61
|
-
},
|
|
62
|
-
"status": {
|
|
63
|
-
"type": "enum",
|
|
64
|
-
"enum": ["draft", "pending", "approved", "rejected", "archived"]
|
|
65
|
-
},
|
|
66
|
-
"email": {
|
|
67
|
-
"type": "string",
|
|
68
|
-
"pattern": "^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\\\.[a-zA-Z]{2,}$"
|
|
69
|
-
}
|
|
70
|
-
},
|
|
71
|
-
"metadata": {
|
|
72
|
-
"name": "Order Schema",
|
|
73
|
-
"version": "3.1.0",
|
|
74
|
-
"description": "Schema for order processing"
|
|
75
|
-
}
|
|
76
|
-
}`;
|
|
77
|
-
const schema = parseSchema(schemaJson);
|
|
78
|
-
expect(schema.fields.price.min).toBe(0.01);
|
|
79
|
-
expect(schema.fields.price.max).toBe(999999.99);
|
|
80
|
-
expect(schema.fields.status.enum).toHaveLength(5);
|
|
81
|
-
expect(schema.fields.email.pattern).toBeDefined();
|
|
82
|
-
expect(schema.metadata?.version).toBe('3.1.0');
|
|
83
|
-
});
|
|
84
|
-
});
|
|
85
|
-
describe('Error reporting quality', () => {
|
|
86
|
-
it('should provide clear error for missing fields property', () => {
|
|
87
|
-
const schemaJson = '{ "metadata": { "name": "Test" } }';
|
|
88
|
-
try {
|
|
89
|
-
parseSchema(schemaJson);
|
|
90
|
-
expect.fail('Should have thrown');
|
|
91
|
-
}
|
|
92
|
-
catch (error) {
|
|
93
|
-
expect(error).toBeInstanceOf(SchemaValidationError);
|
|
94
|
-
const err = error;
|
|
95
|
-
expect(err.message).toContain('fields');
|
|
96
|
-
expect(err.code).toBe(ErrorCodes.MISSING_FIELDS);
|
|
97
|
-
}
|
|
98
|
-
});
|
|
99
|
-
it('should provide clear error for invalid field type', () => {
|
|
100
|
-
const schemaJson = '{ "fields": { "name": { "type": "text" } } }';
|
|
101
|
-
try {
|
|
102
|
-
parseSchema(schemaJson);
|
|
103
|
-
expect.fail('Should have thrown');
|
|
104
|
-
}
|
|
105
|
-
catch (error) {
|
|
106
|
-
expect(error).toBeInstanceOf(SchemaValidationError);
|
|
107
|
-
const err = error;
|
|
108
|
-
expect(err.message).toContain('invalid type');
|
|
109
|
-
expect(err.message).toContain('text');
|
|
110
|
-
expect(err.field).toBe('name');
|
|
111
|
-
expect(err.code).toBe(ErrorCodes.INVALID_FIELD_TYPE);
|
|
112
|
-
expect(err.details?.validTypes).toEqual(['string', 'number', 'date', 'enum', 'boolean']);
|
|
113
|
-
}
|
|
114
|
-
});
|
|
115
|
-
it('should provide clear error for enum without values', () => {
|
|
116
|
-
const schemaJson = '{ "fields": { "status": { "type": "enum" } } }';
|
|
117
|
-
try {
|
|
118
|
-
parseSchema(schemaJson);
|
|
119
|
-
expect.fail('Should have thrown');
|
|
120
|
-
}
|
|
121
|
-
catch (error) {
|
|
122
|
-
expect(error).toBeInstanceOf(SchemaValidationError);
|
|
123
|
-
const err = error;
|
|
124
|
-
expect(err.message).toContain("must have an 'enum' property");
|
|
125
|
-
expect(err.field).toBe('status');
|
|
126
|
-
expect(err.code).toBe(ErrorCodes.MISSING_ENUM_VALUES);
|
|
127
|
-
}
|
|
128
|
-
});
|
|
129
|
-
it('should provide clear error for constraint mismatch', () => {
|
|
130
|
-
const schemaJson = '{ "fields": { "age": { "type": "number", "min": 100, "max": 50 } } }';
|
|
131
|
-
try {
|
|
132
|
-
parseSchema(schemaJson);
|
|
133
|
-
expect.fail('Should have thrown');
|
|
134
|
-
}
|
|
135
|
-
catch (error) {
|
|
136
|
-
expect(error).toBeInstanceOf(SchemaValidationError);
|
|
137
|
-
const err = error;
|
|
138
|
-
expect(err.message).toContain('cannot be greater than');
|
|
139
|
-
expect(err.field).toBe('age');
|
|
140
|
-
expect(err.code).toBe(ErrorCodes.CONSTRAINT_MISMATCH);
|
|
141
|
-
expect(err.details?.min).toBe(100);
|
|
142
|
-
expect(err.details?.max).toBe(50);
|
|
143
|
-
}
|
|
144
|
-
});
|
|
145
|
-
});
|
|
146
|
-
describe('Realistic use cases', () => {
|
|
147
|
-
it('should handle product catalog schema', () => {
|
|
148
|
-
const schema = parseSchema(`{
|
|
149
|
-
"fields": {
|
|
150
|
-
"sku": {
|
|
151
|
-
"type": "string",
|
|
152
|
-
"pattern": "^[A-Z]{3}-[0-9]{6}$",
|
|
153
|
-
"description": "Stock Keeping Unit"
|
|
154
|
-
},
|
|
155
|
-
"name": {
|
|
156
|
-
"type": "string",
|
|
157
|
-
"description": "Product name"
|
|
158
|
-
},
|
|
159
|
-
"price": {
|
|
160
|
-
"type": "number",
|
|
161
|
-
"min": 0,
|
|
162
|
-
"description": "Price in cents"
|
|
163
|
-
},
|
|
164
|
-
"category": {
|
|
165
|
-
"type": "enum",
|
|
166
|
-
"enum": ["electronics", "clothing", "books", "food"],
|
|
167
|
-
"description": "Product category"
|
|
168
|
-
},
|
|
169
|
-
"in_stock": {
|
|
170
|
-
"type": "enum",
|
|
171
|
-
"enum": ["yes", "no"],
|
|
172
|
-
"description": "Stock availability"
|
|
173
|
-
},
|
|
174
|
-
"discontinued_date": {
|
|
175
|
-
"type": "date",
|
|
176
|
-
"optional": true,
|
|
177
|
-
"description": "Date when product was discontinued"
|
|
178
|
-
}
|
|
179
|
-
},
|
|
180
|
-
"metadata": {
|
|
181
|
-
"name": "Product Catalog",
|
|
182
|
-
"version": "1.0.0"
|
|
183
|
-
}
|
|
184
|
-
}`);
|
|
185
|
-
expect(schema.fields.sku.pattern).toBe('^[A-Z]{3}-[0-9]{6}$');
|
|
186
|
-
expect(schema.fields.category.enum).toHaveLength(4);
|
|
187
|
-
expect(schema.fields.discontinued_date.optional).toBe(true);
|
|
188
|
-
});
|
|
189
|
-
it('should handle event registration schema', () => {
|
|
190
|
-
const schema = parseSchema(`{
|
|
191
|
-
"fields": {
|
|
192
|
-
"event_name": {
|
|
193
|
-
"type": "string"
|
|
194
|
-
},
|
|
195
|
-
"attendee_count": {
|
|
196
|
-
"type": "number",
|
|
197
|
-
"min": 1,
|
|
198
|
-
"max": 10000
|
|
199
|
-
},
|
|
200
|
-
"event_type": {
|
|
201
|
-
"type": "enum",
|
|
202
|
-
"enum": ["conference", "workshop", "webinar", "meetup"]
|
|
203
|
-
},
|
|
204
|
-
"event_date": {
|
|
205
|
-
"type": "date"
|
|
206
|
-
},
|
|
207
|
-
"registration_email": {
|
|
208
|
-
"type": "string",
|
|
209
|
-
"pattern": "^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\\\.[a-zA-Z]{2,}$"
|
|
210
|
-
},
|
|
211
|
-
"notes": {
|
|
212
|
-
"type": "string",
|
|
213
|
-
"optional": true
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
}`);
|
|
217
|
-
expect(schema.fields.attendee_count.min).toBe(1);
|
|
218
|
-
expect(schema.fields.attendee_count.max).toBe(10000);
|
|
219
|
-
expect(schema.fields.event_type.enum).toContain('workshop');
|
|
220
|
-
expect(schema.fields.notes.optional).toBe(true);
|
|
221
|
-
});
|
|
222
|
-
});
|
|
223
|
-
describe('Edge cases', () => {
|
|
224
|
-
it('should handle schema with only one field', () => {
|
|
225
|
-
const schema = parseSchema(`{
|
|
226
|
-
"fields": {
|
|
227
|
-
"id": { "type": "string" }
|
|
228
|
-
}
|
|
229
|
-
}`);
|
|
230
|
-
expect(Object.keys(schema.fields)).toHaveLength(1);
|
|
231
|
-
});
|
|
232
|
-
it('should handle fields with all optional properties', () => {
|
|
233
|
-
const schema = parseSchema(`{
|
|
234
|
-
"fields": {
|
|
235
|
-
"field1": {
|
|
236
|
-
"type": "string",
|
|
237
|
-
"description": "A field",
|
|
238
|
-
"optional": true
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
}`);
|
|
242
|
-
expect(schema.fields.field1.optional).toBe(true);
|
|
243
|
-
expect(schema.fields.field1.description).toBe('A field');
|
|
244
|
-
});
|
|
245
|
-
it('should handle minimal valid schema', () => {
|
|
246
|
-
const schema = parseSchema(`{
|
|
247
|
-
"fields": {
|
|
248
|
-
"x": { "type": "string" }
|
|
249
|
-
}
|
|
250
|
-
}`);
|
|
251
|
-
expect(schema.fields.x.type).toBe('string');
|
|
252
|
-
});
|
|
253
|
-
it('should handle schema with metadata only', () => {
|
|
254
|
-
const schema = parseSchema(`{
|
|
255
|
-
"fields": {
|
|
256
|
-
"id": { "type": "string" }
|
|
257
|
-
},
|
|
258
|
-
"metadata": {
|
|
259
|
-
"name": "Simple Schema"
|
|
260
|
-
}
|
|
261
|
-
}`);
|
|
262
|
-
expect(schema.metadata?.name).toBe('Simple Schema');
|
|
263
|
-
expect(schema.metadata?.version).toBeUndefined();
|
|
264
|
-
expect(schema.metadata?.description).toBeUndefined();
|
|
265
|
-
});
|
|
266
|
-
});
|
|
267
|
-
describe('Confidence Configuration', () => {
|
|
268
|
-
it('should parse schema with strict confidence requirements', () => {
|
|
269
|
-
const schema = parseSchema(`{
|
|
270
|
-
"fields": {
|
|
271
|
-
"transaction_id": { "type": "string" },
|
|
272
|
-
"amount": { "type": "number" }
|
|
273
|
-
},
|
|
274
|
-
"confidence": {
|
|
275
|
-
"threshold": 95,
|
|
276
|
-
"failOnLowConfidence": true
|
|
277
|
-
},
|
|
278
|
-
"metadata": {
|
|
279
|
-
"name": "Financial Transaction",
|
|
280
|
-
"description": "High-confidence extraction for financial data"
|
|
281
|
-
}
|
|
282
|
-
}`);
|
|
283
|
-
expect(schema.confidence?.threshold).toBe(95);
|
|
284
|
-
expect(schema.confidence?.failOnLowConfidence).toBe(true);
|
|
285
|
-
});
|
|
286
|
-
it('should parse schema with permissive confidence settings', () => {
|
|
287
|
-
const schema = parseSchema(`{
|
|
288
|
-
"fields": {
|
|
289
|
-
"title": { "type": "string" },
|
|
290
|
-
"tags": { "type": "string", "optional": true }
|
|
291
|
-
},
|
|
292
|
-
"confidence": {
|
|
293
|
-
"threshold": 60,
|
|
294
|
-
"failOnLowConfidence": false
|
|
295
|
-
}
|
|
296
|
-
}`);
|
|
297
|
-
expect(schema.confidence?.threshold).toBe(60);
|
|
298
|
-
expect(schema.confidence?.failOnLowConfidence).toBe(false);
|
|
299
|
-
});
|
|
300
|
-
it('should allow schema without confidence config', () => {
|
|
301
|
-
const schema = parseSchema(`{
|
|
302
|
-
"fields": {
|
|
303
|
-
"name": { "type": "string" }
|
|
304
|
-
}
|
|
305
|
-
}`);
|
|
306
|
-
expect(schema.confidence).toBeUndefined();
|
|
307
|
-
});
|
|
308
|
-
it('should reject schema with invalid confidence threshold', () => {
|
|
309
|
-
const invalidSchema = `{
|
|
310
|
-
"fields": {
|
|
311
|
-
"name": { "type": "string" }
|
|
312
|
-
},
|
|
313
|
-
"confidence": {
|
|
314
|
-
"threshold": 150,
|
|
315
|
-
"failOnLowConfidence": true
|
|
316
|
-
}
|
|
317
|
-
}`;
|
|
318
|
-
expect(() => parseSchema(invalidSchema)).toThrow(SchemaValidationError);
|
|
319
|
-
expect(() => parseSchema(invalidSchema)).toThrow(/between 0 and 100/);
|
|
320
|
-
});
|
|
321
|
-
it('should reject schema with incomplete confidence config', () => {
|
|
322
|
-
const incompleteSchema = `{
|
|
323
|
-
"fields": {
|
|
324
|
-
"name": { "type": "string" }
|
|
325
|
-
},
|
|
326
|
-
"confidence": {
|
|
327
|
-
"threshold": 80
|
|
328
|
-
}
|
|
329
|
-
}`;
|
|
330
|
-
expect(() => parseSchema(incompleteSchema)).toThrow(SchemaValidationError);
|
|
331
|
-
expect(() => parseSchema(incompleteSchema)).toThrow(/failOnLowConfidence/);
|
|
332
|
-
});
|
|
333
|
-
it('should handle real-world high-stakes schema', () => {
|
|
334
|
-
const schema = parseSchema(`{
|
|
335
|
-
"fields": {
|
|
336
|
-
"invoice_number": {
|
|
337
|
-
"type": "string",
|
|
338
|
-
"pattern": "^INV-[0-9]{6}$"
|
|
339
|
-
},
|
|
340
|
-
"total_amount": {
|
|
341
|
-
"type": "number",
|
|
342
|
-
"min": 0
|
|
343
|
-
},
|
|
344
|
-
"payment_status": {
|
|
345
|
-
"type": "enum",
|
|
346
|
-
"enum": ["paid", "pending", "overdue"]
|
|
347
|
-
}
|
|
348
|
-
},
|
|
349
|
-
"confidence": {
|
|
350
|
-
"threshold": 90,
|
|
351
|
-
"failOnLowConfidence": true
|
|
352
|
-
},
|
|
353
|
-
"metadata": {
|
|
354
|
-
"name": "Invoice Extraction",
|
|
355
|
-
"version": "2.0.0",
|
|
356
|
-
"description": "Requires 90% confidence for automated processing"
|
|
357
|
-
}
|
|
358
|
-
}`);
|
|
359
|
-
expect(schema.fields.invoice_number.pattern).toBeDefined();
|
|
360
|
-
expect(schema.confidence?.threshold).toBe(90);
|
|
361
|
-
expect(schema.confidence?.failOnLowConfidence).toBe(true);
|
|
362
|
-
expect(schema.metadata?.version).toBe('2.0.0');
|
|
363
|
-
});
|
|
364
|
-
});
|
|
365
|
-
});
|
|
366
|
-
//# sourceMappingURL=integration.test.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"integration.test.js","sourceRoot":"","sources":["../../../src/schemas/__tests__/integration.test.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,qBAAqB,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAEjE,QAAQ,CAAC,2BAA2B,EAAE,GAAG,EAAE;IACvC,QAAQ,CAAC,uBAAuB,EAAE,GAAG,EAAE;QACnC,EAAE,CAAC,gEAAgE,EAAE,GAAG,EAAE;YACtE,MAAM,UAAU,GAAG;;;;;;;;;;;;;;;;;;;;;QAqBvB,CAAC;YAEG,MAAM,MAAM,GAAG,WAAW,CAAC,UAAU,CAAC,CAAC;YAEvC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,WAAW,EAAE,CAAC;YACpC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,MA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