Skip to content

fix: Split backend pre_conversion/analyzer.py (26K) + batch/queue_manager.py (22K) — post-#1769 split regrowth - #1904

Open
webbrain-one wants to merge 1 commit into
anchapin:mainfrom
webbrain-one:webbrain/issue-1871
Open

fix: Split backend pre_conversion/analyzer.py (26K) + batch/queue_manager.py (22K) — post-#1769 split regrowth#1904
webbrain-one wants to merge 1 commit into
anchapin:mainfrom
webbrain-one:webbrain/issue-1871

Conversation

@webbrain-one

@webbrain-one webbrain-one commented Aug 8, 2026

Copy link
Copy Markdown

Closes #1871

Summary by Sourcery

Extract queue broker integration and pre-conversion analysis responsibilities into dedicated backend service modules to reduce coupling and prepare for further splitting of large files.

New Features:

  • Introduce a Redis-backed queue backend service for job state persistence, progress pub/sub, and broker error handling.
  • Add a Celery task backend wrapper for task submission and non-blocking result polling.
  • Add a pre-conversion file-checks service module for validating manifests, resource packs, and asset directories.
  • Add a centralized pre-conversion scan rules module defining static analysis rules and severities for compatibility checks.

Addresses post-split regrowth from anchapin#1769 by extracting logic into dedicated files:
- pre_conversion/rules.py and file_checks.py for scan rules and file-type validation
- batch/queue_backend.py for Redis/Celery adapter, leaving queue_manager.py as orchestration only

Fixes anchapin#1871
@webbrain-one
webbrain-one requested a review from anchapin as a code owner August 8, 2026 04:08
Copilot AI lite review requested due to automatic review settings August 8, 2026 04:08

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Sorry @webbrain-one, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

@sourcery-ai

sourcery-ai Bot commented Aug 8, 2026

Copy link
Copy Markdown

Reviewer's Guide

This PR continues the post-#1769 backend split by extracting Redis/Celery queue integration and pre-conversion scanning logic into focused service modules, improving separation of concerns and making batch/queue_manager.py and pre_conversion/analyzer.py thinner orchestration layers.

File-Level Changes

Change Details Files
Introduce a dedicated queue backend adapter to encapsulate Redis and Celery interactions for batch processing.
  • Add RedisQueueBackend class to wrap job state persistence and progress pub/sub against a provided Redis connection.
  • Add CeleryTaskBackend class to abstract Celery task submission and non-blocking result polling, with unified error handling via QueueBackendError.
  • Ensure queue orchestration code can depend on this adapter instead of importing Redis/Celery directly, enabling cleaner testing and future backend swaps.
backend/src/services/batch/queue_backend.py
Extract per-file-type pre-conversion checks into a reusable module.
  • Implement check_java_manifest to validate legacy Forge/FML mod metadata and surface potential compatibility issues as warning strings.
  • Implement check_resource_pack_json to load and validate pack.mcjson, returning a simple compatibility/missing-dependency summary structure.
  • Implement scan_asset_directory to walk asset trees and flag files with unsupported extensions, centralizing extension policy.
backend/src/services/pre_conversion/file_checks.py
Centralize static pre-conversion scan rules and severities into a dedicated rules module.
  • Define RuleSeverity enum and ScanRule dataclass to model individual static analysis rules with IDs, names, patterns, and descriptions.
  • Add core rules for Forge API usage and vanilla hack detection using compiled regexes, and expose them via a SCAN_RULES registry list.
  • Prepare analyzer/orchestration code to consume these rules instead of embedding patterns inline, improving maintainability and discoverability.
backend/src/services/pre_conversion/rules.py

Assessment against linked issues

Issue Objective Addressed Explanation
#1871 Extract scan-rule definitions and per-file-type checks from backend/src/services/pre_conversion/analyzer.py into separate modules (pre_conversion/rules.py and pre_conversion/file_checks.py).
#1871 Extract the queue backend adapter (Redis/Celery specifics) from backend/src/services/batch/queue_manager.py into backend/src/services/batch/queue_backend.py so that queue_manager.py is orchestration-only.

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 reduce coupling and prevent “regrowth” of large backend modules by extracting pre-conversion scan rules/file checks and batch queue broker adapters into dedicated service modules.

Changes:

  • Added pre_conversion/rules.py to centralize static scan rule definitions.
  • Added pre_conversion/file_checks.py to host per-file-type validation helpers.
  • Added batch/queue_backend.py to encapsulate Redis/Celery broker interactions.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 8 comments.

File Description
backend/src/services/pre_conversion/rules.py Introduces a rules data model and initial regex-based scan rules.
backend/src/services/pre_conversion/file_checks.py Adds helper functions for validating manifests/resource packs and scanning asset directories.
backend/src/services/batch/queue_backend.py Adds Redis job-state/progress publishing and Celery submit/poll wrappers.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +1 to +6
"""Scan-rule definitions extracted from pre_conversion/analyzer.py (Issue #1871).

This module centralizes static analysis rules, regex patterns, and AST-based
heuristics used to detect compatibility issues, unsupported APIs, and risky
code patterns during the pre-conversion scan phase.
"""
Comment on lines +15 to +20
class RuleSeverity(Enum):
"""Severity levels for pre-conversion scan rules."""
ERROR = auto()
WARNING = auto()
INFO = auto()

id="PRE-001",
name="Forge API Usage",
severity=RuleSeverity.ERROR,
pattern=re.compile(r"import\s+net\.minecraftforge", re.IGNORECASE),
Comment on lines +34 to +52
"""Validate pack.mcjson for Bedrock compatibility prerequisites.

Returns a dictionary with compatibility flags and missing dependencies.
"""
result: dict[str, Any] = {"compatible": True, "missing": []}
pack_file = pack_path / "pack.mcjson"
if not pack_file.exists():
return result

try:
with open(pack_file, encoding="utf-8") as f:
data = json.load(f)
if data.get("pack_format", 0) < 2:
result["compatible"] = False
result["missing"].append("pack_format >= 2")
except json.JSONDecodeError as e:
result["compatible"] = False
result["missing"].append(f"Invalid JSON in pack.mcjson: {e}")
return result
Comment on lines +26 to +27
if "modLoader" in content or "loaderVersion" in content:
issues.append("Legacy FML manifest detected; may require manual mapping.")
Comment on lines +56 to +59
"""Walk asset directory and flag files with unsupported extensions or sizes.

Returns a list of problematic file paths.
"""
Comment on lines +51 to +54
def publish_progress(self, job_id: str, progress: float, message: str = "") -> None:
"""Emit progress update via Redis channel."""
payload = json.dumps({"job_id": job_id, "progress": progress, "message": message})
self._redis.publish(f"progress:{job_id}", payload)
Comment on lines +72 to +78
def poll_result(self, task_id: str) -> dict[str, Any] | None:
"""Check task completion status without blocking."""
from celery.result import AsyncResult # noqa: PLC0415
async_result = AsyncResult(task_id, app=self._app)
if async_result.ready():
return {"status": async_result.status, "result": async_result.get(timeout=0)}
return None
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.

Split backend pre_conversion/analyzer.py (26K) + batch/queue_manager.py (22K) — post-#1769 split regrowth

2 participants