File size: 1,703 Bytes
e249c6d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import { describe, expect, it } from "vitest";
import type { OpenClawConfig } from "../../config/types.openclaw.js";
import { AgentSelectionRequiredError } from "../agent-scope.js";
import { resolveExplicitAgentCommandSessionKey } from "./explicit-session-key.js";

const fixedStoreConfig = {
  session: { store: "/stores/shared.sqlite" },
  agents: {
    ownership: "explicit",
    defaults: { sessionStore: { agentId: "ops" } },
    entries: { ops: {}, research: {} },
  },
} satisfies OpenClawConfig;

describe("explicit agent command session keys", () => {
  it("scopes a bare key through its persisted fixed-store owner", () => {
    expect(
      resolveExplicitAgentCommandSessionKey({
        rawExplicitSessionKey: "incident-42",
        shouldScopeDefaultAgentKey: true,
        cfg: fixedStoreConfig,
      }),
    ).toBe("agent:ops:incident-42");
  });

  it("rejects an explicit agent that conflicts with the persisted owner", () => {
    expect(() =>
      resolveExplicitAgentCommandSessionKey({
        rawExplicitSessionKey: "incident-42",
        agentIdOverride: "research",
        shouldScopeDefaultAgentKey: true,
        cfg: fixedStoreConfig,
      }),
    ).toThrow(AgentSelectionRequiredError);
  });

  it("fails closed when the persisted owner has retired", () => {
    expect(() =>
      resolveExplicitAgentCommandSessionKey({
        rawExplicitSessionKey: "incident-42",
        shouldScopeDefaultAgentKey: true,
        cfg: {
          ...fixedStoreConfig,
          agents: {
            ...fixedStoreConfig.agents,
            defaults: { sessionStore: { agentId: "retired" } },
          },
        },
      }),
    ).toThrow(AgentSelectionRequiredError);
  });
});