Skip to content

Collapse duplicated student and workspace code paths - #58

Merged
eliotwrobson merged 2 commits into
mainfrom
claude/collapse-runners
Nov 18, 2026
Merged

eliotwrobson merged 2 commits into
mainfrom
claude/collapse-runners

Conversation

@eliotwrobson

Copy link
Copy Markdown
Collaborator

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_runner and workspace_runner are now thin wrappers over a single _run_sandbox helper. Workspace mode is selected by passing workspace_dir (which drives the builtins.__import__ patch and sys.path insertion), and the main code object to exec is supplied via a load_main callback (student submission vs. workspace entry-point file). The workspace name-clash preamble stays in workspace_runner.
  • fixture.py: helper_modules is 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_fixture and _initialize_workspace_fixture now share a _resolve_sandbox_config helper 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_sandbox fixtures, ConfigObject, and the StudentFixture / WorkspaceFixture classes keep their names and signatures.

Left intentionally separate: _find_student_files vs. _find_workspace_dir resolve 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 the grader-python-pytest:plot-assert-test image.

🤖 Generated with Claude Code

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
eliotwrobson marked this pull request as ready for review November 18, 2026 23:00
@eliotwrobson
eliotwrobson merged commit 2460873 into main Nov 18, 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