Spaces:
Paused
Paused
File size: 4,602 Bytes
4e7644b | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 | import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
vi.mock("../request", () => ({
request: vi.fn(),
}));
import { agentApi } from "./agent";
import { request } from "../request";
describe("agentApi", () => {
beforeEach(() => {
vi.mocked(request).mockResolvedValue(undefined);
});
afterEach(() => {
vi.clearAllMocks();
});
it("agentRoot calls GET /agent/", async () => {
vi.mocked(request).mockResolvedValue({ status: "ok" });
const result = await agentApi.agentRoot();
expect(request).toHaveBeenCalledWith("/agent/");
expect(result).toEqual({ status: "ok" });
});
it("healthCheck calls GET /agent/health", async () => {
vi.mocked(request).mockResolvedValue({ healthy: true });
const result = await agentApi.healthCheck();
expect(request).toHaveBeenCalledWith("/agent/health");
expect(result).toEqual({ healthy: true });
});
it("agentApi sends POST to /agent/process with body", async () => {
const body = { message: "hello", session_id: "s1" };
await agentApi.agentApi(body as any);
expect(request).toHaveBeenCalledWith("/console/chat", {
method: "POST",
body: JSON.stringify(body),
});
});
it("getProcessStatus calls GET /agent/admin/status", async () => {
vi.mocked(request).mockResolvedValue({ running: true });
const result = await agentApi.getProcessStatus();
expect(request).toHaveBeenCalledWith("/agent/admin/status");
expect(result).toEqual({ running: true });
});
it("shutdown sends POST to /agent/admin/shutdown", async () => {
await agentApi.shutdown();
expect(request).toHaveBeenCalledWith("/agent/admin/shutdown", {
method: "POST",
});
});
it("getAgentRunningConfig calls GET /agent/running-config", async () => {
const config = { agents: [] };
vi.mocked(request).mockResolvedValue(config);
const result = await agentApi.getAgentRunningConfig();
expect(request).toHaveBeenCalledWith("/workspace/running-config");
expect(result).toEqual(config);
});
it("updateAgentRunningConfig sends PUT with config body", async () => {
const config = { agents: [{ name: "test" }] } as any;
vi.mocked(request).mockResolvedValue(config);
const result = await agentApi.updateAgentRunningConfig(config);
expect(request).toHaveBeenCalledWith("/workspace/running-config", {
method: "PUT",
body: JSON.stringify(config),
timeout: 10 * 60 * 1000,
});
expect(result).toEqual(config);
});
it("testEmbedding sends unsaved embedding config", async () => {
const config = {
backend: "openai" as const,
api_key: "key",
base_url: "https://example.com/v1",
model_name: "embedding-model",
dimensions: 1024,
enable_cache: true,
use_dimensions: false,
max_cache_size: 10000,
max_input_length: 8192,
max_batch_size: 10,
};
await agentApi.testEmbedding(config);
expect(request).toHaveBeenCalledWith("/workspace/embedding/test", {
method: "POST",
body: JSON.stringify(config),
timeout: 30 * 1000,
});
});
it("updateAgentLanguage sends PUT with language in body", async () => {
vi.mocked(request).mockResolvedValue({
language: "zh",
copied_files: ["a.txt"],
});
const result = await agentApi.updateAgentLanguage("zh");
expect(request).toHaveBeenCalledWith("/workspace/language", {
method: "PUT",
body: JSON.stringify({ language: "zh" }),
});
expect(result).toEqual({ language: "zh", copied_files: ["a.txt"] });
});
it("updateAudioMode sends PUT with audio_mode in body", async () => {
await agentApi.updateAudioMode("push_to_talk");
expect(request).toHaveBeenCalledWith("/workspace/audio-mode", {
method: "PUT",
body: JSON.stringify({ audio_mode: "push_to_talk" }),
});
});
it("getLocalWhisperStatus calls GET /agent/local-whisper-status", async () => {
const status = {
available: true,
ffmpeg_installed: true,
whisper_installed: true,
};
vi.mocked(request).mockResolvedValue(status);
const result = await agentApi.getLocalWhisperStatus();
expect(request).toHaveBeenCalledWith("/workspace/local-whisper-status");
expect(result).toEqual(status);
});
it("updateTranscriptionProvider sends PUT with provider_id", async () => {
await agentApi.updateTranscriptionProvider("openai");
expect(request).toHaveBeenCalledWith("/workspace/transcription-provider", {
method: "PUT",
body: JSON.stringify({ provider_id: "openai" }),
});
});
});
|