fix(textbooks): 规范核查修复 — 安全漏洞+功能缺失+i18n+类型安全

安全:createPrerequisiteAction 补充 prerequisiteKpId 归属校验;deletePrerequisiteAction 补充双知识点归属校验,防止跨教材越权。

功能:实现图谱添加/删除前置依赖(Dialog + Select 选择知识点 + 调用 Server Action + 自动刷新图谱),替换原 no-op 回调。

i18n:修复 8 处硬编码英文字符串(textbook-reader/chapter-sidebar-list/textbook-card/textbook-form-dialog/textbook-settings-dialog/create-chapter-dialog/teacher-textbook-reader),新增 saveFailed/createFailed/updateFailed/deleteFailed/questionCreatorDefaultContent 等 key。

类型安全:graph-prerequisite-edge.tsx 使用 GraphEdgeData 类型经 unknown 安全转换,替代裸 as 断言。

规范:analytics.tsx 移动 use client 指令到文件第一行;同步架构文档 005 JSON 类型定义(GraphNodeData/GraphEdgeData/MasteryLevel)。

验证:教材模块 lint 零错误、tsc 零错误、193 个单元测试全部通过。
This commit is contained in:
SpecialX
2026-06-23 00:30:14 +08:00
parent 58656da983
commit ec87cd9efa
14 changed files with 388 additions and 104 deletions

View File

@@ -4508,8 +4508,8 @@
{
"name": "GraphNodeData",
"type": "interface",
"definition": "{ id, name, chapterId, chapterTitle, level, questionCount, mastery?: MasteryInfo, isHighlighted?, isRelated?, searchText? } & Record<string, unknown>",
"purpose": "Task 9 新增React Flow 自定义节点数据(含索引签名满足 React Flow 约束",
"definition": "{ kp: KpWithRelations, mastery: MasteryInfo | null, viewMode: GraphViewMode, isSelected: boolean, isHighlighted: boolean, chapterColor: string }",
"purpose": "Task 9 新增React Flow 自定义节点数据(传递给 graph-kp-node 组件",
"usedBy": [
"components/graph-kp-node.tsx",
"components/knowledge-graph.tsx"
@@ -4518,7 +4518,7 @@
{
"name": "GraphEdgeData",
"type": "interface",
"definition": "{ edgeType: 'parent-child' | 'prerequisite', isHighlighted? } & Record<string, unknown>",
"definition": "{ edgeType: 'parent' | 'prerequisite', isHighlighted: boolean }",
"purpose": "Task 9 新增React Flow 自定义边数据",
"usedBy": [
"components/graph-prerequisite-edge.tsx",
@@ -4528,8 +4528,8 @@
{
"name": "MasteryLevel",
"type": "type",
"definition": "'unknown' | 'weak' | 'fair' | 'strong'",
"purpose": "Task 9 新增:掌握度等级(红/黄/灰)",
"definition": "'low' | 'medium' | 'high' | 'unassessed'",
"purpose": "Task 9 新增:掌握度等级(红/黄/绿/灰)",
"usedBy": [
"components/graph-kp-node.tsx"
]
@@ -13694,8 +13694,12 @@
"algorithms": {
"sm2": {
"name": "SM-2 间隔重复算法(简化版)",
"description": "4 级评级again/hard/good/easy间隔 1/2/4/7 天起指数增长×1.2/×1.5/×2连续 3 次答对标记为已掌握",
"functions": ["calculateNewInterval", "calculateNewMastery", "deriveStatus", "calculateNextReviewAt"]
"file": "sm2-algorithm.ts",
"description": "独立纯函数模块4 级评级again/hard/good/easy间隔 1/2/4/7 天起指数增长×1.2/×1.5/×2连续 3 次答对标记为已掌握。支持时间注入便于测试。",
"functions": ["calculateNewInterval", "calculateNewMastery", "deriveStatus", "calculateNextReviewAt", "calculateNewCorrectStreak", "calculateSm2Result"],
"constants": ["REVIEW_INTERVALS", "INTERVAL_MULTIPLIERS", "MAX_MASTERY_LEVEL", "MIN_MASTERY_LEVEL", "MASTERED_REQUIRED_STREAK", "MASTERED_REQUIRED_MASTERY"],
"testFile": "sm2-algorithm.test.ts",
"testCount": 39
}
},
"dataScope": {