modelProviderConnectivityTarget.test.ts 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. import { describe, expect, it } from "vitest";
  2. import { resolveModelProviderConnectivityWorkspacePath } from "@/lib/modelProviderConnectivityTarget.js";
  3. describe("Model Provider connectivity target", () => {
  4. it("uses the active local workspace", () => {
  5. expect(
  6. resolveModelProviderConnectivityWorkspacePath({
  7. activeWorkspacePath: "/local/active",
  8. activeWorkspaceIdentity: undefined,
  9. activeWorkspaceTab: { workspacePath: "/local/active" },
  10. workspaceTabs: [{ workspacePath: "/local/active" }],
  11. }),
  12. ).toBe("/local/active");
  13. });
  14. it("uses a remote tab's remembered local workspace when available", () => {
  15. expect(
  16. resolveModelProviderConnectivityWorkspacePath({
  17. activeWorkspacePath: "/remote/project",
  18. activeWorkspaceIdentity: "remote:ssh:host:/remote/project",
  19. activeWorkspaceTab: {
  20. workspacePath: "/remote/project",
  21. workspaceIdentity: "remote:ssh:host:/remote/project",
  22. localWorkspacePath: "/local/source",
  23. },
  24. workspaceTabs: [],
  25. }),
  26. ).toBe("/local/source");
  27. });
  28. it("returns empty when a remote tab has no local workspace", () => {
  29. expect(
  30. resolveModelProviderConnectivityWorkspacePath({
  31. activeWorkspacePath: "/remote/project",
  32. activeWorkspaceIdentity: "remote:ssh:host:/remote/project",
  33. activeWorkspaceTab: {
  34. workspacePath: "/remote/project",
  35. workspaceIdentity: "remote:ssh:host:/remote/project",
  36. },
  37. workspaceTabs: [
  38. {
  39. workspacePath: "/remote/other",
  40. workspaceIdentity: "remote:ssh:other:/remote/other",
  41. },
  42. ],
  43. }),
  44. ).toBe("");
  45. });
  46. it("returns empty when a remote session tab has no identity or local workspace", () => {
  47. expect(
  48. resolveModelProviderConnectivityWorkspacePath({
  49. activeWorkspacePath: "/remote/project",
  50. activeWorkspaceIdentity: undefined,
  51. activeWorkspaceTab: {
  52. workspacePath: "/remote/project",
  53. remoteSessionId: "remote-session",
  54. },
  55. workspaceTabs: [],
  56. }),
  57. ).toBe("");
  58. });
  59. it("returns empty when a remote target tab has no identity or local workspace", () => {
  60. expect(
  61. resolveModelProviderConnectivityWorkspacePath({
  62. activeWorkspacePath: "/remote/project",
  63. activeWorkspaceIdentity: undefined,
  64. activeWorkspaceTab: {
  65. workspacePath: "/remote/project",
  66. remoteTarget: { kind: "ssh" },
  67. },
  68. workspaceTabs: [],
  69. }),
  70. ).toBe("");
  71. });
  72. it("treats a whitespace-only remote session id as local metadata", () => {
  73. expect(
  74. resolveModelProviderConnectivityWorkspacePath({
  75. activeWorkspacePath: "/remote/project",
  76. activeWorkspaceIdentity: "remote:ssh:host:/remote/project",
  77. activeWorkspaceTab: {
  78. workspacePath: "/remote/project",
  79. workspaceIdentity: "remote:ssh:host:/remote/project",
  80. },
  81. workspaceTabs: [{ workspacePath: "/local/project", remoteSessionId: " " }],
  82. }),
  83. ).toBe("/local/project");
  84. });
  85. });