feat(scenarios): export used snippets with a scenario
- list the snippets a scenario uses in the export dialog, checked by default, with the versions the scenario uses - export each selected snippet once per used version (latest and pinned) via the new snippetIds query parameter - resolve used snippets from the exported version's steps - show the scenario version in the export dialog - document the export query parameters - bump version to 1.22.0
This commit is contained in:
1 parent
f43d902297
commit
23fa302b25
13 files changed
+163
-18
No files matched your search
@@ -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:
|
||||
|
||||
@@ -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<string> {
|
||||
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 {
|
||||
|
||||
@@ -61,3 +61,8 @@
|
||||
cursor: pointer;
|
||||
accent-color: var(--color-primary);
|
||||
}
|
||||
|
||||
.versions {
|
||||
color: var(--color-text-muted);
|
||||
font-size: var(--font-size-xs);
|
||||
}
|
||||
@@ -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<string>;
|
||||
onCredentialToggle: (id: string, checked: boolean) => void;
|
||||
usedSnippets: UsedSnippet[];
|
||||
includedSnippetIds: Set<string>;
|
||||
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<string, { alias: string; versions: number[] }>();
|
||||
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 (
|
||||
<Modal
|
||||
open={open}
|
||||
@@ -64,6 +79,10 @@ export function ExportScenarioModal({
|
||||
<UuidBadge id={scenario.id} />
|
||||
</span>
|
||||
</div>
|
||||
<div className={styles.metaRow}>
|
||||
<span className={styles.metaLabel}>{t('scenarios.field_version')}</span>
|
||||
<span className={styles.metaValue}>v{scenario.version}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{environment && (
|
||||
@@ -95,6 +114,25 @@ export function ExportScenarioModal({
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{snippetRows.size > 0 && (
|
||||
<div className={styles.section}>
|
||||
<h4 className={styles.sectionTitle}>{t('scenarios.export_include_snippets')}</h4>
|
||||
{[...snippetRows].map(([snippetId, row]) => (
|
||||
<label key={snippetId} className={styles.checkboxRow}>
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={includedSnippetIds.has(snippetId)}
|
||||
onChange={(e) => onSnippetToggle(snippetId, e.target.checked)}
|
||||
/>
|
||||
<span>{row.alias}</span>
|
||||
<span className={styles.versions}>
|
||||
{row.versions.map((v) => `v${v}`).join(', ')}
|
||||
</span>
|
||||
</label>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</Modal>
|
||||
|
||||
@@ -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)",
|
||||
|
||||
@@ -94,6 +94,7 @@ export function ScenarioDetailPage() {
|
||||
const [exportModalOpen, setExportModalOpen] = useState(false);
|
||||
const [includeEnvironment, setIncludeEnvironment] = useState(true);
|
||||
const [includedCredentialIds, setIncludedCredentialIds] = useState<Set<string>>(new Set());
|
||||
const [includedSnippetIds, setIncludedSnippetIds] = useState<Set<string>>(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}
|
||||
|
||||
+1
-1
@@ -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
|
||||
---
|
||||
|
||||
Generated
+2
-2
@@ -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"
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "liqa",
|
||||
"version": "1.21.1",
|
||||
"version": "1.22.0",
|
||||
"private": true,
|
||||
"engines": {
|
||||
"node": ">=24"
|
||||
|
||||
@@ -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;
|
||||
@@ -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<string, string> = {
|
||||
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("");
|
||||
|
||||
@@ -486,11 +486,18 @@ export class ScenarioService implements OnModuleInit {
|
||||
*/
|
||||
async getUsedSnippets(scenarioId: string): Promise<UsedSnippet[]> {
|
||||
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<UsedSnippet[]> {
|
||||
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<string>();
|
||||
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
|
||||
|
||||
@@ -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" };
|
||||
|
||||
Reference in new issue
Block a user