feat(training): release V0.8 自调参 Agent
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
import { fireEvent, render, screen, waitFor } from '@testing-library/react';
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
||||
import { TuningApp } from './TuningApp';
|
||||
|
||||
beforeEach(() => {
|
||||
localStorage.clear();
|
||||
sessionStorage.clear();
|
||||
vi.unstubAllGlobals();
|
||||
});
|
||||
|
||||
describe('TuningApp', () => {
|
||||
it('连接调参服务并显示 DeepSeek 能力与新建表单', async () => {
|
||||
const fetchMock = vi.fn((input: string | URL | Request, _init?: RequestInit) => {
|
||||
void _init;
|
||||
const url = String(input);
|
||||
if (url.endsWith('/api/tuning/capabilities'))
|
||||
return Promise.resolve(
|
||||
new Response(
|
||||
JSON.stringify({
|
||||
ready: true,
|
||||
configured: true,
|
||||
apiKeyConfigured: true,
|
||||
frameworkInstalled: true,
|
||||
model: 'deepseek-v4-flash',
|
||||
baseUrl: 'https://api.deepseek.com',
|
||||
}),
|
||||
{ status: 200, headers: { 'Content-Type': 'application/json' } },
|
||||
),
|
||||
);
|
||||
return Promise.resolve(
|
||||
new Response(JSON.stringify({ sessions: [] }), {
|
||||
status: 200,
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
}),
|
||||
);
|
||||
});
|
||||
vi.stubGlobal('fetch', fetchMock);
|
||||
render(<TuningApp />);
|
||||
fireEvent.change(screen.getByLabelText('访问令牌(仅当前标签页)'), {
|
||||
target: { value: 'training-secret' },
|
||||
});
|
||||
fireEvent.click(screen.getByRole('button', { name: '连接/刷新' }));
|
||||
expect(await screen.findByText(/deepseek-v4-flash/)).toBeInTheDocument();
|
||||
expect(screen.getByText('新建 Unitree-Go2-Flat 调参 Session')).toBeInTheDocument();
|
||||
await waitFor(() => expect(fetchMock).toHaveBeenCalledTimes(2));
|
||||
for (const call of fetchMock.mock.calls) {
|
||||
expect(String(call[0])).not.toContain('training-secret');
|
||||
const init = call[1];
|
||||
expect(init).toBeDefined();
|
||||
expect(new Headers(init?.headers).get('Authorization')).toBe('Bearer training-secret');
|
||||
}
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user