Files
AgentHub/client/src/lib/__tests__/codexConfigApi.test.ts
T
nntrivi2001 2ae9b06652 feat(codex): add the codexConfig API namespace
Adds a typed client wrapper for the Codex config API alongside ccConfig,
with methods for reading/writing skills, agents, rules, memory, config,
MCP servers, plugins, and marketplaces. Mirrors ccConfig construction and
error handling. All response shapes match the server's wire format.
2026-09-08 20:20:59 +07:00

48 lines
1.3 KiB
TypeScript

/**
* @file Pins the codexConfig API routes and payloads. Tests that the client
* sends the right method, URL, and body shape to the Codex config backend.
* @author Nguyễn Ngọc Trí Vĩ <vinnt@smartgift.vn>
*/
import { describe, it, expect, vi, afterEach } from "vitest";
import { api } from "../api";
afterEach(() => {
vi.unstubAllGlobals();
});
function stubFetch(response: unknown) {
const spy = vi.fn().mockResolvedValue({
ok: true,
status: 200,
headers: { get: () => "application/json" },
json: async () => response,
text: async () => JSON.stringify(response),
});
vi.stubGlobal("fetch", spy);
return spy;
}
describe("api.codexConfig", () => {
it("sends a write as a single PUT with the artifact envelope", async () => {
const spy = stubFetch({ ok: true, file: "/x", created: true });
await api.codexConfig.write({
scope: "user",
type: "rules",
name: "default",
content: "allow",
});
expect(spy).toHaveBeenCalledTimes(1);
const [, options] = spy.mock.calls[0] as [string, RequestInit | undefined];
expect(options?.method).toBe("PUT");
expect(JSON.parse(options?.body as string)).toEqual({
scope: "user",
type: "rules",
name: "default",
content: "allow",
});
});
});