Skip to content

tests: cover schemas helpers, sanitizer gaps, prompt log_context branch#322

Open
JayDS22 wants to merge 1 commit intojenkinsci:mainfrom
JayDS22:tests/schemas-sanitizer-prompt-coverage
Open

tests: cover schemas helpers, sanitizer gaps, prompt log_context branch#322
JayDS22 wants to merge 1 commit intojenkinsci:mainfrom
JayDS22:tests/schemas-sanitizer-prompt-coverage

Conversation

@JayDS22
Copy link
Copy Markdown

@JayDS22 JayDS22 commented Mar 29, 2026

Adds 30 unit tests covering previously-untested code.

Fixes #321

tests/unit/models/test_schemas.py (22 tests, new file)

  • is_valid_query_type - valid members, case sensitivity, empty string
  • str_to_query_type - valid conversion, ValueError on bad input
  • try_str_to_query_type - fallback to MULTI on bad input
  • ChatRequest - accepts valid messages, rejects empty/whitespace
  • ChatRequestWithFiles - message-only, files-only, both, neither

tests/unit/prompts/test_prompt_builder.py (3 tests appended)

  • log_context provided uses LOG_ANALYSIS_INSTRUCTION and includes log data
  • log_context=None uses standard SYSTEM_INSTRUCTION, no log section

tests/unit/tools/test_sanitizer.py (5 tests appended)

  • Bearer token, GitHub PAT (ghp_), PEM private key block, client_secret, api_key with colon

How to run:

cd chatbot-core && export PYTHONPATH=$(pwd)
pytest tests/unit/models/test_schemas.py \
       tests/unit/prompts/test_prompt_builder.py \
       tests/unit/tools/test_sanitizer.py -v

All 38 tests pass (30 new + 8 existing). No source changes, no new deps.

New file tests/unit/models/test_schemas.py (22 tests):
  is_valid_query_type, str_to_query_type, try_str_to_query_type,
  ChatRequest validator, ChatRequestWithFiles validator.

Appended to tests/unit/prompts/test_prompt_builder.py (3 tests):
  build_prompt() with log_context was completely untested.

Appended to tests/unit/tools/test_sanitizer.py (5 tests):
  Bearer, GitHub PAT, PEM key block, client_secret, api_key patterns
  existed in sanitizer.py but had no coverage.
@JayDS22 JayDS22 requested a review from a team as a code owner March 29, 2026 06:21
@berviantoleo berviantoleo added the tests This PR adds/removes/updates test cases label Mar 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

tests This PR adds/removes/updates test cases

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Tests] Add unit tests for schemas.py, expand sanitizer and prompt_builder coverage

2 participants