Skip to content
TypeScript

fix(server): allow large Azure DevOps PR lists (#8572)

Simonea56b0cd7178d
diff --git a/apps/server/src/pullRequest/AzureDevOpsPullRequestCli.test.ts b/apps/server/src/pullRequest/AzureDevOpsPullRequestCli.test.ts
index 5baf18a1ff6..98e21d75bc5 100644
--- a/apps/server/src/pullRequest/AzureDevOpsPullRequestCli.test.ts
+++ b/apps/server/src/pullRequest/AzureDevOpsPullRequestCli.test.ts
@@ -97,6 +97,46 @@ layer("AzureDevOpsPullRequestCli.layer", (it) => {
}),
);
+ it.effect("reads an Azure pull request page larger than the VCS default output limit", () =>
+ Effect.gen(function* () {
+ const rows = pullRequestRows(100, 1).map((row) => ({
+ ...row,
+ description: "x".repeat(10_000),
+ }));
+ // @effect-diagnostics-next-line preferSchemaOverJson:off
+ const response = JSON.stringify(rows);
+ expect(Buffer.byteLength(response)).toBeGreaterThan(1_000_000);
+
+ mockedExecute.mockImplementationOnce((input) => {
+ const maxOutputBytes =
+ "maxOutputBytes" in input && typeof input.maxOutputBytes === "number"
+ ? input.maxOutputBytes
+ : 1_000_000;
+ return Effect.succeed(
+ maxOutputBytes >= Buffer.byteLength(response)
+ ? output(response)
+ : {
+ ...output(response.slice(0, maxOutputBytes)),
+ stdoutTruncated: true,
+ },
+ );
+ });
+ const cli = yield* AzureDevOpsPullRequestCli.AzureDevOpsPullRequestCli;
+
+ const batch = yield* cli.listPullRequests({
+ cwd: "/w",
+ repository: "web",
+ state: "merged",
+ involvement: "all",
+ viewer: "[email protected]",
+ limit: 99,
+ });
+
+ assert.strictEqual(batch.items.length, 99);
+ assert.isTrue(batch.truncated);
+ }),
+ );
+
it.effect("reads the page unnarrowed when asked to search, having nothing to search with", () =>
Effect.gen(function* () {
mockedExecute.mockReturnValueOnce(Effect.succeed(output(pullRequests(3, 1))));
diff --git a/apps/server/src/pullRequest/AzureDevOpsPullRequestCli.ts b/apps/server/src/pullRequest/AzureDevOpsPullRequestCli.ts
index 549a172b364..96dc4ea1d30 100644
--- a/apps/server/src/pullRequest/AzureDevOpsPullRequestCli.ts
+++ b/apps/server/src/pullRequest/AzureDevOpsPullRequestCli.ts
@@ -111,6 +111,7 @@ export type AzureDevOpsPullRequestCliError =
/** The version every REST call below is pinned to, so a new default cannot reshape a response. */
const REST_API_VERSION = "7.1";
+const PULL_REQUEST_LIST_MAX_OUTPUT_BYTES = 16 * 1024 * 1024;
export class AzureDevOpsPullRequestCli extends Context.Service<
AzureDevOpsPullRequestCli,
@@ -258,10 +259,15 @@ export const make = Effect.gen(function* () {
// how to read all of them.
const detectArgs = ["--detect", "true"] as const;
- const executeJson = (input: { readonly cwd: string; readonly args: ReadonlyArray<string> }) =>
+ const executeJson = (input: {
+ readonly cwd: string;
+ readonly args: ReadonlyArray<string>;
+ readonly maxOutputBytes?: number;
+ }) =>
azure.execute({
cwd: input.cwd,
args: [...input.args, "--only-show-errors", "--output", "json"],
+ ...(input.maxOutputBytes === undefined ? {} : { maxOutputBytes: input.maxOutputBytes }),
});
/**
@@ -290,6 +296,7 @@ export const make = Effect.gen(function* () {
const top = remaining + 1;
return executeJson({
cwd: input.cwd,
+ maxOutputBytes: PULL_REQUEST_LIST_MAX_OUTPUT_BYTES,
args: [
"repos",
"pr",
diff --git a/apps/server/src/sourceControl/AzureDevOpsCli.test.ts b/apps/server/src/sourceControl/AzureDevOpsCli.test.ts
index a5bb9a9e30a..f0cb5200302 100644
--- a/apps/server/src/sourceControl/AzureDevOpsCli.test.ts
+++ b/apps/server/src/sourceControl/AzureDevOpsCli.test.ts
@@ -332,6 +332,28 @@ describe("AzureDevOpsCli.layer", () => {
}).pipe(Effect.provide(layer)),
);
+ it.effect("forwards explicit output limits to the process boundary", () =>
+ Effect.gen(function* () {
+ mockRun.mockReturnValueOnce(Effect.succeed(processOutput("")));
+
+ const az = yield* AzureDevOpsCli.AzureDevOpsCli;
+ yield* az.execute({
+ cwd: "/repo",
+ args: ["repos", "pr", "list"],
+ maxOutputBytes: 16 * 1024 * 1024,
+ });
+
+ expect(mockRun).toHaveBeenCalledWith({
+ operation: "AzureDevOpsCli.execute",
+ command: "az",
+ args: ["repos", "pr", "list"],
+ cwd: "/repo",
+ timeoutMs: 30_000,
+ maxOutputBytes: 16 * 1024 * 1024,
+ });
+ }).pipe(Effect.provide(layer)),
+ );
+
it.effect("preserves VCS causes without copying upstream details into messages", () =>
Effect.gen(function* () {
const cause = new VcsProcessExitError({
diff --git a/apps/server/src/sourceControl/AzureDevOpsCli.ts b/apps/server/src/sourceControl/AzureDevOpsCli.ts
index 556dc4bf213..f05f4a7588c 100644
--- a/apps/server/src/sourceControl/AzureDevOpsCli.ts
+++ b/apps/server/src/sourceControl/AzureDevOpsCli.ts
@@ -218,6 +218,7 @@ export class AzureDevOpsCli extends Context.Service<
readonly cwd: string;
readonly args: ReadonlyArray<string>;
readonly timeoutMs?: number;
+ readonly maxOutputBytes?: number;
}) => Effect.Effect<VcsProcess.VcsProcessOutput, AzureDevOpsCliError>;
readonly listPullRequests: (input: {
@@ -362,6 +363,7 @@ export const make = Effect.gen(function* () {
args: input.args,
cwd: input.cwd,
timeoutMs: input.timeoutMs ?? DEFAULT_TIMEOUT_MS,
+ ...(input.maxOutputBytes === undefined ? {} : { maxOutputBytes: input.maxOutputBytes }),
})
.pipe(
Effect.mapError((error) =>