mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-08 19:12:22 +00:00
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:
@@ -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", () => {
|
||||
|
||||
@@ -260,4 +260,5 @@ export function setFeishuClientRuntimeForTest(overrides?: {
|
||||
feishuClientSdk = overrides?.sdk
|
||||
? { ...defaultFeishuClientSdk, ...overrides.sdk }
|
||||
: defaultFeishuClientSdk;
|
||||
clearClientCache();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user