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

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

fix(server): Forgejo required-check globs no longer hang the event loop (#26183)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

Julius Marminge committed Oct 27, 2026 at 16:51 UTC a8460842360d71f4df4117072f8eeb08f0183e6d
2 files changed +74 -11
packages/source-control-forgejo/src/server/ForgejoSourceControlProvider.test.ts
+42
@@ -17,6 +17,7 @@ import * as TestSourceControlHost from "@t3tools/source-control-testing/TestSour
17 import * as ForgejoCli from "./ForgejoCli.ts";
18 import * as ForgejoPullRequestProvider from "./ForgejoPullRequestProvider.ts";
19 import * as ForgejoSourceControlProvider from "./ForgejoSourceControlProvider.ts";
20 +import { markRequiredForgejoChecks } from "./forgejoRequiredChecks.ts";
21
22 const processOutput = TestSourceControlHost.processOutput;
23
@@ -140,6 +141,47 @@ it.effect.each([
141 ),
142 );
143
144 +it("matches many-wildcard required patterns against long check names without backtracking", () => {
145 + const checks = ["a".repeat(200), `${"a".repeat(199)}b`, "x?y\nz"].map((name) => ({
146 + name,
147 + status: "success" as const,
148 + description: null,
149 + url: null,
150 + }));
151 + const marked = markRequiredForgejoChecks(checks, {
152 + enable_status_check: true,
153 + status_check_contexts: [`${"*a".repeat(12)}b`, "x*?y?z"],
154 + });
155 + assert.deepStrictEqual(
156 + marked.map((check) => [check.name.slice(-3), check.required]),
157 + [
158 + ["aaa", undefined],
159 + ["aab", true],
160 + ["y\nz", true],
161 + ],
162 + );
163 +});
164 +
165 +it("treats a required pattern's `*` as a wildcard even when the check name has one", () => {
166 + const checks = ["*build", "ci/*lint"].map((name) => ({
167 + name,
168 + status: "success" as const,
169 + description: null,
170 + url: null,
171 + }));
172 + const marked = markRequiredForgejoChecks(checks, {
173 + enable_status_check: true,
174 + status_check_contexts: ["*build", "ci/*"],
175 + });
176 + assert.deepStrictEqual(
177 + marked.map((check) => [check.name, check.required]),
178 + [
179 + ["*build", true],
180 + ["ci/*lint", true],
181 + ],
182 + );
183 +});
184 +
185 const forgejoMergeProvider = (repository: Effect.Effect<string, ForgejoCli.ForgejoCliError>) => {
186 const writes: Array<ForgejoCli.ForgejoApiInput> = [];
187 const provider = ForgejoPullRequestProvider.make.pipe(
packages/source-control-forgejo/src/server/forgejoRequiredChecks.ts
+32 -11
@@ -11,13 +11,32 @@ export const ForgejoBranchStatusChecks = Schema.Struct({
11 // run of characters, `/` included, and `?` matches one character. Classes, alternation and escapes
12 // are not handled.
13 const UNSUPPORTED_GLOB = /[[\]{}\\]/;
14 -const contextPattern = (glob: string) =>
15 - new RegExp(
16 - `^${Array.from(glob, (char) =>
17 - char === "*" ? ".*" : char === "?" ? "." : char.replace(/[.+^$()|]/g, "\\$&"),
18 - ).join("")}$`,
19 - "su",
20 - );
14 +// Linear two-pointer match: a regex built from the glob backtracks polynomially per `*`.
15 +const matchesContext = (glob: string, name: string) => {
16 + const pattern = Array.from(glob);
17 + const text = Array.from(name);
18 + let p = 0;
19 + let t = 0;
20 + let star = -1;
21 + let resume = 0;
22 + while (t < text.length) {
23 + // Wildcard first, so a literal `*` in the name never consumes the pattern's `*`.
24 + if (pattern[p] === "*") {
25 + star = p++;
26 + resume = t;
27 + } else if (p < pattern.length && (pattern[p] === "?" || pattern[p] === text[t])) {
28 + p++;
29 + t++;
30 + } else if (star >= 0) {
31 + p = star + 1;
32 + t = ++resume;
33 + } else {
34 + return false;
35 + }
36 + }
37 + while (pattern[p] === "*") p++;
38 + return p === pattern.length;
39 +};
40
41 export function markRequiredForgejoChecks(
42 checks: ReadonlyArray<PullRequestCheck>,
@@ -38,13 +57,15 @@ export function markRequiredForgejoChecks(
57 })),
58 ];
59 }
41 - const patterns = [...new Set(contexts)].map((name) => ({ name, pattern: contextPattern(name) }));
60 + const patterns = [...new Set(contexts)];
61 const marked = checks.map((check) =>
43 - patterns.some(({ pattern }) => pattern.test(check.name)) ? { ...check, required: true } : check,
62 + patterns.some((pattern) => matchesContext(pattern, check.name))
63 + ? { ...check, required: true }
64 + : check,
65 );
66 // Forgejo keeps an unmatched required pattern pending, including wildcards.
46 - const missing = patterns.flatMap(({ name, pattern }) =>
47 - !name.trim() || checks.some((check) => pattern.test(check.name))
67 + const missing = patterns.flatMap((name) =>
68 + !name.trim() || checks.some((check) => matchesContext(name, check.name))
69 ? []
70 : [{ name, status: "pending", description: null, url: null, required: true } as const],
71 );