Skip to content

DeepTutor: Lifelong Personalized Tutoring. https://deeptutor.info/.

fix(question-bank): validate source filters against accepted sources

Bingxi Zhao (Frank)6c72de518588
diff --git a/deeptutor/api/routers/question_notebook.py b/deeptutor/api/routers/question_notebook.py
index 6e7352c71..cc336ed6d 100644
--- a/deeptutor/api/routers/question_notebook.py
+++ b/deeptutor/api/routers/question_notebook.py
@@ -285,9 +285,7 @@ async def list_entries(
bookmarked: bool | None = Query(default=None),
is_correct: bool | None = Query(default=None),
course_id: str = Query(default=""),
- source: str = Query(
- default="", pattern="^(deep_question|mastery_path|immersive_reading|book)?$"
- ),
+ source: AssessmentSource | Literal[""] = Query(default=""),
material_id: str = Query(default="", max_length=500),
section_id: str = Query(default="", max_length=500),
resolved: bool | None = Query(default=None),
diff --git a/tests/api/test_question_bank_api.py b/tests/api/test_question_bank_api.py
index 43ebb7d17..6600c0940 100644
--- a/tests/api/test_question_bank_api.py
+++ b/tests/api/test_question_bank_api.py
@@ -5,6 +5,7 @@ from __future__ import annotations
import asyncio
import importlib
from pathlib import Path
+from typing import get_args
import pytest
@@ -77,6 +78,35 @@ def test_stats_reports_the_triage_counts(client):
}
+ "source",
+ get_args(importlib.import_module("deeptutor.api.routers.question_notebook").AssessmentSource),
+)
+def test_every_assessment_source_can_be_saved_and_filtered(client, source):
+ _seed(client)
+ session_id = asyncio.run(client.store.create_session(title="Source filter"))["id"]
+ saved = client.post(
+ f"{PREFIX}/entries/upsert",
+ json={
+ "session_id": session_id,
+ "question_id": "source-question",
+ "question": "Which source?",
+ "source": source,
+ },
+ )
+ assert saved.status_code == 200
+ response = client.get(f"{PREFIX}/entries", params={"source": source})
+ assert response.status_code == 200
+ items = response.json()["items"]
+ assert saved.json()["id"] in {item["id"] for item in items}
+ assert all(item["source"] == source for item in items)
+
+
+def test_unknown_assessment_source_is_rejected(client):
+ response = client.get(f"{PREFIX}/entries", params={"source": "unknown"})
+ assert response.status_code == 422
+
+
def test_listing_carries_each_entry_categories(client):
ids = _seed(client)
category_id = client.post(f"{PREFIX}/categories", json={"name": "Set A"}).json()["id"]
diff --git a/web/contracts/generated/api.ts b/web/contracts/generated/api.ts
index 4e0342db5..688ee795b 100644
--- a/web/contracts/generated/api.ts
+++ b/web/contracts/generated/api.ts
@@ -11650,7 +11650,11 @@ export interface components {
* @enum {string}
*/
readonly source:
- "deep_question" | "mastery_path" | "immersive_reading" | "book";
+ | "deep_question"
+ | "mastery_path"
+ | "immersive_reading"
+ | "book"
+ | "partner_chat";
/**
* Turn Id
* @default
@@ -13355,7 +13359,11 @@ export interface components {
* @enum {string}
*/
readonly source:
- "deep_question" | "mastery_path" | "immersive_reading" | "book";
+ | "deep_question"
+ | "mastery_path"
+ | "immersive_reading"
+ | "book"
+ | "partner_chat";
/**
* Turn Id
* @default
@@ -25893,7 +25901,15 @@ export interface operations {
readonly search?: string;
readonly section_id?: string;
readonly sort?: string;
- readonly source?: string;
+ readonly source?:
+ | (
+ | "deep_question"
+ | "mastery_path"
+ | "immersive_reading"
+ | "book"
+ | "partner_chat"
+ )
+ | "";
/** @description Only entries filed under no category — the triage inbox. Ignored when category_id is set. */
readonly uncategorized?: boolean;
};
diff --git a/web/contracts/schema/openapi.json b/web/contracts/schema/openapi.json
index 9c2862f3e..48f2ddcfe 100644
--- a/web/contracts/schema/openapi.json
+++ b/web/contracts/schema/openapi.json
@@ -5542,7 +5542,8 @@
"deep_question",
"mastery_path",
"immersive_reading",
- "book"
+ "book",
+ "partner_chat"
],
"title": "Source",
"type": "string"
@@ -9612,7 +9613,8 @@
"deep_question",
"mastery_path",
"immersive_reading",
- "book"
+ "book",
+ "partner_chat"
],
"title": "Source",
"type": "string"
@@ -34648,10 +34650,24 @@
"name": "source",
"required": false,
"schema": {
+ "anyOf": [
+ {
+ "enum": [
+ "deep_question",
+ "mastery_path",
+ "immersive_reading",
+ "book",
+ "partner_chat"
+ ],
+ "type": "string"
+ },
+ {
+ "const": "",
+ "type": "string"
+ }
+ ],
"default": "",
- "pattern": "^(deep_question|mastery_path|immersive_reading|book)?$",
- "title": "Source",
- "type": "string"
+ "title": "Source"
}
},
{