Skip to content

fix(chunker): heading duplication + multibyte infinite loop; 40 mutation-killing tests (50%→97%) - #1024

Merged
ajianaz merged 1 commit into
developfrom
fix/chunker-mutation-hardening
Aug 14, 2026
Merged

ajianaz merged 1 commit into
developfrom
fix/chunker-mutation-hardening

Conversation

@ajianaz

@ajianaz ajianaz commented Aug 14, 2026

Copy link
Copy Markdown
Collaborator

What

Mutation testing hardening for chunker.rs — plus two production bug fixes the process uncovered.

Why

chunker.rs baseline mutation score was 50% (68/163 missed) — the test suite could not detect real logic regressions. Mutation testing exposed two genuine production bugs as proof the gaps were real, not theoretical.

Changes

  • Fix 1 — heading duplication: oversized markdown sections had their heading prepended twice in the first sub-chunk (once by split_by_headings, once more by the sub-chunk loop), corrupting downstream embeddings. Removed the dead heading_prefix re-prepend path entirely.
  • Fix 2 — multibyte infinite loop: split_long_text's zero-progress guard advanced by raw byte offsets that could land inside multi-byte UTF-8 characters (CJK/emoji), flooring back to start forever. chunk_markdown("日本語", 2) would hang. Fixed with a proper forward-char-boundary advance.
  • 40 new mutation-killing tests (chunker: 20 → 60 tests) — exact numeric assertions per the pattern in docs/mutation-testing.md
  • cargo-mutants config moved to .cargo/mutants.toml (v27 schema: exclude_globs/exclude_re, valid keys only). Previous config at crates/uteke-core/mutants.toml was silently never read (invalid key exclude_files → defaults). Glob paths fixed to match from workspace root; CLI update_check also excluded.
  • 3 proven-equivalent mutants excluded with documented reasoning in config comments
  • docs/mutation-testing.md: final scores table, production bug postmortem, timeout/equivalent mutant notes

Testing

  • Full workspace: 538 tests passed, 0 failed
  • Final verify run (35 min): 164 mutants — 149 caught, 0 missed, 5 timeout (infinite-loop mutants, accepted), 10 unviable → effective score 97% (was 50%)
  • Both bug fixes covered by regression tests (test_md_subchunk_no_heading_duplication, test_split_long_text_multibyte_tiny_limit)
  • Clippy clean, fmt clean, cora review clean (pre-commit hooks passed)

Note: mutants output dirs are gitignored local artifacts; ~40 MB of stale run outputs cleaned from disk.

…ion-killing tests (score 50%→97%)

Two production bugs found by mutation testing:

1. Heading duplication: oversized markdown sections had their heading
   prepended twice in the first sub-chunk (once by split_by_headings,
   once more by the sub-chunk loop), corrupting downstream embeddings.
   Fixed by removing the dead heading_prefix re-prepend path entirely.

2. Multibyte infinite loop: split_long_text's zero-progress guard
   advanced by raw byte offsets that could land inside multi-byte UTF-8
   characters (CJK/emoji), flooring back to start forever.
   chunk_markdown("日本語", 2) would hang. Fixed with a proper
   forward-char-boundary advance in the guard.

Also:
- 40 new mutation-killing tests (chunker: 20 → 60 tests)
- cargo-mutants config moved to .cargo/mutants.toml (v27 schema:
  exclude_globs/exclude_re, valid keys only); glob paths fixed to
  match from workspace root; CLI update_check also excluded
- 3 proven-equivalent mutants excluded with documented reasoning
- docs/mutation-testing.md: final scores, bug postmortem, timeout notes

Verify run: 164 mutants, 149 caught, 0 missed, 5 timeout, 10 unviable (97%)
@github-actions

Copy link
Copy Markdown

🔍 Cora AI Code Review

✅ No issues found. Code looks good!


Review powered by cora-code · BYOK · MIT

@ajianaz
ajianaz merged commit 5441eab into develop Aug 14, 2026
13 checks passed
@ajianaz
ajianaz deleted the fix/chunker-mutation-hardening branch August 14, 2026 13:15
@ajianaz ajianaz mentioned this pull request Aug 14, 2026