From 432e038e3ccfedd503480df6f0e499c47985c8b5 Mon Sep 17 00:00:00 2001 From: yu <191972707@qq.com> Date: Wed, 28 Oct 2026 13:08:53 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E6=AD=A3=E9=81=8D=E5=8E=86?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E8=B4=9F=E6=95=B0=E7=BB=93=E6=9D=9F=E7=B4=A2?= =?UTF-8?q?=E5=BC=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/engine/runtime.integration.test.ts | 22 +++++++++++++++++++++ src/main/engine/runtime.ts | 3 ++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/main/engine/runtime.integration.test.ts b/src/main/engine/runtime.integration.test.ts index 3db97aa..3768d11 100644 --- a/src/main/engine/runtime.integration.test.ts +++ b/src/main/engine/runtime.integration.test.ts @@ -197,6 +197,28 @@ describe("runFlow integration", () => { expect(events.filter((event) => event.type === "node.started" && event.nodeId === "accumulate")).toHaveLength(3); }); + it("runs an array loop through the last item when end_index is -1", async () => { + const loop = node("loop", "logic_control_array_for_v3", { + array_name: "items", + reverse: false, + start_index: 0, + end_index: -1 + }); + const definition = flow("array-loop-flow", [ + loop, + node("collect", "Basic_DebugOutput", { msg: "${item}" }, {}, { + parentId: loop.id, + slot: "array_for_fn" + }) + ]); + + const { result, events } = await execute(definition, { items: ["glm", "mini", "other", "kimi"] }); + + expect(result.status).toBe("succeeded"); + expect(result.nodes.find((state) => state.nodeId === "loop")?.output).toBe(4); + expect(events.filter((event) => event.type === "node.started" && event.nodeId === "collect").map((event) => event.nodeId)).toHaveLength(4); + }); + it("retries a transient failure and records the successful attempt", async () => { const component = testComponent("Test.TransientFailure"); let calls = 0; diff --git a/src/main/engine/runtime.ts b/src/main/engine/runtime.ts index 9b7a7c4..d3e8edd 100644 --- a/src/main/engine/runtime.ts +++ b/src/main/engine/runtime.ts @@ -409,7 +409,8 @@ async function executeContainer( const list = asArray(value); const reverse = String(node.values?.reverse ?? "") === "true" || String(node.values?.reverse ?? "") === "1"; const start = Math.max(0, toNumber(node.values?.start_index, 0)); - const end = node.values?.end_index === "" || node.values?.end_index == null ? list.length : toNumber(node.values?.end_index, list.length); + const requestedEnd = node.values?.end_index === "" || node.values?.end_index == null ? list.length : toNumber(node.values?.end_index, list.length); + const end = requestedEnd < 0 ? Math.max(start, list.length + requestedEnd + 1) : requestedEnd; const slice = (reverse ? [...list].reverse() : list).slice(start, end); let iterations = 0; for (let index = 0; index < slice.length; index += 1) {