@terreno/ai 0.10.0 → 0.11.1

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/bunfig.toml CHANGED
@@ -1,3 +1,8 @@
1
1
  [test]
2
2
  preload = ["./src/tests/bunSetup.ts"]
3
3
  root = "./src"
4
+ coveragePathIgnorePatterns = ["**/*.test.ts", "**/tests/**", "../**", "dist/**", "**/node_modules/**"]
5
+ # Enforced by scripts/check-coverage.ts; Bun parses this key but does not
6
+ # fail the run when coverage is below threshold. See
7
+ # https://github.com/oven-sh/bun/issues/7367 and https://github.com/oven-sh/bun/pull/27933.
8
+ coverageThreshold = { line = 95, function = 95 }
@@ -52,17 +52,7 @@ var api_1 = require("@terreno/api");
52
52
  var project_1 = require("../models/project");
53
53
  var addProjectRoutes = function (router, options) {
54
54
  var _a, _b;
55
- router.use("/gpt/projects", (0, api_1.modelRouter)(project_1.Project, __assign(__assign({}, options === null || options === void 0 ? void 0 : options.openApiOptions), { permissions: {
56
- create: [api_1.Permissions.IsAuthenticated],
57
- delete: [api_1.Permissions.IsOwner],
58
- list: [api_1.Permissions.IsAuthenticated],
59
- read: [api_1.Permissions.IsOwner],
60
- update: [api_1.Permissions.IsOwner],
61
- }, preCreate: function (body, req) {
62
- var _a;
63
- return (__assign(__assign({}, body), { userId: (_a = req.user) === null || _a === void 0 ? void 0 : _a._id }));
64
- }, queryFields: ["userId"], queryFilter: function (user) { return ({ userId: user === null || user === void 0 ? void 0 : user.id }); }, sort: "-updated" })));
65
- // Add memory to a project
55
+ // Add memory to a project (registered before modelRouter so it isn't shadowed)
66
56
  router.post("/gpt/projects/:id/memories", [
67
57
  (0, api_1.authenticateMiddleware)(),
68
58
  (0, api_1.createOpenApiBuilder)((_a = options === null || options === void 0 ? void 0 : options.openApiOptions) !== null && _a !== void 0 ? _a : {})
@@ -143,5 +133,15 @@ var addProjectRoutes = function (router, options) {
143
133
  }
144
134
  });
145
135
  }); }));
136
+ router.use("/gpt/projects", (0, api_1.modelRouter)(project_1.Project, __assign(__assign({}, options === null || options === void 0 ? void 0 : options.openApiOptions), { permissions: {
137
+ create: [api_1.Permissions.IsAuthenticated],
138
+ delete: [api_1.Permissions.IsOwner],
139
+ list: [api_1.Permissions.IsAuthenticated],
140
+ read: [api_1.Permissions.IsOwner],
141
+ update: [api_1.Permissions.IsOwner],
142
+ }, preCreate: function (body, req) {
143
+ var _a;
144
+ return (__assign(__assign({}, body), { userId: (_a = req.user) === null || _a === void 0 ? void 0 : _a._id }));
145
+ }, queryFields: ["userId"], queryFilter: function (user) { return ({ userId: user === null || user === void 0 ? void 0 : user.id }); }, sort: "-updated" })));
146
146
  };
147
147
  exports.addProjectRoutes = addProjectRoutes;
package/package.json CHANGED
@@ -10,7 +10,7 @@
10
10
  "@langfuse/otel": "^5.0.1",
11
11
  "@opentelemetry/api": "^1.9.0",
12
12
  "@opentelemetry/sdk-node": "^0.213.0",
13
- "@terreno/api": "0.10.0",
13
+ "@terreno/api": "0.11.1",
14
14
  "ai": "^6.0.97",
15
15
  "multer": "^1.4.5-lts.1"
16
16
  },
@@ -48,7 +48,7 @@
48
48
  "access": "public"
49
49
  },
50
50
  "peerDependencies": {
51
- "@terreno/api": "0.10.0",
51
+ "@terreno/api": "0.11.1",
52
52
  "mongoose": "^8.0.0"
53
53
  },
54
54
  "repository": {
@@ -62,9 +62,10 @@
62
62
  "lint": "biome check ./src",
63
63
  "lint:fix": "biome check --write ./src",
64
64
  "lint:unsafefix": "biome check --fix --unsafe ./src",
65
- "test": "bun test --preload ./src/tests/bunSetup.ts",
66
- "test:ci": "bun test --preload ./src/tests/bunSetup.ts"
65
+ "test": "bun test --preload ./src/tests/bunSetup.ts && for f in ./src/isolated/*.isolated.ts; do bun test --preload ./src/tests/bunSetup.ts \"$f\" || exit 1; done",
66
+ "test:ci": "bun test --preload ./src/tests/bunSetup.ts && for f in ./src/isolated/*.isolated.ts; do bun test --preload ./src/tests/bunSetup.ts \"$f\" || exit 1; done",
67
+ "test:coverage": "bun run ../scripts/check-coverage.ts"
67
68
  },
68
69
  "types": "dist/index.d.ts",
69
- "version": "0.10.0"
70
+ "version": "0.11.1"
70
71
  }
@@ -0,0 +1,150 @@
1
+ import {beforeAll, describe, expect, it, mock} from "bun:test";
2
+ import {createdUpdatedPlugin, setupServer} from "@terreno/api";
3
+ import type {LanguageModel} from "ai";
4
+ import type express from "express";
5
+ import mongoose from "mongoose";
6
+ import passportLocalMongoose from "passport-local-mongoose";
7
+ import supertest from "supertest";
8
+
9
+ import {AiApp} from "./aiApp";
10
+ import type {FileStorageService} from "./service/fileStorage";
11
+ import type {MCPService} from "./service/mcpService";
12
+
13
+ type PasswordedUser = {setPassword: (password: string) => Promise<void>};
14
+
15
+ const userSchema = new mongoose.Schema({
16
+ admin: {default: false, type: Boolean},
17
+ email: {index: true, type: String},
18
+ name: String,
19
+ });
20
+ userSchema.plugin(
21
+ passportLocalMongoose as unknown as (
22
+ schema: mongoose.Schema,
23
+ options: {usernameField: string}
24
+ ) => void,
25
+ {usernameField: "email"}
26
+ );
27
+ userSchema.plugin(createdUpdatedPlugin);
28
+ const UserModel = mongoose.models.User || mongoose.model("User", userSchema);
29
+
30
+ const createMockModel = () => ({
31
+ doGenerate: mock(async () => ({
32
+ content: [{text: "ok", type: "text" as const}],
33
+ finishReason: "stop" as const,
34
+ usage: {inputTokens: 1, outputTokens: 1},
35
+ })),
36
+ doStream: mock(async () => ({
37
+ stream: new ReadableStream({
38
+ start(controller) {
39
+ controller.enqueue({
40
+ finishReason: "stop" as const,
41
+ type: "finish" as const,
42
+ usage: {inputTokens: 1, outputTokens: 1},
43
+ });
44
+ controller.close();
45
+ },
46
+ }),
47
+ })),
48
+ modelId: "mock-model",
49
+ provider: "mock-provider",
50
+ specificationVersion: "v2" as const,
51
+ supportedUrls: {},
52
+ });
53
+
54
+ describe("AiApp", () => {
55
+ beforeAll(async () => {
56
+ await UserModel.deleteMany({});
57
+ const user = await UserModel.create({email: "aiapp@example.com", name: "User"});
58
+ await (user as unknown as PasswordedUser).setPassword("password");
59
+ await user.save();
60
+ });
61
+
62
+ const authAsUser = async (app: express.Application) => {
63
+ const agent = supertest.agent(app);
64
+ const res = await agent
65
+ .post("/auth/login")
66
+ .send({email: "aiapp@example.com", password: "password"})
67
+ .expect(200);
68
+ await agent.set("authorization", `Bearer ${res.body.data.token}`);
69
+ return agent;
70
+ };
71
+
72
+ it("registers gpt and project routes by default", async () => {
73
+ const {AIService} = await import("./service/aiService");
74
+ const aiService = new AIService({model: createMockModel() as unknown as LanguageModel});
75
+ const plugin = new AiApp({aiService});
76
+ const app = setupServer({
77
+ addRoutes: (router) => plugin.register(router as unknown as express.Application),
78
+ skipListen: true,
79
+ userModel: UserModel,
80
+ });
81
+
82
+ const agent = await authAsUser(app);
83
+ const tools = await agent.get("/gpt/tools");
84
+ expect(tools.status).toBe(200);
85
+ const histories = await agent.get("/gpt/histories");
86
+ expect(histories.status).toBe(200);
87
+ const projects = await agent.get("/gpt/projects");
88
+ expect(projects.status).toBe(200);
89
+ });
90
+
91
+ it("registers file routes only when fileStorageService and gcsBucket are provided", async () => {
92
+ const fileStorageService = {
93
+ delete: mock(async () => {}),
94
+ getSignedUrl: mock(async () => "https://gcs/signed"),
95
+ upload: mock(async () => ({
96
+ filename: "file",
97
+ gcsKey: "uploads/file",
98
+ mimeType: "application/octet-stream",
99
+ size: 0,
100
+ url: "https://gcs/file",
101
+ })),
102
+ } as unknown as FileStorageService;
103
+ const plugin = new AiApp({fileStorageService, gcsBucket: "test-bucket"});
104
+ const app = setupServer({
105
+ addRoutes: (router) => plugin.register(router as unknown as express.Application),
106
+ skipListen: true,
107
+ userModel: UserModel,
108
+ });
109
+ // Unauthenticated access to upload route: ensure it exists (returns 401, not 404).
110
+ const upload = await supertest(app).post("/files/upload");
111
+ expect(upload.status).not.toBe(404);
112
+ });
113
+
114
+ it("skips file routes when only fileStorageService is provided", async () => {
115
+ const fileStorageService = {
116
+ upload: mock(async () => ({
117
+ filename: "x",
118
+ gcsKey: "uploads/x",
119
+ mimeType: "application/octet-stream",
120
+ size: 0,
121
+ url: "x",
122
+ })),
123
+ } as unknown as FileStorageService;
124
+ const plugin = new AiApp({fileStorageService});
125
+ const app = setupServer({
126
+ addRoutes: (router) => plugin.register(router as unknown as express.Application),
127
+ skipListen: true,
128
+ userModel: UserModel,
129
+ });
130
+ const upload = await supertest(app).post("/files/upload");
131
+ expect(upload.status).toBe(404);
132
+ });
133
+
134
+ it("registers mcp routes when mcpService is provided", async () => {
135
+ const mcpService = {
136
+ getServerStatus: mock(() => []),
137
+ getTools: mock(async () => ({})),
138
+ reconnectServer: mock(async () => {}),
139
+ } as unknown as MCPService;
140
+ const plugin = new AiApp({mcpService});
141
+ const app = setupServer({
142
+ addRoutes: (router) => plugin.register(router as unknown as express.Application),
143
+ skipListen: true,
144
+ userModel: UserModel,
145
+ });
146
+ const agent = await authAsUser(app);
147
+ const servers = await agent.get("/mcp/servers");
148
+ expect(servers.status).not.toBe(404);
149
+ });
150
+ });
@@ -0,0 +1,64 @@
1
+ import {beforeEach, describe, expect, it, mock} from "bun:test";
2
+
3
+ const shutdownMock = mock(async () => {});
4
+ let ctorCalls = 0;
5
+ class FakeLangfuseClient {
6
+ constructor(public opts: {baseUrl?: string; publicKey: string; secretKey: string}) {
7
+ ctorCalls += 1;
8
+ }
9
+ async shutdown(): Promise<void> {
10
+ return shutdownMock();
11
+ }
12
+ }
13
+
14
+ mock.module("@langfuse/client", () => ({
15
+ LangfuseClient: FakeLangfuseClient,
16
+ }));
17
+
18
+ const {getLangfuseClient, initLangfuseClient, isLangfuseInitialized, shutdownLangfuseClient} =
19
+ await import("../langfuseClient");
20
+
21
+ describe("langfuseClient", () => {
22
+ beforeEach(async () => {
23
+ await shutdownLangfuseClient();
24
+ ctorCalls = 0;
25
+ });
26
+
27
+ it("throws when accessing client before initialization", () => {
28
+ expect(() => getLangfuseClient()).toThrow(/not initialized/);
29
+ expect(isLangfuseInitialized()).toBe(false);
30
+ });
31
+
32
+ it("initializes a client with defaults", () => {
33
+ const client = initLangfuseClient({
34
+ publicKey: "pk",
35
+ secretKey: "sk",
36
+ });
37
+ expect((client as unknown as FakeLangfuseClient).opts.baseUrl).toBe(
38
+ "https://cloud.langfuse.com"
39
+ );
40
+ expect(isLangfuseInitialized()).toBe(true);
41
+ expect(getLangfuseClient()).toBe(client);
42
+ });
43
+
44
+ it("respects a custom baseUrl", () => {
45
+ const client = initLangfuseClient({
46
+ baseUrl: "https://lf.example.com",
47
+ publicKey: "pk",
48
+ secretKey: "sk",
49
+ });
50
+ expect((client as unknown as FakeLangfuseClient).opts.baseUrl).toBe("https://lf.example.com");
51
+ });
52
+
53
+ it("shuts down the client", async () => {
54
+ initLangfuseClient({publicKey: "pk", secretKey: "sk"});
55
+ await shutdownLangfuseClient();
56
+ expect(shutdownMock).toHaveBeenCalled();
57
+ expect(isLangfuseInitialized()).toBe(false);
58
+ });
59
+
60
+ it("no-ops shutdown when no client is initialized", async () => {
61
+ await shutdownLangfuseClient();
62
+ expect(isLangfuseInitialized()).toBe(false);
63
+ });
64
+ });
@@ -0,0 +1,135 @@
1
+ import {beforeAll, beforeEach, describe, expect, it} from "bun:test";
2
+ import {createdUpdatedPlugin, setupServer} from "@terreno/api";
3
+ import type express from "express";
4
+ import mongoose from "mongoose";
5
+ import passportLocalMongoose from "passport-local-mongoose";
6
+ import supertest from "supertest";
7
+
8
+ import {LangfuseApp} from "./langfuseApp";
9
+
10
+ type PasswordedUser = {setPassword: (password: string) => Promise<void>};
11
+
12
+ const userSchema = new mongoose.Schema({
13
+ admin: {default: false, type: Boolean},
14
+ email: {index: true, type: String},
15
+ name: String,
16
+ });
17
+ userSchema.plugin(
18
+ passportLocalMongoose as unknown as (
19
+ schema: mongoose.Schema,
20
+ options: {usernameField: string}
21
+ ) => void,
22
+ {usernameField: "email"}
23
+ );
24
+ userSchema.plugin(createdUpdatedPlugin);
25
+ const UserModel = mongoose.models.User || mongoose.model("User", userSchema);
26
+
27
+ const buildApp = (plugin: LangfuseApp) =>
28
+ setupServer({
29
+ addRoutes: (router) => plugin.register(router as unknown as express.Application),
30
+ skipListen: true,
31
+ userModel: UserModel,
32
+ });
33
+
34
+ describe("LangfuseApp", () => {
35
+ beforeAll(async () => {
36
+ await UserModel.deleteMany({});
37
+ const u = await UserModel.create({email: "lf@example.com", name: "User"});
38
+ await (u as unknown as PasswordedUser).setPassword("password");
39
+ await u.save();
40
+ });
41
+
42
+ beforeEach(async () => {
43
+ const {shutdownLangfuseClient} = await import("./langfuseClient");
44
+ await shutdownLangfuseClient();
45
+ });
46
+
47
+ it("mounts admin routes at the default path", async () => {
48
+ const plugin = new LangfuseApp({
49
+ enableTracing: false,
50
+ publicKey: "pk",
51
+ secretKey: "sk",
52
+ });
53
+ const app = buildApp(plugin);
54
+ const res = await supertest(app).get("/admin/langfuse/prompts");
55
+ expect(res.status).not.toBe(404);
56
+ });
57
+
58
+ it("mounts admin routes at a custom path", async () => {
59
+ const plugin = new LangfuseApp({
60
+ adminPath: "/lf-admin",
61
+ enableTracing: false,
62
+ publicKey: "pk",
63
+ secretKey: "sk",
64
+ });
65
+ const app = buildApp(plugin);
66
+ const custom = await supertest(app).get("/lf-admin/prompts");
67
+ expect(custom.status).not.toBe(404);
68
+ const defaultPath = await supertest(app).get("/admin/langfuse/prompts");
69
+ expect(defaultPath.status).toBe(404);
70
+ });
71
+
72
+ it("skips admin routes when enableAdminUI is false", async () => {
73
+ const plugin = new LangfuseApp({
74
+ enableAdminUI: false,
75
+ enableTracing: false,
76
+ publicKey: "pk",
77
+ secretKey: "sk",
78
+ });
79
+ const app = buildApp(plugin);
80
+ const res = await supertest(app).get("/admin/langfuse/prompts");
81
+ expect(res.status).toBe(404);
82
+ });
83
+
84
+ it("registers evaluation routes when evaluation.enabled is true", async () => {
85
+ const plugin = new LangfuseApp({
86
+ enableTracing: false,
87
+ evaluation: {enabled: true, scoringFunctions: []},
88
+ publicKey: "pk",
89
+ secretKey: "sk",
90
+ });
91
+ const app = buildApp(plugin);
92
+ const res = await supertest(app).get("/admin/langfuse/evaluations/config");
93
+ expect(res.status).not.toBe(404);
94
+ });
95
+
96
+ it("does not register evaluation routes when evaluation.enabled is false", async () => {
97
+ const plugin = new LangfuseApp({
98
+ enableTracing: false,
99
+ evaluation: {enabled: false, scoringFunctions: []},
100
+ publicKey: "pk",
101
+ secretKey: "sk",
102
+ });
103
+ const app = buildApp(plugin);
104
+ const res = await supertest(app).get("/admin/langfuse/evaluations/config");
105
+ expect(res.status).toBe(404);
106
+ });
107
+
108
+ it("shuts down cleanly", async () => {
109
+ const plugin = new LangfuseApp({
110
+ enableTracing: false,
111
+ publicKey: "pk",
112
+ secretKey: "sk",
113
+ });
114
+ const app = buildApp(plugin);
115
+ expect(app).toBeDefined();
116
+ await plugin.shutdown();
117
+ });
118
+
119
+ it("invokes shutdown via the SIGTERM handler registered on register", async () => {
120
+ const plugin = new LangfuseApp({
121
+ enableTracing: false,
122
+ publicKey: "pk",
123
+ secretKey: "sk",
124
+ });
125
+ buildApp(plugin);
126
+ // Find the SIGTERM listener that was added last by register() and invoke it directly.
127
+ const listeners = process.listeners("SIGTERM");
128
+ const last = listeners[listeners.length - 1] as (sig: NodeJS.Signals) => void;
129
+ expect(typeof last).toBe("function");
130
+ last("SIGTERM");
131
+ process.removeListener("SIGTERM", last);
132
+ // Give the fire-and-forget shutdown a tick to settle.
133
+ await new Promise((resolve) => setTimeout(resolve, 10));
134
+ });
135
+ });
@@ -1,89 +1,75 @@
1
- import {afterEach, describe, expect, it, mock} from "bun:test";
1
+ import {beforeEach, describe, expect, it} from "bun:test";
2
2
 
3
3
  import {getCached, invalidateCache, LangfuseCache, setCached} from "./langfuseCache";
4
- import type {LangfuseCachedPrompt} from "./langfuseTypes";
5
4
 
6
- const samplePrompt: LangfuseCachedPrompt = {
7
- config: {},
8
- labels: ["production"],
9
- name: "test-prompt",
10
- prompt: "Hello world",
11
- tags: [],
12
- type: "text",
13
- version: 1,
14
- };
15
-
16
- const originalFindOne = LangfuseCache.findOne;
17
- const originalFindOneAndUpdate = LangfuseCache.findOneAndUpdate;
18
- const originalDeleteMany = LangfuseCache.deleteMany;
19
-
20
- describe("cache", () => {
21
- afterEach(() => {
22
- LangfuseCache.findOne = originalFindOne;
23
- LangfuseCache.findOneAndUpdate = originalFindOneAndUpdate;
24
- LangfuseCache.deleteMany = originalDeleteMany;
5
+ describe("langfuseCache", () => {
6
+ beforeEach(async () => {
7
+ await LangfuseCache.deleteMany({});
25
8
  });
26
9
 
27
- describe("getCached", () => {
28
- it("returns null when no entry exists", async () => {
29
- const lean = mock(async () => null);
30
- const findOne = mock(() => ({lean}));
31
- LangfuseCache.findOne = findOne as unknown as typeof LangfuseCache.findOne;
32
-
33
- const result = await getCached("prompt:missing:production");
34
-
35
- expect(result).toBeNull();
36
- expect(findOne).toHaveBeenCalledTimes(1);
37
- const [query] = (findOne as {mock: {calls: unknown[][]}}).mock.calls[0];
38
- expect((query as {key: string}).key).toBe("prompt:missing:production");
39
- expect((query as {expiresAt: {$gt: Date}}).expiresAt.$gt).toBeInstanceOf(Date);
40
- });
41
-
42
- it("returns cached value when entry exists", async () => {
43
- const lean = mock(async () => ({value: samplePrompt}));
44
- const findOne = mock(() => ({lean}));
45
- LangfuseCache.findOne = findOne as unknown as typeof LangfuseCache.findOne;
46
-
47
- const result = await getCached("prompt:test:production");
48
-
49
- expect(result).toEqual(samplePrompt);
50
- expect(lean).toHaveBeenCalledTimes(1);
51
- });
10
+ it("returns null for missing keys", async () => {
11
+ expect(await getCached("missing")).toBeNull();
52
12
  });
53
13
 
54
- describe("setCached", () => {
55
- it("upserts cache entries with computed expiry", async () => {
56
- const findOneAndUpdate = mock(async () => ({}));
57
- LangfuseCache.findOneAndUpdate =
58
- findOneAndUpdate as unknown as typeof LangfuseCache.findOneAndUpdate;
59
-
60
- const beforeCall = Date.now();
61
- await setCached("prompt:test:production", samplePrompt, 60);
62
- const afterCall = Date.now();
63
-
64
- expect(findOneAndUpdate).toHaveBeenCalledTimes(1);
65
- const [filter, update, options] = (findOneAndUpdate as {mock: {calls: unknown[][]}}).mock
66
- .calls[0];
67
- expect(filter).toEqual({key: "prompt:test:production"});
68
- expect((update as {key: string}).key).toBe("prompt:test:production");
69
- expect((update as {value: LangfuseCachedPrompt}).value).toEqual(samplePrompt);
70
- expect(options).toEqual({upsert: true});
71
-
72
- const expiresAt = (update as {expiresAt: Date}).expiresAt.getTime();
73
- expect(expiresAt).toBeGreaterThanOrEqual(beforeCall + 59000);
74
- expect(expiresAt).toBeLessThanOrEqual(afterCall + 61000);
75
- });
14
+ it("stores and retrieves a cached prompt", async () => {
15
+ await setCached(
16
+ "prompt:hello:production",
17
+ {
18
+ config: {},
19
+ labels: [],
20
+ name: "hello",
21
+ prompt: "Hi",
22
+ tags: [],
23
+ type: "text",
24
+ version: 1,
25
+ },
26
+ 60
27
+ );
28
+ const got = await getCached("prompt:hello:production");
29
+ expect(got?.name).toBe("hello");
76
30
  });
77
31
 
78
- describe("invalidateCache", () => {
79
- it("passes regex key pattern to deleteMany", async () => {
80
- const deleteMany = mock(async () => ({}));
81
- LangfuseCache.deleteMany = deleteMany as unknown as typeof LangfuseCache.deleteMany;
32
+ it("upserts existing entries via setCached", async () => {
33
+ await setCached(
34
+ "prompt:x:production",
35
+ {config: {}, labels: [], name: "x", prompt: "old", tags: [], type: "text", version: 1},
36
+ 60
37
+ );
38
+ await setCached(
39
+ "prompt:x:production",
40
+ {config: {}, labels: [], name: "x", prompt: "new", tags: [], type: "text", version: 2},
41
+ 60
42
+ );
43
+ const got = await getCached("prompt:x:production");
44
+ expect(got?.version).toBe(2);
45
+ });
82
46
 
83
- await invalidateCache("prompt:test-prompt:");
47
+ it("returns null for expired entries", async () => {
48
+ await setCached(
49
+ "prompt:expired:production",
50
+ {config: {}, labels: [], name: "expired", prompt: "", tags: [], type: "text", version: 1},
51
+ 60
52
+ );
53
+ await LangfuseCache.updateOne(
54
+ {key: "prompt:expired:production"},
55
+ {expiresAt: new Date(Date.now() - 1000)}
56
+ );
57
+ expect(await getCached("prompt:expired:production")).toBeNull();
58
+ });
84
59
 
85
- expect(deleteMany).toHaveBeenCalledTimes(1);
86
- expect(deleteMany).toHaveBeenCalledWith({key: {$regex: "prompt:test-prompt:"}});
87
- });
60
+ it("invalidates entries matching a pattern", async () => {
61
+ await setCached(
62
+ "prompt:keep:production",
63
+ {config: {}, labels: [], name: "keep", prompt: "", tags: [], type: "text", version: 1},
64
+ 60
65
+ );
66
+ await setCached(
67
+ "prompt:drop:production",
68
+ {config: {}, labels: [], name: "drop", prompt: "", tags: [], type: "text", version: 1},
69
+ 60
70
+ );
71
+ await invalidateCache("prompt:drop");
72
+ expect(await getCached("prompt:drop:production")).toBeNull();
73
+ expect(await getCached("prompt:keep:production")).not.toBeNull();
88
74
  });
89
75
  });