mirror of
https://github.com/claude-code-best/claude-code.git
synced 2026-06-15 12:55:51 +00:00
test: 新增测试代码文件
This commit is contained in:
34
tests/mocks/api-responses.ts
Normal file
34
tests/mocks/api-responses.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
export const mockStreamResponse = {
|
||||
type: "message_start" as const,
|
||||
message: {
|
||||
id: "msg_mock_001",
|
||||
type: "message" as const,
|
||||
role: "assistant",
|
||||
content: [],
|
||||
model: "claude-sonnet-4-20250514",
|
||||
stop_reason: null,
|
||||
stop_sequence: null,
|
||||
usage: { input_tokens: 100, output_tokens: 0 },
|
||||
},
|
||||
};
|
||||
|
||||
export const mockTextBlock = {
|
||||
type: "content_block_start" as const,
|
||||
index: 0,
|
||||
content_block: { type: "text" as const, text: "Mock response" },
|
||||
};
|
||||
|
||||
export const mockToolUseBlock = {
|
||||
type: "content_block_start" as const,
|
||||
index: 1,
|
||||
content_block: {
|
||||
type: "tool_use" as const,
|
||||
id: "toolu_mock_001",
|
||||
name: "Read",
|
||||
input: { file_path: "/tmp/test.txt" },
|
||||
},
|
||||
};
|
||||
|
||||
export const mockEndEvent = {
|
||||
type: "message_stop" as const,
|
||||
};
|
||||
32
tests/mocks/file-system.ts
Normal file
32
tests/mocks/file-system.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import { mkdtemp, rm, writeFile, mkdir } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
|
||||
export async function createTempDir(
|
||||
prefix = "claude-test-",
|
||||
): Promise<string> {
|
||||
return mkdtemp(join(tmpdir(), prefix));
|
||||
}
|
||||
|
||||
export async function cleanupTempDir(dir: string): Promise<void> {
|
||||
await rm(dir, { recursive: true, force: true });
|
||||
}
|
||||
|
||||
export async function writeTempFile(
|
||||
dir: string,
|
||||
name: string,
|
||||
content: string,
|
||||
): Promise<string> {
|
||||
const path = join(dir, name);
|
||||
await writeFile(path, content, "utf-8");
|
||||
return path;
|
||||
}
|
||||
|
||||
export async function createTempSubdir(
|
||||
dir: string,
|
||||
name: string,
|
||||
): Promise<string> {
|
||||
const path = join(dir, name);
|
||||
await mkdir(path, { recursive: true });
|
||||
return path;
|
||||
}
|
||||
3
tests/mocks/fixtures/sample-claudemd.md
Normal file
3
tests/mocks/fixtures/sample-claudemd.md
Normal file
@@ -0,0 +1,3 @@
|
||||
# Project Instructions
|
||||
|
||||
This is a sample CLAUDE.md file for testing purposes.
|
||||
33
tests/mocks/fixtures/sample-messages.json
Normal file
33
tests/mocks/fixtures/sample-messages.json
Normal file
@@ -0,0 +1,33 @@
|
||||
{
|
||||
"userMessage": {
|
||||
"role": "user",
|
||||
"content": "Hello, Claude"
|
||||
},
|
||||
"assistantMessage": {
|
||||
"role": "assistant",
|
||||
"content": [
|
||||
{ "type": "text", "text": "Hello! How can I help?" }
|
||||
]
|
||||
},
|
||||
"toolUseMessage": {
|
||||
"role": "assistant",
|
||||
"content": [
|
||||
{
|
||||
"type": "tool_use",
|
||||
"id": "toolu_test_001",
|
||||
"name": "Read",
|
||||
"input": { "file_path": "/tmp/test.txt" }
|
||||
}
|
||||
]
|
||||
},
|
||||
"toolResultMessage": {
|
||||
"role": "user",
|
||||
"content": [
|
||||
{
|
||||
"type": "tool_result",
|
||||
"tool_use_id": "toolu_test_001",
|
||||
"content": "file contents here"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user