Open History to see the last commit
1import { describe, expect, it } from "vite-plus/test";
2
3import { describePullRequestDiffError } from "./pullRequestDiffError";
4
5describe("describePullRequestDiffError", () => {
6 it("explains the rate limit inside an HTTP transport error without exposing the endpoint", () => {
7 const error =
8 "Failed to fetch remote environment endpoint http://127.0.0.1:49477/api/pull-requests/diff (PullRequestOperationError: Pull request operation diff failed: github requests to github.com are paused until the rate limit resets.).";
9 const result = describePullRequestDiffError(error, "GitHub", "pull request");
10
11 expect(result.title).toBe("GitHub rate limit reached");
12 expect(result.description).toContain("after the limit resets");
13 expect(result.description).not.toContain("127.0.0.1");
14 expect(result.description).not.toContain("PullRequestOperationError");
15 });
16
17 // regression: #19945 diff load failures from a provider quota showed a generic error
18 it("recognizes a provider's API quota error", () => {
19 expect(
20 describePullRequestDiffError("GitHub API rate limit exceeded.", "GitHub", "pull request")
21 .title,
22 ).toBe("GitHub rate limit reached");
23 });
24
25 it("does not blame a rate limit for an unknown connection failure", () => {
26 const result = describePullRequestDiffError(
27 "Failed to fetch remote environment endpoint http://localhost:49477/api/pull-requests/diff (TypeError: Failed to fetch).",
28 "GitHub",
29 "pull request",
30 );
31
32 expect(result.title).toBe("Couldn't load the changes");
33 expect(result.description).toContain("Try again");
34 expect(result.description).not.toContain("localhost");
35 expect(result.description).not.toContain("limit");
36 });
37});