Skip to content

test(completion): cover the sentence helpers behind 33 surviving mutants - #79

Merged
acamarata merged 1 commit into
mainfrom
test/completion-coverage
Sep 15, 2026
Merged

acamarata merged 1 commit into
mainfrom
test/completion-coverage

Conversation

@acamarata

Copy link
Copy Markdown
Contributor

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.

function missed mutants
find_sentence_start 18
find_sentence_end 13
the 200-char cap in extract_reasoning_sentence 2

Why 33 mutants lived despite 5 existing tests

The existing tests reached these helpers only 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 — 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:

input I wrote correct why
"one. two." 5 4 the trailing . has nothing after it so it is not a boundary; the inner ". " at index 3 wins
"One\nTwo. Three" 9 8 the ". " at index 7 is later than the newline at index 3

Both 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:

Mutant Result
find_sentence_start -> 0 / -> 1 KILLED
while i > 0i < 0 KILLED
newline ==!= KILLED
the ". " guard &&|| KILLED
i + 1 < len<= KILLED
return i + 1i - 1 KILLED
find_sentence_end -> None KILLED
Some(offset + i + 1)- i / * i / i - 1 KILLED
terminator ||&& KILLED
200-cap >>= and >== KILLED

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::completion passes (21); clippy --all-targets --all-features -- -D warnings and cargo fmt --check both exit 0.

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.
@acamarata
acamarata merged commit 46841b5 into main Sep 15, 2026
12 checks passed
@acamarata
acamarata deleted the test/completion-coverage branch September 15, 2026 23:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant