aps-agent/tests/golden/test_optimize_chat_data_sel...

69 lines
2.5 KiB
Python

from __future__ import annotations
import asyncio
from pathlib import Path
from server.agent_core.intent import parse_fast
from server.aps_domain.workflow import handle_intent
from server.state.packs import load_pack, resolve_pack_reference
from server.state.store import WorldStore
PACK_PATH = Path(__file__).resolve().parents[2] / "server" / "data" / "packs" / "optimize-simulation-v1.json"
def test_chat_command_parses_data_pack_and_algorithm_slots():
world = load_pack(str(PACK_PATH))
result = parse_fast(
"使用 Optimize synthetic debug V1 数据用 EDD 算法生成排产方案",
world,
)
assert result is not None
assert result.intent == "flex.schedule"
assert result.params["dataPackRef"] == "Optimize synthetic debug V1"
assert result.params["engine"] == "OPTIMIZE"
assert result.params["sortMode"] == "EDD"
def test_pack_reference_resolves_registered_aliases():
pack = resolve_pack_reference("Optimize 模拟数据")
assert pack is not None
assert pack["file"] == "optimize-simulation-v1.json"
def test_chat_command_loads_pack_and_materializes_optimize_result(tmp_path, monkeypatch):
monkeypatch.setenv("APS_DB_DISABLED", "1")
store = WorldStore(path=str(tmp_path / "world.json"))
intent = parse_fast(
"使用 Optimize synthetic debug V1 数据用 EDD 算法生成排产方案",
store.data,
)
assert intent is not None
reply = asyncio.run(handle_intent(store, "round88", intent, actor="test"))
assert "Optimize" in reply.text
assert "Optimize synthetic debug V1" in reply.text
block = next(block for block in reply.blocks if block.type == "flex-schedule")
assert block.props["dataPack"]["file"] == "optimize-simulation-v1.json"
assert block.props["algorithm"]["rule"] == "EDD"
assert block.props["stats"]["vlCount"] == 10
assert block.props["stats"]["woCount"] == 72
assert store.data["flexScheduleVersions"][-1]["engineType"] == "OPTIMIZE"
assert store.data["flexScheduleVersions"][-1]["algorithmId"] == "optimize.edd"
def test_unknown_pack_fails_closed_without_creating_schedule(tmp_path, monkeypatch):
monkeypatch.setenv("APS_DB_DISABLED", "1")
store = WorldStore(path=str(tmp_path / "world.json"))
intent = parse_fast("使用不存在的数据,用 EDD 算法生成排产方案", store.data)
assert intent is not None
reply = asyncio.run(handle_intent(store, "round88", intent, actor="test"))
assert "找不到数据包" in reply.text
assert not store.data.get("flexScheduleVersions")