tests: add edge-case tests for cfg_structure single-block, irreducible, and nested loops #542

Open
github-bot wants to merge 1 commit from github-bot/gh-542 into main AGit
Owner

@⁠kotekompotek on GitHub · 2026-11-24 07:17 UTC · original
kotekompotek:work/test-cfg-structure-extra → main · +61 −0 · 1 files · 1 commits · open

Claimed in the coordination issue as: coordination issue #14

What and why

  • Rebased onto current main and squashed into one clean commit.
  • Added edge-case tests for tools/cfg_structure.py in tests/test_cfg_structure_extra.py.

Tested

  • python -m pytest tests/test_cfg_structure_extra.py passed after rebasing onto current main.

GPUs tested: n/a

AI-assisted: yes

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed.
**@⁠kotekompotek** on GitHub · 2026-11-24 07:17 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/542) `kotekompotek:work/test-cfg-structure-extra` → `main` · +61 −0 · 1 files · 1 commits · open Claimed in the coordination issue as: coordination issue #14 ### What and why - Rebased onto current `main` and squashed into one clean commit. - Added edge-case tests for `tools/cfg_structure.py` in `tests/test_cfg_structure_extra.py`. ### Tested - `python -m pytest tests/test_cfg_structure_extra.py` passed after rebasing onto current `main`. GPUs tested: n/a AI-assisted: yes ### Checklist - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [ ] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:07:30 +00:00
Author
Owner

@⁠kawaii-shakal on GitHub · 2026-11-24 07:55 UTC · original

Reviewed head 05a43014a34826b02bbfb71820676a705f0dcfac (AI-assisted review). Environment: Linux (WSL2), Python venv with pytest, no GPU.

What ran: python -m pytest tests/test_cfg_structure_extra.py: 3 passed. For comparison, I ran each mutation against tests/test_cfg_structure.py too.

Mutations to tools/cfg_structure.py (extra file / existing file):

  • irreducibility check removed (if False:): caught / caught
  • inner[x] = h (outermost loop wins instead of innermost): caught by the nested-loop test / caught
  • region children emitted in reverse order: missed / caught
  • max_guard_depth = 0: missed / missed (does not change behaviour on these shapes)

Findings:

  • test_single_block_cfg duplicates test_shapes, which already asserts S.structure([[]]) == [("block", 0)]. test_irreducible_two_entry_loop_returns_none is the existing two-entry-loop case ([[1, 2], [2], [1]]) plus an exit block, and test_random_graphs also checks thousands of irreducible graphs against an independent T1/T2 test. Only the nested-loop-with-early-exit test adds a new shape.
  • _run_tree is a second tree interpreter, and its loop semantics differ from S.run: it checks pc == hdr before the first iteration, while S.run runs the body once first. The two agree here only because a loop is always entered with pc at its header. It would be simpler and closer to the code under test to use S.run(tree, step, limit), or the existing walk and chooser helpers in test_cfg_structure.py to compare against the plain graph walk.
  • The extra file runs only under pytest (no __main__ block), unlike test_cfg_structure.py, which runs with python -I.

Not tested: split_irreducible (the PR does not touch it).


Review written by Claude (Claude Code, Opus 5.5), an AI agent, posted from a contributor's account.

**@⁠kawaii-shakal** on GitHub · 2026-11-24 07:55 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/542#issuecomment-7125522049) Reviewed head 05a43014a34826b02bbfb71820676a705f0dcfac (AI-assisted review). Environment: Linux (WSL2), Python venv with pytest, no GPU. What ran: `python -m pytest tests/test_cfg_structure_extra.py`: 3 passed. For comparison, I ran each mutation against `tests/test_cfg_structure.py` too. Mutations to `tools/cfg_structure.py` (extra file / existing file): - irreducibility check removed (`if False:`): caught / caught - `inner[x] = h` (outermost loop wins instead of innermost): caught by the nested-loop test / caught - region children emitted in reverse order: **missed** / caught - `max_guard_depth = 0`: missed / missed (does not change behaviour on these shapes) Findings: - `test_single_block_cfg` duplicates `test_shapes`, which already asserts `S.structure([[]]) == [("block", 0)]`. `test_irreducible_two_entry_loop_returns_none` is the existing two-entry-loop case (`[[1, 2], [2], [1]]`) plus an exit block, and `test_random_graphs` also checks thousands of irreducible graphs against an independent T1/T2 test. Only the nested-loop-with-early-exit test adds a new shape. - `_run_tree` is a second tree interpreter, and its loop semantics differ from `S.run`: it checks `pc == hdr` before the first iteration, while `S.run` runs the body once first. The two agree here only because a loop is always entered with pc at its header. It would be simpler and closer to the code under test to use `S.run(tree, step, limit)`, or the existing `walk` and `chooser` helpers in `test_cfg_structure.py` to compare against the plain graph walk. - The extra file runs only under pytest (no `__main__` block), unlike `test_cfg_structure.py`, which runs with `python -I`. Not tested: `split_irreducible` (the PR does not touch it). --- _Review written by Claude (Claude Code, Opus 5.5), an AI agent, posted from a contributor's account._
Author
Owner

@⁠kawaii-shakal on GitHub · 2026-11-24 14:47 UTC · original

Re-checked head 75f5c355c7bc3ad86be17f60dbcccc818564717c. Environment: Windows 11, native Python 3.13, no pytest, no GPU.

What ran:

  • python -I tests/test_cfg_structure_extra.py: passes (exit 0).
  • python -I tests/test_cfg_structure.py: ok: 18228 graphs structured and run ....
  • python -I scripts/check_no_game_data.py tests/test_cfg_structure_extra.py: exit 0.
  • Mutation: region children emitted in reverse order (sorted(children[m], key=..., reverse=True) in structure). test_sibling_order_diamond_then_tail_executes_every_branch now fails on it with an AssertionError. The existing test_cfg_structure.py also still fails. Reverted afterwards.
  • Merges cleanly into current main (f3e26be7c).

Earlier remarks:

  • Reverse sibling order missed: resolved. The new diamond-then-tail test catches it.
  • Duplicate single-block and two-entry irreducible tests: resolved. Both are removed, and the file keeps only the nested-loop-with-early-exit case and the new sibling-order case.
  • Second tree interpreter _run_tree: resolved. Both tests now use cfg_structure.run.
  • No __main__ block: resolved. The file runs with python -I.

No further changes requested from me.

AI-assisted.

**@⁠kawaii-shakal** on GitHub · 2026-11-24 14:47 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/542#issuecomment-7134961841) Re-checked head 75f5c355c7bc3ad86be17f60dbcccc818564717c. Environment: Windows 11, native Python 3.13, no pytest, no GPU. What ran: - `python -I tests/test_cfg_structure_extra.py`: passes (exit 0). - `python -I tests/test_cfg_structure.py`: `ok: 18228 graphs structured and run ...`. - `python -I scripts/check_no_game_data.py tests/test_cfg_structure_extra.py`: exit 0. - Mutation: region children emitted in reverse order (`sorted(children[m], key=..., reverse=True)` in `structure`). `test_sibling_order_diamond_then_tail_executes_every_branch` now fails on it with an AssertionError. The existing `test_cfg_structure.py` also still fails. Reverted afterwards. - Merges cleanly into current main (f3e26be7c). Earlier remarks: - Reverse sibling order missed: resolved. The new diamond-then-tail test catches it. - Duplicate single-block and two-entry irreducible tests: resolved. Both are removed, and the file keeps only the nested-loop-with-early-exit case and the new sibling-order case. - Second tree interpreter `_run_tree`: resolved. Both tests now use `cfg_structure.run`. - No `__main__` block: resolved. The file runs with `python -I`. No further changes requested from me. AI-assisted.
Author
Owner

@⁠kotekompotek on GitHub · 2026-11-25 08:58 UTC · original

Rebased on current ubi/main (3f81d46ac), no conflicts. The added tests pass locally on this base (python -I).

AI-assisted: yes

**@⁠kotekompotek** on GitHub · 2026-11-25 08:58 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/542#issuecomment-7157710261) Rebased on current ubi/main (3f81d46ac), no conflicts. The added tests pass locally on this base (python -I). AI-assisted: yes
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/542/head:github-bot/gh-542'
git switch 'github-bot/gh-542'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-542'
git switch 'github-bot/gh-542'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-542'
git switch 'github-bot/gh-542'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-542'
git switch 'main'
git merge --squash 'github-bot/gh-542'
git switch 'main'
git merge --ff-only 'github-bot/gh-542'
git switch 'main'
git merge 'github-bot/gh-542'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.