@terreno/ai 57.18.0 → 57.20.0
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/.claude/CLAUDE.local.md +1 -1
- package/.cursor/rules/00-root.mdc +1 -1
- package/.github/copilot-instructions.md +1 -1
- package/AGENTS.md +1 -1
- package/CHANGELOG.md +2074 -0
- package/package.json +8 -8
- package/src/service/fileStorage.test.ts +18 -24
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.217.0",
|
|
13
|
-
"@terreno/blocks": "57.
|
|
13
|
+
"@terreno/blocks": "57.20.0",
|
|
14
14
|
"ai": "^6.0.97",
|
|
15
15
|
"ajv": "8.20.0",
|
|
16
16
|
"csv-parse": "^6.1.0",
|
|
@@ -22,10 +22,10 @@
|
|
|
22
22
|
"description": "Provider-agnostic AI service with streaming chat, request logging, and admin tools — part of Terreno, the batteries-included TypeScript framework for universal apps.",
|
|
23
23
|
"devDependencies": {
|
|
24
24
|
"@biomejs/biome": "^2.3.6",
|
|
25
|
-
"@terreno/admin-backend": "57.
|
|
26
|
-
"@terreno/api": "57.
|
|
27
|
-
"@terreno/jobs": "57.
|
|
28
|
-
"@terreno/test": "57.
|
|
25
|
+
"@terreno/admin-backend": "57.20.0",
|
|
26
|
+
"@terreno/api": "57.20.0",
|
|
27
|
+
"@terreno/jobs": "57.20.0",
|
|
28
|
+
"@terreno/test": "57.20.0",
|
|
29
29
|
"@types/bun": "^1.4.0",
|
|
30
30
|
"@types/express": "^5.0.6",
|
|
31
31
|
"@types/luxon": "^3.7.1",
|
|
@@ -136,8 +136,8 @@
|
|
|
136
136
|
"name": "@terreno/ai",
|
|
137
137
|
"peerDependencies": {
|
|
138
138
|
"@ai-sdk/google-vertex": "^4.0.142",
|
|
139
|
-
"@terreno/api": "57.
|
|
140
|
-
"@terreno/jobs": "57.
|
|
139
|
+
"@terreno/api": "57.20.0",
|
|
140
|
+
"@terreno/jobs": "57.20.0",
|
|
141
141
|
"mongoose": "^8.0.0 || ^9.0.0"
|
|
142
142
|
},
|
|
143
143
|
"peerDependenciesMeta": {
|
|
@@ -168,5 +168,5 @@
|
|
|
168
168
|
"test:coverage": "bun run ../scripts/check-coverage.ts"
|
|
169
169
|
},
|
|
170
170
|
"types": "dist/index.d.ts",
|
|
171
|
-
"version": "57.
|
|
171
|
+
"version": "57.20.0"
|
|
172
172
|
}
|
|
@@ -1,32 +1,18 @@
|
|
|
1
|
-
import {afterEach, beforeEach, describe, expect, it
|
|
1
|
+
import {afterEach, beforeEach, describe, expect, it} from "bun:test";
|
|
2
|
+
import {registerGcsMock} from "@terreno/test";
|
|
2
3
|
import mongoose from "mongoose";
|
|
3
4
|
|
|
4
5
|
import {FileAttachment} from "../models/fileAttachment";
|
|
5
6
|
|
|
6
|
-
//
|
|
7
|
-
const
|
|
8
|
-
delete: mock(async (_opts?: Record<string, unknown>) => [undefined]),
|
|
9
|
-
download: mock(async () => [Buffer.from("stored bytes")]),
|
|
10
|
-
getSignedUrl: mock(async () => ["https://example.com/signed-url"]),
|
|
11
|
-
save: mock(async (_buffer: Buffer, _opts: Record<string, unknown>) => [undefined]),
|
|
12
|
-
};
|
|
13
|
-
const bucketObj = {
|
|
14
|
-
file: mock((_key: string) => bucketFileMock),
|
|
15
|
-
};
|
|
16
|
-
mock.module("@google-cloud/storage", () => ({
|
|
17
|
-
Storage: class {
|
|
18
|
-
bucket = (_name: string) => bucketObj;
|
|
19
|
-
},
|
|
20
|
-
}));
|
|
7
|
+
// In-memory @google-cloud/storage so the service doesn't try to authenticate
|
|
8
|
+
const gcs = registerGcsMock();
|
|
21
9
|
|
|
22
10
|
const {FileStorageService} = await import("./fileStorage");
|
|
23
11
|
|
|
24
12
|
describe("FileStorageService", () => {
|
|
25
13
|
beforeEach(async () => {
|
|
26
14
|
await FileAttachment.deleteMany({});
|
|
27
|
-
|
|
28
|
-
bucketFileMock.getSignedUrl.mockClear();
|
|
29
|
-
bucketFileMock.save.mockClear();
|
|
15
|
+
gcs.reset();
|
|
30
16
|
});
|
|
31
17
|
|
|
32
18
|
afterEach(async () => {
|
|
@@ -51,7 +37,8 @@ describe("FileStorageService", () => {
|
|
|
51
37
|
expect(result.gcsKey).toContain("my_file.txt");
|
|
52
38
|
expect(result.size).toBe(buffer.length);
|
|
53
39
|
expect(result.url).toContain("storage.googleapis.com/test-bucket");
|
|
54
|
-
expect(
|
|
40
|
+
expect(gcs.fileMocks.save).toHaveBeenCalledTimes(1);
|
|
41
|
+
expect(gcs.getObject({bucket: "test-bucket", name: result.gcsKey})?.contents).toEqual(buffer);
|
|
55
42
|
|
|
56
43
|
const attachment = await FileAttachment.findOne({gcsKey: result.gcsKey});
|
|
57
44
|
expect(attachment).toBeDefined();
|
|
@@ -62,10 +49,15 @@ describe("FileStorageService", () => {
|
|
|
62
49
|
|
|
63
50
|
describe("download", () => {
|
|
64
51
|
it("returns the bytes of the bucket file", async () => {
|
|
52
|
+
gcs.putObject({
|
|
53
|
+
bucket: "test-bucket",
|
|
54
|
+
contents: "stored bytes",
|
|
55
|
+
name: "uploads/abc/file.txt",
|
|
56
|
+
});
|
|
65
57
|
const service = new FileStorageService({bucketName: "test-bucket"});
|
|
66
58
|
const bytes = await service.download("uploads/abc/file.txt");
|
|
67
59
|
expect(bytes.toString("utf8")).toBe("stored bytes");
|
|
68
|
-
expect(
|
|
60
|
+
expect(gcs.file).toHaveBeenCalledWith("uploads/abc/file.txt");
|
|
69
61
|
});
|
|
70
62
|
});
|
|
71
63
|
|
|
@@ -73,8 +65,10 @@ describe("FileStorageService", () => {
|
|
|
73
65
|
it("returns a signed url from the bucket file", async () => {
|
|
74
66
|
const service = new FileStorageService({bucketName: "test-bucket"});
|
|
75
67
|
const url = await service.getSignedUrl("uploads/abc/file.txt");
|
|
76
|
-
expect(url).toBe(
|
|
77
|
-
|
|
68
|
+
expect(url).toBe(
|
|
69
|
+
"https://storage.googleapis.com/test-bucket/uploads/abc/file.txt?X-Goog-Signature=mock"
|
|
70
|
+
);
|
|
71
|
+
expect(gcs.fileMocks.getSignedUrl).toHaveBeenCalledTimes(1);
|
|
78
72
|
});
|
|
79
73
|
});
|
|
80
74
|
|
|
@@ -94,7 +88,7 @@ describe("FileStorageService", () => {
|
|
|
94
88
|
await service.delete("uploads/x/y.txt");
|
|
95
89
|
|
|
96
90
|
// findOneAndUpdate may return the old doc — just verify it ran and bucket delete was called
|
|
97
|
-
expect(
|
|
91
|
+
expect(gcs.fileMocks.delete).toHaveBeenCalledTimes(1);
|
|
98
92
|
expect(attachment._id).toBeDefined();
|
|
99
93
|
});
|
|
100
94
|
});
|