Skip to content

Test: Fuzz commit, comment and config parsers - #561

Merged
ModeSevenIndustrialSolutions merged 5 commits into
lfreleng-actions:mainfrom
lfreleng-bot-forks:code-monkey/issue-560
Nov 20, 2026
Merged

ModeSevenIndustrialSolutions merged 5 commits into
lfreleng-actions:mainfrom
lfreleng-bot-forks:code-monkey/issue-560

Conversation

@lf-releng-code-monkey-bot

@lf-releng-code-monkey-bot lf-releng-code-monkey-bot Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Closes #560

Authored by an AI agent; human review required
Command Exit
uv run --frozen pytest -q --no-cov tests/test_fuzz_replay.py 0
python (mutation check: _MENTION_RE patched to never match; old checks pass, new check fails 17 seeds) 0
uv run --frozen --with atheris python tests/fuzzing/fuzz_reconciliation_text.py -max_total_time=65 (before oracle fix: found oracle bug) 77
uv run --frozen --with atheris python tests/fuzzing/fuzz_reconciliation_text.py crash-f3e466756a33... 0
uv run --frozen --with atheris python tests/fuzzing/fuzz_reconciliation_text.py -max_total_time=65 0
uv run --frozen ruff check tests/fuzzing/ tests/test_fuzz_replay.py 0
AISLOP_NO_TELEMETRY=1 prek run --files tests/fuzzing/fuzz_reconciliation_text.py tests/test_fuzz_replay.py 0
uv run --frozen pytest -q 0
git log --raw --format=%h ccb245f..HEAD (no mode changes) 0

The github-code-monkey-bot workflow opened this pull request.
Nobody has merged it; a maintainer must review it first.
Review findings on this pull request are answered by a later revision round of this workflow, up to ten rounds per antagonistic review round; after that a maintainer, or the next antagonistic review, takes on any finding that remains, and a maintainer reviews every round before merge.

Round 3 of revision, on its base.


Adds three Atheris fuzz harnesses under tests/fuzzing/ for the parsers that read text this tool does not control (#560), plus four fixes for contract breaches the harnesses found, each in its own commit with a regression test and a seed:

  • Fix(commit_rules): parse_commit_rules_json returns None for any bad JSON.
  • Fix(gitreview): an oversized port is treated as absent.
  • Fix(mapping): the mapping block is read between its markers.
  • Fix(netrc): escapes are honoured when stripping comments.
  • Test: the harnesses (fuzz_reconciliation_text.py, fuzz_gerrit_text.py, fuzz_config_files.py), the shared runner, tests/test_fuzz_replay.py (replays every seed and feeds each oracle a wrong result), and a Fuzzing section in docs/development.md.

import atheris appears only inside each harness's main(). No workflow, dependency, lock file or hook configuration changes.

This round (3)

Copilot found that the PR command checks took parse_commands as truth, although contains_directive shares its mention matcher and find_open_command delegates to it. A matcher that stopped recognising mentions would still pass. I confirmed that: with _MENTION_RE patched to match nothing, every seed passed the old checks. Now comment_from builds a comment from the fuzz bytes. It plants registered phrases (random case, blank runs between words, word-boundary tails) and word-stem decoys among filler lines that hold no @. verify_planted_commands requires each reader to return exactly what was planted. With the matcher broken, 17 seeds now fail. I added three byte seeds and three replay cases: a dropped directive, an obeyed decoy, and an older check winning.

The first fuzz run of the new check found an oracle bug, not a production one: string.punctuation includes _, which continues a word. The tail alphabet now leaves it out.

Validation

  • prek run --files <changed files>: pass (ruff, mypy, basedpyright, reuse, aislop, pytest)
  • uv run pytest: pass, coverage 76.77%
  • fuzz_reconciliation_text.py -max_total_time=65: 189,559 runs in 66 s, nothing found after the oracle fix
  • Round 2 fuzzed fuzz_gerrit_text.py and fuzz_config_files.py for 65 s each (30k–144k runs) and found nothing. Neither changed this round.

For the reviewer

The planted-comment oracle reads COMMAND_REGISTRY for the phrases it plants. If someone later registers a phrase that is a prefix of another command's phrase, it would need revisiting.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Fuzzing harnesses remain undiscoverable by the central job and Scorecard, and the trailer-removal oracle accepts deleted body text while missing ordering and duplicate-line errors.

2 open issues
What changed in this PR

Adds fuzz testing for the text and configuration parsers used when transferring GitHub pull requests to Gerrit, addressing #560.

Changes:

  • Adds three Atheris harnesses, seed replay tests, and checks that deliberately incorrect results are rejected.
  • Fixes parser failures involving oversized JSON integers and ports, mapping markers and digests, and escaped netrc values.
  • Documents local fuzzing without adding dependencies or workflows.
File Description
tests/​test_netrc.py Covers inline comments after escaped backslashes.
tests/​test_mapping_comment_additional.py Covers malformed mapping markers and digest preservation.
tests/​test_gitreview.py Tests oversized-port fallback on both parsing paths.
tests/​test_fuzz_replay.py Replays seeds and checks rejection of incorrect results.
tests/​test_commit_rules.py Covers oversized integers and deeply nested JSON.
tests/​fuzzing/​fuzz_reconciliation_text.py Fuzzes trailers, mapping comments, and PR commands.
tests/​fuzzing/​fuzz_gerrit_text.py Fuzzes comment cleaning, body filtering, and normalization.
tests/​fuzzing/​fuzz_config_files.py Fuzzes gitreview, netrc, and commit-rule parsing.
tests/​fuzzing/​_runner.py Provides shared byte decoding, contract assertions, and fuzz execution.
tests/​fuzzing/​__init__.py Introduces the importable fuzz harness package.
src/​github2gerrit/​netrc.py Handles escaped characters when stripping inline comments.
src/​github2gerrit/​mapping_comment.py Shares mapping-block detection and preserves updated digests.
src/​github2gerrit/​gitreview.py Treats integer-conversion failures as absent ports.
src/​github2gerrit/​commit_rules.py Handles additional JSON decoding failures.
docs/​development.md Documents harness coverage, execution, and seed replay.

Review effort: Balanced

Comment thread tests/fuzzing/_runner.py Resolved
Comment thread tests/fuzzing/fuzz_gerrit_text.py Resolved

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The fuzz oracle’s casefold() normalization disagrees with production re.IGNORECASE behavior for Unicode characters, causing false crash reports.

1 open issue

Review effort: Balanced

Comment thread tests/fuzzing/fuzz_gerrit_text.py Resolved

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The fuzz checks rely on a shared mention matcher rather than an independent oracle, allowing dropped valid directives to pass undetected and leaving #560’s requirement unmet.

1 open issue

Review effort: Balanced

lf-releng-code-monkey-bot Bot and others added 5 commits November 19, 2026 18:23
parse_commit_rules_json documents that it returns None for unparsable
input and raises nothing. It caught only JSONDecodeError, but json.loads
also raises a bare ValueError for an integer longer than the interpreter
digit limit and RecursionError for deeply nested arrays or objects.
Either escaped into the commit message builder. Catch both, and add a
regression test for each input.

Found while writing the config file fuzz harness.

Co-authored-by: Copilot <[email protected]>
Signed-off-by: lf-releng-code-monkey-bot[bot] <332050256+lf-releng-code-monkey-bot[bot]@users.noreply.github.com>
parse_gitreview documents that it returns a GitReviewInfo or None. A
port= value of more digits than sys.get_int_max_str_digits() passed the
digit pattern and then made int() raise ValueError, which escaped every
caller of the parser, including the reader of a .gitreview fetched from
the pull request's repository. Such a value names no port, so read it
as absent: the default port, with port_given false.

Found while writing the config file fuzz harness.

Co-authored-by: Copilot <[email protected]>
Signed-off-by: lf-releng-code-monkey-bot[bot] <332050256+lf-releng-code-monkey-bot[bot]@users.noreply.github.com>
update_mapping_comment_body documents that it replaces the existing
mapping with the new one, but a body it returned did not always parse
back to that mapping:

- It dropped the mapping's digest, which the caller in core sets from
  the reconciliation plan, so an updated comment lost it.
- It and parse_mapping_comments paired the first start marker with the
  first end marker anywhere in the body. A stray end marker before the
  block made parse_mapping_comments skip a valid mapping, and an
  unterminated block before it leaked its Change-Ids into the result.

Locate a block as the last start marker before the first end marker
that follows a start marker, in both functions, and pass the digest
through. Regression tests cover each input.

Found while writing the reconciliation text fuzz harness.

Co-authored-by: Copilot <[email protected]>
Signed-off-by: lf-releng-code-monkey-bot[bot] <332050256+lf-releng-code-monkey-bot[bot]@users.noreply.github.com>
NetrcParser reads quoted strings with backslash escapes, but the inline
comment stripper treated any quote preceded by a backslash as escaped.
For a value ending in an escaped backslash, such as "pa\\", it never saw
the closing quote, kept the rest of the line, and read a comment's words
as tokens: '# login attacker' replaced the entry's login.

Track escapes inside quoted strings the way the tokenizer does, so the
quote closes and the comment is dropped. A regression test covers the
input.

Found while writing the config file fuzz harness.

Co-authored-by: Copilot <[email protected]>
Signed-off-by: lf-releng-code-monkey-bot[bot] <332050256+lf-releng-code-monkey-bot[bot]@users.noreply.github.com>
Add three Atheris harnesses under tests/fuzzing for the parsers that
read text this tool does not control: commit trailers, the Change-Id
mapping comment and PR commands; comment sanitising, PR body
filtering and similarity normalisers; and .gitreview, .netrc and
COMMIT_RULES_JSON. Each harness checks the contracts its docstring
quotes, through round trips of generated input and through the
documented agreement between readers, rather than only catching
exceptions.

Each harness imports Atheris inside its main(), the line Scorecard
and the organisation's fuzzing job discover a harness by, and passes
the module to the shared runner, which holds no such line. The
harnesses and tests/test_fuzz_replay.py therefore work without it.
The replay test runs every seed through the same checks in the
normal suite and feeds each oracle a wrong result to show it rejects
one. The seeds include an input for each defect fixed earlier on
this branch; each one fails against the code before its fix.

docs/development.md says what is fuzzed and how to run a harness.

Review round 1:
- No .py file held the literal "import atheris": the runner imported
  it through importlib, so no harness was discoverable. Fixed as
  above.
- The remove_commit_trailers oracle compared line sets, so deleting
  the whole body, reordering lines or dropping a duplicate passed.
  It now compares the exact expected output, built from the input's
  non-trailer lines in order, and the replay test covers all three.

Review round 2:
- The remove_commit_trailers oracle used casefold(), which differs
  from the re.IGNORECASE match production uses: it folds "ß" to "ss"
  and leaves the dotless and dotted i unmatched, so it reported false
  failures. It now maps only the four non-ASCII letters the re
  documentation names, and a seed covers both directions.
- Rebased onto main, which moved the trailer boundary rule into
  trailers.find_trailer_boundary and dropped
  Orchestrator._find_trailer_boundary; the harness imported the old
  name, so the merged tree failed pytest and mypy. Since gitutils and
  the builder now share that rule, the oracle derives the expected
  boundary from the raw lines instead of comparing them.

Review round 3:
- The PR command checks took parse_commands as the expected answer,
  but contains_directive shares its mention matcher and
  find_open_command delegates to it, so a matcher that stopped
  recognising mentions still passed. comment_from now builds a
  comment from the fuzz bytes, planting directives and word-stem
  decoys among lines with no mention, and every reader must find
  exactly what was planted. New seeds plant directives, and the
  replay test rejects a dropped directive, an obeyed decoy and an
  older check winning.

Co-authored-by: Copilot <[email protected]>
Signed-off-by: lf-releng-code-monkey-bot[bot] <332050256+lf-releng-code-monkey-bot[bot]@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues remain for the parser-hardening and fuzz-testing changes.

No open issues 🎉

Review effort: Balanced

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 Antagonistic review by agent: no line-level findings; the summary below is the verdict.

The parser fixes and fuzz harnesses appear sound on static review. No actionable defects were found in the diff or its interactions with existing callers.

Antagonistic round 1 of 3.


Automated antagonistic review by lf-releng-antagonistic-review-bot[bot] using model gpt-6-astra; see the run. This is not a human review and never an approval: a maintainer must still review and approve this pull request.

@ModeSevenIndustrialSolutions
ModeSevenIndustrialSolutions merged commit b866dbf into lfreleng-actions:main Nov 20, 2026
33 checks passed
@ModeSevenIndustrialSolutions
ModeSevenIndustrialSolutions deleted the code-monkey/issue-560 branch November 20, 2026 01:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

code-quality Updates to code-quality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Test: Fuzz the commit and comment parsers

2 participants