|
| 1 | +import { ContentBlock } from '../../src/resources/messages'; |
| 2 | + |
| 3 | +import { TracksToolInput } from '@anthropic-ai/sdk/lib/MessageStream'; |
| 4 | +import { TracksToolInput as BetaTracksToolInput } from '@anthropic-ai/sdk/lib/BetaMessageStream'; |
| 5 | +import { BetaContentBlock } from '@anthropic-ai/sdk/resources/beta'; |
| 6 | + |
| 7 | +/** |
| 8 | + * This test ensures that our TracksToolInput type includes all content block types that have an input property. |
| 9 | + * If any new content block types with input properties are added, they should be added to the TracksToolInput types. |
| 10 | + */ |
| 11 | + |
| 12 | +describe('TracksToolInput type', () => { |
| 13 | + describe('Regular MessageStream', () => { |
| 14 | + type ContentBlockWithInput = Extract<ContentBlock, { input: unknown }>; |
| 15 | + |
| 16 | + it('TracksToolInput includes all content block types with input properties', () => { |
| 17 | + // Define a type that extracts all ContentBlock types that have an input property |
| 18 | + |
| 19 | + // TypeScript compile-time check: all ContentBlock types with input property |
| 20 | + // should be assignable to TracksToolInput |
| 21 | + type Test = ContentBlockWithInput extends TracksToolInput ? true : false; |
| 22 | + const test: Test = true; |
| 23 | + expect(test).toBe(true); |
| 24 | + }); |
| 25 | + |
| 26 | + it('all TracksToolInput types should have an input property', () => { |
| 27 | + // TypeScript compile-time check: all TracksToolInput types should have |
| 28 | + // an input property (i.e., be assignable to ContentBlockWithInput) |
| 29 | + type Test2 = TracksToolInput extends ContentBlockWithInput ? true : false; |
| 30 | + const test2: Test2 = true; |
| 31 | + expect(test2).toBe(true); |
| 32 | + }); |
| 33 | + }); |
| 34 | + |
| 35 | + describe('Beta MessageStream', () => { |
| 36 | + type BetaContentBlockWithInput = Extract<BetaContentBlock, { input: unknown }>; |
| 37 | + |
| 38 | + it('TracksToolInput includes all content block types with input properties', () => { |
| 39 | + // Define a type that extracts all BetaContentBlock types that have an input property |
| 40 | + |
| 41 | + // TypeScript compile-time check: all BetaContentBlock types with input property |
| 42 | + // should be assignable to BetaTracksToolInput |
| 43 | + type Test = BetaContentBlockWithInput extends BetaTracksToolInput ? true : false; |
| 44 | + const test: Test = true; |
| 45 | + expect(test).toBe(true); |
| 46 | + }); |
| 47 | + |
| 48 | + it('all BetaTracksToolInput types should have an input property', () => { |
| 49 | + // TypeScript compile-time check: all BetaTracksToolInput types should have |
| 50 | + // an input property (i.e., be assignable to BetaContentBlockWithInput) |
| 51 | + type Test2 = BetaTracksToolInput extends BetaContentBlockWithInput ? true : false; |
| 52 | + const test2: Test2 = true; |
| 53 | + expect(test2).toBe(true); |
| 54 | + }); |
| 55 | + }); |
| 56 | +}); |
0 commit comments