mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-14 02:31:24 +00:00
fix: prefer target entry for compact counters
This commit is contained in:
@@ -31,7 +31,7 @@ vi.mock("./commands-compact.runtime.js", () => ({
|
||||
waitForEmbeddedPiRunEnd: vi.fn().mockResolvedValue(undefined),
|
||||
}));
|
||||
|
||||
const { compactEmbeddedPiSession, resolveSessionFilePathOptions } =
|
||||
const { compactEmbeddedPiSession, incrementCompactionCount, resolveSessionFilePathOptions } =
|
||||
await import("./commands-compact.runtime.js");
|
||||
|
||||
function buildCompactParams(
|
||||
@@ -279,4 +279,44 @@ describe("handleCompactCommand", () => {
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it("prefers the target session entry when incrementing compaction count", async () => {
|
||||
vi.mocked(compactEmbeddedPiSession).mockResolvedValueOnce({
|
||||
ok: true,
|
||||
compacted: true,
|
||||
result: {
|
||||
tokensAfter: 321,
|
||||
},
|
||||
});
|
||||
|
||||
await handleCompactCommand(
|
||||
{
|
||||
...buildCompactParams("/compact", {
|
||||
commands: { text: true },
|
||||
channels: { whatsapp: { allowFrom: ["*"] } },
|
||||
} as OpenClawConfig),
|
||||
sessionKey: "agent:target:whatsapp:direct:12345",
|
||||
sessionEntry: {
|
||||
sessionId: "wrapper-session",
|
||||
updatedAt: Date.now(),
|
||||
},
|
||||
sessionStore: {
|
||||
"agent:target:whatsapp:direct:12345": {
|
||||
sessionId: "target-session",
|
||||
updatedAt: Date.now(),
|
||||
},
|
||||
},
|
||||
} as HandleCommandsParams,
|
||||
true,
|
||||
);
|
||||
|
||||
expect(vi.mocked(incrementCompactionCount)).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
sessionEntry: expect.objectContaining({
|
||||
sessionId: "target-session",
|
||||
}),
|
||||
tokensAfter: 321,
|
||||
}),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -161,7 +161,7 @@ export const handleCompactCommand: CommandHandler = async (params) => {
|
||||
if (result.ok && result.compacted) {
|
||||
await runtime.incrementCompactionCount({
|
||||
cfg: params.cfg,
|
||||
sessionEntry: params.sessionEntry,
|
||||
sessionEntry: targetSessionEntry,
|
||||
sessionStore: params.sessionStore,
|
||||
sessionKey: params.sessionKey,
|
||||
storePath: params.storePath,
|
||||
|
||||
Reference in New Issue
Block a user