mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-19 08:07:27 +00:00
test: dedupe session idle timeout assertions
This commit is contained in:
@@ -139,6 +139,21 @@ function createTelegramBinding(overrides?: Partial<SessionBindingRecord>): Sessi
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function expectIdleTimeoutSetReply(
|
||||||
|
mock: ReturnType<typeof vi.fn>,
|
||||||
|
text: string,
|
||||||
|
idleTimeoutMs: number,
|
||||||
|
idleTimeoutLabel: string,
|
||||||
|
) {
|
||||||
|
expect(mock).toHaveBeenCalledWith({
|
||||||
|
targetSessionKey: "agent:main:subagent:child",
|
||||||
|
accountId: "default",
|
||||||
|
idleTimeoutMs,
|
||||||
|
});
|
||||||
|
expect(text).toContain(`Idle timeout set to ${idleTimeoutLabel}`);
|
||||||
|
expect(text).toContain("2026-02-20T02:00:00.000Z");
|
||||||
|
}
|
||||||
|
|
||||||
function createFakeThreadBindingManager(binding: FakeBinding | null) {
|
function createFakeThreadBindingManager(binding: FakeBinding | null) {
|
||||||
return {
|
return {
|
||||||
getByThreadId: vi.fn((_threadId: string) => binding),
|
getByThreadId: vi.fn((_threadId: string) => binding),
|
||||||
@@ -175,13 +190,12 @@ describe("/session idle and /session max-age", () => {
|
|||||||
const result = await handleSessionCommand(createDiscordCommandParams("/session idle 2h"), true);
|
const result = await handleSessionCommand(createDiscordCommandParams("/session idle 2h"), true);
|
||||||
const text = result?.reply?.text ?? "";
|
const text = result?.reply?.text ?? "";
|
||||||
|
|
||||||
expect(hoisted.setThreadBindingIdleTimeoutBySessionKeyMock).toHaveBeenCalledWith({
|
expectIdleTimeoutSetReply(
|
||||||
targetSessionKey: "agent:main:subagent:child",
|
hoisted.setThreadBindingIdleTimeoutBySessionKeyMock,
|
||||||
accountId: "default",
|
text,
|
||||||
idleTimeoutMs: 2 * 60 * 60 * 1000,
|
2 * 60 * 60 * 1000,
|
||||||
});
|
"2h",
|
||||||
expect(text).toContain("Idle timeout set to 2h");
|
);
|
||||||
expect(text).toContain("2026-02-20T02:00:00.000Z");
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("shows active idle timeout when no value is provided", async () => {
|
it("shows active idle timeout when no value is provided", async () => {
|
||||||
@@ -248,13 +262,12 @@ describe("/session idle and /session max-age", () => {
|
|||||||
);
|
);
|
||||||
const text = result?.reply?.text ?? "";
|
const text = result?.reply?.text ?? "";
|
||||||
|
|
||||||
expect(hoisted.setTelegramThreadBindingIdleTimeoutBySessionKeyMock).toHaveBeenCalledWith({
|
expectIdleTimeoutSetReply(
|
||||||
targetSessionKey: "agent:main:subagent:child",
|
hoisted.setTelegramThreadBindingIdleTimeoutBySessionKeyMock,
|
||||||
accountId: "default",
|
text,
|
||||||
idleTimeoutMs: 2 * 60 * 60 * 1000,
|
2 * 60 * 60 * 1000,
|
||||||
});
|
"2h",
|
||||||
expect(text).toContain("Idle timeout set to 2h");
|
);
|
||||||
expect(text).toContain("2026-02-20T02:00:00.000Z");
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("reports Telegram max-age expiry from the original bind time", async () => {
|
it("reports Telegram max-age expiry from the original bind time", async () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user