import { describe, expect, it } from "bun:test"; import { ApiError } from "./api"; import { hostedRoute, retryableChannelFailure } from "./hosted"; describe("hosted routes", () => { it("recognizes repository and channel routes", () => { expect(hostedRoute("/")).toEqual({ page: "repositories" }); expect(hostedRoute("/repositories/octo-org/score")).toEqual({ page: "repository", owner: "octo-org", repository: "score", }); expect(hostedRoute("/repositories/github%20next/chopin")).toEqual({ page: "repository", owner: "github next", repository: "chopin", }); expect(hostedRoute("/channels/019c1234-1234-4123-8123-123456789abc")).toEqual({ page: "channel", id: "019c1234-1234-4123-8123-123456789abc", }); expect(hostedRoute("/channels/019c1234-1234-5123-8123-123456789abc")).toEqual({ page: "channel", id: "019c1234-1234-5123-8123-123456789abc", }); expect(hostedRoute("/plans/main")).toEqual({ page: "missing" }); }); }); describe("channel recovery", () => { it("retries only failures a repeated channel read can recover from", () => { expect(retryableChannelFailure(new Error("network unavailable"))).toBe(true); expect(retryableChannelFailure(new ApiError("request timed out", 408))).toBe(true); expect(retryableChannelFailure(new ApiError("too many requests", 429))).toBe(true); expect(retryableChannelFailure(new ApiError("storage unavailable", 503))).toBe(true); expect(retryableChannelFailure(new ApiError("channel not found", 404))).toBe(false); expect(retryableChannelFailure(new ApiError("repository access is required", 403))) .toBe(false); }); });