|
1 | | -import { SourceControlProviderKind } from "@t3tools/contracts"; |
| 1 | +import { SourceControlProviderKind, VcsProcessExitError } from "@t3tools/contracts"; |
2 | 2 | import * as NodeServices from "@effect/platform-node/NodeServices"; |
3 | 3 | import * as NodeV8 from "node:v8"; |
4 | 4 | import * as NodeVM from "node:vm"; |
5 | 5 | import * as ChildProcessSpawner from "effect/process/ChildProcessSpawner"; |
6 | 6 | import * as KeyValueStore from "effect/persistence/KeyValueStore"; |
7 | | -import { assert, it } from "@effect/vitest"; |
| 7 | +import { assert, expect, it } from "@effect/vitest"; |
8 | 8 | import * as Cause from "effect/Cause"; |
9 | 9 | import * as Clock from "effect/Clock"; |
10 | 10 | import * as Deferred from "effect/Deferred"; |
@@ -7718,63 +7718,84 @@ it.effect.each([ |
7718 | 7718 | }), |
7719 | 7719 | ); |
7720 | 7720 |
|
7721 | | -it.effect.each(["gitlab.com", "gitlab.example.test"])( |
7722 | | - "pauses uncached GitLab activity reads after an optional endpoint rate limit on %s", |
7723 | | - (host) => |
7724 | | - Effect.gen(function* () { |
7725 | | - let commandCalls = 0; |
7726 | | - const provider = yield* GitLabPullRequestProvider.make.pipe( |
7727 | | - Effect.provide( |
7728 | | - GitLabPullRequestCli.layer.pipe( |
7729 | | - Layer.provide( |
7730 | | - Layer.mock(GitLabCli.GitLabCli)({ |
7731 | | - execute: () => |
7732 | | - Effect.sync(() => { |
| 7721 | +it.effect("pauses uncached GitLab activity after only the reactions endpoint is rate limited", () => |
| 7722 | + Effect.gen(function* () { |
| 7723 | + let commandCalls = 0; |
| 7724 | + const provider = yield* GitLabPullRequestProvider.make.pipe( |
| 7725 | + Effect.provide( |
| 7726 | + GitLabPullRequestCli.layer.pipe( |
| 7727 | + Layer.provide(GitLabCli.layer), |
| 7728 | + Layer.provide( |
| 7729 | + TestSourceControlHost.layer({ |
| 7730 | + process: { |
| 7731 | + run: (input) => |
| 7732 | + Effect.suspend(() => { |
7733 | 7733 | commandCalls += 1; |
7734 | | - }).pipe( |
7735 | | - Effect.andThen( |
7736 | | - Effect.fail( |
7737 | | - new GitLabCli.GitLabCliRateLimitError({ |
7738 | | - operation: "execute", |
7739 | | - command: "glab", |
7740 | | - cwd: "/repo", |
7741 | | - cause: null, |
7742 | | - }), |
7743 | | - ), |
7744 | | - ), |
7745 | | - ), |
7746 | | - }), |
7747 | | - ), |
| 7734 | + return input.args[1] === "graphql" |
| 7735 | + ? Effect.fail( |
| 7736 | + new VcsProcessExitError({ |
| 7737 | + operation: input.operation, |
| 7738 | + command: input.command, |
| 7739 | + cwd: input.cwd, |
| 7740 | + exitCode: 1, |
| 7741 | + detail: "API rate limit exceeded.", |
| 7742 | + failureKind: "rate-limited", |
| 7743 | + }), |
| 7744 | + ) |
| 7745 | + : Effect.succeed(TestSourceControlHost.processOutput("[]")); |
| 7746 | + }), |
| 7747 | + }, |
| 7748 | + }), |
7748 | 7749 | ), |
7749 | 7750 | ), |
7750 | | - ); |
7751 | | - const service = yield* makeService({ |
7752 | | - projects: [ |
7753 | | - project({ |
7754 | | - id: "p1", |
7755 | | - title: "web", |
7756 | | - workspaceRoot: "/repo", |
7757 | | - repository: "acme/web", |
7758 | | - provider: "gitlab", |
7759 | | - host, |
7760 | | - }), |
7761 | | - ], |
7762 | | - providers: [provider], |
7763 | | - }); |
7764 | | - const reference = { projectId: "p1" as ProjectId, repository: "acme/web", number: 1 }; |
7765 | | - const first = yield* Effect.flip(service.activity(reference)); |
7766 | | - assert.instanceOf(first, PullRequestOperationError); |
7767 | | - assert.instanceOf(first.cause, PullRequestProviderError); |
7768 | | - assert.strictEqual(first.cause.reason, "rate-limited"); |
7769 | | - const firstCommandCalls = commandCalls; |
7770 | | - assert.isAbove(firstCommandCalls, 0); |
7771 | | - // A different request bypasses the activity cache and must stop at the host backoff. |
7772 | | - const paused = yield* Effect.flip(service.activity({ ...reference, number: 2 })); |
7773 | | - assert.instanceOf(paused, PullRequestOperationError); |
7774 | | - assert.instanceOf(paused.cause, PullRequestProviderError); |
7775 | | - assert.strictEqual(paused.cause.reason, "rate-limited"); |
7776 | | - assert.strictEqual(commandCalls, firstCommandCalls); |
7777 | | - }), |
| 7751 | + ), |
| 7752 | + ); |
| 7753 | + const service = yield* makeService({ |
| 7754 | + projects: [ |
| 7755 | + project({ |
| 7756 | + id: "p1", |
| 7757 | + title: "web", |
| 7758 | + workspaceRoot: "/repo", |
| 7759 | + repository: "acme/web", |
| 7760 | + provider: "gitlab", |
| 7761 | + host: "gitlab.example.test", |
| 7762 | + }), |
| 7763 | + ], |
| 7764 | + providers: [provider], |
| 7765 | + }); |
| 7766 | + const reference = { projectId: "p1" as ProjectId, repository: "acme/web", number: 1 }; |
| 7767 | + |
| 7768 | + expect(yield* Effect.result(service.activity(reference))).toMatchObject({ |
| 7769 | + _tag: "Failure", |
| 7770 | + failure: { |
| 7771 | + _tag: "PullRequestOperationError", |
| 7772 | + cause: { |
| 7773 | + _tag: "PullRequestProviderError", |
| 7774 | + reason: "rate-limited", |
| 7775 | + cause: { _tag: "GitLabCliRateLimitError" }, |
| 7776 | + }, |
| 7777 | + }, |
| 7778 | + }); |
| 7779 | + const firstCommandCalls = commandCalls; |
| 7780 | + assert.isAbove(firstCommandCalls, 0); |
| 7781 | + |
| 7782 | + // A different merge request cannot reuse the first request's cached failure. |
| 7783 | + expect(yield* Effect.result(service.activity({ ...reference, number: 2 }))).toMatchObject({ |
| 7784 | + _tag: "Failure", |
| 7785 | + failure: { |
| 7786 | + _tag: "PullRequestOperationError", |
| 7787 | + cause: { |
| 7788 | + _tag: "PullRequestProviderError", |
| 7789 | + reason: "rate-limited", |
| 7790 | + cause: { |
| 7791 | + _tag: "SourceControlRateLimitPausedError", |
| 7792 | + host: "gitlab.example.test", |
| 7793 | + }, |
| 7794 | + }, |
| 7795 | + }, |
| 7796 | + }); |
| 7797 | + assert.strictEqual(commandCalls, firstCommandCalls); |
| 7798 | + }), |
7778 | 7799 | ); |
7779 | 7800 |
|
7780 | 7801 | it.effect("expands only files the change request changes, across every slice of its diff", () => |
|
0 commit comments