remoteConnectionErrorMessage.test.ts 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import { describe, expect, it } from "vitest";
  2. import {
  3. formatRemoteConnectionError,
  4. shouldShowStandaloneRemoteErrorToast,
  5. } from "@/lib/remoteConnectionPresentation.js";
  6. describe("formatRemoteConnectionError", () => {
  7. const formatMessage = ({ id }: { id: string }) => id;
  8. it("maps public reason codes and preserves the Host retryable contract", () => {
  9. expect(
  10. formatRemoteConnectionError({
  11. fallback: "raw english error",
  12. reasonCode: "source-server-upgrade-required",
  13. retryable: false,
  14. formatMessage,
  15. }),
  16. ).toBe("remote.error.sourceServerUpgradeRequired");
  17. expect(
  18. formatRemoteConnectionError({
  19. fallback: "raw english error",
  20. reasonCode: "workspace-task-identity-conflict",
  21. retryable: true,
  22. formatMessage,
  23. }),
  24. ).toBe("remote.error.workspaceTaskIdentityConflict remote.error.retryableHint");
  25. });
  26. it("未知错误码回退到通用翻译", () => {
  27. expect(
  28. formatRemoteConnectionError({
  29. fallback: "socket closed",
  30. reasonCode: "private-internal-code",
  31. formatMessage,
  32. }),
  33. ).toBe("remote.error.unknown");
  34. });
  35. it("interpolates recovery attempt values for a budget exhaustion code", () => {
  36. expect(
  37. formatRemoteConnectionError({
  38. fallback: "socket closed",
  39. reasonCode: "remote-recovery-budget-exhausted",
  40. recoveryAttempt: 3,
  41. recoveryLimit: 3,
  42. formatMessage: ({ id }, values) =>
  43. id === "remote.error.recoveryBudgetExhausted"
  44. ? `stopped after ${values?.attempt}/${values?.limit}`
  45. : id,
  46. }),
  47. ).toBe("stopped after 3/3");
  48. });
  49. it("版本阻断交给带更新动作的权威提示,不再弹裸错误", () => {
  50. expect(shouldShowStandaloneRemoteErrorToast("source-server-upgrade-required")).toBe(false);
  51. expect(shouldShowStandaloneRemoteErrorToast("remote-bind-canceled")).toBe(true);
  52. });
  53. });