auto_agent/backend/app/services/local_sample_app_service.py
2521690 a0f7152e80 feat(mvp): 接入真实样板应用桥接并推进演示主线
- 新增 `sample-apps/order-service` Java 样板应用及 Win/Linux 构建、启停、状态脚本
- 新增 `LocalSampleAppService`,在 `software-a` 中支持 `order-service test` 本地桥接部署
- 增加桥接开关配置:`ENABLE_SAMPLE_APP_BRIDGE`、`SAMPLE_APP_ROOT`
- 修正后端配置读取方式,环境变量可在运行时生效(`Settings` 改为 `default_factory`)
- 更新应用元数据默认验证目标:`127.0.0.1:18080`、本地日志路径
- 新增桥接测试 `test_sample_app_bridge.py`,后端基线更新至 `24 passed`
- 更新 `.gitignore`,忽略样板应用 `build/runtime` 产物
- 更新 README 与《当前进度总结》:记录本轮“真实样板应用 + 桥接能力”进展,MVP 进度约 `97%`
2026-04-09 15:45:03 +08:00

46 lines
1.7 KiB
Python

from __future__ import annotations
import os
import platform
import subprocess
from pathlib import Path
from typing import Any
class LocalSampleAppService:
def __init__(self, sample_app_root: str) -> None:
self.root = Path(sample_app_root).resolve()
def deploy_order_service(self, version: str) -> dict[str, Any]:
self._ensure_root()
self._run_script("build")
self._run_script("stop", check=False)
self._run_script("start", extra_args=[f"-Version {version}"] if self._is_windows() else [version])
return self.status()
def status(self) -> dict[str, Any]:
self._ensure_root()
result = self._run_script("status", check=False)
return {
"status_text": (result.stdout + "\n" + result.stderr).strip(),
"return_code": result.returncode,
"running": result.returncode == 0,
}
def _run_script(self, action: str, extra_args: list[str] | None = None, check: bool = True) -> subprocess.CompletedProcess[str]:
extra_args = extra_args or []
if self._is_windows():
script_path = self.root / "scripts" / f"{action}.ps1"
command = ["powershell", "-ExecutionPolicy", "Bypass", "-File", str(script_path), *extra_args]
else:
script_path = self.root / "scripts" / f"{action}.sh"
command = ["bash", str(script_path), *extra_args]
return subprocess.run(command, cwd=str(self.root), capture_output=True, text=True, check=check)
def _ensure_root(self) -> None:
if not self.root.exists():
raise FileNotFoundError(f"sample app root not found: {self.root}")
def _is_windows(self) -> bool:
return platform.system().upper().startswith("WIN")