Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 59 additions & 3 deletions apps/server/src/sourceControl/BitbucketApi.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -533,8 +533,8 @@ it.effect("preserves the HTTP client failure without deriving the domain message
}),
);

assert.instanceOf(error, BitbucketApi.BitbucketRequestError);
assert.strictEqual(error.operation, "getPullRequest");
assert.strictEqual(error.detail, "Failed to send the Bitbucket request.");
assert.strictEqual(
error.message,
"Bitbucket API failed in getPullRequest: Failed to send the Bitbucket request.",
Expand All @@ -544,6 +544,61 @@ it.effect("preserves the HTTP client failure without deriving the domain message
}).pipe(Effect.provide(layer));
});

it.effect("keeps Bitbucket response bodies out of checkout diagnostics", () => {
const responseBody = '{"error":{"message":"credential=secret-value"}}';
const { layer } = makeLayer({
response: () => new Response(responseBody, { status: 403 }),
});

return Effect.gen(function* () {
const bitbucket = yield* BitbucketApi.BitbucketApi;
const error = yield* bitbucket
.checkoutPullRequest({ cwd: "/repo", reference: "42" })
.pipe(Effect.flip);

assert.instanceOf(error, BitbucketApi.BitbucketResponseError);
assert.strictEqual(error.operation, "getPullRequest");
assert.strictEqual(error.status, 403);
assert.strictEqual(error.responseBodyLength, responseBody.length);
assert.notProperty(error, "responseBody");
assert.strictEqual(
error.message,
"Bitbucket API failed in getPullRequest: Bitbucket returned HTTP 403.",
);
assert.notInclude(error.message, "secret-value");
}).pipe(Effect.provide(layer));
});

it.effect("preserves Bitbucket response body read failures as their immediate cause", () => {
const cause = new Error("response stream failed");
const { layer } = makeLayer({
response: () =>
new Response(
new ReadableStream<Uint8Array>({
start: (controller) => controller.error(cause),
}),
{ status: 502 },
),
});

return Effect.gen(function* () {
const bitbucket = yield* BitbucketApi.BitbucketApi;
const error = yield* bitbucket
.getPullRequest({ cwd: "/repo", reference: "42" })
.pipe(Effect.flip);

assert.instanceOf(error, BitbucketApi.BitbucketResponseBodyReadError);
assert.strictEqual(error.operation, "getPullRequest");
assert.strictEqual(error.status, 502);
assert.instanceOf(error.cause, HttpClientError.HttpClientError);
assert.strictEqual(error.cause.cause, cause);
assert.strictEqual(
error.message,
"Bitbucket API failed in getPullRequest: Bitbucket returned HTTP 502.",
);
}).pipe(Effect.provide(layer));
});

it.effect("checks out same-repository pull requests with the existing Bitbucket remote", () => {
const { git, layer } = makeLayer({
response: () =>
Expand Down Expand Up @@ -630,8 +685,9 @@ it.effect("preserves Git checkout failures without deriving the domain message f
}),
);

assert.strictEqual(error.operation, "checkoutPullRequest");
assert.strictEqual(error.detail, "Failed to check out the Bitbucket pull request.");
assert.instanceOf(error, BitbucketApi.BitbucketCheckoutError);
assert.strictEqual(error.cwd, "/repo");
assert.strictEqual(error.reference, "42");
assert.strictEqual(
error.message,
"Bitbucket API failed in checkoutPullRequest: Failed to check out the Bitbucket pull request.",
Expand Down
Loading
Loading