fix(cron): prevent isolated hook session-key double-prefixing (land #27333, @MaheshBhushan)

Co-authored-by: MaheshBhushan <mkoduri73@gmail.com>
This commit is contained in:
Peter Steinberger
2026-02-26 12:28:07 +00:00
parent f692288301
commit 8b5ebff67b
3 changed files with 50 additions and 5 deletions

View File

@@ -0,0 +1,28 @@
import { describe, expect, it } from "vitest";
import { resolveCronAgentSessionKey } from "./run.js";
describe("resolveCronAgentSessionKey", () => {
it("builds an agent-scoped key for legacy aliases", () => {
expect(resolveCronAgentSessionKey({ sessionKey: "main", agentId: "main" })).toBe(
"agent:main:main",
);
});
it("preserves canonical agent keys instead of prefixing twice", () => {
expect(resolveCronAgentSessionKey({ sessionKey: "agent:main:main", agentId: "main" })).toBe(
"agent:main:main",
);
});
it("normalizes canonical keys to lowercase before reuse", () => {
expect(
resolveCronAgentSessionKey({ sessionKey: "AGENT:Main:Hook:Webhook:42", agentId: "x" }),
).toBe("agent:main:hook:webhook:42");
});
it("keeps hook keys scoped under the target agent", () => {
expect(resolveCronAgentSessionKey({ sessionKey: "hook:webhook:42", agentId: "main" })).toBe(
"agent:main:hook:webhook:42",
);
});
});