-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwrapper.test.ts
More file actions
63 lines (53 loc) · 1.97 KB
/
wrapper.test.ts
File metadata and controls
63 lines (53 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import { describe, it } from 'node:test';
import assert from 'node:assert';
import { RequiemWrapper } from './packages/cli/src/db/wrapper';
describe('RequiemWrapper', () => {
it('should intercept calls and attach correlation_id', async () => {
// 1. Setup Mock Client
const mockResponse = {
id: 'chatcmpl-123',
choices: [{ message: { content: 'Hello' } }],
usage: {
prompt_tokens: 10,
completion_tokens: 5,
total_tokens: 15
}
};
const mockClient = {
chat: {
completions: {
create: async (_params: any) => {
return mockResponse;
}
}
}
};
// 2. Initialize Wrapper
const tenantId = 'test-tenant-id';
const wrapper = new RequiemWrapper(mockClient, { tenantId });
// 3. Execute Call
const result = await wrapper.chat.completions.create({
model: 'gpt-4',
messages: [{ role: 'user', content: 'Hi' }]
});
// 4. Verify Interception
assert.ok(result.correlation_id, 'correlation_id should be generated');
assert.strictEqual(typeof result.correlation_id, 'string');
// 5. Verify Metadata
assert.ok(result.requiem_meta, 'requiem_meta should be attached');
assert.strictEqual(result.requiem_meta.tenant_id, tenantId);
assert.strictEqual(result.requiem_meta.verified, true);
assert.ok(result.requiem_meta.latency_ms >= 0, 'latency should be recorded');
// 6. Verify Usage Propagation
assert.deepStrictEqual(result.requiem_meta.usage, mockResponse.usage);
});
it('should handle missing usage in response', async () => {
const mockClient = {
chat: { completions: { create: async () => ({ id: '123' }) } }
};
const wrapper = new RequiemWrapper(mockClient, { tenantId: 'test' });
const result = await wrapper.chat.completions.create({});
assert.ok(result.requiem_meta.usage, 'usage should be defaulted if missing');
assert.strictEqual(result.requiem_meta.usage.total_tokens, 0);
});
});