test(live): prepare independent AE React and Python acceptance

This commit is contained in:
Agent Workbench Dev
2026-11-06 13:01:04 +08:00
parent f5b0ffee1c
commit d4f1e42f7e
13 changed files with 244 additions and 2 deletions
@@ -0,0 +1,11 @@
# Python任务报表工程
修复normalize.py、summary.py、render.py,保留原十项测试、配置和owner文件。
normalize_tasks接收字典列表,返回新的规范化字典列表:id/title必须为非空字符串,去除首尾空白,id去空白后不可重复;done缺省False且必须为bool;hours缺省0,必须为非bool的有限非负int/float。输出仅含id/title/done/hours,输入无效统一抛ValueError,不改变原输入。
summarize_tasks接收规范化任务,返回total、completed、pending_hours;工时仅累加未完成任务,空输入返回三个0,不改变输入。
render_tasks接收规范化任务,按id升序输出每行`[x] id: title (工时h)`或`[ ] id: title (工时h)`,整数不加小数点,非整数保留有效小数,无末尾换行,空输入为空字符串。完整流程使用normalize→summary/render。
使用现成Python3.10+与pytest执行原测试,再编译三个源码模块并仅将它们提交本地Git;不推送。无需下载依赖或修改测试。已有owner暂存、未暂存和未跟踪状态必须保持。
@@ -0,0 +1,2 @@
def normalize_tasks(rows):
return []
@@ -0,0 +1,8 @@
[project]
name = "owned-python-task-report"
version = "0.1.0"
requires-python = ">=3.10"
[tool.pytest.ini_options]
testpaths = ["tests"]
pythonpath = ["."]
@@ -0,0 +1,2 @@
def render_tasks(rows):
return ""
@@ -0,0 +1,2 @@
def summarize_tasks(rows):
return {"total": 0, "completed": 0, "pending_hours": 0}
@@ -0,0 +1,63 @@
from copy import deepcopy
import pytest
from normalize import normalize_tasks
from summary import summarize_tasks
from render import render_tasks
def test_normalization_trims_and_retains_only_contract_fields():
assert normalize_tasks([{"id": " api ", "title": " 编写接口 ", "done": True, "hours": 1.5, "extra": 9}]) == [
{"id": "api", "title": "编写接口", "done": True, "hours": 1.5}]
def test_missing_optional_fields_have_stable_defaults():
assert normalize_tasks([{"id": "one", "title": "任务"}]) == [{"id": "one", "title": "任务", "done": False, "hours": 0}]
def test_invalid_containers_rows_and_strings_raise_value_error():
for value in [None, {}, "rows", [None], [{}], [{"id": " ", "title": "x"}], [{"id": "x", "title": 1}], [{"id": 1, "title": "x"}], [{"id": "x", "title": " "}]]:
with pytest.raises(ValueError):
normalize_tasks(value)
def test_duplicate_trimmed_id_is_rejected():
with pytest.raises(ValueError):
normalize_tasks([{"id": "x", "title": "a"}, {"id": " x ", "title": "b"}])
def test_status_and_hours_are_not_silently_coerced():
for extra in [{"done": "false"}, {"done": 0}, {"hours": True}, {"hours": "2"}, {"hours": -1}, {"hours": float("nan")}, {"hours": float("inf")}]:
with pytest.raises(ValueError):
normalize_tasks([{"id": "x", "title": "a", **extra}])
def test_normalization_does_not_mutate_caller_rows():
rows = [{"id": " x ", "title": " a ", "hours": 2, "done": False}]
before = deepcopy(rows)
result = normalize_tasks(rows)
assert rows == before and result is not rows and result[0] is not rows[0]
def test_summary_uses_states_and_pending_hours():
rows = [{"id": "a", "title": "A", "done": False, "hours": 2}, {"id": "b", "title": "B", "done": True, "hours": 9}, {"id": "c", "title": "C", "done": False, "hours": 1.5}]
before = deepcopy(rows)
assert summarize_tasks(rows) == {"total": 3, "completed": 1, "pending_hours": 3.5}
assert rows == before
def test_empty_summary_and_render_are_exact():
assert summarize_tasks([]) == {"total": 0, "completed": 0, "pending_hours": 0}
assert render_tasks([]) == ""
def test_report_sorts_without_mutating_and_formats_status_and_hours():
rows = [{"id": "b", "title": "乙", "done": False, "hours": 2.5}, {"id": "a", "title": "甲", "done": True, "hours": 3.0}]
before = deepcopy(rows)
assert render_tasks(rows) == "[x] a: 甲 (3h)\n[ ] b: 乙 (2.5h)"
assert rows == before
def test_complete_flow_keeps_unicode_and_exact_aggregate():
rows = normalize_tasks([{"id": " z ", "title": "检查中文🙂", "hours": 2}, {"id": "a", "title": "已验证", "done": True, "hours": 5}])
assert summarize_tasks(rows) == {"total": 2, "completed": 1, "pending_hours": 2}
assert render_tasks(rows) == "[x] a: 已验证 (5h)\n[ ] z: 检查中文🙂 (2h)"