Skip to content

TICKET-658: Let scripts that tests start load files from their folder - #787

Open
Naragod wants to merge 1 commit into
masterfrom
TICKET-658_safe_path_flag
Open

Naragod wants to merge 1 commit into
masterfrom
TICKET-658_safe_path_flag

Conversation

@Naragod

@Naragod Naragod commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

Description

Purpose

The autotester (the server that runs instructor tests on student work) guards itself from student files. A student file named like a Python module could take the place of that module. Since the last release, the guard also reaches scripts that instructor tests start. Those scripts fail to find files in their own folder, so the tests break. This change keeps the guard on the autotester and lifts it from those scripts.

Example

  1. An instructor uploads a test script and a helper file in the same folder. The course has 120 students.
  2. The test script starts a second script. That script loads the helper file.
  3. Before this change, the second script fails to find the helper. The test fails for all 120 students.
  4. With this change, the second script finds the helper (this change). The test grades all 120 students as it did before.
  5. A student uploads a file with the name of a built-in Python module. The autotester still loads the real module.

What happened

In production, the last autotester release broke tests that start their own scripts. The release reached all four production servers we update, between Nov 30 and Dec 3. On Dec 4, an instructor reported that nearly all of their test scripts failed. The release notes left the change out. Instructors learned of it from their broken tests.

Why it happens

Pull request #761 added the guard. The guard is a setting that a program hands down to every program it starts. The autotester hands it to the test. The test hands it to each script it starts. A script with the setting fails to look in its own folder for files.

The fix

  1. The autotester turns on the guard with a start flag. The flag covers the one program it starts with. Scripts that tests start look in their own folder again.
  2. The AI tester starts its feedback program with the same flag. That program keeps the guard it had.

Implementation

  • Remove SAFE_PATH_ENV. _run_test_specs stops adding PYTHONSAFEPATH=1 to each tester's env.
  • Add -P to the tester command in _create_test_script_command.
  • Add -P to the ai_feedback command in AiTester.call_ai_feedback.

Testing

  • test_script_run_by_a_test_imports_its_neighbour runs a script with each tester's env. The script imports a file from its own folder.
  • Without the fix, that test fails with No module named 'helper'.
  • test_uploaded_file_cannot_shadow_stdlib_module now runs with PYTHONSAFEPATH removed from the env. It checks that -P alone guards the tester.
  • test_student_module_importable_only_by_python_testers runs the same way. It checks that the py and jupyter testers still load student modules.
  • test_ai_feedback_runs_with_safe_path checks that ai_feedback starts with -P.
  • The server suite passed locally on Python 3.14, apart from test_tmp_remove_other_user.
  • test_tmp_remove_other_user requires the fake_user account that CI creates. It fails on master locally too.

@Naragod
Naragod force-pushed the TICKET-658_safe_path_flag branch from 2bcd281 to a1d10fc Compare December 4, 2026 19:10
@coveralls

coveralls commented Dec 4, 2026 •

Copy link
Copy Markdown

Coverage Report for CI Build 47405455670

Coverage decreased (-0.001%) to 99.295%

Details

  • Coverage decreased (-0.001%) from the base build.
  • Patch coverage: 2 of 2 lines across 1 file are fully covered (100%).
  • No coverage regressions found.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

No coverage regressions found.


Coverage Stats

Coverage Status
Relevant Lines: 1135
Covered Lines: 1127
Line Coverage: 99.3%
Coverage Strength: 0.99 hits per line

💛 - Coveralls

@Naragod Naragod added this to the v2.10.6 milestone Dec 4, 2026
@Naragod
Naragod requested a review from donny-wong December 4, 2026 19:18
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