Archived
CrossRelay stage 2: Codex /v1/responses relay, config.toml manager, Codex page
This commit is contained in:
1 parent
404704171d
commit
5112f7ca06
30 files changed
+3539
-72
No files matched your search
@@ -0,0 +1,95 @@
|
||||
import { describe, expect, it, vi, beforeEach } from "vitest";
|
||||
import { screen, waitFor } from "@testing-library/react";
|
||||
import { renderWithProviders } from "@/test/utils";
|
||||
import userEvent from "@testing-library/user-event";
|
||||
|
||||
const listProviders = vi.fn();
|
||||
const applyProvider = vi.fn();
|
||||
const restore = vi.fn();
|
||||
const getStatus = vi.fn();
|
||||
|
||||
vi.mock("@/lib/api", () => ({
|
||||
api: {
|
||||
listProviders: () => listProviders(),
|
||||
createProvider: vi.fn(),
|
||||
updateProvider: vi.fn(),
|
||||
deleteProvider: vi.fn(),
|
||||
applyProvider: (id: string, target: string) => applyProvider(id, target),
|
||||
restore: (input: unknown) => restore(input),
|
||||
getStatus: () => getStatus(),
|
||||
getSettings: vi.fn().mockResolvedValue({ language: "zh-CN", port_mode: "auto", fixed_port: 0 }),
|
||||
updateSettings: vi.fn(),
|
||||
listLogs: vi.fn().mockResolvedValue({ items: [] }),
|
||||
listBackups: vi.fn().mockResolvedValue({ items: [] }),
|
||||
},
|
||||
}));
|
||||
|
||||
import Codex from "./Codex";
|
||||
|
||||
const provider = {
|
||||
id: "p_1",
|
||||
name: "DeepSeek",
|
||||
preset: "deepseek",
|
||||
base_url: "https://api.deepseek.com/v1",
|
||||
api_key: "sk-x",
|
||||
models: { default: "deepseek-chat", sonnet: "deepseek-chat", haiku: "deepseek-chat", opus: "deepseek-chat" },
|
||||
enabled_for_claude: false,
|
||||
enabled_for_codex: false,
|
||||
created_at: "2026-10-18T00:00:00Z",
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
listProviders.mockResolvedValue({ items: [provider] });
|
||||
getStatus.mockResolvedValue({
|
||||
running: true,
|
||||
version: "0.1.0",
|
||||
port: 52917,
|
||||
uptime_sec: 95,
|
||||
active_claude_provider: null,
|
||||
active_codex_provider: null,
|
||||
stats: { requests_total: 0, requests_failed: 0, input_tokens: 0, output_tokens: 0 },
|
||||
language: "zh-CN",
|
||||
port_mode: "auto",
|
||||
fixed_port: 0,
|
||||
});
|
||||
applyProvider.mockResolvedValue({
|
||||
provider,
|
||||
injection: {
|
||||
model_provider: "crossrelay",
|
||||
table: {
|
||||
name: "crossrelay",
|
||||
wire_api: "responses",
|
||||
base_url: "http://127.0.0.1:52917",
|
||||
experimental_bearer_token: "crl_x",
|
||||
requires_openai_auth: "false",
|
||||
},
|
||||
},
|
||||
});
|
||||
restore.mockResolvedValue({ restored_from: "" });
|
||||
});
|
||||
|
||||
describe("Codex page", () => {
|
||||
it("shows the injection status, config path and provider list", async () => {
|
||||
renderWithProviders(<Codex />);
|
||||
expect(await screen.findByText("未注入")).toBeInTheDocument();
|
||||
expect(screen.getByText(/config\.toml/)).toBeInTheDocument();
|
||||
expect(screen.getByText("DeepSeek")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("activates a provider for Codex and previews the injected keys", async () => {
|
||||
const user = userEvent.setup();
|
||||
renderWithProviders(<Codex />);
|
||||
await user.click(await screen.findByRole("button", { name: /激活并写入|Activate & apply/ }));
|
||||
await waitFor(() => expect(applyProvider).toHaveBeenCalledWith("p_1", "codex"));
|
||||
expect(await screen.findByText(/experimental_bearer_token/)).toBeInTheDocument();
|
||||
expect(screen.getByText(/wire_api/)).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("restores the official config", async () => {
|
||||
const user = userEvent.setup();
|
||||
renderWithProviders(<Codex />);
|
||||
await user.click(await screen.findByRole("button", { name: /还原官方配置|Restore official config/ }));
|
||||
await waitFor(() => expect(restore).toHaveBeenCalledWith({ target: "codex" }));
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user