The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 04:45 UTC
| 1 | import { |
| 2 | EnvironmentId, |
| 3 | managedCapabilityDenial, |
| 4 | type ManagedPolicySummary, |
| 5 | } from "@t3tools/contracts"; |
| 6 | import { describe, expect, it, vi } from "vite-plus/test"; |
| 7 | |
| 8 | import "~/index.css"; |
| 9 | import { render } from "../../../test/render"; |
| 10 | import { AuthorizedClientsHeaderAction } from "./AuthorizedClientsSettings"; |
| 11 | |
| 12 | const localId = EnvironmentId.make("local"); |
| 13 | const serviceId = EnvironmentId.make("service"); |
| 14 | |
| 15 | const state = vi.hoisted(() => ({ |
| 16 | primaryEnvironmentId: null as string | null, |
| 17 | policies: new Map<string, unknown>(), |
| 18 | })); |
| 19 | |
| 20 | vi.mock(import("../../state/environments"), async (original) => ({ |
| 21 | ...(await original()), |
| 22 | usePrimaryEnvironmentId: (() => state.primaryEnvironmentId) as never, |
| 23 | })); |
| 24 | vi.mock(import("../../state/entities"), async (original) => ({ |
| 25 | ...(await original()), |
| 26 | useServerConfigs: (() => |
| 27 | new Map( |
| 28 | [...state.policies].map(([environmentId, managedPolicy]) => [ |
| 29 | environmentId, |
| 30 | { managedPolicy }, |
| 31 | ]), |
| 32 | )) as never, |
| 33 | })); |
| 34 | vi.mock(import("../../state/use-atom-command"), async (original) => ({ |
| 35 | ...(await original()), |
| 36 | useAtomCommand: (() => vi.fn()) as never, |
| 37 | })); |
| 38 | |
| 39 | const remoteClientsOff: ManagedPolicySummary = { |
| 40 | organization: "Example Corp", |
| 41 | lockedSettings: [], |
| 42 | limits: { clients: ["desktop"] }, |
| 43 | }; |
| 44 | |
| 45 | function setup(policies: ReadonlyArray<readonly [EnvironmentId, ManagedPolicySummary]>) { |
| 46 | state.primaryEnvironmentId = localId; |
| 47 | state.policies = new Map(policies); |
| 48 | } |
| 49 | |
| 50 | const renderHeader = (environmentId: EnvironmentId) => |
| 51 | render( |
| 52 | <AuthorizedClientsHeaderAction |
| 53 | environmentId={environmentId} |
| 54 | onPairingLinkCreated={() => {}} |
| 55 | clientSessions={null} |
| 56 | isRevokingOtherClients={false} |
| 57 | onRevokeOtherClients={() => {}} |
| 58 | delegatableScopes={[]} |
| 59 | />, |
| 60 | ); |
| 61 | |
| 62 | describe("AuthorizedClientsHeaderAction", () => { |
| 63 | const denial = managedCapabilityDenial(remoteClientsOff, "remoteClients")!; |
| 64 | |
| 65 | it("follows the selected service's policy, not the primary's", async () => { |
| 66 | setup([[serviceId, remoteClientsOff]]); |
| 67 | await using screen = await renderHeader(serviceId); |
| 68 | |
| 69 | await expect.element(screen.getByRole("group", { name: denial })).toBeVisible(); |
| 70 | await expect.element(screen.getByRole("button", { name: "Create link" })).toBeDisabled(); |
| 71 | }); |
| 72 | |
| 73 | it("leaves pairing open on an unmanaged service when the primary is managed", async () => { |
| 74 | setup([[localId, remoteClientsOff]]); |
| 75 | await using screen = await renderHeader(serviceId); |
| 76 | |
| 77 | await expect.element(screen.getByRole("button", { name: "Create link" })).toBeEnabled(); |
| 78 | expect(screen.getByRole("group", { name: denial }).query()).toBeNull(); |
| 79 | }); |
| 80 | }); |