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

@@ -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,