Skip to content

tests: 100% coverage for helpers, fix extract_xml_tag bug#4

Merged
will-fawcett-trillium merged 3 commits intomainfrom
tests/helpers-coverage
Apr 28, 2026
Merged

tests: 100% coverage for helpers, fix extract_xml_tag bug#4
will-fawcett-trillium merged 3 commits intomainfrom
tests/helpers-coverage

Conversation

@will-fawcett
Copy link
Copy Markdown
Collaborator

@will-fawcett will-fawcett commented Apr 28, 2026

Summary

  • Add unit tests for src/eve_mcp/server/helpers.py covering every previously-untested function: tag extractors, get_eve_client lazy init + caching, ensure_logged_in, the full _query_eve streaming path (token assembly, FINAL fallback, ERROR short-circuit, conversation cleanup), _extract_factuality_issues, and _assess_factuality_issue.
  • Fix a bug surfaced while writing the tests: extract_xml_tag returned a slice of garbage instead of raising NoTagFoundError when only a closing tag was present in the input. The single check p2 <= p1 failed because find() returns -1 on miss.
  • Ratchet --fail-under from 50 to 100 to lock in the new coverage floor.

Stacks on top of #3 (cleanup/dead-code). Will retarget to main once #2 and #3 merge.

This addresses items 8 (unit tests) and 9 (100% coverage) from the v0.0.1 release checklist.

Test plan

  • poetry run pre-commit run --all-files — all hooks pass at 100% coverage
  • 35 tests pass locally (17 existing + 18 new)
  • CI matrix (3.11 / 3.12 / 3.13 / 3.14) — verify after push
  • Manual smoke: end-to-end query_eve against the live EVE API with real credentials

extract_xml_tag previously used a single check `p2 <= p1` to detect a
missing tag, but `find()` returns -1 on miss. With input containing
only the closing tag (p1 = -1, p2 = some positive index), the check
passed and the function returned a slice of garbage characters
instead of raising NoTagFoundError.

Check both positions explicitly: raise if the opening tag is missing,
or if the closing tag is at or before the opener.
Cover all previously-untested code paths in src/eve_mcp/server/helpers.py:

- extract_xml_tag / extract_tag: happy paths, missing-tag cases
- get_eve_client: missing-credentials RuntimeError, lazy
  construction, cached singleton on subsequent calls
- ensure_logged_in: refreshes auth token on the cached client
- _query_eve: token/source/final event assembly, FINAL-only fallback,
  ERROR event short-circuit, conversation cleanup robustness when
  delete fails
- _extract_factuality_issues: parses ```json fence from the LLM answer
- _assess_factuality_issue: strips <CODE_RECOMMENDATIONS> from the
  answer body and unwraps an optional inner ```json fence

Brings overall coverage to 100%.
With the new helpers tests landed, the suite achieves 100% line
coverage. Lock that in: any future change that introduces an
untested branch will now fail pre-commit.
Base automatically changed from cleanup/dead-code to main April 28, 2026 13:00
@will-fawcett-trillium will-fawcett-trillium merged commit 68997d6 into main Apr 28, 2026
4 checks passed
@will-fawcett-trillium will-fawcett-trillium deleted the tests/helpers-coverage branch April 28, 2026 13:00
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.

3 participants