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

Co-authored-by: Simone <[email protected]>
This commit is contained in:
SimoneandSimone authored and GitHub committed 2026-09-02 00:43:10 -07:00
1 parent 4116db9807
commit a56b0cd717
4 files changed
+72 -1

No files matched your search

@@ -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))));
@@ -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",
@@ -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({
@@ -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) =>