Skip to content

Add all missing TS integ tests & remove integ-tests.old.ts #1992

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions integ-tests/typescript/tests/dynamic-clients.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { b } from './test-setup'
import { ClientRegistry } from '@boundaryml/baml'

describe('Dynamic Clients', () => {
it('should work with dynamic client', async () => {
const clientRegistry = new ClientRegistry()
clientRegistry.addLlmClient('myClient', 'openai', {
model: 'gpt-3.5-turbo',
})
clientRegistry.setPrimary('myClient')

const capitol = await b.ExpectFailure({
clientRegistry,
})
expect(capitol.toLowerCase()).toContain('london')
})

})
32 changes: 32 additions & 0 deletions integ-tests/typescript/tests/dynamic-types.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,20 @@ describe('Dynamic Type Tests', () => {
expect(res[0]['animalLiked']).toEqual('GIRAFFE')
})

it('should work with dynamic types class', async () => {
let tb = new TypeBuilder()
const animalClass = tb.addClass('Animal')
animalClass.addProperty('animal', tb.string()).description('The animal mentioned, in singular form.')
tb.Person.addProperty('animalLiked', animalClass.type())
const res = await b.ExtractPeople(
"My name is Harrison. My hair is black and I'm 6 feet tall. I'm pretty good around the hoop. I like giraffes.",
{ tb },
)
expect(res.length).toBeGreaterThan(0)
const animalLiked = res[0]['animalLiked']
expect(animalLiked['animal']).toContain('giraffe')
})

it('should work with dynamic literals', async () => {
let tb = new TypeBuilder()
const animals = tb.union(['giraffe', 'elephant', 'lion'].map((animal) => tb.literalString(animal.toUpperCase())))
Expand All @@ -47,9 +61,27 @@ describe('Dynamic Type Tests', () => {
expect(res.length).toBeGreaterThan(0)
expect(res[0]['animalLiked']).toEqual('GIRAFFE')
})

it('should work with dynamic inputs class', async () => {
let tb = new TypeBuilder()
tb.DynInputOutput.addProperty('new-key', tb.string().optional())

const res = await b.DynamicInputOutput({ 'new-key': 'hi', testKey: 'myTest' }, { tb })
expect(res['new-key']).toEqual('hi')
expect(res['testKey']).toEqual('myTest')
})
})

describe('Complex Dynamic Types', () => {
it('should work with dynamic inputs list', async () => {
let tb = new TypeBuilder()
tb.DynInputOutput.addProperty('new-key', tb.string().optional())

const res = await b.DynamicListInputOutput([{ 'new-key': 'hi', testKey: 'myTest' }], { tb })
expect(res[0]['new-key']).toEqual('hi')
expect(res[0]['testKey']).toEqual('myTest')
})

it('should work with dynamic output map', async () => {
let tb = new TypeBuilder()
tb.DynamicOutput.addProperty('hair_color', tb.string())
Expand Down
29 changes: 28 additions & 1 deletion integ-tests/typescript/tests/input-output.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { NamedArgsSingleEnumList } from '../baml_client'
import { partial_types } from '../baml_client/partial_types'
import { b } from './test-setup'
import { b, b_sync } from './test-setup'

describe('Basic Input/Output Tests', () => {
describe('Input Types', () => {
Expand Down Expand Up @@ -136,6 +136,33 @@ describe('Basic Input/Output Tests', () => {
})
})

describe('Clients Tests', () => {
it('should work with a sync client', () => {
const res = b_sync.TestFnNamedArgsSingleStringList(['a', 'b', 'c'])
expect(res).toContain('a')
})
})

describe('Streaming Tests', () => {
it('should support streaming without iterating', async () => {
const final = await b.stream.PromptTestStreaming('Mt Rainier is tall').getFinalResponse()
expect(final.length).toBeGreaterThan(0)
})

it('should work with nested classes', async () => {
let stream = b.stream.FnOutputClassNested('hi!')
let msgs: partial_types.TestClassNested[] = []
for await (const msg of stream) {
console.log('msg', msg)
msgs.push(msg)
}

const final = await stream.getFinalResponse()
expect(msgs.length).toBeGreaterThan(0)
expect(msgs.at(-1)).toEqual(final)
})
})

describe('Semantic Streaming Tests', () => {
it('should support semantic streaming', async () => {
const stream = b.stream.MakeSemanticContainer()
Expand Down
Loading
Loading