fix: mock Redis dependencies in test_create_conversion_success#1340
Merged
fix: mock Redis dependencies in test_create_conversion_success#1340
Conversation
Contributor
There was a problem hiding this comment.
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_successto 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 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 | ||
|
|
Contributor
AI-Engine Test Coverage66.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 mocks for cache.set_job_status, cache.set_progress, cache.get_job_status - Add mock for get_celery_monitor.check_queue_health Ref: #1338
eac80dc to
11ac050
Compare
Contributor
AI-Engine Test Coverage66.68% (267 files tracked) Required: 65% |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
test_create_conversion_successtest which was failing withConnectionRefusedError: [Errno 111] Connection refusedatlocalhost:6379Changes
@patch("api.conversions.cache")decorator to mock theCacheServiceinstance@patch("api.conversions.get_celery_monitor")decorator to mock theCeleryQueueMonitorBoth were attempting real Redis connections. The test now passes without requiring Redis to be running.
Testing