mirror of
https://github.com/QwenLM/qwen-code.git
synced 2025-12-19 09:33:53 +00:00
Merge pull request #1161 from QwenLM/mingholy/fix/integration-test-scripts
test: separating integration tests for the CLI and SDK
This commit is contained in:
2
.github/workflows/release-sdk.yml
vendored
2
.github/workflows/release-sdk.yml
vendored
@@ -202,7 +202,7 @@ jobs:
|
|||||||
registry-url: 'https://registry.npmjs.org'
|
registry-url: 'https://registry.npmjs.org'
|
||||||
scope: '@qwen-code'
|
scope: '@qwen-code'
|
||||||
|
|
||||||
- name: 'Publish @qwen-code/sdk-typescript'
|
- name: 'Publish @qwen-code/sdk'
|
||||||
working-directory: 'packages/sdk-typescript'
|
working-directory: 'packages/sdk-typescript'
|
||||||
run: |-
|
run: |-
|
||||||
npm publish --access public --tag=${{ steps.version.outputs.NPM_TAG }} ${{ steps.vars.outputs.is_dry_run == 'true' && '--dry-run' || '' }}
|
npm publish --access public --tag=${{ steps.version.outputs.NPM_TAG }} ${{ steps.vars.outputs.is_dry_run == 'true' && '--dry-run' || '' }}
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import {
|
|||||||
isSDKAssistantMessage,
|
isSDKAssistantMessage,
|
||||||
type TextBlock,
|
type TextBlock,
|
||||||
type ContentBlock,
|
type ContentBlock,
|
||||||
} from '@qwen-code/sdk-typescript';
|
} from '@qwen-code/sdk';
|
||||||
import { SDKTestHelper, createSharedTestOptions } from './test-helper.js';
|
import { SDKTestHelper, createSharedTestOptions } from './test-helper.js';
|
||||||
|
|
||||||
const SHARED_TEST_OPTIONS = createSharedTestOptions();
|
const SHARED_TEST_OPTIONS = createSharedTestOptions();
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ import {
|
|||||||
isSDKAssistantMessage,
|
isSDKAssistantMessage,
|
||||||
isSDKSystemMessage,
|
isSDKSystemMessage,
|
||||||
type SDKMessage,
|
type SDKMessage,
|
||||||
} from '@qwen-code/sdk-typescript';
|
} from '@qwen-code/sdk';
|
||||||
import {
|
import {
|
||||||
SDKTestHelper,
|
SDKTestHelper,
|
||||||
extractText,
|
extractText,
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ import {
|
|||||||
type SDKMessage,
|
type SDKMessage,
|
||||||
type ToolUseBlock,
|
type ToolUseBlock,
|
||||||
type SDKSystemMessage,
|
type SDKSystemMessage,
|
||||||
} from '@qwen-code/sdk-typescript';
|
} from '@qwen-code/sdk';
|
||||||
import {
|
import {
|
||||||
SDKTestHelper,
|
SDKTestHelper,
|
||||||
createMCPServer,
|
createMCPServer,
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ import {
|
|||||||
type SDKMessage,
|
type SDKMessage,
|
||||||
type ControlMessage,
|
type ControlMessage,
|
||||||
type ToolUseBlock,
|
type ToolUseBlock,
|
||||||
} from '@qwen-code/sdk-typescript';
|
} from '@qwen-code/sdk';
|
||||||
import { SDKTestHelper, createSharedTestOptions } from './test-helper.js';
|
import { SDKTestHelper, createSharedTestOptions } from './test-helper.js';
|
||||||
|
|
||||||
const SHARED_TEST_OPTIONS = createSharedTestOptions();
|
const SHARED_TEST_OPTIONS = createSharedTestOptions();
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ import {
|
|||||||
type SDKUserMessage,
|
type SDKUserMessage,
|
||||||
type ToolUseBlock,
|
type ToolUseBlock,
|
||||||
type ContentBlock,
|
type ContentBlock,
|
||||||
} from '@qwen-code/sdk-typescript';
|
} from '@qwen-code/sdk';
|
||||||
import {
|
import {
|
||||||
SDKTestHelper,
|
SDKTestHelper,
|
||||||
createSharedTestOptions,
|
createSharedTestOptions,
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ import {
|
|||||||
isSDKSystemMessage,
|
isSDKSystemMessage,
|
||||||
type SDKMessage,
|
type SDKMessage,
|
||||||
type SDKSystemMessage,
|
type SDKSystemMessage,
|
||||||
} from '@qwen-code/sdk-typescript';
|
} from '@qwen-code/sdk';
|
||||||
import {
|
import {
|
||||||
SDKTestHelper,
|
SDKTestHelper,
|
||||||
extractText,
|
extractText,
|
||||||
@@ -51,12 +51,6 @@ describe('SDK MCP Server Integration (E2E)', () => {
|
|||||||
describe('Basic SDK MCP Tool Usage', () => {
|
describe('Basic SDK MCP Tool Usage', () => {
|
||||||
it('should use SDK MCP tool to perform a simple calculation', async () => {
|
it('should use SDK MCP tool to perform a simple calculation', async () => {
|
||||||
// Define a simple calculator tool using the tool() API with Zod schema
|
// Define a simple calculator tool using the tool() API with Zod schema
|
||||||
console.log(
|
|
||||||
z.object({
|
|
||||||
a: z.number().describe('First number'),
|
|
||||||
b: z.number().describe('Second number'),
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
const calculatorTool = tool(
|
const calculatorTool = tool(
|
||||||
'calculate_sum',
|
'calculate_sum',
|
||||||
'Calculate the sum of two numbers',
|
'Calculate the sum of two numbers',
|
||||||
@@ -82,7 +76,6 @@ describe('SDK MCP Server Integration (E2E)', () => {
|
|||||||
options: {
|
options: {
|
||||||
...SHARED_TEST_OPTIONS,
|
...SHARED_TEST_OPTIONS,
|
||||||
cwd: testDir,
|
cwd: testDir,
|
||||||
stderr: (message) => console.error(message),
|
|
||||||
mcpServers: {
|
mcpServers: {
|
||||||
'sdk-calculator': serverConfig,
|
'sdk-calculator': serverConfig,
|
||||||
},
|
},
|
||||||
@@ -96,7 +89,6 @@ describe('SDK MCP Server Integration (E2E)', () => {
|
|||||||
try {
|
try {
|
||||||
for await (const message of q) {
|
for await (const message of q) {
|
||||||
messages.push(message);
|
messages.push(message);
|
||||||
console.log(JSON.stringify(message, null, 2));
|
|
||||||
|
|
||||||
if (isSDKAssistantMessage(message)) {
|
if (isSDKAssistantMessage(message)) {
|
||||||
const toolUseBlocks = findToolUseBlocks(message, 'calculate_sum');
|
const toolUseBlocks = findToolUseBlocks(message, 'calculate_sum');
|
||||||
@@ -172,7 +164,6 @@ describe('SDK MCP Server Integration (E2E)', () => {
|
|||||||
assistantText += extractText(message.message.content);
|
assistantText += extractText(message.message.content);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
console.log(JSON.stringify(messages, null, 2));
|
|
||||||
|
|
||||||
// Validate tool was called
|
// Validate tool was called
|
||||||
expect(foundToolUse).toBe(true);
|
expect(foundToolUse).toBe(true);
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import {
|
|||||||
type SDKMessage,
|
type SDKMessage,
|
||||||
type SDKSystemMessage,
|
type SDKSystemMessage,
|
||||||
type SDKAssistantMessage,
|
type SDKAssistantMessage,
|
||||||
} from '@qwen-code/sdk-typescript';
|
} from '@qwen-code/sdk';
|
||||||
import {
|
import {
|
||||||
SDKTestHelper,
|
SDKTestHelper,
|
||||||
extractText,
|
extractText,
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ import {
|
|||||||
type SubagentConfig,
|
type SubagentConfig,
|
||||||
type ContentBlock,
|
type ContentBlock,
|
||||||
type ToolUseBlock,
|
type ToolUseBlock,
|
||||||
} from '@qwen-code/sdk-typescript';
|
} from '@qwen-code/sdk';
|
||||||
import {
|
import {
|
||||||
SDKTestHelper,
|
SDKTestHelper,
|
||||||
extractText,
|
extractText,
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import {
|
|||||||
isSDKAssistantMessage,
|
isSDKAssistantMessage,
|
||||||
isSDKSystemMessage,
|
isSDKSystemMessage,
|
||||||
type SDKUserMessage,
|
type SDKUserMessage,
|
||||||
} from '@qwen-code/sdk-typescript';
|
} from '@qwen-code/sdk';
|
||||||
import { SDKTestHelper, createSharedTestOptions } from './test-helper.js';
|
import { SDKTestHelper, createSharedTestOptions } from './test-helper.js';
|
||||||
|
|
||||||
const SHARED_TEST_OPTIONS = createSharedTestOptions();
|
const SHARED_TEST_OPTIONS = createSharedTestOptions();
|
||||||
|
|||||||
@@ -21,12 +21,12 @@ import type {
|
|||||||
ContentBlock,
|
ContentBlock,
|
||||||
TextBlock,
|
TextBlock,
|
||||||
ToolUseBlock,
|
ToolUseBlock,
|
||||||
} from '@qwen-code/sdk-typescript';
|
} from '@qwen-code/sdk';
|
||||||
import {
|
import {
|
||||||
isSDKAssistantMessage,
|
isSDKAssistantMessage,
|
||||||
isSDKSystemMessage,
|
isSDKSystemMessage,
|
||||||
isSDKResultMessage,
|
isSDKResultMessage,
|
||||||
} from '@qwen-code/sdk-typescript';
|
} from '@qwen-code/sdk';
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
// Core Test Helper Class
|
// Core Test Helper Class
|
||||||
|
|||||||
@@ -12,11 +12,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
|
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
|
||||||
import {
|
import { query, isSDKAssistantMessage, type SDKMessage } from '@qwen-code/sdk';
|
||||||
query,
|
|
||||||
isSDKAssistantMessage,
|
|
||||||
type SDKMessage,
|
|
||||||
} from '@qwen-code/sdk-typescript';
|
|
||||||
import {
|
import {
|
||||||
SDKTestHelper,
|
SDKTestHelper,
|
||||||
extractText,
|
extractText,
|
||||||
|
|||||||
@@ -5,9 +5,7 @@
|
|||||||
"allowJs": true,
|
"allowJs": true,
|
||||||
"baseUrl": ".",
|
"baseUrl": ".",
|
||||||
"paths": {
|
"paths": {
|
||||||
"@qwen-code/sdk-typescript": [
|
"@qwen-code/sdk": ["../packages/sdk-typescript/dist/index.d.ts"]
|
||||||
"../packages/sdk-typescript/dist/index.d.ts"
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"include": ["**/*.ts"],
|
"include": ["**/*.ts"],
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ export default defineConfig({
|
|||||||
resolve: {
|
resolve: {
|
||||||
alias: {
|
alias: {
|
||||||
// Use built SDK bundle for e2e tests
|
// Use built SDK bundle for e2e tests
|
||||||
'@qwen-code/sdk-typescript': resolve(
|
'@qwen-code/sdk': resolve(
|
||||||
__dirname,
|
__dirname,
|
||||||
'../packages/sdk-typescript/dist/index.mjs',
|
'../packages/sdk-typescript/dist/index.mjs',
|
||||||
),
|
),
|
||||||
|
|||||||
4
package-lock.json
generated
4
package-lock.json
generated
@@ -2793,7 +2793,7 @@
|
|||||||
"resolved": "packages/test-utils",
|
"resolved": "packages/test-utils",
|
||||||
"link": true
|
"link": true
|
||||||
},
|
},
|
||||||
"node_modules/@qwen-code/sdk-typescript": {
|
"node_modules/@qwen-code/sdk": {
|
||||||
"resolved": "packages/sdk-typescript",
|
"resolved": "packages/sdk-typescript",
|
||||||
"link": true
|
"link": true
|
||||||
},
|
},
|
||||||
@@ -16676,7 +16676,7 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"packages/sdk-typescript": {
|
"packages/sdk-typescript": {
|
||||||
"name": "@qwen-code/sdk-typescript",
|
"name": "@qwen-code/sdk",
|
||||||
"version": "0.1.0",
|
"version": "0.1.0",
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
|||||||
@@ -37,8 +37,8 @@
|
|||||||
"test:integration:sandbox:none": "cross-env GEMINI_SANDBOX=false vitest run --root ./integration-tests",
|
"test:integration:sandbox:none": "cross-env GEMINI_SANDBOX=false vitest run --root ./integration-tests",
|
||||||
"test:integration:sandbox:docker": "cross-env GEMINI_SANDBOX=docker npm run build:sandbox && GEMINI_SANDBOX=docker vitest run --root ./integration-tests",
|
"test:integration:sandbox:docker": "cross-env GEMINI_SANDBOX=docker npm run build:sandbox && GEMINI_SANDBOX=docker vitest run --root ./integration-tests",
|
||||||
"test:integration:sandbox:podman": "cross-env GEMINI_SANDBOX=podman vitest run --root ./integration-tests",
|
"test:integration:sandbox:podman": "cross-env GEMINI_SANDBOX=podman vitest run --root ./integration-tests",
|
||||||
"test:integration:sdk:sandbox:none": "cross-env GEMINI_SANDBOX=false vitest run --root ./integration-tests --dir sdk-typescript",
|
"test:integration:sdk:sandbox:none": "cross-env GEMINI_SANDBOX=false vitest run --root ./integration-tests sdk-typescript",
|
||||||
"test:integration:sdk:sandbox:docker": "cross-env GEMINI_SANDBOX=docker npm run build:sandbox && GEMINI_SANDBOX=docker vitest run --root ./integration-tests --dir sdk-typescript",
|
"test:integration:sdk:sandbox:docker": "cross-env GEMINI_SANDBOX=docker npm run build:sandbox && GEMINI_SANDBOX=docker vitest run --root ./integration-tests sdk-typescript",
|
||||||
"test:integration:cli:sandbox:none": "cross-env GEMINI_SANDBOX=false vitest run --root ./integration-tests --exclude '**/sdk-typescript/**'",
|
"test:integration:cli:sandbox:none": "cross-env GEMINI_SANDBOX=false vitest run --root ./integration-tests --exclude '**/sdk-typescript/**'",
|
||||||
"test:integration:cli:sandbox:docker": "cross-env GEMINI_SANDBOX=docker npm run build:sandbox && GEMINI_SANDBOX=docker vitest run --root ./integration-tests --exclude '**/sdk-typescript/**'",
|
"test:integration:cli:sandbox:docker": "cross-env GEMINI_SANDBOX=docker npm run build:sandbox && GEMINI_SANDBOX=docker vitest run --root ./integration-tests --exclude '**/sdk-typescript/**'",
|
||||||
"test:terminal-bench": "cross-env VERBOSE=true KEEP_OUTPUT=true vitest run --config ./vitest.terminal-bench.config.ts --root ./integration-tests",
|
"test:terminal-bench": "cross-env VERBOSE=true KEEP_OUTPUT=true vitest run --config ./vitest.terminal-bench.config.ts --root ./integration-tests",
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
# @qwen-code/sdk-typescript
|
# @qwen-code/sdk
|
||||||
|
|
||||||
A minimum experimental TypeScript SDK for programmatic access to Qwen Code.
|
A minimum experimental TypeScript SDK for programmatic access to Qwen Code.
|
||||||
|
|
||||||
@@ -7,7 +7,7 @@ Feel free to submit a feature request/issue/PR.
|
|||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
npm install @qwen-code/sdk-typescript
|
npm install @qwen-code/sdk
|
||||||
```
|
```
|
||||||
|
|
||||||
## Requirements
|
## Requirements
|
||||||
@@ -20,7 +20,7 @@ npm install @qwen-code/sdk-typescript
|
|||||||
## Quick Start
|
## Quick Start
|
||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
import { query } from '@qwen-code/sdk-typescript';
|
import { query } from '@qwen-code/sdk';
|
||||||
|
|
||||||
// Single-turn query
|
// Single-turn query
|
||||||
const result = query({
|
const result = query({
|
||||||
@@ -107,7 +107,7 @@ import {
|
|||||||
isSDKSystemMessage,
|
isSDKSystemMessage,
|
||||||
isSDKResultMessage,
|
isSDKResultMessage,
|
||||||
isSDKPartialAssistantMessage,
|
isSDKPartialAssistantMessage,
|
||||||
} from '@qwen-code/sdk-typescript';
|
} from '@qwen-code/sdk';
|
||||||
|
|
||||||
for await (const message of result) {
|
for await (const message of result) {
|
||||||
if (isSDKAssistantMessage(message)) {
|
if (isSDKAssistantMessage(message)) {
|
||||||
@@ -167,7 +167,7 @@ The SDK supports different permission modes for controlling tool execution:
|
|||||||
### Multi-turn Conversation
|
### Multi-turn Conversation
|
||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
import { query, type SDKUserMessage } from '@qwen-code/sdk-typescript';
|
import { query, type SDKUserMessage } from '@qwen-code/sdk';
|
||||||
|
|
||||||
async function* generateMessages(): AsyncIterable<SDKUserMessage> {
|
async function* generateMessages(): AsyncIterable<SDKUserMessage> {
|
||||||
yield {
|
yield {
|
||||||
@@ -201,7 +201,7 @@ for await (const message of result) {
|
|||||||
### Custom Permission Handler
|
### Custom Permission Handler
|
||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
import { query, type CanUseTool } from '@qwen-code/sdk-typescript';
|
import { query, type CanUseTool } from '@qwen-code/sdk';
|
||||||
|
|
||||||
const canUseTool: CanUseTool = async (toolName, input, { signal }) => {
|
const canUseTool: CanUseTool = async (toolName, input, { signal }) => {
|
||||||
// Allow all read operations
|
// Allow all read operations
|
||||||
@@ -230,7 +230,7 @@ const result = query({
|
|||||||
### With External MCP Servers
|
### With External MCP Servers
|
||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
import { query } from '@qwen-code/sdk-typescript';
|
import { query } from '@qwen-code/sdk';
|
||||||
|
|
||||||
const result = query({
|
const result = query({
|
||||||
prompt: 'Use the custom tool from my MCP server',
|
prompt: 'Use the custom tool from my MCP server',
|
||||||
@@ -290,7 +290,7 @@ Returns a `McpSdkServerConfigWithInstance` object that can be passed directly to
|
|||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
import { query, tool, createSdkMcpServer } from '@qwen-code/sdk-typescript';
|
import { query, tool, createSdkMcpServer } from '@qwen-code/sdk';
|
||||||
|
|
||||||
// Define a tool with Zod schema
|
// Define a tool with Zod schema
|
||||||
const calculatorTool = tool(
|
const calculatorTool = tool(
|
||||||
@@ -327,7 +327,7 @@ for await (const message of result) {
|
|||||||
### Abort a Query
|
### Abort a Query
|
||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
import { query, isAbortError } from '@qwen-code/sdk-typescript';
|
import { query, isAbortError } from '@qwen-code/sdk';
|
||||||
|
|
||||||
const abortController = new AbortController();
|
const abortController = new AbortController();
|
||||||
|
|
||||||
@@ -359,7 +359,7 @@ try {
|
|||||||
The SDK provides an `AbortError` class for handling aborted queries:
|
The SDK provides an `AbortError` class for handling aborted queries:
|
||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
import { AbortError, isAbortError } from '@qwen-code/sdk-typescript';
|
import { AbortError, isAbortError } from '@qwen-code/sdk';
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// ... query operations
|
// ... query operations
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"name": "@qwen-code/sdk-typescript",
|
"name": "@qwen-code/sdk",
|
||||||
"version": "0.1.0",
|
"version": "0.1.0",
|
||||||
"description": "TypeScript SDK for programmatic access to qwen-code CLI",
|
"description": "TypeScript SDK for programmatic access to qwen-code CLI",
|
||||||
"main": "./dist/index.cjs",
|
"main": "./dist/index.cjs",
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ import { dirname, join } from 'node:path';
|
|||||||
const __filename = fileURLToPath(import.meta.url);
|
const __filename = fileURLToPath(import.meta.url);
|
||||||
const __dirname = dirname(__filename);
|
const __dirname = dirname(__filename);
|
||||||
|
|
||||||
const PACKAGE_NAME = '@qwen-code/sdk-typescript';
|
const PACKAGE_NAME = '@qwen-code/sdk';
|
||||||
const TAG_PREFIX = 'sdk-typescript-v';
|
const TAG_PREFIX = 'sdk-typescript-v';
|
||||||
|
|
||||||
function readJson(filePath) {
|
function readJson(filePath) {
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ export type McpSdkServerConfigWithInstance = {
|
|||||||
* @example
|
* @example
|
||||||
* ```typescript
|
* ```typescript
|
||||||
* import { z } from 'zod';
|
* import { z } from 'zod';
|
||||||
* import { tool, createSdkMcpServer } from '@qwen-code/sdk-typescript';
|
* import { tool, createSdkMcpServer } from '@qwen-code/sdk';
|
||||||
*
|
*
|
||||||
* const calculatorTool = tool(
|
* const calculatorTool = tool(
|
||||||
* 'calculate_sum',
|
* 'calculate_sum',
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ export type SdkMcpToolDefinition<Schema extends ZodRawShape = ZodRawShape> = {
|
|||||||
* @example
|
* @example
|
||||||
* ```typescript
|
* ```typescript
|
||||||
* import { z } from 'zod';
|
* import { z } from 'zod';
|
||||||
* import { tool } from '@qwen-code/sdk-typescript';
|
* import { tool } from '@qwen-code/sdk';
|
||||||
*
|
*
|
||||||
* const calculatorTool = tool(
|
* const calculatorTool = tool(
|
||||||
* 'calculate_sum',
|
* 'calculate_sum',
|
||||||
|
|||||||
Reference in New Issue
Block a user