import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; import type { HookRunner } from "../../plugins/hooks.js"; import type { HandleCommandsParams } from "./commands-types.js";
it("passes the bound agent id to before_reset hooks for multi-agent session keys", async () => { const ctx = await runBeforeResetContext("agent:navi:main");
expect(ctx).toMatchObject({
agentId: "navi",
sessionKey: "agent:navi:main",
sessionId: "prev-session",
workspaceDir: "/tmp/openclaw-workspace",
});
});
it("falls back to main when the reset hook has no session key", async () => { const ctx = await runBeforeResetContext(undefined);
expect(ctx).toMatchObject({
agentId: "main",
sessionKey: undefined,
sessionId: "prev-session",
workspaceDir: "/tmp/openclaw-workspace",
});
});
it("keeps the main-agent path on the main agent workspace", async () => { const ctx = await runBeforeResetContext("agent:main:main");
expect(ctx).toMatchObject({
agentId: "main",
sessionKey: "agent:main:main",
sessionId: "prev-session",
workspaceDir: "/tmp/openclaw-workspace",
});
});
it("recovers the archived transcript when the original reset transcript path is gone", async () => {
fsMocks.readFile.mockRejectedValueOnce(Object.assign(new Error("ENOENT"), { code: "ENOENT" }));
fsMocks.readdir.mockResolvedValueOnce(["prev-session.jsonl.reset.2026-02-16T22-26-33.000Z"]);
fsMocks.readFile.mockResolvedValueOnce(
`${JSON.stringify({
type: "message",
id: "m1",
message: { role: "user", content: "Recovered from archive" },
})}\n`,
); const command = {
surface: "telegram",
senderId: "vac",
channel: "telegram",
from: "telegram:vac",
to: "telegram:bot",
resetHookTriggered: false,
} as HandleCommandsParams["command"];
await emitResetCommandHooks({
action: "new",
ctx: {} as HandleCommandsParams["ctx"],
cfg: {} as HandleCommandsParams["cfg"],
command,
sessionKey: "agent:main:telegram:group:-1003826723328:topic:8428",
previousSessionEntry: {
sessionId: "prev-session",
sessionFile: "/tmp/prev-session.jsonl",
} as HandleCommandsParams["previousSessionEntry"],
workspaceDir: "/tmp/openclaw-workspace",
});
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.