Skip to content

Commit 18b5176

Browse files
Add all missing TS integ tests & remove integ-tests.old.ts (#1992)
<!-- ELLIPSIS_HIDDEN --> > [!IMPORTANT] > Add comprehensive integration tests for dynamic clients, types, media, providers, retry policies, and tracing, and remove outdated test file. > > - **New Tests**: > - Add `dynamic-clients.test.ts` for testing dynamic client registration and usage. > - Add `dynamic-types.test.ts` for testing dynamic type handling, including classes, enums, and literals. > - Add `media.test.ts` for testing image and audio input handling. > - Add `prompt_renderer.test.ts` for testing prompt rendering with aliasing. > - Add `retry.test.ts` for testing retry policies and fallbacks. > - Add `tracing.test.ts` for testing synchronous and asynchronous tracing, and event logging. > - **Provider Tests**: > - Add tests for `Anthropic`, `AWS`, `Azure`, and `OpenAI` providers, including streaming and error handling. > - **File Removal**: > - Remove `integ-tests.test.ts.old`, consolidating tests into new files. > > <sup>This description was created by </sup>[<img alt="Ellipsis" src="https://img.shields.io/badge/Ellipsis-blue?color=175173">](https://www.ellipsis.dev?ref=BoundaryML%2Fbaml&utm_source=github&utm_medium=referral)<sup> for ae7bc16. You can [customize](https://app.ellipsis.dev/BoundaryML/settings/summaries) this summary. It will automatically update as commits are pushed.</sup> <!-- ELLIPSIS_HIDDEN -->
1 parent 4c0fd28 commit 18b5176

12 files changed

+232
-787
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { b } from './test-setup'
2+
import { ClientRegistry } from '@boundaryml/baml'
3+
4+
describe('Dynamic Clients', () => {
5+
it('should work with dynamic client', async () => {
6+
const clientRegistry = new ClientRegistry()
7+
clientRegistry.addLlmClient('myClient', 'openai', {
8+
model: 'gpt-3.5-turbo',
9+
})
10+
clientRegistry.setPrimary('myClient')
11+
12+
const capitol = await b.ExpectFailure({
13+
clientRegistry,
14+
})
15+
expect(capitol.toLowerCase()).toContain('london')
16+
})
17+
18+
})

integ-tests/typescript/tests/dynamic-types.test.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,20 @@ describe('Dynamic Type Tests', () => {
3636
expect(res[0]['animalLiked']).toEqual('GIRAFFE')
3737
})
3838

39+
it('should work with dynamic types class', async () => {
40+
let tb = new TypeBuilder()
41+
const animalClass = tb.addClass('Animal')
42+
animalClass.addProperty('animal', tb.string()).description('The animal mentioned, in singular form.')
43+
tb.Person.addProperty('animalLiked', animalClass.type())
44+
const res = await b.ExtractPeople(
45+
"My name is Harrison. My hair is black and I'm 6 feet tall. I'm pretty good around the hoop. I like giraffes.",
46+
{ tb },
47+
)
48+
expect(res.length).toBeGreaterThan(0)
49+
const animalLiked = res[0]['animalLiked']
50+
expect(animalLiked['animal']).toContain('giraffe')
51+
})
52+
3953
it('should work with dynamic literals', async () => {
4054
let tb = new TypeBuilder()
4155
const animals = tb.union(['giraffe', 'elephant', 'lion'].map((animal) => tb.literalString(animal.toUpperCase())))
@@ -47,9 +61,27 @@ describe('Dynamic Type Tests', () => {
4761
expect(res.length).toBeGreaterThan(0)
4862
expect(res[0]['animalLiked']).toEqual('GIRAFFE')
4963
})
64+
65+
it('should work with dynamic inputs class', async () => {
66+
let tb = new TypeBuilder()
67+
tb.DynInputOutput.addProperty('new-key', tb.string().optional())
68+
69+
const res = await b.DynamicInputOutput({ 'new-key': 'hi', testKey: 'myTest' }, { tb })
70+
expect(res['new-key']).toEqual('hi')
71+
expect(res['testKey']).toEqual('myTest')
72+
})
5073
})
5174

5275
describe('Complex Dynamic Types', () => {
76+
it('should work with dynamic inputs list', async () => {
77+
let tb = new TypeBuilder()
78+
tb.DynInputOutput.addProperty('new-key', tb.string().optional())
79+
80+
const res = await b.DynamicListInputOutput([{ 'new-key': 'hi', testKey: 'myTest' }], { tb })
81+
expect(res[0]['new-key']).toEqual('hi')
82+
expect(res[0]['testKey']).toEqual('myTest')
83+
})
84+
5385
it('should work with dynamic output map', async () => {
5486
let tb = new TypeBuilder()
5587
tb.DynamicOutput.addProperty('hair_color', tb.string())

integ-tests/typescript/tests/input-output.test.ts

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { NamedArgsSingleEnumList } from '../baml_client'
22
import { partial_types } from '../baml_client/partial_types'
3-
import { b } from './test-setup'
3+
import { b, b_sync } from './test-setup'
44

55
describe('Basic Input/Output Tests', () => {
66
describe('Input Types', () => {
@@ -136,6 +136,33 @@ describe('Basic Input/Output Tests', () => {
136136
})
137137
})
138138

139+
describe('Clients Tests', () => {
140+
it('should work with a sync client', () => {
141+
const res = b_sync.TestFnNamedArgsSingleStringList(['a', 'b', 'c'])
142+
expect(res).toContain('a')
143+
})
144+
})
145+
146+
describe('Streaming Tests', () => {
147+
it('should support streaming without iterating', async () => {
148+
const final = await b.stream.PromptTestStreaming('Mt Rainier is tall').getFinalResponse()
149+
expect(final.length).toBeGreaterThan(0)
150+
})
151+
152+
it('should work with nested classes', async () => {
153+
let stream = b.stream.FnOutputClassNested('hi!')
154+
let msgs: partial_types.TestClassNested[] = []
155+
for await (const msg of stream) {
156+
console.log('msg', msg)
157+
msgs.push(msg)
158+
}
159+
160+
const final = await stream.getFinalResponse()
161+
expect(msgs.length).toBeGreaterThan(0)
162+
expect(msgs.at(-1)).toEqual(final)
163+
})
164+
})
165+
139166
describe('Semantic Streaming Tests', () => {
140167
it('should support semantic streaming', async () => {
141168
const stream = b.stream.MakeSemanticContainer()

0 commit comments

Comments
 (0)