mirror of
https://github.com/ThearchyHelios/AgentLab.git
synced 2026-11-24 15:52:01 +00:00
驳回不再记成失败(后端):人的驳回收成 cancelled + end_reason=rejected,消费方都读这一个字段
为什么:动作确认、工具 / 代码审批、审批驳回即终止、填写 / 编辑被驳回、双盲裁决的驳回以前抛普通 NodeError,运行记成 failed。 通知推「实例失败」,定时推「运行失败」,发布单把驳回过的试运行说成「试运行失败了」并挡住发布,记录页还给「继续运行」 (接着跑只会读到同一个驳回答复、再停一次)。人的决定被说成故障,每个消费方各写一份映射,已经漏了四处(05-已知遗留 (a)、总方案 X9)。 做了什么: - engine/context 新增 NodeRejected(NodeError),带 node_id、kind、decision(reject / expired_reject)、actor、note;六处驳回改抛它, 原话一字不变。待办超时驳回的答复带 expired,Decision.expired 据此记成 expired_reject。 - runner._drive 在通用 except 之前单独接住:status=cancelled、end_reason=rejected、error 写原话、error_node 写那一步, run.cancelled 带 reason/node_id/label/kind/decision/actor/note;关审批、回收沙箱、关流、封存走取消的那一套。手动停止 (执行中取消、放弃断点上的运行)写 end_reason=stopped,run.cancelled 带 reason=stopped。 - 继续运行:被驳回的 409 code=run_rejected「被驳回的运行不能接着跑:改好内容后重新发起」;存量 failed+驳回(失败那一步上 最近一条处理完的待办是驳回,和实例页同一份判断 resolve.legacy_rejected)也拒。RunOut 带 end_reason。 - apps/resolve.instance_state:cancelled+rejected 和存量 failed+驳回说同一句(「「付款」未确认(被驳回)」「「x」被驳回」)。 - notify_run:状态那一句取自 instance_state,被驳回的走「实例结束」、ok=False,走到「已退回」成果的不再写「已完成」; 手动停止照旧不推。顺带修 04-对外集成与触达 B1:发起人是认证身份(run.origin.actor_verified)时 users 传 [started_by], 个人渠道订阅了实例完成 / 失败终于收得到;自报署名不算。 - 定时 webhook:cancelled+rejected 按「运行结束」推「未出具(被驳回)」、写驳回的那一步,不写备注和原话、不画成功色; 手动停止仍不推。 - 发布单:试运行被驳回不算 plan.trial_failed,记 warning plan.trial_rejected「最近一次试运行在「x」被驳回、没有走完」(带白话)。 - (h) 重启时排队中的运行改成 failed 时补发 run.failed(同一句原因),时间线里有了失败原因这一行;不写结束时间、不封存,同以前。 - (f) tasks.tick / actions.tick 交回这一拍处理过的 id 列表(调度循环只记条数),测试改成只断言自己造的待办;先加了预置 一条无关到期待办的 fixture,旧的按条数断言当场失败(3 == 1),改完通过。 已封存的老运行不改写。测试:新增 test_run_rejected(五种关卡参数化、超时驳回、继续运行拒绝含存量、手动停止、补发 run.failed、 instance_state 新老形状同一句)、test_notify_run(驳回走实例结束、手动停止不推、已退回不写已完成、个人渠道 B1 两条); webhook、发布单、动作确认、双盲、审批的老断言跟上。去掉 runner 里接 NodeRejected 的分支回跑,新测试 8 条失败。
This commit is contained in:
@@ -271,7 +271,24 @@ async def test_login_on_only_assignees_can_respond():
|
||||
# --------------------------------------------------------------------------
|
||||
|
||||
|
||||
async def test_escalation_adds_the_director_whose_answer_decides():
|
||||
@pytest.fixture
|
||||
async def stray_due_task():
|
||||
"""别的测试留下的、早就到期、可升级的待办(-n 8 下同一个库里常有)。tick 扫全库,按条数断言的测试会被它带偏:
|
||||
这里先放一条,测试只断言自己造的那条在不在 tick 交回的 id 里(05-已知遗留 (f))。"""
|
||||
async with SessionLocal() as session:
|
||||
run = Run(workflow_name="别的测试留下的", status="interrupted", graph={}, input={})
|
||||
session.add(run)
|
||||
await session.flush()
|
||||
task = Task(run_id=run.id, node_id="x", kind="approve", title="残留", due_at=utcnow() - timedelta(days=1),
|
||||
on_timeout={"action": "escalate", "to_slot": "nobody"})
|
||||
session.add(task)
|
||||
await session.commit()
|
||||
yield task.id
|
||||
await session.execute(delete(Run).where(Run.id == run.id))
|
||||
await session.commit()
|
||||
|
||||
|
||||
async def test_escalation_adds_the_director_whose_answer_decides(stray_due_task):
|
||||
a, b, g, boss = f"a{_u()}", f"b{_u()}", f"finance{_u()}", f"boss{_u()}"
|
||||
await _people(a, b, group=g)
|
||||
run_id = await _app_run(
|
||||
@@ -280,9 +297,9 @@ async def test_escalation_adds_the_director_whose_answer_decides():
|
||||
{"finance": [{"kind": "group", "name": g}], "director": [{"kind": "user", "name": boss}]})
|
||||
task = await _task(run_id)
|
||||
assert task.due_at is not None
|
||||
assert await tasks.tick(utcnow()) == 0 # 还没到时限
|
||||
assert await tasks.tick(utcnow() + timedelta(hours=2)) == 1
|
||||
assert await tasks.tick(utcnow() + timedelta(hours=3)) == 0 # 只升一次
|
||||
assert task.id not in await tasks.tick(utcnow()) # 还没到时限
|
||||
assert task.id in await tasks.tick(utcnow() + timedelta(hours=2))
|
||||
assert task.id not in await tasks.tick(utcnow() + timedelta(hours=3)) # 只升一次
|
||||
detail = await tasks.detail(task.id, off(None))
|
||||
assert detail["escalation_level"] == 1 and detail["status"] == "pending"
|
||||
assert ("user", boss, "escalation") in [(x["principal_kind"], x["principal"], x["source"])
|
||||
@@ -293,13 +310,13 @@ async def test_escalation_adds_the_director_whose_answer_decides():
|
||||
assert (await _wait(run_id, ("succeeded", "failed"))).output.get("结论") == "通过"
|
||||
|
||||
|
||||
async def test_timeout_reject_never_approves():
|
||||
async def test_timeout_reject_never_approves(stray_due_task):
|
||||
run = await run_manager.start(
|
||||
graph=approval_flow(due="PT30M", on_timeout={"action": "reject"}), input_payload={"q": "x"})
|
||||
await _wait(run.id, ("interrupted",))
|
||||
await run_manager.wait_idle(run.id)
|
||||
task = await _task(run.id)
|
||||
assert await tasks.tick(utcnow() + timedelta(hours=1)) == 1
|
||||
assert task.id in await tasks.tick(utcnow() + timedelta(hours=1))
|
||||
final = await _wait(run.id, ("succeeded", "failed"))
|
||||
assert final.output.get("结论") == "退回"
|
||||
assert len(await _events(run.id, "task.expired")) == 1
|
||||
@@ -308,16 +325,16 @@ async def test_timeout_reject_never_approves():
|
||||
assert row.status == "resolved" and row.outcome["decision"] == "expired_reject"
|
||||
|
||||
|
||||
async def test_remind_repeats_every_interval():
|
||||
async def test_remind_repeats_every_interval(stray_due_task):
|
||||
run = await run_manager.start(
|
||||
graph=approval_flow(due="PT1H", on_timeout={"action": "remind", "every": "PT1H"}), input_payload={"q": "x"})
|
||||
await _wait(run.id, ("interrupted",))
|
||||
await run_manager.wait_idle(run.id)
|
||||
task = await _task(run.id)
|
||||
later = utcnow() + timedelta(hours=1, minutes=1)
|
||||
assert await tasks.tick(later) == 1
|
||||
assert await tasks.tick(later) == 0
|
||||
assert await tasks.tick(later + timedelta(hours=1)) == 1
|
||||
assert task.id in await tasks.tick(later)
|
||||
assert task.id not in await tasks.tick(later)
|
||||
assert task.id in await tasks.tick(later + timedelta(hours=1))
|
||||
assert len(await _events(run.id, "task.reminded")) == 2
|
||||
async with SessionLocal() as session:
|
||||
assert (await session.get(Task, task.id)).status == "pending"
|
||||
|
||||
Reference in New Issue
Block a user