The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import { EnvironmentId } from "@t3tools/contracts"; |
| 2 | import { describe, expect, it } from "vite-plus/test"; |
| 3 | |
| 4 | import { resolveFileContextMenuAbsolutePath } from "./fileContextMenu"; |
| 5 | |
| 6 | const BASE_TARGET = { |
| 7 | environmentId: EnvironmentId.make("environment-local"), |
| 8 | filePath: "src/index.ts", |
| 9 | workspaceRoot: "/workspace/project", |
| 10 | }; |
| 11 | |
| 12 | describe("resolveFileContextMenuAbsolutePath", () => { |
| 13 | it("strips the repository prefix when the repo root is nested in the workspace", () => { |
| 14 | expect( |
| 15 | resolveFileContextMenuAbsolutePath({ |
| 16 | ...BASE_TARGET, |
| 17 | workspaceRoot: "/workspace/project/packages/app", |
| 18 | repositoryRoot: "/workspace/project", |
| 19 | filePath: "packages/app/src/index.ts", |
| 20 | }), |
| 21 | ).toBe("/workspace/project/packages/app/src/index.ts"); |
| 22 | }); |
| 23 | |
| 24 | it("returns null for paths outside the workspace when a repository root is set", () => { |
| 25 | expect( |
| 26 | resolveFileContextMenuAbsolutePath({ |
| 27 | ...BASE_TARGET, |
| 28 | workspaceRoot: "/workspace/project/packages/app", |
| 29 | repositoryRoot: "/workspace/project", |
| 30 | filePath: "other/src/index.ts", |
| 31 | }), |
| 32 | ).toBeNull(); |
| 33 | }); |
| 34 | |
| 35 | it("rejects absolute paths without a workspace root, matching diff path resolution", () => { |
| 36 | expect( |
| 37 | resolveFileContextMenuAbsolutePath({ |
| 38 | ...BASE_TARGET, |
| 39 | workspaceRoot: undefined, |
| 40 | filePath: "/absolute/src/index.ts", |
| 41 | }), |
| 42 | ).toBeNull(); |
| 43 | }); |
| 44 | }); |