diff --git a/scripts/runtime-oauth-polling.ts b/scripts/runtime-oauth-polling.ts index 7117eee..2b1f959 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 0000000..d4f49ad --- /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); +});