-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtypes.test.ts
More file actions
141 lines (125 loc) · 5.1 KB
/
types.test.ts
File metadata and controls
141 lines (125 loc) · 5.1 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
import { describe, it, expect } from "vitest";
import { resolveContainerTag, parseConfig } from "./types.js";
import type { SupermemoryConfig } from "./types.js";
function makeConfig(overrides: Partial<SupermemoryConfig> = {}): SupermemoryConfig {
return parseConfig(overrides);
}
describe("resolveContainerTag", () => {
describe("agent scope (default)", () => {
it("returns agentId when provided", () => {
const config = makeConfig({ containerScope: "agent" });
const result = resolveContainerTag({ config, agentId: "main" });
expect(result).toBe("main");
});
it("returns prefixed agentId when containerTag is set", () => {
const config = makeConfig({ containerScope: "agent", containerTag: "myns" });
const result = resolveContainerTag({ config, agentId: "main" });
expect(result).toBe("myns:main");
});
it("falls back to containerTag when agentId not provided", () => {
const config = makeConfig({ containerScope: "agent", containerTag: "myns" });
const result = resolveContainerTag({ config });
expect(result).toBe("myns");
});
it("returns undefined when no agentId and no containerTag", () => {
const config = makeConfig({ containerScope: "agent" });
const result = resolveContainerTag({ config });
expect(result).toBeUndefined();
});
it("never returns the literal string 'agent'", () => {
const config = makeConfig({ containerScope: "agent" });
const result = resolveContainerTag({ config, agentId: "main" });
expect(result).not.toBe("agent");
expect(result).toBe("main");
});
});
describe("session scope", () => {
it("returns sessionKey when provided", () => {
const config = makeConfig({ containerScope: "session" });
const result = resolveContainerTag({
config,
agentId: "main",
sessionKey: "agent:main:telegram:group:123",
});
expect(result).toBe("agent:main:telegram:group:123");
});
it("returns prefixed sessionKey when containerTag is set", () => {
const config = makeConfig({ containerScope: "session", containerTag: "myns" });
const result = resolveContainerTag({
config,
agentId: "main",
sessionKey: "agent:main:telegram:group:123",
});
expect(result).toBe("myns:agent:main:telegram:group:123");
});
it("falls back to agentId when sessionKey not provided", () => {
const config = makeConfig({ containerScope: "session" });
const result = resolveContainerTag({ config, agentId: "main" });
expect(result).toBe("main");
});
it("falls back to containerTag when neither sessionKey nor agentId", () => {
const config = makeConfig({ containerScope: "session", containerTag: "myns" });
const result = resolveContainerTag({ config });
expect(result).toBe("myns");
});
it("never returns the literal string 'session'", () => {
const config = makeConfig({ containerScope: "session" });
const result = resolveContainerTag({
config,
agentId: "main",
sessionKey: "agent:main:telegram:group:123",
});
expect(result).not.toBe("session");
});
});
describe("bug regression: must not return containerScope value as tag", () => {
it("agent scope with agentId returns agentId, not 'agent'", () => {
const config = makeConfig({ containerScope: "agent" });
const result = resolveContainerTag({ config, agentId: "main" });
expect(result).toBe("main");
});
it("session scope with sessionKey returns sessionKey, not 'session'", () => {
const config = makeConfig({ containerScope: "session" });
const result = resolveContainerTag({
config,
sessionKey: "agent:main:telegram:group:123",
});
expect(result).toBe("agent:main:telegram:group:123");
});
it("tools with default agentId resolve correctly", () => {
// Simulates how tools call resolveContainerTag with the default "main" agentId
const config = makeConfig({ containerScope: "agent" });
const result = resolveContainerTag({ config, agentId: "main" });
expect(result).toBe("main");
});
});
});
describe("parseConfig", () => {
it("applies defaults", () => {
const config = parseConfig({});
expect(config.mode).toBe("tandem");
expect(config.containerScope).toBe("agent");
expect(config.autoRecall).toBe(true);
expect(config.threshold).toBe(0.5);
expect(config.baseUrl).toBe("https://api.supermemory.ai");
expect(config.apiKey).toBe("");
});
it("preserves explicit values", () => {
const config = parseConfig({
apiKey: "test-key",
mode: "primary",
containerScope: "session",
containerTag: "myns",
autoRecall: false,
threshold: 0.8,
baseUrl: "https://custom.api.com",
});
expect(config.apiKey).toBe("test-key");
expect(config.mode).toBe("primary");
expect(config.containerScope).toBe("session");
expect(config.containerTag).toBe("myns");
expect(config.autoRecall).toBe(false);
expect(config.threshold).toBe(0.8);
expect(config.baseUrl).toBe("https://custom.api.com");
});
});