Fix automation test output when loop max iterations or failure condition hit.

This commit is contained in:
Sam Rose 2025-03-04 16:49:20 +00:00
parent daa4b1e397
commit b8c5c7cfe2
No known key found for this signature in database
2 changed files with 30 additions and 0 deletions

View File

@ -195,7 +195,34 @@ describe("Attempt to run a basic loop automation", () => {
.serverLog({ text: "{{steps.1.iterations}}" })
.test({ fields: {} })
expect(results.steps[0].outputs.status).toBe(
AutomationStepStatus.MAX_ITERATIONS
)
expect(results.steps[0].outputs.iterations).toBe(2)
expect(results.steps[0].outputs.items).toHaveLength(2)
expect(results.steps[0].outputs.items[0].message).toEndWith("test")
expect(results.steps[0].outputs.items[1].message).toEndWith("test2")
})
it("should stop when a failure condition is hit", async () => {
const results = await createAutomationBuilder(config)
.onAppAction()
.loop({
option: LoopStepType.ARRAY,
binding: ["test", "test2", "test3"],
failure: "test3",
})
.serverLog({ text: "{{loop.currentItem}}" })
.serverLog({ text: "{{steps.1.iterations}}" })
.test({ fields: {} })
expect(results.steps[0].outputs.status).toBe(
AutomationStepStatus.FAILURE_CONDITION
)
expect(results.steps[0].outputs.iterations).toBe(2)
expect(results.steps[0].outputs.items).toHaveLength(2)
expect(results.steps[0].outputs.items[0].message).toEndWith("test")
expect(results.steps[0].outputs.items[1].message).toEndWith("test2")
})
it("should run an automation with loop and max iterations to ensure context correctness further down the tree", async () => {

View File

@ -478,6 +478,7 @@ class Orchestrator {
return stepFailure(stepToLoop, {
status: AutomationStepStatus.MAX_ITERATIONS,
iterations,
items,
})
}
@ -488,6 +489,8 @@ class Orchestrator {
})
return stepFailure(stepToLoop, {
status: AutomationStepStatus.FAILURE_CONDITION,
iterations,
items,
})
}