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 type { EnvironmentCloudLinkStateResult } from "@t3tools/contracts"; |
| 2 | import { describe, expect, it } from "vite-plus/test"; |
| 3 | |
| 4 | import { cloudChangeReplacesLink } from "./t3ConnectState"; |
| 5 | |
| 6 | function linkState(input: { |
| 7 | readonly linked: boolean; |
| 8 | readonly tunnel: boolean; |
| 9 | readonly revoked?: boolean; |
| 10 | }): EnvironmentCloudLinkStateResult { |
| 11 | return { |
| 12 | linked: input.linked, |
| 13 | cloudUserId: input.linked ? "user" : null, |
| 14 | relayUrl: input.linked ? "https://relay.example.test" : null, |
| 15 | relayIssuer: null, |
| 16 | managedTunnelActive: input.tunnel, |
| 17 | publishAgentActivity: input.linked, |
| 18 | linkRevoked: input.revoked ?? false, |
| 19 | }; |
| 20 | } |
| 21 | |
| 22 | describe("cloudChangeReplacesLink", () => { |
| 23 | it.each([ |
| 24 | { |
| 25 | name: "linking a tunnel", |
| 26 | state: { linked: false, tunnel: false }, |
| 27 | tunnel: true, |
| 28 | publish: false, |
| 29 | expected: true, |
| 30 | }, |
| 31 | { |
| 32 | name: "linking publish-only", |
| 33 | state: { linked: false, tunnel: false }, |
| 34 | tunnel: false, |
| 35 | publish: true, |
| 36 | expected: true, |
| 37 | }, |
| 38 | { |
| 39 | name: "repairing a revoked link", |
| 40 | state: { linked: true, tunnel: true, revoked: true }, |
| 41 | tunnel: true, |
| 42 | publish: true, |
| 43 | expected: true, |
| 44 | }, |
| 45 | { |
| 46 | name: "dropping the tunnel but keeping publish", |
| 47 | state: { linked: true, tunnel: true }, |
| 48 | tunnel: false, |
| 49 | publish: true, |
| 50 | expected: true, |
| 51 | }, |
| 52 | { |
| 53 | name: "adding a tunnel to a publish-only link", |
| 54 | state: { linked: true, tunnel: false }, |
| 55 | tunnel: true, |
| 56 | publish: true, |
| 57 | expected: true, |
| 58 | }, |
| 59 | { |
| 60 | name: "unlinking", |
| 61 | state: { linked: true, tunnel: true }, |
| 62 | tunnel: false, |
| 63 | publish: false, |
| 64 | expected: false, |
| 65 | }, |
| 66 | { |
| 67 | name: "toggling publish on a tunnel link", |
| 68 | state: { linked: true, tunnel: true }, |
| 69 | tunnel: true, |
| 70 | publish: false, |
| 71 | expected: false, |
| 72 | }, |
| 73 | ])("$name → $expected", ({ state, tunnel, publish, expected }) => { |
| 74 | expect( |
| 75 | cloudChangeReplacesLink(linkState(state), undefined, { managedTunnel: tunnel, publish }), |
| 76 | ).toBe(expected); |
| 77 | }); |
| 78 | }); |