mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 22:04:30 +00:00
chore: Fix types in tests 3/N.
This commit is contained in:
@@ -52,7 +52,8 @@ describe("gateway server chat", () => {
|
||||
|
||||
const spy = vi.mocked(getReplyFromConfig);
|
||||
spy.mockClear();
|
||||
const callsBeforeSanitized = spy.mock.calls.length;
|
||||
const spyCalls = spy.mock.calls as unknown[][];
|
||||
const callsBeforeSanitized = spyCalls.length;
|
||||
const sanitizedRes = await rpcReq(ws, "chat.send", {
|
||||
sessionKey: "main",
|
||||
message: "Cafe\u0301\u0007\tline",
|
||||
@@ -60,8 +61,8 @@ describe("gateway server chat", () => {
|
||||
});
|
||||
expect(sanitizedRes.ok).toBe(true);
|
||||
|
||||
await waitFor(() => spy.mock.calls.length > callsBeforeSanitized);
|
||||
const ctx = spy.mock.calls.at(-1)?.[0] as
|
||||
await waitFor(() => spyCalls.length > callsBeforeSanitized);
|
||||
const ctx = spyCalls.at(-1)?.[0] as
|
||||
| { Body?: string; RawBody?: string; BodyForCommands?: string }
|
||||
| undefined;
|
||||
expect(ctx?.Body).toBe("Café\tline");
|
||||
@@ -99,8 +100,9 @@ describe("gateway server chat", () => {
|
||||
|
||||
const spy = vi.mocked(getReplyFromConfig);
|
||||
spy.mockClear();
|
||||
const spyCalls = spy.mock.calls as unknown[][];
|
||||
testState.agentConfig = { timeoutSeconds: 123 };
|
||||
const callsBeforeTimeout = spy.mock.calls.length;
|
||||
const callsBeforeTimeout = spyCalls.length;
|
||||
const timeoutRes = await rpcReq(ws, "chat.send", {
|
||||
sessionKey: "main",
|
||||
message: "hello",
|
||||
@@ -108,13 +110,13 @@ describe("gateway server chat", () => {
|
||||
});
|
||||
expect(timeoutRes.ok).toBe(true);
|
||||
|
||||
await waitFor(() => spy.mock.calls.length > callsBeforeTimeout);
|
||||
const timeoutCall = spy.mock.calls.at(-1)?.[1] as { runId?: string } | undefined;
|
||||
await waitFor(() => spyCalls.length > callsBeforeTimeout);
|
||||
const timeoutCall = spyCalls.at(-1)?.[1] as { runId?: string } | undefined;
|
||||
expect(timeoutCall?.runId).toBe("idem-timeout-1");
|
||||
testState.agentConfig = undefined;
|
||||
|
||||
spy.mockClear();
|
||||
const callsBeforeSession = spy.mock.calls.length;
|
||||
const callsBeforeSession = spyCalls.length;
|
||||
const sessionRes = await rpcReq(ws, "chat.send", {
|
||||
sessionKey: "agent:main:subagent:abc",
|
||||
message: "hello",
|
||||
@@ -122,8 +124,8 @@ describe("gateway server chat", () => {
|
||||
});
|
||||
expect(sessionRes.ok).toBe(true);
|
||||
|
||||
await waitFor(() => spy.mock.calls.length > callsBeforeSession);
|
||||
const sessionCall = spy.mock.calls.at(-1)?.[0] as { SessionKey?: string } | undefined;
|
||||
await waitFor(() => spyCalls.length > callsBeforeSession);
|
||||
const sessionCall = spyCalls.at(-1)?.[0] as { SessionKey?: string } | undefined;
|
||||
expect(sessionCall?.SessionKey).toBe("agent:main:subagent:abc");
|
||||
|
||||
const sendPolicyDir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-gw-"));
|
||||
@@ -198,7 +200,7 @@ describe("gateway server chat", () => {
|
||||
testState.sessionConfig = undefined;
|
||||
|
||||
spy.mockClear();
|
||||
const callsBeforeImage = spy.mock.calls.length;
|
||||
const callsBeforeImage = spyCalls.length;
|
||||
const pngB64 =
|
||||
"iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/woAAn8B9FD5fHAAAAAASUVORK5CYII=";
|
||||
|
||||
@@ -228,13 +230,13 @@ describe("gateway server chat", () => {
|
||||
expect(imgRes.ok).toBe(true);
|
||||
expect(imgRes.payload?.runId).toBeDefined();
|
||||
|
||||
await waitFor(() => spy.mock.calls.length > callsBeforeImage, 8000);
|
||||
const imgOpts = spy.mock.calls.at(-1)?.[1] as
|
||||
await waitFor(() => spyCalls.length > callsBeforeImage, 8000);
|
||||
const imgOpts = spyCalls.at(-1)?.[1] as
|
||||
| { images?: Array<{ type: string; data: string; mimeType: string }> }
|
||||
| undefined;
|
||||
expect(imgOpts?.images).toEqual([{ type: "image", data: pngB64, mimeType: "image/png" }]);
|
||||
|
||||
const callsBeforeImageOnly = spy.mock.calls.length;
|
||||
const callsBeforeImageOnly = spyCalls.length;
|
||||
const reqIdOnly = "chat-img-only";
|
||||
ws.send(
|
||||
JSON.stringify({
|
||||
@@ -261,8 +263,8 @@ describe("gateway server chat", () => {
|
||||
expect(imgOnlyRes.ok).toBe(true);
|
||||
expect(imgOnlyRes.payload?.runId).toBeDefined();
|
||||
|
||||
await waitFor(() => spy.mock.calls.length > callsBeforeImageOnly, 8000);
|
||||
const imgOnlyOpts = spy.mock.calls.at(-1)?.[1] as
|
||||
await waitFor(() => spyCalls.length > callsBeforeImageOnly, 8000);
|
||||
const imgOnlyOpts = spyCalls.at(-1)?.[1] as
|
||||
| { images?: Array<{ type: string; data: string; mimeType: string }> }
|
||||
| undefined;
|
||||
expect(imgOnlyOpts?.images).toEqual([{ type: "image", data: pngB64, mimeType: "image/png" }]);
|
||||
@@ -410,10 +412,7 @@ describe("gateway server chat", () => {
|
||||
});
|
||||
|
||||
const evt = await agentEvtP;
|
||||
const payload =
|
||||
evt.payload && typeof evt.payload === "object"
|
||||
? (evt.payload as Record<string, unknown>)
|
||||
: {};
|
||||
const payload = evt.payload && typeof evt.payload === "object" ? evt.payload : {};
|
||||
expect(payload.sessionKey).toBe("main");
|
||||
expect(payload.stream).toBe("assistant");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user