sshHistorySuggestions.test.ts 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import { describe, expect, it } from "vitest";
  2. import type { RemoteWorkspaceSessionEntry } from "@zcode/shared";
  3. import { buildSshConnectionHistorySuggestions } from "@/remote-connection/sshHistorySuggestions.js";
  4. describe("buildSshConnectionHistorySuggestions", () => {
  5. it("dedupes ssh history by recent order and ignores non-ssh entries", () => {
  6. const sessions: RemoteWorkspaceSessionEntry[] = [
  7. {
  8. kind: "remote",
  9. workspacePath: "/workspace/recent",
  10. workspaceIdentity: "remote:ssh:prod.internal:/workspace/recent",
  11. lastOpenedAt: 30,
  12. lastConnectionStatus: "connected",
  13. target: {
  14. kind: "ssh",
  15. host: "prod.internal",
  16. port: 2200,
  17. username: "deploy",
  18. privateKeyPath: "~/.ssh/deploy_ed25519",
  19. },
  20. },
  21. {
  22. kind: "remote",
  23. workspacePath: "/workspace/older",
  24. workspaceIdentity: "remote:ssh:prod.internal:/workspace/older",
  25. lastOpenedAt: 20,
  26. lastConnectionStatus: "connected",
  27. target: {
  28. kind: "ssh",
  29. host: "prod.internal",
  30. port: 2200,
  31. username: "deploy",
  32. privateKeyPath: "~/.ssh/deploy_ed25519",
  33. },
  34. },
  35. {
  36. kind: "remote",
  37. workspacePath: "/workspace/default-port",
  38. workspaceIdentity: "remote:ssh:demo.internal:/workspace/default-port",
  39. lastOpenedAt: 10,
  40. lastConnectionStatus: "connected",
  41. target: {
  42. kind: "ssh",
  43. host: "demo.internal",
  44. username: "root",
  45. },
  46. },
  47. {
  48. kind: "remote",
  49. workspacePath: "/workspace/docker",
  50. workspaceIdentity: "remote:docker:toolbox:/workspace/docker",
  51. lastOpenedAt: 5,
  52. lastConnectionStatus: "connected",
  53. target: {
  54. kind: "docker",
  55. container: "toolbox",
  56. },
  57. },
  58. ];
  59. expect(buildSshConnectionHistorySuggestions(sessions)).toEqual({
  60. hosts: ["prod.internal", "demo.internal"],
  61. ports: ["2200", "22"],
  62. usernames: ["deploy", "root"],
  63. privateKeyPaths: ["~/.ssh/deploy_ed25519"],
  64. });
  65. });
  66. });