huskies: merge 948
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import type { AgentConfigInfo, AgentEvent, AgentInfo } from "./agents";
|
||||
import { agentsApi, subscribeAgentStream } from "./agents";
|
||||
import { installRpcMock } from "./__test_utils__/mockRpcWebSocket";
|
||||
|
||||
const mockFetch = vi.fn();
|
||||
|
||||
@@ -133,26 +134,24 @@ describe("agentsApi", () => {
|
||||
});
|
||||
|
||||
describe("getAgentConfig", () => {
|
||||
it("sends GET to /agents/config and returns config list", async () => {
|
||||
mockFetch.mockResolvedValueOnce(okResponse([sampleConfig]));
|
||||
it("dispatches an agent_config.list RPC and returns the config list", async () => {
|
||||
const rpc = installRpcMock();
|
||||
rpc.respond("agent_config.list", [sampleConfig]);
|
||||
|
||||
const result = await agentsApi.getAgentConfig();
|
||||
|
||||
expect(mockFetch).toHaveBeenCalledWith(
|
||||
"/api/agents/config",
|
||||
expect.objectContaining({}),
|
||||
);
|
||||
expect(rpc.calls).toEqual([
|
||||
{ method: "agent_config.list", params: {} },
|
||||
]);
|
||||
expect(result).toEqual([sampleConfig]);
|
||||
});
|
||||
|
||||
it("uses custom baseUrl when provided", async () => {
|
||||
mockFetch.mockResolvedValueOnce(okResponse([sampleConfig]));
|
||||
it("surfaces RPC errors visibly", async () => {
|
||||
const rpc = installRpcMock();
|
||||
rpc.respondError("agent_config.list", "config not found", "NOT_FOUND");
|
||||
|
||||
await agentsApi.getAgentConfig("http://localhost:3002/api");
|
||||
|
||||
expect(mockFetch).toHaveBeenCalledWith(
|
||||
"http://localhost:3002/api/agents/config",
|
||||
expect.objectContaining({}),
|
||||
await expect(agentsApi.getAgentConfig()).rejects.toThrow(
|
||||
"config not found",
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -183,18 +182,18 @@ describe("agentsApi", () => {
|
||||
});
|
||||
|
||||
describe("error handling", () => {
|
||||
it("throws on non-ok response with body text", async () => {
|
||||
mockFetch.mockResolvedValueOnce(errorResponse(404, "config not found"));
|
||||
it("throws on non-ok HTTP response from startAgent", async () => {
|
||||
mockFetch.mockResolvedValueOnce(errorResponse(404, "story not found"));
|
||||
|
||||
await expect(agentsApi.getAgentConfig()).rejects.toThrow(
|
||||
"config not found",
|
||||
await expect(agentsApi.startAgent("missing_story")).rejects.toThrow(
|
||||
"story not found",
|
||||
);
|
||||
});
|
||||
|
||||
it("throws with status code when no body", async () => {
|
||||
it("throws with status code from startAgent when body is empty", async () => {
|
||||
mockFetch.mockResolvedValueOnce(errorResponse(500, ""));
|
||||
|
||||
await expect(agentsApi.getAgentConfig()).rejects.toThrow(
|
||||
await expect(agentsApi.startAgent("missing_story")).rejects.toThrow(
|
||||
"Request failed (500)",
|
||||
);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user