sync snapshot from LAN repo (source codex/merge-tjlnew-classic-retrieval-20261019 @ ded012d9)
This commit is contained in:
1 parent
ea9dcff9c0
commit
c753e6c9b5
818 files changed
+14037
-108991
No files matched your search
@@ -8,6 +8,11 @@ from alembic import command
|
||||
from alembic.config import Config
|
||||
from sqlalchemy.ext.asyncio import async_sessionmaker, create_async_engine
|
||||
|
||||
from deerflow.persistence.base import Base
|
||||
from deerflow.persistence.llmwiki.memory import MemoryLlmWikiStore
|
||||
from deerflow.persistence.llmwiki.model import LlmWikiKnowledgeBaseRow
|
||||
from deerflow.persistence.llmwiki.sql import LlmWikiRepository
|
||||
|
||||
_EDGE_INDEXES = {
|
||||
"ix_llmwiki_wiki_edges_knowledge_base_mapping_id",
|
||||
"ix_llmwiki_wiki_edges_source_page_id",
|
||||
@@ -157,12 +162,7 @@ def test_duplicate_historical_stamps_reconcile_to_single_head(
|
||||
inspector = sa.inspect(connection)
|
||||
assert connection.execute(
|
||||
sa.text("SELECT version_num FROM alembic_version")
|
||||
).scalar_one() == "20261102_02"
|
||||
assert inspector.has_table("task_deeplink_threads")
|
||||
assert connection.execute(
|
||||
sa.text("SELECT COUNT(*) FROM task_deeplink_threads")
|
||||
).scalar_one() == 0
|
||||
assert inspector.has_table("task_deeplink_details")
|
||||
).scalar_one() == "20261019_01"
|
||||
|
||||
assert inspector.has_table("llmwiki_wiki_edges")
|
||||
assert _EDGE_INDEXES <= {
|
||||
@@ -183,7 +183,6 @@ def test_duplicate_historical_stamps_reconcile_to_single_head(
|
||||
assert {
|
||||
"model_name",
|
||||
"supports_reasoning_effort",
|
||||
"default_reasoning_effort",
|
||||
"updated_by",
|
||||
"updated_at",
|
||||
} == capability_columns.keys()
|
||||
@@ -243,218 +242,6 @@ def test_duplicate_historical_stamps_reconcile_to_single_head(
|
||||
engine.dispose()
|
||||
|
||||
|
||||
def test_conflicting_20261019_feature_stamp_reconciles_task_schema(
|
||||
tmp_path: Path,
|
||||
) -> None:
|
||||
"""旧知识迁移误用 20261019_01 时,升级仍补齐任务表且不重复加列。"""
|
||||
database = tmp_path / "conflicting-20261019-feature-stamp.db"
|
||||
_prepare_old_database(
|
||||
database,
|
||||
"20260920_01",
|
||||
has_sync_result=True,
|
||||
has_retrieval_profile=True,
|
||||
)
|
||||
config = _config(database)
|
||||
command.upgrade(config, "20261014_02")
|
||||
|
||||
engine = sa.create_engine(f"sqlite:///{database.resolve().as_posix()}")
|
||||
with engine.begin() as connection:
|
||||
inspector = sa.inspect(connection)
|
||||
assert inspector.has_table("knowledge_retrieval_settings")
|
||||
assert not inspector.has_table("task_deeplink_threads")
|
||||
connection.exec_driver_sql(
|
||||
"ALTER TABLE knowledge_retrieval_settings "
|
||||
"ADD COLUMN advanced_management_enabled BOOLEAN NOT NULL DEFAULT 0"
|
||||
)
|
||||
connection.exec_driver_sql(
|
||||
"INSERT INTO knowledge_retrieval_settings "
|
||||
"(scope, smart_reasoning_enabled, advanced_management_enabled, "
|
||||
"revision, updated_at) VALUES "
|
||||
"('global', 1, 1, 2, '2026-10-19 00:00:00')"
|
||||
)
|
||||
connection.exec_driver_sql("DELETE FROM alembic_version")
|
||||
connection.exec_driver_sql(
|
||||
"INSERT INTO alembic_version (version_num) VALUES ('20261019_01')"
|
||||
)
|
||||
engine.dispose()
|
||||
|
||||
command.upgrade(config, "head")
|
||||
command.upgrade(config, "head")
|
||||
|
||||
engine = sa.create_engine(f"sqlite:///{database.resolve().as_posix()}")
|
||||
with engine.connect() as connection:
|
||||
inspector = sa.inspect(connection)
|
||||
assert connection.execute(
|
||||
sa.text("SELECT version_num FROM alembic_version")
|
||||
).scalar_one() == "20261102_02"
|
||||
|
||||
retrieval_columns = [
|
||||
str(item["name"])
|
||||
for item in inspector.get_columns("knowledge_retrieval_settings")
|
||||
]
|
||||
assert retrieval_columns.count("advanced_management_enabled") == 1
|
||||
assert connection.execute(
|
||||
sa.text(
|
||||
"SELECT advanced_management_enabled "
|
||||
"FROM knowledge_retrieval_settings WHERE scope = 'global'"
|
||||
)
|
||||
).scalar_one() in (1, True)
|
||||
|
||||
assert inspector.has_table("task_deeplink_threads")
|
||||
task_columns = {
|
||||
str(item["name"]) for item in inspector.get_columns("task_deeplink_threads")
|
||||
}
|
||||
assert {"sub_type", "display_name", "status", "metadata_json"} <= task_columns
|
||||
task_indexes = {
|
||||
str(item["name"]): [str(column) for column in item["column_names"]]
|
||||
for item in inspector.get_indexes("task_deeplink_threads")
|
||||
}
|
||||
assert task_indexes["ix_task_deeplink_threads_scope"] == [
|
||||
"task_id",
|
||||
"go_path",
|
||||
"sub_type",
|
||||
"updated_at",
|
||||
"thread_id",
|
||||
]
|
||||
assert task_indexes["ix_task_deeplink_threads_task_go_updated"] == [
|
||||
"task_id",
|
||||
"go_path",
|
||||
"updated_at",
|
||||
"thread_id",
|
||||
]
|
||||
engine.dispose()
|
||||
|
||||
|
||||
def test_broken_two_column_detail_key_is_repaired_at_head(tmp_path: Path) -> None:
|
||||
"""20261022_02 的中间版本只加了列没换成三列主键(batch API 不存在)。
|
||||
|
||||
这类库 alembic_version 已到 head 但键仍是两列,typed upsert 必炸
|
||||
UNIQUE 约束。兜底修复迁移应把键换成三列且保留旧数据。用最小库直接
|
||||
从坏状态升级(不跑全链,链上其它迁移依赖 create_all 的表)。
|
||||
"""
|
||||
database = tmp_path / "broken-detail-key.db"
|
||||
engine = sa.create_engine(f"sqlite:///{database.resolve().as_posix()}")
|
||||
try:
|
||||
with engine.begin() as connection:
|
||||
connection.exec_driver_sql(
|
||||
"CREATE TABLE alembic_version (version_num VARCHAR(32) NOT NULL PRIMARY KEY)"
|
||||
)
|
||||
connection.exec_driver_sql(
|
||||
"INSERT INTO alembic_version (version_num) VALUES ('20261023_02')"
|
||||
)
|
||||
# 「半执行」现场:sub_type 列存在,主键仍是两列,有一行旧快照。
|
||||
connection.exec_driver_sql(
|
||||
"CREATE TABLE task_deeplink_details ("
|
||||
"detail_type VARCHAR(32) NOT NULL, "
|
||||
"detail_id VARCHAR(128) NOT NULL, "
|
||||
"task_name VARCHAR(512) NOT NULL, "
|
||||
"task_content TEXT NOT NULL, "
|
||||
"overview TEXT NOT NULL, "
|
||||
"extra_json JSON NOT NULL, "
|
||||
"version INTEGER NOT NULL, "
|
||||
"created_by VARCHAR(64), "
|
||||
"updated_by VARCHAR(64), "
|
||||
"created_at DATETIME NOT NULL, "
|
||||
"updated_at DATETIME NOT NULL, "
|
||||
"sub_type VARCHAR(64) NOT NULL DEFAULT '', "
|
||||
"PRIMARY KEY (detail_type, detail_id))"
|
||||
)
|
||||
connection.exec_driver_sql(
|
||||
"INSERT INTO task_deeplink_details "
|
||||
"(detail_type, detail_id, task_name, task_content, overview, "
|
||||
"extra_json, version, created_at, updated_at, sub_type) VALUES "
|
||||
"('b5-1', '001', '旧任务', '旧详情', '', '{}', 1, "
|
||||
"CURRENT_TIMESTAMP, CURRENT_TIMESTAMP, '')"
|
||||
)
|
||||
finally:
|
||||
engine.dispose()
|
||||
|
||||
command.upgrade(_config(database), "head")
|
||||
|
||||
engine = sa.create_engine(f"sqlite:///{database.resolve().as_posix()}")
|
||||
try:
|
||||
with engine.connect() as connection:
|
||||
inspector = sa.inspect(connection)
|
||||
pk = [
|
||||
str(column)
|
||||
for column in inspector.get_pk_constraint("task_deeplink_details")[
|
||||
"constrained_columns"
|
||||
]
|
||||
]
|
||||
assert pk == ["detail_type", "detail_id", "sub_type"]
|
||||
assert connection.execute(
|
||||
sa.text(
|
||||
"SELECT detail_type, detail_id, sub_type, task_name "
|
||||
"FROM task_deeplink_details"
|
||||
)
|
||||
).fetchall() == [("b5-1", "001", "", "旧任务")]
|
||||
finally:
|
||||
engine.dispose()
|
||||
|
||||
|
||||
def test_custom_business_mapping_migration_preserves_existing_rows(tmp_path: Path) -> None:
|
||||
"""The new type columns and widened history key upgrade a populated install."""
|
||||
database = tmp_path / "custom-business-mapping.db"
|
||||
engine = sa.create_engine(f"sqlite:///{database.resolve().as_posix()}")
|
||||
try:
|
||||
with engine.begin() as connection:
|
||||
connection.exec_driver_sql(
|
||||
"CREATE TABLE alembic_version (version_num VARCHAR(32) NOT NULL PRIMARY KEY)"
|
||||
)
|
||||
connection.exec_driver_sql(
|
||||
"INSERT INTO alembic_version (version_num) VALUES ('20261102_01')"
|
||||
)
|
||||
connection.exec_driver_sql(
|
||||
"CREATE TABLE business_mapping ("
|
||||
"business_code VARCHAR(32) PRIMARY KEY, label VARCHAR(128) NOT NULL, "
|
||||
"agent_id VARCHAR(64), agent_name VARCHAR(191), chain_id VARCHAR(64), "
|
||||
"chain_title VARCHAR(512), sort_order INTEGER NOT NULL, "
|
||||
"created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL)"
|
||||
)
|
||||
connection.exec_driver_sql(
|
||||
"INSERT INTO business_mapping "
|
||||
"(business_code, label, sort_order, created_at, updated_at) VALUES "
|
||||
"('3Q', '3QFX', 0, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP)"
|
||||
)
|
||||
connection.exec_driver_sql(
|
||||
"CREATE TABLE task_deeplink_threads ("
|
||||
"thread_id VARCHAR(64) PRIMARY KEY, task_id VARCHAR(128) NOT NULL, "
|
||||
"source_task_id VARCHAR(128) NOT NULL, go_path VARCHAR(16) NOT NULL, "
|
||||
"sub_type VARCHAR(64) NOT NULL DEFAULT '', agent_id VARCHAR(128), "
|
||||
"display_name VARCHAR(256), status VARCHAR(20) NOT NULL DEFAULT 'idle', "
|
||||
"metadata_json JSON, created_by VARCHAR(64), "
|
||||
"created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL)"
|
||||
)
|
||||
connection.exec_driver_sql(
|
||||
"INSERT INTO task_deeplink_threads "
|
||||
"(thread_id, task_id, source_task_id, go_path, created_at, updated_at) VALUES "
|
||||
"('thread-1', 'task-1', 'task-1', '3qfx', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP)"
|
||||
)
|
||||
|
||||
command.upgrade(_config(database), "head")
|
||||
|
||||
with engine.connect() as connection:
|
||||
inspector = sa.inspect(connection)
|
||||
mapping_columns = {
|
||||
str(column["name"]): column for column in inspector.get_columns("business_mapping")
|
||||
}
|
||||
assert {"mapping_type", "is_custom"} <= mapping_columns.keys()
|
||||
assert connection.execute(
|
||||
sa.text(
|
||||
"SELECT mapping_type, is_custom FROM business_mapping "
|
||||
"WHERE business_code = '3Q'"
|
||||
)
|
||||
).one() == ("内置业务", 0)
|
||||
assert connection.execute(
|
||||
sa.text("SELECT go_path FROM task_deeplink_threads WHERE thread_id = 'thread-1'")
|
||||
).scalar_one() == "3qfx"
|
||||
assert connection.execute(
|
||||
sa.text("SELECT version_num FROM alembic_version")
|
||||
).scalar_one() == "20261102_02"
|
||||
finally:
|
||||
engine.dispose()
|
||||
|
||||
|
||||
async def _exercise_parent_directories(store) -> str:
|
||||
configured = ["专题资料", "政策法规"]
|
||||
directory_paths = [["专题资料"], ["专题资料", "国内政策"]]
|
||||
@@ -526,8 +313,6 @@ async def _exercise_parent_directories(store) -> str:
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_memory_llmwiki_parent_directories_persistence() -> None:
|
||||
from deerflow.persistence.llmwiki.memory import MemoryLlmWikiStore
|
||||
|
||||
store = MemoryLlmWikiStore()
|
||||
|
||||
mapping_id = await _exercise_parent_directories(store)
|
||||
@@ -544,10 +329,6 @@ async def test_memory_llmwiki_parent_directories_persistence() -> None:
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_sql_llmwiki_parent_directories_persistence(tmp_path: Path) -> None:
|
||||
from deerflow.persistence.base import Base
|
||||
from deerflow.persistence.llmwiki.model import LlmWikiKnowledgeBaseRow
|
||||
from deerflow.persistence.llmwiki.sql import LlmWikiRepository
|
||||
|
||||
engine = create_async_engine(
|
||||
f"sqlite+aiosqlite:///{tmp_path / 'llmwiki-parent-directories.db'}"
|
||||
)
|
||||
|
||||
Reference in new issue
Block a user