From 04187fd4eb037da7f0c299336cd4fc6d387146f7 Mon Sep 17 00:00:00 2001 From: Kingsword Date: Sun, 6 Dec 2026 19:47:29 +0800 Subject: [PATCH] fix(runtime): escape minified OAuth function names --- scripts/runtime-oauth-polling.ts | 2 +- test/runtime/oauth-polling.test.ts | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 test/runtime/oauth-polling.test.ts diff --git a/scripts/runtime-oauth-polling.ts b/scripts/runtime-oauth-polling.ts index 7117eeec..2b1f9592 100644 --- a/scripts/runtime-oauth-polling.ts +++ b/scripts/runtime-oauth-polling.ts @@ -21,7 +21,7 @@ function escape(value: string): string { function namedFunction(runtime: string, label: string): FunctionExpression { const name = symbol(runtime, label); const match = unique( - [...runtime.matchAll(new RegExp(`(?:async )?function ${name}\\(`, "gu"))], + [...runtime.matchAll(new RegExp(`(?:async )?function ${escape(name)}\\(`, "gu"))], `${label} function` ); const fn = parseExpressionAt(runtime, match.index!, { ecmaVersion: "latest" }); diff --git a/test/runtime/oauth-polling.test.ts b/test/runtime/oauth-polling.test.ts new file mode 100644 index 00000000..d4f49adb --- /dev/null +++ b/test/runtime/oauth-polling.test.ts @@ -0,0 +1,20 @@ +import { expect, test } from "bun:test"; +import { hasRuntimeNativePollingOAuth } from "../../scripts/runtime-oauth-polling.ts"; + +test("native OAuth polling recognizes dollar signs in minified function names", () => { + const runtime = ` + r(login$,"loginZCodeCli"); + r(bigmodel$,"loginBigmodelCodingPlan"); + r(poll$,"pollUntilReady"); + async function login$(e={}) { + const credentialKeys={}, oauth={}; + poll$({authSource:"oauth"}); + return {authSource:"oauth",[credentialKeys.zcodeJwtToken]:oauth.token,[credentialKeys.bigmodelAccessToken]:oauth.accessToken,}; + } + async function bigmodel$(e={}) { + return login$({...e,providerId:"bigmodel"}); + } + `; + + expect(hasRuntimeNativePollingOAuth(runtime)).toBe(true); +});