




















@@ -21,6 +21,16 @@ type SeedSessionInput = {
2121type AgentDefaultsConfig = NonNullable<NonNullable<OpenClawConfig["agents"]>["defaults"]>;
2222type HeartbeatConfig = NonNullable<AgentDefaultsConfig["heartbeat"]>;
232324+function expectReplyOptions(options: unknown, expected: Record<string, unknown>) {
25+expect(typeof options).toBe("object");
26+expect(options).not.toBeNull();
27+const actual = options as Record<string, unknown>;
28+for (const [key, value] of Object.entries(expected)) {
29+expect(actual[key]).toEqual(value);
30+}
31+return actual;
32+}
33+2434async function withHeartbeatFixture(
2535run: (ctx: {
2636tmpDir: string;
@@ -155,56 +165,49 @@ describe("runHeartbeatOnce – heartbeat model override", () => {
155165 replySpy,
156166});
157167158-expect(result.replySpy).toHaveBeenCalledWith(
159-expect.any(Object),
160-expect.objectContaining({
161-isHeartbeat: true,
162- ...params.expectedOptions,
163-}),
164-cfg,
165-);
168+expect(result.replySpy).toHaveBeenCalledTimes(1);
169+const [ctx, opts, passedConfig] = result.replySpy.mock.calls[0] ?? [];
170+expect(typeof ctx).toBe("object");
171+expect(ctx).not.toBeNull();
172+expectReplyOptions(opts, {
173+isHeartbeat: true,
174+ ...params.expectedOptions,
175+});
176+expect(passedConfig).toBe(cfg);
166177});
167178}
168179169180it("passes heartbeatModelOverride from defaults heartbeat config", async () => {
170181const replyOpts = await runDefaultsHeartbeat({ model: "ollama/llama3.2:1b" });
171-expect(replyOpts).toEqual(
172-expect.objectContaining({
173-isHeartbeat: true,
174-heartbeatModelOverride: "ollama/llama3.2:1b",
175-suppressToolErrorWarnings: false,
176-}),
177-);
182+expectReplyOptions(replyOpts, {
183+isHeartbeat: true,
184+heartbeatModelOverride: "ollama/llama3.2:1b",
185+suppressToolErrorWarnings: false,
186+});
178187});
179188180189it("passes suppressToolErrorWarnings when configured", async () => {
181190const replyOpts = await runDefaultsHeartbeat({ suppressToolErrorWarnings: true });
182-expect(replyOpts).toEqual(
183-expect.objectContaining({
184-isHeartbeat: true,
185-suppressToolErrorWarnings: true,
186-}),
187-);
191+expectReplyOptions(replyOpts, {
192+isHeartbeat: true,
193+suppressToolErrorWarnings: true,
194+});
188195});
189196190197it("passes heartbeat timeoutSeconds as a reply-run timeout override", async () => {
191198const replyOpts = await runDefaultsHeartbeat({ timeoutSeconds: 45 });
192-expect(replyOpts).toEqual(
193-expect.objectContaining({
194-isHeartbeat: true,
195-timeoutOverrideSeconds: 45,
196-}),
197-);
199+expectReplyOptions(replyOpts, {
200+isHeartbeat: true,
201+timeoutOverrideSeconds: 45,
202+});
198203});
199204200205it("passes bootstrapContextMode when heartbeat lightContext is enabled", async () => {
201206const replyOpts = await runDefaultsHeartbeat({ lightContext: true });
202-expect(replyOpts).toEqual(
203-expect.objectContaining({
204-isHeartbeat: true,
205-bootstrapContextMode: "lightweight",
206-}),
207-);
207+expectReplyOptions(replyOpts, {
208+isHeartbeat: true,
209+bootstrapContextMode: "lightweight",
210+});
208211});
209212210213it("uses isolated session key when isolatedSession is enabled", async () => {
@@ -295,20 +298,15 @@ describe("runHeartbeatOnce – heartbeat model override", () => {
295298296299it("does not pass heartbeatModelOverride when no heartbeat model is configured", async () => {
297300const replyOpts = await runDefaultsHeartbeat({ model: undefined });
298-expect(replyOpts).toEqual(
299-expect.objectContaining({
300-isHeartbeat: true,
301-}),
302-);
301+const actual = expectReplyOptions(replyOpts, { isHeartbeat: true });
302+expect(actual.heartbeatModelOverride).toBeUndefined();
303303});
304304305305it("trims heartbeat model override before passing it downstream", async () => {
306306const replyOpts = await runDefaultsHeartbeat({ model: " ollama/llama3.2:1b " });
307-expect(replyOpts).toEqual(
308-expect.objectContaining({
309-isHeartbeat: true,
310-heartbeatModelOverride: "ollama/llama3.2:1b",
311-}),
312-);
307+expectReplyOptions(replyOpts, {
308+isHeartbeat: true,
309+heartbeatModelOverride: "ollama/llama3.2:1b",
310+});
313311});
314312});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。