Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

test(relay): bare-fetch guard also catches fetch as a ternary branch

Bugfixer 26c614381b5b8
diff --git a/src/lib/relay-server-callers.test.ts b/src/lib/relay-server-callers.test.ts
index 40f5df51b5..a802309791 100644
--- a/src/lib/relay-server-callers.test.ts
+++ b/src/lib/relay-server-callers.test.ts
@@ -16,8 +16,9 @@ function appFiles(): string[] {
}
/** A call to fetch, whitespace or a line break before its `(` too, or fetch handed on as a value (`fetchImpl = fetch`,
- * `run(fetch)`, `impl ?? fetch`, `custom || fetch`, `return fetch`, `() => fetch`); not `.fetch(` or a `fetch:` key. */
-const BARE_FETCH = /(?<![\w$.])fetch\s*\(|(?:[=(,:]|=>|\?\?|\|\||&&|\breturn)\s*fetch\b(?![\w$.(]|\s*[:(])/g;
+ * `run(fetch)`, `impl ?? fetch`, `custom || fetch`, `return fetch`, `() => fetch`, `ok ? fetch : other`); not `.fetch(`
+ * or a `fetch:` key. */
+const BARE_FETCH = /(?<![\w$.])fetch\s*\(|(?:[=(,:]|=>|\?\?|\|\||&&|\breturn)\s*fetch\b(?![\w$.(]|\s*[:(])|(?<!\?)\?\s*fetch\b(?![\w$.(]|\s*\()/g;
/** The 1-based lines of `source` with a bare fetch, `//` comments left out. */
function bareFetchLines(source: string): number[] {
@@ -39,7 +40,8 @@ describe("app requests to its own server", () => {
expect(bareFetchLines("const run = fetch;\nuse(fetch)")).toEqual([1, 2]);
expect(bareFetchLines('const impl = options.fetchImpl ?? fetch;\nconst alt = custom || fetch;')).toEqual([1, 2]);
expect(bareFetchLines("function impl() { return fetch; }\nconst get = () => fetch;")).toEqual([1, 2]);
- expect(bareFetchLines('link.fetch("/api/bots");\nconst x = { fetch: go };\n// fetch("/api/bots")\nserverFetch("/api/bots");')).toEqual([]);
+ expect(bareFetchLines("const send = useNative ? fetch : serverFetch;\nconst alt = ok ? serverFetch : fetch;")).toEqual([1, 2]);
+ expect(bareFetchLines('link.fetch("/api/bots");\nlink?.fetch("/api/bots");\nconst x = { fetch: go };\n// fetch("/api/bots")\nserverFetch("/api/bots");')).toEqual([]);
expect(bareFetchLines("const UNREACHABLE = /Load failed|fetch failed$/i;")).toEqual([]);
});
});