| 1 | import { SourceControlProviderKind } from "@t3tools/contracts"; |
| 2 | import { assert, it } from "@effect/vitest"; |
| 3 | |
| 4 | import * as AzureDevOpsCli from "@t3tools/source-control-azure-devops/server/AzureDevOpsCli"; |
| 5 | import * as BitbucketApi from "@t3tools/source-control-bitbucket/server/BitbucketApi"; |
| 6 | import * as GitHubApi from "@t3tools/source-control-github/server/GitHubApi"; |
| 7 | import * as SourceControlRateLimit from "@t3tools/source-control-core/server/SourceControlRateLimit"; |
| 8 | import * as GitLabCli from "@t3tools/source-control-gitlab/server/GitLabCli"; |
| 9 | import { azureDevOpsProviderFailure } from "@t3tools/source-control-azure-devops/server/AzureDevOpsPullRequestProvider"; |
| 10 | import { bitbucketProviderFailure } from "@t3tools/source-control-bitbucket/server/BitbucketPullRequestProvider"; |
| 11 | import { gitHubProviderFailure } from "@t3tools/source-control-github/server/GitHubPullRequestProvider"; |
| 12 | import { gitLabProviderFailure } from "@t3tools/source-control-gitlab/server/GitLabPullRequestProvider"; |
| 13 | |
| 14 | const cause = new Error("redacted provider failure"); |
| 15 | |
| 16 | it("classifies rate limits from every pull-request provider", () => { |
| 17 | assert.deepStrictEqual( |
| 18 | gitHubProviderFailure( |
| 19 | new GitHubApi.GitHubApiRateLimitError({ host: "github.com", operation: "execute" }), |
| 20 | ), |
| 21 | { reason: "rate-limited" }, |
| 22 | ); |
| 23 | assert.deepStrictEqual( |
| 24 | gitLabProviderFailure( |
| 25 | new GitLabCli.GitLabCliRateLimitError({ |
| 26 | operation: "execute", |
| 27 | command: "glab", |
| 28 | cwd: "/repo", |
| 29 | cause, |
| 30 | }), |
| 31 | ), |
| 32 | { reason: "rate-limited" }, |
| 33 | ); |
| 34 | assert.deepStrictEqual( |
| 35 | azureDevOpsProviderFailure( |
| 36 | new AzureDevOpsCli.AzureDevOpsCliRateLimitError({ |
| 37 | operation: "execute", |
| 38 | command: "az", |
| 39 | cwd: "/repo", |
| 40 | argumentCount: 1, |
| 41 | cause, |
| 42 | }), |
| 43 | ), |
| 44 | { reason: "rate-limited" }, |
| 45 | ); |
| 46 | assert.deepStrictEqual( |
| 47 | bitbucketProviderFailure( |
| 48 | new BitbucketApi.BitbucketResponseError({ |
| 49 | operation: "request", |
| 50 | status: 429, |
| 51 | responseBodyLength: 0, |
| 52 | retryAt: 120_000, |
| 53 | }), |
| 54 | ), |
| 55 | { reason: "rate-limited", retryAt: 120_000 }, |
| 56 | ); |
| 57 | }); |
| 58 | |
| 59 | it("keeps GitHub's exact retry time", () => { |
| 60 | assert.deepStrictEqual( |
| 61 | gitHubProviderFailure( |
| 62 | new SourceControlRateLimit.SourceControlRateLimitPausedError({ |
| 63 | provider: SourceControlProviderKind.make("github"), |
| 64 | host: "github.com", |
| 65 | retryAt: 1_786_802_400_000, |
| 66 | }), |
| 67 | ), |
| 68 | { reason: "rate-limited", retryAt: 1_786_802_400_000 }, |
| 69 | ); |
| 70 | }); |