From e586ab9bd9ad2ba3e8cb99a9e95d2c356bda63fb Mon Sep 17 00:00:00 2001 From: Andrii Arsenin Date: Wed, 30 Sep 2026 21:07:15 +0300 Subject: [PATCH] fix(scenarios): preselect default environment when opening run modal - choose the scenario's default environment when the run modal opens on the scenario detail page, instead of in a load effect that raced with loading the scenario and could fall back to the first environment - set the run to a final status directly in the status filter test so the scheduler can't change it mid-test - bump version to 1.19.2 --- CHANGELOG.md | 9 +++++ .../src/pages/scenario/ScenarioDetailPage.tsx | 40 ++++++++----------- package-lock.json | 4 +- package.json | 2 +- server/test/scenario.controller.spec.ts | 31 ++++++++------ 5 files changed, 47 insertions(+), 39 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 66b47c4..255d65a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,15 @@ All notable changes to this project will be documented in this file. +## 1.19.2 - 2026-09-30 + +Changes since 1.19.1: + +### Fixed + +- Running a scenario from its detail page could preselect the first environment in the list instead of the scenario's default environment, depending on whether the environment list or the scenario loaded first. The default environment is now chosen when the run modal opens. +- Made the run status filter test deterministic; it could fail when the scheduler picked up the test's pending run mid-test. + ## 1.19.1 - 2026-09-30 Changes since 1.19.0: diff --git a/client/src/pages/scenario/ScenarioDetailPage.tsx b/client/src/pages/scenario/ScenarioDetailPage.tsx index 3a9f7dc..5b7fa54 100644 --- a/client/src/pages/scenario/ScenarioDetailPage.tsx +++ b/client/src/pages/scenario/ScenarioDetailPage.tsx @@ -1,4 +1,4 @@ -import { useEffect, useRef, useState, useCallback, SubmitEvent } from 'react'; +import { useEffect, useState, useCallback, SubmitEvent } from 'react'; import { useNavigate, useParams } from 'react-router-dom'; import { useTranslation } from 'react-i18next'; import { usePageTitle } from '../../hooks/usePageTitle'; @@ -85,7 +85,6 @@ export function ScenarioDetailPage() { const traceMode = traceModeOverride ?? runDefaults?.traceMode ?? 'off'; const [envs, setEnvs] = useState([]); const [selectedEnvId, setSelectedEnvId] = useState(''); - const envInitRef = useRef(false); const [pendingDelete, setPendingDelete] = useState< { type: 'scenario' } | { type: 'step'; id: string } | { type: 'credential'; id: string } | null >(null); @@ -144,14 +143,23 @@ export function ScenarioDetailPage() { .catch(() => {}); }, [id, loadFiles]); - // Default selected env to scenario's linked environment (or first env) once both are loaded - useEffect(() => { - if (envInitRef.current || envs.length === 0) return; - envInitRef.current = true; + const openRunModal = () => { + // Preselect the scenario's default environment (or the first one) when the + // modal opens: by then both are loaded, and it follows default env edits const preferred = scenario?.environmentId ?? null; const exists = preferred ? envs.some((e) => e.id === preferred) : false; - setSelectedEnvId(exists ? preferred! : envs[0].id); - }, [scenario, envs]); + setSelectedEnvId(exists ? preferred! : (envs[0]?.id ?? '')); + setTraceModeOverride(null); + setRunVersion(null); + setRunVersions([]); + if (id) { + scenarios + .versions(id) + .then(setRunVersions) + .catch(() => undefined); + } + setRunModalOpen(true); + }; const reloadScenario = async () => { if (!id) return; @@ -470,21 +478,7 @@ export function ScenarioDetailPage() { /> {scenario && (
- diff --git a/package-lock.json b/package-lock.json index 9081c0d..119522d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "liqa", - "version": "1.19.1", + "version": "1.19.2", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "liqa", - "version": "1.19.1", + "version": "1.19.2", "workspaces": [ "server", "client" diff --git a/package.json b/package.json index b8878ed..332fa70 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "liqa", - "version": "1.19.1", + "version": "1.19.2", "private": true, "engines": { "node": ">=24" diff --git a/server/test/scenario.controller.spec.ts b/server/test/scenario.controller.spec.ts index 8effc82..d23cd5f 100644 --- a/server/test/scenario.controller.spec.ts +++ b/server/test/scenario.controller.spec.ts @@ -550,22 +550,27 @@ describe("ScenarioController", () => { it("filters by status", async () => { const sc = await createScenario(); await createStep(sc.id, { order: 0 }); - await createRun(sc.id); + const run = await createRun(sc.id); + // Put the run in a final state directly: a pending run would be picked + // up by the scheduler (@Interval) and could change status mid-test + await app + .get(DataSource) + .query(`UPDATE scenario_runs SET status = 'fail' WHERE id = ?`, [ + run.id, + ]); - const pendingRes = await request(app.getHttpServer()) - .get(`/scenarios/${sc.id}/runs?status=pending`) + const failRes = await request(app.getHttpServer()) + .get(`/scenarios/${sc.id}/runs?status=fail`) .expect(200); + expect(failRes.body.total).toBe(1); + expect(failRes.body.data[0].id).toBe(run.id); - expect(pendingRes.body.total).toBeGreaterThanOrEqual(1); - pendingRes.body.data.forEach((r: { status: string }) => - expect(r.status).toBe("pending"), - ); - - const passRes = await request(app.getHttpServer()) - .get(`/scenarios/${sc.id}/runs?status=pass`) - .expect(200); - - expect(passRes.body.total).toBe(0); + for (const status of ["pending", "pass"]) { + const res = await request(app.getHttpServer()) + .get(`/scenarios/${sc.id}/runs?status=${status}`) + .expect(200); + expect(res.body.total).toBe(0); + } }); it("returns 400 for invalid status filter", async () => {