reconnectingRemoteWorkspaceLogs.test.ts 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. import { describe, expect, it } from "vitest";
  2. import {
  3. buildRemoteWorkspaceReconnectLogLabelPrefix,
  4. resolveRemoteWorkspaceReconnectLogHistoryIds,
  5. } from "@/root/reconnectingRemoteWorkspaceLogs.js";
  6. describe("reconnecting remote workspace runtime logs", () => {
  7. it("matches reconnecting SSH history entry by runtime log label", () => {
  8. const historyIds = resolveRemoteWorkspaceReconnectLogHistoryIds({
  9. runtimeLabel: "remote-workspace-ssh-github.com-a1b2c3d4-9",
  10. reconnectingEntries: [
  11. {
  12. id: "history-ssh",
  13. target: {
  14. kind: "ssh",
  15. host: "github.com",
  16. username: "git",
  17. },
  18. },
  19. {
  20. id: "history-docker",
  21. target: {
  22. kind: "docker",
  23. container: "zcode-dev",
  24. },
  25. },
  26. ],
  27. });
  28. expect(historyIds).toEqual(["history-ssh"]);
  29. });
  30. it("uses sanitized label prefix for docker container names", () => {
  31. const prefix = buildRemoteWorkspaceReconnectLogLabelPrefix({
  32. kind: "docker",
  33. container: "project/container#1",
  34. });
  35. expect(prefix).toBe("remote-workspace-docker-project-container-1-");
  36. });
  37. it("matches WSL default distro logs", () => {
  38. const historyIds = resolveRemoteWorkspaceReconnectLogHistoryIds({
  39. runtimeLabel: "remote-workspace-wsl-default-b7e89f10-3",
  40. reconnectingEntries: [
  41. {
  42. id: "history-wsl",
  43. target: {
  44. kind: "wsl",
  45. },
  46. },
  47. ],
  48. });
  49. expect(historyIds).toEqual(["history-wsl"]);
  50. });
  51. it("does not guess a workspace when entries share one target prefix without request id", () => {
  52. const historyIds = resolveRemoteWorkspaceReconnectLogHistoryIds({
  53. runtimeLabel: "remote-workspace-ssh-build-host-ff001122-5",
  54. reconnectingEntries: [
  55. {
  56. id: "history-a",
  57. target: {
  58. kind: "ssh",
  59. host: "build host",
  60. username: "dev",
  61. },
  62. },
  63. {
  64. id: "history-b",
  65. target: {
  66. kind: "ssh",
  67. host: "build host",
  68. username: "ops",
  69. },
  70. },
  71. ],
  72. });
  73. expect(historyIds).toEqual([]);
  74. });
  75. it("prefers request id over target prefix when concurrent reconnects share one target", () => {
  76. const historyIds = resolveRemoteWorkspaceReconnectLogHistoryIds({
  77. runtimeLabel: "remote-workspace-ssh-build-host-ff001122-5",
  78. runtimeRequestId: "request-b",
  79. reconnectingEntries: [
  80. {
  81. id: "history-a",
  82. requestId: "request-a",
  83. target: {
  84. kind: "ssh",
  85. host: "build host",
  86. username: "dev",
  87. },
  88. },
  89. {
  90. id: "history-b",
  91. requestId: "request-b",
  92. target: {
  93. kind: "ssh",
  94. host: "build host",
  95. username: "ops",
  96. },
  97. },
  98. ],
  99. });
  100. expect(historyIds).toEqual(["history-b"]);
  101. });
  102. it("matches request-scoped window Host logs without relying on the legacy runtime label", () => {
  103. const historyIds = resolveRemoteWorkspaceReconnectLogHistoryIds({
  104. runtimeLabel: "window-host-7",
  105. runtimeRequestId: "request-ssh",
  106. reconnectingEntries: [
  107. {
  108. id: "history-ssh",
  109. requestId: "request-ssh",
  110. target: {
  111. kind: "ssh",
  112. host: "linux-amd64",
  113. username: "root",
  114. },
  115. },
  116. ],
  117. });
  118. expect(historyIds).toEqual(["history-ssh"]);
  119. });
  120. });