Repository navigation
Expand file tree
/
Copy pathprofile-set.test.ts
More file actions
114 lines (102 loc) · 3.42 KB
/
Copy pathprofile-set.test.ts
File metadata and controls
114 lines (102 loc) · 3.42 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
import { describe, it, expect, beforeEach, afterEach } from "vitest";
import { mkdtempSync, rmSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import type { ToolContext } from "../tool-registry.js";
import { ProfileStore } from "../../memory/profile-store.js";
import { buildProfileSetTool } from "./profile-set.js";
function makeCtx(): ToolContext {
return {
workingDir: "/work",
sessionId: "s1",
stepIndex: 0,
signal: new AbortController().signal,
};
}
describe("memory.profile.set", () => {
let tmp: string;
let store: ProfileStore;
beforeEach(() => {
tmp = mkdtempSync(join(tmpdir(), "atomic-agent-tool-profile-"));
store = new ProfileStore({ dbFile: join(tmp, "memory.sqlite") });
});
afterEach(() => {
store.close();
rmSync(tmp, { recursive: true, force: true });
});
it("upserts a fact and persists it in the store", async () => {
const tool = buildProfileSetTool({ store });
const result = await tool.run(
{ key: "language", value: "ru" },
makeCtx(),
);
expect(result.status).toBe("ok");
expect(result.details.key).toBe("language");
expect(result.details.value).toBe("ru");
expect(result.details.updated).toBe(true);
expect(store.get("language")?.value).toBe("ru");
});
it("returns an error tool-result for invalid keys", async () => {
const tool = buildProfileSetTool({ store });
const result = await tool.run(
{ key: "has space", value: "x" },
makeCtx(),
);
expect(result.status).toBe("error");
expect(result.details.field).toBe("key");
});
it("returns an error tool-result for empty values", async () => {
const tool = buildProfileSetTool({ store });
const result = await tool.run(
{ key: "ok", value: "" },
makeCtx(),
);
expect(result.status).toBe("error");
expect(result.details.field).toBe("value");
});
it("defaults pinned=true when the flag is omitted", async () => {
const tool = buildProfileSetTool({ store });
const result = await tool.run(
{ key: "language", value: "ru" },
makeCtx(),
);
expect(result.status).toBe("ok");
expect(result.details.pinned).toBe(true);
expect(result.details.keywords).toEqual([]);
expect(store.get("language")?.pinned).toBe(true);
});
it("persists pinned=false contextual facts with keywords", async () => {
const tool = buildProfileSetTool({ store });
const result = await tool.run(
{
key: "deploy_cmd",
value: "pnpm run deploy",
pinned: false,
keywords: ["deploy", "release"],
},
makeCtx(),
);
expect(result.status).toBe("ok");
expect(result.details.pinned).toBe(false);
expect(result.details.keywords).toEqual(["deploy", "release"]);
const saved = store.get("deploy_cmd");
expect(saved?.pinned).toBe(false);
expect(saved?.keywords).toEqual(["deploy", "release"]);
});
it("rejects non-boolean pinned", async () => {
const tool = buildProfileSetTool({ store });
const result = await tool.run(
{ key: "x", value: "y", pinned: "true" },
makeCtx(),
);
expect(result.status).toBe("error");
});
it("rejects non-array keywords", async () => {
const tool = buildProfileSetTool({ store });
const result = await tool.run(
{ key: "x", value: "y", pinned: false, keywords: "deploy" },
makeCtx(),
);
expect(result.status).toBe("error");
});
});