mirror of
https://github.com/farcasclaudiu/openclaw.git
synced 2026-06-29 03:01:50 +03:00
perf(test): merge block-streaming scenarios into single fixture run
This commit is contained in:
@@ -98,7 +98,7 @@ describe("block streaming", () => {
|
|||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("waits for block replies and preserves ordering when typing start is slow", async () => {
|
it("handles ordering, timeout fallback, and telegram streamMode block", async () => {
|
||||||
await withTempHome(async (home) => {
|
await withTempHome(async (home) => {
|
||||||
let releaseTyping: (() => void) | undefined;
|
let releaseTyping: (() => void) | undefined;
|
||||||
const typingGate = new Promise<void>((resolve) => {
|
const typingGate = new Promise<void>((resolve) => {
|
||||||
@@ -161,13 +161,9 @@ describe("block streaming", () => {
|
|||||||
const res = await replyPromise;
|
const res = await replyPromise;
|
||||||
expect(res).toBeUndefined();
|
expect(res).toBeUndefined();
|
||||||
expect(seen).toEqual(["first\n\nsecond"]);
|
expect(seen).toEqual(["first\n\nsecond"]);
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it("falls back to final payloads and respects telegram streamMode block", async () => {
|
|
||||||
await withTempHome(async (home) => {
|
|
||||||
let sawAbort = false;
|
let sawAbort = false;
|
||||||
const onBlockReply = vi.fn((_, context) => {
|
const onBlockReplyTimeout = vi.fn((_, context) => {
|
||||||
return new Promise<void>((resolve) => {
|
return new Promise<void>((resolve) => {
|
||||||
context?.abortSignal?.addEventListener(
|
context?.abortSignal?.addEventListener(
|
||||||
"abort",
|
"abort",
|
||||||
@@ -180,7 +176,7 @@ describe("block streaming", () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
const impl = async (params: RunEmbeddedPiAgentParams) => {
|
const timeoutImpl = async (params: RunEmbeddedPiAgentParams) => {
|
||||||
void params.onBlockReply?.({ text: "streamed" });
|
void params.onBlockReply?.({ text: "streamed" });
|
||||||
return {
|
return {
|
||||||
payloads: [{ text: "final" }],
|
payloads: [{ text: "final" }],
|
||||||
@@ -190,9 +186,9 @@ describe("block streaming", () => {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
piEmbeddedMock.runEmbeddedPiAgent.mockImplementation(impl);
|
piEmbeddedMock.runEmbeddedPiAgent.mockImplementation(timeoutImpl);
|
||||||
|
|
||||||
const replyPromise = getReplyFromConfig(
|
const timeoutReplyPromise = getReplyFromConfig(
|
||||||
{
|
{
|
||||||
Body: "ping",
|
Body: "ping",
|
||||||
From: "+1004",
|
From: "+1004",
|
||||||
@@ -201,7 +197,7 @@ describe("block streaming", () => {
|
|||||||
Provider: "telegram",
|
Provider: "telegram",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
onBlockReply,
|
onBlockReply: onBlockReplyTimeout,
|
||||||
blockReplyTimeoutMs: 1,
|
blockReplyTimeoutMs: 1,
|
||||||
disableBlockStreaming: false,
|
disableBlockStreaming: false,
|
||||||
},
|
},
|
||||||
@@ -217,8 +213,8 @@ describe("block streaming", () => {
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
const res = await replyPromise;
|
const timeoutRes = await timeoutReplyPromise;
|
||||||
expect(res).toMatchObject({ text: "final" });
|
expect(timeoutRes).toMatchObject({ text: "final" });
|
||||||
expect(sawAbort).toBe(true);
|
expect(sawAbort).toBe(true);
|
||||||
|
|
||||||
const onBlockReplyStreamMode = vi.fn().mockResolvedValue(undefined);
|
const onBlockReplyStreamMode = vi.fn().mockResolvedValue(undefined);
|
||||||
|
|||||||
Reference in New Issue
Block a user