zizi 091b66a9bb 重构: 收敛 Agent/Skill 运行时与创作质量闭环
将角色与 Skill 从 .claude 迁入 .agent,移除 Claude CLI 运行时并接入固定 Opus 角色 profile、完整 schema、预算 deadline、raw 与回执证据链。

同步拆分 Skill 职责、复利 lesson、Gate 回放、Dashboard 人审入口、数据库登记和机械门禁;候选设计正文不包含在本提交中。
2026-08-22 02:12:32 +08:00

55 lines
2.0 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env python3
"""db execparams 参数装载逻辑离线自测(不连库)。
跑法(仓库根目录):.venv/bin/python tests/skills/access-database/test_db_params.py
"""
import io
import json
import sys
from pathlib import Path
PROJECT_ROOT = Path(__file__).resolve().parents[3]
SCRIPTS_DIR = PROJECT_ROOT / ".agent" / "skills" / "access-database" / "scripts"
sys.path.insert(0, str(SCRIPTS_DIR))
import click # noqa: E402
import db # noqa: E402
def expect_exc(fn, msg):
try:
fn()
except click.ClickException:
return
raise AssertionError(f"应抛 ClickException:{msg}")
def main():
# --param 按序
assert db._read_params(False, ("a", "b")) == ["a", "b"]
assert db._read_params(False, ()) == []
# --stdin 合法 JSON 数组(含 null/数字)
assert db._read_params(True, (), stream=io.StringIO('["x", 1, null]')) == ["x", 1, None]
# 大对象(含中文引号/换行)经 stdin 不破坏
big = '中文"引号"\n换行\\反斜杠' * 5000
assert db._read_params(True, (), stream=io.StringIO(json.dumps([big])))[0] == big
# --stdin 与 --param 互斥
expect_exc(lambda: db._read_params(True, ("a",)), "--stdin 与 --param 互斥")
# 非法 JSON
expect_exc(lambda: db._read_params(True, (), stream=io.StringIO("not json")), "非法 JSON")
# 非数组
expect_exc(lambda: db._read_params(True, (), stream=io.StringIO('{"a":1}')), "非数组")
# exec / execparams:拒绝 DDL 与裸 DELETE
expect_exc(lambda: db._guard_exec("CREATE TABLE t (id int)"), "exec 拒 DDL")
expect_exc(lambda: db._guard_exec("DELETE FROM t"), "exec 拒裸 DELETE")
expect_exc(lambda: db._guard_execparams("ALTER TABLE t ADD COLUMN x int"), "execparams 拒 DDL")
expect_exc(lambda: db._guard_execparams("DELETE FROM t"), "execparams 拒裸 DELETE")
db._guard_exec("UPDATE t SET x=1 WHERE id=1")
db._guard_execparams("DELETE FROM t WHERE id=%s")
print("PASS:db execparams 参数装载与写守卫全部通过")
if __name__ == "__main__":
main()