From 49a6001dde72622df9410b738322e9a23e68ddee Mon Sep 17 00:00:00 2001 From: t Date: Fri, 21 Aug 2026 11:26:48 -0600 Subject: Add workflow cancellation controls --- spec/test_luatool.lua | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'spec/test_luatool.lua') diff --git a/spec/test_luatool.lua b/spec/test_luatool.lua index 62f9283..509b804 100644 --- a/spec/test_luatool.lua +++ b/spec/test_luatool.lua @@ -165,6 +165,46 @@ return { end) end }, + { "public workflow records cancel agents or every running agent", function() + with_host(function(handle, profiles) + handle.ext.workflows = workflow.workflows + handle.queue_for("alpha", { settle = 100000 }) + handle.queue_for("beta", { settle = 100000 }) + local id = luatool.handle({ source = [[ + return subagents.workflow(function(ctx) + local alpha = ctx:agent{name="alpha", agent="alpha", prompt="alpha"} + local beta = ctx:agent{name="beta", agent="beta", prompt="beta"} + ctx:await({alpha, beta}, "all") + return "completed" + end) + ]] }, profiles) + + local record = handle.ext.workflows[id] + for _ = 1, 100 do + uv.run("nowait") + if record.agents.alpha and record.agents.beta then break end + uv.sleep(1) + end + assert(type(record.cancel) == "function", "workflow exposes cancel") + assert(type(record.agents.alpha.cancel) == "function", "agent exposes cancel") + assert(record.agents.alpha:cancel(), "an in-flight agent accepts cancellation") + + for _ = 1, 100 do + uv.run("nowait") + if record.agents.alpha.status == "cancelled" then break end + uv.sleep(1) + end + assert(record.agents.alpha.status == "cancelled") + assert(record.agents.beta.status == "running") + assert(record:cancel(), "an in-flight workflow accepts cancellation") + + record = pump(id) + assert(record.status == "cancelled", tostring(record.error)) + assert(record.agents.beta.status == "cancelled") + assert(record:cancel() == false, "terminal workflows ignore cancellation") + end) + end }, + { "agent names are required and unique within a workflow", function() with_host(function(handle, profiles) local id = luatool.handle({ source = [[ -- cgit v1.3