Skip to content

Commit 55be7b1

Browse files
committed
fix tests
1 parent 28c57d6 commit 55be7b1

File tree

1 file changed

+31
-22
lines changed

1 file changed

+31
-22
lines changed

packages/sdk/server-ai/__tests__/LDAIClientImpl.test.ts

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -21,27 +21,21 @@ it('returns config with interpolated messagess', async () => {
2121
const key = 'test-flag';
2222
const defaultValue: LDAIDefaults = {
2323
model: { name: 'test', parameters: { name: 'test-model' } },
24-
messages: [{ role: 'system', content: 'Hello {{name}}' }],
24+
messages: [],
2525
enabled: true,
2626
};
2727

2828
const mockVariation = {
2929
model: {
3030
name: 'example-model',
31-
parameters: { name: 'imagination', temperature: 0.7, maxTokens: 4096 },
31+
parameters: { name: 'imagination', temperature: 0.7 },
3232
},
3333
provider: {
3434
name: 'example-provider',
3535
},
3636
messages: [
37-
{
38-
role: 'system',
39-
content: 'You are a helpful assistant. Your name is {{name}} and your score is {{score}}',
40-
},
41-
{
42-
role: 'user',
43-
content: 'Tell me about yourself.',
44-
},
37+
{ role: 'system', content: 'Hello {{name}}' },
38+
{ role: 'user', content: 'Score: {{score}}' },
4539
],
4640
_ldMeta: {
4741
variationKey: 'v1',
@@ -57,34 +51,48 @@ it('returns config with interpolated messagess', async () => {
5751
expect(result).toEqual({
5852
model: {
5953
name: 'example-model',
60-
parameters: { name: 'imagination', temperature: 0.7, maxTokens: 4096 },
54+
parameters: { name: 'imagination', temperature: 0.7 },
6155
},
6256
provider: {
6357
name: 'example-provider',
6458
},
6559
messages: [
66-
{
67-
role: 'system',
68-
content: 'You are a helpful assistant. Your name is John and your score is 42',
69-
},
70-
{
71-
role: 'user',
72-
content: 'Tell me about yourself.',
73-
},
60+
{ role: 'system', content: 'Hello John' },
61+
{ role: 'user', content: 'Score: 42' },
7462
],
7563
tracker: expect.any(Object),
7664
enabled: true,
7765
toVercelAISDK: expect.any(Function),
7866
});
7967
});
8068

69+
it('includes context in variables for messages interpolation', async () => {
70+
const client = new LDAIClientImpl(mockLdClient);
71+
const key = 'test-flag';
72+
const defaultValue: LDAIDefaults = {
73+
model: { name: 'test', parameters: { name: 'test-model' } },
74+
messages: [],
75+
};
76+
77+
const mockVariation = {
78+
messages: [{ role: 'system', content: 'User key: {{ldctx.key}}' }],
79+
_ldMeta: { variationKey: 'v1', enabled: true },
80+
};
81+
82+
mockLdClient.variation.mockResolvedValue(mockVariation);
83+
84+
const result = await client.config(key, testContext, defaultValue);
85+
86+
expect(result.messages?.[0].content).toBe('User key: test-user');
87+
expect(result.toVercelAISDK).toEqual(expect.any(Function));
88+
});
89+
8190
it('handles missing metadata in variation', async () => {
8291
const client = new LDAIClientImpl(mockLdClient);
8392
const key = 'test-flag';
8493
const defaultValue: LDAIDefaults = {
8594
model: { name: 'test', parameters: { name: 'test-model' } },
86-
messages: [{ role: 'system', content: 'Hello' }],
87-
enabled: true,
95+
messages: [],
8896
};
8997

9098
const mockVariation = {
@@ -111,7 +119,7 @@ it('passes the default value to the underlying client', async () => {
111119
const defaultValue: LDAIDefaults = {
112120
model: { name: 'default-model', parameters: { name: 'default' } },
113121
provider: { name: 'default-provider' },
114-
messages: [{ role: 'system', content: 'Default message' }],
122+
messages: [{ role: 'system', content: 'Default messages' }],
115123
enabled: true,
116124
};
117125

@@ -131,6 +139,7 @@ it('passes the default value to the underlying client', async () => {
131139
expect(mockLdClient.variation).toHaveBeenCalledWith(key, testContext, defaultValue);
132140
});
133141

142+
// New agent-related tests
134143
it('returns single agent config with interpolated instructions', async () => {
135144
const client = new LDAIClientImpl(mockLdClient);
136145
const key = 'test-agent';

0 commit comments

Comments
 (0)