Skip to content

fix: mock Redis dependencies in test_create_conversion_success#1340

Merged
anchapin merged 7 commits intomainfrom
fix/1338-test-create-conversion-redis-mock
May 7, 2026
Merged

fix: mock Redis dependencies in test_create_conversion_success#1340
anchapin merged 7 commits intomainfrom
fix/1338-test-create-conversion-redis-mock

Conversation

@anchapin
Copy link
Copy Markdown
Owner

@anchapin anchapin commented May 7, 2026

Summary

  • Mock Redis dependencies in test_create_conversion_success test which was failing with ConnectionRefusedError: [Errno 111] Connection refused at localhost:6379

Changes

  1. Add @patch("api.conversions.cache") decorator to mock the CacheService instance
  2. Add @patch("api.conversions.get_celery_monitor") decorator to mock the CeleryQueueMonitor

Both were attempting real Redis connections. The test now passes without requiring Redis to be running.

Testing

cd backend && python3 -m pytest src/tests/unit/test_api_conversions_targeted.py::TestConversionsAPITargeted::test_create_conversion_success -v --no-cov -n 0

Copilot AI review requested due to automatic review settings May 7, 2026 07:12
Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry @anchapin, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR aims to make the backend conversion-creation unit test independent of Redis, but it also introduces broader AI-engine inference/deployment and MMSD dataset/training changes that extend well beyond the stated scope.

Changes:

  • Update test_create_conversion_success to mock Redis-dependent globals used by the conversions API.
  • Add “quantization floor” validation plumbing for self-hosted inference configuration.
  • Add MMSD mapping validation/training-recipe documentation and new deployment artifacts (RunPod/Modal).

Reviewed changes

Copilot reviewed 18 out of 18 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
docs/INFERENCE_DEPLOYMENT.md Adds quantization standards and env var configuration guidance.
backend/src/tests/unit/test_api_conversions_targeted.py Patches conversions API globals in the unit test to avoid real Redis connections.
backend/src/services/sentry_config.py Tweaks Sentry Celery integration configuration.
backend/src/main.py Reformats Sentry imports (multiline).
backend/src/api/premium_conversion.py Minor formatting/whitespace/docstring adjustments.
ai-engine/utils/self_hosted_inference.py Adds quantization floor parsing/validation and env-driven config fields.
ai-engine/tests/unit/test_mojmap_validator.py Adds unit tests for Mojmap mapping validation (currently placed under ai-engine test tree).
ai-engine/services/runpod_server.py Adds a FastAPI OpenAI-compatible inference server backed by vLLM.
ai-engine/services/runpod_entrypoint.sh Adds entrypoint that downloads HF model snapshot before starting server.
ai-engine/services/modal_inference.py Adds Modal deployment for vLLM-based inference.
ai-engine/services/Dockerfile.runpod Adds Dockerfile for RunPod serverless inference image.
ai_engine/tests/test_premium_client.py Small test cleanup/renames/formatting.
ai_engine/mmsd/validators/mojmap_validator.py Introduces Mojmap vs SRG/MCP pattern validator.
ai_engine/mmsd/TRAINING_REPORT.md Documents general-code mixing to mitigate catastrophic forgetting.
ai_engine/mmsd/train_portkit_coder.py Adds general Java/JS dataset sampling and mixing to training pipeline.
ai_engine/mmsd/run_validation.py Extends validation pipeline to skip non-Mojmap Java sources.
ai_engine/mmsd/README.md Adds MMSD mapping standard and validation documentation.
ai_engine/mmsd/premium_client.py Removes unused imports.

Comment on lines +54 to 56
@patch("api.conversions.cache")
@patch("api.conversions.get_celery_monitor")
async def test_create_conversion_success(
Comment thread docs/INFERENCE_DEPLOYMENT.md Outdated
Comment on lines +190 to +191
| **AWQ / EXL2** | **4-bit, group_size ≤ 128** | group_size 128 preserves more precision than default 128 |
| **vLLM / SGLang** | Same as above | Both use the same model files; enforce via quantization type |
Comment on lines +50 to +68
"""
Check if a model meets the minimum quantization floor.

For GGUF: minimum Q5_K_M (5-bit)
For AWQ/EXL2: minimum 4-bit with group_size ≤ 128

Returns (passes, detail_str).
"""
if quant_type in ("gguf", "llama"):
bits = _parse_quant_bits(model_name)
if bits is None:
return True, "quantization bit depth unknown (GGUF)"
if bits < MIN_QUANT_BITS_GGUF:
return False, (
f"model is {bits}-bit; Q5_K_M (5-bit) is the minimum floor for GGUF. "
f"Models below Q5_K_M produce syntax errors in code generation."
)
detail = f"GGUF {bits}-bit (meets Q5_K_M floor)"
return True, detail
Comment on lines +32 to +87
def _parse_quant_bits(model_name: str) -> Optional[int]:
"""Extract quantization bit depth from a model filename or identifier."""
pattern = re.compile(r"Q([0-9]+)_?K?|Q([0-9]+)\.")
for match in pattern.finditer(model_name):
bits = match.group(1) or match.group(2)
if bits:
try:
return int(bits)
except ValueError:
pass
return None


def check_quantization_floor(
model_name: str,
quant_type: str = "gguf",
awq_group_size: Optional[int] = None,
) -> tuple[bool, str]:
"""
Check if a model meets the minimum quantization floor.

For GGUF: minimum Q5_K_M (5-bit)
For AWQ/EXL2: minimum 4-bit with group_size ≤ 128

Returns (passes, detail_str).
"""
if quant_type in ("gguf", "llama"):
bits = _parse_quant_bits(model_name)
if bits is None:
return True, "quantization bit depth unknown (GGUF)"
if bits < MIN_QUANT_BITS_GGUF:
return False, (
f"model is {bits}-bit; Q5_K_M (5-bit) is the minimum floor for GGUF. "
f"Models below Q5_K_M produce syntax errors in code generation."
)
detail = f"GGUF {bits}-bit (meets Q5_K_M floor)"
return True, detail

elif quant_type in ("awq", "exl2", "gptq"):
bits = _parse_quant_bits(model_name)
if bits is None:
return True, "quantization bit depth unknown (AWQ/EXL2)"
if bits < MIN_QUANT_BITS_AWQ:
return False, (
f"model is {bits}-bit; AWQ/EXL2 requires 4-bit minimum. "
f"Use AWQ 4-bit with group_size ≤ {MIN_AWQ_GROUP_SIZE}."
)
if awq_group_size is not None and awq_group_size > MIN_AWQ_GROUP_SIZE:
return False, (
f"AWQ group_size={awq_group_size} exceeds maximum {MIN_AWQ_GROUP_SIZE}. "
f"For reliable code generation, use group_size ≤ {MIN_AWQ_GROUP_SIZE}."
)
detail = f"AWQ/EXL2 {bits}-bit group_size={awq_group_size or 'default'} (meets floor)"
return True, detail

return True, "quantization type unrecognized, skipping check"
Comment on lines +5 to +9
MODEL_REPO="alexchapin/portkit-7b"
MODEL_REVISION="${MODEL_REVISION:-main}"
MODEL_DIR="/model_cache/portkit_7b"

echo "[entrypoint] Downloading ${MODEL_REPO} to ${MODEL_DIR}..."
Comment on lines +1 to +3
import pytest
from ai_engine.mmsd.validators.mojmap_validator import MojmapMappingValidator

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 7, 2026

AI-Engine Test Coverage

66.61% (267 files tracked)

Required: 65%

…enRouter

- Add ai_engine/mmsd/premium_client.py with PortKitPremium client
  - Supports DeepSeek V4 Pro, Kimi K2, GLM-5, DeepSeek V4 Flash
  - 3 curated few-shot examples for blocks, items, entity spawning
  - Auto-fallback and retry with backoff for rate limits
  - Cost estimation (~$0.006 per conversion)
  - CLI interface for quick conversions

- Add backend/src/api/premium_conversion.py API endpoints
  - POST /api/v1/premium/convert - Premium conversion
  - GET /api/v1/premium/models - List available models
  - POST /api/v1/premium/estimate - Estimate conversion cost

- Update frontend API service (frontend/src/services/api.ts)
  - Add premiumConvert, listPremiumModels, estimatePremiumCost

- Update subscriptionTier.ts with premium_conversion feature
  - Studio tier required for premium conversion access

- Update documentation
  - ai-engine/README.md - Add BYOK section
  - docs/api-reference.md - Add Premium Conversion section

- Add unit tests (ai_engine/tests/test_premium_client.py)
Ruff F401: json, dataclasses.field, httpx, ConversionResult unused
- Add @patch for api.conversions.cache to mock CacheService
- Add @patch for api.conversions.get_celery_monitor to mock CeleryQueueMonitor
- Both were attempting real Redis connections at localhost:6379

Fixes #1338
- Add mocks for cache.set_job_status, cache.set_progress, cache.get_job_status
- Add mock for get_celery_monitor.check_queue_health

Ref: #1338
@anchapin anchapin force-pushed the fix/1338-test-create-conversion-redis-mock branch from eac80dc to 11ac050 Compare May 7, 2026 08:09
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 7, 2026

AI-Engine Test Coverage

66.68% (267 files tracked)

Required: 65%

@anchapin anchapin merged commit cfced98 into main May 7, 2026
41 of 47 checks passed
@anchapin anchapin deleted the fix/1338-test-create-conversion-redis-mock branch May 7, 2026 11:57
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