2ae9b06652
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.
48 lines
1.3 KiB
TypeScript
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",
|
|
});
|
|
});
|
|
});
|