Skip to content

Add a notebook renderer for QDK Learning multiple-choice questions - #3690

Draft
Dhairya Patel (HABER7789) wants to merge 1 commit into
mainfrom
HABER7789/mcq-renderer
Draft

Add a notebook renderer for QDK Learning multiple-choice questions#3690
Dhairya Patel (HABER7789) wants to merge 1 commit into
mainfrom
HABER7789/mcq-renderer

Conversation

@HABER7789

Copy link
Copy Markdown
Contributor

Each section of the IQPE chapter ends with a self-check question. Today it's a dropdown you click to reveal the answer. This turns those 12 into multiple choice questions a learner answers, gets marked on, and can retry.

  • The repo's first notebook renderer, for application/vnd.qdk.learning+json
  • Grading happens in the renderer, so questions work without a running kernel
  • Choices live in _unit.py, so the notebook cell only says quiz("id")
  • details_to_quiz.py bakes a chapter's questions; --check reports stale output
  • A quiz is stored as JSON in the notebook cell's output. That shape is written twice in schema.ts and in _learning_output.py with nothing linking them, so checkRendererContract() compares the two at build time and fails if a field name or the MIME type stops matching

Comment thread source/vscode/resources/qdk-learning/courses/chemistry-qpe/_learning_output.py Dismissed
Comment thread source/vscode/resources/qdk-learning/courses/chemistry-qpe/_learning_output.py Dismissed
Comment thread source/vscode/src/notebookRenderer/rendering.ts Dismissed

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Untrusted renderer content can reach Copilot, while payload and stale-output validation gaps can produce incorrect quiz behavior.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Adds an interactive, kernel-independent notebook renderer for QDK Learning quizzes.

Changes:

  • Implements multiple-choice rendering, grading, retry, accessibility, and Copilot actions.
  • Adds Python quiz authoring, validation, conversion, and baked-output tooling.
  • Converts IQPE self-check content and integrates renderer builds and messaging.
File summaries
File Description
source/vscode/tsconfig.json Separates renderer type-checking.
source/vscode/src/notebookRenderer/tsconfig.json Configures renderer TypeScript checks.
source/vscode/src/notebookRenderer/styles.css Styles quiz states and controls.
source/vscode/src/notebookRenderer/schema.ts Defines payload and messaging contracts.
source/vscode/src/notebookRenderer/rendering.ts Adds safe DOM helpers.
source/vscode/src/notebookRenderer/rendererApi.d.ts Declares notebook renderer APIs.
source/vscode/src/notebookRenderer/multipleChoice.ts Implements quiz interaction and grading.
source/vscode/src/notebookRenderer/index.ts Activates rendering and manages lifecycle.
source/vscode/src/notebookRenderer/css.d.ts Types CSS text imports.
source/vscode/src/learning/notebookRendererMessaging.ts Bridges renderer actions to Copilot.
source/vscode/src/learning/notebookExercises.ts Excludes quizzes from tracked activities.
source/vscode/src/learning/index.ts Registers renderer messaging.
source/vscode/resources/qdk-learning/utils/chemistry-qpe/verify_course.py Recognizes baked quiz cells.
source/vscode/resources/qdk-learning/utils/chemistry-qpe/README.md Documents quiz conversion workflow.
source/vscode/resources/qdk-learning/utils/chemistry-qpe/details_to_quiz.py Converts and rebakes quiz outputs.
source/vscode/resources/qdk-learning/courses/chemistry-qpe/06-iterative-phase-estimation/_unit.py Registers IQPE quiz content.
source/vscode/resources/qdk-learning/courses/chemistry-qpe/_learning_output.py Defines quiz payloads and fallbacks.
source/vscode/package.json Registers and type-checks the renderer.
source/vscode/build.mjs Builds the renderer and checks contracts.
source/vscode/authoring-courses.md Documents quiz authoring.
source/npm/qsharp/ux/qdk-theme.css Adds quiz theme colors.
Review details
  • Files reviewed: 19/22 changed files
  • Comments generated: 3
  • Review effort level: Balanced

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +40 to +42
await handleAction(service, message.actionId, {
...message.context,
});
Comment on lines +325 to +342
for cell in notebook["cells"]:
source = "".join(cell["source"])
outputs = cell.get("outputs", [])
position = 0
for call in QUIZ_CALL.findall(source):
for quiz_id in QUIZ_ID.findall(call):
expected = _normalize_bundle(
emitter._lookup_quiz(quiz_id)._repr_mimebundle_()
)
actual = (
_normalize_bundle(outputs[position].get("data"))
if position < len(outputs)
else None
)
if actual != expected:
stale.append(quiz_id)
position += 1
return stale
Comment on lines +139 to +143
if (payload.cellId !== undefined && typeof payload.cellId !== "string") {
throw new Error("QDK learning payload has a non-string cellId.");
}

return payload as unknown as LearningPayload;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants