Artifex/control_plane/resources/management/commands/qwen_coding_smoke.py
2026-08-15 13:50:24 +07:00

47 lines
2.4 KiB
Python

from __future__ import annotations
from pathlib import Path
from django.core.management.base import BaseCommand, CommandError
from control_plane.agents.management.commands.seed_core_agents import Command as SeedAgentsCommand
from control_plane.projects.models import Milestone, Project, ProjectPlan, Task, TaskStatus
from control_plane.resources.models import Resource
from model_router.providers import QwenProvider
from model_router.router import ModelRouter
from runtime_loop.autonomous_task_loop import AutonomousTaskLoop
class Command(BaseCommand):
help = "Opt-in smoke test: run one M2 task through configured Qwen provider against an existing disposable repo."
def add_arguments(self, parser):
parser.add_argument("repository_path")
def handle(self, *args, **options):
repo = Path(options["repository_path"]).resolve()
if not (repo / ".git").exists():
raise CommandError("repository_path must be a Git repository")
resource = Resource.objects.filter(provider="local_inference", is_active=True).first()
if resource is None:
raise CommandError("No Qwen/local_inference resource configured. Run seed_spark_resources first.")
SeedAgentsCommand().handle()
project = Project.objects.create(name="Qwen Smoke", goal="Add health endpoint", repository_path=str(repo))
plan = ProjectPlan.objects.create(project=project, version=1, goal=project.goal)
milestone = Milestone.objects.create(project=project, plan=plan, key="M2", title="Smoke", goal="Run Qwen coding")
Task.objects.create(
project=project,
milestone=milestone,
task_type="implementation",
status=TaskStatus.READY,
goal='Add a /health endpoint returning JSON {"status": "ok"} and add tests.',
acceptance_criteria=["/health returns ok", "tests pass"],
)
router = ModelRouter({"qwen": QwenProvider(resource)}, persist_requests=True)
task = AutonomousTaskLoop(router).run_once(test_command=["python", "manage.py", "test"])
if task is None:
raise CommandError("No task was executed")
task.refresh_from_db()
if task.status != TaskStatus.COMPLETE:
raise CommandError(f"Qwen smoke failed with task status {task.status}")
self.stdout.write(self.style.SUCCESS(f"Qwen smoke committed {task.commits.first().sha}"))