From 32dd0aa7e779aaf87a55af3d883275fefa06dc5b Mon Sep 17 00:00:00 2001 From: Vincent Koc Date: Sat, 4 Apr 2026 14:43:39 +0900 Subject: [PATCH] fix(plugin-sdk): lazy acp runtime testing merge --- src/plugin-sdk/acp-runtime.ts | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/src/plugin-sdk/acp-runtime.ts b/src/plugin-sdk/acp-runtime.ts index 094173426e4..3ad4b8b9a54 100644 --- a/src/plugin-sdk/acp-runtime.ts +++ b/src/plugin-sdk/acp-runtime.ts @@ -26,7 +26,29 @@ export type { export { readAcpSessionEntry } from "../acp/runtime/session-meta.js"; export type { AcpSessionStoreEntry } from "../acp/runtime/session-meta.js"; -export const __testing = { - ...managerTesting, - ...registryTesting, -}; +// Keep test helpers off the hot init path. Eagerly merging them here can +// create a back-edge through the bundled ACP runtime chunk before the imported +// testing bindings finish initialization. +export const __testing = new Proxy({} as typeof managerTesting & typeof registryTesting, { + get(_target, prop, receiver) { + if (Reflect.has(managerTesting, prop)) { + return Reflect.get(managerTesting, prop, receiver); + } + return Reflect.get(registryTesting, prop, receiver); + }, + has(_target, prop) { + return Reflect.has(managerTesting, prop) || Reflect.has(registryTesting, prop); + }, + ownKeys() { + return Array.from(new Set([...Reflect.ownKeys(managerTesting), ...Reflect.ownKeys(registryTesting)])); + }, + getOwnPropertyDescriptor(_target, prop) { + if (Reflect.has(managerTesting, prop) || Reflect.has(registryTesting, prop)) { + return { + configurable: true, + enumerable: true, + }; + } + return undefined; + }, +});