mirror of
https://github.com/farion1231/cc-switch.git
synced 2026-10-25 17:22:27 +08:00
Aggregation mode used to strip [agents] default_subagent_model, so Codex sub-agents always followed the main model (#8286). Users can now choose a sub-agent model and reasoning effort for aggregation, both in the "Switch to Aggregation" dialog and in a new Aggregation settings sheet on the Stack tab. - The choice is a device setting (settings.json). On every rewrite it is checked against the merged model catalog: an id that is no longer published (member removed, or it is now the default provider) is not written, so sub-agents fall back to the main model instead of every spawn failing, and it comes back when the member is re-added. An effort the model does not support is dropped. - Codex reads [agents] when a thread starts: new conversations pick up a change without a restart; open ones keep the old value. - The classic sub-agent tools toggle moves from Settings into the sheet and is now on by default: with the newer tools the main agent's provider encrypts the task and a sub-agent on another provider gets nothing (#8253). It is stored under a new key, codexStackClassicTools; the old codexStackClassicSubagents key was written as false on every save since v4.0.10, so it is no longer read. - Docs and the four locales updated.
136 lines
4.5 KiB
TypeScript
136 lines
4.5 KiB
TypeScript
import {
|
|
act,
|
|
render,
|
|
screen,
|
|
fireEvent,
|
|
waitFor,
|
|
} from "@testing-library/react";
|
|
import { describe, it, expect, vi, beforeEach } from "vitest";
|
|
import { CodexAuthSettings } from "@/components/settings/CodexAuthSettings";
|
|
import type { SettingsFormState } from "@/hooks/useSettings";
|
|
|
|
vi.mock("react-i18next", () => ({
|
|
useTranslation: () => ({
|
|
t: (key: string, options?: Record<string, unknown>) =>
|
|
options?.size ? `${key}:${options.size}` : key,
|
|
}),
|
|
}));
|
|
|
|
const forcesMultiAgentV2Mock = vi.fn();
|
|
const getCompressionMock = vi.fn();
|
|
const setCompressionMock = vi.fn();
|
|
const diskUsageMock = vi.fn();
|
|
|
|
vi.mock("@/lib/api", () => ({
|
|
settingsApi: {
|
|
codexForcesMultiAgentV2: () => forcesMultiAgentV2Mock(),
|
|
hasCodexUnifyHistoryBackup: vi.fn().mockResolvedValue(false),
|
|
restoreCodexUnifiedHistory: vi.fn(),
|
|
getCodexSessionCompression: () => getCompressionMock(),
|
|
setCodexSessionCompression: (enabled: boolean) =>
|
|
setCompressionMock(enabled),
|
|
getCodexSessionsDiskUsage: () => diskUsageMock(),
|
|
},
|
|
}));
|
|
|
|
const LABEL = "settings.codexStackClassicSubagents";
|
|
|
|
/** 挂载后把读取 config.toml / 会话占用的异步更新一并冲刷掉 */
|
|
async function renderWith(classic: boolean, onChange = vi.fn()) {
|
|
await act(async () => {
|
|
render(
|
|
<CodexAuthSettings
|
|
settings={{ codexStackClassicTools: classic } as SettingsFormState}
|
|
onChange={onChange}
|
|
/>,
|
|
);
|
|
});
|
|
return onChange;
|
|
}
|
|
|
|
describe("CodexAuthSettings classic sub-agent toggle", () => {
|
|
beforeEach(() => {
|
|
forcesMultiAgentV2Mock.mockReset();
|
|
getCompressionMock.mockResolvedValue(false);
|
|
diskUsageMock.mockResolvedValue(0);
|
|
});
|
|
|
|
// 开关挪到了 Codex 聚合页签的「聚合设置」(StackSettingsSheet),设置页不再显示
|
|
it("is no longer on the settings page", async () => {
|
|
await renderWith(true);
|
|
|
|
expect(
|
|
screen.queryByRole("switch", { name: LABEL }),
|
|
).not.toBeInTheDocument();
|
|
expect(forcesMultiAgentV2Mock).not.toHaveBeenCalled();
|
|
});
|
|
});
|
|
|
|
describe("CodexAuthSettings session compression toggle", () => {
|
|
const COMPRESSION = "settings.codexSessionCompression";
|
|
|
|
beforeEach(() => {
|
|
forcesMultiAgentV2Mock.mockResolvedValue(false);
|
|
getCompressionMock.mockReset();
|
|
setCompressionMock.mockReset();
|
|
diskUsageMock.mockReset();
|
|
});
|
|
|
|
it("reflects config.toml and shows the sessions disk usage", async () => {
|
|
getCompressionMock.mockResolvedValue(true);
|
|
diskUsageMock.mockResolvedValue(3 * 1024 * 1024 * 1024);
|
|
const onChange = await renderWith(false);
|
|
|
|
const toggle = screen.getByRole("switch", { name: COMPRESSION });
|
|
await waitFor(() => expect(toggle).toHaveAttribute("aria-checked", "true"));
|
|
expect(
|
|
await screen.findByText("settings.codexSessionCompressionUsage:3.00 GB"),
|
|
).toBeInTheDocument();
|
|
expect(onChange).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it("re-reads config.toml after the saved Codex directory changes", async () => {
|
|
getCompressionMock.mockResolvedValue(false);
|
|
diskUsageMock.mockResolvedValue(1024);
|
|
const props = {
|
|
settings: {} as SettingsFormState,
|
|
onChange: vi.fn(),
|
|
};
|
|
let rerender!: (ui: React.ReactElement) => void;
|
|
await act(async () => {
|
|
({ rerender } = render(
|
|
<CodexAuthSettings {...props} codexConfigDir="/old/codex" />,
|
|
));
|
|
});
|
|
const toggle = screen.getByRole("switch", { name: COMPRESSION });
|
|
expect(toggle).toHaveAttribute("aria-checked", "false");
|
|
|
|
getCompressionMock.mockResolvedValue(true);
|
|
diskUsageMock.mockResolvedValue(2 * 1024 * 1024 * 1024);
|
|
await act(async () => {
|
|
rerender(<CodexAuthSettings {...props} codexConfigDir="/new/codex" />);
|
|
});
|
|
|
|
expect(toggle).toHaveAttribute("aria-checked", "true");
|
|
expect(
|
|
screen.getByText("settings.codexSessionCompressionUsage:2.00 GB"),
|
|
).toBeInTheDocument();
|
|
expect(getCompressionMock).toHaveBeenCalledTimes(2);
|
|
});
|
|
|
|
it("writes the feature through its own command, not the settings form", async () => {
|
|
getCompressionMock.mockResolvedValue(false);
|
|
diskUsageMock.mockResolvedValue(0);
|
|
setCompressionMock.mockResolvedValue(true);
|
|
const onChange = await renderWith(false);
|
|
|
|
const toggle = screen.getByRole("switch", { name: COMPRESSION });
|
|
await waitFor(() => expect(getCompressionMock).toHaveBeenCalled());
|
|
fireEvent.click(toggle);
|
|
|
|
await waitFor(() => expect(toggle).toHaveAttribute("aria-checked", "true"));
|
|
expect(setCompressionMock).toHaveBeenCalledWith(true);
|
|
expect(onChange).not.toHaveBeenCalled();
|
|
});
|
|
});
|