Skip to content

Fix running exercises in the sandbox - #335

Merged
AydinHassan merged 1 commit into
masterfrom
run-skip-missing-reference
Oct 24, 2026
Merged

AydinHassan merged 1 commit into
masterfrom
run-skip-missing-reference

Conversation

@AydinHassan

@AydinHassan AydinHassan commented Oct 24, 2026 •

Copy link
Copy Markdown
Member

Running an exercise has been failing on phpschool.io. Two bugs; verify wasn't affected by either.

1. The code patcher read a reference solution that a run never copies.
CodePatchListener::patch patches the student's file and the reference solution's copy. Verify copies the reference solution before patching, but a run only executes the student's code, so it never copies it. On run.start, file_get_contents() then hit a missing file, and Application turned the warning into an exception.
→ run.start now uses a new patchStudent method, which only patches the student's file. Verify keeps using patch. The patch loop moved into a private patchFiles.

2. Run passed the student's absolute host path to php.
In the Docker sandbox, the working directory is mounted at /solution, so that path doesn't exist inside the container ("Could not open input file"). Verify already passes basename(...).
→ CliRunner::run and CgiRunner::run now do the same.

Tests: patchStudent patches only the student file, and CliRunner::run passes the entry point relative to the working directory. Both tests fail without the fix.

Checked end to end in phpschool.io with the Docker sandbox. Run and verify pass for 22 of 24 learnyouphp and php8appreciate exercises. The other two are composer exercises, and my script didn't install their dependencies.

On a run, the code patcher patched the reference solution, but a run
never copies it, so reading it threw and every run failed. run.start now
uses patchStudent, which only patches the student's solution.

Runs also passed the student's absolute host path to PHP, which doesn't
exist inside the sandbox where the working directory is mounted
elsewhere. They now pass the file name relative to the working
directory, like verify does.
@AydinHassan
AydinHassan force-pushed the run-skip-missing-reference branch from 76f73aa to 30722a0 Compare October 24, 2026 20:02
@AydinHassan AydinHassan changed the title Only patch solution files that exist Fix running exercises in the sandbox Oct 24, 2026
@AydinHassan
AydinHassan merged commit 649543a into master Oct 24, 2026
4 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