初始化测试通过

This commit is contained in:
2026-09-10 13:04:13 +08:00
parent ccb12dad7c
commit 9c7b27c675
40 changed files with 141 additions and 1790 deletions

View File

@@ -355,8 +355,10 @@ class TestActionsManifest(unittest.TestCase):
def test_bindable_business_tables_helper_loads_template_db(self) -> None:
"""helper 本身必须可用:模板默认无业务表,隔离库仍应可读且不含元数据表。"""
from util.constants import BUSINESS_TABLES
bindable = _load_bindable_business_tables()
self.assertEqual(bindable, set())
self.assertEqual(bindable, set(BUSINESS_TABLES))
self.assertNotIn("_jiangchang_tables", bindable)
self.assertNotIn("_jiangchang_columns", bindable)

View File

@@ -96,7 +96,7 @@ class TestCliSmoke(unittest.TestCase):
config.reset_cache()
buf = io.StringIO()
with redirect_stdout(buf), redirect_stderr(io.StringIO()):
rc = main("run")
rc = main(["run"])
self.assertNotEqual(rc, 0)
self.assertIn("模板", buf.getvalue())
finally:

View File

@@ -12,6 +12,7 @@ class TestDbSmoke(unittest.TestCase):
with IsolatedDataRoot():
from db.connection import get_conn, init_db
from db.display_metadata import METADATA_TABLES, iter_user_tables
from util.constants import BUSINESS_TABLES
init_db()
init_db()
@@ -26,9 +27,9 @@ class TestDbSmoke(unittest.TestCase):
self.assertIn("_jiangchang_tables", tables)
self.assertIn("_jiangchang_columns", tables)
self.assertNotIn("task_logs", tables)
self.assertEqual(list(iter_user_tables(cur)), [])
leftover = tables - METADATA_TABLES
self.assertEqual(leftover, set())
self.assertEqual(set(iter_user_tables(cur)), set(BUSINESS_TABLES))
leftover = set(tables) - set(METADATA_TABLES)
self.assertEqual(leftover, set(BUSINESS_TABLES))
finally:
conn.close()

View File

@@ -19,6 +19,7 @@ class TestDisplayMetadata(unittest.TestCase):
def test_init_db_metadata_idempotent(self) -> None:
with IsolatedDataRoot():
from db.connection import get_conn, init_db
from util.constants import BUSINESS_TABLES
init_db()
init_db()
@@ -27,9 +28,9 @@ class TestDisplayMetadata(unittest.TestCase):
try:
cur = conn.cursor()
cur.execute("SELECT COUNT(*) FROM _jiangchang_tables")
self.assertEqual(int(cur.fetchone()[0]), 0)
self.assertEqual(int(cur.fetchone()[0]), len(BUSINESS_TABLES))
cur.execute("SELECT COUNT(*) FROM _jiangchang_columns")
self.assertEqual(int(cur.fetchone()[0]), 0)
self.assertGreater(int(cur.fetchone()[0]), 0)
cur.execute(
"SELECT 1 FROM sqlite_master WHERE type='table' AND name='task_logs'"
)
@@ -203,12 +204,13 @@ class TestDisplayMetadata(unittest.TestCase):
with IsolatedDataRoot():
from db.connection import get_conn, init_db
from db.display_metadata import iter_user_tables
from util.constants import BUSINESS_TABLES
init_db()
conn = get_conn()
try:
tables = list(iter_user_tables(conn.cursor()))
self.assertEqual(tables, [])
self.assertEqual(set(tables), set(BUSINESS_TABLES))
finally:
conn.close()

View File

@@ -10,8 +10,8 @@ import unittest
from _support import get_skill_root
TEMPLATE_MARKER = ".openclaw-skill-template"
TEMPLATE_SLUG_KEBAB = "add-todo-all"
TEMPLATE_SLUG_UNDERSCORE = "add_todo_all"
TEMPLATE_SLUG_KEBAB = "your-skill-slug"
TEMPLATE_SLUG_UNDERSCORE = "your_skill_slug"
SCAFFOLD_TEST_SLUG = "query-demo-records"
SCAFFOLD_TEST_SLUG_UNDERSCORE = "query_demo_records"

View File

@@ -44,9 +44,9 @@ class TestSkillMetadata(unittest.TestCase):
if skill_dir == "skill-template":
# 模板仓库本体:允许占位 slug
self.assertEqual(SKILL_SLUG, "add-todo-all")
self.assertEqual(SKILL_SLUG, "your-skill-slug")
else:
self.assertNotEqual(SKILL_SLUG, "add-todo-all", "复制为真实技能后不得保留占位 slug")
self.assertNotEqual(SKILL_SLUG, "your-skill-slug", "复制为真实技能后不得保留占位 slug")
self.assertEqual(SKILL_SLUG, skill_dir)
self.assertEqual(slug_md, skill_dir)

View File

@@ -30,8 +30,8 @@ class TestSlugNaming(unittest.TestCase):
self.assertEqual(classify_slug_form(segments, slug="generate-article-all"), "scope")
def test_classify_legacy_exempt(self) -> None:
segments = parse_slug_segments("add-todo-all")
self.assertEqual(classify_slug_form(segments, slug="add-todo-all"), "legacy_exempt")
segments = parse_slug_segments("your-skill-slug")
self.assertEqual(classify_slug_form(segments, slug="your-skill-slug"), "legacy_exempt")
def test_valid_hyphenated_platform_slug(self) -> None:
slug = "fill-export-declaration-single-window"
@@ -79,7 +79,7 @@ class TestSlugNaming(unittest.TestCase):
self.assertTrue(any("48" in err for err in errors))
def test_legacy_exempt_set(self) -> None:
self.assertIn("add-todo-all", LEGACY_EXEMPT_SLUGS)
self.assertIn("your-skill-slug", LEGACY_EXEMPT_SLUGS)
self.assertIn("account-manager", LEGACY_EXEMPT_SLUGS)