fix(review): 套题回顾显示正确答案与对错判定 - #105
Merged
Merged
Conversation
套题回顾界面正确答案列为空、对错判定全部丢失。
根因是两处缺陷叠加,缺一不可:
1. `_resolveReplayCorrectAnswerMap` 只在 entry/realData/rawData/
rawData.realData 四处找 `correctAnswerMap`,四处都空就返回 `{}`
—— 即便 `answerComparison` 每题都带着 `correctAnswer` 也不采用。
2. `_normalizeSuiteResult` 明明算出了 `correctAnswerMap`,但构造
`suiteEntries` 持久化时没有复制该字段。
于是套题记录写出去就不带正确答案,回顾重建时又不会反推,
`correctAnswers` 恒为 `{}`,每题渲染成空白且 `isCorrect: null`。
两处都修:
- 反推兜底修复**存量记录**(老数据没有该字段,只能从
`answerComparison` 反推)。反推结果排在显式字段之后传入
`_mergeReplayAnswerMapsFirstWins`,保持 first-wins 语义,
显式 `correctAnswerMap` 仍然优先。
- 补 `correctAnswerMap` 字段保证**新记录**自带正确答案。
安全性:只采信非空值(null/空串/空数组一律跳过),
无来源时仍降级为 `isCorrect: null`,绝不臆测对错。
反推的 map 照常走 `_normalizeReplayAnswerMap` 归一,
examId 前缀隔离不被绕过。
测试:新增 suiteReviewCorrectAnswers.test.js(11 例),
覆盖存量记录、新记录、显式优先、无来源降级、部分可推、
多选数组、前缀归一、他篇隔离、单篇不受影响。
已验证回退修复后该测试失败。
同步重建 bundles(运行时加载的是 js/bundles/*.bundle.js)。
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: bf48e208b6
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题
套题练习的回顾界面正确答案列为空,对错判定全部丢失。用户看到每道题的正确答案是空白,对错状态无法显示。
单篇(非套题)回顾不受影响。
根因
两处缺陷叠加,缺一不可:
(a) 提取器不会反推 —
js/app/examSessionMixin.js_resolveReplayCorrectAnswerMap()只在
entry/realData/rawData/rawData.realData四处找correctAnswerMap字段,四处都空就返回{}。即便answerComparison里每道题都带着correctAnswer也不采用。(b) 持久化丢字段 —
_normalizeSuiteResult()明明算出了correctAnswerMap,但构造suiteEntries写入记录时没有复制这个字段。于是:套题记录写出去就不带正确答案 → 回顾重建时又不会从
answerComparison反推 →correctAnswers恒为{}→ 每题渲染成空白且isCorrect: null。复现证据
在本分支基线(
7698e9a)上实跑,输入一条典型套题记录(带answerComparison、不带correctAnswerMap,即当前代码实际写出的形状):对照实验:手工给同一条记录补上
correctAnswerMap后,回顾立即恢复正常 —— 证明回放链路本身无缺陷,问题纯在数据供给。修复
两处都改,各自解决不同人群:
correctAnswerMap字段,只能从answerComparison反推。只做其中一条都不够:只做 (a) 则新记录继续缺字段、永远依赖兜底;只做 (b) 则所有历史记录仍然是坏的。
关键设计点
_mergeReplayAnswerMapsFirstWins,保持 first-wins 语义 —— 显式correctAnswerMap仍然优先,反推只在前面全空时生效。null/ 空字符串 / 空数组一律跳过。无来源时仍然降级为isCorrect: null,绝不臆测对错。_normalizeReplayAnswerMap归一,examId前缀隔离不被绕过(他篇的答案不会串用到本篇)。改动量:源码 35 行(含注释),其余为 bundle 同步。未新增消息类型、未加版本号、未引入回退框架。
测试
新增
developer/tests/js/suiteReviewCorrectAnswers.test.js,11 例全部通过:answerComparison反推correctAnswerMap生效isCorrect: nullexamId前缀的复合键归一已验证该测试是真回归测试:
git stash掉修复后测试在第一条断言即失败,恢复后通过。既有套件
suiteModeFlow/suiteModeRegression/appDataV2/unifiedReadingPageInlineSuiteRegression/practicePageEnhancerReplay/examPlaceholderReplay/suiteInlineFallback—— 全部 PASS。全量 JS 套件:50 passed, 3 failed。三个失败(
dataKernelV2、unifiedReadingCoreRegression、unifiedReadingNotesMigration)已验证在未加本改动的干净opensource上同样失败,与本 PR 无关。Bundles
已跑
node scripts/build-bundles.mjs(运行时加载的是js/bundles/*.bundle.js,不重建则改动不生效)。只提交了本改动波及的browse.bundle.js与session.bundle.js;core-foundation.bundle.js有一处上游 PDF manifest 的既有 drift,与本 PR 无关,已还原不带入。