release: v1.0.117 沉淀多数据源契约(SQLite 默认 + 可选 MySQL 云库)
All checks were successful
技能自动化发布 / release (push) Successful in 9s
All checks were successful
技能自动化发布 / release (push) Successful in 9s
新增 DATA_SOURCES.md、data-sources 示例与双后端 connection 骨架;CLI 与宿主 UI 可读写同一库。要求匠厂 Host ≥ 6.9.28。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
49
tests/test_db_backend.py
Normal file
49
tests/test_db_backend.py
Normal file
@@ -0,0 +1,49 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""数据库后端选择:默认 SQLite,DSN 解析。"""
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
import unittest
|
||||
|
||||
from _support import IsolatedDataRoot
|
||||
|
||||
|
||||
class TestDbBackend(unittest.TestCase):
|
||||
def test_resolve_backend_defaults_to_sqlite(self) -> None:
|
||||
with IsolatedDataRoot():
|
||||
from db.backend import resolve_backend
|
||||
|
||||
self.assertEqual(resolve_backend(), "sqlite")
|
||||
|
||||
def test_parse_mysql_dsn(self) -> None:
|
||||
with IsolatedDataRoot():
|
||||
from db.backend import parse_mysql_dsn
|
||||
|
||||
params = parse_mysql_dsn("mysql://root:secret@192.168.0.20:3306/demo_db")
|
||||
self.assertEqual(params["host"], "192.168.0.20")
|
||||
self.assertEqual(params["port"], 3306)
|
||||
self.assertEqual(params["user"], "root")
|
||||
self.assertEqual(params["password"], "secret")
|
||||
self.assertEqual(params["database"], "demo_db")
|
||||
|
||||
def test_resolve_backend_uses_mysql_dsn_from_env(self) -> None:
|
||||
with IsolatedDataRoot():
|
||||
from db.backend import resolve_backend
|
||||
|
||||
os.environ["MYSQL_DSN"] = "mysql://u:p@127.0.0.1:3306/t"
|
||||
try:
|
||||
self.assertEqual(resolve_backend(), "mysql")
|
||||
finally:
|
||||
os.environ.pop("MYSQL_DSN", None)
|
||||
|
||||
def test_describe_active_store_sqlite(self) -> None:
|
||||
with IsolatedDataRoot():
|
||||
from db.connection import describe_active_store
|
||||
|
||||
info = describe_active_store()
|
||||
self.assertEqual(info["backend"], "sqlite")
|
||||
self.assertIn("db_path", info)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -385,6 +385,28 @@ class TestDocsStandards(unittest.TestCase):
|
||||
):
|
||||
self.assertIn(marker, text, msg=f"SCHEMA.md missing {marker!r}")
|
||||
|
||||
def test_data_sources_md_documents_mysql_and_declaration(self) -> None:
|
||||
text = self._read("references/DATA_SOURCES.md")
|
||||
for marker in (
|
||||
"data-sources.json",
|
||||
"MYSQL_DSN",
|
||||
"6.9.28",
|
||||
"resolve_backend",
|
||||
"一个 `sourceId`",
|
||||
"process-work-order",
|
||||
"tableAdmin",
|
||||
):
|
||||
self.assertIn(marker, text, msg=f"DATA_SOURCES.md missing {marker!r}")
|
||||
self.assertTrue(os.path.isfile(os.path.join(get_skill_root(), "assets/data-sources.example.json")))
|
||||
self.assertTrue(
|
||||
os.path.isfile(os.path.join(get_skill_root(), "assets/examples/data-sources.mysql.example.json"))
|
||||
)
|
||||
env_example = self._read(".env.example")
|
||||
self.assertIn("MYSQL_DSN", env_example)
|
||||
checklist = self._read("development/CHECKLIST.md")
|
||||
self.assertIn("A6-16", checklist)
|
||||
self.assertIn("DATA_SOURCES.md", checklist)
|
||||
|
||||
def test_actions_md_documents_form_schema_split(self) -> None:
|
||||
text = self._read("references/ACTIONS.md")
|
||||
for marker in (
|
||||
|
||||
Reference in New Issue
Block a user