feat(chat): 完善运行状态与权限交互
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
import { fetchAgentRuntimeHealth } from "./agentRuntime";
|
||||
|
||||
const apiFetch = jest.fn();
|
||||
|
||||
jest.mock("@/lib/apiFetch", () => ({
|
||||
apiFetch: (...args: unknown[]) => apiFetch(...args),
|
||||
}));
|
||||
|
||||
describe("fetchAgentRuntimeHealth", () => {
|
||||
beforeEach(() => {
|
||||
apiFetch.mockReset();
|
||||
});
|
||||
|
||||
it("reports ready only after runtime warmup is complete", async () => {
|
||||
apiFetch.mockResolvedValueOnce({
|
||||
ok: true,
|
||||
json: async () => ({
|
||||
ok: true,
|
||||
ready: true,
|
||||
warmed_up: true,
|
||||
runtime: { healthy: true },
|
||||
}),
|
||||
});
|
||||
|
||||
await expect(fetchAgentRuntimeHealth()).resolves.toBe(true);
|
||||
expect(apiFetch).toHaveBeenCalledWith(
|
||||
expect.stringContaining("/health"),
|
||||
expect.objectContaining({
|
||||
method: "GET",
|
||||
projectHeaderMode: "omit",
|
||||
skipAuthRedirect: true,
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it("reports unavailable when runtime health is not ready", async () => {
|
||||
apiFetch.mockResolvedValueOnce({
|
||||
ok: false,
|
||||
json: async () => ({ ok: false, ready: false, warmed_up: true }),
|
||||
});
|
||||
|
||||
await expect(fetchAgentRuntimeHealth()).resolves.toBe(false);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user