mirror of
https://github.com/langgenius/dify.git
synced 2026-10-04 13:47:55 +08:00
- test_wiring.py: expected dict was missing SessionView's new `model` field - model_resolver.normalize_completion_params: a string `stop` was being char-split into a list of letters instead of wrapped in a single-element list; added a regression test - controllers/console/dify_builder._ping: log the exception server-side before returning the ok:false envelope - ruff-clean the slice's new/extended test files (ARG001/ARG002/ARG005 via precise noqa, PT018 compound-assert splits, E306, E501) with no change to test behavior or assertion meaning Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
46 lines
2.1 KiB
Python
46 lines
2.1 KiB
Python
import dataclasses
|
|
from unittest.mock import patch
|
|
|
|
from core.dify_builder.errors import BusyError, ConflictError, NotFoundError
|
|
from core.dify_builder.models import Action, Actor
|
|
from services.dify_builder import wiring
|
|
from services.dify_builder.service import SessionView
|
|
|
|
|
|
def test_session_view_to_dict_round_trips_fields():
|
|
view = SessionView(
|
|
session_id="s1", app_id="a1", version=3, state="fix.await_verify",
|
|
# "waiting-input" (hyphen) is a raw passthrough literal for this
|
|
# asdict round-trip test, not real service output -- _run_status
|
|
# never returns this; the real widened value is "waiting_input".
|
|
canvas_read_only=False, run_status="waiting-input", interrupted=False,
|
|
conversation=[],
|
|
)
|
|
d = wiring.session_view_to_dict(view)
|
|
assert d == {
|
|
"session_id": "s1", "app_id": "a1", "version": 3, "state": "fix.await_verify",
|
|
"canvas_read_only": False, "run_status": "waiting-input", "interrupted": False,
|
|
"conversation": [], "entry_mode": "fix", "phase": "understand", "actions": [],
|
|
"checkpoint": None, "recovery": None, "model": None,
|
|
}
|
|
|
|
|
|
def test_error_map():
|
|
assert wiring.dify_builder_error_response(NotFoundError("x"))[1] == 404
|
|
assert wiring.dify_builder_error_response(NotFoundError("x"))[0]["code"] == "not_found"
|
|
assert wiring.dify_builder_error_response(ConflictError("x")) == ({"code": "conflict"}, 409)
|
|
assert wiring.dify_builder_error_response(BusyError("x")) == ({"code": "session_busy"}, 409)
|
|
assert wiring.dify_builder_error_response(ValueError("x")) is None # unknown → caller re-raises
|
|
|
|
|
|
def test_build_service_enqueue_calls_delay_with_dicts():
|
|
with patch("services.dify_builder.wiring.advance_session") as task, \
|
|
patch("services.dify_builder.wiring.db"):
|
|
svc = wiring.build_service()
|
|
action = Action(kind="run_verify", base_version=2)
|
|
actor = Actor(account_id="acc", tenant_id="ten")
|
|
svc._enqueue_fn("sid-1", action, actor, "tok-9") # the injected enqueue
|
|
task.delay.assert_called_once_with(
|
|
"sid-1", dataclasses.asdict(action), dataclasses.asdict(actor), "tok-9"
|
|
)
|