mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-19 07:27:28 +00:00
refactor: share extension deferred and runtime helpers
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import type { PluginRuntime, RuntimeEnv } from "openclaw/plugin-sdk/matrix";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { createRuntimeEnv } from "../../test-utils/runtime-env.js";
|
||||
import { matrixPlugin } from "./channel.js";
|
||||
import { setMatrixRuntime } from "./runtime.js";
|
||||
import { createMatrixBotSdkMock } from "./test-mocks.js";
|
||||
@@ -10,13 +11,7 @@ vi.mock("@vector-im/matrix-bot-sdk", () =>
|
||||
);
|
||||
|
||||
describe("matrix directory", () => {
|
||||
const runtimeEnv: RuntimeEnv = {
|
||||
log: vi.fn(),
|
||||
error: vi.fn(),
|
||||
exit: vi.fn((code: number): never => {
|
||||
throw new Error(`exit ${code}`);
|
||||
}),
|
||||
};
|
||||
const runtimeEnv: RuntimeEnv = createRuntimeEnv();
|
||||
|
||||
beforeEach(() => {
|
||||
setMatrixRuntime({
|
||||
|
||||
@@ -15,6 +15,7 @@ import {
|
||||
PAIRING_APPROVED_MESSAGE,
|
||||
type ChannelPlugin,
|
||||
} from "openclaw/plugin-sdk/matrix";
|
||||
import { buildTrafficStatusSummary } from "../../shared/channel-status-summary.js";
|
||||
import { matrixMessageActions } from "./actions.js";
|
||||
import { MatrixConfigSchema } from "./config-schema.js";
|
||||
import { listMatrixDirectoryGroupsLive, listMatrixDirectoryPeersLive } from "./directory-live.js";
|
||||
@@ -410,8 +411,7 @@ export const matrixPlugin: ChannelPlugin<ResolvedMatrixAccount> = {
|
||||
lastError: runtime?.lastError ?? null,
|
||||
probe,
|
||||
lastProbeAt: runtime?.lastProbeAt ?? null,
|
||||
lastInboundAt: runtime?.lastInboundAt ?? null,
|
||||
lastOutboundAt: runtime?.lastOutboundAt ?? null,
|
||||
...buildTrafficStatusSummary(runtime),
|
||||
}),
|
||||
},
|
||||
gateway: {
|
||||
|
||||
@@ -1,16 +1,7 @@
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { createDeferred } from "../../../shared/deferred.js";
|
||||
import { DEFAULT_SEND_GAP_MS, enqueueSend } from "./send-queue.js";
|
||||
|
||||
function deferred<T>() {
|
||||
let resolve!: (value: T | PromiseLike<T>) => void;
|
||||
let reject!: (reason?: unknown) => void;
|
||||
const promise = new Promise<T>((res, rej) => {
|
||||
resolve = res;
|
||||
reject = rej;
|
||||
});
|
||||
return { promise, resolve, reject };
|
||||
}
|
||||
|
||||
describe("enqueueSend", () => {
|
||||
beforeEach(() => {
|
||||
vi.useFakeTimers();
|
||||
@@ -21,7 +12,7 @@ describe("enqueueSend", () => {
|
||||
});
|
||||
|
||||
it("serializes sends per room", async () => {
|
||||
const gate = deferred<void>();
|
||||
const gate = createDeferred<void>();
|
||||
const events: string[] = [];
|
||||
|
||||
const first = enqueueSend("!room:example.org", async () => {
|
||||
@@ -91,7 +82,7 @@ describe("enqueueSend", () => {
|
||||
});
|
||||
|
||||
it("continues queued work when the head task fails", async () => {
|
||||
const gate = deferred<void>();
|
||||
const gate = createDeferred<void>();
|
||||
const events: string[] = [];
|
||||
|
||||
const first = enqueueSend("!room:example.org", async () => {
|
||||
|
||||
Reference in New Issue
Block a user