Skip to content

Add student_source() for inspecting the submission - #61

Merged
eliotwrobson merged 1 commit into
mainfrom
claude/student-source-api
Nov 20, 2026
Merged

eliotwrobson merged 1 commit into
mainfrom
claude/student-source-api

Conversation

@eliotwrobson

Copy link
Copy Markdown
Collaborator

Summary

Adds StudentFixture.student_source(), a documented way for a test to read the student's submitted source as a string and inspect it — typically with ast — instead of reaching for the semi-internal student_code_file path.

It returns only the student's file (not any leading_code.py/trailing_code.py the question wraps around it). For a notebook submission it returns the graded cells' code, selected by notebook_cell_tag when one is set — the same source that runs in the sandbox — so .py and .ipynb questions use the same call.

This supports converting legacy questions that statically analyze the submission (e.g. CS357's 11-Sparse/Sparse-COO-*, which read /grade/student/user_code.py and parse it to check how a result was built).

Testing

  • test_student_source scenario: a .py submission read back through the full sandbox, asserting the text matches and that ast finds the function and a matmul.
  • test_student_source_notebook scenario: a notebook submission returns only the #grade cell's code, not a scratch cell.
  • Full suite green (326 passed), mypy, ruff, and format clean on Python 3.14.

🤖 Generated with Claude Code

StudentFixture.student_source() returns the student's submitted source as
a string, a documented way to inspect the submission itself (for example
with ast) instead of reaching for the student_code_file path. For a
notebook it returns the graded cells' code, the same source that runs in
the sandbox, so .py and .ipynb questions use the same call.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@eliotwrobson
eliotwrobson marked this pull request as ready for review November 20, 2026 07:40
@eliotwrobson
eliotwrobson merged commit 478a665 into main Nov 20, 2026
5 checks passed
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.

1 participant