feat: introduce CodeJailConfig class; keep module-level backward compat
Summary
Closes #159.
The three module-level globals (, , ) make it impossible for callers to maintain isolated codejail state — test fixtures bleed into each other, and multi-tenant scenarios that want different limits per request must serialize globally.
This PR introduces a class that encapsulates those three dicts along with all the mutation methods (, , , ). A module-level instance is created, and the existing module-level names become aliases pointing at the same dict objects inside it — so every existing caller continues to work without any changes.
What changed
| File | Change |
|---|---|
Add CodeJailConfig + _default_config; compat aliases; jail_code(config=None) |
|
apply_django_settings(…, config=None) |
|
tests/test_jail_code.py |
Import CodeJailConfig; add TestCodeJailConfig (9 unit tests) |
tests/util.py |
ResetJailCodeStateMixin mutates dicts in-place instead of rebinding names |
Backward compatibility
All existing module-level APIs (, , , , , direct dict access via //) are fully preserved.
Testing
The new unit tests run without a sandbox and cover:
- Instance isolation (two configs don't share state)
- / round-trip
- /
- Context-specific limit overrides
- override guard
- Isolation from module-level globals
Full integration tests require the sandbox environment described in the repo README and cannot be run from a fork per issue #139.
Test plan
- [x] ============================= test session starts ============================== platform linux -- Python 3.14.4, pytest-9.0.3, pluggy-1.6.0 rootdir: /home/sean-campbell/github/willow-2.0 configfile: pyproject.toml plugins: timeout-2.4.0, anyio-4.13.0 collected 0 items / 1 error
==================================== ERRORS ====================================
_ ERROR collecting worktrees/upstream-codejail/codejail/tests/test_jail_code.py _
ImportError while importing test module '/home/sean-campbell/github/willow-2.0/worktrees/upstream-codejail/codejail/tests/test_jail_code.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
/usr/lib/python3.14/importlib/init.py:88: in import_module
return _bootstrap._gcd_import(name[level:], package, level)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
codejail/tests/test_jail_code.py:13: in
- [ ] Maintainer: run full Running all tests with no proxy process CODEJAIL_PROXY=0 pytest --junitxml=reports/pytest-no-proxy.xml --log-level=DEBUG ============================= test session starts ============================== platform linux -- Python 3.14.4, pytest-9.0.3, pluggy-1.6.0 rootdir: /home/sean-campbell/github/willow-2.0 configfile: pyproject.toml plugins: timeout-2.4.0, anyio-4.13.0 collected 0 items / 4 errors
==================================== ERRORS ====================================
_ ERROR collecting worktrees/upstream-codejail/codejail/tests/test_django_integration_utils.py _
ImportError while importing test module '/home/sean-campbell/github/willow-2.0/worktrees/upstream-codejail/codejail/tests/test_django_integration_utils.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
/usr/lib/python3.14/importlib/init.py:88: in import_module
return _bootstrap._gcd_import(name[level:], package, level)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
codejail/tests/test_django_integration_utils.py:5: in
- generated xml file: /home/sean-campbell/github/willow-2.0/worktrees/upstream-codejail/reports/pytest-no-proxy.xml - =========================== short test summary info ============================ ERROR codejail/tests/test_django_integration_utils.py ERROR codejail/tests/test_jail_code.py ERROR codejail/tests/test_json_safe.py ERROR codejail/tests/test_safe_exec.py !!!!!!!!!!!!!!!!!!! Interrupted: 4 errors during collection !!!!!!!!!!!!!!!!!!!! ============================== 4 errors in 0.11s =============================== + Running all tests with proxy process CODEJAIL_PROXY=1 pytest --junitxml=reports/pytest-proxy.xml --log-level=DEBUG ============================= test session starts ============================== platform linux -- Python 3.14.4, pytest-9.0.3, pluggy-1.6.0 rootdir: /home/sean-campbell/github/willow-2.0 configfile: pyproject.toml plugins: timeout-2.4.0, anyio-4.13.0 collected 0 items / 4 errors
==================================== ERRORS ====================================
_ ERROR collecting worktrees/upstream-codejail/codejail/tests/test_django_integration_utils.py _
ImportError while importing test module '/home/sean-campbell/github/willow-2.0/worktrees/upstream-codejail/codejail/tests/test_django_integration_utils.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
/usr/lib/python3.14/importlib/init.py:88: in import_module
return _bootstrap._gcd_import(name[level:], package, level)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
codejail/tests/test_django_integration_utils.py:5: in
- generated xml file: /home/sean-campbell/github/willow-2.0/worktrees/upstream-codejail/reports/pytest-proxy.xml - =========================== short test summary info ============================ ERROR codejail/tests/test_django_integration_utils.py ERROR codejail/tests/test_jail_code.py ERROR codejail/tests/test_json_safe.py ERROR codejail/tests/test_safe_exec.py !!!!!!!!!!!!!!!!!!! Interrupted: 4 errors during collection !!!!!!!!!!!!!!!!!!!! ============================== 4 errors in 0.10s =============================== in sandbox environment
Thanks for the pull request, @rudi193-cmd!
This repository is currently maintained by @moisesgsalas.
Once you've gone through the following steps feel free to tag them in a comment and let them know that your changes are ready for engineering review.
:radio_button: Get product approval
If you haven't already, check this list to see if your contribution needs to go through the product review process.
- If it does, you'll need to submit a product proposal for your contribution, and have it reviewed by the Product Working Group.
- This process (including the steps you'll need to take) is documented here.
- If it doesn't, simply proceed with the next step.
:radio_button: Provide context
To help your reviewers and other members of the community understand the purpose and larger context of your changes, feel free to add as much of the following information to the PR description as you can:
- Dependencies
This PR must be merged before / after / at the same time as ...
- Blockers
This PR is waiting for OEP-1234 to be accepted.
- Timeline information
This PR must be merged by XX date because ...
- Partner information
This is for a course on edx.org.
- Supporting documentation
- Relevant Open edX discussion forum threads
:radio_button: Get a green build
If one or more checks are failing, continue working on your changes until this is no longer the case and your build turns green.
Where can I find more information?
If you'd like to get more details on all aspects of the review process for open source pull requests (OSPRs), check out the following resources:
When can I expect my changes to be merged?
Our goal is to get community contributions seen and reviewed as efficiently as possible.
However, the amount of time that it takes to review and merge a PR can vary significantly based on factors such as:
- The size and impact of the changes that it introduces
- The need for product review
- Maintenance status of the parent repository
:bulb: As a result it may take up to several weeks or months to complete a review and merge your PR.
Hi @rudi193-cmd! Welcome, and thank you for this contribution! In order for your CLA check to turn green, you'll need to submit a CLA form. If you are contributing as an individual, please fill out the individual CLA form here.
If you are contributing on behalf of an organization, please have your manager reach out to [email protected] so you may be added to your org's existing entity agreement.
Please let me know if you have any questions. Thanks!
@mphilbrick211 I wanted to let you know that it was submitted and signed yesterday, June 18. I have not heard anything back. This is a wonderful project, and I'm looking forward to helping where I can.
@mphilbrick211 I wanted to let you know that it was submitted and signed yesterday, June 18. I have not heard anything back. This is a wonderful project, and I'm looking forward to helping where I can.
Great, thanks! You should receive an executed copy from our legal counsel in the next day or so.
Hi @rudi193-cmd have you received your executed copy of the form?
Hi @rudi193-cmd have you received your executed copy of the form?
I did, just about an hour ago!
Thanks again @mphilbrick211 — now that the CLA is executed on my end (received 06-24), this should be clear on the legal side. Whenever you or @moisesgsalas have a moment, I'd welcome a review of the changes here. The PR introduces a CodeJailConfig class while keeping the module-level globals working for backward compatibility, and CI is green. Happy to adjust anything you'd like to see different.
@rudi193-cmd Your branch was behind the base. I've pulled in changes from master as a merge commit which will update your branch and cause the tests to be re-run. You should pull the changes into your local branch.