19 Commits

Author SHA1 Message Date
Irtaza Akram
d29b0473f4 fix: align pylint fixes in edx-platform Problem XBlock with extracted xblocks-contrib/problem (#37758)
* fix: pylint issues for problem xblock
2026-01-07 16:39:11 +05:00
Irtaza Akram
1945b12769 Autoformat Problem XBlock Source Files for Consistency (1/2) (#37476)
* fix: run formatter black and isort

* fix: linting, pydocstyle, xsslint and security issues
2025-12-05 18:31:45 +05:00
Tim McCormack
447fd0b6cb feat: Upgrade to codejail 4.0.0 (#36916)
This brings an important security improvement -- codejail won't default to
running in unsafe mode, which can happen if certain configuration errors
are present.

Properly configured installations shouldn't be affected. We just need to
adjust some unit tests to opt into unsafe mode.

Changes:

- Update `edx-codejail` dependency to [version 4.0.0](https://github.com/openedx/codejail/blob/master/CHANGELOG.rst#400---2025-06-13)
- Define a `use_unsafe_codejail` decorator that allows running a unit test (or entire TestCase class) in unsafe mode
- Use that decorator as needed, based on which tests started failing
2025-06-17 09:33:52 -04:00
Tim McCormack
d5a273ce2f feat!: Expand codejail darklaunch normalizers; append by default (#36682)
For darklaunch comparisons where the two sides have different Python
versions, we'll want a more comprehensive list of normalizers.

- Expand the default list to include patterns discovered during a Python
  3.8 vs. 3.12 comparison.
- Append the setting value by default, rather than replacing (but still
  allow replacing).
- Use default normalizers if custom ones can't be loaded.
- Add log message when loading normalizers fails.
- Validate the replacement pattern, not just the search pattern.
2025-05-08 13:43:53 -04:00
Tim McCormack
5bc05810dc feat: Improve codejail darklaunch logging (#36671)
This is intended to make logs more or less a standalone source for
analyzing mismatches.

- Only log mismatches or exceptions
- Merge local and remote log messages into one so they can be correlated
  more easily
- Different log messages for mismatch vs. unexpected exceptions
- Include course ID (as limit overrides context) in log message
2025-05-06 16:42:55 -04:00
Tim McCormack
ca335b3c3a feat: Fix character range for codejail darklaunch tmpdir normalization (#36615)
Python's tempfile naming also includes underscore:
https://github.com/python/cpython/blob/3.12/Lib/tempfile.py#L140

This omission would cause normalization to fail about 1/6 of the time.

Also expand test to exercise more of character range.
2025-04-28 12:35:41 -04:00
Tim McCormack
3a9b4367e6 fix: Call json_safe on globals in codejail remote_exec (#36542)
We need to make globals JSON-friendly before sending them across the
network.

Addresses https://github.com/edx/edx-arch-experiments/issues/1016
2025-04-18 11:22:43 -04:00
Tim McCormack
a960cdff8d fix: Add much more codejail darklaunch info; fix remote error bug (#36534)
- Fix bug where we were overwriting `remote_emsg` with None, and add test
  that would have caught it.
- Suppress differences due solely to the codejail sandbox directory name
  differing (in stack traces), and add test for this. Configurable because
  we'll need to add an additional search/replace pair for the sandbox venv
  paths.
- Add a variety of custom attributes, replacing existing ones. The attrs
  now have a prefixed naming scheme to simplify searching.
- Add slug to log output so we can more readily correlate traces and logs,
  as well as logs across services.
- Fix typo in error message.
- Fix existing import sort order lint.
2025-04-17 15:39:47 -04:00
Tim McCormack
bf2f8c3705 fix: Don't let local codejail exec pollute darklaunched remote globals
We were running local exec before making the copy of globals_dict for
remote_exec, so remote exec has been getting a polluted version of the
globals.
2025-04-15 15:50:12 -04:00
Tim McCormack
fd66048a49 test: Improve codejail darklaunch tests
- Separate test for misconfiguration
- Add helper method for generic dark launch testing
- Test two darklaunch scenarios: Globals interference, and error that would
  previously have caused the remote side not to run
- Rename mocks to have our usual `mock_` prefix
2025-04-15 15:50:12 -04:00
Diana Huang
ef49090c31 feat: Add codejail darklaunch toggle.
This adds a toggle for running codejail in both remote
and local configurations for testing purposes.

https://github.com/edx/edx-arch-experiments/issues/895
2025-03-05 17:56:40 -05:00
Irtaza Akram
ec2a698604 cleanup references of python 2 & <3.11 (#35799)
* chore: cleanup of old python references
2024-11-15 16:58:20 +05:00
Kyle McCormick
9c6e765bf6 test: run ./xmodule/ tests with CMS settings (#33534)
Currently, ./xmodule/ unit tests are only run with LMS settings. However,
./common/ and ./xmodule/ are run twice: once with LMS settings and once with
CMS settings.

Just like ./common/ and ./openedx/, the unit tests in ./xmodule/ validate
behavior in both LMS and CMS. So, order to fully test ./xmodule/, we should to
run its tests with CMS settings too.

This will enable us to better validate certain LibraryContentBlocks behaviors
being touched by https://github.com/openedx/edx-platform/pull/33263 which can't
be expressed under LMS settings.

Also in this commit:

* refactor: rename the shards to be clear whether they're running under LMS or CMS
* docs: correct comments regarding conditions under which codejail's
   test_cant_do_something_forbidden is skipped.
* test: update a unit test which was using the now-deleted library_sourced block to use
   library_content block instead.
2023-10-19 10:19:28 -04:00
Babatunde Olusola
6e2c43e4e0 refactor: update codejail test condition (#32955)
Skip the test for codejail if the codejailservice api is not enabled.
It fixes running this test case in Tutor.
2023-09-07 17:08:30 +02:00
Usama Sadiq
7710e60328 fix: fix middleware get_response parameter deprecation warning (#33067) 2023-08-22 15:52:30 +05:00
Braden MacDonald
9b9b88df52 chore: remove some usages of six (Python2 compat) (#32554)
* get rid of six.text_type(s)
* get rid of six.b()
* get rid of six.string_types
* get rid of six.PY2/six.PY3
* get rid of six.iteritems() and six.viewvalues()
2023-07-17 12:18:43 -07:00
Muhammad Soban Javed
d053bba952 Revert "Revert "refactor: move common/lib/capa/capa to xmodule/capa" (#30762)"
This reverts commit 4463ee751d.
2022-07-27 15:36:08 +05:00
Muhammad Soban Javed
4463ee751d Revert "refactor: move common/lib/capa/capa to xmodule/capa" (#30762) 2022-07-21 18:22:15 +05:00
Soban Javed
9eba9f983a refactor!: move common/lib/capa/capa to xmodule/capa
As part of dissolving our sub-projects in edx-platform, we are moving this package under the xmodule directory.
We have fixed all the occurences of import of this package and also fixed all documents related references.
This might break your platform if you have any reference of `import capa` or `from capa import` in your codebase or in any Xblock.

Ref: https://openedx.atlassian.net/browse/BOM-2582
2022-07-19 12:20:04 +05:00