Files
qwenpaw/tests/unit/loop/test_mission_settings.py
agent-radar 1a3a4ccde1
Creator App Tests / PR Spam Gate (push) Skipped
Frontend Tests / PR Spam Gate (push) Skipped
NPM Format (website & console) / PR Spam Gate (push) Skipped
Pre-commit Checks / PR Spam Gate (push) Skipped
QwenPaw Creator Plugin Release / check-version (push) Canceled after 0s
QwenPaw Creator Plugin Release / upload-oss (push) Canceled after 0s
Tests / PR Spam Gate (push) Skipped
CodeQL / CodeQL (python) (push) Canceled after 0s
CodeQL / CodeQL (typescript) (push) Canceled after 0s
Creator App Tests / Creator Backend Tests (push) Canceled after 0s
Creator App Tests / Creator UI Build & Tests (push) Canceled after 0s
E2E Smoke Tests / Playwright UI Smoke (push) Canceled after 0s
Frontend Tests / Detect console changes (push) Canceled after 0s
NPM Format (website & console) / website format check (push) Canceled after 0s
NPM Format (website & console) / console format check (push) Canceled after 0s
Pre-commit Checks / Pre-commit (push) Canceled after 0s
QwenPaw Data Plugin Release / check-version (push) Canceled after 0s
Tests / Detect code changes (push) Canceled after 0s
Frontend Tests / Vitest Unit Tests (push) Canceled after 0s
Frontend Tests / Frontend Summary (push) Canceled after 0s
QwenPaw Data Plugin Release / upload-oss (push) Canceled after 0s
Tests / Maintainer Approval (push) Canceled after 0s
Tests / Unit Tests - py3.11 - macos-latest (push) Canceled after 0s
Tests / Unit Tests - py3.11 - ubuntu-latest (push) Canceled after 0s
Tests / Unit Tests - py3.13 - ubuntu-latest (push) Canceled after 0s
Tests / Unit Tests - py3.11 - windows-latest (push) Canceled after 0s
Tests / Contract Tests - py3.11 - macos-latest (push) Canceled after 0s
Tests / Contract Tests - py3.11 - ubuntu-latest (push) Canceled after 0s
Tests / Contract Tests - py3.13 - ubuntu-latest (push) Canceled after 0s
Tests / Contract Tests - py3.11 - windows-latest (push) Canceled after 0s
Tests / Integrated Tests - py3.11 - macos-latest - p0 (push) Canceled after 0s
Tests / Integrated Tests - py3.11 - macos-latest - p1 (push) Canceled after 0s
Tests / Integrated Tests - py3.11 - macos-latest - p2 (push) Canceled after 0s
Tests / Integrated Tests - py3.11 - ubuntu-latest - fallback (push) Canceled after 0s
Tests / Integrated Tests - py3.11 - ubuntu-latest - p0 (push) Canceled after 0s
Tests / Integrated Tests - py3.11 - ubuntu-latest - p1 (push) Canceled after 0s
Tests / Integrated Tests - py3.11 - ubuntu-latest - p2 (push) Canceled after 0s
Tests / Integrated Tests - py3.13 - ubuntu-latest - p0 (push) Canceled after 0s
Tests / Integrated Tests - py3.13 - ubuntu-latest - p1 (push) Canceled after 0s
Tests / Integrated Tests - py3.13 - ubuntu-latest - p2 (push) Canceled after 0s
Tests / Integrated Tests - py3.11 - windows-latest - p0 (push) Canceled after 0s
Tests / Integrated Tests - py3.11 - windows-latest - p1 (push) Canceled after 0s
Tests / Integrated Tests - py3.11 - windows-latest - p2 (push) Canceled after 0s
Tests / Coverage Report (push) Canceled after 0s
Tests / Test Summary (push) Canceled after 0s
源码快照 @ 2026-09-01 (source-only, 剔除非源码素材)
2026-09-01 20:01:50 +08:00

114 lines
3.8 KiB
Python

# -*- coding: utf-8 -*-
"""Tests for user-editable Mission defaults."""
from __future__ import annotations
from unittest.mock import AsyncMock, patch
import pytest
from pydantic import ValidationError
from qwenpaw.config.config import MissionLoopModeConfig
from qwenpaw.modes.mission.handler import (
parse_mission_args,
start_mission,
)
from qwenpaw.modes.mission.prompts import build_master_prompt
from qwenpaw.modes.mission.state import read_loop_config
def test_mission_config_defaults_and_bounds() -> None:
"""Mission settings expose conservative defaults with validation."""
config = MissionLoopModeConfig()
assert config.max_iterations == 20
assert config.max_retries_per_story == 3
assert config.default_verification_instructions == ""
assert config.default_verify_command == ""
with pytest.raises(ValidationError):
MissionLoopModeConfig(max_retries_per_story=11)
def test_mission_args_use_defaults_and_allow_command_override() -> None:
"""Per-mission arguments override only values explicitly provided."""
defaults = parse_mission_args(
"implement the feature",
default_max_iterations=12,
default_verify_command="npm test",
)
override = parse_mission_args(
"implement the feature --max-iterations 7 --verify pytest",
default_max_iterations=12,
default_verify_command="npm test",
)
assert defaults["max_iterations"] == 12
assert defaults["verify_commands"] == "npm test"
assert override["max_iterations"] == 7
assert override["verify_commands"] == "pytest"
def test_master_prompt_uses_configured_story_retry_limit() -> None:
"""Retry configuration replaces the previous hard-coded prompt value."""
prompt = build_master_prompt(
loop_dir="/tmp/mission",
agent_id="agent",
max_retries_per_story=6,
)
assert "Max 6 retries per story" in prompt
assert "Max 3 retries per story" not in prompt
def test_master_prompt_includes_verification_instructions() -> None:
"""Verifier receives natural-language guidance separately from commands."""
prompt = build_master_prompt(
loop_dir="/tmp/mission",
agent_id="agent",
verification_instructions=(
"Check Windows path handling and inspect the rendered UI."
),
verify_commands="pytest -q",
)
assert "Check Windows path handling" in prompt
assert "**Verify command**: pytest -q" in prompt
@pytest.mark.asyncio
async def test_start_mission_persists_editable_defaults(tmp_path) -> None:
"""New missions persist settings used by the existing workflow."""
git_context = {
"git_installed": False,
"is_git_repo": False,
"default_branch": "",
"repo_root": "",
}
with patch(
"qwenpaw.modes.mission.handler.detect_git_context",
new=AsyncMock(return_value=git_context),
):
_, loop_dir = await start_mission(
task_text="Implement the approved feature",
project_dir=tmp_path,
agent_workspace_dir=tmp_path / "agent-workspace",
agent_id="agent",
session_id="session",
verify_commands="pytest -q",
verification_instructions="Check accessibility manually.",
max_iterations=14,
max_retries_per_story=5,
)
config = read_loop_config(loop_dir)
assert config["max_iterations"] == 14
assert config["max_retries_per_story"] == 5
assert config["verify_commands"] == "pytest -q"
assert config["verification_instructions"] == (
"Check accessibility manually."
)
assert loop_dir.parent == tmp_path / ".qwenpaw" / "missions"
assert config["source_project_dir"] == str(tmp_path)
assert config["workspace_dir"] == str(tmp_path / "agent-workspace")
assert config["mission_run_dir"] == str(tmp_path)