test(completion): cover the sentence helpers behind 33 surviving mutants - #79
Merged
Merged
Conversation
Targeted from the mutation gate's actual surviving-mutant list for this file
(run 34917215492): 33 missed, and all 33 sit in three private helpers -
find_sentence_start (18), find_sentence_end (13), and the 200-char cap in
extract_reasoning_sentence (2).
Why 33 mutants lived despite 5 existing tests: those tests only reached the
helpers INDIRECTLY, through parse_confidence, and asserted with contains().
Index arithmetic can be wrong by one in either direction and a contains()
check still passes. These call the helpers directly and assert EXACT indices.
completion.rs drops 141 -> 107 lines; the 5 pre-existing tests move verbatim
into completion/tests.rs alongside 16 new ones.
Two of my own expected values were wrong on the first run, and the code was
right both times:
find_sentence_start("one. two.") is 4, not 5 - the trailing '.' has
nothing after it so it is not a boundary, and the inner '. ' at index 3
wins.
find_sentence_start("One\nTwo. Three") is 8, not 9 - the '. ' at index 7 is
later than the newline at 3.
I re-derived both from the algorithm independently before changing the
assertions, rather than editing the numbers until the test went green.
Verified by applying 14 mutants: 14 KILLED. Including both index-arithmetic
families that the old contains()-style tests could never catch:
find_sentence_start -> 0 and -> 1
while i > 0 -> i < 0
newline == -> !=
the '. ' guard && -> ||
i + 1 < len -> <=
return i + 1 -> i - 1
find_sentence_end -> None
Some(offset + i + 1) -> -i / *i / i - 1
the terminator || -> &&
the 200-cap > -> >= and > -> ==
cargo test --lib session::completion passes (21); clippy --all-targets
--all-features -D warnings and cargo fmt --check both exit 0.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Targeted from the mutation gate's actual surviving-mutant list for this file (run 34917215492): 33 missed, and all 33 sit in three private helpers.
find_sentence_startfind_sentence_endextract_reasoning_sentenceWhy 33 mutants lived despite 5 existing tests
The existing tests reached these helpers only indirectly, through
parse_confidence, and asserted withcontains(). Index arithmetic can be wrong by one in either direction and acontains()check still passes.These call the helpers directly and assert exact indices.
completion.rsdrops 141 → 107 lines; the 5 pre-existing tests move verbatim intocompletion/tests.rsalongside 16 new ones.Two of my own expected values were wrong — the code was right
On the first run, two assertions failed. I re-derived both from the algorithm independently rather than editing numbers until the test went green:
"one. two.".has nothing after it so it is not a boundary; the inner". "at index 3 wins"One\nTwo. Three"". "at index 7 is later than the newline at index 3Both are now asserted at the correct value with the reasoning in a comment.
Verification — 14 applied, 14 killed
Including both index-arithmetic families the old
contains()-style tests could never catch:find_sentence_start -> 0/-> 1while i > 0→i < 0==→!=". "guard&&→||i + 1 < len→<=return i + 1→i - 1find_sentence_end -> NoneSome(offset + i + 1)→- i/* i/i - 1||→&&>→>=and>→==The 200-cap pair needs boundary inputs specifically: a string of exactly 200 characters must come back whole (kills
>=), and 201 must be truncated (kills==).cargo test --lib session::completionpasses (21);clippy --all-targets --all-features -- -D warningsandcargo fmt --checkboth exit 0.