Repository navigation
Collapse duplicated student and workspace code paths - #58
Merged
Merged
Conversation
Refactor only; no behavior change. Unifies the near-identical student and workspace implementations behind one shared, parameterized path in each layer: - _student_code_runner.py: student_code_runner and workspace_runner now wrap a single _run_sandbox helper; workspace mode is selected by workspace_dir and the main code object to exec is supplied by a load_main callback. - fixture.py: lift helper_modules into _SandboxBase and extract the shared subprocess/connect/send/read sequence into _SandboxBase._start_server. - plugin.py: _initialize_sandbox_fixture and _initialize_workspace_fixture share a new _resolve_sandbox_config helper that resolves the common config. Public API (sandbox, module_sandbox, workspace_sandbox fixtures, ConfigObject, StudentFixture, WorkspaceFixture) is unchanged. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
The collapse dropped the debug lines that recorded which source each setting came from. Restore them in the unified helper so both the student and workspace paths log them (run.sh runs pytest at --log-cli-level=DEBUG). Logging only; no behavior change. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
eliotwrobson
marked this pull request as ready for review
November 18, 2026 23:00
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.
Behavior-preserving refactor that collapses the two near-identical student and workspace code paths into one shared, parameterized implementation in each layer.
What was unified:
_student_code_runner.py:student_code_runnerandworkspace_runnerare now thin wrappers over a single_run_sandboxhelper. Workspace mode is selected by passingworkspace_dir(which drives thebuiltins.__import__patch andsys.pathinsertion), and the main code object to exec is supplied via aload_maincallback (student submission vs. workspace entry-point file). The workspace name-clash preamble stays inworkspace_runner.fixture.py:helper_modulesis lifted into_SandboxBase, and the shared subprocess/connect/send/read-response sequence is extracted into_SandboxBase._start_server. Each subclass keeps only its own start-message assembly.plugin.py:_initialize_sandbox_fixtureand_initialize_workspace_fixturenow share a_resolve_sandbox_confighelper for the common data.json/ConfigObject/timeout/names_for_user resolution; each wrapper only reads its fixture-specific field (notebook_cell_tag/workspace_exec_entry) and builds its fixture.The public API is unchanged: the
sandbox,module_sandbox,workspace_sandboxfixtures,ConfigObject, and theStudentFixture/WorkspaceFixtureclasses keep their names and signatures.Left intentionally separate:
_find_student_filesvs._find_workspace_dirresolve different things (a glob of files vs. a single directory with a 4-step lookup) and merging them would be forced rather than a genuine shared path.Testing
mypy,
ruff check,ruff format --check, and the full pytest suite (322 passing) all clean in thegrader-python-pytest:plot-assert-testimage.🤖 Generated with Claude Code