初始化测试通过

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

@@ -13,6 +13,7 @@ import json
import os
import time
from typing import Any, Optional
import uuid
from jiangchang_skill_core import collect_runtime_diagnostics, config, format_runtime_health_lines
from jiangchang_skill_core.activity import JobStopped, emit, finish, job_context
@@ -68,7 +69,7 @@ async def _run_template_demo(target: Optional[str], input_id: Optional[str]) ->
def cmd_run(target: Optional[str] = None, input_id: Optional[str] = None) -> int:
"""通用任务执行入口模板。复制后请实现真实业务逻辑。"""
log = _get_task_logger()
task_type = "cmd_run"
task_type = "demo"
with job_context(skill=SKILL_SLUG):
log.info(
@@ -223,7 +224,7 @@ def cmd_add(*, title: str, priority: str = "normal", due_at: Optional[int] = Non
try:
todo = todo_service.add_todo(title=title, priority=priority, due_at=due_at)
except ValueError as exc:
print(f"ERROR:TODO_INVALID: {exc}")
_get_task_logger().error(f"ERROR:TODO_INVALID: {exc}")
return 1
_get_task_logger().info(json.dumps(todo.to_dict(), ensure_ascii=False))
return 0
@@ -266,7 +267,7 @@ async def _run_remind_async(*, seconds: int) -> dict[str, Any]:
"""
steps = max(1, int(seconds))
for i in range(1, steps + 1):
await asyncio.sleep(1)
await interruptible_sleep(1)
emit(f"提醒任务进度 {i}/{steps}", skill=SKILL_SLUG, stage="remind", progress=i, total=steps)
# 真实业务在这里会查 todos 表挑出 due/pending 项发出提醒;demo 不做真实推送
summary = todo_service.stats()

View File

@@ -10,8 +10,12 @@ from __future__ import annotations
import time
from dataclasses import dataclass
from typing import Optional
import logging
from db.connection import get_conn
from util.logging_config import get_skill_logger, setup_skill_logging
logger = logging.getLogger(__name__)
# 业务常量(不暴露给宿主,技能自定)
STATUS_PENDING = "pending"
@@ -59,8 +63,10 @@ def add_todo(
"""新增一条待办。领域校验:标题非空、优先级合法。"""
title = (title or "").strip()
if not title:
logger.warning("标题不能为空")
raise ValueError("标题不能为空")
if priority not in VALID_PRIORITY:
logger.warning(f"优先级不合法,可选:{sorted(VALID_PRIORITY)}")
raise ValueError(f"优先级不合法,可选:{sorted(VALID_PRIORITY)}")
now = _now()
conn = get_conn()
@@ -84,6 +90,7 @@ def list_todos(*, status: Optional[str] = None, limit: int = 100) -> list[Todo]:
params: list = []
if status:
if status not in VALID_STATUS:
logger.warning(f"状态不合法,可选:{sorted(VALID_STATUS)}")
raise ValueError(f"状态不合法,可选:{sorted(VALID_STATUS)}")
sql += " WHERE status = ?"
params.append(status)
@@ -118,8 +125,10 @@ def mark_done(todo_id: int) -> Todo:
"""标记一条待办为完成。"""
todo = get_todo(todo_id)
if not todo:
logger.warning(f"待办 {todo_id} 不存在")
raise ValueError(f"待办 {todo_id} 不存在")
if todo.status == STATUS_DONE:
logger.warning(f"待办 {todo_id} 已是完成状态")
raise ValueError(f"待办 {todo_id} 已是完成状态")
now = _now()
conn = get_conn()