Open History to see the last commit
1import { RegistryContext } from "@effect/atom-react";
2import { EnvironmentId, ProviderDriverKind, ProviderInstanceId } from "@t3tools/contracts";
3import { AsyncResult, Atom } from "effect/reactivity";
4import { expect, it, vi } from "vite-plus/test";
5
6import "~/index.css";
7import { render } from "../../../test/render";
8
9const state = vi.hoisted(() => ({
10 mutateProviderInstance: vi.fn(),
11 config: null as unknown,
12}));
13
14vi.mock(import("../../state/server"), async (original) => {
15 const actual = await original();
16 return {
17 ...actual,
18 serverEnvironment: {
19 ...actual.serverEnvironment,
20 configValueAtom: (() => state.config) as never,
21 mutateProviderInstance: "mutateProviderInstance" as never,
22 },
23 };
24});
25vi.mock(import("../../state/use-atom-command"), async (original) => ({
26 ...(await original()),
27 useAtomCommand: ((command: "mutateProviderInstance") => state[command]) as never,
28}));
29
30import { appAtomRegistry } from "../../rpc/atomRegistry";
31import { UsageAccessQuestion, type UsageAccessPrompt } from "./UsageAccessDialog";
32
33const environmentId = EnvironmentId.make("primary");
34const prompt = (driver: string): UsageAccessPrompt => ({
35 environmentId,
36 environmentLabel: "cups",
37 instanceId: ProviderInstanceId.make(driver),
38 driver: ProviderDriverKind.make(driver),
39});
40
41it("says what each agent's access reads and saves only the agents left on", async () => {
42 state.config = Atom.make({ settings: { providerInstances: {} } });
43 state.mutateProviderInstance.mockReset().mockResolvedValue(AsyncResult.success(undefined));
44 await using screen = await render(
45 <RegistryContext.Provider value={appAtomRegistry}>
46 <UsageAccessQuestion prompts={[prompt("claudeAgent"), prompt("codex")]} />
47 </RegistryContext.Provider>,
48 );
49 await expect.element(screen.getByText("Session history and sign-in")).toBeVisible();
50 await expect.element(screen.getByText("Session history", { exact: true })).toBeVisible();
51
52 await screen.getByRole("switch", { name: /Codex/ }).click();
53 await screen.getByRole("button", { name: "Allow", exact: true }).click();
54 await vi.waitFor(() => expect(state.mutateProviderInstance).toHaveBeenCalledTimes(2));
55
56 const saved = state.mutateProviderInstance.mock.calls.map(
57 ([call]) => call.input.providerInstanceMutation.instance,
58 );
59 expect(saved).toEqual([
60 { driver: "claudeAgent", usageAccess: "allowed" },
61 { driver: "codex", usageAccess: "denied" },
62 ]);
63});