Skip to content

Commit 75b54e4

Browse files
committed
Fix sdk types test
1 parent 2391db6 commit 75b54e4

File tree

2 files changed

+69
-48
lines changed

2 files changed

+69
-48
lines changed
Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,54 @@
11
// Test TypeScript type resolution in CommonJS environment
2-
import type { CodebuffClient, CustomToolDefinition, RunState } from '@codebuff/sdk';
3-
import { CodebuffClient as ClientClass, getCustomToolDefinition } from '@codebuff/sdk';
2+
import {
3+
CodebuffClient as ClientClass,
4+
getCustomToolDefinition,
5+
} from '@codebuff/sdk'
6+
7+
import type {
8+
CodebuffClient,
9+
CustomToolDefinition,
10+
RunState,
11+
} from '@codebuff/sdk'
412

513
// Test 1: Type imports work correctly
6-
const testClient: CodebuffClient = {} as any;
7-
const testTool: CustomToolDefinition = {} as any;
8-
const testState: RunState = {} as any;
14+
const testClient: CodebuffClient = {} as any
15+
const testTool: CustomToolDefinition = {} as any
16+
const testState: RunState = {} as any
917

10-
console.log('✅ Type imports successful');
18+
console.log('✅ Type imports successful')
1119

1220
// Test 2: Value imports work correctly in TypeScript
13-
const clientConstructor = ClientClass;
14-
const toolDefFunction = getCustomToolDefinition;
21+
const clientConstructor = ClientClass
22+
const toolDefFunction = getCustomToolDefinition
1523

16-
console.log('✅ Value imports successful:', typeof clientConstructor, typeof toolDefFunction);
24+
console.log(
25+
'✅ Value imports successful:',
26+
typeof clientConstructor,
27+
typeof toolDefFunction,
28+
)
1729

1830
// Test 3: Test actual instantiation would work (without requiring API key)
19-
type ClientOptions = ConstructorParameters<typeof ClientClass>[0];
31+
type ClientOptions = ConstructorParameters<typeof ClientClass>[0]
2032

2133
const mockOptions: ClientOptions = {
2234
apiKey: 'test-key',
23-
onError: (error) => console.error('Test error:', error.message),
24-
};
35+
}
2536

2637
// This should compile without errors
27-
const mockClient = new ClientClass(mockOptions);
38+
const mockClient = new ClientClass(mockOptions)
2839

29-
console.log('✅ Client instantiation types work correctly');
40+
console.log('✅ Client instantiation types work correctly')
3041

3142
// Test 4: Custom tool definition types (compile-time only)
32-
type MockTool = ReturnType<typeof getCustomToolDefinition<'test-tool', any, any, any>>;
33-
const toolTypeTest: MockTool = {} as any;
43+
type MockTool = ReturnType<typeof getCustomToolDefinition>
44+
const toolTypeTest: MockTool = {} as any
3445

35-
console.log('✅ Custom tool definition types work correctly');
46+
console.log('✅ Custom tool definition types work correctly')
3647

3748
// Test 5: CommonJS import syntax also works in TypeScript
38-
const SDKRequire = require('@codebuff/sdk');
39-
const ClientFromRequire: typeof ClientClass = SDKRequire.CodebuffClient;
49+
const SDKRequire = require('@codebuff/sdk')
50+
const ClientFromRequire: typeof ClientClass = SDKRequire.CodebuffClient
4051

41-
console.log('✅ CommonJS require syntax works in TypeScript');
52+
console.log('✅ CommonJS require syntax works in TypeScript')
4253

43-
export {}; // Make this a module
54+
export {} // Make this a module
Lines changed: 37 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,59 @@
11
// Test TypeScript type resolution in ESM environment
2-
import type { CodebuffClient, CustomToolDefinition, RunState } from '@codebuff/sdk';
3-
import { CodebuffClient as ClientClass, getCustomToolDefinition } from '@codebuff/sdk';
4-
import * as FullSDK from '@codebuff/sdk';
5-
6-
(async () => {
2+
import type {
3+
CodebuffClient,
4+
CustomToolDefinition,
5+
RunState,
6+
} from '@codebuff/sdk'
7+
import {
8+
CodebuffClient as ClientClass,
9+
getCustomToolDefinition,
10+
} from '@codebuff/sdk'
11+
import * as FullSDK from '@codebuff/sdk'
12+
13+
;(async () => {
714
// Test 1: Type imports work correctly
8-
const testClient: CodebuffClient = {} as any;
9-
const testTool: CustomToolDefinition = {} as any;
10-
const testState: RunState = {} as any;
15+
const testClient: CodebuffClient = {} as any
16+
const testTool: CustomToolDefinition = {} as any
17+
const testState: RunState = {} as any
1118

12-
console.log('✅ Type imports successful');
19+
console.log('✅ Type imports successful')
1320

1421
// Test 2: Value imports work correctly in TypeScript
15-
const clientConstructor = ClientClass;
16-
const toolDefFunction = getCustomToolDefinition;
22+
const clientConstructor = ClientClass
23+
const toolDefFunction = getCustomToolDefinition
1724

18-
console.log('✅ Value imports successful:', typeof clientConstructor, typeof toolDefFunction);
25+
console.log(
26+
'✅ Value imports successful:',
27+
typeof clientConstructor,
28+
typeof toolDefFunction,
29+
)
1930

2031
// Test 3: Test actual instantiation would work (without requiring API key)
21-
type ClientOptions = ConstructorParameters<typeof ClientClass>[0];
32+
type ClientOptions = ConstructorParameters<typeof ClientClass>[0]
2233

2334
const mockOptions: ClientOptions = {
2435
apiKey: 'test-key',
25-
onError: (error) => console.error('Test error:', error.message),
26-
};
36+
}
2737

2838
// This should compile without errors
29-
const mockClient = new ClientClass(mockOptions);
39+
const mockClient = new ClientClass(mockOptions)
3040

31-
console.log('✅ Client instantiation types work correctly');
41+
console.log('✅ Client instantiation types work correctly')
3242

3343
// Test 4: Custom tool definition types (compile-time only)
34-
type MockTool = ReturnType<typeof getCustomToolDefinition<'test-tool', any, any, any>>;
35-
const toolTypeTest: MockTool = {} as any;
44+
type MockTool = ReturnType<typeof getCustomToolDefinition>
45+
const toolTypeTest: MockTool = {} as any
3646

37-
console.log('✅ Custom tool definition types work correctly');
47+
console.log('✅ Custom tool definition types work correctly')
3848

3949
// Test 5: Dynamic imports also work in TypeScript ESM
40-
const dynamicSDK = await import('@codebuff/sdk');
41-
const ClientFromDynamic: typeof ClientClass = dynamicSDK.CodebuffClient;
42-
console.log('✅ Dynamic imports work in TypeScript ESM');
50+
const dynamicSDK = await import('@codebuff/sdk')
51+
const ClientFromDynamic: typeof ClientClass = dynamicSDK.CodebuffClient
52+
console.log('✅ Dynamic imports work in TypeScript ESM')
4353

4454
// Test 6: Namespace imports work
45-
const ClientFromNamespace: typeof ClientClass = FullSDK.CodebuffClient;
46-
console.log('✅ Namespace imports work correctly');
47-
})();
55+
const ClientFromNamespace: typeof ClientClass = FullSDK.CodebuffClient
56+
console.log('✅ Namespace imports work correctly')
57+
})()
4858

49-
export {}; // Make this a module
59+
export {} // Make this a module

0 commit comments

Comments
 (0)