@studious-lms/server 1.4.3 → 1.4.5
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/.vscode/settings.json +3 -0
- package/dist/index.js +4 -18
- package/dist/index.js.map +1 -1
- package/dist/models/conversation.d.ts +22 -0
- package/dist/models/conversation.d.ts.map +1 -1
- package/dist/models/conversation.js +13 -2
- package/dist/models/conversation.js.map +1 -1
- package/dist/models/labChat.d.ts +3 -0
- package/dist/models/labChat.d.ts.map +1 -1
- package/dist/models/message.d.ts +2 -0
- package/dist/models/message.d.ts.map +1 -1
- package/dist/models/newtonChat.d.ts +1 -0
- package/dist/models/newtonChat.d.ts.map +1 -1
- package/dist/models/worksheet.d.ts +1 -0
- package/dist/models/worksheet.d.ts.map +1 -1
- package/dist/models/worksheet.js +2 -2
- package/dist/models/worksheet.js.map +1 -1
- package/dist/pipelines/pdfToWorksheet.d.ts +12 -0
- package/dist/pipelines/pdfToWorksheet.d.ts.map +1 -0
- package/dist/pipelines/pdfToWorksheet.js +155 -0
- package/dist/pipelines/pdfToWorksheet.js.map +1 -0
- package/dist/routers/_app.d.ts +252 -0
- package/dist/routers/_app.d.ts.map +1 -1
- package/dist/routers/_app.js +4 -2
- package/dist/routers/_app.js.map +1 -1
- package/dist/routers/conversation.d.ts +14 -0
- package/dist/routers/conversation.d.ts.map +1 -1
- package/dist/routers/conversation.js +6 -3
- package/dist/routers/conversation.js.map +1 -1
- package/dist/routers/labChat.d.ts +2 -0
- package/dist/routers/labChat.d.ts.map +1 -1
- package/dist/routers/search.d.ts +41 -0
- package/dist/routers/search.d.ts.map +1 -0
- package/dist/routers/search.js +15 -0
- package/dist/routers/search.js.map +1 -0
- package/dist/routers/worksheet.d.ts +71 -0
- package/dist/routers/worksheet.d.ts.map +1 -1
- package/dist/routers/worksheet.js +110 -3
- package/dist/routers/worksheet.js.map +1 -1
- package/dist/services/conversation.d.ts +8 -0
- package/dist/services/conversation.d.ts.map +1 -1
- package/dist/services/conversation.js +24 -6
- package/dist/services/conversation.js.map +1 -1
- package/dist/services/labChat.d.ts +2 -0
- package/dist/services/labChat.d.ts.map +1 -1
- package/dist/services/message.d.ts.map +1 -1
- package/dist/services/message.js +9 -2
- package/dist/services/message.js.map +1 -1
- package/dist/services/search.d.ts +21 -0
- package/dist/services/search.d.ts.map +1 -0
- package/dist/services/search.js +352 -0
- package/dist/services/search.js.map +1 -0
- package/dist/services/worksheet.d.ts +21 -0
- package/dist/services/worksheet.d.ts.map +1 -1
- package/dist/services/worksheet.js +50 -2
- package/dist/services/worksheet.js.map +1 -1
- package/dist/utils/inference.d.ts +2 -1
- package/dist/utils/inference.d.ts.map +1 -1
- package/dist/utils/inference.js +53 -5
- package/dist/utils/inference.js.map +1 -1
- package/package.json +1 -1
- package/prisma/migrations/20260417083000_add_conversation_member_hidden_at/migration.sql +2 -0
- package/prisma/schema.prisma +1 -0
- package/src/index.ts +4 -19
- package/src/models/conversation.ts +12 -0
- package/src/models/worksheet.ts +1 -0
- package/src/pipelines/pdfToWorksheet.ts +177 -0
- package/src/routers/_app.ts +2 -0
- package/src/routers/conversation.ts +7 -0
- package/src/routers/search.ts +14 -0
- package/src/routers/worksheet.ts +143 -0
- package/src/services/conversation.ts +27 -3
- package/src/services/message.ts +8 -0
- package/src/services/search.ts +397 -0
- package/src/services/worksheet.ts +61 -0
- package/src/utils/inference.ts +77 -7
- package/tests/pipelines/pdfToWorksheet.test.ts +176 -0
- package/tests/routers/conversation.test.ts +114 -2
- package/tests/routers/search.test.ts +109 -0
- package/tests/utils/inference.test.ts +37 -0
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `pdfToWorksheet` integration-style tests: real DB, mocked inference.
|
|
3
|
+
* CI does not call the model, and the PDF URL is passed through directly.
|
|
4
|
+
*/
|
|
5
|
+
import { describe, test, expect, vi, beforeAll, beforeEach, afterEach } from "vitest";
|
|
6
|
+
import { user1Caller } from "../setup";
|
|
7
|
+
import { prisma } from "../../src/lib/prisma";
|
|
8
|
+
import { logger } from "../../src/utils/logger";
|
|
9
|
+
|
|
10
|
+
vi.mock("../../src/utils/inference.js", () => ({
|
|
11
|
+
inference: vi.fn(),
|
|
12
|
+
}));
|
|
13
|
+
|
|
14
|
+
import { inference } from "../../src/utils/inference.js";
|
|
15
|
+
import { pdfToWorksheet } from "../../src/pipelines/pdfToWorksheet.js";
|
|
16
|
+
|
|
17
|
+
/** Same PDF path represented as a signed Google Cloud Storage URL. */
|
|
18
|
+
export const CONV_TEST_PDF_GCS_URL =
|
|
19
|
+
"https://storage.googleapis.com/studious-test-bucket/worksheets/conv-test.pdf?X-Goog-Algorithm=GOOG4-RSA-SHA256&X-Goog-Signature=test-signature";
|
|
20
|
+
|
|
21
|
+
export const NON_GCS_PDF_URL =
|
|
22
|
+
"https://drive.google.com/file/d/1BfotteM60Ax0krHzE6rFN1Df8S8kT3kb/view?usp=drive_link";
|
|
23
|
+
|
|
24
|
+
/** Mirrors the 8-question conv-test worksheet shape the model is expected to return. */
|
|
25
|
+
function draftWithEightQuestions(title = "Conv test worksheet") {
|
|
26
|
+
const types = [
|
|
27
|
+
"SHORT_ANSWER",
|
|
28
|
+
"MULTIPLE_CHOICE",
|
|
29
|
+
"TRUE_FALSE",
|
|
30
|
+
"SHORT_ANSWER",
|
|
31
|
+
"LONG_ANSWER",
|
|
32
|
+
"MATH_EXPRESSION",
|
|
33
|
+
"ESSAY",
|
|
34
|
+
"SHORT_ANSWER",
|
|
35
|
+
] as const;
|
|
36
|
+
|
|
37
|
+
return {
|
|
38
|
+
title,
|
|
39
|
+
questions: types.map((type, i) => ({
|
|
40
|
+
type,
|
|
41
|
+
question: `Question ${i + 1}`,
|
|
42
|
+
answer: `Answer ${i + 1}`,
|
|
43
|
+
options:
|
|
44
|
+
type === "MULTIPLE_CHOICE"
|
|
45
|
+
? [
|
|
46
|
+
{ id: "a", text: "Wrong", isCorrect: false },
|
|
47
|
+
{ id: "b", text: "Right", isCorrect: true },
|
|
48
|
+
]
|
|
49
|
+
: [],
|
|
50
|
+
markScheme: [] as { id: string; points: number; description: string }[],
|
|
51
|
+
points: i + 1,
|
|
52
|
+
order: i + 1,
|
|
53
|
+
})),
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
describe("pdfToWorksheet", () => {
|
|
58
|
+
let classId: string;
|
|
59
|
+
const createdWorksheetIds: string[] = [];
|
|
60
|
+
|
|
61
|
+
beforeAll(async () => {
|
|
62
|
+
const cls = await user1Caller.class.create({
|
|
63
|
+
name: "pdfToWorksheet pipeline class",
|
|
64
|
+
subject: "Science",
|
|
65
|
+
section: "Test",
|
|
66
|
+
});
|
|
67
|
+
classId = cls.id;
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
beforeEach(() => {
|
|
71
|
+
vi.mocked(inference).mockReset();
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
afterEach(async () => {
|
|
75
|
+
for (const id of createdWorksheetIds.splice(0)) {
|
|
76
|
+
await prisma.worksheet.delete({ where: { id } }).catch(() => undefined);
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
test("passes the PDF URL directly to inference and persists a worksheet with 8 questions", async () => {
|
|
81
|
+
const draft = draftWithEightQuestions();
|
|
82
|
+
vi.mocked(inference).mockResolvedValue(draft);
|
|
83
|
+
|
|
84
|
+
const worksheet = await pdfToWorksheet(CONV_TEST_PDF_GCS_URL, classId);
|
|
85
|
+
expect(worksheet).not.toBeNull();
|
|
86
|
+
createdWorksheetIds.push(worksheet!.id);
|
|
87
|
+
|
|
88
|
+
expect(worksheet!.name).toBe(draft.title);
|
|
89
|
+
expect(worksheet!.classId).toBe(classId);
|
|
90
|
+
|
|
91
|
+
const questions = await prisma.worksheetQuestion.findMany({
|
|
92
|
+
where: { worksheetId: worksheet!.id },
|
|
93
|
+
orderBy: { order: "asc" },
|
|
94
|
+
});
|
|
95
|
+
expect(questions).toHaveLength(8);
|
|
96
|
+
expect(questions.map((q) => q.question)).toEqual(
|
|
97
|
+
draft.questions.map((q) => q.question)
|
|
98
|
+
);
|
|
99
|
+
expect(questions.map((q) => q.order)).toEqual([1, 2, 3, 4, 5, 6, 7, 8]);
|
|
100
|
+
expect(questions.map((q) => q.points)).toEqual([1, 2, 3, 4, 5, 6, 7, 8]);
|
|
101
|
+
|
|
102
|
+
expect(inference).toHaveBeenCalledTimes(1);
|
|
103
|
+
const input = vi.mocked(inference).mock.calls[0][0];
|
|
104
|
+
expect(Array.isArray(input)).toBe(true);
|
|
105
|
+
type InputPart = { type?: string; file_url?: string; text?: string };
|
|
106
|
+
const content = (input as { role: string; content: InputPart[] }[])[0].content;
|
|
107
|
+
const filePart = content.find((p) => p.type === "input_file");
|
|
108
|
+
expect(filePart).toEqual({
|
|
109
|
+
type: "input_file",
|
|
110
|
+
file_url: CONV_TEST_PDF_GCS_URL,
|
|
111
|
+
});
|
|
112
|
+
expect(vi.mocked(inference)).toHaveBeenCalledWith(
|
|
113
|
+
expect.any(Array),
|
|
114
|
+
expect.anything(),
|
|
115
|
+
expect.objectContaining({
|
|
116
|
+
reason: "pdf_to_worksheet_draft",
|
|
117
|
+
metadata: expect.objectContaining({
|
|
118
|
+
classId,
|
|
119
|
+
filename: "conv-test.pdf",
|
|
120
|
+
}),
|
|
121
|
+
})
|
|
122
|
+
);
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
test("rejects non-Google Cloud URLs and only logs a sanitized path", async () => {
|
|
126
|
+
const warnSpy = vi.spyOn(logger, "warn").mockImplementation(() => undefined);
|
|
127
|
+
|
|
128
|
+
await expect(pdfToWorksheet(NON_GCS_PDF_URL, classId)).rejects.toThrow(
|
|
129
|
+
"Only Google Cloud Storage URLs are supported"
|
|
130
|
+
);
|
|
131
|
+
|
|
132
|
+
expect(warnSpy).toHaveBeenCalledWith(
|
|
133
|
+
"pdfToWorksheet: rejected unsupported PDF URL",
|
|
134
|
+
{ sanitizedUrl: "https://drive.google.com/file/d/1BfotteM60Ax0krHzE6rFN1Df8S8kT3kb/view" }
|
|
135
|
+
);
|
|
136
|
+
expect(inference).not.toHaveBeenCalled();
|
|
137
|
+
warnSpy.mockRestore();
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
test("rounds persisted integer fields from model output", async () => {
|
|
141
|
+
vi.mocked(inference).mockResolvedValue({
|
|
142
|
+
title: "Rounded worksheet",
|
|
143
|
+
questions: [{
|
|
144
|
+
type: "SHORT_ANSWER",
|
|
145
|
+
question: "Rounded question",
|
|
146
|
+
answer: "Rounded answer",
|
|
147
|
+
options: [],
|
|
148
|
+
markScheme: [{ id: "step-1", points: 0.6, description: "Half step" }],
|
|
149
|
+
points: 1.7,
|
|
150
|
+
order: 1.2,
|
|
151
|
+
}],
|
|
152
|
+
} as Awaited<ReturnType<typeof inference>>);
|
|
153
|
+
|
|
154
|
+
const worksheet = await pdfToWorksheet(CONV_TEST_PDF_GCS_URL, classId);
|
|
155
|
+
expect(worksheet).not.toBeNull();
|
|
156
|
+
createdWorksheetIds.push(worksheet!.id);
|
|
157
|
+
|
|
158
|
+
const [question] = await prisma.worksheetQuestion.findMany({
|
|
159
|
+
where: { worksheetId: worksheet!.id },
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
expect(question.points).toBe(2);
|
|
163
|
+
expect(question.order).toBe(1);
|
|
164
|
+
expect(question.markScheme).toEqual([{ id: "step-1", points: 1, description: "Half step" }]);
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
test("returns null when inference yields no parsed output", async () => {
|
|
168
|
+
vi.mocked(inference).mockResolvedValue(
|
|
169
|
+
null as unknown as Awaited<ReturnType<typeof inference>>
|
|
170
|
+
);
|
|
171
|
+
|
|
172
|
+
const out = await pdfToWorksheet(CONV_TEST_PDF_GCS_URL, classId);
|
|
173
|
+
expect(out).toBeNull();
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
});
|
|
@@ -1,17 +1,35 @@
|
|
|
1
1
|
import { test, expect, describe, beforeAll } from 'vitest';
|
|
2
|
+
import { prisma } from '../../src/lib/prisma';
|
|
2
3
|
import { user1Caller, user2Caller, user3Caller } from '../setup';
|
|
3
4
|
import { expectUnauth } from '../helpers';
|
|
4
5
|
|
|
5
6
|
describe('Conversation Router', () => {
|
|
6
7
|
let dmConversation: any;
|
|
7
8
|
let groupConversation: any;
|
|
9
|
+
let user1Id: string;
|
|
8
10
|
let user3Id: string;
|
|
11
|
+
let hideConversationCounter = 0;
|
|
9
12
|
|
|
10
13
|
beforeAll(async () => {
|
|
11
|
-
const
|
|
12
|
-
|
|
14
|
+
const [user1Profile, user3Profile] = await Promise.all([
|
|
15
|
+
user1Caller.user.getProfile(),
|
|
16
|
+
user3Caller.user.getProfile(),
|
|
17
|
+
]);
|
|
18
|
+
|
|
19
|
+
user1Id = user1Profile.id;
|
|
20
|
+
user3Id = user3Profile.id;
|
|
13
21
|
});
|
|
14
22
|
|
|
23
|
+
async function createHideableConversation() {
|
|
24
|
+
hideConversationCounter += 1;
|
|
25
|
+
|
|
26
|
+
return user1Caller.conversation.create({
|
|
27
|
+
type: 'GROUP',
|
|
28
|
+
name: `Hide Test Group Chat ${hideConversationCounter}`,
|
|
29
|
+
memberIds: ['testuser2'],
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
|
|
15
33
|
describe('create', () => {
|
|
16
34
|
test('should create a DM conversation', async () => {
|
|
17
35
|
dmConversation = await user1Caller.conversation.create({
|
|
@@ -36,6 +54,13 @@ describe('Conversation Router', () => {
|
|
|
36
54
|
expect(groupConversation.name).toBe('Test Group Chat');
|
|
37
55
|
});
|
|
38
56
|
|
|
57
|
+
test('should create a hideable GROUP conversation', async () => {
|
|
58
|
+
const conversation = await createHideableConversation();
|
|
59
|
+
|
|
60
|
+
expect(conversation).toBeDefined();
|
|
61
|
+
expect(conversation.type).toBe('GROUP');
|
|
62
|
+
});
|
|
63
|
+
|
|
39
64
|
test('should fail to create duplicate DM', async () => {
|
|
40
65
|
await expect(
|
|
41
66
|
user1Caller.conversation.create({
|
|
@@ -125,6 +150,93 @@ describe('Conversation Router', () => {
|
|
|
125
150
|
});
|
|
126
151
|
});
|
|
127
152
|
|
|
153
|
+
describe('hide', () => {
|
|
154
|
+
test('should hide a conversation only for the requesting member', async () => {
|
|
155
|
+
const conversation = await createHideableConversation();
|
|
156
|
+
|
|
157
|
+
const result = await user1Caller.conversation.hide({
|
|
158
|
+
conversationId: conversation.id,
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
expect(result).toEqual({ success: true });
|
|
162
|
+
|
|
163
|
+
const membership = await prisma.conversationMember.findUniqueOrThrow({
|
|
164
|
+
where: {
|
|
165
|
+
userId_conversationId: {
|
|
166
|
+
userId: user1Id,
|
|
167
|
+
conversationId: conversation.id,
|
|
168
|
+
},
|
|
169
|
+
},
|
|
170
|
+
select: { hiddenAt: true },
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
expect(membership.hiddenAt).not.toBeNull();
|
|
174
|
+
|
|
175
|
+
const user1Conversations = await user1Caller.conversation.list();
|
|
176
|
+
const user2Conversations = await user2Caller.conversation.list();
|
|
177
|
+
|
|
178
|
+
expect(user1Conversations.map((item) => item.id)).not.toContain(
|
|
179
|
+
conversation.id,
|
|
180
|
+
);
|
|
181
|
+
expect(user2Conversations.map((item) => item.id)).toContain(
|
|
182
|
+
conversation.id,
|
|
183
|
+
);
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
test('should keep hidden conversations accessible by id', async () => {
|
|
187
|
+
const conversation = await createHideableConversation();
|
|
188
|
+
|
|
189
|
+
await user1Caller.conversation.hide({
|
|
190
|
+
conversationId: conversation.id,
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
const hiddenConversation = await user1Caller.conversation.get({
|
|
194
|
+
conversationId: conversation.id,
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
expect(hiddenConversation.id).toBe(conversation.id);
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
test('should unhide a hidden conversation after new activity', async () => {
|
|
201
|
+
const conversation = await createHideableConversation();
|
|
202
|
+
|
|
203
|
+
await user1Caller.conversation.hide({
|
|
204
|
+
conversationId: conversation.id,
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
await user2Caller.message.send({
|
|
208
|
+
conversationId: conversation.id,
|
|
209
|
+
content: 'Bringing this conversation back',
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
const membership = await prisma.conversationMember.findUniqueOrThrow({
|
|
213
|
+
where: {
|
|
214
|
+
userId_conversationId: {
|
|
215
|
+
userId: user1Id,
|
|
216
|
+
conversationId: conversation.id,
|
|
217
|
+
},
|
|
218
|
+
},
|
|
219
|
+
select: { hiddenAt: true },
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
expect(membership.hiddenAt).toBeNull();
|
|
223
|
+
|
|
224
|
+
const conversations = await user1Caller.conversation.list();
|
|
225
|
+
|
|
226
|
+
expect(conversations.map((item) => item.id)).toContain(conversation.id);
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
test('should fail for non-members', async () => {
|
|
230
|
+
const conversation = await createHideableConversation();
|
|
231
|
+
|
|
232
|
+
await expect(
|
|
233
|
+
user3Caller.conversation.hide({
|
|
234
|
+
conversationId: conversation.id,
|
|
235
|
+
}),
|
|
236
|
+
).rejects.toThrow('Not a member of this conversation');
|
|
237
|
+
});
|
|
238
|
+
});
|
|
239
|
+
|
|
128
240
|
describe('removeMember', () => {
|
|
129
241
|
test('should remove member from conversation', async () => {
|
|
130
242
|
await user1Caller.conversation.removeMember({
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { describe, expect, test, beforeAll } from "vitest";
|
|
2
|
+
import { expectUnauth } from "../helpers";
|
|
3
|
+
import { user1Caller, user2Caller, user3Caller } from "../setup";
|
|
4
|
+
|
|
5
|
+
describe("Search Router", () => {
|
|
6
|
+
let testClass: any;
|
|
7
|
+
let assignment: any;
|
|
8
|
+
let event: any;
|
|
9
|
+
let worksheet: any;
|
|
10
|
+
|
|
11
|
+
beforeAll(async () => {
|
|
12
|
+
testClass = await user1Caller.class.create({
|
|
13
|
+
name: "Global Search Biology",
|
|
14
|
+
subject: "Biology",
|
|
15
|
+
section: "STU-65",
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
await user1Caller.class.addStudent({
|
|
19
|
+
classId: testClass.id,
|
|
20
|
+
studentId: (await user2Caller.user.getProfile()).id,
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
await user1Caller.class.updateSyllabus({
|
|
24
|
+
classId: testClass.id,
|
|
25
|
+
contents: "Photosynthesis lab policies and chlorophyll grading overview.",
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
assignment = await user1Caller.assignment.create({
|
|
29
|
+
classId: testClass.id,
|
|
30
|
+
title: "Chlorophyll Response",
|
|
31
|
+
instructions: "Explain the photosynthesis command palette experiment.",
|
|
32
|
+
dueDate: new Date(Date.now() + 86400000).toISOString(),
|
|
33
|
+
type: "HOMEWORK",
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
event = await user1Caller.event.create({
|
|
37
|
+
classId: testClass.id,
|
|
38
|
+
name: "Photosynthesis Attendance Lab",
|
|
39
|
+
location: "Room 65",
|
|
40
|
+
startTime: new Date(Date.now() + 3600000).toISOString(),
|
|
41
|
+
endTime: new Date(Date.now() + 7200000).toISOString(),
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
worksheet = await user1Caller.worksheet.create({
|
|
45
|
+
classId: testClass.id,
|
|
46
|
+
name: "Chloroplast Worksheet",
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
test("returns matching class resources for a teacher", async () => {
|
|
51
|
+
const results = await user1Caller.search.global({
|
|
52
|
+
query: "photosynthesis",
|
|
53
|
+
limit: 20,
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
expect(results.query).toBe("photosynthesis");
|
|
57
|
+
expect(results.results).toEqual(
|
|
58
|
+
expect.arrayContaining([
|
|
59
|
+
expect.objectContaining({
|
|
60
|
+
type: "assignment",
|
|
61
|
+
id: assignment.id,
|
|
62
|
+
href: `/class/${testClass.id}/assignment/${assignment.id}`,
|
|
63
|
+
}),
|
|
64
|
+
expect.objectContaining({
|
|
65
|
+
type: "event",
|
|
66
|
+
id: event.event.id,
|
|
67
|
+
href: `/class/${testClass.id}/attendance/${event.event.id}`,
|
|
68
|
+
}),
|
|
69
|
+
expect.objectContaining({
|
|
70
|
+
type: "syllabus",
|
|
71
|
+
href: `/class/${testClass.id}/syllabus`,
|
|
72
|
+
}),
|
|
73
|
+
])
|
|
74
|
+
);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
test("returns visible class resources for an enrolled student", async () => {
|
|
78
|
+
const results = await user2Caller.search.global({
|
|
79
|
+
query: "chloroplast",
|
|
80
|
+
limit: 20,
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
expect(results.results).toEqual(
|
|
84
|
+
expect.arrayContaining([
|
|
85
|
+
expect.objectContaining({
|
|
86
|
+
type: "worksheet",
|
|
87
|
+
id: worksheet.id,
|
|
88
|
+
href: `/class/${testClass.id}/worksheets`,
|
|
89
|
+
}),
|
|
90
|
+
])
|
|
91
|
+
);
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
test("does not expose resources to non-members", async () => {
|
|
95
|
+
const results = await user3Caller.search.global({
|
|
96
|
+
query: "photosynthesis",
|
|
97
|
+
limit: 20,
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
expect(results.results).not.toEqual(
|
|
101
|
+
expect.arrayContaining([
|
|
102
|
+
expect.objectContaining({ classId: testClass.id }),
|
|
103
|
+
])
|
|
104
|
+
);
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
test("fails without authentication", () =>
|
|
108
|
+
expectUnauth((c) => c.search.global({ query: "biology" })));
|
|
109
|
+
});
|
|
@@ -186,6 +186,43 @@ describe('inference', () => {
|
|
|
186
186
|
metadata: { worksheetResponseId: 'response-1' },
|
|
187
187
|
}),
|
|
188
188
|
});
|
|
189
|
+
expect(responseParseMock).toHaveBeenCalledWith({
|
|
190
|
+
model: 'gpt-5-nano',
|
|
191
|
+
input: [{
|
|
192
|
+
role: 'user',
|
|
193
|
+
content: [{ type: 'input_text', text: 'Grade this' }],
|
|
194
|
+
}],
|
|
195
|
+
text: {
|
|
196
|
+
format: expect.any(Object),
|
|
197
|
+
},
|
|
198
|
+
});
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
test('rejects ResponseInput content with input parts when format is missing', async () => {
|
|
202
|
+
await expect(
|
|
203
|
+
inference<string>([
|
|
204
|
+
{
|
|
205
|
+
role: 'user',
|
|
206
|
+
content: [
|
|
207
|
+
{ type: 'input_text', text: 'Read this PDF' },
|
|
208
|
+
{ type: 'input_file', file_url: 'https://storage.googleapis.com/bucket/file.pdf' },
|
|
209
|
+
],
|
|
210
|
+
},
|
|
211
|
+
] as any, undefined, {
|
|
212
|
+
reason: 'pdf_without_format',
|
|
213
|
+
}),
|
|
214
|
+
).rejects.toThrow(
|
|
215
|
+
'normalizeInferenceInput cannot handle ResponseInput content with input_* parts when format is undefined; pass a format to use responses.parse.',
|
|
216
|
+
);
|
|
217
|
+
|
|
218
|
+
expect(chatCreateMock).not.toHaveBeenCalled();
|
|
219
|
+
expect(prismaMocks.aiUsageLog.create).toHaveBeenCalledWith({
|
|
220
|
+
data: expect.objectContaining({
|
|
221
|
+
reason: 'pdf_without_format',
|
|
222
|
+
operation: 'chat.completions',
|
|
223
|
+
success: false,
|
|
224
|
+
}),
|
|
225
|
+
});
|
|
189
226
|
});
|
|
190
227
|
|
|
191
228
|
test('logs failed attempts before rethrowing', async () => {
|