mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-26 23:47:52 +00:00
test: guard auto reply command mock calls
This commit is contained in:
@@ -1013,8 +1013,8 @@ describe("resolveCommandAuthorization", () => {
|
||||
commandAuthorized: true,
|
||||
});
|
||||
expect(warn).toHaveBeenCalledTimes(1);
|
||||
expect(String(warn.mock.calls[0]?.[0] ?? "")).toContain("Error");
|
||||
expect(String(warn.mock.calls[0]?.[0] ?? "")).not.toContain("SECRET-TOKEN-123");
|
||||
expect(String(warn.mock.calls.at(0)?.[0] ?? "")).toContain("Error");
|
||||
expect(String(warn.mock.calls.at(0)?.[0] ?? "")).not.toContain("SECRET-TOKEN-123");
|
||||
} finally {
|
||||
warn.mockRestore();
|
||||
}
|
||||
|
||||
@@ -830,7 +830,7 @@ describe("runAgentTurnWithFallback", () => {
|
||||
expect(result.kind).toBe("success");
|
||||
expect(state.runCliAgentMock).not.toHaveBeenCalled();
|
||||
expect(state.runEmbeddedPiAgentMock).toHaveBeenCalledOnce();
|
||||
expect(state.runEmbeddedPiAgentMock.mock.calls[0]?.[0]).not.toHaveProperty(
|
||||
expect(state.runEmbeddedPiAgentMock.mock.calls.at(0)?.[0]).not.toHaveProperty(
|
||||
"agentHarnessId",
|
||||
"claude-cli",
|
||||
);
|
||||
@@ -880,7 +880,7 @@ describe("runAgentTurnWithFallback", () => {
|
||||
expectMockCallArgFields(onToolResult, 0, "tool result payload", {
|
||||
mediaUrls: ["/tmp/generated.png"],
|
||||
});
|
||||
expect(onToolResult.mock.calls[0]?.[0]?.text).toBeUndefined();
|
||||
expect(onToolResult.mock.calls.at(0)?.[0]?.text).toBeUndefined();
|
||||
});
|
||||
|
||||
it("surfaces model capacity errors from no-text mid-turn failures", async () => {
|
||||
|
||||
@@ -1144,7 +1144,7 @@ describe("/acp command", () => {
|
||||
expectBoundIntroTextToExclude("session ids: pending (available after the first reply)");
|
||||
expectGatewayMethodNotCalled("sessions.patch");
|
||||
expect(hoisted.upsertAcpSessionMetaMock).toHaveBeenCalledTimes(1);
|
||||
const upsertArgs = hoisted.upsertAcpSessionMetaMock.mock.calls[0]?.[0] as
|
||||
const upsertArgs = hoisted.upsertAcpSessionMetaMock.mock.calls.at(0)?.[0] as
|
||||
| {
|
||||
sessionKey: string;
|
||||
mutate: (
|
||||
@@ -1632,7 +1632,7 @@ describe("/acp command", () => {
|
||||
reason: "manual",
|
||||
});
|
||||
expect(hoisted.upsertAcpSessionMetaMock).toHaveBeenCalledTimes(1);
|
||||
const clearMetaArgs = hoisted.upsertAcpSessionMetaMock.mock.calls[0]?.[0] as
|
||||
const clearMetaArgs = hoisted.upsertAcpSessionMetaMock.mock.calls.at(0)?.[0] as
|
||||
| {
|
||||
sessionKey: string;
|
||||
mutate: (current: unknown, entry: { sessionId: string; updatedAt: number }) => unknown;
|
||||
|
||||
@@ -60,7 +60,7 @@ describe("emitResetCommandHooks", () => {
|
||||
});
|
||||
|
||||
expect(hookRunnerMocks.runBeforeReset).toHaveBeenCalledTimes(1);
|
||||
const [, ctx] = hookRunnerMocks.runBeforeReset.mock.calls[0] ?? [];
|
||||
const [, ctx] = hookRunnerMocks.runBeforeReset.mock.calls.at(0) ?? [];
|
||||
return ctx;
|
||||
}
|
||||
|
||||
@@ -136,7 +136,7 @@ describe("emitResetCommandHooks", () => {
|
||||
});
|
||||
|
||||
await vi.waitFor(() => expect(hookRunnerMocks.runBeforeReset).toHaveBeenCalledTimes(1));
|
||||
const [event, ctx] = hookRunnerMocks.runBeforeReset.mock.calls[0] as unknown as [
|
||||
const [event, ctx] = hookRunnerMocks.runBeforeReset.mock.calls.at(0) as unknown as [
|
||||
Record<string, unknown>,
|
||||
Record<string, unknown>,
|
||||
];
|
||||
|
||||
@@ -186,7 +186,8 @@ describe("handleModelsCommand", () => {
|
||||
expect(result?.reply?.text).toContain("Use: /models <provider>");
|
||||
expect(result?.reply?.text).toContain("Switch: /model <provider/model>");
|
||||
expect(result?.reply?.text).not.toContain("Add: /models add");
|
||||
const authCheckerParams = modelProviderAuthMocks.createProviderAuthChecker.mock.calls[0]?.[0];
|
||||
const authCheckerParams =
|
||||
modelProviderAuthMocks.createProviderAuthChecker.mock.calls.at(0)?.[0];
|
||||
expect(authCheckerParams?.workspaceDir).toBe("/tmp");
|
||||
});
|
||||
|
||||
@@ -411,7 +412,8 @@ describe("handleModelsCommand", () => {
|
||||
const result = await handleModelsCommand(params, true);
|
||||
|
||||
expect(result?.reply?.text).toContain("- anthropic (2)");
|
||||
const authCheckerParams = modelProviderAuthMocks.createProviderAuthChecker.mock.calls[0]?.[0];
|
||||
const authCheckerParams =
|
||||
modelProviderAuthMocks.createProviderAuthChecker.mock.calls.at(0)?.[0];
|
||||
expect(authCheckerParams?.workspaceDir).toBe("/tmp/spawned-workspace");
|
||||
});
|
||||
|
||||
|
||||
@@ -128,7 +128,7 @@ describe("handleRestartCommand", () => {
|
||||
|
||||
expect(result?.shouldContinue).toBe(false);
|
||||
expect(mocks.writeRestartSentinel).toHaveBeenCalledOnce();
|
||||
const sentinelPayload = mocks.writeRestartSentinel.mock.calls[0]?.[0];
|
||||
const sentinelPayload = mocks.writeRestartSentinel.mock.calls.at(0)?.[0];
|
||||
expect(sentinelPayload?.kind).toBe("restart");
|
||||
expect(sentinelPayload?.status).toBe("ok");
|
||||
expect(typeof sentinelPayload?.ts).toBe("number");
|
||||
@@ -166,7 +166,7 @@ describe("handleRestartCommand", () => {
|
||||
await scheduledArgs?.emitHooks?.beforeEmit?.();
|
||||
|
||||
expect(mocks.writeRestartSentinel).toHaveBeenCalledOnce();
|
||||
const sentinelPayload = mocks.writeRestartSentinel.mock.calls[0]?.[0];
|
||||
const sentinelPayload = mocks.writeRestartSentinel.mock.calls.at(0)?.[0];
|
||||
expect(sentinelPayload?.kind).toBe("restart");
|
||||
expect(sentinelPayload?.status).toBe("ok");
|
||||
expect(sentinelPayload?.sessionKey).toBe("agent:main:telegram:direct:123:thread:thread-1");
|
||||
|
||||
@@ -178,7 +178,7 @@ type SessionBindingBindInput = {
|
||||
};
|
||||
|
||||
function firstFocusTargetSessionParams(): FocusTargetSessionParams {
|
||||
const firstCall = hoisted.resolveFocusTargetSessionMock.mock.calls[0];
|
||||
const firstCall = hoisted.resolveFocusTargetSessionMock.mock.calls.at(0);
|
||||
if (!firstCall) {
|
||||
throw new Error("Expected focus target session call");
|
||||
}
|
||||
@@ -186,7 +186,7 @@ function firstFocusTargetSessionParams(): FocusTargetSessionParams {
|
||||
}
|
||||
|
||||
function firstSessionBindingBindInput(): SessionBindingBindInput {
|
||||
const firstCall = hoisted.sessionBindingBindMock.mock.calls[0];
|
||||
const firstCall = hoisted.sessionBindingBindMock.mock.calls.at(0);
|
||||
if (!firstCall) {
|
||||
throw new Error("Expected session binding bind call");
|
||||
}
|
||||
|
||||
@@ -109,7 +109,7 @@ describe("dispatchReplyFromConfig reply_dispatch hook", () => {
|
||||
});
|
||||
|
||||
expect(runtimePluginMocks.ensureRuntimePluginsLoaded).toHaveBeenCalledOnce();
|
||||
const runtimeLoadCall = runtimePluginMocks.ensureRuntimePluginsLoaded.mock.calls[0]?.[0] as
|
||||
const runtimeLoadCall = runtimePluginMocks.ensureRuntimePluginsLoaded.mock.calls.at(0)?.[0] as
|
||||
| { config?: unknown; workspaceDir?: unknown }
|
||||
| undefined;
|
||||
expect(runtimeLoadCall?.config).toBe(emptyConfig);
|
||||
@@ -118,7 +118,7 @@ describe("dispatchReplyFromConfig reply_dispatch hook", () => {
|
||||
|
||||
expect(hookMocks.runner.runReplyDispatch).toHaveBeenCalledOnce();
|
||||
const [replyDispatchEvent, replyDispatchRuntime] =
|
||||
(hookMocks.runner.runReplyDispatch.mock.calls[0] as
|
||||
(hookMocks.runner.runReplyDispatch.mock.calls.at(0) as
|
||||
| [
|
||||
{
|
||||
sessionKey?: string;
|
||||
|
||||
@@ -133,7 +133,7 @@ describe("getReplyFromConfig fast test bootstrap", () => {
|
||||
expect(mocks.initSessionState).not.toHaveBeenCalled();
|
||||
expect(mocks.resolveReplyDirectives).not.toHaveBeenCalled();
|
||||
expect(vi.mocked(runPreparedReplyMock)).toHaveBeenCalledOnce();
|
||||
const preparedReplyParams = vi.mocked(runPreparedReplyMock).mock.calls[0]?.[0];
|
||||
const preparedReplyParams = vi.mocked(runPreparedReplyMock).mock.calls.at(0)?.[0];
|
||||
if (!preparedReplyParams) {
|
||||
throw new Error("expected prepared reply params");
|
||||
}
|
||||
@@ -443,7 +443,7 @@ describe("getReplyFromConfig fast test bootstrap", () => {
|
||||
expect(mocks.initSessionState).not.toHaveBeenCalled();
|
||||
expect(vi.mocked(runPreparedReplyMock)).not.toHaveBeenCalled();
|
||||
expect(mocks.resolveReplyDirectives).toHaveBeenCalledOnce();
|
||||
const directiveParams = mocks.resolveReplyDirectives.mock.calls[0]?.[0] as
|
||||
const directiveParams = mocks.resolveReplyDirectives.mock.calls.at(0)?.[0] as
|
||||
| { sessionKey?: string; workspaceDir?: string }
|
||||
| undefined;
|
||||
if (!directiveParams) {
|
||||
|
||||
@@ -80,8 +80,8 @@ describe("session-updates lifecycle hooks", () => {
|
||||
expect(hookRunnerMocks.runSessionEnd).toHaveBeenCalledTimes(1);
|
||||
expect(hookRunnerMocks.runSessionStart).toHaveBeenCalledTimes(1);
|
||||
|
||||
const [endEvent, endContext] = hookRunnerMocks.runSessionEnd.mock.calls[0] ?? [];
|
||||
const [startEvent, startContext] = hookRunnerMocks.runSessionStart.mock.calls[0] ?? [];
|
||||
const [endEvent, endContext] = hookRunnerMocks.runSessionEnd.mock.calls.at(0) ?? [];
|
||||
const [startEvent, startContext] = hookRunnerMocks.runSessionStart.mock.calls.at(0) ?? [];
|
||||
|
||||
expect(endEvent?.sessionId).toBe("s1");
|
||||
expect(endEvent?.sessionKey).toBe(sessionKey);
|
||||
|
||||
Reference in New Issue
Block a user