Files
openclaw/src/agents/pi-embedded-runner.resolvesessionagentids.test.ts

69 lines
2.0 KiB
TypeScript
Raw Normal View History

import { describe, expect, it } from "vitest";
2026-01-30 03:15:10 +01:00
import type { OpenClawConfig } from "../config/config.js";
2026-01-14 01:08:15 +00:00
import { resolveSessionAgentIds } from "./agent-scope.js";
describe("resolveSessionAgentIds", () => {
const cfg = {
agents: {
list: [{ id: "main" }, { id: "beta", default: true }],
},
2026-01-30 03:15:10 +01:00
} as OpenClawConfig;
2026-01-14 01:08:15 +00:00
it("falls back to the configured default when sessionKey is missing", () => {
const { defaultAgentId, sessionAgentId } = resolveSessionAgentIds({
config: cfg,
});
expect(defaultAgentId).toBe("beta");
expect(sessionAgentId).toBe("beta");
});
2026-01-14 01:08:15 +00:00
it("falls back to the configured default when sessionKey is non-agent", () => {
const { sessionAgentId } = resolveSessionAgentIds({
sessionKey: "telegram:slash:123",
config: cfg,
});
expect(sessionAgentId).toBe("beta");
});
2026-01-14 01:08:15 +00:00
it("falls back to the configured default for global sessions", () => {
const { sessionAgentId } = resolveSessionAgentIds({
sessionKey: "global",
config: cfg,
});
expect(sessionAgentId).toBe("beta");
});
2026-01-14 01:08:15 +00:00
it("keeps the agent id for provider-qualified agent sessions", () => {
const { sessionAgentId } = resolveSessionAgentIds({
sessionKey: "agent:beta:slack:channel:c1",
2026-01-14 01:08:15 +00:00
config: cfg,
});
expect(sessionAgentId).toBe("beta");
});
2026-01-14 01:08:15 +00:00
it("uses the agent id from agent session keys", () => {
const { sessionAgentId } = resolveSessionAgentIds({
sessionKey: "agent:main:main",
config: cfg,
});
expect(sessionAgentId).toBe("main");
});
it("uses explicit agentId when sessionKey is missing", () => {
const { sessionAgentId } = resolveSessionAgentIds({
agentId: "main",
config: cfg,
});
expect(sessionAgentId).toBe("main");
});
it("prefers explicit agentId over non-agent session keys", () => {
const { sessionAgentId } = resolveSessionAgentIds({
sessionKey: "telegram:slash:123",
agentId: "main",
config: cfg,
});
expect(sessionAgentId).toBe("main");
});
2026-01-14 01:08:15 +00:00
});