diff --git a/CHANGELOG.md b/CHANGELOG.md index e0337cb..5a99755 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,15 @@ All notable changes to this project will be documented in this file. +## 1.22.0 - 2026-10-01 + +Changes since 1.21.1: + +### Added + +- The Export Scenario dialog lists the snippets the scenario uses (including ones used only through other snippets), all checked by default. A selected snippet is exported once per version the scenario uses: the latest for `runSnippet("alias")`, plus each version pinned with `alias@N`. `GET /scenarios/:id/export` takes the new `snippetIds` query parameter for this. +- The Export Scenario dialog shows the scenario version next to its name and id. + ## 1.21.1 - 2026-10-01 Changes since 1.21.0: diff --git a/client/src/api/client.ts b/client/src/api/client.ts index 23af313..4c2a732 100644 --- a/client/src/api/client.ts +++ b/client/src/api/client.ts @@ -247,9 +247,10 @@ export const scenarios = { }, exportScenario( id: string, - options: { includeEnvironment: boolean; credentialIds: string[] } = { + options: { includeEnvironment: boolean; credentialIds: string[]; snippetIds: string[] } = { includeEnvironment: false, credentialIds: [], + snippetIds: [], }, ): Promise { const params = new URLSearchParams(); @@ -257,6 +258,9 @@ export const scenarios = { for (const cid of options.credentialIds) { params.append('credentialIds', cid); } + for (const sid of options.snippetIds) { + params.append('snippetIds', sid); + } return request(`/scenarios/${id}/export?${params.toString()}`); }, exportE2eTestUrl(id: string): string { diff --git a/client/src/components/modals/ExportScenarioModal.module.css b/client/src/components/modals/ExportScenarioModal.module.css index f36f586..3cc4522 100644 --- a/client/src/components/modals/ExportScenarioModal.module.css +++ b/client/src/components/modals/ExportScenarioModal.module.css @@ -61,3 +61,8 @@ cursor: pointer; accent-color: var(--color-primary); } + +.versions { + color: var(--color-text-muted); + font-size: var(--font-size-xs); +} diff --git a/client/src/components/modals/ExportScenarioModal.tsx b/client/src/components/modals/ExportScenarioModal.tsx index 962aea7..e1d9074 100644 --- a/client/src/components/modals/ExportScenarioModal.tsx +++ b/client/src/components/modals/ExportScenarioModal.tsx @@ -1,7 +1,7 @@ import { useTranslation } from 'react-i18next'; import { X, Upload } from 'lucide-react'; import { Modal, Button, UuidBadge } from '../../ui'; -import type { Scenario, ScenarioCredential } from '../../api'; +import type { Scenario, ScenarioCredential, UsedSnippet } from '../../api'; import styles from './ExportScenarioModal.module.css'; export interface ExportScenarioModalProps { @@ -13,6 +13,9 @@ export interface ExportScenarioModalProps { onIncludeEnvironmentChange: (v: boolean) => void; includedCredentialIds: Set; onCredentialToggle: (id: string, checked: boolean) => void; + usedSnippets: UsedSnippet[]; + includedSnippetIds: Set; + onSnippetToggle: (id: string, checked: boolean) => void; onClose: () => void; onExport: () => void; isExporting: boolean; @@ -27,12 +30,24 @@ export function ExportScenarioModal({ onIncludeEnvironmentChange, includedCredentialIds, onCredentialToggle, + usedSnippets, + includedSnippetIds, + onSnippetToggle, onClose, onExport, isExporting, }: ExportScenarioModalProps) { const { t } = useTranslation(); + // One row per snippet, listing every version the scenario uses (latest or pinned) + const snippetRows = new Map(); + for (const s of usedSnippets) { + const row = snippetRows.get(s.id) ?? { alias: s.alias, versions: [] }; + const version = s.pinnedVersion ?? s.version; + if (!row.versions.includes(version)) row.versions.push(version); + snippetRows.set(s.id, row); + } + return ( +
+ {t('scenarios.field_version')} + v{scenario.version} +
{environment && ( @@ -95,6 +114,25 @@ export function ExportScenarioModal({ ))} )} + + {snippetRows.size > 0 && ( +
+

{t('scenarios.export_include_snippets')}

+ {[...snippetRows].map(([snippetId, row]) => ( + + ))} +
+ )} )}
diff --git a/client/src/i18n/locales/en.json b/client/src/i18n/locales/en.json index 33a2d88..4e16472 100644 --- a/client/src/i18n/locales/en.json +++ b/client/src/i18n/locales/en.json @@ -217,6 +217,7 @@ "export_modal_title": "Export Scenario", "export_include_environment": "Include Environment", "export_include_credentials": "Include Credentials", + "export_include_snippets": "Include Snippets", "form_timeout": "Scenario Timeout (seconds)", "form_timeout_placeholder": "Default: 600", "form_timeout_hint": "Max seconds for the entire scenario run (default: 600)", diff --git a/client/src/pages/scenario/ScenarioDetailPage.tsx b/client/src/pages/scenario/ScenarioDetailPage.tsx index 5f969ee..4cc0d51 100644 --- a/client/src/pages/scenario/ScenarioDetailPage.tsx +++ b/client/src/pages/scenario/ScenarioDetailPage.tsx @@ -94,6 +94,7 @@ export function ScenarioDetailPage() { const [exportModalOpen, setExportModalOpen] = useState(false); const [includeEnvironment, setIncludeEnvironment] = useState(true); const [includedCredentialIds, setIncludedCredentialIds] = useState>(new Set()); + const [includedSnippetIds, setIncludedSnippetIds] = useState>(new Set()); const [isExporting, setIsExporting] = useState(false); // Files state @@ -212,8 +213,9 @@ export function ScenarioDetailPage() { const handleOpenExportModal = () => { if (!scenario) return; - // Initialise all credential checkboxes to checked + // Initialise all credential and snippet checkboxes to checked setIncludedCredentialIds(new Set(scenarioCreds.map((sc) => sc.credentialId))); + setIncludedSnippetIds(new Set(usedSnippets.map((s) => s.id))); setIncludeEnvironment(true); setExportModalOpen(true); }; @@ -226,6 +228,7 @@ export function ScenarioDetailPage() { const yamlContent = await scenarios.exportScenario(scenario.id, { includeEnvironment, credentialIds: credIds, + snippetIds: Array.from(includedSnippetIds), }); const blob = new Blob([yamlContent], { type: 'application/yaml' }); const url = URL.createObjectURL(blob); @@ -899,6 +902,16 @@ export function ScenarioDetailPage() { return next; }); }} + usedSnippets={usedSnippets} + includedSnippetIds={includedSnippetIds} + onSnippetToggle={(snippetId, checked) => { + setIncludedSnippetIds((prev) => { + const next = new Set(prev); + if (checked) next.add(snippetId); + else next.delete(snippetId); + return next; + }); + }} onClose={() => setExportModalOpen(false)} onExport={handleExport} isExporting={isExporting} diff --git a/docs/scenario.md b/docs/scenario.md index 5f653a1..91ce5cf 100644 --- a/docs/scenario.md +++ b/docs/scenario.md @@ -77,7 +77,7 @@ Exports hold exactly one version and always include its `version` number (the la - Items are imported in dependency order - environments, credentials, snippets, scenarios - regardless of their order in the file, so a scenario can reference an environment or credential from the same file. - The response lists what was imported: `{ imported: [{ kind, id, name, version? }] }`. -A scenario export (`GET /scenarios/:id/export`, optionally with its environment and credentials) is in this format, one document per entity, and can be imported back as is. +A scenario export (`GET /scenarios/:id/export`, optionally with its environment, credentials and used snippets) is in this format, one document per entity, and can be imported back as is. Query parameters: `includeEnvironment=true`, `credentialIds` and `snippetIds` (repeat the parameter or separate ids with commas) and `version`. A selected snippet is exported once per version the scenario uses: the latest for plain `runSnippet("alias")` calls, plus each version pinned with `alias@N`. Snippets used only through other snippets count as used. ```yaml --- diff --git a/package-lock.json b/package-lock.json index 2751341..1bb1573 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "liqa", - "version": "1.21.1", + "version": "1.22.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "liqa", - "version": "1.21.1", + "version": "1.22.0", "workspaces": [ "server", "client" diff --git a/package.json b/package.json index 79be934..4423cb8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "liqa", - "version": "1.21.1", + "version": "1.22.0", "private": true, "engines": { "node": ">=24" diff --git a/server/src/scenario/dto/scenario-export.dto.ts b/server/src/scenario/dto/scenario-export.dto.ts index 7c99919..1ce6367 100644 --- a/server/src/scenario/dto/scenario-export.dto.ts +++ b/server/src/scenario/dto/scenario-export.dto.ts @@ -13,6 +13,7 @@ import { ValidateNested, } from "class-validator"; import { EnvironmentData } from "../../environment/environment.entity"; +import { SnippetExportDto } from "../../snippet/dto/snippet-export.dto"; export class ScenarioStepExportDto { @ApiPropertyOptional() @@ -154,4 +155,5 @@ export class ScenarioExportDto { export type ExportEntity = | EnvironmentExportInlineDto | CredentialExportDto + | SnippetExportDto | ScenarioExportDto; diff --git a/server/src/scenario/scenario.controller.ts b/server/src/scenario/scenario.controller.ts index 6676a25..583e343 100644 --- a/server/src/scenario/scenario.controller.ts +++ b/server/src/scenario/scenario.controller.ts @@ -135,18 +135,17 @@ export class ScenarioController { @Param("id", ParseUUIDPipe) id: string, @Query("includeEnvironment") includeEnvironment: string, @Query("credentialIds") credentialIds: string | string[] | undefined, + @Query("snippetIds") snippetIds: string | string[] | undefined, @Query("version", new ParseIntPipe({ optional: true })) version: number | undefined, @Res({ passthrough: true }) res: Response, ) { - const credIds: string[] = credentialIds - ? Array.isArray(credentialIds) - ? credentialIds - : credentialIds.split(",").filter(Boolean) - : []; + const toIds = (ids: string | string[] | undefined): string[] => + ids ? (Array.isArray(ids) ? ids : ids.split(",").filter(Boolean)) : []; const entities = await this.scenarioService.exportScenario(id, { includeEnvironment: includeEnvironment === "true", - credentialIds: credIds, + credentialIds: toIds(credentialIds), + snippetIds: toIds(snippetIds), version, }); res.setHeader("Content-Type", "application/yaml; charset=utf-8"); @@ -155,12 +154,17 @@ export class ScenarioController { const kindLabels: Record = { environment: "Environment", credential: "Credential", + snippet: "Snippet", scenario: "Scenario", }; return (entities as ExportEntity[]) .map((entity) => { const label = kindLabels[entity.kind ?? ""] ?? entity.kind ?? "Entity"; - const comment = `# ${label}: ${entity.name ?? entity.id ?? ""}`; + const title = + entity.kind === "snippet" + ? `${entity.alias ?? entity.name} v${entity.version}` + : entity.name; + const comment = `# ${label}: ${title ?? entity.id ?? ""}`; return `---\n${comment}\n${yamlStringify(entity)}`; }) .join(""); diff --git a/server/src/scenario/scenario.service.ts b/server/src/scenario/scenario.service.ts index 68c2c55..b4e7fd6 100644 --- a/server/src/scenario/scenario.service.ts +++ b/server/src/scenario/scenario.service.ts @@ -486,11 +486,18 @@ export class ScenarioService implements OnModuleInit { */ async getUsedSnippets(scenarioId: string): Promise { const scenario = await this.findOne(scenarioId); - const snippetMap = await this.snippetService.buildSnippetMap(); - const usedRefs = resolveUsedSnippetAliases( + return this.resolveUsedSnippets( scenario.steps.map((s) => s.execCode ?? ""), - snippetMap, - ).map(parseSnippetRef); + ); + } + + private async resolveUsedSnippets( + execCodes: string[], + ): Promise { + const snippetMap = await this.snippetService.buildSnippetMap(); + const usedRefs = resolveUsedSnippetAliases(execCodes, snippetMap).map( + parseSnippetRef, + ); if (usedRefs.length === 0) return []; const snippets = await this.snippetService.findByAliases([ ...new Set(usedRefs.map((r) => r.alias)), @@ -699,6 +706,8 @@ export class ScenarioService implements OnModuleInit { options: { includeEnvironment: boolean; credentialIds: string[]; + /** Used snippets to include, at every version the scenario uses. */ + snippetIds?: string[]; /** Version to export; defaults to the latest. */ version?: number; }, @@ -741,6 +750,25 @@ export class ScenarioService implements OnModuleInit { } } + // Include selected snippets, once per used version (latest or pinned) + const snippetIds = options.snippetIds ?? []; + if (snippetIds.length > 0) { + const used = await this.resolveUsedSnippets( + content.steps.map((s) => s.execCode ?? ""), + ); + const seen = new Set(); + for (const snippet of used) { + if (!snippetIds.includes(snippet.id)) continue; + const version = snippet.pinnedVersion ?? snippet.version; + const key = `${snippet.id}@${version}`; + if (seen.has(key)) continue; + seen.add(key); + entities.push( + await this.snippetService.exportSnippet(snippet, version), + ); + } + } + // Scenario is always last const allCreds = scenario.scenarioCredentials ?? []; const credentialMappings = allCreds diff --git a/server/test/versioning.spec.ts b/server/test/versioning.spec.ts index 5d373ce..ff70cc7 100644 --- a/server/test/versioning.spec.ts +++ b/server/test/versioning.spec.ts @@ -277,6 +277,47 @@ describe("Versioning", () => { expect(first[first.length - 1]).toMatchObject({ version: 1, steps: [] }); }); + it("includes selected used snippets at the versions the scenario uses", async () => { + const alias = `exp-snip-${uniq()}`; + const sn = await snippetService.create({ + alias, + title: "t", + code: "return 'one';", + }); + await snippetService.update(sn.id, { code: "return 'two';" }); + const other = await snippetService.create({ + alias: `exp-other-${uniq()}`, + title: "t", + code: "return 3;", + }); + + const sc = await scenarioService.create({ name: `exp-sn-${uniq()}` }); + await scenarioService.createStep(sc.id, { + execCode: `await context.runSnippet("${alias}"); await context.runSnippet("${alias}@1"); await context.runSnippet("${alias}"); return context.runSnippet("${other.alias}");`, + }); + + const withSnippet = await scenarioService.exportScenario(sc.id, { + includeEnvironment: false, + credentialIds: [], + snippetIds: [sn.id], + }); + expect(withSnippet.map((e) => e.kind)).toEqual([ + "snippet", + "snippet", + "scenario", + ]); + expect(withSnippet.slice(0, 2)).toMatchObject([ + { id: sn.id, version: 2, code: "return 'two';" }, + { id: sn.id, version: 1, code: "return 'one';" }, + ]); + + const without = await scenarioService.exportScenario(sc.id, { + includeEnvironment: false, + credentialIds: [], + }); + expect(without.map((e) => e.kind)).toEqual(["scenario"]); + }); + it("restores exact versions by id + version", async () => { const id = crypto.randomUUID(); const base = { kind: "scenario" as const, id, name: "imported" };