Skip to content

Commit 762d8d8

Browse files
authored
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.
1 parent 205ab8d commit 762d8d8

2 files changed

Lines changed: 26 additions & 0 deletions

File tree

‎extensions/feishu/src/client.test.ts‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,31 @@ describe("createFeishuClient HTTP timeout", () => {
386386
timeout: 45_000,
387387
});
388388
});
389+
390+
it("evicts client cache when SDK is replaced via setFeishuClientRuntimeForTest (#83911)", () => {
391+
const ctorCountA = clientCtorMock.mock.calls.length;
392+
393+
// First client gets cached
394+
createFeishuClient({ appId: "app_7", appSecret: "secret_7", accountId: "cache-clear-test" }); // pragma: allowlist secret
395+
expect(clientCtorMock.mock.calls.length).toBe(ctorCountA + 1);
396+
397+
// SDK swap via setFeishuClientRuntimeForTest should clear the cache
398+
setFeishuClientRuntimeForTest({
399+
sdk: {
400+
AppType: { SelfBuild: "self" } as never,
401+
Client: clientCtorMock as never,
402+
Domain: { Feishu: "https://open.feishu.cn", Lark: "https://open.larksuite.com" } as never,
403+
LoggerLevel: { info: "info" } as never,
404+
WSClient: vi.fn() as never,
405+
EventDispatcher: vi.fn() as never,
406+
defaultHttpInstance: mockBaseHttpInstance as never,
407+
},
408+
});
409+
410+
// Same credentials — would hit cache before the fix; now evicted
411+
createFeishuClient({ appId: "app_7", appSecret: "secret_7", accountId: "cache-clear-test" }); // pragma: allowlist secret
412+
expect(clientCtorMock.mock.calls.length).toBe(ctorCountA + 2);
413+
});
389414
});
390415

391416
describe("createFeishuWSClient proxy handling", () => {

‎extensions/feishu/src/client.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,4 +260,5 @@ export function setFeishuClientRuntimeForTest(overrides?: {
260260
feishuClientSdk = overrides?.sdk
261261
? { ...defaultFeishuClientSdk, ...overrides.sdk }
262262
: defaultFeishuClientSdk;
263+
clearClientCache();
263264
}

0 commit comments

Comments
 (0)