import test from "node:test"; import assert from "node:assert/strict"; import { buildSelectedNodeEnvRows, getWorkflowEditorLockState, isWorkflowSettingsLocked, } from "../../src/lib/workflow-editor.js"; test("workflow settings lock while an active run is still in flight", () => { assert.equal( isWorkflowSettingsLocked({ isReadOnly: false, activeRunStatus: "running", isRunContextLoading: false, }), true, ); }); test("workflow settings lock only for readonly or active workflows", () => { assert.equal( isWorkflowSettingsLocked({ isReadOnly: false, activeRunStatus: "completed", isRunContextLoading: false, }), false, ); assert.equal( isWorkflowSettingsLocked({ isReadOnly: true, activeRunStatus: "", isRunContextLoading: false, }), true, ); assert.equal( isWorkflowSettingsLocked({ isReadOnly: false, activeRunStatus: "", isRunContextLoading: false, }), false, ); }); test("terminal runs release every editor mutation lock", () => { for (const activeRunStatus of ["completed", "failed", "cancelled", ""]) { assert.deepEqual( getWorkflowEditorLockState({ isReadOnly: false, activeRunStatus, isRunContextLoading: false, }), { locked: false, reason: "ready", message: "" }, ); } }); test("node env rows include inherited workflow envs but keep node overrides first", () => { const rows = buildSelectedNodeEnvRows({ nodeHyperparams: [ { key: "GLOBAL_ENV", value: "node-level" }, { key: "NODE_ONLY", value: "yes" }, ], workflowHyperparams: [ { key: "GLOBAL_ENV", value: "workflow-level" }, { key: "WORKFLOW_ONLY", value: "shared" }, ], systemRows: [{ key: "WORKFLOW_CURRENT_RUN_TIMESTAMP", value: "2026-04-22T10:00:00+08:00", source: "system" }], }); assert.deepEqual( rows.map((item) => ({ key: item.key, value: item.value, source: item.source })), [ { key: "GLOBAL_ENV", value: "node-level", source: "custom" }, { key: "NODE_ONLY", value: "yes", source: "custom" }, { key: "WORKFLOW_ONLY", value: "shared", source: "workflow" }, { key: "WORKFLOW_CURRENT_RUN_TIMESTAMP", value: "2026-04-22T10:00:00+08:00", source: "system", }, ], ); });