mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-25 11:55:47 -06:00
test: tighten heartbeat model assertions
This commit is contained in:
@@ -21,6 +21,16 @@ type SeedSessionInput = {
|
||||
type AgentDefaultsConfig = NonNullable<NonNullable<OpenClawConfig["agents"]>["defaults"]>;
|
||||
type HeartbeatConfig = NonNullable<AgentDefaultsConfig["heartbeat"]>;
|
||||
|
||||
function expectReplyOptions(options: unknown, expected: Record<string, unknown>) {
|
||||
expect(typeof options).toBe("object");
|
||||
expect(options).not.toBeNull();
|
||||
const actual = options as Record<string, unknown>;
|
||||
for (const [key, value] of Object.entries(expected)) {
|
||||
expect(actual[key]).toEqual(value);
|
||||
}
|
||||
return actual;
|
||||
}
|
||||
|
||||
async function withHeartbeatFixture(
|
||||
run: (ctx: {
|
||||
tmpDir: string;
|
||||
@@ -155,56 +165,49 @@ describe("runHeartbeatOnce – heartbeat model override", () => {
|
||||
replySpy,
|
||||
});
|
||||
|
||||
expect(result.replySpy).toHaveBeenCalledWith(
|
||||
expect.any(Object),
|
||||
expect.objectContaining({
|
||||
isHeartbeat: true,
|
||||
...params.expectedOptions,
|
||||
}),
|
||||
cfg,
|
||||
);
|
||||
expect(result.replySpy).toHaveBeenCalledTimes(1);
|
||||
const [ctx, opts, passedConfig] = result.replySpy.mock.calls[0] ?? [];
|
||||
expect(typeof ctx).toBe("object");
|
||||
expect(ctx).not.toBeNull();
|
||||
expectReplyOptions(opts, {
|
||||
isHeartbeat: true,
|
||||
...params.expectedOptions,
|
||||
});
|
||||
expect(passedConfig).toBe(cfg);
|
||||
});
|
||||
}
|
||||
|
||||
it("passes heartbeatModelOverride from defaults heartbeat config", async () => {
|
||||
const replyOpts = await runDefaultsHeartbeat({ model: "ollama/llama3.2:1b" });
|
||||
expect(replyOpts).toEqual(
|
||||
expect.objectContaining({
|
||||
isHeartbeat: true,
|
||||
heartbeatModelOverride: "ollama/llama3.2:1b",
|
||||
suppressToolErrorWarnings: false,
|
||||
}),
|
||||
);
|
||||
expectReplyOptions(replyOpts, {
|
||||
isHeartbeat: true,
|
||||
heartbeatModelOverride: "ollama/llama3.2:1b",
|
||||
suppressToolErrorWarnings: false,
|
||||
});
|
||||
});
|
||||
|
||||
it("passes suppressToolErrorWarnings when configured", async () => {
|
||||
const replyOpts = await runDefaultsHeartbeat({ suppressToolErrorWarnings: true });
|
||||
expect(replyOpts).toEqual(
|
||||
expect.objectContaining({
|
||||
isHeartbeat: true,
|
||||
suppressToolErrorWarnings: true,
|
||||
}),
|
||||
);
|
||||
expectReplyOptions(replyOpts, {
|
||||
isHeartbeat: true,
|
||||
suppressToolErrorWarnings: true,
|
||||
});
|
||||
});
|
||||
|
||||
it("passes heartbeat timeoutSeconds as a reply-run timeout override", async () => {
|
||||
const replyOpts = await runDefaultsHeartbeat({ timeoutSeconds: 45 });
|
||||
expect(replyOpts).toEqual(
|
||||
expect.objectContaining({
|
||||
isHeartbeat: true,
|
||||
timeoutOverrideSeconds: 45,
|
||||
}),
|
||||
);
|
||||
expectReplyOptions(replyOpts, {
|
||||
isHeartbeat: true,
|
||||
timeoutOverrideSeconds: 45,
|
||||
});
|
||||
});
|
||||
|
||||
it("passes bootstrapContextMode when heartbeat lightContext is enabled", async () => {
|
||||
const replyOpts = await runDefaultsHeartbeat({ lightContext: true });
|
||||
expect(replyOpts).toEqual(
|
||||
expect.objectContaining({
|
||||
isHeartbeat: true,
|
||||
bootstrapContextMode: "lightweight",
|
||||
}),
|
||||
);
|
||||
expectReplyOptions(replyOpts, {
|
||||
isHeartbeat: true,
|
||||
bootstrapContextMode: "lightweight",
|
||||
});
|
||||
});
|
||||
|
||||
it("uses isolated session key when isolatedSession is enabled", async () => {
|
||||
@@ -295,20 +298,15 @@ describe("runHeartbeatOnce – heartbeat model override", () => {
|
||||
|
||||
it("does not pass heartbeatModelOverride when no heartbeat model is configured", async () => {
|
||||
const replyOpts = await runDefaultsHeartbeat({ model: undefined });
|
||||
expect(replyOpts).toEqual(
|
||||
expect.objectContaining({
|
||||
isHeartbeat: true,
|
||||
}),
|
||||
);
|
||||
const actual = expectReplyOptions(replyOpts, { isHeartbeat: true });
|
||||
expect(actual.heartbeatModelOverride).toBeUndefined();
|
||||
});
|
||||
|
||||
it("trims heartbeat model override before passing it downstream", async () => {
|
||||
const replyOpts = await runDefaultsHeartbeat({ model: " ollama/llama3.2:1b " });
|
||||
expect(replyOpts).toEqual(
|
||||
expect.objectContaining({
|
||||
isHeartbeat: true,
|
||||
heartbeatModelOverride: "ollama/llama3.2:1b",
|
||||
}),
|
||||
);
|
||||
expectReplyOptions(replyOpts, {
|
||||
isHeartbeat: true,
|
||||
heartbeatModelOverride: "ollama/llama3.2:1b",
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user