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 { describe, expect, it } from "vite-plus/test"; |
| 2 | import type { EnvironmentProject } from "@t3tools/client-runtime/state/models"; |
| 3 | import type { EnvironmentConnectionPhase } from "@t3tools/client-runtime/connection"; |
| 4 | import { EnvironmentId } from "@t3tools/contracts"; |
| 5 | import { pullRequestFallbackEnvironment } from "./pullRequestEnvironmentFallback"; |
| 6 | |
| 7 | const project = (environmentId: string, id: string, canonicalKey: string) => |
| 8 | ({ |
| 9 | environmentId, |
| 10 | id, |
| 11 | repositoryIdentity: { canonicalKey }, |
| 12 | }) as unknown as EnvironmentProject; |
| 13 | |
| 14 | const projects = [ |
| 15 | project("laptop", "t3", "github.com/pingdotgg/t3code"), |
| 16 | project("desktop", "other", "github.com/pingdotgg/other"), |
| 17 | project("server", "t3-copy", "github.com/pingdotgg/t3code"), |
| 18 | ]; |
| 19 | const target = { |
| 20 | environmentId: "laptop", |
| 21 | projectId: "t3", |
| 22 | repository: "pingdotgg/t3code", |
| 23 | host: "github.com", |
| 24 | }; |
| 25 | const environment = ( |
| 26 | environmentId: string, |
| 27 | connectionState: EnvironmentConnectionPhase = "connected", |
| 28 | isEnabled = true, |
| 29 | ) => ({ environmentId: EnvironmentId.make(environmentId), connectionState, isEnabled }); |
| 30 | |
| 31 | describe("pullRequestFallbackEnvironment", () => { |
| 32 | it("moves to a connected copy of the repository when the original is down", () => { |
| 33 | expect( |
| 34 | pullRequestFallbackEnvironment(target, projects, [ |
| 35 | environment("desktop"), |
| 36 | environment("server"), |
| 37 | ]), |
| 38 | ).toEqual({ environmentId: "server", projectId: "t3-copy" }); |
| 39 | }); |
| 40 | |
| 41 | it("stays put while the original is connected or nothing else holds the repository", () => { |
| 42 | expect( |
| 43 | pullRequestFallbackEnvironment(target, projects, [ |
| 44 | environment("laptop"), |
| 45 | environment("server"), |
| 46 | ]), |
| 47 | ).toBe(null); |
| 48 | expect(pullRequestFallbackEnvironment(target, projects, [environment("desktop")])).toBe(null); |
| 49 | }); |
| 50 | |
| 51 | it("derives the host from the original project when the route has none", () => { |
| 52 | const { host: _host, ...hostless } = target; |
| 53 | expect(pullRequestFallbackEnvironment(hostless, projects, [environment("server")])).toEqual({ |
| 54 | environmentId: "server", |
| 55 | projectId: "t3-copy", |
| 56 | }); |
| 57 | }); |
| 58 | }); |