@axiom-lattice/local-stores 5.0.0 → 5.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +10 -10
- package/CHANGELOG.md +180 -0
- package/dist/index.d.mts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +46 -21
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +66 -41
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
- package/src/__tests__/LocalAssistantStore.test.ts +235 -0
- package/src/__tests__/LocalDatabaseConfigStore.test.ts +194 -0
- package/src/__tests__/LocalEvalStore.crud.test.ts +355 -0
- package/src/__tests__/LocalMetricsServerConfigStore.test.ts +276 -0
- package/src/__tests__/LocalModelProviderStore.test.ts +203 -0
- package/src/__tests__/LocalScheduleStorage.crud.test.ts +304 -0
- package/src/__tests__/LocalSkillStore.test.ts +284 -0
- package/src/__tests__/LocalWorkflowTrackingStore.test.ts +510 -0
- package/src/stores/LocalMetricsServerConfigStore.ts +35 -3
- package/src/stores/LocalScheduleStorage.ts +6 -1
- package/src/stores/LocalWorkflowTrackingStore.ts +13 -3
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LocalSkillStore behavior tests, mirroring the PostgreSQL skill integration
|
|
3
|
+
* suite: CRUD, metadata search, compatibility/license filters, sub-skill
|
|
4
|
+
* membership, and tenant isolation.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { afterEach, beforeEach, describe, expect, it } from "@jest/globals";
|
|
8
|
+
import { tmpdir } from "os";
|
|
9
|
+
import path from "path";
|
|
10
|
+
import { randomUUID } from "crypto";
|
|
11
|
+
|
|
12
|
+
import { closeDatabase, initDatabase, type DatabaseWrapper } from "../database";
|
|
13
|
+
import { LocalSkillStore } from "../stores/LocalSkillStore";
|
|
14
|
+
|
|
15
|
+
const nextDbPath = () =>
|
|
16
|
+
path.join(tmpdir(), `lt-skill-test-${Date.now()}-${Math.random().toString(36).slice(2)}.db`);
|
|
17
|
+
|
|
18
|
+
describe("LocalSkillStore", () => {
|
|
19
|
+
let db: DatabaseWrapper;
|
|
20
|
+
let store: LocalSkillStore;
|
|
21
|
+
|
|
22
|
+
beforeEach(async () => {
|
|
23
|
+
db = await initDatabase({ dbPath: nextDbPath() });
|
|
24
|
+
store = new LocalSkillStore(db);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
afterEach(() => {
|
|
28
|
+
closeDatabase();
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
function tenantId(): string {
|
|
32
|
+
return `skill-${randomUUID()}`;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
async function seedSkill(
|
|
36
|
+
tenant: string,
|
|
37
|
+
data: Partial<Parameters<LocalSkillStore["createSkill"]>[2]> = {},
|
|
38
|
+
): Promise<{ id: string; tenantId: string }> {
|
|
39
|
+
const id = randomUUID();
|
|
40
|
+
await store.createSkill(tenant, id, {
|
|
41
|
+
name: `skill-${id}`,
|
|
42
|
+
description: "A test skill",
|
|
43
|
+
...data,
|
|
44
|
+
});
|
|
45
|
+
return { id, tenantId: tenant };
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
it("round-trips a created skill through get by id", async () => {
|
|
49
|
+
const tenant = tenantId();
|
|
50
|
+
const id = randomUUID();
|
|
51
|
+
|
|
52
|
+
const createdSkill = await store.createSkill(tenant, id, {
|
|
53
|
+
name: "pdf-reader",
|
|
54
|
+
description: "Reads PDFs",
|
|
55
|
+
license: "MIT",
|
|
56
|
+
compatibility: ">=1.0.0",
|
|
57
|
+
metadata: { category: "documents", level: "1" },
|
|
58
|
+
content: "# Body",
|
|
59
|
+
subSkills: ["pdf", "ocr"],
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
expect(createdSkill.tenantId).toBe(tenant);
|
|
63
|
+
expect(createdSkill.name).toBe("pdf-reader");
|
|
64
|
+
|
|
65
|
+
const read = await store.getSkillById(tenant, id);
|
|
66
|
+
expect(read).not.toBeNull();
|
|
67
|
+
expect(read).toMatchObject({
|
|
68
|
+
id,
|
|
69
|
+
tenantId: tenant,
|
|
70
|
+
name: "pdf-reader",
|
|
71
|
+
description: "Reads PDFs",
|
|
72
|
+
license: "MIT",
|
|
73
|
+
compatibility: ">=1.0.0",
|
|
74
|
+
metadata: { category: "documents", level: "1" },
|
|
75
|
+
content: "# Body",
|
|
76
|
+
subSkills: ["pdf", "ocr"],
|
|
77
|
+
});
|
|
78
|
+
expect(read!.createdAt).toBeInstanceOf(Date);
|
|
79
|
+
expect(read!.updatedAt).toBeInstanceOf(Date);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it("maps absent optional fields to undefined and empty metadata", async () => {
|
|
83
|
+
const tenant = tenantId();
|
|
84
|
+
const { id } = await seedSkill(tenant, { name: "minimal", description: "bare" });
|
|
85
|
+
|
|
86
|
+
const read = await store.getSkillById(tenant, id);
|
|
87
|
+
expect(read!.license).toBeUndefined();
|
|
88
|
+
expect(read!.compatibility).toBeUndefined();
|
|
89
|
+
expect(read!.content).toBeUndefined();
|
|
90
|
+
expect(read!.metadata).toEqual({});
|
|
91
|
+
expect(read!.subSkills).toEqual([]);
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
it("returns null and false for an absent skill id", async () => {
|
|
95
|
+
const tenant = tenantId();
|
|
96
|
+
const missing = randomUUID();
|
|
97
|
+
|
|
98
|
+
expect(await store.getSkillById(tenant, missing)).toBeNull();
|
|
99
|
+
expect(await store.hasSkill(tenant, missing)).toBe(false);
|
|
100
|
+
expect(await store.updateSkill(tenant, missing, { name: "nope" })).toBeNull();
|
|
101
|
+
expect(await store.deleteSkill(tenant, missing)).toBe(false);
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
it("lists only the requested tenant's skills", async () => {
|
|
105
|
+
const tenantA = tenantId();
|
|
106
|
+
const tenantB = tenantId();
|
|
107
|
+
const a1 = await seedSkill(tenantA);
|
|
108
|
+
const a2 = await seedSkill(tenantA);
|
|
109
|
+
const b1 = await seedSkill(tenantB);
|
|
110
|
+
|
|
111
|
+
const listedA = await store.getAllSkills(tenantA);
|
|
112
|
+
const idsA = listedA.map((skill) => skill.id).sort();
|
|
113
|
+
expect(idsA).toEqual([a1.id, a2.id].sort());
|
|
114
|
+
expect(listedA.every((skill) => skill.tenantId === tenantA)).toBe(true);
|
|
115
|
+
|
|
116
|
+
const listedB = await store.getAllSkills(tenantB);
|
|
117
|
+
expect(listedB.map((skill) => skill.id)).toEqual([b1.id]);
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
it("updates only the provided fields and preserves the rest", async () => {
|
|
121
|
+
const tenant = tenantId();
|
|
122
|
+
const { id } = await seedSkill(tenant, {
|
|
123
|
+
name: "before",
|
|
124
|
+
description: "keep me",
|
|
125
|
+
license: "MIT",
|
|
126
|
+
compatibility: ">=1.0.0",
|
|
127
|
+
content: "# Old",
|
|
128
|
+
subSkills: ["a", "b"],
|
|
129
|
+
metadata: { a: "1" },
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
const updated = await store.updateSkill(tenant, id, {
|
|
133
|
+
name: "after",
|
|
134
|
+
metadata: { a: "2" },
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
expect(updated).not.toBeNull();
|
|
138
|
+
expect(updated!.name).toBe("after");
|
|
139
|
+
expect(updated!.metadata).toEqual({ a: "2" });
|
|
140
|
+
expect(updated!.description).toBe("keep me");
|
|
141
|
+
expect(updated!.license).toBe("MIT");
|
|
142
|
+
expect(updated!.compatibility).toBe(">=1.0.0");
|
|
143
|
+
expect(updated!.content).toBe("# Old");
|
|
144
|
+
expect(updated!.subSkills).toEqual(["a", "b"]);
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
it("clears optional fields and empty collections on update", async () => {
|
|
148
|
+
const tenant = tenantId();
|
|
149
|
+
const { id } = await seedSkill(tenant, {
|
|
150
|
+
license: "MIT",
|
|
151
|
+
compatibility: ">=1.0.0",
|
|
152
|
+
content: "# Body",
|
|
153
|
+
subSkills: ["a"],
|
|
154
|
+
metadata: { a: "1" },
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
const updated = await store.updateSkill(tenant, id, {
|
|
158
|
+
license: "",
|
|
159
|
+
compatibility: "",
|
|
160
|
+
content: "",
|
|
161
|
+
subSkills: [],
|
|
162
|
+
metadata: {},
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
expect(updated!.license).toBeUndefined();
|
|
166
|
+
expect(updated!.compatibility).toBeUndefined();
|
|
167
|
+
expect(updated!.content).toBeUndefined();
|
|
168
|
+
expect(updated!.subSkills).toEqual([]);
|
|
169
|
+
expect(updated!.metadata).toEqual({});
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
it("reports has and deletes a skill", async () => {
|
|
173
|
+
const tenant = tenantId();
|
|
174
|
+
const { id } = await seedSkill(tenant);
|
|
175
|
+
|
|
176
|
+
expect(await store.hasSkill(tenant, id)).toBe(true);
|
|
177
|
+
expect(await store.deleteSkill(tenant, id)).toBe(true);
|
|
178
|
+
expect(await store.hasSkill(tenant, id)).toBe(false);
|
|
179
|
+
expect(await store.getSkillById(tenant, id)).toBeNull();
|
|
180
|
+
expect(await store.deleteSkill(tenant, id)).toBe(false);
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
it("searches by metadata within a tenant", async () => {
|
|
184
|
+
const tenant = tenantId();
|
|
185
|
+
const otherTenant = tenantId();
|
|
186
|
+
const match = await seedSkill(tenant, { metadata: { category: "finance" } });
|
|
187
|
+
await seedSkill(tenant, { metadata: { category: "other" } });
|
|
188
|
+
await seedSkill(otherTenant, { metadata: { category: "finance" } });
|
|
189
|
+
|
|
190
|
+
const results = await store.searchByMetadata(tenant, "category", "finance");
|
|
191
|
+
expect(results.map((skill) => skill.id)).toEqual([match.id]);
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
it("returns no metadata matches for an unknown key or value", async () => {
|
|
195
|
+
const tenant = tenantId();
|
|
196
|
+
await seedSkill(tenant, { metadata: { category: "finance" } });
|
|
197
|
+
|
|
198
|
+
expect(await store.searchByMetadata(tenant, "missing", "finance")).toEqual([]);
|
|
199
|
+
expect(await store.searchByMetadata(tenant, "category", "missing")).toEqual([]);
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
it("filters by compatibility within a tenant", async () => {
|
|
203
|
+
const tenant = tenantId();
|
|
204
|
+
const otherTenant = tenantId();
|
|
205
|
+
const match = await seedSkill(tenant, { compatibility: ">=2.0.0" });
|
|
206
|
+
await seedSkill(tenant, { compatibility: ">=3.0.0" });
|
|
207
|
+
await seedSkill(otherTenant, { compatibility: ">=2.0.0" });
|
|
208
|
+
|
|
209
|
+
const results = await store.filterByCompatibility(tenant, ">=2.0.0");
|
|
210
|
+
expect(results.map((skill) => skill.id)).toEqual([match.id]);
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
it("filters by license within a tenant", async () => {
|
|
214
|
+
const tenant = tenantId();
|
|
215
|
+
const otherTenant = tenantId();
|
|
216
|
+
const match = await seedSkill(tenant, { license: "Apache-2.0" });
|
|
217
|
+
await seedSkill(tenant, { license: "MIT" });
|
|
218
|
+
await seedSkill(otherTenant, { license: "Apache-2.0" });
|
|
219
|
+
|
|
220
|
+
const results = await store.filterByLicense(tenant, "Apache-2.0");
|
|
221
|
+
expect(results.map((skill) => skill.id)).toEqual([match.id]);
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
it("finds skills that list the parent in subSkills within a tenant", async () => {
|
|
225
|
+
const tenant = tenantId();
|
|
226
|
+
const otherTenant = tenantId();
|
|
227
|
+
const parent = "parent-skill";
|
|
228
|
+
|
|
229
|
+
await seedSkill(tenant, { name: parent });
|
|
230
|
+
const child = await seedSkill(tenant, {
|
|
231
|
+
name: "child-skill",
|
|
232
|
+
subSkills: [parent],
|
|
233
|
+
});
|
|
234
|
+
// Membership, not exact-array equality: the parent is one element among others.
|
|
235
|
+
const membershipChild = await seedSkill(tenant, {
|
|
236
|
+
name: "membership-child",
|
|
237
|
+
subSkills: ["other", parent],
|
|
238
|
+
});
|
|
239
|
+
const otherChild = await seedSkill(otherTenant, {
|
|
240
|
+
name: "other-child",
|
|
241
|
+
subSkills: [parent],
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
const results = await store.getSubSkills(tenant, parent);
|
|
245
|
+
|
|
246
|
+
expect(results.map((skill) => skill.id).sort()).toEqual(
|
|
247
|
+
[child.id, membershipChild.id].sort(),
|
|
248
|
+
);
|
|
249
|
+
expect(results.map((skill) => skill.id)).not.toContain(otherChild.id);
|
|
250
|
+
expect(results.every((skill) => skill.tenantId === tenant)).toBe(true);
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
it("returns empty results for sub-skills of an unknown parent", async () => {
|
|
254
|
+
const tenant = tenantId();
|
|
255
|
+
await seedSkill(tenant, { name: "unrelated", subSkills: ["some-other"] });
|
|
256
|
+
|
|
257
|
+
expect(await store.getSubSkills(tenant, "missing")).toEqual([]);
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
it("keeps the same skill id independent across tenants", async () => {
|
|
261
|
+
const tenantA = tenantId();
|
|
262
|
+
const tenantB = tenantId();
|
|
263
|
+
const id = randomUUID();
|
|
264
|
+
await store.createSkill(tenantA, id, { name: "A", description: "A", metadata: { tenant: "a" } });
|
|
265
|
+
await store.createSkill(tenantB, id, { name: "B", description: "B", metadata: { tenant: "b" } });
|
|
266
|
+
|
|
267
|
+
expect((await store.getSkillById(tenantA, id))?.name).toBe("A");
|
|
268
|
+
expect((await store.getSkillById(tenantB, id))?.name).toBe("B");
|
|
269
|
+
|
|
270
|
+
expect(await store.deleteSkill(tenantA, id)).toBe(true);
|
|
271
|
+
expect(await store.hasSkill(tenantA, id)).toBe(false);
|
|
272
|
+
expect(await store.hasSkill(tenantB, id)).toBe(true);
|
|
273
|
+
});
|
|
274
|
+
|
|
275
|
+
it("declares the optional resource methods and returns no resources", async () => {
|
|
276
|
+
const tenant = tenantId();
|
|
277
|
+
const { id } = await seedSkill(tenant);
|
|
278
|
+
|
|
279
|
+
expect(store.listSkillResources).toBeDefined();
|
|
280
|
+
expect(store.loadSkillResource).toBeDefined();
|
|
281
|
+
await expect(store.listSkillResources!(tenant, id)).resolves.toEqual([]);
|
|
282
|
+
await expect(store.loadSkillResource!(tenant, id, "missing.txt")).resolves.toBeNull();
|
|
283
|
+
});
|
|
284
|
+
});
|