This PR supports running all existing tests in WebAssembly. I am keeping the use of an "allow list" of test files to run in conftest_wasm.py so that new test files added are not automatically included as I don't fully trust the work flow yet.
The tests run and pass locally for me (with some flakiness, see later). I have also added a CI run test-wasm which will only run on demand rather than automatically.
One change to existing tests is to change the code to read the contents of a file from the form with open(file) as f to the form pathlib.Path.read_text() as the latter is easier to monkeypatch to run in the browser as it is a single atomic action rather than opening a stream to access file contents. It would be good to adopt this approach for future tests too, when they are added.
There are two classes of problem observed:
Some git2cpp commands on error return the expected error text on stderr but have an exit code of zero, which is incorrect. This must be due to some WebAssembly build problem, and is important to fix soon. These specific checks are currently skipped in the WebAssembly tests.
There is some flakiness with failures reported as "bad packet length". This is an incorrect error description and is pretty much a catch-all for any error trying to contact a remote repo. This I will improve/fix in the work I am doing to better patch the WebAssembly build of libgit2 for remote access.
Example local test run output:
$ make test
================================================================= test session starts =================================================================
platform darwin -- Python 3.14.2, pytest-9.0.2, pluggy-1.6.0 -- /Users/iant/micromamba/envs/git2cpp-wasm/bin/python3.14
cachedir: .pytest_cache
rootdir: /Users/iant/github/git2cpp
configfile: .pytest.ini
plugins: anyio-4.12.1, playwright-0.7.2, base-url-2.1.0
collected 102 items
test_add.py::test_add[chromium-] PASSED [ 0%]
test_add.py::test_add_nogit[chromium] PASSED [ 1%]
test_branch.py::test_branch_list[chromium] PASSED [ 2%]
<snip>
test_status.py::test_status_new_file[chromium---long---short] PASSED [ 99%]
test_status.py::test_status_add_file[chromium---long---short] PASSED [100%]
======================================================================= PASSES ========================================================================
=========================================================== 102 passed in 158.10s (0:02:38) ===========================================================
Built target test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR supports running all existing tests in WebAssembly. I am keeping the use of an "allow list" of test files to run in conftest_wasm.py so that new test files added are not automatically included as I don't fully trust the work flow yet.
The tests run and pass locally for me (with some flakiness, see later). I have also added a CI run test-wasm which will only run on demand rather than automatically.
One change to existing tests is to change the code to read the contents of a file from the form with open(file) as f to the form pathlib.Path.read_text() as the latter is easier to monkeypatch to run in the browser as it is a single atomic action rather than opening a stream to access file contents. It would be good to adopt this approach for future tests too, when they are added.
There are two classes of problem observed:
Example local test run output: