@devries-cameron20 / t3code-1 / commits / c516061259
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(server): Forgejo PR lookup reads tea API pages over 1 MB (#38211)

Julius Marminge committed Nov 17, 2026 at 08:40 UTC c516061259d3591941d8437745a3116588b45e78
2 files changed +106
packages/source-control-forgejo/src/server/ForgejoCli.ts
+11
@@ -18,6 +18,9 @@ import * as SourceControlHost from "@t3tools/source-control-core/server/SourceCo
18 import { collectUint8StreamText } from "@t3tools/provider-core/server/collectStreamText";
19 import type { SourceControlProviderContext } from "@t3tools/source-control-core/server/SourceControlProvider";
20
21 +// A Gitea list page can hold 50 pull request bodies; tea's output is otherwise capped at 1 MB.
22 +const API_MAX_OUTPUT_BYTES = 16 * 1024 * 1024;
23 +
24 const encodeApiBody = Schema.encodeEffect(Schema.fromJsonString(Schema.Unknown));
25
26 export class ForgejoCliError extends Schema.TaggedError<ForgejoCliError>()("ForgejoCliError", {
@@ -731,6 +734,7 @@ export const make = Effect.gen(function* () {
734 `${repository.baseUrl}/api/v1/${path}`,
735 ],
736 ...(stdin === undefined ? {} : { stdin }),
737 + maxOutputBytes: API_MAX_OUTPUT_BYTES,
738 });
739 // tea reports HTTP failures with exit code zero; use its response status.
740 const status = Number(/^HTTP\/\S+ (\d{3})/m.exec(result.stderr)?.[1]);
@@ -763,6 +767,13 @@ export const make = Effect.gen(function* () {
767 : `Forgejo API request failed (HTTP ${status}).`,
768 });
769 }
770 + if (result.stdoutTruncated)
771 + return yield* new ForgejoCliError({
772 + command: "tea",
773 + cwd: input.cwd,
774 + reason: "invalid-response",
775 + detail: "Forgejo API response exceeded the output size limit.",
776 + });
777 return result;
778 });
779 return ForgejoCli.of({ execute, listLogins, getAccount, resolveRepository, api });
packages/source-control-forgejo/src/server/ForgejoSourceControlProvider.test.ts
+95
@@ -1124,6 +1124,101 @@ it.effect("reads only the changed front of a Gitea pull request list it has read
1124 );
1125 });
1126
1127 +it.effect(
1128 + "finds a branch's pull request on Gitea when a page of the full list exceeds 1 MB",
1129 + () => {
1130 + const repo = { full_name: "maria/project", owner: { login: "maria" } };
1131 + const pull = (number: number, head: string, body: string) => ({
1132 + number,
1133 + title: `PR ${number}`,
1134 + body,
1135 + html_url: `http://forgejo.local:3000/maria/project/pulls/${number}`,
1136 + state: "closed",
1137 + merged: true,
1138 + updated_at: `2026-10-12T00:00:0${number}Z`,
1139 + base: { ref: "main", label: "main", sha: "base", repo },
1140 + head: { ref: head, label: head, sha: "h", repo },
1141 + });
1142 + const pulls = [pull(2, "renovate", "x".repeat(999_993)), pull(1, "feature", "small")];
1143 + return Effect.gen(function* () {
1144 + const provider = yield* ForgejoSourceControlProvider.make;
1145 + const found = yield* provider.listChangeRequests({
1146 + cwd: "/repo",
1147 + context: {
1148 + provider: {
1149 + kind: SourceControlProviderKind.make("forgejo"),
1150 + name: "Forgejo",
1151 + baseUrl: "http://forgejo.local:3000",
1152 + },
1153 + remoteName: "origin",
1154 + remoteUrl: "http://forgejo.local:3000/maria/project.git",
1155 + },
1156 + headSelector: "feature",
1157 + state: "all",
1158 + });
1159 + assert.deepStrictEqual(
1160 + found.map((item) => item.number),
1161 + [1],
1162 + );
1163 + }).pipe(
1164 + Effect.provide(
1165 + ForgejoCli.layer.pipe(
1166 + Layer.provideMerge(
1167 + Layer.mergeAll(
1168 + Layer.succeed(
1169 + FileSystem.FileSystem,
1170 + FileSystem.makeNoop({ exists: () => Effect.succeed(false) }),
1171 + ),
1172 + Layer.succeed(
1173 + HttpClient.HttpClient,
1174 + HttpClient.make(() => {
1175 + throw new Error("tea must handle its own HTTP request");
1176 + }),
1177 + ),
1178 + TestSourceControlHost.layer({
1179 + process: {
1180 + run: (input) => {
1181 + if (input.args[0] === "login")
1182 + return Effect.succeed(
1183 + processOutput(
1184 + encodeJson([
1185 + {
1186 + name: "work",
1187 + url: "http://forgejo.local:3000",
1188 + ssh_host: "forgejo.local",
1189 + user: "maria",
1190 + default: "true",
1191 + },
1192 + ]),
1193 + ),
1194 + );
1195 + const url = new URL(input.args.at(-1) ?? "");
1196 + const number = /\/pulls\/(\d+)$/.exec(url.pathname)?.[1];
1197 + // Gitea ignores `head=`, so every list page holds every pull request.
1198 + const stdout = encodeJson(
1199 + number
1200 + ? pulls.find((item) => item.number === Number(number))
1201 + : url.searchParams.get("page") === "1"
1202 + ? pulls
1203 + : [],
1204 + );
1205 + // VcsProcess truncates at 1,000,000 bytes unless a caller raises the cap.
1206 + const maxBytes = input.maxOutputBytes ?? 1_000_000;
1207 + return Effect.succeed({
1208 + ...processOutput(stdout.slice(0, maxBytes), { stderr: "HTTP/1.1 200 OK\n" }),
1209 + stdoutTruncated: stdout.length > maxBytes,
1210 + });
1211 + },
1212 + },
1213 + }),
1214 + ),
1215 + ),
1216 + ),
1217 + ),
1218 + );
1219 + },
1220 +);
1221 +
1222 it.effect("finds a merged Forgejo pull request whose head branch was deleted", () =>
1223 Effect.gen(function* () {
1224 const provider = yield* ForgejoSourceControlProvider.make;