mirror of
https://github.com/HKUDS/DeepTutor.git
synced 2026-12-04 16:09:50 +08:00
fix(mastery): validate recall offsets and preserve missing fields
This commit is contained in:
@@ -11,6 +11,7 @@ from deeptutor.core.tool_protocol import BaseTool, ToolDefinition, ToolParameter
|
||||
_FIELDS = ("prompt", "options", "learner_answer", "feedback")
|
||||
_PREVIEW_CHARS = 200
|
||||
_DETAIL_CHARS = 6000
|
||||
_MAX_SQLITE_OFFSET = 2**63 - 1
|
||||
|
||||
|
||||
def _project(row: dict[str, Any]) -> dict[str, Any]:
|
||||
@@ -31,7 +32,7 @@ def _project(row: dict[str, Any]) -> dict[str, Any]:
|
||||
"options": json.dumps(question["options"], ensure_ascii=False)
|
||||
if question.get("options")
|
||||
else None,
|
||||
"learner_answer": row["learner_answer"],
|
||||
"learner_answer": row["learner_answer"] or None,
|
||||
"feedback": payload.get("feedback") or payload.get("diagnosis") or None,
|
||||
}
|
||||
|
||||
@@ -75,6 +76,7 @@ class MasteryRecordTool(BaseTool):
|
||||
"Next offset from a previous list response.",
|
||||
required=False,
|
||||
minimum=0,
|
||||
maximum=_MAX_SQLITE_OFFSET,
|
||||
),
|
||||
ToolParameter(
|
||||
"record_id", "string", "Exact record ID from this path's list.", required=False
|
||||
@@ -112,7 +114,8 @@ class MasteryRecordTool(BaseTool):
|
||||
if (
|
||||
any(type(v) is not int for v in (limit, offset, text_offset))
|
||||
or not 1 <= limit <= 20
|
||||
or min(offset, text_offset) < 0
|
||||
or not 0 <= offset <= _MAX_SQLITE_OFFSET
|
||||
or text_offset < 0
|
||||
):
|
||||
return ToolResult(
|
||||
content="Use limit 1–20 and nonnegative integer offsets.", success=False
|
||||
|
||||
@@ -155,6 +155,7 @@ async def test_path_and_workspace_scope_and_invalid_inputs(store, tmp_path, monk
|
||||
{"limit": 0},
|
||||
{"limit": 21},
|
||||
{"offset": -1},
|
||||
{"offset": 2**63, "expected_revision": store.load("path").version},
|
||||
{"limit": True},
|
||||
{"text_offset": "0"},
|
||||
):
|
||||
@@ -258,6 +259,11 @@ async def test_qualitative_originals_missing_fields_and_empty_path(store, monkey
|
||||
"反馈原文",
|
||||
"partial",
|
||||
)
|
||||
progress = store.load("path")
|
||||
progress.learning_evidence[0].learner_answer = ""
|
||||
store.save(progress)
|
||||
result = json.loads((await tool.execute(_mastery_path_id="path")).content)
|
||||
assert result["records"][0]["learner_answer"] is None
|
||||
|
||||
|
||||
def test_group_parent_does_not_duplicate_completed_leaves(store):
|
||||
|
||||
Reference in New Issue
Block a user