sourceServerRecoveryPolicy.test.ts 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. import { describe, expect, it } from "vitest";
  2. import { createSourceServerRecoveryCloseEvent } from "../src/host/sourceServerRecoveryPolicy.js";
  3. const profileId = "17ef20b3-622d-4a53-98c1-0cdff29f3e6d";
  4. describe("Source Server recovery policy", () => {
  5. it("projects installation confirmation as a terminal logical close", () => {
  6. expect(
  7. createSourceServerRecoveryCloseEvent({
  8. profileId,
  9. state: "needs-install",
  10. errorCode: "source-server-install-required",
  11. retryable: false,
  12. updatedAt: 1,
  13. }),
  14. ).toEqual({
  15. exitCode: null,
  16. signal: null,
  17. recoverable: false,
  18. reasonCode: "source-server-install-required",
  19. retryable: false,
  20. });
  21. });
  22. it("preserves retry progress and budget exhaustion metadata", () => {
  23. expect(
  24. createSourceServerRecoveryCloseEvent({
  25. profileId,
  26. state: "retrying",
  27. recoveryAttempt: 2,
  28. recoveryLimit: 3,
  29. updatedAt: 1,
  30. }),
  31. ).toEqual({
  32. exitCode: null,
  33. signal: null,
  34. recoverable: true,
  35. recoveryAttempt: 2,
  36. recoveryLimit: 3,
  37. });
  38. expect(
  39. createSourceServerRecoveryCloseEvent({
  40. profileId,
  41. state: "offline",
  42. error: "network unavailable",
  43. errorCode: "remote-recovery-budget-exhausted",
  44. recoveryAttempt: 3,
  45. recoveryLimit: 3,
  46. recoveryBudgetExhausted: true,
  47. retryable: true,
  48. updatedAt: 2,
  49. }),
  50. ).toEqual({
  51. exitCode: null,
  52. signal: null,
  53. recoverable: false,
  54. error: "network unavailable",
  55. recoveryAttempt: 3,
  56. recoveryLimit: 3,
  57. recoveryBudgetExhausted: true,
  58. reasonCode: "remote-recovery-budget-exhausted",
  59. retryable: true,
  60. });
  61. });
  62. it("projects only non-retryable failures as terminal closes", () => {
  63. expect(
  64. createSourceServerRecoveryCloseEvent({
  65. profileId,
  66. state: "failed",
  67. error: "user action required",
  68. retryable: false,
  69. updatedAt: 1,
  70. }),
  71. ).toEqual({
  72. exitCode: null,
  73. signal: null,
  74. recoverable: false,
  75. error: "user action required",
  76. retryable: false,
  77. });
  78. expect(
  79. createSourceServerRecoveryCloseEvent({
  80. profileId,
  81. state: "failed",
  82. error: "transient",
  83. retryable: true,
  84. updatedAt: 2,
  85. }),
  86. ).toBeUndefined();
  87. expect(
  88. createSourceServerRecoveryCloseEvent({
  89. profileId,
  90. state: "online",
  91. updatedAt: 3,
  92. }),
  93. ).toBeUndefined();
  94. });
  95. });