fix(feishu): clear client cache on test SDK swap

Clear cached Feishu clients when the test runtime replaces the SDK, preventing stale clients from leaking across test setup. Adds regression coverage for the SDK swap path. Fixes #83911.
This commit is contained in:
Song Zhenlin
2026-06-13 22:01:15 +08:00
committed by GitHub
parent 205ab8d4bd
commit 762d8d8e64
2 changed files with 26 additions and 0 deletions

View File

@@ -386,6 +386,31 @@ describe("createFeishuClient HTTP timeout", () => {
timeout: 45_000,
});
});
it("evicts client cache when SDK is replaced via setFeishuClientRuntimeForTest (#83911)", () => {
const ctorCountA = clientCtorMock.mock.calls.length;
// First client gets cached
createFeishuClient({ appId: "app_7", appSecret: "secret_7", accountId: "cache-clear-test" }); // pragma: allowlist secret
expect(clientCtorMock.mock.calls.length).toBe(ctorCountA + 1);
// SDK swap via setFeishuClientRuntimeForTest should clear the cache
setFeishuClientRuntimeForTest({
sdk: {
AppType: { SelfBuild: "self" } as never,
Client: clientCtorMock as never,
Domain: { Feishu: "https://open.feishu.cn", Lark: "https://open.larksuite.com" } as never,
LoggerLevel: { info: "info" } as never,
WSClient: vi.fn() as never,
EventDispatcher: vi.fn() as never,
defaultHttpInstance: mockBaseHttpInstance as never,
},
});
// Same credentials — would hit cache before the fix; now evicted
createFeishuClient({ appId: "app_7", appSecret: "secret_7", accountId: "cache-clear-test" }); // pragma: allowlist secret
expect(clientCtorMock.mock.calls.length).toBe(ctorCountA + 2);
});
});
describe("createFeishuWSClient proxy handling", () => {

View File

@@ -260,4 +260,5 @@ export function setFeishuClientRuntimeForTest(overrides?: {
feishuClientSdk = overrides?.sdk
? { ...defaultFeishuClientSdk, ...overrides.sdk }
: defaultFeishuClientSdk;
clearClientCache();
}