mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-05 21:10:21 +00:00
test: finish reply seam cleanup
This commit is contained in:
@@ -1,61 +0,0 @@
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import type { OpenClawConfig } from "../config/config.js";
|
||||
import { runEmbeddedPiAgentMock } from "./reply.directive.directive-behavior.e2e-mocks.js";
|
||||
import { createTempHomeHarness, makeReplyConfig } from "./reply.test-harness.js";
|
||||
|
||||
vi.mock(
|
||||
"../agents/model-fallback.js",
|
||||
async () => await import("../test-utils/model-fallback.mock.js"),
|
||||
);
|
||||
|
||||
const webMocks = vi.hoisted(() => ({
|
||||
webAuthExists: vi.fn().mockResolvedValue(true),
|
||||
getWebAuthAgeMs: vi.fn().mockReturnValue(120_000),
|
||||
readWebSelfId: vi.fn().mockReturnValue({ e164: "+1999" }),
|
||||
}));
|
||||
|
||||
vi.mock("../../extensions/whatsapp/runtime-api.js", () => webMocks);
|
||||
|
||||
import { getReplyFromConfig } from "./reply.js";
|
||||
|
||||
const { withTempHome } = createTempHomeHarness({
|
||||
prefix: "openclaw-typing-",
|
||||
beforeEachCase: () => runEmbeddedPiAgentMock.mockClear(),
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
vi.restoreAllMocks();
|
||||
});
|
||||
|
||||
describe("getReplyFromConfig typing (heartbeat)", () => {
|
||||
async function runReplyFlow(isHeartbeat: boolean): Promise<ReturnType<typeof vi.fn>> {
|
||||
const onReplyStart = vi.fn();
|
||||
await withTempHome(async (home) => {
|
||||
runEmbeddedPiAgentMock.mockResolvedValueOnce({
|
||||
payloads: [{ text: "ok" }],
|
||||
meta: {},
|
||||
});
|
||||
|
||||
await getReplyFromConfig(
|
||||
{ Body: "hi", From: "+1000", To: "+2000", Provider: "whatsapp" },
|
||||
{ onReplyStart, isHeartbeat },
|
||||
makeReplyConfig(home) as unknown as OpenClawConfig,
|
||||
);
|
||||
});
|
||||
return onReplyStart;
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
vi.stubEnv("OPENCLAW_TEST_FAST", "1");
|
||||
});
|
||||
|
||||
it("starts typing for normal runs", async () => {
|
||||
const onReplyStart = await runReplyFlow(false);
|
||||
expect(onReplyStart).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("does not start typing for heartbeat runs", async () => {
|
||||
const onReplyStart = await runReplyFlow(true);
|
||||
expect(onReplyStart).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
@@ -106,16 +106,6 @@ vi.mock("../../infra/outbound/session-binding-service.js", async (importOriginal
|
||||
return patched;
|
||||
});
|
||||
|
||||
// Prevent transitive import chain from reaching discord/monitor which needs https-proxy-agent.
|
||||
vi.mock("../../../extensions/discord/runtime-api.js", async (importOriginal) => {
|
||||
const actual =
|
||||
await importOriginal<typeof import("../../../extensions/discord/runtime-api.js")>();
|
||||
return {
|
||||
...actual,
|
||||
createDiscordGatewayPlugin: () => ({}),
|
||||
};
|
||||
});
|
||||
|
||||
const { handleAcpCommand } = await import("./commands-acp.js");
|
||||
const { buildCommandTestParams } = await import("./commands-spawn.test-harness.js");
|
||||
const { __testing: acpManagerTesting } = await import("../../acp/control-plane/manager.js");
|
||||
|
||||
@@ -1,6 +1,12 @@
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import type { OpenClawConfig } from "../../config/config.js";
|
||||
import type { SessionBindingRecord } from "../../infra/outbound/session-binding-service.js";
|
||||
import {
|
||||
resolveThreadBindingIdleTimeoutMs,
|
||||
resolveThreadBindingInactivityExpiresAt,
|
||||
resolveThreadBindingMaxAgeExpiresAt,
|
||||
resolveThreadBindingMaxAgeMs,
|
||||
} from "../../plugin-sdk/discord.js";
|
||||
|
||||
const hoisted = vi.hoisted(() => {
|
||||
const getThreadBindingManagerMock = vi.fn();
|
||||
@@ -24,20 +30,16 @@ const hoisted = vi.hoisted(() => {
|
||||
});
|
||||
|
||||
vi.mock("../../plugins/runtime/index.js", async () => {
|
||||
const discordThreadBindings = await vi.importActual<
|
||||
typeof import("../../../extensions/discord/runtime-api.js")
|
||||
>("../../../extensions/discord/runtime-api.js");
|
||||
return {
|
||||
createPluginRuntime: () => ({
|
||||
channel: {
|
||||
discord: {
|
||||
threadBindings: {
|
||||
getManager: hoisted.getThreadBindingManagerMock,
|
||||
resolveIdleTimeoutMs: discordThreadBindings.resolveThreadBindingIdleTimeoutMs,
|
||||
resolveInactivityExpiresAt:
|
||||
discordThreadBindings.resolveThreadBindingInactivityExpiresAt,
|
||||
resolveMaxAgeMs: discordThreadBindings.resolveThreadBindingMaxAgeMs,
|
||||
resolveMaxAgeExpiresAt: discordThreadBindings.resolveThreadBindingMaxAgeExpiresAt,
|
||||
resolveIdleTimeoutMs: resolveThreadBindingIdleTimeoutMs,
|
||||
resolveInactivityExpiresAt: resolveThreadBindingInactivityExpiresAt,
|
||||
resolveMaxAgeMs: resolveThreadBindingMaxAgeMs,
|
||||
resolveMaxAgeExpiresAt: resolveThreadBindingMaxAgeExpiresAt,
|
||||
setIdleTimeoutBySessionKey: hoisted.setThreadBindingIdleTimeoutBySessionKeyMock,
|
||||
setMaxAgeBySessionKey: hoisted.setThreadBindingMaxAgeBySessionKeyMock,
|
||||
unbindBySessionKey: vi.fn(),
|
||||
|
||||
@@ -8,9 +8,4 @@ vi.mock("../../config/config.js", async (importOriginal) => {
|
||||
};
|
||||
});
|
||||
|
||||
// Prevent transitive import chain from reaching discord/monitor which needs https-proxy-agent.
|
||||
vi.mock("../../../extensions/discord/runtime-api.js", () => ({
|
||||
createDiscordGatewayPlugin: () => ({}),
|
||||
}));
|
||||
|
||||
export function installSubagentsCommandCoreMocks() {}
|
||||
|
||||
Reference in New Issue
Block a user