codeflash-internal/tiles/codeflash-internal-rules/evals/scenario-1/task.md
2026-02-14 22:25:30 -05:00

2.1 KiB

Scenario 1: Implement a Ruby Optimizer Handler

Context

The codeflash-internal monorepo currently supports Python and JavaScript/TypeScript optimization through the multi-language handler system. The team wants to add Ruby as a new supported language for the optimizer feature. The handler should integrate with the existing registry, dispatcher, and router systems.

The relevant existing code lives in:

  • django/aiservice/core/languages/ (per-language handlers)
  • django/aiservice/core/registry.py (LanguageRegistry, @register_handler)
  • django/aiservice/core/dispatcher.py (get_handler_for_feature, Feature enum)
  • django/aiservice/core/protocols/ (OptimizerProtocol, LanguageHandler)
  • django/aiservice/core/shared/optimizer_router.py (shared router that dispatches by language)

Task

  1. Create a new Ruby optimizer handler at django/aiservice/core/languages/ruby/optimizer/optimizer.py that:

    • Registers itself using the @register_handler("ruby") decorator
    • Sets supports_optimizer = True and other supports_* flags to False
    • Implements OptimizerProtocol with an optimizer_optimize(request, data) async method
    • Uses ninja.Schema for any request/response models
    • Calls LLM through the proper abstraction layer
    • Stores the optimization prompt as a .md file alongside the module, rendered with Jinja2
  2. Add the Ruby language routing in core/shared/optimizer_router.py using lazy imports with the # noqa: PLC0415 suppression

  3. Import the Ruby handler module in core/languages/__init__.py so the decorator fires at startup

  4. Create a basic test file at django/aiservice/tests/optimizer/test_ruby_optimizer.py

Expected Outputs

  • core/languages/ruby/__init__.py
  • core/languages/ruby/optimizer/__init__.py
  • core/languages/ruby/optimizer/optimizer.py — handler class with decorator, protocol, async method
  • core/languages/ruby/optimizer/optimize_prompt.md — Jinja2 prompt template
  • Updated core/shared/optimizer_router.py — lazy import dispatch for "ruby"
  • Updated core/languages/__init__.py — import of ruby module
  • tests/optimizer/test_ruby_optimizer.py — async test with @pytest.mark.asyncio