The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import { describe, expect, it } from "@effect/vitest"; |
| 2 | |
| 3 | import { deriveAssetUrlState } from "./asset-url-state"; |
| 4 | |
| 5 | const SUCCESS = { |
| 6 | _tag: "Success" as const, |
| 7 | url: "https://environment.example/api/assets/abc", |
| 8 | expiresAt: Number.MAX_SAFE_INTEGER, |
| 9 | }; |
| 10 | |
| 11 | describe("deriveAssetUrlState", () => { |
| 12 | it("stops waiting once the environment is offline, retrying, or in error", () => { |
| 13 | for (const connectionPhase of ["offline", "reconnecting", "error"] as const) { |
| 14 | expect(deriveAssetUrlState({ connectionPhase, shared: { _tag: "Loading" } })).toEqual({ |
| 15 | _tag: "Failure", |
| 16 | reason: "disconnected", |
| 17 | }); |
| 18 | } |
| 19 | }); |
| 20 | |
| 21 | // regression: #9123 show an error instead of an endless preview spinner |
| 22 | it("reports disconnected when the query failed while the environment is down", () => { |
| 23 | for (const connectionPhase of ["available", "offline", "reconnecting", "error"] as const) { |
| 24 | expect(deriveAssetUrlState({ connectionPhase, shared: { _tag: "Failure" } })).toEqual({ |
| 25 | _tag: "Failure", |
| 26 | reason: "disconnected", |
| 27 | }); |
| 28 | } |
| 29 | }); |
| 30 | |
| 31 | it("does not hand out a resolved URL for a disconnected environment", () => { |
| 32 | for (const connectionPhase of ["offline", "reconnecting", "error"] as const) { |
| 33 | expect(deriveAssetUrlState({ connectionPhase, shared: SUCCESS })).toEqual({ |
| 34 | _tag: "Failure", |
| 35 | reason: "disconnected", |
| 36 | }); |
| 37 | } |
| 38 | }); |
| 39 | }); |