summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
Diffstat (limited to 'spec')
-rw-r--r--spec/test_luatool.lua40
1 files changed, 40 insertions, 0 deletions
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 = [[