mirror of
https://github.com/openclaw/openclaw.git
synced 2026-07-25 12:01:11 +00:00
refactor(node-host): trim internal exports (#107270)
This commit is contained in:
committed by
GitHub
parent
1d4188138e
commit
4dff4e95b1
@@ -1,9 +1,6 @@
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import type { NodeHostClient } from "./client.js";
|
||||
import {
|
||||
createNodeInvokeProgressWriter,
|
||||
resolveNodeInvokeHeartbeatInterval,
|
||||
} from "./node-invoke-progress.js";
|
||||
import { createNodeInvokeProgressWriter } from "./node-invoke-progress.js";
|
||||
|
||||
const frame = {
|
||||
id: "invoke-1",
|
||||
@@ -35,30 +32,38 @@ describe("node invoke progress writer", () => {
|
||||
}
|
||||
});
|
||||
|
||||
it("emits idle heartbeats at the clamped half-timeout interval", async () => {
|
||||
vi.useFakeTimers();
|
||||
try {
|
||||
const request = vi.fn(async () => ({}));
|
||||
const writer = createNodeInvokeProgressWriter({
|
||||
client: { request } as NodeHostClient,
|
||||
frame,
|
||||
idleTimeoutMs: 2_000,
|
||||
onError: vi.fn(),
|
||||
});
|
||||
writer.startHeartbeats();
|
||||
await vi.advanceTimersByTimeAsync(1_000);
|
||||
expect(request).toHaveBeenCalledWith("node.invoke.progress", {
|
||||
invokeId: "invoke-1",
|
||||
nodeId: "node-1",
|
||||
seq: 0,
|
||||
chunk: "",
|
||||
});
|
||||
writer.stop();
|
||||
await writer.flush();
|
||||
} finally {
|
||||
vi.useRealTimers();
|
||||
}
|
||||
expect(resolveNodeInvokeHeartbeatInterval(100)).toBe(250);
|
||||
expect(resolveNodeInvokeHeartbeatInterval(60_000)).toBe(5_000);
|
||||
});
|
||||
it.each([
|
||||
{ idleTimeoutMs: 100, heartbeatIntervalMs: 250 },
|
||||
{ idleTimeoutMs: 2_000, heartbeatIntervalMs: 1_000 },
|
||||
{ idleTimeoutMs: 60_000, heartbeatIntervalMs: 5_000 },
|
||||
])(
|
||||
"emits idle heartbeats every $heartbeatIntervalMs ms for a $idleTimeoutMs ms timeout",
|
||||
async ({ idleTimeoutMs, heartbeatIntervalMs }) => {
|
||||
vi.useFakeTimers();
|
||||
try {
|
||||
vi.setSystemTime(0);
|
||||
const request = vi.fn(async () => ({}));
|
||||
const writer = createNodeInvokeProgressWriter({
|
||||
client: { request } as NodeHostClient,
|
||||
frame,
|
||||
idleTimeoutMs,
|
||||
onError: vi.fn(),
|
||||
});
|
||||
writer.startHeartbeats();
|
||||
await vi.advanceTimersByTimeAsync(heartbeatIntervalMs - 1);
|
||||
expect(request).not.toHaveBeenCalled();
|
||||
await vi.advanceTimersByTimeAsync(1);
|
||||
expect(request).toHaveBeenCalledWith("node.invoke.progress", {
|
||||
invokeId: "invoke-1",
|
||||
nodeId: "node-1",
|
||||
seq: 0,
|
||||
chunk: "",
|
||||
});
|
||||
writer.stop();
|
||||
await writer.flush();
|
||||
} finally {
|
||||
vi.useRealTimers();
|
||||
}
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user