Skip to content

Commit 3b8e29d

Browse files
test(gitlab): focus activity error regressions
1 parent 337abb5 commit 3b8e29d

2 files changed

Lines changed: 135 additions & 113 deletions

File tree

‎apps/server/src/pullRequest/PullRequestService.test.ts‎

Lines changed: 77 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { SourceControlProviderKind } from "@t3tools/contracts";
1+
import { SourceControlProviderKind, VcsProcessExitError } from "@t3tools/contracts";
22
import * as NodeServices from "@effect/platform-node/NodeServices";
33
import * as NodeV8 from "node:v8";
44
import * as NodeVM from "node:vm";
55
import * as ChildProcessSpawner from "effect/process/ChildProcessSpawner";
66
import * as KeyValueStore from "effect/persistence/KeyValueStore";
7-
import { assert, it } from "@effect/vitest";
7+
import { assert, expect, it } from "@effect/vitest";
88
import * as Cause from "effect/Cause";
99
import * as Clock from "effect/Clock";
1010
import * as Deferred from "effect/Deferred";
@@ -7718,63 +7718,84 @@ it.effect.each([
77187718
}),
77197719
);
77207720

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(() => {
77337733
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+
}),
77487749
),
77497750
),
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+
}),
77787799
);
77797800

77807801
it.effect("expands only files the change request changes, across every slice of its diff", () =>

‎packages/source-control-gitlab/src/server/GitLabPullRequestProvider.test.ts‎

Lines changed: 58 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -295,72 +295,73 @@ describe("optional activity reads", () => {
295295
cwd: "/w",
296296
cause: null,
297297
};
298-
const failures = [
299-
[new GitLabCli.GitLabCliRateLimitError(context), "rate-limited"],
300-
[new GitLabCli.GitLabCliAuthenticationError(context), "unauthenticated"],
301-
[new GitLabCli.GitLabCliUnavailableError(context), "missing-tool"],
302-
] as const;
303-
304-
const operations = ["listNotes", "listCommits", "listDiscussions", "listReactions"] as const;
305-
it.effect.each(
306-
operations.flatMap((operation) =>
307-
failures.map(([error, reason]) => ({ operation, error, reason })),
308-
),
309-
)("preserves critical activity failure $operation: $reason", ({ operation, error, reason }) =>
310-
Effect.gen(function* () {
311-
const provider = yield* make.pipe(
312-
Effect.provide(
313-
Layer.mock(GitLabPullRequestCli.GitLabPullRequestCli)({
314-
...reads,
315-
[operation]: () => Effect.fail(error),
316-
}),
317-
),
318-
);
319-
expect(yield* Effect.flip(provider.getChangeRequestActivity(reference))).toMatchObject({
320-
provider: "gitlab",
321-
operation: "getChangeRequestActivity",
322-
reason,
323-
cause: error,
324-
});
325-
}),
326-
);
327298

328-
it.effect.each(operations)(
329-
"recovers an ordinary %s failure while preserving other activity",
330-
(operation) =>
299+
it.effect.each([
300+
{
301+
operation: "listNotes",
302+
error: new GitLabCli.GitLabCliAuthenticationError(context),
303+
reason: "unauthenticated",
304+
},
305+
{
306+
operation: "listCommits",
307+
error: new GitLabCli.GitLabCliUnavailableError(context),
308+
reason: "missing-tool",
309+
},
310+
] as const)(
311+
"reports $reason instead of successful partial activity",
312+
({ operation, error, reason }) =>
331313
Effect.gen(function* () {
332314
const provider = yield* make.pipe(
333315
Effect.provide(
334316
Layer.mock(GitLabPullRequestCli.GitLabPullRequestCli)({
335317
...reads,
336-
listReactions: () =>
337-
Effect.succeed({
338-
reactions: [
339-
{ content: "heart" as const, count: 1, actors: [], viewerHasReacted: false },
340-
],
341-
reactionsByNoteId: new Map(),
342-
}),
343-
[operation]: () =>
344-
Effect.fail(
345-
new GitLabPullRequestCli.GitLabMergeRequestReadError({
346-
command: "glab",
347-
cwd: "/w",
348-
operation,
349-
cause: null,
350-
}),
351-
),
318+
[operation]: () => Effect.fail(error),
352319
}),
353320
),
354321
);
355-
const activity = yield* provider.getChangeRequestActivity(reference);
356-
expect(activity.commentsTruncated).toBe(
357-
operation === "listNotes" || operation === "listDiscussions",
358-
);
359-
expect(activity.reactions).toHaveLength(operation === "listReactions" ? 0 : 1);
360-
expect(activity.comments.map(({ id }) => id)).toEqual(
361-
operation === "listNotes" ? [] : [comment.id],
362-
);
363-
expect(activity.commits).toEqual(operation === "listCommits" ? [] : [commit]);
322+
323+
expect(yield* Effect.result(provider.getChangeRequestActivity(reference))).toMatchObject({
324+
_tag: "Failure",
325+
failure: {
326+
_tag: "PullRequestProviderError",
327+
provider: "gitlab",
328+
operation: "getChangeRequestActivity",
329+
reason,
330+
detail: error.detail,
331+
cause: error,
332+
},
333+
});
364334
}),
365335
);
336+
337+
it.effect("keeps comments and commits when optional discussions and reactions fail", () =>
338+
Effect.gen(function* () {
339+
const provider = yield* make.pipe(
340+
Effect.provide(
341+
Layer.mock(GitLabPullRequestCli.GitLabPullRequestCli)({
342+
...reads,
343+
listDiscussions: () =>
344+
Effect.fail(
345+
new GitLabPullRequestCli.GitLabMergeRequestReadError({
346+
command: "glab",
347+
cwd: "/w",
348+
operation: "listDiscussions",
349+
cause: null,
350+
}),
351+
),
352+
listReactions: () => Effect.fail(new GitLabCli.GitLabCliCommandError(context)),
353+
}),
354+
),
355+
);
356+
357+
expect(yield* provider.getChangeRequestActivity(reference)).toEqual({
358+
comments: [{ ...comment, reactions: [] }],
359+
commentCount: 1,
360+
commentsTruncated: true,
361+
reviewThreads: [],
362+
reactions: [],
363+
commits: [commit],
364+
});
365+
}),
366+
);
366367
});

0 commit comments

Comments
 (0)