Skip to content

Add test coverage for pure modules + fix FTS and reranker bugs#10

Merged
chatman-media merged 8 commits into
mainfrom
claude/eager-visvesvaraya-2c47f6
May 17, 2026
Merged

Add test coverage for pure modules + fix FTS and reranker bugs#10
chatman-media merged 8 commits into
mainfrom
claude/eager-visvesvaraya-2c47f6

Conversation

@chatman-media

Copy link
Copy Markdown
Owner

Summary

Расширяет покрытие тестами непокрытых чистых функций и исправляет два реальных бага, найденных при написании тестов.

Фиксы:

  • sanitizeFtsQuery убирал булевы ключевые слова (AND/OR/NOT/NEAR) только когда они окружены пробелами с обеих сторон — ведущее/замыкающее ключевое слово протекало как поисковый токен (OR "injection"OR:* | injection:*). Теперь фильтруются на этапе токенизации, в любой позиции, как и описано в docstring.
  • CohereReranker / JinaReranker маппили результат API через ...(hits[index] as KbSearchHit). Каст маскировал undefined от noUncheckedIndexedAccess, и индекс вне диапазона давал «битый» хит без chunk_id/text. Теперь такие результаты отбрасываются.

Тесты: новые файлы для utils.ts (RRF + FTS), text-style-rules.ts, rewrite-query.ts, grade-skills.ts, reranker.ts. Всего тестов: 91 → 148.

Прочее: удалён мёртвый biome-ignore в answer-types.ts.

Test plan

  • bun test — 148 pass, 0 fail
  • bun run typecheck — без ошибок
  • bun run check — без ошибок (warning из answer-types.ts устранён)
  • CI зелёный на PR

🤖 Generated with Claude Code

chatman-media and others added 8 commits May 18, 2026 02:37
The previous regex only removed AND/OR/NOT/NEAR when surrounded by
whitespace on both sides, so a leading or trailing keyword leaked through
as a search token (`OR "injection"` became `OR:* | injection:*` instead
of `injection:*`). Filter keywords at the token stage so they are
dropped consistently regardless of position, matching the documented
behavior.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Add unit tests for src/utils.ts: reciprocalRankFusion (list fusion,
cross-list rank boost, k truncation, empty-list early returns, rrfK
sensitivity, distance remap) and sanitizeFtsQuery (prefix-OR form,
short-token drop, operator/keyword stripping, empty-input handling).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Add unit tests for src/text-style-rules.ts: each individual rule (dash
and ellipsis normalization, AI lead-in stripping, first-letter
capitalization, markdown bold/italic/code/header/link stripping), the
idempotency invariant required of every rule, and applyStyleRules
ordering and rule threading.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Add unit tests for the pure exports of src/rewrite-query.ts:
questionNeedsRewrite (empty input, no-history, short follow-ups, deictic
markers, leading conjunctions, long self-contained questions) and
sanitizeRewritten (think-tag and code-fence stripping, answer-prefix
removal, first-line selection, maxLength truncation, fallback on empty
output).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Add unit tests for parseSlugList in src/grade-skills.ts: bare JSON
array, code-fenced JSON, comma/newline-separated plain text,
allowed-list filtering, empty input, empty array, and non-string
element rejection.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
CohereReranker and JinaReranker mapped each API result with
`...(hits[index] as KbSearchHit)`. The cast masked an `undefined` from
`noUncheckedIndexedAccess`, so an index outside the input range produced
a malformed hit carrying only `distance` — no `chunk_id`, `text`, or
other KB fields. Switch to `flatMap` and drop results whose index has no
corresponding hit. Adds test/reranker.test.ts covering both rerankers
via a mocked fetch.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
The biome-ignore above `outputSchema` no longer suppresses anything —
the field is typed `z.ZodTypeAny`, not an explicit `any` — and biome
flagged the comment itself as having no effect.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented May 17, 2026

Copy link
Copy Markdown

Warning

Rate limit exceeded

@chatman-media has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 16 minutes and 55 seconds before requesting another review.

You’ve run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 0e2c3422-b738-42be-aa1f-3c0febbf240e

📥 Commits

Reviewing files that changed from the base of the PR and between 6871619 and 62cab54.

📒 Files selected for processing (8)
  • src/answer-types.ts
  • src/reranker.ts
  • src/utils.ts
  • test/grade-skills.test.ts
  • test/reranker.test.ts
  • test/rewrite-query.test.ts
  • test/text-style-rules.test.ts
  • test/utils.test.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/eager-visvesvaraya-2c47f6

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@chatman-media chatman-media merged commit cfa39d4 into main May 17, 2026
4 checks passed
@github-actions

Copy link
Copy Markdown

🎉 This PR is included in version 1.2.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant