93 lines
2.9 KiB
TypeScript
93 lines
2.9 KiB
TypeScript
|
|
import { test, expect } from '@playwright/test';
|
||
|
|
|
||
|
|
// API 接口测试
|
||
|
|
test.describe('Swarm API 接口测试', () => {
|
||
|
|
const apiBase = 'http://localhost:8000/api';
|
||
|
|
|
||
|
|
test('健康检查接口', async ({ request }) => {
|
||
|
|
const response = await request.get(`${apiBase}/health`);
|
||
|
|
expect(response.ok()).toBeTruthy();
|
||
|
|
|
||
|
|
const body = await response.json();
|
||
|
|
expect(body).toHaveProperty('status');
|
||
|
|
expect(body).toHaveProperty('version');
|
||
|
|
expect(body.status).toBe('healthy');
|
||
|
|
});
|
||
|
|
|
||
|
|
test('获取 Agent 列表', async ({ request }) => {
|
||
|
|
const response = await request.get(`${apiBase}/agents`);
|
||
|
|
expect(response.ok()).toBeTruthy();
|
||
|
|
|
||
|
|
const body = await response.json();
|
||
|
|
expect(body).toHaveProperty('agents');
|
||
|
|
expect(Array.isArray(body.agents)).toBeTruthy();
|
||
|
|
});
|
||
|
|
|
||
|
|
test('获取文件锁列表', async ({ request }) => {
|
||
|
|
const response = await request.get(`${apiBase}/locks`);
|
||
|
|
expect(response.ok()).toBeTruthy();
|
||
|
|
|
||
|
|
const body = await response.json();
|
||
|
|
expect(body).toHaveProperty('locks');
|
||
|
|
expect(Array.isArray(body.locks)).toBeTruthy();
|
||
|
|
});
|
||
|
|
|
||
|
|
test('获取心跳列表', async ({ request }) => {
|
||
|
|
const response = await request.get(`${apiBase}/heartbeats`);
|
||
|
|
expect(response.ok()).toBeTruthy();
|
||
|
|
|
||
|
|
const body = await response.json();
|
||
|
|
expect(body).toHaveProperty('heartbeats');
|
||
|
|
});
|
||
|
|
|
||
|
|
test('注册 Agent', async ({ request }) => {
|
||
|
|
const testAgent = {
|
||
|
|
agent_id: `test-agent-${Date.now()}`,
|
||
|
|
name: 'Test Agent',
|
||
|
|
role: 'developer',
|
||
|
|
model: 'test-model',
|
||
|
|
description: 'Playwright 测试用 Agent',
|
||
|
|
};
|
||
|
|
|
||
|
|
const response = await request.post(`${apiBase}/agents/register`, {
|
||
|
|
data: testAgent,
|
||
|
|
});
|
||
|
|
|
||
|
|
expect(response.ok()).toBeTruthy();
|
||
|
|
const body = await response.json();
|
||
|
|
expect(body.agent_id).toBe(testAgent.agent_id);
|
||
|
|
expect(body.name).toBe(testAgent.name);
|
||
|
|
});
|
||
|
|
|
||
|
|
test('解析任务文件', async ({ request }) => {
|
||
|
|
const response = await request.post(`${apiBase}/parse-task`, {
|
||
|
|
data: { task: '修复 src/auth/login.py 中的 bug' },
|
||
|
|
});
|
||
|
|
|
||
|
|
expect(response.ok()).toBeTruthy();
|
||
|
|
const body = await response.json();
|
||
|
|
expect(body).toHaveProperty('files');
|
||
|
|
expect(Array.isArray(body.files)).toBeTruthy();
|
||
|
|
});
|
||
|
|
|
||
|
|
test('获取任务主要角色', async ({ request }) => {
|
||
|
|
const response = await request.post(`${apiBase}/roles/primary`, {
|
||
|
|
data: { task: '实现登录功能并编写测试用例' },
|
||
|
|
});
|
||
|
|
|
||
|
|
expect(response.ok()).toBeTruthy();
|
||
|
|
const body = await response.json();
|
||
|
|
expect(body).toHaveProperty('primary_role');
|
||
|
|
expect(body).toHaveProperty('role_scores');
|
||
|
|
});
|
||
|
|
|
||
|
|
test('列出工作流文件', async ({ request }) => {
|
||
|
|
const response = await request.get(`${apiBase}/workflows/files`);
|
||
|
|
expect(response.ok()).toBeTruthy();
|
||
|
|
|
||
|
|
const body = await response.json();
|
||
|
|
expect(body).toHaveProperty('files');
|
||
|
|
expect(Array.isArray(body.files)).toBeTruthy();
|
||
|
|
});
|
||
|
|
});
|