chore: Fix types in tests 11/N.

This commit is contained in:
cpojer
2026-02-17 11:17:32 +09:00
parent 058eb85762
commit e02feaff83
6 changed files with 87 additions and 86 deletions

View File

@@ -92,7 +92,7 @@ describe("hooks mapping", () => {
],
});
expect(result?.ok).toBe(true);
if (result?.ok) {
if (result?.ok && result.action?.kind === "agent") {
expect(result.action.kind).toBe("agent");
expect(result.action.message).toBe("Subject: Hello");
}
@@ -146,11 +146,9 @@ describe("hooks mapping", () => {
});
expect(result?.ok).toBe(true);
if (result?.ok) {
if (result?.ok && result.action?.kind === "wake") {
expect(result.action.kind).toBe("wake");
if (result.action.kind === "wake") {
expect(result.action.text).toBe("Ping Ada");
}
expect(result.action.text).toBe("Ping Ada");
}
});
@@ -259,7 +257,7 @@ describe("hooks mapping", () => {
],
});
expect(result?.ok).toBe(true);
if (result?.ok) {
if (result?.ok && result.action?.kind === "agent") {
expect(result.action.kind).toBe("agent");
expect(result.action.message).toBe("Override subject: Hello");
}

View File

@@ -113,7 +113,7 @@ describe("OpenAI-compatible HTTP API (e2e)", () => {
const res = await postChatCompletions(port, request.body, request.headers);
expect(res.status).toBe(200);
expect(agentCommand).toHaveBeenCalledTimes(1);
const [opts] = agentCommand.mock.calls[0] ?? [];
const opts = (agentCommand.mock.calls[0] as unknown[] | undefined)?.[0];
expect((opts as { sessionKey?: string } | undefined)?.sessionKey ?? "").toMatch(
request.matcher,
);
@@ -181,7 +181,7 @@ describe("OpenAI-compatible HTTP API (e2e)", () => {
);
expect(res.status).toBe(200);
const [opts] = agentCommand.mock.calls[0] ?? [];
const opts = (agentCommand.mock.calls[0] as unknown[] | undefined)?.[0];
expect((opts as { sessionKey?: string } | undefined)?.sessionKey).toBe(
"agent:beta:openai:custom",
);
@@ -197,7 +197,7 @@ describe("OpenAI-compatible HTTP API (e2e)", () => {
});
expect(res.status).toBe(200);
const [opts] = agentCommand.mock.calls[0] ?? [];
const opts = (agentCommand.mock.calls[0] as unknown[] | undefined)?.[0];
expect((opts as { sessionKey?: string } | undefined)?.sessionKey ?? "").toContain(
"openai-user:alice",
);
@@ -220,7 +220,7 @@ describe("OpenAI-compatible HTTP API (e2e)", () => {
});
expect(res.status).toBe(200);
const [opts] = agentCommand.mock.calls[0] ?? [];
const opts = (agentCommand.mock.calls[0] as unknown[] | undefined)?.[0];
expect((opts as { message?: string } | undefined)?.message).toBe("hello\nworld");
await res.text();
}
@@ -238,7 +238,7 @@ describe("OpenAI-compatible HTTP API (e2e)", () => {
});
expect(res.status).toBe(200);
const [opts] = agentCommand.mock.calls[0] ?? [];
const opts = (agentCommand.mock.calls[0] as unknown[] | undefined)?.[0];
const message = (opts as { message?: string } | undefined)?.message ?? "";
expect(message).toContain(HISTORY_CONTEXT_MARKER);
expect(message).toContain("User: Hello, who are you?");
@@ -259,7 +259,7 @@ describe("OpenAI-compatible HTTP API (e2e)", () => {
});
expect(res.status).toBe(200);
const [opts] = agentCommand.mock.calls[0] ?? [];
const opts = (agentCommand.mock.calls[0] as unknown[] | undefined)?.[0];
const message = (opts as { message?: string } | undefined)?.message ?? "";
expect(message).not.toContain(HISTORY_CONTEXT_MARKER);
expect(message).not.toContain(CURRENT_MESSAGE_MARKER);
@@ -278,7 +278,7 @@ describe("OpenAI-compatible HTTP API (e2e)", () => {
});
expect(res.status).toBe(200);
const [opts] = agentCommand.mock.calls[0] ?? [];
const opts = (agentCommand.mock.calls[0] as unknown[] | undefined)?.[0];
const extraSystemPrompt =
(opts as { extraSystemPrompt?: string } | undefined)?.extraSystemPrompt ?? "";
expect(extraSystemPrompt).toBe("You are a helpful assistant.");
@@ -298,7 +298,7 @@ describe("OpenAI-compatible HTTP API (e2e)", () => {
});
expect(res.status).toBe(200);
const [opts] = agentCommand.mock.calls[0] ?? [];
const opts = (agentCommand.mock.calls[0] as unknown[] | undefined)?.[0];
const message = (opts as { message?: string } | undefined)?.message ?? "";
expect(message).toContain(HISTORY_CONTEXT_MARKER);
expect(message).toContain("User: What's the weather?");
@@ -389,12 +389,12 @@ describe("OpenAI-compatible HTTP API (e2e)", () => {
try {
{
agentCommand.mockReset();
agentCommand.mockImplementationOnce(async (opts: unknown) => {
agentCommand.mockImplementationOnce((async (opts: unknown) => {
const runId = (opts as { runId?: string } | undefined)?.runId ?? "";
emitAgentEvent({ runId, stream: "assistant", data: { delta: "he" } });
emitAgentEvent({ runId, stream: "assistant", data: { delta: "llo" } });
return { payloads: [{ text: "hello" }] } as never;
});
}) as never);
const res = await postChatCompletions(port, {
stream: true,
@@ -422,12 +422,12 @@ describe("OpenAI-compatible HTTP API (e2e)", () => {
{
agentCommand.mockReset();
agentCommand.mockImplementationOnce(async (opts: unknown) => {
agentCommand.mockImplementationOnce((async (opts: unknown) => {
const runId = (opts as { runId?: string } | undefined)?.runId ?? "";
emitAgentEvent({ runId, stream: "assistant", data: { delta: "hi" } });
emitAgentEvent({ runId, stream: "assistant", data: { delta: "hi" } });
return { payloads: [{ text: "hihi" }] } as never;
});
}) as never);
const repeatedRes = await postChatCompletions(port, {
stream: true,

View File

@@ -158,7 +158,7 @@ describe("OpenResponses HTTP API (e2e)", () => {
{ "x-openclaw-agent-id": "beta" },
);
expect(resHeader.status).toBe(200);
const [optsHeader] = agentCommand.mock.calls[0] ?? [];
const optsHeader = (agentCommand.mock.calls[0] as unknown[] | undefined)?.[0];
expect((optsHeader as { sessionKey?: string } | undefined)?.sessionKey ?? "").toMatch(
/^agent:beta:/,
);
@@ -167,7 +167,7 @@ describe("OpenResponses HTTP API (e2e)", () => {
mockAgentOnce([{ text: "hello" }]);
const resModel = await postResponses(port, { model: "openclaw:beta", input: "hi" });
expect(resModel.status).toBe(200);
const [optsModel] = agentCommand.mock.calls[0] ?? [];
const optsModel = (agentCommand.mock.calls[0] as unknown[] | undefined)?.[0];
expect((optsModel as { sessionKey?: string } | undefined)?.sessionKey ?? "").toMatch(
/^agent:beta:/,
);
@@ -180,7 +180,7 @@ describe("OpenResponses HTTP API (e2e)", () => {
input: "hi",
});
expect(resUser.status).toBe(200);
const [optsUser] = agentCommand.mock.calls[0] ?? [];
const optsUser = (agentCommand.mock.calls[0] as unknown[] | undefined)?.[0];
expect((optsUser as { sessionKey?: string } | undefined)?.sessionKey ?? "").toContain(
"openresponses-user:alice",
);
@@ -192,7 +192,7 @@ describe("OpenResponses HTTP API (e2e)", () => {
input: "hello world",
});
expect(resString.status).toBe(200);
const [optsString] = agentCommand.mock.calls[0] ?? [];
const optsString = (agentCommand.mock.calls[0] as unknown[] | undefined)?.[0];
expect((optsString as { message?: string } | undefined)?.message).toBe("hello world");
await ensureResponseConsumed(resString);
@@ -202,7 +202,7 @@ describe("OpenResponses HTTP API (e2e)", () => {
input: [{ type: "message", role: "user", content: "hello there" }],
});
expect(resArray.status).toBe(200);
const [optsArray] = agentCommand.mock.calls[0] ?? [];
const optsArray = (agentCommand.mock.calls[0] as unknown[] | undefined)?.[0];
expect((optsArray as { message?: string } | undefined)?.message).toBe("hello there");
await ensureResponseConsumed(resArray);
@@ -216,7 +216,7 @@ describe("OpenResponses HTTP API (e2e)", () => {
],
});
expect(resSystemDeveloper.status).toBe(200);
const [optsSystemDeveloper] = agentCommand.mock.calls[0] ?? [];
const optsSystemDeveloper = (agentCommand.mock.calls[0] as unknown[] | undefined)?.[0];
const extraSystemPrompt =
(optsSystemDeveloper as { extraSystemPrompt?: string } | undefined)?.extraSystemPrompt ??
"";
@@ -231,7 +231,7 @@ describe("OpenResponses HTTP API (e2e)", () => {
instructions: "Always respond in French.",
});
expect(resInstructions.status).toBe(200);
const [optsInstructions] = agentCommand.mock.calls[0] ?? [];
const optsInstructions = (agentCommand.mock.calls[0] as unknown[] | undefined)?.[0];
const instructionPrompt =
(optsInstructions as { extraSystemPrompt?: string } | undefined)?.extraSystemPrompt ?? "";
expect(instructionPrompt).toContain("Always respond in French.");
@@ -248,7 +248,7 @@ describe("OpenResponses HTTP API (e2e)", () => {
],
});
expect(resHistory.status).toBe(200);
const [optsHistory] = agentCommand.mock.calls[0] ?? [];
const optsHistory = (agentCommand.mock.calls[0] as unknown[] | undefined)?.[0];
const historyMessage = (optsHistory as { message?: string } | undefined)?.message ?? "";
expect(historyMessage).toContain(HISTORY_CONTEXT_MARKER);
expect(historyMessage).toContain("User: Hello, who are you?");
@@ -266,7 +266,7 @@ describe("OpenResponses HTTP API (e2e)", () => {
],
});
expect(resFunctionOutput.status).toBe(200);
const [optsFunctionOutput] = agentCommand.mock.calls[0] ?? [];
const optsFunctionOutput = (agentCommand.mock.calls[0] as unknown[] | undefined)?.[0];
const functionOutputMessage =
(optsFunctionOutput as { message?: string } | undefined)?.message ?? "";
expect(functionOutputMessage).toContain("Sunny, 70F.");
@@ -295,7 +295,7 @@ describe("OpenResponses HTTP API (e2e)", () => {
],
});
expect(resInputFile.status).toBe(200);
const [optsInputFile] = agentCommand.mock.calls[0] ?? [];
const optsInputFile = (agentCommand.mock.calls[0] as unknown[] | undefined)?.[0];
const inputFileMessage = (optsInputFile as { message?: string } | undefined)?.message ?? "";
const inputFilePrompt =
(optsInputFile as { extraSystemPrompt?: string } | undefined)?.extraSystemPrompt ?? "";
@@ -316,7 +316,7 @@ describe("OpenResponses HTTP API (e2e)", () => {
tool_choice: "none",
});
expect(resToolNone.status).toBe(200);
const [optsToolNone] = agentCommand.mock.calls[0] ?? [];
const optsToolNone = (agentCommand.mock.calls[0] as unknown[] | undefined)?.[0];
expect(
(optsToolNone as { clientTools?: unknown[] } | undefined)?.clientTools,
).toBeUndefined();
@@ -339,9 +339,9 @@ describe("OpenResponses HTTP API (e2e)", () => {
tool_choice: { type: "function", function: { name: "get_time" } },
});
expect(resToolChoice.status).toBe(200);
const [optsToolChoice] = agentCommand.mock.calls[0] ?? [];
const optsToolChoice = (agentCommand.mock.calls[0] as unknown[] | undefined)?.[0];
const clientTools =
(optsToolChoice as { clientTools?: Array<{ function?: { name?: string } }> })
(optsToolChoice as { clientTools?: Array<{ function?: { name?: string } }> } | undefined)
?.clientTools ?? [];
expect(clientTools).toHaveLength(1);
expect(clientTools[0]?.function?.name).toBe("get_time");
@@ -368,7 +368,7 @@ describe("OpenResponses HTTP API (e2e)", () => {
max_output_tokens: 123,
});
expect(resMaxTokens.status).toBe(200);
const [optsMaxTokens] = agentCommand.mock.calls[0] ?? [];
const optsMaxTokens = (agentCommand.mock.calls[0] as unknown[] | undefined)?.[0];
expect(
(optsMaxTokens as { streamParams?: { maxTokens?: number } } | undefined)?.streamParams
?.maxTokens,
@@ -433,12 +433,12 @@ describe("OpenResponses HTTP API (e2e)", () => {
const port = enabledPort;
try {
agentCommand.mockReset();
agentCommand.mockImplementationOnce(async (opts: unknown) => {
agentCommand.mockImplementationOnce((async (opts: unknown) => {
const runId = (opts as { runId?: string } | undefined)?.runId ?? "";
emitAgentEvent({ runId, stream: "assistant", data: { delta: "he" } });
emitAgentEvent({ runId, stream: "assistant", data: { delta: "llo" } });
return { payloads: [{ text: "hello" }] } as never;
});
}) as never);
const resDelta = await postResponses(port, {
stream: true,

View File

@@ -77,7 +77,7 @@ describe("gateway server hooks", () => {
});
expect(resAgentModel.status).toBe(202);
await waitForSystemEvent();
const call = cronIsolatedRun.mock.calls[0]?.[0] as {
const call = (cronIsolatedRun.mock.calls[0] as unknown[] | undefined)?.[0] as {
job?: { payload?: { model?: string } };
};
expect(call?.job?.payload?.model).toBe("openai/gpt-4.1-mini");
@@ -98,7 +98,7 @@ describe("gateway server hooks", () => {
});
expect(resAgentWithId.status).toBe(202);
await waitForSystemEvent();
const routedCall = cronIsolatedRun.mock.calls[0]?.[0] as {
const routedCall = (cronIsolatedRun.mock.calls[0] as unknown[] | undefined)?.[0] as {
job?: { agentId?: string };
};
expect(routedCall?.job?.agentId).toBe("hooks");
@@ -119,7 +119,7 @@ describe("gateway server hooks", () => {
});
expect(resAgentUnknown.status).toBe(202);
await waitForSystemEvent();
const fallbackCall = cronIsolatedRun.mock.calls[0]?.[0] as {
const fallbackCall = (cronIsolatedRun.mock.calls[0] as unknown[] | undefined)?.[0] as {
job?: { agentId?: string };
};
expect(fallbackCall?.job?.agentId).toBe("main");
@@ -250,7 +250,9 @@ describe("gateway server hooks", () => {
});
expect(defaultRoute.status).toBe(202);
await waitForSystemEvent();
const defaultCall = cronIsolatedRun.mock.calls[0]?.[0] as { sessionKey?: string } | undefined;
const defaultCall = (cronIsolatedRun.mock.calls[0] as unknown[] | undefined)?.[0] as
| { sessionKey?: string }
| undefined;
expect(defaultCall?.sessionKey).toBe("hook:ingress");
drainSystemEvents(resolveMainKey());
@@ -266,7 +268,9 @@ describe("gateway server hooks", () => {
});
expect(mappedOk.status).toBe(202);
await waitForSystemEvent();
const mappedCall = cronIsolatedRun.mock.calls[0]?.[0] as { sessionKey?: string } | undefined;
const mappedCall = (cronIsolatedRun.mock.calls[0] as unknown[] | undefined)?.[0] as
| { sessionKey?: string }
| undefined;
expect(mappedCall?.sessionKey).toBe("hook:mapped:42");
drainSystemEvents(resolveMainKey());
@@ -328,7 +332,7 @@ describe("gateway server hooks", () => {
});
expect(resNoAgent.status).toBe(202);
await waitForSystemEvent();
const noAgentCall = cronIsolatedRun.mock.calls[0]?.[0] as {
const noAgentCall = (cronIsolatedRun.mock.calls[0] as unknown[] | undefined)?.[0] as {
job?: { agentId?: string };
};
expect(noAgentCall?.job?.agentId).toBeUndefined();
@@ -349,7 +353,7 @@ describe("gateway server hooks", () => {
});
expect(resAllowed.status).toBe(202);
await waitForSystemEvent();
const allowedCall = cronIsolatedRun.mock.calls[0]?.[0] as {
const allowedCall = (cronIsolatedRun.mock.calls[0] as unknown[] | undefined)?.[0] as {
job?: { agentId?: string };
};
expect(allowedCall?.job?.agentId).toBe("hooks");