semantic_mutants: leave docstrings alone, so their op names are not reported as surviving mutants (OLD-9432) #660

Merged
leonida/mandy
qhukz13 merged 3 commits from cont/semantic-mutants-docstrings into main 2026-11-24 16:06:18 +00:00

Pull request successfully merged and closed

qhukz13 commented 2026-11-24 11:13:41 +00:00

Claimed in the coordination issue as: OLD-9432 (restoration of ItsNotRexed/Leonida#9432, closed unmerged when that repository went private)

mutants_for treated any line starting with a quote as code (meant for f"... OpIAdd ..." emit lines), so a docstring naming an opcode produced mutants that can never fail a test and were always reported SURVIVED: --function nminmax_f32 listed 5 mutants, 4 of them in its docstring, and 47 across rdna2spirv.py.

  • Tokenize the mutated range and skip strings that stand alone as a statement; a range that does not tokenize keeps the old behaviour.
  • A --lines range that starts inside a docstring is widened to the whole string (from review on the original PR: --lines 595-595 inside u16_half's docstring was mutated as code). Every one of the translator's 1,049 docstring lines now gives 0 mutants as a one-line range.

Tested: python -I tests/test_semantic_mutants.py (13 tests OK) on main 21625bca8, Linux, CPU only; no GPU needed. No game files.

AI-assisted (Claude Code).

🤖 Generated with Claude Code

Claimed in the coordination issue as: OLD-9432 (restoration of ItsNotRexed/Leonida#9432, closed unmerged when that repository went private) `mutants_for` treated any line starting with a quote as code (meant for `f"... OpIAdd ..."` emit lines), so a docstring naming an opcode produced mutants that can never fail a test and were always reported SURVIVED: `--function nminmax_f32` listed 5 mutants, 4 of them in its docstring, and 47 across `rdna2spirv.py`. - Tokenize the mutated range and skip strings that stand alone as a statement; a range that does not tokenize keeps the old behaviour. - A `--lines` range that starts inside a docstring is widened to the whole string (from review on the original PR: `--lines 595-595` inside `u16_half`'s docstring was mutated as code). Every one of the translator's 1,049 docstring lines now gives 0 mutants as a one-line range. Tested: `python -I tests/test_semantic_mutants.py` (13 tests OK) on `main` 21625bca8, Linux, CPU only; no GPU needed. No game files. AI-assisted (Claude Code). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
lixonik reviewed 2026-11-24 11:53:24 +00:00
lixonik left a comment
No description provided.
Independent CLI check at `e3c4d0c1` with synthetic Python sources and `--lines N-N --list`. A one-line range inside an ordinary multiline docstring yields zero mutants. Adding a preceding comment containing `"""` makes the equivalent range yield one mutant, `OpIAdd` to `OpISub`. An implicitly concatenated first-statement docstring also yields one mutant: `"OpIAdd is an example. " "Emit an instruction."`. Python's `ast.get_docstring()` recognizes both variants. The first appears to come from counting delimiters in raw lines and the second from treating adjacent string tokens as separate statements. A scan of the checked-in translator's docstrings found zero mutants, so these are synthetic coverage cases. Could both be added to the regression tests? [Relevant logic](https://github.com/ubiquitarianism/leonida/blob/e3c4d0c1f6c282f8587b8cea6637d4ff7db96810/tools/semantic_mutants.py#L151-L186) AI-assisted testing. No game data or GPU used.
GeorgiyDemo commented 2026-11-24 13:03:49 +00:00

Ran e3c4d0c1f on Apple M5 Pro, macOS 26.7.3 (25G342), Python 3.15.2, against main d42773d07:

  • tests/test_semantic_mutants.py: 13 tests OK at this head.
  • The same file against main's tools/semantic_mutants.py fails 5 of 13, so the docstring handling is covered by the new cases.

No GPU leg (CPU tool). AI-assisted.

Ran `e3c4d0c1f` on Apple M5 Pro, macOS 26.7.3 (25G342), Python 3.15.2, against `main` `d42773d07`: - `tests/test_semantic_mutants.py`: 13 tests OK at this head. - The same file against `main`'s `tools/semantic_mutants.py` fails 5 of 13, so the docstring handling is covered by the new cases. No GPU leg (CPU tool). AI-assisted.
qhukz13 commented 2026-11-24 13:13:16 +00:00

Thanks — both reproduced and fixed in 4a5458b05:

  • A """ in a comment no longer counts as a delimiter: string_context now follows triple quotes with a small scanner that skips comments, one-line strings and escaped delimiters, instead of counting them in raw lines.
  • Adjacent literals are one docstring: docstring_lines takes a run of string tokens that ends the statement ("OpIAdd is an example. " "Emit an instruction."). A literal the code goes on to read (("..." "...") and self.emit(...)) stays code and is still mutated.

Both cases are in test_docstring_after_a_comment_with_quotes_and_concatenated_docstring, plus the stays-code one; it fails on e3c4d0c1f and passes now. tests/test_semantic_mutants.py: 14 tests OK. #734, which builds on this branch, is rebased on it (20 tests OK).

Thanks — both reproduced and fixed in 4a5458b05: - A `"""` in a comment no longer counts as a delimiter: `string_context` now follows triple quotes with a small scanner that skips comments, one-line strings and escaped delimiters, instead of counting them in raw lines. - Adjacent literals are one docstring: `docstring_lines` takes a run of string tokens that ends the statement (`"OpIAdd is an example. " "Emit an instruction."`). A literal the code goes on to read (`("..." "...") and self.emit(...)`) stays code and is still mutated. Both cases are in `test_docstring_after_a_comment_with_quotes_and_concatenated_docstring`, plus the stays-code one; it fails on e3c4d0c1f and passes now. `tests/test_semantic_mutants.py`: 14 tests OK. #734, which builds on this branch, is rebased on it (20 tests OK).
lixonik commented 2026-11-24 13:35:44 +00:00

Thanks for the fix. I independently retested 4a5458b05 from a full Git checkout on Windows. The new regression test covering the quote-in-comment case, the concatenated docstring, and the expression that should remain mutable passes. The full python -I -B tests/test_semantic_mutants.py -v run passed all 14 tests.

AI-assisted testing with synthetic inputs. No game data or GPU used.

Thanks for the fix. I independently retested `4a5458b05` from a full Git checkout on Windows. The new regression test covering the quote-in-comment case, the concatenated docstring, and the expression that should remain mutable passes. The full `python -I -B tests/test_semantic_mutants.py -v` run passed all 14 tests. AI-assisted testing with synthetic inputs. No game data or GPU used.
Sign in to join this conversation.
No description provided.