From ff83b6c7da6b067a2a460789b39b3fea7e4785fa Mon Sep 17 00:00:00 2001 From: Andrii Arsenin Date: Wed, 30 Sep 2026 15:24:44 +0300 Subject: [PATCH] feat(versioning): version scenarios and snippets, bump to 1.16.0 - snapshot scenario and snippet content into version tables on every content change; live tables keep holding the latest version - record the scenario version on each run and copy its steps into the run steps, so runs execute and show the version they were created with - keep run step history when a step is deleted (FK set null) - pin a snippet version with runSnippet('alias@N') - add version picker to the run modal and version info across the UI - add version list/get endpoints and MCP tools - include version in exports and require it on import, restoring the exact version by id + version --- CHANGELOG.md | 19 + client/src/api/client.ts | 15 +- client/src/api/types.ts | 51 ++- .../components/modals/RunScenarioModal.tsx | 29 +- client/src/i18n/locales/en.json | 10 + client/src/pages/run/AllRunsPage.tsx | 11 + client/src/pages/run/RunDetailPage.tsx | 9 +- client/src/pages/run/RunsPage.tsx | 11 + .../src/pages/scenario/ScenarioDetailPage.tsx | 35 +- client/src/pages/scenario/ScenariosPage.tsx | 21 +- .../src/pages/snippet/SnippetDetailPage.tsx | 1 + client/src/pages/snippet/SnippetsPage.tsx | 1 + docs/mcp.md | 20 +- docs/scenario.md | 20 +- package-lock.json | 4 +- package.json | 2 +- server/src/app.module.ts | 4 + server/src/common/snippet-usage.ts | 14 + server/src/mcp/mcp.service.ts | 137 +++++- .../scenario/dto/create-scenario-run.dto.ts | 8 + .../src/scenario/dto/scenario-export.dto.ts | 19 + .../src/scenario/scenario-run-step.entity.ts | 20 +- server/src/scenario/scenario-run.entity.ts | 4 + .../scenario/scenario-scheduler.service.ts | 34 +- .../src/scenario/scenario-version.entity.ts | 59 +++ server/src/scenario/scenario.controller.ts | 24 ++ server/src/scenario/scenario.entity.ts | 4 + server/src/scenario/scenario.module.ts | 2 + server/src/scenario/scenario.service.ts | 311 +++++++++++--- server/src/snippet/dto/snippet-export.dto.ts | 7 + server/src/snippet/snippet-version.entity.ts | 47 +++ server/src/snippet/snippet.controller.ts | 27 +- server/src/snippet/snippet.entity.ts | 4 + server/src/snippet/snippet.module.ts | 3 +- server/src/snippet/snippet.service.ts | 189 +++++++-- server/test/app.harness.ts | 4 + server/test/exec-context-files.spec.ts | 5 + server/test/mcp.controller.spec.ts | 5 + server/test/scenario.controller.spec.ts | 11 +- server/test/versioning.spec.ts | 393 ++++++++++++++++++ 40 files changed, 1457 insertions(+), 137 deletions(-) create mode 100644 server/src/scenario/scenario-version.entity.ts create mode 100644 server/src/snippet/snippet-version.entity.ts create mode 100644 server/test/versioning.spec.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index 089da7f..f5d0851 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,25 @@ All notable changes to this project will be documented in this file. +## 1.16.0 - 2026-09-30 + +Changes since 1.15.0: + +### Added + +- Scenarios and snippets are now versioned, starting at version 1. A scenario's version goes up when its name, description, default environment, timeout or steps change; a snippet's when its alias, title, description or code changes. Saving without changes does not create a new version. Credential assignments and scenario files are not versioned. +- Each run records the scenario version it runs. The run modal has a version picker (latest by default), `POST /scenarios/:id/run` and the `run_scenario` MCP tool accept an optional `version`, and "Repeat run" reuses the run's version. +- `context.runSnippet("alias@N")` pins version N of a snippet; `runSnippet("alias")` keeps using the latest. The scenario page's "Used Snippets" section shows which snippets are pinned. +- Version numbers are shown on the scenario, snippet and run pages and in the scenario and run lists. +- Added `GET /scenarios/:id/versions[/:version]` and `GET /snippets/:id/versions[/:version]`, and the `list_scenario_versions`, `get_scenario_version`, `list_snippet_versions` and `get_snippet_version` MCP tools. +- Scenario and snippet exports accept `?version=N` (the `export_scenario` MCP tool takes `version`). + +### Changed + +- **Breaking:** scenario and snippet exports now include `version`, and imports require it. An import restores that exact version by id + version: an existing version is left untouched, and a new one is stored under its number and becomes the latest when it is higher than the current latest. Export files from earlier releases need a `version` field added before they can be imported. +- Scenario exports now include scenario and step timeouts. +- Runs keep their own copy of the steps they were created with. Editing or deleting a step no longer changes past runs, and deleting a step no longer deletes its results from past runs. Existing run steps are backfilled from the current steps on startup. + ## 1.15.0 - 2026-09-30 Changes since 1.14.0: diff --git a/client/src/api/client.ts b/client/src/api/client.ts index 72266fd..7dd7f8a 100644 --- a/client/src/api/client.ts +++ b/client/src/api/client.ts @@ -12,8 +12,11 @@ import type { ScenarioRunDetail, ScenarioRunStep, ScenarioStep, + ScenarioVersion, Snippet, + SnippetVersion, TraceMode, + UsedSnippet, } from './types'; import { emitApiErrorToast } from '../lib/toast-events'; @@ -122,6 +125,9 @@ export const snippets = { remove(id: string): Promise { return request(`/snippets/${id}`, { method: 'DELETE' }); }, + versions(id: string): Promise { + return request(`/snippets/${id}/versions`); + }, exportSnippet(id: string): Promise { return request(`/snippets/${id}/export`); }, @@ -229,12 +235,17 @@ export const scenarios = { environmentId: string, saveSession?: boolean, traceMode?: TraceMode, + /** Scenario version to run; omit for the latest. */ + version?: number, ): Promise { return request(`/scenarios/${id}/run`, { method: 'POST', - body: JSON.stringify({ environmentId, saveSession, traceMode }), + body: JSON.stringify({ environmentId, saveSession, traceMode, version }), }); }, + versions(id: string): Promise { + return request(`/scenarios/${id}/versions`); + }, runDefaults(): Promise { return request('/scenarios/run-defaults'); }, @@ -274,7 +285,7 @@ export const scenarios = { exportE2eTestUrl(id: string): string { return `${BASE_URL}/scenarios/${id}/export-e2e`; }, - usedSnippets(id: string): Promise { + usedSnippets(id: string): Promise { return request(`/scenarios/${id}/used-snippets`); }, }; diff --git a/client/src/api/types.ts b/client/src/api/types.ts index 2ee0241..9eaf945 100644 --- a/client/src/api/types.ts +++ b/client/src/api/types.ts @@ -41,10 +41,29 @@ export interface Snippet { title: string; description: string | null; code: string; + /** Latest version number. */ + version: number; createdAt: string; updatedAt: string; } +export interface SnippetVersion { + id: string; + snippetId: string; + version: number; + alias: string; + title: string; + description: string | null; + code: string; + createdAt: string; +} + +/** A snippet referenced by a scenario's steps. */ +export interface UsedSnippet extends Snippet { + /** Version pinned via runSnippet('alias@N'), or null for the latest. */ + pinnedVersion: number | null; +} + // ── Sessions ────────────────────────────────────────────────────────────────── export type SessionStatus = 'open' | 'closed'; @@ -87,6 +106,8 @@ export interface Scenario { description?: string; environmentId?: string | null; timeoutSeconds?: number | null; + /** Latest version number. */ + version: number; environment?: Pick; steps?: ScenarioStep[]; scenarioCredentials?: ScenarioCredential[]; @@ -96,6 +117,26 @@ export interface Scenario { updatedAt: string; } +export interface ScenarioStepSnapshot { + id: string | null; + order: number; + title: string | null; + execCode: string | null; + timeoutSeconds: number | null; +} + +export interface ScenarioVersion { + id: string; + scenarioId: string; + version: number; + name: string; + description: string | null; + environmentId: string | null; + timeoutSeconds: number | null; + steps: ScenarioStepSnapshot[]; + createdAt: string; +} + export type ScenarioRunStatus = 'pending' | 'in_progress' | 'pass' | 'fail'; export type TraceMode = 'on' | 'retain-on-failure' | 'off'; @@ -115,6 +156,8 @@ export interface ScenarioRun { sessionId?: string | null; saveSession: boolean; traceMode: TraceMode | null; + /** Scenario version the run executes; null for runs created before versioning. */ + scenarioVersion: number | null; scenario?: Pick; environment?: Pick; session?: { id: string; sessionName: string }; @@ -127,8 +170,12 @@ export interface ScenarioRun { export interface ScenarioRunStep { id: string; runId: string; - scenarioStepId: string; - scenarioStep: ScenarioStep; + /** Live step this run step came from; null once that step is deleted. */ + scenarioStepId: string | null; + // Step content as of the run's scenario version + title: string | null; + execCode: string | null; + timeoutSeconds: number | null; status: RunStepStatus; order: number; description: string | null; diff --git a/client/src/components/modals/RunScenarioModal.tsx b/client/src/components/modals/RunScenarioModal.tsx index 9c181f6..1e3027c 100644 --- a/client/src/components/modals/RunScenarioModal.tsx +++ b/client/src/components/modals/RunScenarioModal.tsx @@ -1,7 +1,7 @@ import { useTranslation } from 'react-i18next'; import { X, Play } from 'lucide-react'; import { Modal, Button, Select } from '../../ui'; -import type { Environment, TraceMode } from '../../api'; +import type { Environment, ScenarioVersion, TraceMode } from '../../api'; const TRACE_MODES: TraceMode[] = ['on', 'retain-on-failure', 'off']; @@ -12,6 +12,11 @@ export interface RunScenarioModalProps { onEnvSelect: (envId: string) => void; saveSessionFlag: boolean; onSaveSessionChange: (flag: boolean) => void; + /** Scenario versions, newest first; empty while loading. */ + versions: Pick[]; + /** Selected version, or null for the latest. */ + selectedVersion: number | null; + onVersionChange: (version: number | null) => void; traceMode: TraceMode; defaultTraceMode: TraceMode | null; onTraceModeChange: (mode: TraceMode) => void; @@ -28,6 +33,9 @@ export function RunScenarioModal({ onEnvSelect, saveSessionFlag, onSaveSessionChange, + versions, + selectedVersion, + onVersionChange, traceMode, defaultTraceMode, onTraceModeChange, @@ -66,6 +74,25 @@ export function RunScenarioModal({ onChange={(e) => onEnvSelect(e.target.value)} options={environments.map((env) => ({ value: env.id, label: env.name }))} /> +
+