-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathworker.test.ts
More file actions
117 lines (110 loc) · 3.54 KB
/
Copy pathworker.test.ts
File metadata and controls
117 lines (110 loc) · 3.54 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
import { describe, expect, it } from "vitest";
import worker from "../src/worker";
function createAssetsResponse(status = 404): { fetch: () => Promise<Response> } {
return {
async fetch() {
return new Response("asset fallback", { status });
},
};
}
describe("worker model assets", () => {
it("R2 모델을 public 모델 경로로 서빙한다", async () => {
const response = await worker.fetch(
new Request("https://path-finder.test/models/mobileclip2-s0-vision.onnx"),
{
ASSETS: createAssetsResponse(),
MODEL_BUCKET: {
async get(key: string) {
expect(key).toBe("models/mobileclip2-s0-vision.onnx");
return {
body: new Blob(["onnx"]).stream(),
writeHttpMetadata(headers: Headers) {
headers.set("content-type", "application/octet-stream");
},
};
},
},
},
);
expect(response.status).toBe(200);
expect(response.headers.get("content-type")).toBe("application/octet-stream");
expect(response.headers.get("cache-control")).toBe("public, max-age=31536000, immutable");
await expect(response.text()).resolves.toBe("onnx");
});
it("R2에 모델이 없으면 404를 반환한다", async () => {
const response = await worker.fetch(
new Request("https://path-finder.test/models/mobileclip2-s0-vision.onnx"),
{
ASSETS: createAssetsResponse(),
MODEL_BUCKET: {
async get() {
return null;
},
},
},
);
expect(response.status).toBe(404);
await expect(response.text()).resolves.toBe("모델을 R2에서 찾을 수 없습니다.");
});
});
describe("worker search metadata", () => {
it("D1 keyframes metadata를 DINO Vectorize 검색 결과에 붙인다", async () => {
const response = await worker.fetch(
new Request("https://path-finder.test/api/search", {
method: "POST",
headers: { "content-type": "application/json" },
body: JSON.stringify({ modelId: "dinov2-small-v1", embedding: [1, 0, 0], topK: 1 }),
}),
{
ASSETS: createAssetsResponse(),
VECTORIZE_DINOV2: {
async query() {
return {
matches: [{ id: "coex-001", score: 0.98, metadata: { label: "coex-001" } }],
};
},
},
DB: {
prepare(sql: string) {
expect(sql).toContain("FROM keyframes");
return {
bind(...ids: string[]) {
expect(ids).toEqual(["coex-001"]);
return {
async all() {
return {
results: [
{
id: "coex-001",
label: "별마당도서관 북측",
floor: "B1",
zone: "STARFIELD",
imagePath: "/keyframes/coex-001.jpg",
x: 20,
y: 35,
},
],
};
},
};
},
};
},
},
},
);
expect(response.status).toBe(200);
await expect(response.json()).resolves.toMatchObject({
modelId: "dinov2-small-v1",
results: [
{
id: "coex-001",
label: "별마당도서관 북측",
floor: "B1",
zone: "STARFIELD",
imagePath: "/keyframes/coex-001.jpg",
},
],
});
});
});