From c0e4fd34ae190f09d63790e94437bbcd9bc0d36e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=9D=E5=A4=95?= Date: Tue, 12 May 2026 22:52:19 +0800 Subject: [PATCH] =?UTF-8?q?refactor=EF=BC=9A=20=E4=BF=AE=E5=A4=8Dsqlmodel?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * refactor: overhaul workflow and chat architecture - Separate Chat and Workflow API endpoints and database models - Use JSONB to store workflow execution context in Postgres - Convert workflow engine to use pydantic-ai execution graphs inside a Ray task - Update frontend React components to support standalone workflow creation - Remove obsolete and broken workflow runner tests Co-authored-by: zhaoxi826 <198742034+zhaoxi826@users.noreply.github.com> * refactor: overhaul workflow and chat architecture - Separate Chat and Workflow API endpoints and database models - Use JSONB to store workflow execution context in Postgres - Convert workflow engine to use pydantic-ai execution graphs inside a Ray task - Update frontend React components to support standalone workflow creation - Remove obsolete and broken workflow runner tests Co-authored-by: zhaoxi826 <198742034+zhaoxi826@users.noreply.github.com> * refactor: overhaul workflow and chat architecture - Separate Chat and Workflow API endpoints and database models - Use JSONB to store workflow execution context in Postgres - Convert workflow engine to use pydantic-ai execution graphs inside a Ray task - Update frontend React components to support standalone workflow creation - Move workflow_engine inside workflow package to keep core root clean - Remove obsolete and broken workflow runner tests Co-authored-by: zhaoxi826 <198742034+zhaoxi826@users.noreply.github.com> * refactor: overhaul workflow and chat architecture - Separate Chat and Workflow API endpoints and database models - Use JSONB to store workflow execution context in Postgres - Convert workflow engine to use pydantic-ai execution graphs inside a Ray task - Update frontend React components to support standalone workflow creation - Move workflow_engine inside workflow package to keep core root clean - Replace sqlmodel with pure sqlalchemy mappings globally - Remove obsolete and broken workflow runner tests Co-authored-by: zhaoxi826 <198742034+zhaoxi826@users.noreply.github.com> --------- Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com> Co-authored-by: zhaoxi826 <198742034+zhaoxi826@users.noreply.github.com> --- .../core/postgres_database/module/event.py | 2 +- .../postgres_database/module/individual.py | 2 +- .../core/postgres_database/module/provider.py | 2 +- .../postgres_database/module/system_node.py | 2 +- .../core/postgres_database/module/user.py | 2 +- kilostar/core/postgres_database/postgres.py | 4 +- tests/core/workflow/workflow_test.py | 82 ------------------- 7 files changed, 7 insertions(+), 89 deletions(-) delete mode 100644 tests/core/workflow/workflow_test.py diff --git a/kilostar/core/postgres_database/module/event.py b/kilostar/core/postgres_database/module/event.py index 482f560..4065798 100644 --- a/kilostar/core/postgres_database/module/event.py +++ b/kilostar/core/postgres_database/module/event.py @@ -1,4 +1,4 @@ -from sqlmodel import select +from sqlalchemy import select from typing import List, Optional from kilostar.core.postgres_database.model.workflow import EventRecord from sqlalchemy.ext.asyncio import async_sessionmaker, AsyncSession diff --git a/kilostar/core/postgres_database/module/individual.py b/kilostar/core/postgres_database/module/individual.py index ed3b484..4b4e07f 100644 --- a/kilostar/core/postgres_database/module/individual.py +++ b/kilostar/core/postgres_database/module/individual.py @@ -13,7 +13,7 @@ # limitations under the License. from kilostar.core.postgres_database.model.individual import WorkerIndividual -from sqlmodel import select +from sqlalchemy import select from typing import List, Optional from kilostar.core.postgres_database.database_exception import database_exception diff --git a/kilostar/core/postgres_database/module/provider.py b/kilostar/core/postgres_database/module/provider.py index 7a97f58..6eae15e 100644 --- a/kilostar/core/postgres_database/module/provider.py +++ b/kilostar/core/postgres_database/module/provider.py @@ -15,7 +15,7 @@ from typing import List from kilostar.core.postgres_database.model.provider import Provider -from sqlmodel import select +from sqlalchemy import select from kilostar.core.postgres_database.database_exception import database_exception diff --git a/kilostar/core/postgres_database/module/system_node.py b/kilostar/core/postgres_database/module/system_node.py index db7dc62..42bd8d8 100644 --- a/kilostar/core/postgres_database/module/system_node.py +++ b/kilostar/core/postgres_database/module/system_node.py @@ -13,7 +13,7 @@ # limitations under the License. from kilostar.core.postgres_database.model.system_node import SystemNodeConfig -from sqlmodel import select +from sqlalchemy import select from typing import List, Optional from kilostar.core.postgres_database.database_exception import database_exception diff --git a/kilostar/core/postgres_database/module/user.py b/kilostar/core/postgres_database/module/user.py index 969174d..fd1f315 100644 --- a/kilostar/core/postgres_database/module/user.py +++ b/kilostar/core/postgres_database/module/user.py @@ -13,7 +13,7 @@ # limitations under the License. from kilostar.core.postgres_database.model.user import User -from sqlmodel import select +from sqlalchemy import select from kilostar.utils.error import UserNotExistError, UserPasswordError from kilostar.core.postgres_database.database_exception import database_exception from kilostar.core.postgres_database.model.user import UserAuthority diff --git a/kilostar/core/postgres_database/postgres.py b/kilostar/core/postgres_database/postgres.py index 68f38ce..e2ffef8 100644 --- a/kilostar/core/postgres_database/postgres.py +++ b/kilostar/core/postgres_database/postgres.py @@ -18,7 +18,7 @@ import asyncio import ray from sqlalchemy.ext.asyncio import create_async_engine, AsyncSession from sqlalchemy.orm import sessionmaker -from sqlmodel import SQLModel +from kilostar.core.postgres_database.model.base import BaseDataModel from .module.individual import IndividualDatabase from .module.event import EventDatabase @@ -64,7 +64,7 @@ class PostgresDatabase: Returns: (None): 经由当前业务模型加工处理后所输出的具体数据实例或领域模型对象。""" try: async with self.async_engine.begin() as conn: - await conn.run_sync(SQLModel.metadata.create_all) + await conn.run_sync(BaseDataModel.metadata.create_all) except Exception as e: # Provide a warning if the database is not accessible, allowing # the app to start up for development/UI tests without crashing immediately. diff --git a/tests/core/workflow/workflow_test.py b/tests/core/workflow/workflow_test.py deleted file mode 100644 index 0b8721f..0000000 --- a/tests/core/workflow/workflow_test.py +++ /dev/null @@ -1,82 +0,0 @@ -import pytest -from kilostar.core.workflow_running_engine.workflow import ( - WorkStep, - kilostarWorkflow, - WorkflowStatus, - LogicGate, -) - - -def test_work_step(): - ws = WorkStep( - step=1, - name="step1", - node="control_node", - action="coding", - desc="Write some code", - ) - assert ws.step == 1 - assert ws.name == "step1" - assert ws.node == "control_node" - assert ws.action == "coding" - assert ws.desc == "Write some code" - assert ws.status == "waiting" - - -def test_kilostar_workflow_validation_success(): - ws1 = WorkStep(step=1, name="s1", node="control_node", action="a1", desc="d1") - ws2 = WorkStep(step=2, name="s2", node="regulatory_node", action="a2", desc="d2") - wf = kilostarWorkflow( - title="wf1", - work_link=[ws1, ws2], - trace_id="t", - event_info={"platform": "a", "user_name": "b"}, - ) - assert wf.title == "wf1" - - -def test_kilostar_workflow_validation_error_step_discontinuous(): - ws1 = WorkStep(step=1, name="s1", node="control_node", action="a1", desc="d1") - ws2 = WorkStep(step=3, name="s3", node="regulatory_node", action="a2", desc="d2") - with pytest.raises(ValueError, match="工作链步数不连续"): - kilostarWorkflow( - title="wf1", - work_link=[ws1, ws2], - trace_id="t", - event_info={"platform": "a", "user_name": "b"}, - ) - - -def test_kilostar_workflow_validation_error_jump_out_of_bounds(): - lg = LogicGate(if_fail="jump_to_step_3", if_pass="continue") - ws1 = WorkStep( - step=1, name="s1", node="control_node", action="a1", desc="d1", logic_gate=lg - ) - ws2 = WorkStep(step=2, name="s2", node="regulatory_node", action="a2", desc="d2") - with pytest.raises(ValueError, match="跳转目标 Step 3 越界了"): - kilostarWorkflow( - title="wf1", - work_link=[ws1, ws2], - trace_id="t", - event_info={"platform": "a", "user_name": "b"}, - ) - - -def test_kilostar_workflow_validation_error_jump_format_error(): - lg = LogicGate(if_fail="jump_to_step_invalid", if_pass="continue") - ws1 = WorkStep( - step=1, name="s1", node="control_node", action="a1", desc="d1", logic_gate=lg - ) - with pytest.raises(ValueError, match="LogicGate 格式错误"): - kilostarWorkflow( - title="wf1", - work_link=[ws1], - trace_id="t", - event_info={"platform": "a", "user_name": "b"}, - ) - - -def test_workflow_status(): - status = WorkflowStatus() - assert status.step == 1 - assert status.status == "waiting_llm_working"