Compare commits

...

1 Commits

Author SHA1 Message Date
Vincent Koc
a0a9501990 fix(plugins): restore release package compatibility 2026-06-17 15:04:16 +08:00
6 changed files with 79 additions and 23 deletions

View File

@@ -0,0 +1,30 @@
// Feishu client module import behavior tests.
import { afterEach, describe, expect, it, vi } from "vitest";
afterEach(() => {
vi.doUnmock("@larksuiteoapi/node-sdk");
vi.doUnmock("@openclaw/proxyline");
vi.resetModules();
});
describe("Feishu client module", () => {
it("loads when the SDK has no default HTTP instance", async () => {
vi.doMock("@larksuiteoapi/node-sdk", () => ({
AppType: { SelfBuild: "self" },
Domain: { Feishu: "https://open.feishu.cn", Lark: "https://open.larksuite.com" },
LoggerLevel: { info: "info" },
Client: vi.fn(),
WSClient: vi.fn(),
EventDispatcher: vi.fn(),
defaultHttpInstance: undefined,
}));
vi.doMock("@openclaw/proxyline", () => ({
createAmbientNodeProxyAgent: vi.fn(),
hasAmbientNodeProxyConfigured: vi.fn(() => false),
}));
await expect(import("./client.js")).resolves.toMatchObject({
createFeishuClient: expect.any(Function),
});
});
});

View File

@@ -387,6 +387,23 @@ describe("createFeishuClient HTTP timeout", () => {
});
});
it("rejects client creation when the SDK default HTTP instance is unavailable", () => {
setFeishuClientRuntimeForTest({
sdk: {
defaultHttpInstance: undefined as never,
},
});
expect(() =>
createFeishuClient({
appId: "app-default-http",
appSecret: "secret-default-http", // pragma: allowlist secret
accountId: "default-http-instance",
}),
).toThrow("Feishu SDK default HTTP instance is unavailable");
expect(clientCtorMock).not.toHaveBeenCalled();
});
it("evicts client cache when SDK is replaced via setFeishuClientRuntimeForTest (#83911)", () => {
const ctorCountA = clientCtorMock.mock.calls.length;

View File

@@ -67,12 +67,14 @@ let feishuClientSdk: FeishuClientSdk = defaultFeishuClientSdk;
// If a future SDK version adds more interceptors, the upgrade will need
// compatibility verification regardless.
{
const inst = Lark.defaultHttpInstance as {
interceptors?: {
request: { handlers: unknown[]; use: (fn: (req: unknown) => unknown) => void };
};
};
if (inst.interceptors?.request) {
const inst = Lark.defaultHttpInstance as
| {
interceptors?: {
request: { handlers: unknown[]; use: (fn: (req: unknown) => unknown) => void };
};
}
| undefined;
if (inst?.interceptors?.request) {
inst.interceptors.request.handlers = [];
inst.interceptors.request.use((req: unknown) => {
const r = req as { headers?: Record<string, string> };
@@ -119,9 +121,10 @@ function resolveDomain(domain: FeishuDomain | undefined): Lark.Domain | string {
* but injects a default request timeout and User-Agent header to prevent
* indefinite hangs and set a standardized User-Agent per OAPI best practices.
*/
function createTimeoutHttpInstance(defaultTimeoutMs: number): Lark.HttpInstance {
const base: FeishuHttpInstanceLike = feishuClientSdk.defaultHttpInstance;
function createTimeoutHttpInstance(
base: FeishuHttpInstanceLike,
defaultTimeoutMs: number,
): Lark.HttpInstance {
function injectTimeout<D>(opts?: Lark.HttpRequestOptions<D>): Lark.HttpRequestOptions<D> {
return { timeout: defaultTimeoutMs, ...opts } as Lark.HttpRequestOptions<D>;
}
@@ -175,13 +178,19 @@ export function createFeishuClient(creds: FeishuClientCredentials): Lark.Client
return cached.client;
}
// Create new client with timeout-aware HTTP instance
const defaultHttpInstance = feishuClientSdk.defaultHttpInstance as
| FeishuHttpInstanceLike
| undefined;
if (!defaultHttpInstance) {
throw new Error("Feishu SDK default HTTP instance is unavailable");
}
const client = new feishuClientSdk.Client({
appId,
appSecret,
appType: feishuClientSdk.AppType.SelfBuild,
domain: resolveDomain(domain),
httpInstance: createTimeoutHttpInstance(defaultHttpTimeoutMs),
httpInstance: createTimeoutHttpInstance(defaultHttpInstance, defaultHttpTimeoutMs),
});
// Cache it

View File

@@ -8,7 +8,7 @@
"name": "@openclaw/matrix",
"version": "2026.6.8",
"dependencies": {
"@matrix-org/matrix-sdk-crypto-nodejs": "0.6.0",
"@matrix-org/matrix-sdk-crypto-nodejs": "0.4.0",
"@matrix-org/matrix-sdk-crypto-wasm": "18.3.0",
"fake-indexeddb": "6.2.5",
"markdown-it": "14.2.0",
@@ -46,9 +46,9 @@
}
},
"node_modules/@matrix-org/matrix-sdk-crypto-nodejs": {
"version": "0.6.0",
"resolved": "https://registry.npmjs.org/@matrix-org/matrix-sdk-crypto-nodejs/-/matrix-sdk-crypto-nodejs-0.6.0.tgz",
"integrity": "sha512-AndGryzkDtFbaDyPBAQ2B4pUhaA/q4HJf3wgiGpPa/70DsdY1Z3R5Wn9yp+56CeHOpk61mNHz/8WDPlzrZDSJw==",
"version": "0.4.0",
"resolved": "https://registry.npmjs.org/@matrix-org/matrix-sdk-crypto-nodejs/-/matrix-sdk-crypto-nodejs-0.4.0.tgz",
"integrity": "sha512-+qqgpn39XFSbsD0dFjssGO9vHEP7sTyfs8yTpt8vuqWpUpF20QMwpCZi0jpYw7GxjErNTsMshopuo8677DfGEA==",
"hasInstallScript": true,
"license": "Apache-2.0",
"dependencies": {
@@ -56,7 +56,7 @@
"node-downloader-helper": "^2.1.9"
},
"engines": {
"node": ">= 24"
"node": ">= 22"
}
},
"node_modules/@matrix-org/matrix-sdk-crypto-wasm": {

View File

@@ -8,7 +8,7 @@
},
"type": "module",
"dependencies": {
"@matrix-org/matrix-sdk-crypto-nodejs": "0.6.0",
"@matrix-org/matrix-sdk-crypto-nodejs": "0.4.0",
"@matrix-org/matrix-sdk-crypto-wasm": "18.3.0",
"fake-indexeddb": "6.2.5",
"markdown-it": "14.2.0",

12
pnpm-lock.yaml generated
View File

@@ -957,8 +957,8 @@ importers:
extensions/matrix:
dependencies:
'@matrix-org/matrix-sdk-crypto-nodejs':
specifier: 0.6.0
version: 0.6.0
specifier: 0.4.0
version: 0.4.0
'@matrix-org/matrix-sdk-crypto-wasm':
specifier: 18.3.0
version: 18.3.0
@@ -2926,9 +2926,9 @@ packages:
'@lydell/node-pty@1.2.0-beta.12':
resolution: {integrity: sha512-qIK890UwPupoj07osVvgOIa++1mxeHbcGry4PKRHhNVNs81V2SCG34eJr46GybiOmBtc8Sj5PB1/GGM5PL549g==}
'@matrix-org/matrix-sdk-crypto-nodejs@0.6.0':
resolution: {integrity: sha512-AndGryzkDtFbaDyPBAQ2B4pUhaA/q4HJf3wgiGpPa/70DsdY1Z3R5Wn9yp+56CeHOpk61mNHz/8WDPlzrZDSJw==}
engines: {node: '>= 24'}
'@matrix-org/matrix-sdk-crypto-nodejs@0.4.0':
resolution: {integrity: sha512-+qqgpn39XFSbsD0dFjssGO9vHEP7sTyfs8yTpt8vuqWpUpF20QMwpCZi0jpYw7GxjErNTsMshopuo8677DfGEA==}
engines: {node: '>= 22'}
'@matrix-org/matrix-sdk-crypto-wasm@18.3.0':
resolution: {integrity: sha512-9a4feyt8QLysARu7PHKaRWT+wcCd+IYH074LXp9QK5WqfN4zUXueRhiSSMNT18Bm+8q3sBR/4zxDxOSDR0M8Kg==}
@@ -8873,7 +8873,7 @@ snapshots:
'@lydell/node-pty-win32-arm64': 1.2.0-beta.12
'@lydell/node-pty-win32-x64': 1.2.0-beta.12
'@matrix-org/matrix-sdk-crypto-nodejs@0.6.0':
'@matrix-org/matrix-sdk-crypto-nodejs@0.4.0':
dependencies:
https-proxy-agent: 7.0.6
node-downloader-helper: 2.1.11