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
This commit is contained in:
ars9 committed 2026-09-30 21:07:15 +03:00
1 parent 68415f805b
commit e586ab9bd9
5 files changed
+47 -39

No files matched your search

+9
View File
@@ -2,6 +2,15 @@
All notable changes to this project will be documented in this file. 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 ## 1.19.1 - 2026-09-30
Changes since 1.19.0: Changes since 1.19.0:
@@ -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 { useNavigate, useParams } from 'react-router-dom';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import { usePageTitle } from '../../hooks/usePageTitle'; import { usePageTitle } from '../../hooks/usePageTitle';
@@ -85,7 +85,6 @@ export function ScenarioDetailPage() {
const traceMode = traceModeOverride ?? runDefaults?.traceMode ?? 'off'; const traceMode = traceModeOverride ?? runDefaults?.traceMode ?? 'off';
const [envs, setEnvs] = useState<Environment[]>([]); const [envs, setEnvs] = useState<Environment[]>([]);
const [selectedEnvId, setSelectedEnvId] = useState(''); const [selectedEnvId, setSelectedEnvId] = useState('');
const envInitRef = useRef(false);
const [pendingDelete, setPendingDelete] = useState< const [pendingDelete, setPendingDelete] = useState<
{ type: 'scenario' } | { type: 'step'; id: string } | { type: 'credential'; id: string } | null { type: 'scenario' } | { type: 'step'; id: string } | { type: 'credential'; id: string } | null
>(null); >(null);
@@ -144,14 +143,23 @@ export function ScenarioDetailPage() {
.catch(() => {}); .catch(() => {});
}, [id, loadFiles]); }, [id, loadFiles]);
// Default selected env to scenario's linked environment (or first env) once both are loaded const openRunModal = () => {
useEffect(() => { // Preselect the scenario's default environment (or the first one) when the
if (envInitRef.current || envs.length === 0) return; // modal opens: by then both are loaded, and it follows default env edits
envInitRef.current = true;
const preferred = scenario?.environmentId ?? null; const preferred = scenario?.environmentId ?? null;
const exists = preferred ? envs.some((e) => e.id === preferred) : false; const exists = preferred ? envs.some((e) => e.id === preferred) : false;
setSelectedEnvId(exists ? preferred! : envs[0].id); setSelectedEnvId(exists ? preferred! : (envs[0]?.id ?? ''));
}, [scenario, envs]); setTraceModeOverride(null);
setRunVersion(null);
setRunVersions([]);
if (id) {
scenarios
.versions(id)
.then(setRunVersions)
.catch(() => undefined);
}
setRunModalOpen(true);
};
const reloadScenario = async () => { const reloadScenario = async () => {
if (!id) return; if (!id) return;
@@ -470,21 +478,7 @@ export function ScenarioDetailPage() {
/> />
{scenario && ( {scenario && (
<div className={styles.toolbarActions}> <div className={styles.toolbarActions}>
<Button <Button size="sm" onClick={openRunModal}>
size="sm"
onClick={() => {
setTraceModeOverride(null);
setRunVersion(null);
setRunVersions([]);
if (id) {
scenarios
.versions(id)
.then(setRunVersions)
.catch(() => undefined);
}
setRunModalOpen(true);
}}
>
<Play size={14} /> <Play size={14} />
{t('scenarios.action_run')} {t('scenarios.action_run')}
</Button> </Button>
+2 -2
View File
@@ -1,12 +1,12 @@
{ {
"name": "liqa", "name": "liqa",
"version": "1.19.1", "version": "1.19.2",
"lockfileVersion": 3, "lockfileVersion": 3,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "liqa", "name": "liqa",
"version": "1.19.1", "version": "1.19.2",
"workspaces": [ "workspaces": [
"server", "server",
"client" "client"
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "liqa", "name": "liqa",
"version": "1.19.1", "version": "1.19.2",
"private": true, "private": true,
"engines": { "engines": {
"node": ">=24" "node": ">=24"
+18 -13
View File
@@ -550,22 +550,27 @@ describe("ScenarioController", () => {
it("filters by status", async () => { it("filters by status", async () => {
const sc = await createScenario(); const sc = await createScenario();
await createStep(sc.id, { order: 0 }); 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()) const failRes = await request(app.getHttpServer())
.get(`/scenarios/${sc.id}/runs?status=pending`) .get(`/scenarios/${sc.id}/runs?status=fail`)
.expect(200); .expect(200);
expect(failRes.body.total).toBe(1);
expect(failRes.body.data[0].id).toBe(run.id);
expect(pendingRes.body.total).toBeGreaterThanOrEqual(1); for (const status of ["pending", "pass"]) {
pendingRes.body.data.forEach((r: { status: string }) => const res = await request(app.getHttpServer())
expect(r.status).toBe("pending"), .get(`/scenarios/${sc.id}/runs?status=${status}`)
); .expect(200);
expect(res.body.total).toBe(0);
const passRes = await request(app.getHttpServer()) }
.get(`/scenarios/${sc.id}/runs?status=pass`)
.expect(200);
expect(passRes.body.total).toBe(0);
}); });
it("returns 400 for invalid status filter", async () => { it("returns 400 for invalid status filter", async () => {