Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ff83b6c7da | ||
|
|
a328ef5ea7 | ||
|
|
7d366e6368 | ||
|
|
5ea1e38f25 | ||
|
|
d99bb75fc2 | ||
|
|
d79415cbb3 | ||
|
|
1eea4eb8d8 | ||
|
|
385f51f3ba | ||
|
|
540a7ec96b | ||
|
|
4e79d3cd81 | ||
|
|
cbfd4404c1 | ||
|
|
50820b8b40 |
No files matched your search
+4
-1
@@ -14,4 +14,7 @@ DB_PATH=data/sessions.db
|
||||
# Close open sessions that have been idle for longer than this many minutes
|
||||
SESSION_IDLE_TIMEOUT_MINUTES=30
|
||||
# Delete closed sessions whose updatedAt is older than this many days
|
||||
SESSION_DELETE_CLOSED_DAYS=7
|
||||
SESSION_DELETE_CLOSED_DAYS=7
|
||||
|
||||
# Playwright trace recording for scenario runs: on | retain-on-failure | off
|
||||
PLAYWRIGHT_TRACE_MODE=on
|
||||
@@ -1,5 +1,6 @@
|
||||
# runtime
|
||||
/data
|
||||
server/data/
|
||||
.env
|
||||
*.log
|
||||
|
||||
|
||||
+126
@@ -2,6 +2,132 @@
|
||||
|
||||
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:
|
||||
|
||||
### Added
|
||||
|
||||
- Scenario runs now record a Playwright trace (screenshots and DOM snapshots) and upload it to the run's files as `trace.zip` when the run finishes. Open it with `npx playwright show-trace trace.zip` or at https://trace.playwright.dev.
|
||||
- Added the `PLAYWRIGHT_TRACE_MODE` setting (`on` (default), `retain-on-failure`, or `off`) that controls which traces are kept.
|
||||
- Added a "Playwright trace" option to the run modal to override the trace mode for a single run. It defaults to the server's `PLAYWRIGHT_TRACE_MODE`, served by the new `GET /scenarios/run-defaults` endpoint.
|
||||
- `POST /scenarios/:id/run` and the `run_scenario` MCP tool accept an optional `traceMode`. The trace mode is stored on the run, shown on the run detail page, and reused by "Repeat run".
|
||||
|
||||
### Changed
|
||||
|
||||
- The run modals on the scenario list and scenario detail pages now share one component.
|
||||
- `server/data/` is now git-ignored.
|
||||
|
||||
## 1.14.0 - 2026-09-30
|
||||
|
||||
Changes since 1.13.0:
|
||||
|
||||
### Added
|
||||
|
||||
- Added a "Repeat run" button on the scenario run detail page that starts a new run of the same scenario with the same environment and "save session" setting, then navigates to it. The button is disabled when the run's environment has since been deleted.
|
||||
|
||||
## 1.13.0 - 2026-09-30
|
||||
|
||||
Changes since 1.12.0:
|
||||
|
||||
### Added
|
||||
|
||||
- Added credential CRUD tools to the MCP server: `list_credentials`, `get_credential`, `create_credential`, `update_credential`, and `delete_credential`. Combined with the existing `add_scenario_credential` tool, credentials can now be created and attached to scenarios entirely via MCP.
|
||||
|
||||
## 1.12.0 - 2026-09-16
|
||||
|
||||
Changes since 1.11.0:
|
||||
|
||||
### Added
|
||||
|
||||
- When a scenario or snippet step fails, a full-page screenshot and the current page HTML are captured and uploaded as run artifacts, so failures can be diagnosed from the run's file list.
|
||||
|
||||
## 1.11.0 - 2026-09-15
|
||||
|
||||
Changes since 1.10.1:
|
||||
|
||||
### Added
|
||||
|
||||
- Added export of a scenario as a standalone, plug-and-play Playwright e2e test project (zip archive with `package.json`, `playwright.config.ts`, `test.spec.ts`, `README.md`, `.env`, `credentials.json`, `snippets/*.js`, and any attached scenario files) that runs entirely independently of the liqa backend. Available as a "Export e2e test" button on the scenario detail page, `GET /scenarios/:id/export-e2e`, and the `export_e2e_test` MCP tool.
|
||||
- The exported test only bundles the credentials, snippets, and attached files actually referenced (directly or transitively) by the scenario's steps.
|
||||
- Added a "Used Snippets" section on the scenario detail page listing the snippets referenced by the scenario's steps, linking to each snippet's detail page. Backed by `GET /scenarios/:id/used-snippets`.
|
||||
|
||||
## 1.10.1 - 2026-09-15
|
||||
|
||||
Changes since 1.10.0:
|
||||
|
||||
### Added
|
||||
|
||||
- `context.runSnippet()` now logs "Snippet started"/"finished"/"failed" entries, matching the automatic step start/pass/fail logging.
|
||||
|
||||
### Changed
|
||||
|
||||
- Reworked the Markdown log export format: each log entry is now its own `## [level] timestamp` section with the message as its body, instead of a single large table.
|
||||
|
||||
### Fixed
|
||||
|
||||
- Run logs could persist out of call order (e.g. a snippet's "started" log appearing after its "finished" log) because writes were fire-and-forget and raced against each other. Log entries now carry a per-run sequence number assigned in call order, and queries/exports sort by it.
|
||||
|
||||
## 1.10.0 - 2026-09-15
|
||||
|
||||
Changes since 1.9.1:
|
||||
|
||||
### Added
|
||||
|
||||
- Added a "Download logs" button on the scenario run detail page: opens a modal to choose Markdown (default) or CSV, then downloads the run's logs in that format.
|
||||
- Added `GET /scenarios/:id/run/:runId/logs/export?format=csv|md` backend endpoint to export a run's logs.
|
||||
|
||||
## 1.9.1 - 2026-09-15
|
||||
|
||||
Changes since 1.9.0:
|
||||
|
||||
### Added
|
||||
|
||||
- Scenario run logs now include an automatic entry when a step starts and when it finishes (pass or fail), so step boundaries are visible in run logs even for steps that don't call `context.log`/`context.assert` themselves.
|
||||
|
||||
## 1.9.0 - 2026-09-15
|
||||
|
||||
Changes since 1.8.0:
|
||||
|
||||
### Added
|
||||
|
||||
- Added `context.assert(fn, description)` for scenario/snippet script steps: runs the given function, requires it to return `true`, logs the outcome (`log` on success, `error` on failure or exception), and throws to stop the step on failure.
|
||||
|
||||
### Changed
|
||||
|
||||
- Documented `context.assert` in `docs/scenario.md`.
|
||||
|
||||
## 1.8.0 - 2026-09-15
|
||||
|
||||
Changes since 1.7.1:
|
||||
|
||||
### Added
|
||||
|
||||
- `context.downloadFile()` now accepts `data:` URIs, so scenario steps can save in-script generated content (e.g. a credential JWT) as a run artifact without a network fetch.
|
||||
|
||||
### Changed
|
||||
|
||||
- Documented the full scenario step `context` file API (`getScenarioFiles`, `downloadFile`) in `docs/scenario.md`.
|
||||
|
||||
## 1.7.1 - 2026-04-21
|
||||
|
||||
Changes since 1.7.0:
|
||||
|
||||
@@ -4,6 +4,7 @@ import type {
|
||||
Environment,
|
||||
FileMetadata,
|
||||
FileListResponse,
|
||||
RunDefaults,
|
||||
ScenarioCredential,
|
||||
Session,
|
||||
Scenario,
|
||||
@@ -11,7 +12,11 @@ import type {
|
||||
ScenarioRunDetail,
|
||||
ScenarioRunStep,
|
||||
ScenarioStep,
|
||||
ScenarioVersion,
|
||||
Snippet,
|
||||
SnippetVersion,
|
||||
TraceMode,
|
||||
UsedSnippet,
|
||||
} from './types';
|
||||
import { emitApiErrorToast } from '../lib/toast-events';
|
||||
|
||||
@@ -120,6 +125,9 @@ export const snippets = {
|
||||
remove(id: string): Promise<void> {
|
||||
return request(`/snippets/${id}`, { method: 'DELETE' });
|
||||
},
|
||||
versions(id: string): Promise<SnippetVersion[]> {
|
||||
return request(`/snippets/${id}/versions`);
|
||||
},
|
||||
exportSnippet(id: string): Promise<unknown> {
|
||||
return request(`/snippets/${id}/export`);
|
||||
},
|
||||
@@ -222,12 +230,25 @@ export const scenarios = {
|
||||
remove(id: string): Promise<void> {
|
||||
return request(`/scenarios/${id}`, { method: 'DELETE' });
|
||||
},
|
||||
run(id: string, environmentId: string, saveSession?: boolean): Promise<ScenarioRun> {
|
||||
run(
|
||||
id: string,
|
||||
environmentId: string,
|
||||
saveSession?: boolean,
|
||||
traceMode?: TraceMode,
|
||||
/** Scenario version to run; omit for the latest. */
|
||||
version?: number,
|
||||
): Promise<ScenarioRun> {
|
||||
return request(`/scenarios/${id}/run`, {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ environmentId, saveSession }),
|
||||
body: JSON.stringify({ environmentId, saveSession, traceMode, version }),
|
||||
});
|
||||
},
|
||||
versions(id: string): Promise<ScenarioVersion[]> {
|
||||
return request(`/scenarios/${id}/versions`);
|
||||
},
|
||||
runDefaults(): Promise<RunDefaults> {
|
||||
return request('/scenarios/run-defaults');
|
||||
},
|
||||
getRun(scenarioId: string, runId: string): Promise<ScenarioRunDetail> {
|
||||
return request(`/scenarios/${scenarioId}/run/${runId}`);
|
||||
},
|
||||
@@ -261,6 +282,12 @@ export const scenarios = {
|
||||
body: JSON.stringify(payload),
|
||||
});
|
||||
},
|
||||
exportE2eTestUrl(id: string): string {
|
||||
return `${BASE_URL}/scenarios/${id}/export-e2e`;
|
||||
},
|
||||
usedSnippets(id: string): Promise<UsedSnippet[]> {
|
||||
return request(`/scenarios/${id}/used-snippets`);
|
||||
},
|
||||
};
|
||||
|
||||
// ── Runs ─────────────────────────────────────────────────────────────────────
|
||||
@@ -292,6 +319,9 @@ export const runs = {
|
||||
const qs = q?.trim() ? `?q=${encodeURIComponent(q.trim())}` : '';
|
||||
return request(`/scenarios/${scenarioId}/run/${runId}${qs}`);
|
||||
},
|
||||
exportLogs(scenarioId: string, runId: string, format: 'csv' | 'md'): Promise<string> {
|
||||
return request(`/scenarios/${scenarioId}/run/${runId}/logs/export?format=${format}`);
|
||||
},
|
||||
};
|
||||
|
||||
// ── Scenario Credentials ──────────────────────────────────────────────────────
|
||||
|
||||
+57
-3
@@ -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<Environment, 'id' | 'name'>;
|
||||
steps?: ScenarioStep[];
|
||||
scenarioCredentials?: ScenarioCredential[];
|
||||
@@ -96,8 +117,34 @@ 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';
|
||||
|
||||
export interface RunDefaults {
|
||||
traceMode: TraceMode;
|
||||
}
|
||||
|
||||
export type RunStepStatus = 'waiting' | 'pending' | 'in_progress' | 'pass' | 'fail' | 'cancelled';
|
||||
|
||||
export type LogLevel = 'log' | 'warn' | 'error';
|
||||
@@ -105,9 +152,12 @@ export type LogLevel = 'log' | 'warn' | 'error';
|
||||
export interface ScenarioRun {
|
||||
id: string;
|
||||
scenarioId: string;
|
||||
environmentId: string;
|
||||
environmentId: string | null;
|
||||
sessionId?: string | null;
|
||||
saveSession: boolean;
|
||||
traceMode: TraceMode | null;
|
||||
/** Scenario version the run executes; null for runs created before versioning. */
|
||||
scenarioVersion: number | null;
|
||||
scenario?: Pick<Scenario, 'id' | 'name'>;
|
||||
environment?: Pick<Environment, 'id' | 'name'>;
|
||||
session?: { id: string; sessionName: string };
|
||||
@@ -120,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;
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
.section {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
.sectionTitle {
|
||||
font-size: 0.8125rem;
|
||||
font-weight: 600;
|
||||
color: var(--text-muted, #888);
|
||||
margin: 0;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.04em;
|
||||
}
|
||||
|
||||
.radioRow {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
font-size: 0.875rem;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.radioRow input[type='radio'] {
|
||||
cursor: pointer;
|
||||
accent-color: var(--color-primary);
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { X, Download } from 'lucide-react';
|
||||
import { Modal, Button } from '../../ui';
|
||||
import styles from './ExportLogsModal.module.css';
|
||||
|
||||
export type LogExportFormat = 'md' | 'csv';
|
||||
|
||||
export interface ExportLogsModalProps {
|
||||
open: boolean;
|
||||
format: LogExportFormat;
|
||||
onFormatChange: (format: LogExportFormat) => void;
|
||||
onClose: () => void;
|
||||
onExport: () => void;
|
||||
isExporting: boolean;
|
||||
}
|
||||
|
||||
export function ExportLogsModal({
|
||||
open,
|
||||
format,
|
||||
onFormatChange,
|
||||
onClose,
|
||||
onExport,
|
||||
isExporting,
|
||||
}: ExportLogsModalProps) {
|
||||
const { t } = useTranslation();
|
||||
|
||||
return (
|
||||
<Modal
|
||||
open={open}
|
||||
title={t('runs.export_logs_modal_title')}
|
||||
onClose={() => !isExporting && onClose()}
|
||||
footer={
|
||||
<>
|
||||
<Button variant="secondary" onClick={onClose} disabled={isExporting}>
|
||||
<X size={14} />
|
||||
{t('common.button_cancel')}
|
||||
</Button>
|
||||
<Button variant="primary" onClick={onExport} disabled={isExporting}>
|
||||
<Download size={14} />
|
||||
{t('runs.action_export')}
|
||||
</Button>
|
||||
</>
|
||||
}
|
||||
>
|
||||
<div className={styles.section}>
|
||||
<h4 className={styles.sectionTitle}>{t('runs.export_logs_format')}</h4>
|
||||
<label className={styles.radioRow}>
|
||||
<input
|
||||
type="radio"
|
||||
name="log-export-format"
|
||||
checked={format === 'md'}
|
||||
onChange={() => onFormatChange('md')}
|
||||
/>
|
||||
<span>{t('runs.export_logs_format_md')}</span>
|
||||
</label>
|
||||
<label className={styles.radioRow}>
|
||||
<input
|
||||
type="radio"
|
||||
name="log-export-format"
|
||||
checked={format === 'csv'}
|
||||
onChange={() => onFormatChange('csv')}
|
||||
/>
|
||||
<span>{t('runs.export_logs_format_csv')}</span>
|
||||
</label>
|
||||
</div>
|
||||
</Modal>
|
||||
);
|
||||
}
|
||||
@@ -1,7 +1,9 @@
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { X, Play } from 'lucide-react';
|
||||
import { Modal, Button, Select } from '../../ui';
|
||||
import type { Environment } from '../../api';
|
||||
import type { Environment, ScenarioVersion, TraceMode } from '../../api';
|
||||
|
||||
const TRACE_MODES: TraceMode[] = ['on', 'retain-on-failure', 'off'];
|
||||
|
||||
export interface RunScenarioModalProps {
|
||||
open: boolean;
|
||||
@@ -10,6 +12,14 @@ export interface RunScenarioModalProps {
|
||||
onEnvSelect: (envId: string) => void;
|
||||
saveSessionFlag: boolean;
|
||||
onSaveSessionChange: (flag: boolean) => void;
|
||||
/** Scenario versions, newest first; empty while loading. */
|
||||
versions: Pick<ScenarioVersion, 'version' | 'createdAt'>[];
|
||||
/** Selected version, or null for the latest. */
|
||||
selectedVersion: number | null;
|
||||
onVersionChange: (version: number | null) => void;
|
||||
traceMode: TraceMode;
|
||||
defaultTraceMode: TraceMode | null;
|
||||
onTraceModeChange: (mode: TraceMode) => void;
|
||||
onClose: () => void;
|
||||
onRun: () => void;
|
||||
isRunning: boolean;
|
||||
@@ -23,6 +33,12 @@ export function RunScenarioModal({
|
||||
onEnvSelect,
|
||||
saveSessionFlag,
|
||||
onSaveSessionChange,
|
||||
versions,
|
||||
selectedVersion,
|
||||
onVersionChange,
|
||||
traceMode,
|
||||
defaultTraceMode,
|
||||
onTraceModeChange,
|
||||
onClose,
|
||||
onRun,
|
||||
isRunning,
|
||||
@@ -58,6 +74,25 @@ export function RunScenarioModal({
|
||||
onChange={(e) => onEnvSelect(e.target.value)}
|
||||
options={environments.map((env) => ({ value: env.id, label: env.name }))}
|
||||
/>
|
||||
<div style={{ marginTop: '1rem' }}>
|
||||
<Select
|
||||
label={t('scenarios.run_modal_version_label')}
|
||||
value={selectedVersion == null ? '' : String(selectedVersion)}
|
||||
onChange={(e) => onVersionChange(e.target.value ? Number(e.target.value) : null)}
|
||||
options={[
|
||||
{
|
||||
value: '',
|
||||
label: versions[0]
|
||||
? t('scenarios.run_modal_version_latest_n', { version: versions[0].version })
|
||||
: t('scenarios.run_modal_version_latest'),
|
||||
},
|
||||
...versions.map((v) => ({
|
||||
value: String(v.version),
|
||||
label: `v${v.version} — ${new Date(v.createdAt).toLocaleString()}`,
|
||||
})),
|
||||
]}
|
||||
/>
|
||||
</div>
|
||||
<label
|
||||
style={{
|
||||
display: 'flex',
|
||||
@@ -73,6 +108,19 @@ export function RunScenarioModal({
|
||||
/>
|
||||
<span>{t('common.save_session')}</span>
|
||||
</label>
|
||||
<div style={{ marginTop: '1rem' }}>
|
||||
<Select
|
||||
label={t('scenarios.run_modal_trace_label')}
|
||||
value={traceMode}
|
||||
onChange={(e) => onTraceModeChange(e.target.value as TraceMode)}
|
||||
options={TRACE_MODES.map((mode) => ({
|
||||
value: mode,
|
||||
label:
|
||||
t(`scenarios.trace_mode_${mode.replace(/-/g, '_')}`) +
|
||||
(mode === defaultTraceMode ? ` ${t('scenarios.trace_mode_default_suffix')}` : ''),
|
||||
}))}
|
||||
/>
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
</Modal>
|
||||
|
||||
@@ -4,3 +4,5 @@ export { ExportScenarioModal } from './ExportScenarioModal';
|
||||
export type { ExportScenarioModalProps } from './ExportScenarioModal';
|
||||
export { RunScenarioModal } from './RunScenarioModal';
|
||||
export type { RunScenarioModalProps } from './RunScenarioModal';
|
||||
export { ExportLogsModal } from './ExportLogsModal';
|
||||
export type { ExportLogsModalProps, LogExportFormat } from './ExportLogsModal';
|
||||
@@ -0,0 +1,26 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
import { scenarios } from '../api';
|
||||
import type { RunDefaults } from '../api';
|
||||
|
||||
// Server run defaults don't change while the app is open; fetch them once
|
||||
let cached: Promise<RunDefaults> | null = null;
|
||||
|
||||
/**
|
||||
* Returns the server-configured defaults for new scenario runs, or null
|
||||
* while they are loading (or if the request failed).
|
||||
*/
|
||||
export function useRunDefaults(): RunDefaults | null {
|
||||
const [defaults, setDefaults] = useState<RunDefaults | null>(null);
|
||||
useEffect(() => {
|
||||
let cancelled = false;
|
||||
cached ??= scenarios.runDefaults().catch((err: unknown) => {
|
||||
cached = null;
|
||||
throw err;
|
||||
});
|
||||
cached.then((d) => !cancelled && setDefaults(d)).catch(() => undefined);
|
||||
return () => {
|
||||
cancelled = true;
|
||||
};
|
||||
}, []);
|
||||
return defaults;
|
||||
}
|
||||
@@ -126,6 +126,7 @@
|
||||
"run_started": "Scenario run started",
|
||||
"col_id": "ID",
|
||||
"col_name": "Name",
|
||||
"col_version": "Version",
|
||||
"col_description": "Description",
|
||||
"col_last_run": "Last Run",
|
||||
"col_updated": "Updated",
|
||||
@@ -135,6 +136,7 @@
|
||||
"action_delete": "Delete",
|
||||
"field_id": "ID",
|
||||
"field_name": "Name",
|
||||
"field_version": "Version",
|
||||
"field_description": "Description",
|
||||
"field_steps": "Steps",
|
||||
"field_created": "Created",
|
||||
@@ -149,6 +151,7 @@
|
||||
"action_edit": "Edit",
|
||||
"action_runs": "Runs",
|
||||
"action_export": "Export",
|
||||
"action_export_e2e": "Export e2e test",
|
||||
"action_import": "Import",
|
||||
"import_error": "Failed to import scenario",
|
||||
"action_save": "Create",
|
||||
@@ -165,6 +168,9 @@
|
||||
"form_name_placeholder": "e.g. Login flow",
|
||||
"form_name_required": "Name is required",
|
||||
"credentials_heading": "Credentials",
|
||||
"used_snippets_heading": "Used Snippets",
|
||||
"used_snippet_pinned": "v{{version}} (pinned)",
|
||||
"used_snippet_latest": "Latest (v{{version}})",
|
||||
"cred_empty": "No credentials assigned.",
|
||||
"cred_col_alias": "Alias",
|
||||
"cred_col_name": "Credential",
|
||||
@@ -183,6 +189,14 @@
|
||||
"run_modal_env_label": "Environment",
|
||||
"run_modal_no_env": "No environments found. Create an environment before running a scenario.",
|
||||
"run_modal_env_required": "Please select an environment",
|
||||
"run_modal_version_label": "Version",
|
||||
"run_modal_version_latest": "Latest",
|
||||
"run_modal_version_latest_n": "Latest (v{{version}})",
|
||||
"run_modal_trace_label": "Playwright trace",
|
||||
"trace_mode_on": "Always keep",
|
||||
"trace_mode_retain_on_failure": "Keep on failure",
|
||||
"trace_mode_off": "Off",
|
||||
"trace_mode_default_suffix": "(default)",
|
||||
"export_modal_title": "Export Scenario",
|
||||
"export_include_environment": "Include Environment",
|
||||
"export_include_credentials": "Include Credentials",
|
||||
@@ -240,12 +254,15 @@
|
||||
"col_scenario": "Scenario",
|
||||
"col_status": "Status",
|
||||
"col_steps": "Steps",
|
||||
"col_version": "Version",
|
||||
"col_created": "Started",
|
||||
"field_id": "ID",
|
||||
"field_status": "Status",
|
||||
"field_steps": "Steps",
|
||||
"field_created": "Started",
|
||||
"field_updated": "Updated",
|
||||
"field_trace": "Playwright trace",
|
||||
"field_scenario_version": "Scenario version",
|
||||
"steps_heading": "Step runs",
|
||||
"step_title": "Title",
|
||||
"logs_heading": "Logs",
|
||||
@@ -257,7 +274,15 @@
|
||||
"step_description": "Result",
|
||||
"log_level": "Level",
|
||||
"log_message": "Message",
|
||||
"log_time": "Time"
|
||||
"log_time": "Time",
|
||||
"action_download_logs": "Download logs",
|
||||
"action_repeat": "Repeat run",
|
||||
"repeat_no_environment": "The environment used by this run no longer exists",
|
||||
"export_logs_modal_title": "Export logs",
|
||||
"export_logs_format": "Format",
|
||||
"export_logs_format_md": "Markdown (.md)",
|
||||
"export_logs_format_csv": "CSV (.csv)",
|
||||
"action_export": "Export"
|
||||
},
|
||||
"snippets": {
|
||||
"title": "Snippets",
|
||||
@@ -287,6 +312,7 @@
|
||||
"form_code_required": "Code is required",
|
||||
"field_id": "ID",
|
||||
"field_alias": "Alias",
|
||||
"field_version": "Version",
|
||||
"field_title": "Title",
|
||||
"field_description": "Description",
|
||||
"field_created": "Created",
|
||||
|
||||
@@ -96,6 +96,17 @@ export function AllRunsPage() {
|
||||
sortable: true,
|
||||
render: (r) => <Badge variant={STATUS_VARIANT[r.status]}>{STATUS_LABEL[r.status]}</Badge>,
|
||||
},
|
||||
{
|
||||
key: 'scenarioVersion',
|
||||
header: t('runs.col_version'),
|
||||
width: 80,
|
||||
render: (r) =>
|
||||
r.scenarioVersion != null ? (
|
||||
`v${r.scenarioVersion}`
|
||||
) : (
|
||||
<span className={styles.muted}>–</span>
|
||||
),
|
||||
},
|
||||
{
|
||||
key: 'createdAt',
|
||||
header: t('runs.col_created'),
|
||||
|
||||
@@ -14,6 +14,7 @@ import type {
|
||||
FileMetadata,
|
||||
} from '../../api';
|
||||
import { scenarios } from '../../api';
|
||||
import { ExportLogsModal, type LogExportFormat } from '../../components/modals';
|
||||
import {
|
||||
AutoRefreshIndicator,
|
||||
Badge,
|
||||
@@ -27,10 +28,18 @@ import {
|
||||
Table,
|
||||
Timestamp,
|
||||
UuidBadge,
|
||||
useToast,
|
||||
type TableColumn,
|
||||
} from '../../ui';
|
||||
import type { BadgeVariant } from '../../ui';
|
||||
import { ChevronDown, ChevronRight, ClipboardList, Activity, Download } from 'lucide-react';
|
||||
import {
|
||||
ChevronDown,
|
||||
ChevronRight,
|
||||
ClipboardList,
|
||||
Activity,
|
||||
Download,
|
||||
RotateCcw,
|
||||
} from 'lucide-react';
|
||||
import styles from '../Page.module.css';
|
||||
|
||||
const RUN_STATUS_VARIANT: Record<ScenarioRunStatus, BadgeVariant> = {
|
||||
@@ -65,9 +74,16 @@ const LOG_LEVEL_VARIANT: Record<LogLevel, BadgeVariant> = {
|
||||
const FINAL: ScenarioRunStatus[] = ['pass', 'fail'];
|
||||
|
||||
export function RunDetailPage() {
|
||||
const { runId } = useParams<{ runId: string }>();
|
||||
// Remount per run so "Repeat run" navigation starts from a clean state
|
||||
return <RunDetail key={runId} />;
|
||||
}
|
||||
|
||||
function RunDetail() {
|
||||
const { t } = useTranslation();
|
||||
const { id, runId } = useParams<{ id: string; runId: string }>();
|
||||
const navigate = useNavigate();
|
||||
const toast = useToast();
|
||||
|
||||
const [scenario, setScenario] = useState<Scenario | null>(null);
|
||||
const [run, setRun] = useState<ScenarioRunDetail | null>(null);
|
||||
@@ -84,6 +100,10 @@ export function RunDetailPage() {
|
||||
const [artifacts, setArtifacts] = useState<FileMetadata[]>([]);
|
||||
const [artifactsTotal, setArtifactsTotal] = useState(0);
|
||||
const [artifactsLoading, setArtifactsLoading] = useState(false);
|
||||
const [exportLogsOpen, setExportLogsOpen] = useState(false);
|
||||
const [exportLogsFormat, setExportLogsFormat] = useState<LogExportFormat>('md');
|
||||
const [exportingLogs, setExportingLogs] = useState(false);
|
||||
const [repeating, setRepeating] = useState(false);
|
||||
const logSearchRef = useRef('');
|
||||
const LOG_PAGE_SIZE = 25;
|
||||
const pollRef = useRef<ReturnType<typeof setInterval> | null>(null);
|
||||
@@ -106,6 +126,47 @@ export function RunDetailPage() {
|
||||
const isFileExpired = (file: FileMetadata) =>
|
||||
file.expiresAt != null && new Date(file.expiresAt).getTime() <= Date.now();
|
||||
|
||||
const handleExportLogs = async () => {
|
||||
if (!id || !runId) return;
|
||||
setExportingLogs(true);
|
||||
try {
|
||||
const content = await runs.exportLogs(id, runId, exportLogsFormat);
|
||||
const mimeType = exportLogsFormat === 'csv' ? 'text/csv' : 'text/markdown';
|
||||
const blob = new Blob([content], { type: mimeType });
|
||||
const url = URL.createObjectURL(blob);
|
||||
const a = document.createElement('a');
|
||||
a.href = url;
|
||||
a.download = `run-${runId}-logs.${exportLogsFormat}`;
|
||||
a.click();
|
||||
URL.revokeObjectURL(url);
|
||||
setExportLogsOpen(false);
|
||||
} catch {
|
||||
// error toast is already emitted by the API client
|
||||
} finally {
|
||||
setExportingLogs(false);
|
||||
}
|
||||
};
|
||||
|
||||
const handleRepeatRun = async () => {
|
||||
if (!id || !run?.environmentId) return;
|
||||
setRepeating(true);
|
||||
try {
|
||||
const newRun = await scenarios.run(
|
||||
id,
|
||||
run.environmentId,
|
||||
run.saveSession,
|
||||
run.traceMode ?? undefined,
|
||||
run.scenarioVersion ?? undefined,
|
||||
);
|
||||
toast.success(t('scenarios.run_started'));
|
||||
navigate(`/scenarios/${id}/runs/${newRun.id}`);
|
||||
} catch (err) {
|
||||
toast.error((err as Error).message);
|
||||
} finally {
|
||||
setRepeating(false);
|
||||
}
|
||||
};
|
||||
|
||||
const manualRefresh = () => {
|
||||
if (!id || !runId) return;
|
||||
runs
|
||||
@@ -198,7 +259,7 @@ export function RunDetailPage() {
|
||||
key: 'title',
|
||||
header: t('runs.step_title'),
|
||||
width: 220,
|
||||
render: (s) => s.scenarioStep?.title ?? <span className={styles.muted}>–</span>,
|
||||
render: (s) => s.title ?? <span className={styles.muted}>–</span>,
|
||||
},
|
||||
{
|
||||
key: 'status',
|
||||
@@ -359,12 +420,27 @@ export function RunDetailPage() {
|
||||
{ label: `${runId}` },
|
||||
]}
|
||||
/>
|
||||
<AutoRefreshIndicator
|
||||
active={polling}
|
||||
pulseKey={pulseKey}
|
||||
error={!!error}
|
||||
onClick={manualRefresh}
|
||||
/>
|
||||
<div style={{ display: 'flex', alignItems: 'center', gap: '8px' }}>
|
||||
{run && (
|
||||
<span title={run.environmentId ? undefined : t('runs.repeat_no_environment')}>
|
||||
<Button
|
||||
variant="secondary"
|
||||
size="sm"
|
||||
onClick={handleRepeatRun}
|
||||
disabled={!run.environmentId || repeating}
|
||||
>
|
||||
<RotateCcw size={14} />
|
||||
{t('runs.action_repeat')}
|
||||
</Button>
|
||||
</span>
|
||||
)}
|
||||
<AutoRefreshIndicator
|
||||
active={polling}
|
||||
pulseKey={pulseKey}
|
||||
error={!!error}
|
||||
onClick={manualRefresh}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{loading && <p className={styles.muted}>{t('runs.loading')}</p>}
|
||||
@@ -388,6 +464,20 @@ export function RunDetailPage() {
|
||||
{ term: t('runs.field_created'), detail: <Timestamp value={run.createdAt} /> },
|
||||
{ term: t('runs.field_updated'), detail: <Timestamp value={run.updatedAt} /> },
|
||||
];
|
||||
if (run.scenarioVersion != null) {
|
||||
items.push({
|
||||
term: t('runs.field_scenario_version'),
|
||||
detail: <span>v{run.scenarioVersion}</span>,
|
||||
});
|
||||
}
|
||||
if (run.traceMode) {
|
||||
items.push({
|
||||
term: t('runs.field_trace'),
|
||||
detail: (
|
||||
<span>{t(`scenarios.trace_mode_${run.traceMode.replace(/-/g, '_')}`)}</span>
|
||||
),
|
||||
});
|
||||
}
|
||||
if (run.environment) {
|
||||
items.push({
|
||||
term: 'Environment',
|
||||
@@ -436,11 +526,17 @@ export function RunDetailPage() {
|
||||
<div className={styles.stepsSection}>
|
||||
<div className={styles.sectionHeadingRow}>
|
||||
<h2 className={styles.sectionHeading}>{t('runs.logs_heading')}</h2>
|
||||
<Search
|
||||
value={logSearch}
|
||||
onChange={setLogSearch}
|
||||
placeholder={t('runs.logs_search_placeholder')}
|
||||
/>
|
||||
<div style={{ display: 'flex', alignItems: 'center', gap: '8px' }}>
|
||||
<Search
|
||||
value={logSearch}
|
||||
onChange={setLogSearch}
|
||||
placeholder={t('runs.logs_search_placeholder')}
|
||||
/>
|
||||
<Button variant="secondary" size="sm" onClick={() => setExportLogsOpen(true)}>
|
||||
<Download size={14} />
|
||||
{t('runs.action_download_logs')}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
<Table
|
||||
columns={logColumns}
|
||||
@@ -523,6 +619,15 @@ export function RunDetailPage() {
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
|
||||
<ExportLogsModal
|
||||
open={exportLogsOpen}
|
||||
format={exportLogsFormat}
|
||||
onFormatChange={setExportLogsFormat}
|
||||
onClose={() => setExportLogsOpen(false)}
|
||||
onExport={handleExportLogs}
|
||||
isExporting={exportingLogs}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -161,6 +161,17 @@ export function RunsPage() {
|
||||
sortable: true,
|
||||
render: (r) => <Badge variant={STATUS_VARIANT[r.status]}>{STATUS_LABEL[r.status]}</Badge>,
|
||||
},
|
||||
{
|
||||
key: 'scenarioVersion',
|
||||
header: t('runs.col_version'),
|
||||
width: 80,
|
||||
render: (r) =>
|
||||
r.scenarioVersion != null ? (
|
||||
`v${r.scenarioVersion}`
|
||||
) : (
|
||||
<span className={styles.muted}>–</span>
|
||||
),
|
||||
},
|
||||
{
|
||||
key: 'createdAt',
|
||||
header: t('runs.col_created'),
|
||||
|
||||
@@ -12,6 +12,7 @@ import {
|
||||
Upload,
|
||||
GripVertical,
|
||||
ClipboardList,
|
||||
FileArchive,
|
||||
} from 'lucide-react';
|
||||
import {
|
||||
environments,
|
||||
@@ -28,6 +29,9 @@ import type {
|
||||
Credential,
|
||||
Environment,
|
||||
FileMetadata,
|
||||
ScenarioVersion,
|
||||
TraceMode,
|
||||
UsedSnippet,
|
||||
} from '../../api';
|
||||
import {
|
||||
Breadcrumbs,
|
||||
@@ -44,7 +48,8 @@ import {
|
||||
useToast,
|
||||
type TableColumn,
|
||||
} from '../../ui';
|
||||
import { ExportScenarioModal } from '../../components/modals';
|
||||
import { ExportScenarioModal, RunScenarioModal } from '../../components/modals';
|
||||
import { useRunDefaults } from '../../hooks/useRunDefaults';
|
||||
import styles from '../Page.module.css';
|
||||
|
||||
export function ScenarioDetailPage() {
|
||||
@@ -71,6 +76,13 @@ export function ScenarioDetailPage() {
|
||||
const [runModalOpen, setRunModalOpen] = useState(false);
|
||||
const [running, setRunning] = useState(false);
|
||||
const [saveSessionFlag, setSaveSessionFlag] = useState(false);
|
||||
// null = use the server's configured default
|
||||
const [traceModeOverride, setTraceModeOverride] = useState<TraceMode | null>(null);
|
||||
const runDefaults = useRunDefaults();
|
||||
const [runVersions, setRunVersions] = useState<ScenarioVersion[]>([]);
|
||||
// null = latest
|
||||
const [runVersion, setRunVersion] = useState<number | null>(null);
|
||||
const traceMode = traceModeOverride ?? runDefaults?.traceMode ?? 'on';
|
||||
const [envs, setEnvs] = useState<Environment[]>([]);
|
||||
const [selectedEnvId, setSelectedEnvId] = useState('');
|
||||
const envInitRef = useRef(false);
|
||||
@@ -94,6 +106,8 @@ export function ScenarioDetailPage() {
|
||||
const [uploadExpiresAt, setUploadExpiresAt] = useState('');
|
||||
const [uploading, setUploading] = useState(false);
|
||||
|
||||
const [usedSnippets, setUsedSnippets] = useState<UsedSnippet[]>([]);
|
||||
|
||||
const loadFiles = useCallback(async () => {
|
||||
if (!id) return;
|
||||
setFilesLoading(true);
|
||||
@@ -116,6 +130,10 @@ export function ScenarioDetailPage() {
|
||||
})
|
||||
.finally(() => setLoading(false));
|
||||
void loadFiles();
|
||||
scenarios
|
||||
.usedSnippets(id)
|
||||
.then(setUsedSnippets)
|
||||
.catch(() => {});
|
||||
credentialsApi
|
||||
.list(1, 200)
|
||||
.then((r) => setAllCredentials(r.data))
|
||||
@@ -142,6 +160,10 @@ export function ScenarioDetailPage() {
|
||||
const s = await scenarios.get(id);
|
||||
setScenario(s);
|
||||
setScenarioCreds(s.scenarioCredentials ?? []);
|
||||
scenarios
|
||||
.usedSnippets(id)
|
||||
.then(setUsedSnippets)
|
||||
.catch(() => {});
|
||||
};
|
||||
|
||||
const handleRun = async () => {
|
||||
@@ -152,7 +174,13 @@ export function ScenarioDetailPage() {
|
||||
}
|
||||
setRunning(true);
|
||||
try {
|
||||
const run = await scenarios.run(scenario.id, selectedEnvId, saveSessionFlag);
|
||||
const run = await scenarios.run(
|
||||
scenario.id,
|
||||
selectedEnvId,
|
||||
saveSessionFlag,
|
||||
traceModeOverride ?? undefined,
|
||||
runVersion ?? undefined,
|
||||
);
|
||||
toast.success(t('scenarios.run_started'));
|
||||
navigate(`/scenarios/${id}/runs/${run.id}`);
|
||||
setRunModalOpen(false);
|
||||
@@ -444,7 +472,21 @@ export function ScenarioDetailPage() {
|
||||
/>
|
||||
{scenario && (
|
||||
<div className={styles.toolbarActions}>
|
||||
<Button size="sm" onClick={() => setRunModalOpen(true)}>
|
||||
<Button
|
||||
size="sm"
|
||||
onClick={() => {
|
||||
setTraceModeOverride(null);
|
||||
setRunVersion(null);
|
||||
setRunVersions([]);
|
||||
if (id) {
|
||||
scenarios
|
||||
.versions(id)
|
||||
.then(setRunVersions)
|
||||
.catch(() => undefined);
|
||||
}
|
||||
setRunModalOpen(true);
|
||||
}}
|
||||
>
|
||||
<Play size={14} />
|
||||
{t('scenarios.action_run')}
|
||||
</Button>
|
||||
@@ -456,6 +498,16 @@ export function ScenarioDetailPage() {
|
||||
<Upload size={14} />
|
||||
{t('scenarios.action_export')}
|
||||
</Button>
|
||||
<Button
|
||||
variant="secondary"
|
||||
size="sm"
|
||||
onClick={() =>
|
||||
handleFileDownload(scenarios.exportE2eTestUrl(id!), `${scenario.name}-e2e-test.zip`)
|
||||
}
|
||||
>
|
||||
<FileArchive size={14} />
|
||||
{t('scenarios.action_export_e2e')}
|
||||
</Button>
|
||||
<Button variant="secondary" size="sm" onClick={() => navigate(`/scenarios/${id}/edit`)}>
|
||||
<Pencil size={14} />
|
||||
{t('scenarios.action_edit')}
|
||||
@@ -482,6 +534,7 @@ export function ScenarioDetailPage() {
|
||||
items={[
|
||||
{ term: t('scenarios.field_id'), detail: <UuidBadge id={scenario.id} /> },
|
||||
{ term: t('scenarios.field_name'), detail: scenario.name },
|
||||
{ term: t('scenarios.field_version'), detail: `v${scenario.version}` },
|
||||
...(scenario.environment
|
||||
? [
|
||||
{
|
||||
@@ -651,6 +704,44 @@ export function ScenarioDetailPage() {
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* ── Used snippets section ───────────────────────────────────────── */}
|
||||
{usedSnippets.length > 0 && (
|
||||
<div className={styles.stepsSection}>
|
||||
<div className={styles.sectionToolbar}>
|
||||
<h2 className={styles.sectionHeading}>{t('scenarios.used_snippets_heading')}</h2>
|
||||
</div>
|
||||
<Table<UsedSnippet>
|
||||
data={usedSnippets}
|
||||
rowKey={(s) => `${s.id}@${s.pinnedVersion ?? 'latest'}`}
|
||||
loading={false}
|
||||
emptyMessage=""
|
||||
onRowClick={(s) => navigate(`/snippets/${s.id}`)}
|
||||
columns={
|
||||
[
|
||||
{
|
||||
key: 'alias',
|
||||
header: t('snippets.field_alias'),
|
||||
render: (s) => s.alias,
|
||||
},
|
||||
{
|
||||
key: 'title',
|
||||
header: t('snippets.field_title'),
|
||||
render: (s) => s.title,
|
||||
},
|
||||
{
|
||||
key: 'version',
|
||||
header: t('snippets.field_version'),
|
||||
render: (s) =>
|
||||
s.pinnedVersion != null
|
||||
? t('scenarios.used_snippet_pinned', { version: s.pinnedVersion })
|
||||
: t('scenarios.used_snippet_latest', { version: s.version }),
|
||||
},
|
||||
] satisfies TableColumn<UsedSnippet>[]
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* ── Files section ───────────────────────────────────────────────── */}
|
||||
<div className={styles.stepsSection}>
|
||||
<div className={styles.sectionToolbar}>
|
||||
@@ -774,44 +865,23 @@ export function ScenarioDetailPage() {
|
||||
{pendingDelete?.type === 'scenario' && t('common.confirm_delete_scenario')}
|
||||
</Modal>
|
||||
|
||||
<Modal
|
||||
<RunScenarioModal
|
||||
open={runModalOpen}
|
||||
title={t('scenarios.run_modal_title')}
|
||||
onClose={() => !running && setRunModalOpen(false)}
|
||||
footer={
|
||||
<>
|
||||
<Button variant="secondary" onClick={() => setRunModalOpen(false)} disabled={running}>
|
||||
{t('common.button_cancel')}
|
||||
</Button>
|
||||
<Button variant="primary" onClick={handleRun} disabled={running || !selectedEnvId}>
|
||||
{t('scenarios.action_run')}
|
||||
</Button>
|
||||
</>
|
||||
}
|
||||
>
|
||||
{envs.length === 0 ? (
|
||||
<p>{t('scenarios.run_modal_no_env')}</p>
|
||||
) : (
|
||||
<>
|
||||
<Select
|
||||
label={t('scenarios.run_modal_env_label')}
|
||||
value={selectedEnvId}
|
||||
onChange={(e) => setSelectedEnvId(e.target.value)}
|
||||
options={envs.map((env) => ({ value: env.id, label: env.name }))}
|
||||
/>
|
||||
<label
|
||||
style={{ display: 'flex', alignItems: 'center', marginTop: '1rem', gap: '0.5rem' }}
|
||||
>
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={saveSessionFlag}
|
||||
onChange={(e) => setSaveSessionFlag(e.target.checked)}
|
||||
/>
|
||||
<span>{t('common.save_session')}</span>
|
||||
</label>
|
||||
</>
|
||||
)}
|
||||
</Modal>
|
||||
environments={envs}
|
||||
selectedEnvId={selectedEnvId}
|
||||
onEnvSelect={setSelectedEnvId}
|
||||
saveSessionFlag={saveSessionFlag}
|
||||
onSaveSessionChange={setSaveSessionFlag}
|
||||
versions={runVersions}
|
||||
selectedVersion={runVersion}
|
||||
onVersionChange={setRunVersion}
|
||||
traceMode={traceMode}
|
||||
defaultTraceMode={runDefaults?.traceMode ?? null}
|
||||
onTraceModeChange={setTraceModeOverride}
|
||||
onClose={() => setRunModalOpen(false)}
|
||||
onRun={handleRun}
|
||||
isRunning={running}
|
||||
/>
|
||||
|
||||
<ExportScenarioModal
|
||||
open={exportModalOpen}
|
||||
|
||||
@@ -5,13 +5,14 @@ import { usePageTitle } from '../../hooks/usePageTitle';
|
||||
import { Play, Plus, Trash2, Download, ClipboardList } from 'lucide-react';
|
||||
import { parse as yamlParse } from 'yaml';
|
||||
import { environments, scenarios } from '../../api';
|
||||
import type { Environment, Scenario } from '../../api';
|
||||
import type { Environment, Scenario, ScenarioVersion, TraceMode } from '../../api';
|
||||
import { RunScenarioModal } from '../../components/modals';
|
||||
import { useRunDefaults } from '../../hooks/useRunDefaults';
|
||||
import {
|
||||
Badge,
|
||||
Breadcrumbs,
|
||||
Button,
|
||||
Modal,
|
||||
Select,
|
||||
Table,
|
||||
type TableColumn,
|
||||
type SortDirection,
|
||||
@@ -49,6 +50,13 @@ export function ScenariosPage() {
|
||||
const [runScenarioId, setRunScenarioId] = useState<string | null>(null);
|
||||
const [running, setRunning] = useState(false);
|
||||
const [saveSessionFlag, setSaveSessionFlag] = useState(false);
|
||||
// null = use the server's configured default
|
||||
const [traceModeOverride, setTraceModeOverride] = useState<TraceMode | null>(null);
|
||||
const runDefaults = useRunDefaults();
|
||||
const [runVersions, setRunVersions] = useState<ScenarioVersion[]>([]);
|
||||
// null = latest
|
||||
const [runVersion, setRunVersion] = useState<number | null>(null);
|
||||
const traceMode = traceModeOverride ?? runDefaults?.traceMode ?? 'on';
|
||||
const [envs, setEnvs] = useState<Environment[]>([]);
|
||||
const [selectedEnvId, setSelectedEnvId] = useState('');
|
||||
|
||||
@@ -104,6 +112,13 @@ export function ScenariosPage() {
|
||||
|
||||
const openRunModal = (id: string) => {
|
||||
setRunScenarioId(id);
|
||||
setTraceModeOverride(null);
|
||||
setRunVersion(null);
|
||||
setRunVersions([]);
|
||||
scenarios
|
||||
.versions(id)
|
||||
.then(setRunVersions)
|
||||
.catch(() => undefined);
|
||||
const scenario = items.find((s) => s.id === id);
|
||||
const preferred = scenario?.environmentId ?? null;
|
||||
const exists = preferred ? envs.some((e) => e.id === preferred) : false;
|
||||
@@ -114,7 +129,13 @@ export function ScenariosPage() {
|
||||
if (!runScenarioId || !selectedEnvId) return;
|
||||
setRunning(true);
|
||||
try {
|
||||
const run = await scenarios.run(runScenarioId, selectedEnvId, saveSessionFlag);
|
||||
const run = await scenarios.run(
|
||||
runScenarioId,
|
||||
selectedEnvId,
|
||||
saveSessionFlag,
|
||||
traceModeOverride ?? undefined,
|
||||
runVersion ?? undefined,
|
||||
);
|
||||
toast.success(t('scenarios.run_started'));
|
||||
navigate(`/scenarios/${runScenarioId}/runs/${run.id}`);
|
||||
setRunScenarioId(null);
|
||||
@@ -155,6 +176,12 @@ export function ScenariosPage() {
|
||||
const columns: TableColumn<Scenario>[] = [
|
||||
{ key: 'id', header: t('scenarios.col_id'), render: (s) => <UuidBadge id={s.id} />, width: 60 },
|
||||
{ key: 'name', header: t('scenarios.col_name'), render: (s) => s.name, sortable: true },
|
||||
{
|
||||
key: 'version',
|
||||
header: t('scenarios.col_version'),
|
||||
width: 80,
|
||||
render: (s) => `v${s.version}`,
|
||||
},
|
||||
{
|
||||
key: 'lastRunStatus',
|
||||
header: t('scenarios.col_last_run'),
|
||||
@@ -271,44 +298,23 @@ export function ScenariosPage() {
|
||||
{t('common.confirm_delete_scenario')}
|
||||
</Modal>
|
||||
|
||||
<Modal
|
||||
<RunScenarioModal
|
||||
open={runScenarioId != null}
|
||||
title={t('scenarios.run_modal_title')}
|
||||
onClose={() => !running && setRunScenarioId(null)}
|
||||
footer={
|
||||
<>
|
||||
<Button variant="secondary" onClick={() => setRunScenarioId(null)} disabled={running}>
|
||||
Cancel
|
||||
</Button>
|
||||
<Button variant="primary" onClick={handleRun} disabled={running || !selectedEnvId}>
|
||||
{t('scenarios.action_run')}
|
||||
</Button>
|
||||
</>
|
||||
}
|
||||
>
|
||||
{envs.length === 0 ? (
|
||||
<p>{t('scenarios.run_modal_no_env')}</p>
|
||||
) : (
|
||||
<>
|
||||
<Select
|
||||
label={t('scenarios.run_modal_env_label')}
|
||||
value={selectedEnvId}
|
||||
onChange={(e) => setSelectedEnvId(e.target.value)}
|
||||
options={envs.map((env) => ({ value: env.id, label: env.name }))}
|
||||
/>
|
||||
<label
|
||||
style={{ display: 'flex', alignItems: 'center', marginTop: '1rem', gap: '0.5rem' }}
|
||||
>
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={saveSessionFlag}
|
||||
onChange={(e) => setSaveSessionFlag(e.target.checked)}
|
||||
/>
|
||||
<span>{t('common.save_session')}</span>
|
||||
</label>
|
||||
</>
|
||||
)}
|
||||
</Modal>
|
||||
environments={envs}
|
||||
selectedEnvId={selectedEnvId}
|
||||
onEnvSelect={setSelectedEnvId}
|
||||
saveSessionFlag={saveSessionFlag}
|
||||
onSaveSessionChange={setSaveSessionFlag}
|
||||
versions={runVersions}
|
||||
selectedVersion={runVersion}
|
||||
onVersionChange={setRunVersion}
|
||||
traceMode={traceMode}
|
||||
defaultTraceMode={runDefaults?.traceMode ?? null}
|
||||
onTraceModeChange={setTraceModeOverride}
|
||||
onClose={() => setRunScenarioId(null)}
|
||||
onRun={handleRun}
|
||||
isRunning={running}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -107,6 +107,7 @@ export function SnippetDetailPage() {
|
||||
{ term: t('snippets.field_id'), detail: <UuidBadge id={snippet.id} /> },
|
||||
{ term: t('snippets.field_alias'), detail: snippet.alias },
|
||||
{ term: t('snippets.field_title'), detail: snippet.title },
|
||||
{ term: t('snippets.field_version'), detail: `v${snippet.version}` },
|
||||
{
|
||||
term: t('snippets.field_created'),
|
||||
detail: <Timestamp value={snippet.createdAt} />,
|
||||
|
||||
@@ -84,6 +84,7 @@ function SnippetCard({ snippet, onDelete }: { snippet: Snippet; onDelete: (id: s
|
||||
>
|
||||
<p className={styles.muted}>
|
||||
{t('snippets.field_alias')}: <code className={styles.codeInline}>{snippet.alias}</code>
|
||||
{' · '}v{snippet.version}
|
||||
</p>
|
||||
{snippet.description &&
|
||||
(() => {
|
||||
|
||||
+17
-3
@@ -44,11 +44,25 @@ The server currently registers the following tools.
|
||||
| `update_scenario_step` | Update step fields |
|
||||
| `delete_scenario_step` | Delete step |
|
||||
| `list_scenario_runs` | List runs for a scenario |
|
||||
| `run_scenario` | Trigger run for scenario |
|
||||
| `list_scenario_versions` | List a scenario's versions, newest first |
|
||||
| `get_scenario_version` | Get one scenario version with its steps |
|
||||
| `run_scenario` | Trigger run for scenario; optional `version` (defaults to latest) and `traceMode` |
|
||||
| `get_scenario_run` | Get run with step runs and logs |
|
||||
| `wait_for_scenario_run` | Wait until run is `pass` or `fail` |
|
||||
| `export_scenario` | Export scenario payload |
|
||||
| `import_scenario` | Import scenario payload |
|
||||
| `export_scenario` | Export one scenario version (optional `version`, defaults to latest) |
|
||||
| `import_scenario` | Import one scenario version; `version` is required (see "Versioning" in `scenario.md`) |
|
||||
|
||||
## Snippets
|
||||
|
||||
| Tool | Description |
|
||||
|---|---|
|
||||
| `list_snippets` | List snippets (paginated) |
|
||||
| `get_snippet` | Get one snippet (latest version) |
|
||||
| `create_snippet` | Create snippet (`alias`, `title`, `code`) |
|
||||
| `update_snippet` | Update snippet fields; bumps its version when content changes |
|
||||
| `delete_snippet` | Delete snippet and all its versions |
|
||||
| `list_snippet_versions` | List a snippet's versions, newest first |
|
||||
| `get_snippet_version` | Get one snippet version |
|
||||
|
||||
## Scenario Files
|
||||
|
||||
|
||||
+34
-1
@@ -35,11 +35,44 @@ Available in scope:
|
||||
- `context.getStepOutput(order)`: prior step output by absolute order (`1`, `2`, ...) or relative (`-1` = previous step)
|
||||
- `context.dumpDom(selector?)`: simplified DOM snapshot
|
||||
- `context.log(...args)`, `context.warn(...args)`, `context.error(...args)`: structured step logs
|
||||
- `context.runSnippet(name, ...args)`: execute stored snippet code with the same context
|
||||
- `context.assert(() => boolean, description)`: runs the arrow function and requires it to return `true`. Logs `description` (as a `log` entry on success, as an `error` entry on failure or exception), then throws to stop the step if the function returned anything other than `true` or threw
|
||||
- `context.runSnippet(name, ...args)`: execute stored snippet code with the same context. `name` is the snippet alias for its latest version, or `alias@<version>` (e.g. `login@3`) to pin a specific version
|
||||
- `context.getScenarioFiles(opts?)`: list files uploaded to the scenario (`limit`, `offset`)
|
||||
- `context.downloadFile(url, opts?)`: fetch `url` and save the result as a run artifact (requires a real scenario run — throws when invoked ad hoc, e.g. via the `exec_code` MCP tool). `opts` may include `method`, `headers`, `body`, `filename`. `url` also accepts a `data:` URI (`data:<mediaType>;base64,<data>` or `data:<mediaType>,<percent-encoded data>`) to save content generated in-script (e.g. a credential JWT) directly, without an actual network fetch.
|
||||
- `console`: proxied to run logs (`log`, `warn`, `error`, etc.)
|
||||
|
||||
`validateCode` additionally receives `result` in scope, which is the value returned by `execCode`.
|
||||
|
||||
## Versioning
|
||||
|
||||
Scenarios and snippets are versioned, starting at version 1.
|
||||
|
||||
- A scenario's version goes up when its content changes: name, description, default environment, timeout, or any step change (add, edit, delete, reorder). Credential assignments and uploaded files are not versioned. Saving without changes does not create a new version.
|
||||
- A snippet's version goes up when its alias, title, description or code changes.
|
||||
- The scenario and snippet pages always show the latest version. Older versions are available via `GET /scenarios/:id/versions[/:version]` and `GET /snippets/:id/versions[/:version]`.
|
||||
- A run executes one scenario version, chosen in the run modal (latest by default) or via `version` in `POST /scenarios/:id/run`. The run keeps its own copy of that version's steps, so deleting or editing steps later doesn't change what the run shows. "Repeat run" reuses the run's version.
|
||||
- Step code uses the latest version of a snippet by default. `context.runSnippet("alias@3")` pins version 3 instead. The version is looked up through the snippet's current alias. Pinned versions are listed under "Used Snippets" on the scenario page.
|
||||
|
||||
### Export / import
|
||||
|
||||
Exports hold exactly one version and always include its `version` number (the latest by default, or `?version=N`). Imports require `version`, and restore that exact version by id + version:
|
||||
|
||||
- If that version already exists, it is left untouched.
|
||||
- Otherwise it is stored under that number, and becomes the latest if it is higher than the current latest version.
|
||||
- Without an `id`, a new scenario or snippet is created at the given version.
|
||||
|
||||
## Playwright traces
|
||||
|
||||
Each run records a [Playwright trace](https://playwright.dev/docs/trace-viewer) of its browser context (screenshots and DOM snapshots). When the run finishes, the trace is uploaded to the run's files as `trace.zip`. Download it from the run detail page, then open it with `npx playwright show-trace trace.zip` or at https://trace.playwright.dev.
|
||||
|
||||
The trace mode is chosen per run: the run modal in the UI, the `traceMode` field of `POST /scenarios/:id/run`, and the `traceMode` argument of the `run_scenario` MCP tool all accept one of the values below. When it is omitted, the server's `PLAYWRIGHT_TRACE_MODE` setting is used (exposed via `GET /scenarios/run-defaults`). "Repeat run" reuses the original run's mode.
|
||||
|
||||
- `on` (default): keep the trace of every run
|
||||
- `retain-on-failure`: keep traces only for runs that failed
|
||||
- `off`: do not record traces
|
||||
|
||||
Traces are run artifacts, so they expire after `FILE_RUN_EXPIRATION_DAYS` like other run files.
|
||||
|
||||
## Validation contract
|
||||
|
||||
`validateCode` may return:
|
||||
|
||||
Generated
+667
-6
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "liqa",
|
||||
"version": "1.7.1",
|
||||
"version": "1.16.0",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "liqa",
|
||||
"version": "1.7.1",
|
||||
"version": "1.16.0",
|
||||
"workspaces": [
|
||||
"server",
|
||||
"client"
|
||||
@@ -4665,6 +4665,16 @@
|
||||
"@types/react": "^19.2.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@types/readdir-glob": {
|
||||
"version": "1.1.5",
|
||||
"resolved": "https://registry.npmjs.org/@types/readdir-glob/-/readdir-glob-1.1.5.tgz",
|
||||
"integrity": "sha512-raiuEPUYqXu+nvtY2Pe8s8FEmZ3x5yAH4VkLdihcPdalvsHltomrRC9BzuStrJ9yk06470hS0Crw0f1pXqD+Hg==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@types/node": "*"
|
||||
}
|
||||
},
|
||||
"node_modules/@types/resolve": {
|
||||
"version": "1.20.6",
|
||||
"resolved": "https://registry.npmjs.org/@types/resolve/-/resolve-1.20.6.tgz",
|
||||
@@ -5565,6 +5575,18 @@
|
||||
"dev": true,
|
||||
"license": "Apache-2.0"
|
||||
},
|
||||
"node_modules/abort-controller": {
|
||||
"version": "3.0.0",
|
||||
"resolved": "https://registry.npmjs.org/abort-controller/-/abort-controller-3.0.0.tgz",
|
||||
"integrity": "sha512-h8lQ8tacZYnR3vNQTgibj+tODHI5/+l06Au2Pcriv/Gmet0eaj4TwWH41sO9wnHDiQsEj19q0drzdWdeAHtweg==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"event-target-shim": "^5.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=6.5"
|
||||
}
|
||||
},
|
||||
"node_modules/accepts": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/accepts/-/accepts-2.0.0.tgz",
|
||||
@@ -5760,6 +5782,201 @@
|
||||
"integrity": "sha512-klpgFSWLW1ZEs8svjfb7g4qWY0YS5imI82dTg+QahUvJ8YqAY0P10Uk8tTyh9ZGuYEZEMaeJYCF5BFuX552hsw==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/archiver": {
|
||||
"version": "7.0.1",
|
||||
"resolved": "https://registry.npmjs.org/archiver/-/archiver-7.0.1.tgz",
|
||||
"integrity": "sha512-ZcbTaIqJOfCc03QwD468Unz/5Ir8ATtvAHsK+FdXbDIbGfihqh9mrvdcYunQzqn4HrvWWaFyaxJhGZagaJJpPQ==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"archiver-utils": "^5.0.2",
|
||||
"async": "^3.2.4",
|
||||
"buffer-crc32": "^1.0.0",
|
||||
"readable-stream": "^4.0.0",
|
||||
"readdir-glob": "^1.1.2",
|
||||
"tar-stream": "^3.0.0",
|
||||
"zip-stream": "^6.0.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 14"
|
||||
}
|
||||
},
|
||||
"node_modules/archiver-utils": {
|
||||
"version": "5.0.2",
|
||||
"resolved": "https://registry.npmjs.org/archiver-utils/-/archiver-utils-5.0.2.tgz",
|
||||
"integrity": "sha512-wuLJMmIBQYCsGZgYLTy5FIB2pF6Lfb6cXMSF8Qywwk3t20zWnAi7zLcQFdKQmIB8wyZpY5ER38x08GbwtR2cLA==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"glob": "^10.0.0",
|
||||
"graceful-fs": "^4.2.0",
|
||||
"is-stream": "^2.0.1",
|
||||
"lazystream": "^1.0.0",
|
||||
"lodash": "^4.17.15",
|
||||
"normalize-path": "^3.0.0",
|
||||
"readable-stream": "^4.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 14"
|
||||
}
|
||||
},
|
||||
"node_modules/archiver-utils/node_modules/brace-expansion": {
|
||||
"version": "2.1.7",
|
||||
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.1.7.tgz",
|
||||
"integrity": "sha512-uZbew1NqdmPDTMJ8ah1y+b+9QEJrfkXFk3RcTQw3X0jW/xRUvFKsg1CfQdSYGdTbXZWExtU3J3ccxtnfw1Fi0g==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"balanced-match": "^1.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/archiver-utils/node_modules/buffer": {
|
||||
"version": "6.0.3",
|
||||
"resolved": "https://registry.npmjs.org/buffer/-/buffer-6.0.3.tgz",
|
||||
"integrity": "sha512-FTiCpNxtwiZZHEZbcbTIcZjERVICn9yq/pDFkTl95/AxzD1naBctN7YO68riM/gLSDY7sdrMby8hofADYuuqOA==",
|
||||
"funding": [
|
||||
{
|
||||
"type": "github",
|
||||
"url": "https://github.com/sponsors/feross"
|
||||
},
|
||||
{
|
||||
"type": "patreon",
|
||||
"url": "https://www.patreon.com/feross"
|
||||
},
|
||||
{
|
||||
"type": "consulting",
|
||||
"url": "https://feross.org/support"
|
||||
}
|
||||
],
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"base64-js": "^1.3.1",
|
||||
"ieee754": "^1.2.1"
|
||||
}
|
||||
},
|
||||
"node_modules/archiver-utils/node_modules/glob": {
|
||||
"version": "10.5.0",
|
||||
"resolved": "https://registry.npmjs.org/glob/-/glob-10.5.0.tgz",
|
||||
"integrity": "sha512-DfXN8DfhJ7NH3Oe7cFmu3NCu1wKbkReJ8TorzSAFbSKrlNaQSKfIzqYqVY8zlbs2NLBbWpRiU52GX2PbaBVNkg==",
|
||||
"deprecated": "Old versions of glob are not supported, and contain widely publicized security vulnerabilities, which have been fixed in the current version. Please update. Support for old versions may be purchased (at exorbitant rates) by contacting i@izs.me",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"foreground-child": "^3.1.0",
|
||||
"jackspeak": "^3.1.2",
|
||||
"minimatch": "^9.0.4",
|
||||
"minipass": "^7.1.2",
|
||||
"package-json-from-dist": "^1.0.0",
|
||||
"path-scurry": "^1.11.1"
|
||||
},
|
||||
"bin": {
|
||||
"glob": "dist/esm/bin.mjs"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/isaacs"
|
||||
}
|
||||
},
|
||||
"node_modules/archiver-utils/node_modules/lru-cache": {
|
||||
"version": "10.4.3",
|
||||
"resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-10.4.3.tgz",
|
||||
"integrity": "sha512-JNAzZcXrCt42VGLuYz0zfAzDfAvJWW6AfYlDBQyDV5DClI2m5sAmK+OIO7s59XfsRsWHp02jAJrRadPRGTt6SQ==",
|
||||
"license": "ISC"
|
||||
},
|
||||
"node_modules/archiver-utils/node_modules/minimatch": {
|
||||
"version": "9.0.9",
|
||||
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.9.tgz",
|
||||
"integrity": "sha512-OBwBN9AL4dqmETlpS2zasx+vTeWclWzkblfZk7KTA5j3jeOONz/tRCnZomUyvNg83wL5Zv9Ss6HMJXAgL8R2Yg==",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"brace-expansion": "^2.0.2"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=16 || 14 >=14.17"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/isaacs"
|
||||
}
|
||||
},
|
||||
"node_modules/archiver-utils/node_modules/path-scurry": {
|
||||
"version": "1.11.1",
|
||||
"resolved": "https://registry.npmjs.org/path-scurry/-/path-scurry-1.11.1.tgz",
|
||||
"integrity": "sha512-Xa4Nw17FS9ApQFJ9umLiJS4orGjm7ZzwUrwamcGQuHSzDyth9boKDaycYdDcZDuqYATXw4HFXgaqWTctW/v1HA==",
|
||||
"license": "BlueOak-1.0.0",
|
||||
"dependencies": {
|
||||
"lru-cache": "^10.2.0",
|
||||
"minipass": "^5.0.0 || ^6.0.2 || ^7.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=16 || 14 >=14.18"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/isaacs"
|
||||
}
|
||||
},
|
||||
"node_modules/archiver-utils/node_modules/readable-stream": {
|
||||
"version": "4.7.0",
|
||||
"resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-4.7.0.tgz",
|
||||
"integrity": "sha512-oIGGmcpTLwPga8Bn6/Z75SVaH1z5dUut2ibSyAMVhmUggWpmDn2dapB0n7f8nwaSiRtepAsfJyfXIO5DCVAODg==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"abort-controller": "^3.0.0",
|
||||
"buffer": "^6.0.3",
|
||||
"events": "^3.3.0",
|
||||
"process": "^0.11.10",
|
||||
"string_decoder": "^1.3.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": "^12.22.0 || ^14.17.0 || >=16.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/archiver/node_modules/buffer": {
|
||||
"version": "6.0.3",
|
||||
"resolved": "https://registry.npmjs.org/buffer/-/buffer-6.0.3.tgz",
|
||||
"integrity": "sha512-FTiCpNxtwiZZHEZbcbTIcZjERVICn9yq/pDFkTl95/AxzD1naBctN7YO68riM/gLSDY7sdrMby8hofADYuuqOA==",
|
||||
"funding": [
|
||||
{
|
||||
"type": "github",
|
||||
"url": "https://github.com/sponsors/feross"
|
||||
},
|
||||
{
|
||||
"type": "patreon",
|
||||
"url": "https://www.patreon.com/feross"
|
||||
},
|
||||
{
|
||||
"type": "consulting",
|
||||
"url": "https://feross.org/support"
|
||||
}
|
||||
],
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"base64-js": "^1.3.1",
|
||||
"ieee754": "^1.2.1"
|
||||
}
|
||||
},
|
||||
"node_modules/archiver/node_modules/readable-stream": {
|
||||
"version": "4.7.0",
|
||||
"resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-4.7.0.tgz",
|
||||
"integrity": "sha512-oIGGmcpTLwPga8Bn6/Z75SVaH1z5dUut2ibSyAMVhmUggWpmDn2dapB0n7f8nwaSiRtepAsfJyfXIO5DCVAODg==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"abort-controller": "^3.0.0",
|
||||
"buffer": "^6.0.3",
|
||||
"events": "^3.3.0",
|
||||
"process": "^0.11.10",
|
||||
"string_decoder": "^1.3.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": "^12.22.0 || ^14.17.0 || >=16.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/archiver/node_modules/tar-stream": {
|
||||
"version": "3.2.1",
|
||||
"resolved": "https://registry.npmjs.org/tar-stream/-/tar-stream-3.2.1.tgz",
|
||||
"integrity": "sha512-nqsEO8zLZJvrOMdEwkA0QdCLFbetHMn95Zqu4fKwX+hkaTWJPZZOrxx/PwtxoK0MMGQmBQNRW3CPs8IFYQz4cQ==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"b4a": "^1.6.4",
|
||||
"bare-fs": "^4.5.5",
|
||||
"fast-fifo": "^1.2.0",
|
||||
"streamx": "^2.15.0"
|
||||
}
|
||||
},
|
||||
"node_modules/argparse": {
|
||||
"version": "2.0.1",
|
||||
"resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz",
|
||||
@@ -5842,6 +6059,12 @@
|
||||
"dev": true,
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/async": {
|
||||
"version": "3.2.6",
|
||||
"resolved": "https://registry.npmjs.org/async/-/async-3.2.6.tgz",
|
||||
"integrity": "sha512-htCUDlxyyCLMgaM3xXg0C0LW2xqfuQ6p05pCEIsXuyQ+a1koYKTuBMzRNwmybfLgvJDMd0r1LTn4+E0Ti6C2AA==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/asynckit": {
|
||||
"version": "0.4.0",
|
||||
"resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz",
|
||||
@@ -5874,6 +6097,20 @@
|
||||
"node": ">=4"
|
||||
}
|
||||
},
|
||||
"node_modules/b4a": {
|
||||
"version": "1.9.0",
|
||||
"resolved": "https://registry.npmjs.org/b4a/-/b4a-1.9.0.tgz",
|
||||
"integrity": "sha512-dpfcF9fDNR6++cthXR67iyhgqWy9CBouAvIWhIntzBG6cvK/cnIPiZQjBwi/ZqjjBEDGfoNDtmB0kTjroOJ3pQ==",
|
||||
"license": "Apache-2.0",
|
||||
"peerDependencies": {
|
||||
"react-native-b4a": "*"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"react-native-b4a": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/babel-jest": {
|
||||
"version": "30.3.0",
|
||||
"resolved": "https://registry.npmjs.org/babel-jest/-/babel-jest-30.3.0.tgz",
|
||||
@@ -5989,6 +6226,86 @@
|
||||
"integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/bare-events": {
|
||||
"version": "2.9.2",
|
||||
"resolved": "https://registry.npmjs.org/bare-events/-/bare-events-2.9.2.tgz",
|
||||
"integrity": "sha512-AIPKioV7/Y/8KfZ3AAhjPJxLLbY49S64Ym5DakZlUg75qQiTgUq9hEJoEwa4eUezPUlXRy/i5NpsKvo9jgKmoA==",
|
||||
"license": "Apache-2.0",
|
||||
"peerDependencies": {
|
||||
"bare-abort-controller": "*"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"bare-abort-controller": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/bare-fs": {
|
||||
"version": "4.8.1",
|
||||
"resolved": "https://registry.npmjs.org/bare-fs/-/bare-fs-4.8.1.tgz",
|
||||
"integrity": "sha512-N1nnXdHZAOSstz0XiHikGS4HGMH4CnSwhqWdGQQMqqdvp4Jybm9sE3R1WVnpWVd4SFkc8ryPDBLViNLwiEqECg==",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"bare-events": "^2.5.4",
|
||||
"bare-path": "^3.0.0",
|
||||
"bare-stream": "^2.6.4",
|
||||
"bare-url": "^2.2.2",
|
||||
"fast-fifo": "^1.3.2"
|
||||
},
|
||||
"engines": {
|
||||
"bare": ">=1.28.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"bare-buffer": "*"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"bare-buffer": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/bare-path": {
|
||||
"version": "3.1.2",
|
||||
"resolved": "https://registry.npmjs.org/bare-path/-/bare-path-3.1.2.tgz",
|
||||
"integrity": "sha512-ZyKbsuuqK6Ag0K8pX6V5Txq6XeJRvY+wXucnFGRjiyVYP9YWDpIQugk/b+enRYrEYBJaqLzghRQpXPMR7341Nw==",
|
||||
"license": "Apache-2.0"
|
||||
},
|
||||
"node_modules/bare-stream": {
|
||||
"version": "2.13.4",
|
||||
"resolved": "https://registry.npmjs.org/bare-stream/-/bare-stream-2.13.4.tgz",
|
||||
"integrity": "sha512-PcrQ8lVLbiJscNm1Kez+Yp4Gy4AHGcN1lzwjvf5NybWen7VvEgUfyfnXYJ2zNqWnzOfCb1Abq6lH8ti0syQszA==",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"b4a": "^1.8.1",
|
||||
"streamx": "^2.25.0",
|
||||
"teex": "^1.0.1"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"bare-abort-controller": "*",
|
||||
"bare-buffer": "*",
|
||||
"bare-events": "*"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"bare-abort-controller": {
|
||||
"optional": true
|
||||
},
|
||||
"bare-buffer": {
|
||||
"optional": true
|
||||
},
|
||||
"bare-events": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/bare-url": {
|
||||
"version": "2.5.4",
|
||||
"resolved": "https://registry.npmjs.org/bare-url/-/bare-url-2.5.4.tgz",
|
||||
"integrity": "sha512-Gxa7UVWBr0/edU1b+TJhn/AZvMQUj9OGspvYsaTYQrAbZA4BOTZGL3LiZxvD+CeMlDH4juwD84+eTAp/bLYW5g==",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"bare-path": "^3.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/base64-js": {
|
||||
"version": "1.5.1",
|
||||
"resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.5.1.tgz",
|
||||
@@ -6181,6 +6498,15 @@
|
||||
"ieee754": "^1.1.13"
|
||||
}
|
||||
},
|
||||
"node_modules/buffer-crc32": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/buffer-crc32/-/buffer-crc32-1.0.0.tgz",
|
||||
"integrity": "sha512-Db1SbgBS/fg/392AblrMJk97KggmvYhr4pB5ZIMTWtaivCPMWLkmb7m21cJvpvgK+J3nsU2CmmixNBZx4vFj/w==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=8.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/buffer-from": {
|
||||
"version": "1.1.2",
|
||||
"resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.2.tgz",
|
||||
@@ -6680,6 +7006,62 @@
|
||||
"url": "https://github.com/sponsors/sindresorhus"
|
||||
}
|
||||
},
|
||||
"node_modules/compress-commons": {
|
||||
"version": "6.0.2",
|
||||
"resolved": "https://registry.npmjs.org/compress-commons/-/compress-commons-6.0.2.tgz",
|
||||
"integrity": "sha512-6FqVXeETqWPoGcfzrXb37E50NP0LXT8kAMu5ooZayhWWdgEY4lBEEcbQNXtkuKQsGduxiIcI4gOTsxTmuq/bSg==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"crc-32": "^1.2.0",
|
||||
"crc32-stream": "^6.0.0",
|
||||
"is-stream": "^2.0.1",
|
||||
"normalize-path": "^3.0.0",
|
||||
"readable-stream": "^4.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 14"
|
||||
}
|
||||
},
|
||||
"node_modules/compress-commons/node_modules/buffer": {
|
||||
"version": "6.0.3",
|
||||
"resolved": "https://registry.npmjs.org/buffer/-/buffer-6.0.3.tgz",
|
||||
"integrity": "sha512-FTiCpNxtwiZZHEZbcbTIcZjERVICn9yq/pDFkTl95/AxzD1naBctN7YO68riM/gLSDY7sdrMby8hofADYuuqOA==",
|
||||
"funding": [
|
||||
{
|
||||
"type": "github",
|
||||
"url": "https://github.com/sponsors/feross"
|
||||
},
|
||||
{
|
||||
"type": "patreon",
|
||||
"url": "https://www.patreon.com/feross"
|
||||
},
|
||||
{
|
||||
"type": "consulting",
|
||||
"url": "https://feross.org/support"
|
||||
}
|
||||
],
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"base64-js": "^1.3.1",
|
||||
"ieee754": "^1.2.1"
|
||||
}
|
||||
},
|
||||
"node_modules/compress-commons/node_modules/readable-stream": {
|
||||
"version": "4.7.0",
|
||||
"resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-4.7.0.tgz",
|
||||
"integrity": "sha512-oIGGmcpTLwPga8Bn6/Z75SVaH1z5dUut2ibSyAMVhmUggWpmDn2dapB0n7f8nwaSiRtepAsfJyfXIO5DCVAODg==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"abort-controller": "^3.0.0",
|
||||
"buffer": "^6.0.3",
|
||||
"events": "^3.3.0",
|
||||
"process": "^0.11.10",
|
||||
"string_decoder": "^1.3.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": "^12.22.0 || ^14.17.0 || >=16.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/concat-map": {
|
||||
"version": "0.0.1",
|
||||
"resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
|
||||
@@ -6765,6 +7147,12 @@
|
||||
"dev": true,
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/core-util-is": {
|
||||
"version": "1.0.3",
|
||||
"resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.3.tgz",
|
||||
"integrity": "sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/cors": {
|
||||
"version": "2.8.6",
|
||||
"resolved": "https://registry.npmjs.org/cors/-/cors-2.8.6.tgz",
|
||||
@@ -6809,6 +7197,71 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/crc-32": {
|
||||
"version": "1.2.2",
|
||||
"resolved": "https://registry.npmjs.org/crc-32/-/crc-32-1.2.2.tgz",
|
||||
"integrity": "sha512-ROmzCKrTnOwybPcJApAA6WBWij23HVfGVNKqqrZpuyZOHqK2CwHSvpGuyt/UNNvaIjEd8X5IFGp4Mh+Ie1IHJQ==",
|
||||
"license": "Apache-2.0",
|
||||
"bin": {
|
||||
"crc32": "bin/crc32.njs"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=0.8"
|
||||
}
|
||||
},
|
||||
"node_modules/crc32-stream": {
|
||||
"version": "6.0.0",
|
||||
"resolved": "https://registry.npmjs.org/crc32-stream/-/crc32-stream-6.0.0.tgz",
|
||||
"integrity": "sha512-piICUB6ei4IlTv1+653yq5+KoqfBYmj9bw6LqXoOneTMDXk5nM1qt12mFW1caG3LlJXEKW1Bp0WggEmIfQB34g==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"crc-32": "^1.2.0",
|
||||
"readable-stream": "^4.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 14"
|
||||
}
|
||||
},
|
||||
"node_modules/crc32-stream/node_modules/buffer": {
|
||||
"version": "6.0.3",
|
||||
"resolved": "https://registry.npmjs.org/buffer/-/buffer-6.0.3.tgz",
|
||||
"integrity": "sha512-FTiCpNxtwiZZHEZbcbTIcZjERVICn9yq/pDFkTl95/AxzD1naBctN7YO68riM/gLSDY7sdrMby8hofADYuuqOA==",
|
||||
"funding": [
|
||||
{
|
||||
"type": "github",
|
||||
"url": "https://github.com/sponsors/feross"
|
||||
},
|
||||
{
|
||||
"type": "patreon",
|
||||
"url": "https://www.patreon.com/feross"
|
||||
},
|
||||
{
|
||||
"type": "consulting",
|
||||
"url": "https://feross.org/support"
|
||||
}
|
||||
],
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"base64-js": "^1.3.1",
|
||||
"ieee754": "^1.2.1"
|
||||
}
|
||||
},
|
||||
"node_modules/crc32-stream/node_modules/readable-stream": {
|
||||
"version": "4.7.0",
|
||||
"resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-4.7.0.tgz",
|
||||
"integrity": "sha512-oIGGmcpTLwPga8Bn6/Z75SVaH1z5dUut2ibSyAMVhmUggWpmDn2dapB0n7f8nwaSiRtepAsfJyfXIO5DCVAODg==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"abort-controller": "^3.0.0",
|
||||
"buffer": "^6.0.3",
|
||||
"events": "^3.3.0",
|
||||
"process": "^0.11.10",
|
||||
"string_decoder": "^1.3.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": "^12.22.0 || ^14.17.0 || >=16.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/cron": {
|
||||
"version": "4.4.0",
|
||||
"resolved": "https://registry.npmjs.org/cron/-/cron-4.4.0.tgz",
|
||||
@@ -7951,16 +8404,33 @@
|
||||
"node": ">= 0.6"
|
||||
}
|
||||
},
|
||||
"node_modules/event-target-shim": {
|
||||
"version": "5.0.1",
|
||||
"resolved": "https://registry.npmjs.org/event-target-shim/-/event-target-shim-5.0.1.tgz",
|
||||
"integrity": "sha512-i/2XbnSz/uxRCU6+NdVJgKWDTM427+MqYbkQzD321DuCQJUqOuJKIA0IM2+W2xtYHdKOmZ4dR6fExsd4SXL+WQ==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=6"
|
||||
}
|
||||
},
|
||||
"node_modules/events": {
|
||||
"version": "3.3.0",
|
||||
"resolved": "https://registry.npmjs.org/events/-/events-3.3.0.tgz",
|
||||
"integrity": "sha512-mQw+2fkQbALzQ7V0MY0IqdnXNOeTtP4r0lN9z7AAawCXgqea7bDii20AYrIBrFd/Hx0M2Ocz6S111CaFkUcb0Q==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=0.8.x"
|
||||
}
|
||||
},
|
||||
"node_modules/events-universal": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/events-universal/-/events-universal-1.0.1.tgz",
|
||||
"integrity": "sha512-LUd5euvbMLpwOF8m6ivPCbhQeSiYVNb8Vs0fQ8QjXo0JTkEHpz8pxdQf0gStltaPpw0Cca8b39KxvK9cfKRiAw==",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"bare-events": "^2.7.0"
|
||||
}
|
||||
},
|
||||
"node_modules/eventsource": {
|
||||
"version": "3.0.7",
|
||||
"resolved": "https://registry.npmjs.org/eventsource/-/eventsource-3.0.7.tgz",
|
||||
@@ -8178,6 +8648,12 @@
|
||||
"dev": true,
|
||||
"license": "Apache-2.0"
|
||||
},
|
||||
"node_modules/fast-fifo": {
|
||||
"version": "1.3.2",
|
||||
"resolved": "https://registry.npmjs.org/fast-fifo/-/fast-fifo-1.3.2.tgz",
|
||||
"integrity": "sha512-/d9sfos4yxzpwkDkuN7k2SqFKtYNmCTzgfEpz82x34IM9/zc8KGxQoXg1liNC/izpRM/MBdt44Nmx41ZWqk+FQ==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/fast-json-stable-stringify": {
|
||||
"version": "2.1.0",
|
||||
"resolved": "https://registry.npmjs.org/fast-json-stable-stringify/-/fast-json-stable-stringify-2.1.0.tgz",
|
||||
@@ -8721,7 +9197,6 @@
|
||||
"version": "4.2.11",
|
||||
"resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.11.tgz",
|
||||
"integrity": "sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ==",
|
||||
"dev": true,
|
||||
"license": "ISC"
|
||||
},
|
||||
"node_modules/handlebars": {
|
||||
@@ -9336,7 +9811,6 @@
|
||||
"version": "2.0.1",
|
||||
"resolved": "https://registry.npmjs.org/is-stream/-/is-stream-2.0.1.tgz",
|
||||
"integrity": "sha512-hFoiJiTl63nn+kstHGBtewWSKnQLpyb155KHheA1l39uvtO9nWIop1p3udqPcUd/xbF1VLMO4n7OI6p7RbngDg==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=8"
|
||||
@@ -10523,6 +10997,54 @@
|
||||
"json-buffer": "3.0.1"
|
||||
}
|
||||
},
|
||||
"node_modules/lazystream": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/lazystream/-/lazystream-1.0.1.tgz",
|
||||
"integrity": "sha512-b94GiNHQNy6JNTrt5w6zNyffMrNkXZb3KTkCZJb2V1xaEGCk093vkZ2jk3tpaeP33/OiXC+WvK9AxUebnf5nbw==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"readable-stream": "^2.0.5"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.6.3"
|
||||
}
|
||||
},
|
||||
"node_modules/lazystream/node_modules/isarray": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz",
|
||||
"integrity": "sha512-VLghIWNM6ELQzo7zwmcg0NmTVyWKYjvIeM83yjp0wRDTmUnrM678fQbcKBo6n2CJEF0szoG//ytg+TKla89ALQ==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/lazystream/node_modules/readable-stream": {
|
||||
"version": "2.3.8",
|
||||
"resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.8.tgz",
|
||||
"integrity": "sha512-8p0AUk4XODgIewSi0l8Epjs+EVnWiK7NoDIEGU0HhE7+ZyY8D1IMY7odu5lRrFXGg71L15KG8QrPmum45RTtdA==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"core-util-is": "~1.0.0",
|
||||
"inherits": "~2.0.3",
|
||||
"isarray": "~1.0.0",
|
||||
"process-nextick-args": "~2.0.0",
|
||||
"safe-buffer": "~5.1.1",
|
||||
"string_decoder": "~1.1.1",
|
||||
"util-deprecate": "~1.0.1"
|
||||
}
|
||||
},
|
||||
"node_modules/lazystream/node_modules/safe-buffer": {
|
||||
"version": "5.1.2",
|
||||
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz",
|
||||
"integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/lazystream/node_modules/string_decoder": {
|
||||
"version": "1.1.1",
|
||||
"resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz",
|
||||
"integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"safe-buffer": "~5.1.0"
|
||||
}
|
||||
},
|
||||
"node_modules/leven": {
|
||||
"version": "3.1.0",
|
||||
"resolved": "https://registry.npmjs.org/leven/-/leven-3.1.0.tgz",
|
||||
@@ -12011,7 +12533,6 @@
|
||||
"version": "3.0.0",
|
||||
"resolved": "https://registry.npmjs.org/normalize-path/-/normalize-path-3.0.0.tgz",
|
||||
"integrity": "sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=0.10.0"
|
||||
@@ -12637,6 +13158,21 @@
|
||||
"url": "https://github.com/chalk/ansi-styles?sponsor=1"
|
||||
}
|
||||
},
|
||||
"node_modules/process": {
|
||||
"version": "0.11.10",
|
||||
"resolved": "https://registry.npmjs.org/process/-/process-0.11.10.tgz",
|
||||
"integrity": "sha512-cdGef/drWFoydD1JsMzuFf8100nZl+GT+yacc2bEced5f9Rjk4z+WtFUTBu9PhOi9j/jfmBPu0mMEY4wIdAF8A==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 0.6.0"
|
||||
}
|
||||
},
|
||||
"node_modules/process-nextick-args": {
|
||||
"version": "2.0.1",
|
||||
"resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.1.tgz",
|
||||
"integrity": "sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/property-information": {
|
||||
"version": "7.1.0",
|
||||
"resolved": "https://registry.npmjs.org/property-information/-/property-information-7.1.0.tgz",
|
||||
@@ -12939,6 +13475,36 @@
|
||||
"node": ">= 6"
|
||||
}
|
||||
},
|
||||
"node_modules/readdir-glob": {
|
||||
"version": "1.1.3",
|
||||
"resolved": "https://registry.npmjs.org/readdir-glob/-/readdir-glob-1.1.3.tgz",
|
||||
"integrity": "sha512-v05I2k7xN8zXvPD9N+z/uhXPaj0sUFCe2rcWZIpBsqxfP7xXFQ0tipAd/wjj1YxWyWtUS5IDJpOG82JKt2EAVA==",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"minimatch": "^5.1.0"
|
||||
}
|
||||
},
|
||||
"node_modules/readdir-glob/node_modules/brace-expansion": {
|
||||
"version": "2.1.7",
|
||||
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.1.7.tgz",
|
||||
"integrity": "sha512-uZbew1NqdmPDTMJ8ah1y+b+9QEJrfkXFk3RcTQw3X0jW/xRUvFKsg1CfQdSYGdTbXZWExtU3J3ccxtnfw1Fi0g==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"balanced-match": "^1.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/readdir-glob/node_modules/minimatch": {
|
||||
"version": "5.1.9",
|
||||
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-5.1.9.tgz",
|
||||
"integrity": "sha512-7o1wEA2RyMP7Iu7GNba9vc0RWWGACJOCZBJX2GJWip0ikV+wcOsgVuY9uE8CPiyQhkGFSlhuSkZPavN7u1c2Fw==",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"brace-expansion": "^2.0.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=10"
|
||||
}
|
||||
},
|
||||
"node_modules/readdirp": {
|
||||
"version": "4.1.2",
|
||||
"resolved": "https://registry.npmjs.org/readdirp/-/readdirp-4.1.2.tgz",
|
||||
@@ -13813,6 +14379,17 @@
|
||||
"node": ">=10.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/streamx": {
|
||||
"version": "2.28.1",
|
||||
"resolved": "https://registry.npmjs.org/streamx/-/streamx-2.28.1.tgz",
|
||||
"integrity": "sha512-zEzXb0s5Cds7tqMH6rhZ05lcJydCWiQPEwiNngVqzsxCc962vLY4Uw+mW7od8kDH258k2Uz/JrOkdIAAhSh9VA==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"events-universal": "^1.0.0",
|
||||
"fast-fifo": "^1.3.2",
|
||||
"text-decoder": "^1.1.0"
|
||||
}
|
||||
},
|
||||
"node_modules/string_decoder": {
|
||||
"version": "1.3.0",
|
||||
"resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.3.0.tgz",
|
||||
@@ -14140,6 +14717,15 @@
|
||||
"node": ">=6"
|
||||
}
|
||||
},
|
||||
"node_modules/teex": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/teex/-/teex-1.0.1.tgz",
|
||||
"integrity": "sha512-eYE6iEI62Ni1H8oIa7KlDU6uQBtqr4Eajni3wX7rpfXD8ysFx8z0+dri+KWEPWpBsxXfxu58x/0jvTVT1ekOSg==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"streamx": "^2.12.5"
|
||||
}
|
||||
},
|
||||
"node_modules/terser": {
|
||||
"version": "5.46.1",
|
||||
"resolved": "https://registry.npmjs.org/terser/-/terser-5.46.1.tgz",
|
||||
@@ -14275,6 +14861,15 @@
|
||||
"url": "https://github.com/sponsors/isaacs"
|
||||
}
|
||||
},
|
||||
"node_modules/text-decoder": {
|
||||
"version": "1.2.7",
|
||||
"resolved": "https://registry.npmjs.org/text-decoder/-/text-decoder-1.2.7.tgz",
|
||||
"integrity": "sha512-vlLytXkeP4xvEq2otHeJfSQIRyWxo/oZGEbXrtEEF9Hnmrdly59sUbzZ/QgyWuLYHctCHxFF4tRQZNQ9k60ExQ==",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"b4a": "^1.6.4"
|
||||
}
|
||||
},
|
||||
"node_modules/tiny-invariant": {
|
||||
"version": "1.3.3",
|
||||
"resolved": "https://registry.npmjs.org/tiny-invariant/-/tiny-invariant-1.3.3.tgz",
|
||||
@@ -15974,6 +16569,60 @@
|
||||
"url": "https://github.com/sponsors/sindresorhus"
|
||||
}
|
||||
},
|
||||
"node_modules/zip-stream": {
|
||||
"version": "6.0.1",
|
||||
"resolved": "https://registry.npmjs.org/zip-stream/-/zip-stream-6.0.1.tgz",
|
||||
"integrity": "sha512-zK7YHHz4ZXpW89AHXUPbQVGKI7uvkd3hzusTdotCg1UxyaVtg0zFJSTfW/Dq5f7OBBVnq6cZIaC8Ti4hb6dtCA==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"archiver-utils": "^5.0.0",
|
||||
"compress-commons": "^6.0.2",
|
||||
"readable-stream": "^4.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 14"
|
||||
}
|
||||
},
|
||||
"node_modules/zip-stream/node_modules/buffer": {
|
||||
"version": "6.0.3",
|
||||
"resolved": "https://registry.npmjs.org/buffer/-/buffer-6.0.3.tgz",
|
||||
"integrity": "sha512-FTiCpNxtwiZZHEZbcbTIcZjERVICn9yq/pDFkTl95/AxzD1naBctN7YO68riM/gLSDY7sdrMby8hofADYuuqOA==",
|
||||
"funding": [
|
||||
{
|
||||
"type": "github",
|
||||
"url": "https://github.com/sponsors/feross"
|
||||
},
|
||||
{
|
||||
"type": "patreon",
|
||||
"url": "https://www.patreon.com/feross"
|
||||
},
|
||||
{
|
||||
"type": "consulting",
|
||||
"url": "https://feross.org/support"
|
||||
}
|
||||
],
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"base64-js": "^1.3.1",
|
||||
"ieee754": "^1.2.1"
|
||||
}
|
||||
},
|
||||
"node_modules/zip-stream/node_modules/readable-stream": {
|
||||
"version": "4.7.0",
|
||||
"resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-4.7.0.tgz",
|
||||
"integrity": "sha512-oIGGmcpTLwPga8Bn6/Z75SVaH1z5dUut2ibSyAMVhmUggWpmDn2dapB0n7f8nwaSiRtepAsfJyfXIO5DCVAODg==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"abort-controller": "^3.0.0",
|
||||
"buffer": "^6.0.3",
|
||||
"events": "^3.3.0",
|
||||
"process": "^0.11.10",
|
||||
"string_decoder": "^1.3.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": "^12.22.0 || ^14.17.0 || >=16.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/zod": {
|
||||
"version": "4.3.6",
|
||||
"resolved": "https://registry.npmjs.org/zod/-/zod-4.3.6.tgz",
|
||||
@@ -16031,6 +16680,7 @@
|
||||
"@nestjs/typeorm": "^11.0.1",
|
||||
"@playwright/test": "^1.59.1",
|
||||
"acorn": "^8.16.0",
|
||||
"archiver": "^7.0.1",
|
||||
"better-sqlite3": "^12.8.0",
|
||||
"class-transformer": "^0.5.1",
|
||||
"class-validator": "^0.14.4",
|
||||
@@ -16048,6 +16698,7 @@
|
||||
"@nestjs/cli": "^11.0.17",
|
||||
"@nestjs/testing": "^11.1.18",
|
||||
"@types/acorn": "^4.0.6",
|
||||
"@types/archiver": "^6.0.4",
|
||||
"@types/better-sqlite3": "^7.6.13",
|
||||
"@types/debug": "^4.1.13",
|
||||
"@types/express": "^5.0.6",
|
||||
@@ -16067,6 +16718,16 @@
|
||||
"typescript-eslint": "^8.58.1"
|
||||
}
|
||||
},
|
||||
"server/node_modules/@types/archiver": {
|
||||
"version": "6.0.4",
|
||||
"resolved": "https://registry.npmjs.org/@types/archiver/-/archiver-6.0.4.tgz",
|
||||
"integrity": "sha512-ULdQpARQ3sz9WH4nb98mJDYA0ft2A8C4f4fovvUcFwINa1cgGjY36JCAYuP5YypRq4mco1lJp1/7jEMS2oR0Hg==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@types/readdir-glob": "*"
|
||||
}
|
||||
},
|
||||
"server/node_modules/ajv": {
|
||||
"version": "6.14.0",
|
||||
"resolved": "https://registry.npmjs.org/ajv/-/ajv-6.14.0.tgz",
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "liqa",
|
||||
"version": "1.7.1",
|
||||
"version": "1.16.0",
|
||||
"private": true,
|
||||
"workspaces": [
|
||||
"server",
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
"@nestjs/typeorm": "^11.0.1",
|
||||
"@playwright/test": "^1.59.1",
|
||||
"acorn": "^8.16.0",
|
||||
"archiver": "^7.0.1",
|
||||
"better-sqlite3": "^12.8.0",
|
||||
"class-transformer": "^0.5.1",
|
||||
"class-validator": "^0.14.4",
|
||||
@@ -46,6 +47,7 @@
|
||||
"@nestjs/cli": "^11.0.17",
|
||||
"@nestjs/testing": "^11.1.18",
|
||||
"@types/acorn": "^4.0.6",
|
||||
"@types/archiver": "^6.0.4",
|
||||
"@types/better-sqlite3": "^7.6.13",
|
||||
"@types/debug": "^4.1.13",
|
||||
"@types/express": "^5.0.6",
|
||||
|
||||
@@ -19,6 +19,8 @@ import { ScenarioRunLogEntity } from "./scenario/scenario-run-log.entity";
|
||||
import { ScenarioRunStepEntity } from "./scenario/scenario-run-step.entity";
|
||||
import { ScenarioRunEntity } from "./scenario/scenario-run.entity";
|
||||
import { ScenarioStepEntity } from "./scenario/scenario-step.entity";
|
||||
import { ScenarioVersionEntity } from "./scenario/scenario-version.entity";
|
||||
import { SnippetVersionEntity } from "./snippet/snippet-version.entity";
|
||||
import { ScenarioEntity } from "./scenario/scenario.entity";
|
||||
import { ScenarioModule } from "./scenario/scenario.module";
|
||||
import { SessionEntity } from "./session/session.entity";
|
||||
@@ -44,11 +46,13 @@ import { SnippetModule } from "./snippet/snippet.module";
|
||||
CredentialEntity,
|
||||
ScenarioEntity,
|
||||
ScenarioStepEntity,
|
||||
ScenarioVersionEntity,
|
||||
ScenarioRunEntity,
|
||||
ScenarioRunStepEntity,
|
||||
ScenarioRunLogEntity,
|
||||
ScenarioCredentialEntity,
|
||||
SnippetEntity,
|
||||
SnippetVersionEntity,
|
||||
FileEntity,
|
||||
ScenarioFileEntity,
|
||||
ScenarioRunFileEntity,
|
||||
|
||||
@@ -42,6 +42,15 @@ export interface ScriptContext {
|
||||
log: (...args: unknown[]) => void;
|
||||
warn: (...args: unknown[]) => void;
|
||||
error: (...args: unknown[]) => void;
|
||||
/**
|
||||
* Runs `fn` and requires it to return `true`. Logs the outcome under
|
||||
* `description`, then throws if `fn` returned anything other than `true`
|
||||
* or threw an exception.
|
||||
*/
|
||||
assert: (
|
||||
fn: () => boolean | Promise<boolean>,
|
||||
description: string,
|
||||
) => Promise<void>;
|
||||
/** Runs a named snippet with the same context, plus any extra positional args. */
|
||||
runSnippet: (alias: string, ...args: unknown[]) => Promise<unknown>;
|
||||
/** Returns metadata + absolute disk path for files attached to the current scenario. */
|
||||
@@ -141,6 +150,28 @@ export class CodeExecutorService {
|
||||
log: (...args: unknown[]) => scriptLog("log", toStr(args)),
|
||||
warn: (...args: unknown[]) => scriptLog("warn", toStr(args)),
|
||||
error: (...args: unknown[]) => scriptLog("error", toStr(args)),
|
||||
assert: async (
|
||||
fn: () => boolean | Promise<boolean>,
|
||||
description: string,
|
||||
): Promise<void> => {
|
||||
let passed: boolean;
|
||||
let failureReason: string | undefined;
|
||||
try {
|
||||
passed = (await fn()) === true;
|
||||
} catch (err) {
|
||||
passed = false;
|
||||
failureReason = (err as Error).message;
|
||||
}
|
||||
if (passed) {
|
||||
scriptLog("log", `Assertion passed: ${description}`);
|
||||
return;
|
||||
}
|
||||
const message = failureReason
|
||||
? `Assertion failed: ${description} (${failureReason})`
|
||||
: `Assertion failed: ${description}`;
|
||||
scriptLog("error", message);
|
||||
throw new Error(message);
|
||||
},
|
||||
getStepOutput: getStepOutput ?? (() => Promise.resolve(null)),
|
||||
getCredential: (alias: string): unknown => {
|
||||
if (!(alias in credMap)) {
|
||||
@@ -168,6 +199,7 @@ export class CodeExecutorService {
|
||||
if (snippetCode == null) {
|
||||
throw new Error(`Snippet alias "${alias}" not found`);
|
||||
}
|
||||
scriptLog("log", `Snippet "${alias}" started`);
|
||||
const snippetFn = new Function(
|
||||
"context",
|
||||
"console",
|
||||
@@ -175,7 +207,22 @@ export class CodeExecutorService {
|
||||
"expect",
|
||||
`return (async (context, ...args) => { ${snippetCode} })(context, ...snippetArgs)`,
|
||||
);
|
||||
return snippetFn(scriptContext, fakeConsole, args, playwrightExpect);
|
||||
try {
|
||||
const snippetResult = await snippetFn(
|
||||
scriptContext,
|
||||
fakeConsole,
|
||||
args,
|
||||
playwrightExpect,
|
||||
);
|
||||
scriptLog("log", `Snippet "${alias}" finished`);
|
||||
return snippetResult;
|
||||
} catch (err) {
|
||||
scriptLog(
|
||||
"error",
|
||||
`Snippet "${alias}" failed: ${(err as Error).message}`,
|
||||
);
|
||||
throw err;
|
||||
}
|
||||
},
|
||||
getScenarioFiles: async (opts?: { limit?: number; offset?: number }) => {
|
||||
if (!fileService || !scenarioId) {
|
||||
|
||||
@@ -5,6 +5,18 @@ import { URL } from "url";
|
||||
const MAX_FILE_SIZE = 100 * 1024 * 1024; // 100 MB
|
||||
const TIMEOUT_MS = 30000; // 30 seconds
|
||||
|
||||
function decodeDataUrl(urlStr: string): Buffer {
|
||||
const match = /^data:([^,]*),(.*)$/s.exec(urlStr);
|
||||
if (!match) {
|
||||
throw new Error("Malformed data: URL");
|
||||
}
|
||||
const [, meta, data] = match;
|
||||
if (meta.endsWith(";base64")) {
|
||||
return Buffer.from(data, "base64");
|
||||
}
|
||||
return Buffer.from(decodeURIComponent(data), "utf-8");
|
||||
}
|
||||
|
||||
export async function downloadFile(
|
||||
urlStr: string,
|
||||
options?: {
|
||||
@@ -13,6 +25,10 @@ export async function downloadFile(
|
||||
body?: string;
|
||||
},
|
||||
): Promise<Buffer> {
|
||||
if (urlStr.startsWith("data:")) {
|
||||
return decodeDataUrl(urlStr);
|
||||
}
|
||||
|
||||
const url = new URL(urlStr);
|
||||
const protocol = url.protocol === "https:" ? https : http;
|
||||
const method = options?.method ?? "GET";
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
/** Extracts the alias literals passed to `runSnippet("alias", ...)` calls in `code`. */
|
||||
export function extractRunSnippetAliases(code: string): string[] {
|
||||
const aliases: string[] = [];
|
||||
const regex = /runSnippet\s*\(\s*(['"`])((?:(?!\1).)*)\1/g;
|
||||
let match: RegExpExecArray | null;
|
||||
while ((match = regex.exec(code)) !== null) {
|
||||
aliases.push(match[2]);
|
||||
}
|
||||
return aliases;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolves the transitive closure of snippet aliases referenced (directly, or via
|
||||
* other snippets) by `stepCodes`, against the full alias -> code map. Aliases with
|
||||
* no matching entry in `snippetCodeByAlias` are dropped. Returned in discovery order.
|
||||
*/
|
||||
export function resolveUsedSnippetAliases(
|
||||
stepCodes: string[],
|
||||
snippetCodeByAlias: Record<string, string>,
|
||||
): string[] {
|
||||
const used: string[] = [];
|
||||
const seen = new Set<string>();
|
||||
const queue = stepCodes.flatMap((code) => extractRunSnippetAliases(code));
|
||||
while (queue.length > 0) {
|
||||
const alias = queue.shift()!;
|
||||
if (seen.has(alias)) continue;
|
||||
seen.add(alias);
|
||||
const code = snippetCodeByAlias[alias];
|
||||
if (code == null) continue;
|
||||
used.push(alias);
|
||||
queue.push(...extractRunSnippetAliases(code));
|
||||
}
|
||||
return used;
|
||||
}
|
||||
|
||||
/**
|
||||
* Splits a `runSnippet` reference into its alias and pinned version:
|
||||
* `"login@3"` → `{ alias: "login", version: 3 }`, `"login"` → `{ alias: "login", version: null }`.
|
||||
*/
|
||||
export function parseSnippetRef(ref: string): {
|
||||
alias: string;
|
||||
version: number | null;
|
||||
} {
|
||||
const match = /^(.+)@(\d+)$/.exec(ref);
|
||||
return match
|
||||
? { alias: match[1], version: Number(match[2]) }
|
||||
: { alias: ref, version: null };
|
||||
}
|
||||
@@ -1,8 +1,21 @@
|
||||
import { plainToInstance } from "class-transformer";
|
||||
import { IsInt, IsString, Max, Min, validateSync } from "class-validator";
|
||||
import {
|
||||
IsEnum,
|
||||
IsInt,
|
||||
IsString,
|
||||
Max,
|
||||
Min,
|
||||
validateSync,
|
||||
} from "class-validator";
|
||||
|
||||
import pkg from "../../package.json";
|
||||
|
||||
export enum TraceMode {
|
||||
On = "on",
|
||||
RetainOnFailure = "retain-on-failure",
|
||||
Off = "off",
|
||||
}
|
||||
|
||||
export class AppConfig {
|
||||
@IsString()
|
||||
NODE_ENV: string = "development";
|
||||
@@ -41,6 +54,9 @@ export class AppConfig {
|
||||
|
||||
@IsString()
|
||||
FILE_CLEANUP_CRON: string = "0 3 * * *";
|
||||
|
||||
@IsEnum(TraceMode)
|
||||
PLAYWRIGHT_TRACE_MODE: TraceMode = TraceMode.On;
|
||||
}
|
||||
|
||||
export function validateAppConfig(config: Record<string, unknown>): AppConfig {
|
||||
|
||||
@@ -7,10 +7,12 @@ import { SessionService } from "../session/session.service";
|
||||
import { SessionContextService } from "../session/session-context.service";
|
||||
import { EnvironmentService } from "../environment/environment.service";
|
||||
import type { EnvironmentData } from "../environment/environment.entity";
|
||||
import { TraceMode } from "../config/app.config";
|
||||
import { CredentialService } from "../credential/credential.service";
|
||||
import { BrowserService } from "../browser/browser.service";
|
||||
import { CodeExecutorService } from "../code-executor/code-executor.service";
|
||||
import { ScenarioService } from "../scenario/scenario.service";
|
||||
import { E2eExportService } from "../scenario/e2e-export.service";
|
||||
import { SnippetService } from "../snippet/snippet.service";
|
||||
|
||||
import pkg from "../../package.json";
|
||||
@@ -25,6 +27,7 @@ export class McpService {
|
||||
private readonly browserService: BrowserService,
|
||||
private readonly codeExecutor: CodeExecutorService,
|
||||
private readonly scenarioService: ScenarioService,
|
||||
private readonly e2eExportService: E2eExportService,
|
||||
private readonly snippetService: SnippetService,
|
||||
) {}
|
||||
|
||||
@@ -273,6 +276,166 @@ export class McpService {
|
||||
},
|
||||
);
|
||||
|
||||
// ── Credentials ───────────────────────────────────────────────────────────
|
||||
|
||||
server.registerTool(
|
||||
"list_credentials",
|
||||
{
|
||||
description: "List all credentials (paginated)",
|
||||
inputSchema: {
|
||||
page: z
|
||||
.number()
|
||||
.int()
|
||||
.min(1)
|
||||
.optional()
|
||||
.describe("Page number (default 1)"),
|
||||
limit: z
|
||||
.number()
|
||||
.int()
|
||||
.min(1)
|
||||
.optional()
|
||||
.describe("Items per page (default 20)"),
|
||||
orderBy: z
|
||||
.enum(["id", "name", "lastUsedAt", "createdAt", "updatedAt"])
|
||||
.optional()
|
||||
.describe("Field to order by (default id)"),
|
||||
orderDir: z
|
||||
.enum(["ASC", "DESC"])
|
||||
.optional()
|
||||
.describe("Sort direction (default ASC)"),
|
||||
},
|
||||
},
|
||||
async ({ page, limit, orderBy, orderDir }) => {
|
||||
const result = await this.credentialService.findAll({
|
||||
page,
|
||||
limit,
|
||||
orderBy,
|
||||
orderDir,
|
||||
});
|
||||
return {
|
||||
content: [{ type: "text" as const, text: JSON.stringify(result) }],
|
||||
};
|
||||
},
|
||||
);
|
||||
|
||||
server.registerTool(
|
||||
"get_credential",
|
||||
{
|
||||
description: "Get a credential by ID",
|
||||
inputSchema: {
|
||||
id: z.uuid().describe("Credential ID"),
|
||||
},
|
||||
},
|
||||
async ({ id }) => {
|
||||
try {
|
||||
const credential = await this.credentialService.findOne(id);
|
||||
return {
|
||||
content: [
|
||||
{ type: "text" as const, text: JSON.stringify(credential) },
|
||||
],
|
||||
};
|
||||
} catch (err) {
|
||||
return {
|
||||
isError: true,
|
||||
content: [{ type: "text" as const, text: (err as Error).message }],
|
||||
};
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
server.registerTool(
|
||||
"create_credential",
|
||||
{
|
||||
description:
|
||||
"Create a new credential. Assign it to a scenario with add_scenario_credential to use it via context.getCredential(alias).",
|
||||
inputSchema: {
|
||||
name: z.string().min(1).describe("Human-readable credential name"),
|
||||
data: z
|
||||
.string()
|
||||
.optional()
|
||||
.describe(
|
||||
'JSON-encoded credential payload, e.g. {"token":"abc123"}',
|
||||
),
|
||||
},
|
||||
},
|
||||
async ({ name, data }) => {
|
||||
try {
|
||||
const credential = await this.credentialService.create({
|
||||
name,
|
||||
data,
|
||||
});
|
||||
return {
|
||||
content: [
|
||||
{ type: "text" as const, text: JSON.stringify(credential) },
|
||||
],
|
||||
};
|
||||
} catch (err) {
|
||||
return {
|
||||
isError: true,
|
||||
content: [{ type: "text" as const, text: (err as Error).message }],
|
||||
};
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
server.registerTool(
|
||||
"update_credential",
|
||||
{
|
||||
description: "Update an existing credential (name and/or data)",
|
||||
inputSchema: {
|
||||
id: z.uuid().describe("Credential ID to update"),
|
||||
name: z.string().min(1).optional().describe("New name"),
|
||||
data: z
|
||||
.string()
|
||||
.optional()
|
||||
.describe("New JSON-encoded credential payload"),
|
||||
},
|
||||
},
|
||||
async ({ id, name, data }) => {
|
||||
try {
|
||||
const credential = await this.credentialService.update(id, {
|
||||
...(name !== undefined && { name }),
|
||||
...(data !== undefined && { data }),
|
||||
});
|
||||
return {
|
||||
content: [
|
||||
{ type: "text" as const, text: JSON.stringify(credential) },
|
||||
],
|
||||
};
|
||||
} catch (err) {
|
||||
return {
|
||||
isError: true,
|
||||
content: [{ type: "text" as const, text: (err as Error).message }],
|
||||
};
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
server.registerTool(
|
||||
"delete_credential",
|
||||
{
|
||||
description: "Delete a credential by ID",
|
||||
inputSchema: {
|
||||
id: z.uuid().describe("Credential ID to delete"),
|
||||
},
|
||||
},
|
||||
async ({ id }) => {
|
||||
try {
|
||||
await this.credentialService.remove(id);
|
||||
return {
|
||||
content: [
|
||||
{ type: "text" as const, text: `Credential ${id} deleted` },
|
||||
],
|
||||
};
|
||||
} catch (err) {
|
||||
return {
|
||||
isError: true,
|
||||
content: [{ type: "text" as const, text: (err as Error).message }],
|
||||
};
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
// ── Browser ───────────────────────────────────────────────────────────────
|
||||
|
||||
server.registerTool(
|
||||
@@ -777,14 +940,30 @@ export class McpService {
|
||||
.boolean()
|
||||
.optional()
|
||||
.describe("Save session after run completes"),
|
||||
traceMode: z
|
||||
.enum(TraceMode)
|
||||
.optional()
|
||||
.describe(
|
||||
"Playwright trace recording: on (keep every trace), retain-on-failure, or off. Defaults to the server's PLAYWRIGHT_TRACE_MODE",
|
||||
),
|
||||
version: z
|
||||
.number()
|
||||
.int()
|
||||
.min(1)
|
||||
.optional()
|
||||
.describe(
|
||||
"Scenario version to run (see list_scenario_versions). Defaults to the latest",
|
||||
),
|
||||
},
|
||||
},
|
||||
async ({ id, environmentId, saveSession }) => {
|
||||
async ({ id, environmentId, saveSession, traceMode, version }) => {
|
||||
try {
|
||||
const run = await this.scenarioService.createRun(
|
||||
id,
|
||||
environmentId,
|
||||
saveSession,
|
||||
traceMode,
|
||||
version,
|
||||
);
|
||||
return {
|
||||
content: [{ type: "text" as const, text: JSON.stringify(run) }],
|
||||
@@ -985,19 +1164,74 @@ export class McpService {
|
||||
);
|
||||
|
||||
server.registerTool(
|
||||
"export_scenario",
|
||||
"list_scenario_versions",
|
||||
{
|
||||
description:
|
||||
"Export a scenario as a portable JSON payload (name + steps)",
|
||||
"List a scenario's versions, newest first. Each version holds the scenario content and steps as of that version",
|
||||
inputSchema: {
|
||||
id: z.uuid().describe("Scenario ID to export"),
|
||||
id: z.uuid().describe("Scenario ID"),
|
||||
},
|
||||
},
|
||||
async ({ id }) => {
|
||||
try {
|
||||
const versions = await this.scenarioService.listVersions(id);
|
||||
return {
|
||||
content: [{ type: "text" as const, text: JSON.stringify(versions) }],
|
||||
};
|
||||
} catch (err) {
|
||||
return {
|
||||
isError: true,
|
||||
content: [{ type: "text" as const, text: (err as Error).message }],
|
||||
};
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
server.registerTool(
|
||||
"get_scenario_version",
|
||||
{
|
||||
description: "Get one version of a scenario, with its steps",
|
||||
inputSchema: {
|
||||
id: z.uuid().describe("Scenario ID"),
|
||||
version: z.number().int().min(1).describe("Scenario version"),
|
||||
},
|
||||
},
|
||||
async ({ id, version }) => {
|
||||
try {
|
||||
const row = await this.scenarioService.findVersion(id, version);
|
||||
return {
|
||||
content: [{ type: "text" as const, text: JSON.stringify(row) }],
|
||||
};
|
||||
} catch (err) {
|
||||
return {
|
||||
isError: true,
|
||||
content: [{ type: "text" as const, text: (err as Error).message }],
|
||||
};
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
server.registerTool(
|
||||
"export_scenario",
|
||||
{
|
||||
description:
|
||||
"Export one version of a scenario as a portable JSON payload (version, name + steps)",
|
||||
inputSchema: {
|
||||
id: z.uuid().describe("Scenario ID to export"),
|
||||
version: z
|
||||
.number()
|
||||
.int()
|
||||
.min(1)
|
||||
.optional()
|
||||
.describe("Scenario version to export. Defaults to the latest"),
|
||||
},
|
||||
},
|
||||
async ({ id, version }) => {
|
||||
try {
|
||||
const exported = await this.scenarioService.exportScenario(id, {
|
||||
includeEnvironment: false,
|
||||
credentialIds: [],
|
||||
version,
|
||||
});
|
||||
return {
|
||||
content: [
|
||||
@@ -1017,8 +1251,17 @@ export class McpService {
|
||||
"import_scenario",
|
||||
{
|
||||
description:
|
||||
"Import a scenario from an export payload, creating a new scenario with all its steps",
|
||||
"Import one scenario version from an export payload. Upserts by id + version: an existing version is left untouched; a new one is stored under its number and becomes the latest when higher than the current latest. Without an id a new scenario is created",
|
||||
inputSchema: {
|
||||
id: z
|
||||
.uuid()
|
||||
.optional()
|
||||
.describe("Scenario ID to import into (from the export)"),
|
||||
version: z
|
||||
.number()
|
||||
.int()
|
||||
.min(1)
|
||||
.describe("Scenario version the payload holds (from the export)"),
|
||||
name: z.string().describe("Scenario name"),
|
||||
description: z
|
||||
.string()
|
||||
@@ -1040,10 +1283,12 @@ export class McpService {
|
||||
.describe("Ordered list of steps"),
|
||||
},
|
||||
},
|
||||
async ({ name, description, steps }) => {
|
||||
async ({ id, version, name, description, steps }) => {
|
||||
try {
|
||||
const scenario = await this.scenarioService.importScenario({
|
||||
kind: "scenario",
|
||||
id,
|
||||
version,
|
||||
name,
|
||||
description,
|
||||
steps: steps as { title: string | null; execCode: string | null }[],
|
||||
@@ -1062,6 +1307,40 @@ export class McpService {
|
||||
},
|
||||
);
|
||||
|
||||
server.registerTool(
|
||||
"export_e2e_test",
|
||||
{
|
||||
description:
|
||||
"Export a scenario as a standalone, plug-and-play Playwright e2e test project (package.json, playwright.config.ts, test.spec.ts, .env), zipped and returned as base64",
|
||||
inputSchema: {
|
||||
id: z.uuid().describe("Scenario ID to export"),
|
||||
},
|
||||
},
|
||||
async ({ id }) => {
|
||||
try {
|
||||
const { filename, buffer } =
|
||||
await this.e2eExportService.buildE2eTestPackage(id);
|
||||
return {
|
||||
content: [
|
||||
{
|
||||
type: "text" as const,
|
||||
text: JSON.stringify({
|
||||
filename,
|
||||
contentBase64: buffer.toString("base64"),
|
||||
encoding: "base64",
|
||||
}),
|
||||
},
|
||||
],
|
||||
};
|
||||
} catch (err) {
|
||||
return {
|
||||
isError: true,
|
||||
content: [{ type: "text" as const, text: (err as Error).message }],
|
||||
};
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
// ── Scenario Files ────────────────────────────────────────────────────────
|
||||
|
||||
server.registerTool(
|
||||
@@ -1391,7 +1670,7 @@ export class McpService {
|
||||
alias: z
|
||||
.string()
|
||||
.describe(
|
||||
"Unique identifier used to invoke the snippet via context.runSnippet(alias, ...args)",
|
||||
"Unique identifier used to invoke the snippet via context.runSnippet(alias, ...args). Use 'alias@<version>' to pin a specific version instead of the latest",
|
||||
),
|
||||
title: z.string().describe("Human-readable title"),
|
||||
description: z
|
||||
@@ -1460,6 +1739,54 @@ export class McpService {
|
||||
},
|
||||
);
|
||||
|
||||
server.registerTool(
|
||||
"list_snippet_versions",
|
||||
{
|
||||
description:
|
||||
"List a snippet's versions, newest first. Step code pins a version with context.runSnippet('alias@<version>')",
|
||||
inputSchema: {
|
||||
id: z.uuid().describe("Snippet ID"),
|
||||
},
|
||||
},
|
||||
async ({ id }) => {
|
||||
try {
|
||||
const versions = await this.snippetService.listVersions(id);
|
||||
return {
|
||||
content: [{ type: "text" as const, text: JSON.stringify(versions) }],
|
||||
};
|
||||
} catch (err) {
|
||||
return {
|
||||
isError: true,
|
||||
content: [{ type: "text" as const, text: (err as Error).message }],
|
||||
};
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
server.registerTool(
|
||||
"get_snippet_version",
|
||||
{
|
||||
description: "Get one version of a snippet",
|
||||
inputSchema: {
|
||||
id: z.uuid().describe("Snippet ID"),
|
||||
version: z.number().int().min(1).describe("Snippet version"),
|
||||
},
|
||||
},
|
||||
async ({ id, version }) => {
|
||||
try {
|
||||
const row = await this.snippetService.findVersion(id, version);
|
||||
return {
|
||||
content: [{ type: "text" as const, text: JSON.stringify(row) }],
|
||||
};
|
||||
} catch (err) {
|
||||
return {
|
||||
isError: true,
|
||||
content: [{ type: "text" as const, text: (err as Error).message }],
|
||||
};
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
server.registerTool(
|
||||
"delete_snippet",
|
||||
{
|
||||
|
||||
@@ -1,4 +1,13 @@
|
||||
import { IsBoolean, IsNotEmpty, IsOptional, IsUUID } from "class-validator";
|
||||
import {
|
||||
IsBoolean,
|
||||
IsEnum,
|
||||
IsInt,
|
||||
IsNotEmpty,
|
||||
IsOptional,
|
||||
IsUUID,
|
||||
Min,
|
||||
} from "class-validator";
|
||||
import { TraceMode } from "../../config/app.config";
|
||||
|
||||
export class CreateScenarioRunDto {
|
||||
@IsUUID()
|
||||
@@ -8,4 +17,14 @@ export class CreateScenarioRunDto {
|
||||
@IsBoolean()
|
||||
@IsOptional()
|
||||
saveSession?: boolean;
|
||||
|
||||
@IsEnum(TraceMode)
|
||||
@IsOptional()
|
||||
traceMode?: TraceMode;
|
||||
|
||||
/** Scenario version to run; defaults to the latest. */
|
||||
@IsInt()
|
||||
@Min(1)
|
||||
@IsOptional()
|
||||
version?: number;
|
||||
}
|
||||
@@ -3,11 +3,13 @@ import { Type } from "class-transformer";
|
||||
import {
|
||||
IsArray,
|
||||
IsIn,
|
||||
IsInt,
|
||||
IsNotEmpty,
|
||||
IsObject,
|
||||
IsOptional,
|
||||
IsString,
|
||||
IsUUID,
|
||||
Min,
|
||||
ValidateNested,
|
||||
} from "class-validator";
|
||||
import { EnvironmentData } from "../../environment/environment.entity";
|
||||
@@ -24,6 +26,12 @@ export class ScenarioStepExportDto {
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
execCode: string | null;
|
||||
|
||||
@ApiPropertyOptional()
|
||||
@IsOptional()
|
||||
@IsInt()
|
||||
@Min(1)
|
||||
timeoutSeconds?: number | null;
|
||||
}
|
||||
|
||||
export class CredentialExportDto {
|
||||
@@ -117,6 +125,17 @@ export class ScenarioExportDto {
|
||||
@IsUUID()
|
||||
environmentId?: string;
|
||||
|
||||
@ApiProperty({ description: "Scenario version this export holds" })
|
||||
@IsInt()
|
||||
@Min(1)
|
||||
version: number;
|
||||
|
||||
@ApiPropertyOptional()
|
||||
@IsOptional()
|
||||
@IsInt()
|
||||
@Min(1)
|
||||
timeoutSeconds?: number;
|
||||
|
||||
@ApiPropertyOptional({ type: [ScenarioCredentialMappingDto] })
|
||||
@IsOptional()
|
||||
@IsArray()
|
||||
|
||||
@@ -0,0 +1,473 @@
|
||||
import { Injectable } from "@nestjs/common";
|
||||
import archiver = require("archiver");
|
||||
import { resolveUsedSnippetAliases } from "../common/snippet-usage";
|
||||
import { SnippetService } from "../snippet/snippet.service";
|
||||
import { ScenarioService } from "./scenario.service";
|
||||
|
||||
const DEFAULT_SCENARIO_TIMEOUT_SEC = 600;
|
||||
const DEFAULT_STEP_TIMEOUT_SEC = 60;
|
||||
|
||||
function slugify(name: string): string {
|
||||
const slug = name
|
||||
.toLowerCase()
|
||||
.trim()
|
||||
.replace(/[^a-z0-9]+/g, "-")
|
||||
.replace(/^-+|-+$/g, "");
|
||||
return slug || "scenario";
|
||||
}
|
||||
|
||||
function jsStringLiteral(code: string): string {
|
||||
return JSON.stringify(code);
|
||||
}
|
||||
|
||||
function sanitizeAlias(alias: string): string {
|
||||
const sanitized = alias.replace(/[^A-Za-z0-9_-]+/g, "_").replace(/^_+|_+$/g, "");
|
||||
return sanitized || "snippet";
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds a standalone, plug-and-play Playwright test project (package.json,
|
||||
* playwright.config.ts, test.spec.ts, .env, README) from a scenario's steps,
|
||||
* zipped for download. Each step's execCode is embedded verbatim and run
|
||||
* against a `context` shim that mirrors the shape scripts already use in
|
||||
* liqa (env, credentials, snippets, assert, ...).
|
||||
*/
|
||||
@Injectable()
|
||||
export class E2eExportService {
|
||||
constructor(
|
||||
private readonly scenarioService: ScenarioService,
|
||||
private readonly snippetService: SnippetService,
|
||||
) {}
|
||||
|
||||
async buildE2eTestPackage(scenarioId: string): Promise<{ filename: string; buffer: Buffer }> {
|
||||
const scenario = await this.scenarioService.findOne(scenarioId);
|
||||
const [credentialMap, snippetMap, attachedFiles] = await Promise.all([
|
||||
this.scenarioService.buildCredentialMap(scenarioId),
|
||||
this.snippetService.buildSnippetMap(),
|
||||
this.scenarioService.listScenarioFiles(scenarioId, 1000, 0),
|
||||
]);
|
||||
const envData = scenario.environment?.data ?? {};
|
||||
|
||||
const slug = slugify(scenario.name);
|
||||
const files: Record<string, string | Buffer> = {
|
||||
"package.json": this.buildPackageJson(slug),
|
||||
"playwright.config.ts": this.buildPlaywrightConfig(scenario.timeoutSeconds),
|
||||
".env": this.buildEnvFile(envData),
|
||||
"credentials.json": JSON.stringify(credentialMap, null, 2) + "\n",
|
||||
".gitignore": [
|
||||
"node_modules/",
|
||||
"test-results/",
|
||||
"playwright-report/",
|
||||
"downloads/",
|
||||
".env",
|
||||
"credentials.json",
|
||||
].join("\n") + "\n",
|
||||
"README.md": this.buildReadme(scenario.name, scenario.description),
|
||||
};
|
||||
|
||||
// Bundle any files attached to the scenario so getScenarioFiles works offline.
|
||||
const fileManifest: { id: string; name: string; mimeType: string; size: number; sha256: string; zipPath: string }[] =
|
||||
[];
|
||||
for (const item of attachedFiles.items as {
|
||||
id: string;
|
||||
name: string;
|
||||
mimeType: string;
|
||||
size: number;
|
||||
sha256: string;
|
||||
}[]) {
|
||||
const { contentBuffer } = await this.scenarioService.getScenarioFileContentAsBuffer(
|
||||
scenarioId,
|
||||
item.id,
|
||||
);
|
||||
const zipPath = `files/${item.id}__${item.name}`;
|
||||
files[zipPath] = contentBuffer;
|
||||
fileManifest.push({
|
||||
id: item.id,
|
||||
name: item.name,
|
||||
mimeType: item.mimeType,
|
||||
size: item.size,
|
||||
sha256: item.sha256,
|
||||
zipPath,
|
||||
});
|
||||
}
|
||||
|
||||
// Bundle only the snippets actually referenced (directly or transitively via
|
||||
// other snippets) by this scenario's steps, as individual .js files under snippets/.
|
||||
const usedAliases = resolveUsedSnippetAliases(
|
||||
scenario.steps.map((s) => s.execCode ?? ""),
|
||||
snippetMap,
|
||||
);
|
||||
const snippetManifest: { alias: string; filename: string }[] = [];
|
||||
const usedSnippetFilenames = new Set<string>();
|
||||
for (const alias of usedAliases) {
|
||||
const code = snippetMap[alias];
|
||||
const base = sanitizeAlias(alias);
|
||||
let filename = `${base}.js`;
|
||||
let suffix = 2;
|
||||
while (usedSnippetFilenames.has(filename)) {
|
||||
filename = `${base}-${suffix}.js`;
|
||||
suffix += 1;
|
||||
}
|
||||
usedSnippetFilenames.add(filename);
|
||||
files[`snippets/${filename}`] = code;
|
||||
snippetManifest.push({ alias, filename });
|
||||
}
|
||||
|
||||
files["test.spec.ts"] = this.buildTestSpec(scenario, snippetManifest, fileManifest);
|
||||
|
||||
const buffer = await this.zip(files);
|
||||
return { filename: `${slug}-e2e-test.zip`, buffer };
|
||||
}
|
||||
|
||||
private buildPackageJson(slug: string): string {
|
||||
return (
|
||||
JSON.stringify(
|
||||
{
|
||||
name: `${slug}-e2e-test`,
|
||||
version: "1.0.0",
|
||||
private: true,
|
||||
scripts: {
|
||||
test: "playwright test",
|
||||
"test:headed": "playwright test --headed",
|
||||
},
|
||||
devDependencies: {
|
||||
"@playwright/test": "^1.59.1",
|
||||
dotenv: "^17.4.2",
|
||||
},
|
||||
},
|
||||
null,
|
||||
2,
|
||||
) + "\n"
|
||||
);
|
||||
}
|
||||
|
||||
private buildPlaywrightConfig(scenarioTimeoutSeconds: number | null): string {
|
||||
const timeoutMs = (scenarioTimeoutSeconds ?? DEFAULT_SCENARIO_TIMEOUT_SEC) * 1000;
|
||||
return `import { defineConfig } from "@playwright/test";
|
||||
import * as dotenv from "dotenv";
|
||||
import * as path from "path";
|
||||
|
||||
dotenv.config({ path: path.resolve(__dirname, ".env") });
|
||||
|
||||
export default defineConfig({
|
||||
testDir: ".",
|
||||
timeout: ${timeoutMs},
|
||||
use: {
|
||||
headless: true,
|
||||
},
|
||||
});
|
||||
`;
|
||||
}
|
||||
|
||||
private buildEnvFile(envData: Record<string, string>): string {
|
||||
const lines = Object.entries(envData).map(([key, value]) => `${key}=${value}`);
|
||||
return (
|
||||
[
|
||||
"# Environment values copied from the scenario's liqa environment.",
|
||||
"# This file may contain secrets - do not commit it.",
|
||||
...lines,
|
||||
].join("\n") + "\n"
|
||||
);
|
||||
}
|
||||
|
||||
private buildReadme(scenarioName: string, description: string | null): string {
|
||||
const descriptionSection = description?.trim() ? `${description.trim()}\n\n` : "";
|
||||
return `# ${scenarioName} - standalone e2e test
|
||||
|
||||
${descriptionSection}## Setup
|
||||
|
||||
\`\`\`sh
|
||||
npm install
|
||||
npx playwright install --with-deps chromium
|
||||
\`\`\`
|
||||
|
||||
## Run
|
||||
|
||||
\`\`\`sh
|
||||
npm test
|
||||
\`\`\`
|
||||
|
||||
Environment values are loaded from \`.env\` (as plain process env vars). Credential
|
||||
data resolved from this scenario's aliases is stored in \`credentials.json\` and
|
||||
loaded by \`context.getCredential\`. Snippet bodies are stored as individual \`.js\`
|
||||
files under \`snippets/\` and loaded by \`context.runSnippet\`. Files attached to
|
||||
the scenario are bundled under \`files/\` and served locally by
|
||||
\`context.getScenarioFiles\`. \`context.downloadFile\` performs a real HTTP (or
|
||||
\`data:\` URL) download and saves the result under \`downloads/\`.
|
||||
`;
|
||||
}
|
||||
|
||||
private buildTestSpec(
|
||||
scenario: { name: string; timeoutSeconds: number | null; steps: { order: number; title: string | null; execCode: string | null; timeoutSeconds: number | null }[] },
|
||||
snippetManifest: { alias: string; filename: string }[],
|
||||
fileManifest: { id: string; name: string; mimeType: string; size: number; sha256: string; zipPath: string }[],
|
||||
): string {
|
||||
const steps = [...scenario.steps].sort((a, b) => a.order - b.order);
|
||||
const scenarioTimeoutSec = scenario.timeoutSeconds ?? DEFAULT_SCENARIO_TIMEOUT_SEC;
|
||||
|
||||
const stepBlocks = steps
|
||||
.map((step, index) => {
|
||||
const title = (step.title ?? `Step ${index + 1}`).replace(/`/g, "\\`");
|
||||
const timeoutSec = step.timeoutSeconds ?? scenarioTimeoutSec ?? DEFAULT_STEP_TIMEOUT_SEC;
|
||||
const code = step.execCode ?? "";
|
||||
return ` await test.step(\`${title}\`, async () => {
|
||||
const __run = new Function(
|
||||
"context",
|
||||
"console",
|
||||
"result",
|
||||
"expect",
|
||||
\`return (async (context) => { ${code.replace(/\\/g, "\\\\").replace(/`/g, "\\`").replace(/\$\{/g, "\\${")} })(context)\`,
|
||||
);
|
||||
const __timeoutMs = ${timeoutSec * 1000};
|
||||
const __output = await Promise.race([
|
||||
__run(context, console, undefined, expect),
|
||||
new Promise((_, reject) =>
|
||||
setTimeout(() => reject(new Error(\`Step timed out after ${timeoutSec}s\`)), __timeoutMs),
|
||||
),
|
||||
]);
|
||||
stepOutputs.push({ order: ${step.order}, output: __output });
|
||||
});`;
|
||||
})
|
||||
.join("\n\n");
|
||||
|
||||
return `import { test, expect } from "@playwright/test";
|
||||
import type { BrowserContext, Page } from "@playwright/test";
|
||||
import * as fs from "fs";
|
||||
import * as path from "path";
|
||||
import * as crypto from "crypto";
|
||||
import * as http from "http";
|
||||
import * as https from "https";
|
||||
import { URL } from "url";
|
||||
import { randomUUID } from "crypto";
|
||||
|
||||
// Credential data resolved from this scenario's aliases at export time.
|
||||
// Stored in credentials.json (gitignored) - contains sensitive values.
|
||||
const CREDENTIALS: Record<string, unknown> = JSON.parse(
|
||||
fs.readFileSync(path.resolve(__dirname, "credentials.json"), "utf-8"),
|
||||
);
|
||||
|
||||
// Snippet bodies are stored as individual .js files under snippets/, available
|
||||
// via context.runSnippet(alias, ...args).
|
||||
const SNIPPET_FILES: { alias: string; filename: string }[] = ${JSON.stringify(snippetManifest, null, 2)};
|
||||
|
||||
// Files attached to the scenario, bundled alongside this test under files/.
|
||||
const FILES: { id: string; name: string; mimeType: string; size: number; sha256: string; zipPath: string }[] =
|
||||
${JSON.stringify(fileManifest, null, 2)};
|
||||
|
||||
interface StepOutput {
|
||||
order: number;
|
||||
output: unknown;
|
||||
}
|
||||
|
||||
// ── Standalone downloadFile: real HTTP/data: URL fetch, no liqa backend involved ──
|
||||
|
||||
const MAX_DOWNLOAD_SIZE = 100 * 1024 * 1024; // 100 MB
|
||||
const DOWNLOAD_TIMEOUT_MS = 30000;
|
||||
|
||||
function decodeDataUrl(urlStr: string): Buffer {
|
||||
const match = /^data:([^,]*),(.*)$/s.exec(urlStr);
|
||||
if (!match) {
|
||||
throw new Error("Malformed data: URL");
|
||||
}
|
||||
const [, meta, data] = match;
|
||||
if (meta.endsWith(";base64")) {
|
||||
return Buffer.from(data, "base64");
|
||||
}
|
||||
return Buffer.from(decodeURIComponent(data), "utf-8");
|
||||
}
|
||||
|
||||
function fetchBytes(
|
||||
urlStr: string,
|
||||
options?: { method?: string; headers?: Record<string, string>; body?: string },
|
||||
): Promise<Buffer> {
|
||||
if (urlStr.startsWith("data:")) {
|
||||
return Promise.resolve(decodeDataUrl(urlStr));
|
||||
}
|
||||
const url = new URL(urlStr);
|
||||
const protocol = url.protocol === "https:" ? https : http;
|
||||
const method = options?.method ?? "GET";
|
||||
const headers = options?.headers ?? {};
|
||||
return new Promise((resolve, reject) => {
|
||||
const req = protocol.request(
|
||||
{ hostname: url.hostname, port: url.port, path: url.pathname + url.search, method, headers, timeout: DOWNLOAD_TIMEOUT_MS },
|
||||
(res) => {
|
||||
if (res.statusCode && res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
|
||||
fetchBytes(res.headers.location, options).then(resolve).catch(reject);
|
||||
return;
|
||||
}
|
||||
if (res.statusCode && res.statusCode !== 200) {
|
||||
reject(new Error(\`HTTP \${res.statusCode}: \${res.statusMessage}\`));
|
||||
return;
|
||||
}
|
||||
const chunks: Buffer[] = [];
|
||||
let totalSize = 0;
|
||||
res.on("data", (chunk: Buffer) => {
|
||||
totalSize += chunk.length;
|
||||
if (totalSize > MAX_DOWNLOAD_SIZE) {
|
||||
req.destroy();
|
||||
reject(new Error(\`File exceeds maximum size of \${MAX_DOWNLOAD_SIZE} bytes\`));
|
||||
return;
|
||||
}
|
||||
chunks.push(chunk);
|
||||
});
|
||||
res.on("end", () => resolve(Buffer.concat(chunks)));
|
||||
res.on("error", reject);
|
||||
},
|
||||
);
|
||||
req.on("timeout", () => {
|
||||
req.destroy();
|
||||
reject(new Error("Download timeout"));
|
||||
});
|
||||
req.on("error", reject);
|
||||
if (options?.body && (method === "POST" || method === "PUT")) {
|
||||
req.write(options.body);
|
||||
}
|
||||
req.end();
|
||||
});
|
||||
}
|
||||
|
||||
const MIME_TYPES: Record<string, string> = {
|
||||
pdf: "application/pdf",
|
||||
doc: "application/msword",
|
||||
docx: "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
||||
xls: "application/vnd.ms-excel",
|
||||
xlsx: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
||||
jpg: "image/jpeg",
|
||||
jpeg: "image/jpeg",
|
||||
png: "image/png",
|
||||
gif: "image/gif",
|
||||
csv: "text/csv",
|
||||
txt: "text/plain",
|
||||
zip: "application/zip",
|
||||
};
|
||||
|
||||
function inferMimeType(filename: string): string {
|
||||
const ext = filename.split(".").pop()?.toLowerCase() ?? "";
|
||||
return MIME_TYPES[ext] ?? "application/octet-stream";
|
||||
}
|
||||
|
||||
function buildContext(page: Page, browser: BrowserContext, stepOutputs: StepOutput[]) {
|
||||
const context: Record<string, unknown> = {
|
||||
page,
|
||||
browser,
|
||||
env: { ...process.env },
|
||||
getEnv(key: string): string {
|
||||
const value = process.env[key];
|
||||
if (value == null) {
|
||||
throw new Error(\`Environment value "\${key}" is not defined\`);
|
||||
}
|
||||
return value;
|
||||
},
|
||||
getCredential(alias: string): unknown {
|
||||
if (!(alias in CREDENTIALS)) {
|
||||
throw new Error(\`Credential alias "\${alias}" not found in this export\`);
|
||||
}
|
||||
return CREDENTIALS[alias];
|
||||
},
|
||||
log: (...args: unknown[]) => console.log(...args),
|
||||
warn: (...args: unknown[]) => console.warn(...args),
|
||||
error: (...args: unknown[]) => console.error(...args),
|
||||
assert: async (fn: () => boolean | Promise<boolean>, description: string): Promise<void> => {
|
||||
let passed: boolean;
|
||||
let failureReason: string | undefined;
|
||||
try {
|
||||
passed = (await fn()) === true;
|
||||
} catch (err) {
|
||||
passed = false;
|
||||
failureReason = (err as Error).message;
|
||||
}
|
||||
if (passed) {
|
||||
console.log(\`Assertion passed: \${description}\`);
|
||||
return;
|
||||
}
|
||||
const message = failureReason
|
||||
? \`Assertion failed: \${description} (\${failureReason})\`
|
||||
: \`Assertion failed: \${description}\`;
|
||||
console.error(message);
|
||||
throw new Error(message);
|
||||
},
|
||||
getStepOutput: async (order: number): Promise<unknown> => {
|
||||
const targetOrder = order < 0 ? stepOutputs.length + order + 1 : order;
|
||||
return stepOutputs.find((s) => s.order === targetOrder)?.output ?? null;
|
||||
},
|
||||
runSnippet: async (alias: string, ...args: unknown[]): Promise<unknown> => {
|
||||
const entry = SNIPPET_FILES.find((s) => s.alias === alias);
|
||||
if (!entry) {
|
||||
throw new Error(\`Snippet alias "\${alias}" not found\`);
|
||||
}
|
||||
const snippetCode = fs.readFileSync(path.resolve(__dirname, "snippets", entry.filename), "utf-8");
|
||||
const snippetFn = new Function(
|
||||
"context",
|
||||
"console",
|
||||
"snippetArgs",
|
||||
"expect",
|
||||
\`return (async (context, ...args) => { \${snippetCode} })(context, ...snippetArgs)\`,
|
||||
);
|
||||
return snippetFn(context, console, args, expect);
|
||||
},
|
||||
dumpDom: async (): Promise<never> => {
|
||||
throw new Error("dumpDom is not available in this standalone export");
|
||||
},
|
||||
getScenarioFiles: async (opts?: { limit?: number; offset?: number }) => {
|
||||
const offset = opts?.offset ?? 0;
|
||||
const limit = opts?.limit ?? FILES.length;
|
||||
const items = FILES.slice(offset, offset + limit).map((f) => ({
|
||||
id: f.id,
|
||||
name: f.name,
|
||||
mimeType: f.mimeType,
|
||||
size: f.size,
|
||||
sha256: f.sha256,
|
||||
path: path.resolve(__dirname, f.zipPath),
|
||||
}));
|
||||
return { items, total: FILES.length };
|
||||
},
|
||||
downloadFile: async (
|
||||
url: string,
|
||||
opts?: { method?: string; headers?: Record<string, string>; body?: string; filename?: string },
|
||||
) => {
|
||||
const buffer = await fetchBytes(url, opts);
|
||||
const filename =
|
||||
opts?.filename ??
|
||||
(url.startsWith("data:") ? "download" : new URL(url).pathname.split("/").pop() || "download");
|
||||
const downloadsDir = path.resolve(__dirname, "downloads");
|
||||
fs.mkdirSync(downloadsDir, { recursive: true });
|
||||
const filePath = path.join(downloadsDir, filename);
|
||||
fs.writeFileSync(filePath, buffer);
|
||||
return {
|
||||
id: randomUUID(),
|
||||
name: filename,
|
||||
mimeType: inferMimeType(filename),
|
||||
size: buffer.length,
|
||||
sha256: crypto.createHash("sha256").update(buffer).digest("hex"),
|
||||
path: filePath,
|
||||
};
|
||||
},
|
||||
};
|
||||
return context;
|
||||
}
|
||||
|
||||
test.describe(${jsStringLiteral(scenario.name)}, () => {
|
||||
test(${jsStringLiteral(scenario.name)}, async ({ page, context: browserContext }) => {
|
||||
const stepOutputs: StepOutput[] = [];
|
||||
const context = buildContext(page, browserContext, stepOutputs);
|
||||
|
||||
${stepBlocks}
|
||||
});
|
||||
});
|
||||
`;
|
||||
}
|
||||
|
||||
private zip(files: Record<string, string | Buffer>): Promise<Buffer> {
|
||||
return new Promise((resolve, reject) => {
|
||||
const archive = archiver("zip", { zlib: { level: 9 } });
|
||||
const chunks: Buffer[] = [];
|
||||
archive.on("data", (chunk: Buffer) => chunks.push(chunk));
|
||||
archive.on("error", (err) => reject(err));
|
||||
archive.on("end", () => resolve(Buffer.concat(chunks)));
|
||||
for (const [name, content] of Object.entries(files)) {
|
||||
archive.append(content, { name });
|
||||
}
|
||||
void archive.finalize();
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -39,6 +39,11 @@ export class ScenarioRunLogEntity {
|
||||
@Column({ type: "text" })
|
||||
message: string;
|
||||
|
||||
// Assigned in call order per run, since concurrent unawaited writes can
|
||||
// otherwise persist out of order (createdAt alone isn't a reliable tiebreaker).
|
||||
@Column({ type: "int", default: 0 })
|
||||
seq: number;
|
||||
|
||||
@CreateDateColumn()
|
||||
createdAt: Date;
|
||||
}
|
||||
@@ -32,12 +32,24 @@ export class ScenarioRunStepEntity {
|
||||
@JoinColumn({ name: "runId" })
|
||||
run: ScenarioRunEntity;
|
||||
|
||||
@Column("text")
|
||||
scenarioStepId: string;
|
||||
/** Live step this run step was created from; null once that step is deleted. */
|
||||
@Column("text", { nullable: true })
|
||||
scenarioStepId: string | null;
|
||||
|
||||
@ManyToOne(() => ScenarioStepEntity, { onDelete: "CASCADE" })
|
||||
@ManyToOne(() => ScenarioStepEntity, { onDelete: "SET NULL", nullable: true })
|
||||
@JoinColumn({ name: "scenarioStepId" })
|
||||
scenarioStep: ScenarioStepEntity;
|
||||
scenarioStep: ScenarioStepEntity | null;
|
||||
|
||||
// Step content copied from the run's scenario version, so the run executes
|
||||
// (and keeps showing) exactly what it was created with.
|
||||
@Column({ type: "text", nullable: true })
|
||||
title: string | null;
|
||||
|
||||
@Column({ type: "text", nullable: true })
|
||||
execCode: string | null;
|
||||
|
||||
@Column({ type: "int", nullable: true })
|
||||
timeoutSeconds: number | null;
|
||||
|
||||
@Column({ type: "text", default: "waiting" })
|
||||
status: RunStepStatus;
|
||||
|
||||
@@ -8,6 +8,7 @@ import {
|
||||
PrimaryGeneratedColumn,
|
||||
UpdateDateColumn,
|
||||
} from "typeorm";
|
||||
import type { TraceMode } from "../config/app.config";
|
||||
import { EnvironmentEntity } from "../environment/environment.entity";
|
||||
import { SessionEntity } from "../session/session.entity";
|
||||
import { ScenarioRunStepEntity } from "./scenario-run-step.entity";
|
||||
@@ -41,12 +42,20 @@ export class ScenarioRunEntity {
|
||||
@JoinColumn({ name: "sessionId" })
|
||||
session: SessionEntity | null;
|
||||
|
||||
/** Scenario version this run executes; null for runs created before versioning. */
|
||||
@Column({ type: "int", nullable: true, default: null })
|
||||
scenarioVersion: number | null;
|
||||
|
||||
@Column({ type: "text", default: "pending" })
|
||||
status: RunStatus;
|
||||
|
||||
@Column({ type: "boolean", default: false })
|
||||
saveSession: boolean;
|
||||
|
||||
// Playwright trace mode for this run; null falls back to PLAYWRIGHT_TRACE_MODE
|
||||
@Column("text", { nullable: true, default: null })
|
||||
traceMode: TraceMode | null;
|
||||
|
||||
@OneToMany(() => ScenarioRunStepEntity, (rs) => rs.run, {
|
||||
cascade: true,
|
||||
eager: false,
|
||||
|
||||
@@ -1,11 +1,16 @@
|
||||
import { Injectable, OnModuleInit } from "@nestjs/common";
|
||||
import { ConfigService } from "@nestjs/config";
|
||||
import { Interval } from "@nestjs/schedule";
|
||||
import { InjectRepository } from "@nestjs/typeorm";
|
||||
import * as crypto from "crypto";
|
||||
import * as fs from "fs/promises";
|
||||
import * as os from "os";
|
||||
import * as path from "path";
|
||||
import { Effect } from "effect";
|
||||
import type { Browser, BrowserContext, Page } from "playwright";
|
||||
import { chromium } from "playwright";
|
||||
import { Repository } from "typeorm";
|
||||
import { type AppConfig, TraceMode } from "../config/app.config";
|
||||
import { FileStorageService } from "../file/file-storage.service";
|
||||
import type { ScriptLogger } from "../code-executor/code-executor.service";
|
||||
import { CodeExecutorService } from "../code-executor/code-executor.service";
|
||||
@@ -22,13 +27,13 @@ import { SnippetService } from "../snippet/snippet.service";
|
||||
import { ScenarioRunLogEntity } from "./scenario-run-log.entity";
|
||||
import { ScenarioRunStepEntity } from "./scenario-run-step.entity";
|
||||
import { ScenarioRunEntity } from "./scenario-run.entity";
|
||||
import { ScenarioStepEntity } from "./scenario-step.entity";
|
||||
import { ScenarioService } from "./scenario.service";
|
||||
|
||||
interface BrowserHandle {
|
||||
browser: Browser;
|
||||
context: BrowserContext;
|
||||
page: Page;
|
||||
tracing: boolean;
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
@@ -46,6 +51,12 @@ export class ScenarioSchedulerService implements OnModuleInit {
|
||||
private readonly runScenarioTimeouts = new Map<string, number | null>();
|
||||
// Cache scenarioId per run
|
||||
private readonly runScenarioIds = new Map<string, string>();
|
||||
// Monotonic log sequence per run, since persistLog writes are unawaited and
|
||||
// can otherwise resolve out of call order
|
||||
private readonly runLogSeq = new Map<string, number>();
|
||||
// Cache Playwright trace mode per run
|
||||
private readonly runTraceModes = new Map<string, TraceMode>();
|
||||
private readonly defaultTraceMode: TraceMode;
|
||||
|
||||
private static readonly DEFAULT_SCENARIO_TIMEOUT_SEC = 600;
|
||||
private static readonly DEFAULT_STEP_TIMEOUT_SEC = 60;
|
||||
@@ -66,7 +77,10 @@ export class ScenarioSchedulerService implements OnModuleInit {
|
||||
private readonly sessionService: SessionService,
|
||||
private readonly sessionContextService: SessionContextService,
|
||||
private readonly fileStorageService: FileStorageService,
|
||||
) {}
|
||||
configService: ConfigService<AppConfig, true>,
|
||||
) {
|
||||
this.defaultTraceMode = configService.get("PLAYWRIGHT_TRACE_MODE");
|
||||
}
|
||||
|
||||
async onModuleInit(): Promise<void> {
|
||||
const staleRuns = await this.runRepo.find({
|
||||
@@ -138,8 +152,10 @@ export class ScenarioSchedulerService implements OnModuleInit {
|
||||
level: "log" | "warn" | "error",
|
||||
message: string,
|
||||
): void {
|
||||
const seq = (this.runLogSeq.get(runId) ?? 0) + 1;
|
||||
this.runLogSeq.set(runId, seq);
|
||||
void this.runLogRepo.save(
|
||||
this.runLogRepo.create({ runId, stepRunId, level, message }),
|
||||
this.runLogRepo.create({ runId, stepRunId, level, message, seq }),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -198,11 +214,24 @@ export class ScenarioSchedulerService implements OnModuleInit {
|
||||
.then((env) => env?.data ?? {})
|
||||
.catch(() => ({}) as EnvironmentData);
|
||||
this.runEnvironments.set(run.id, environmentData);
|
||||
const scenario = await this.scenarioService
|
||||
.findOne(run.scenarioId)
|
||||
.catch(() => null);
|
||||
this.runScenarioTimeouts.set(run.id, scenario?.timeoutSeconds ?? null);
|
||||
// Legacy runs (no scenarioVersion) fall back to the live scenario
|
||||
const versioned =
|
||||
run.scenarioVersion != null
|
||||
? await this.scenarioService
|
||||
.findVersion(run.scenarioId, run.scenarioVersion)
|
||||
.catch(() => null)
|
||||
: await this.scenarioService
|
||||
.findOne(run.scenarioId)
|
||||
.catch(() => null);
|
||||
this.runScenarioTimeouts.set(
|
||||
run.id,
|
||||
versioned?.timeoutSeconds ?? null,
|
||||
);
|
||||
this.runScenarioIds.set(run.id, run.scenarioId);
|
||||
this.runTraceModes.set(
|
||||
run.id,
|
||||
run.traceMode ?? this.defaultTraceMode,
|
||||
);
|
||||
const traceId = crypto.randomUUID();
|
||||
void traceStorage.run({ traceId }, () =>
|
||||
this.processRunToCompletion(run.id),
|
||||
@@ -216,6 +245,8 @@ export class ScenarioSchedulerService implements OnModuleInit {
|
||||
this.runEnvironments.delete(run.id);
|
||||
this.runScenarioTimeouts.delete(run.id);
|
||||
this.runScenarioIds.delete(run.id);
|
||||
this.runTraceModes.delete(run.id);
|
||||
this.runLogSeq.delete(run.id);
|
||||
this.logger.error(
|
||||
`Run #${run.id}: setup failed — ${String(err)}`,
|
||||
);
|
||||
@@ -240,7 +271,6 @@ export class ScenarioSchedulerService implements OnModuleInit {
|
||||
try {
|
||||
let stepRun = await this.runStepRepo.findOne({
|
||||
where: { runId, status: "pending" },
|
||||
relations: ["scenarioStep"],
|
||||
order: { order: "ASC" },
|
||||
});
|
||||
while (stepRun) {
|
||||
@@ -257,7 +287,6 @@ export class ScenarioSchedulerService implements OnModuleInit {
|
||||
await this.executeStepRun(stepRun);
|
||||
stepRun = await this.runStepRepo.findOne({
|
||||
where: { runId, status: "pending" },
|
||||
relations: ["scenarioStep"],
|
||||
order: { order: "ASC" },
|
||||
});
|
||||
}
|
||||
@@ -273,12 +302,16 @@ export class ScenarioSchedulerService implements OnModuleInit {
|
||||
);
|
||||
await this.failRun(runId, `Unexpected error: ${(err as Error).message}`);
|
||||
} finally {
|
||||
// Before runLogSeq is cleared, so the trace log entry keeps its order
|
||||
await this.saveTrace(runId);
|
||||
this.activeRuns.delete(runId);
|
||||
this.runCredentials.delete(runId);
|
||||
this.runSnippets.delete(runId);
|
||||
this.runEnvironments.delete(runId);
|
||||
this.runScenarioTimeouts.delete(runId);
|
||||
this.runScenarioIds.delete(runId);
|
||||
this.runTraceModes.delete(runId);
|
||||
this.runLogSeq.delete(runId);
|
||||
await this.maybePreserveSession(runId);
|
||||
}
|
||||
}
|
||||
@@ -338,12 +371,19 @@ export class ScenarioSchedulerService implements OnModuleInit {
|
||||
}
|
||||
|
||||
private async executeStepRun(stepRun: ScenarioRunStepEntity): Promise<void> {
|
||||
const step = stepRun.scenarioStep as ScenarioStepEntity;
|
||||
// Run steps carry a copy of the step from the run's scenario version
|
||||
const step = stepRun;
|
||||
|
||||
stepRun.status = "in_progress";
|
||||
await this.runStepRepo.save(stepRun);
|
||||
this.logger.log(
|
||||
`StepRun #${stepRun.id} (run #${stepRun.runId}, step #${step.id} order=${step.order}) → in_progress`,
|
||||
`StepRun #${stepRun.id} (run #${stepRun.runId}, step #${step.scenarioStepId ?? "deleted"} order=${step.order}) → in_progress`,
|
||||
);
|
||||
this.persistLog(
|
||||
stepRun.runId,
|
||||
stepRun.id,
|
||||
"log",
|
||||
`Step ${step.order} started${step.title ? `: ${step.title}` : ""}`,
|
||||
);
|
||||
|
||||
try {
|
||||
@@ -418,9 +458,21 @@ export class ScenarioSchedulerService implements OnModuleInit {
|
||||
executablePath: process.env.PLAYWRIGHT_CHROMIUM_EXECUTABLE_PATH,
|
||||
});
|
||||
const context = await browser.newContext();
|
||||
let tracing = false;
|
||||
const traceMode = this.runTraceModes.get(runId) ?? this.defaultTraceMode;
|
||||
if (traceMode !== TraceMode.Off) {
|
||||
try {
|
||||
await context.tracing.start({ screenshots: true, snapshots: true });
|
||||
tracing = true;
|
||||
} catch (err) {
|
||||
this.logger.warn(
|
||||
`Run #${runId}: failed to start tracing — ${(err as Error).message}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
const page = await context.newPage();
|
||||
|
||||
const handle: BrowserHandle = { browser, context, page };
|
||||
const handle: BrowserHandle = { browser, context, page, tracing };
|
||||
this.runBrowsers.set(runId, handle);
|
||||
this.logger.log(`Run #${runId}: browser created`);
|
||||
return handle;
|
||||
@@ -440,6 +492,53 @@ export class ScenarioSchedulerService implements OnModuleInit {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Stops the run's Playwright trace and uploads it as a `trace.zip` run
|
||||
* artifact. In retain-on-failure mode, traces of runs that did not fail are
|
||||
* discarded.
|
||||
*/
|
||||
private async saveTrace(runId: string): Promise<void> {
|
||||
const handle = this.runBrowsers.get(runId);
|
||||
if (!handle?.tracing) return;
|
||||
handle.tracing = false;
|
||||
|
||||
const run = await this.runRepo.findOneBy({ id: runId }).catch(() => null);
|
||||
const traceMode = this.runTraceModes.get(runId) ?? this.defaultTraceMode;
|
||||
const keep = traceMode === TraceMode.On || run?.status === "fail";
|
||||
|
||||
let tmpDir: string | null = null;
|
||||
try {
|
||||
if (!keep) {
|
||||
await handle.context.tracing.stop();
|
||||
return;
|
||||
}
|
||||
tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), "liqa-trace-"));
|
||||
const tracePath = path.join(tmpDir, "trace.zip");
|
||||
await handle.context.tracing.stop({ path: tracePath });
|
||||
const trace = await fs.readFile(tracePath);
|
||||
await this.fileStorageService.createAndSaveRunArtifact(
|
||||
runId,
|
||||
trace,
|
||||
"trace.zip",
|
||||
"application/zip",
|
||||
);
|
||||
this.persistLog(
|
||||
runId,
|
||||
null,
|
||||
"log",
|
||||
"Playwright trace uploaded to run files (open with `npx playwright show-trace trace.zip` or https://trace.playwright.dev)",
|
||||
);
|
||||
} catch (err) {
|
||||
this.logger.warn(
|
||||
`Run #${runId}: failed to save trace — ${(err as Error).message}`,
|
||||
);
|
||||
} finally {
|
||||
if (tmpDir) {
|
||||
await fs.rm(tmpDir, { recursive: true, force: true }).catch(() => {});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ── Pass / fail helpers ────────────────────────────────────────────────────
|
||||
|
||||
private async passStepRun(
|
||||
@@ -453,6 +552,12 @@ export class ScenarioSchedulerService implements OnModuleInit {
|
||||
output !== null && output !== undefined ? JSON.stringify(output) : null;
|
||||
await this.runStepRepo.save(stepRun);
|
||||
this.logger.log(`StepRun #${stepRun.id} → pass`);
|
||||
this.persistLog(
|
||||
stepRun.runId,
|
||||
stepRun.id,
|
||||
"log",
|
||||
`Step ${stepRun.order} passed`,
|
||||
);
|
||||
|
||||
// Find the next waiting step in this run (next by order)
|
||||
const nextStep = await this.runStepRepo.findOne({
|
||||
@@ -489,6 +594,14 @@ export class ScenarioSchedulerService implements OnModuleInit {
|
||||
stepRun.description = description;
|
||||
await this.runStepRepo.save(stepRun);
|
||||
this.logger.log(`StepRun #${stepRun.id} → fail: ${description}`);
|
||||
this.persistLog(
|
||||
stepRun.runId,
|
||||
stepRun.id,
|
||||
"error",
|
||||
`Step ${stepRun.order} failed: ${description}`,
|
||||
);
|
||||
|
||||
await this.dumpPageOnFailure(stepRun);
|
||||
|
||||
// Cancel all remaining waiting/pending step runs in this run
|
||||
await this.runStepRepo
|
||||
@@ -509,4 +622,50 @@ export class ScenarioSchedulerService implements OnModuleInit {
|
||||
await this.runRepo.update(stepRun.runId, { status: "fail" });
|
||||
this.logger.log(`Run #${stepRun.runId} → fail`);
|
||||
}
|
||||
|
||||
// ── Page dump on failure ────────────────────────────────────────────────────
|
||||
|
||||
private async dumpPageOnFailure(
|
||||
stepRun: ScenarioRunStepEntity,
|
||||
): Promise<void> {
|
||||
const handle = this.runBrowsers.get(stepRun.runId);
|
||||
if (!handle) return; // no browser was ever opened for this run (e.g. setup error)
|
||||
|
||||
const namePrefix = `step-${stepRun.order}-failure`;
|
||||
|
||||
try {
|
||||
const screenshot = await handle.page.screenshot({ fullPage: true });
|
||||
await this.fileStorageService.createAndSaveRunArtifact(
|
||||
stepRun.runId,
|
||||
screenshot,
|
||||
`${namePrefix}.png`,
|
||||
"image/png",
|
||||
);
|
||||
} catch (err) {
|
||||
this.logger.warn(
|
||||
`StepRun #${stepRun.id}: failed to capture failure screenshot — ${(err as Error).message}`,
|
||||
);
|
||||
}
|
||||
|
||||
try {
|
||||
const html = await handle.page.content();
|
||||
await this.fileStorageService.createAndSaveRunArtifact(
|
||||
stepRun.runId,
|
||||
Buffer.from(html, "utf-8"),
|
||||
`${namePrefix}.html`,
|
||||
"text/html",
|
||||
);
|
||||
} catch (err) {
|
||||
this.logger.warn(
|
||||
`StepRun #${stepRun.id}: failed to capture failure page HTML — ${(err as Error).message}`,
|
||||
);
|
||||
}
|
||||
|
||||
this.persistLog(
|
||||
stepRun.runId,
|
||||
stepRun.id,
|
||||
"log",
|
||||
`Step ${stepRun.order} failed: page dump uploaded to run files`,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
import {
|
||||
Column,
|
||||
CreateDateColumn,
|
||||
Entity,
|
||||
JoinColumn,
|
||||
ManyToOne,
|
||||
PrimaryGeneratedColumn,
|
||||
Unique,
|
||||
} from "typeorm";
|
||||
import { ScenarioEntity } from "./scenario.entity";
|
||||
|
||||
/** A step as it was at a given scenario version. */
|
||||
export interface ScenarioStepSnapshot {
|
||||
/** Id of the live step this snapshot was taken from (may no longer exist). */
|
||||
id: string | null;
|
||||
order: number;
|
||||
title: string | null;
|
||||
execCode: string | null;
|
||||
timeoutSeconds: number | null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Immutable snapshot of a scenario's content at one version. The `scenarios`
|
||||
* and `scenario_steps` tables always hold the latest version.
|
||||
*/
|
||||
@Entity("scenario_versions")
|
||||
@Unique(["scenarioId", "version"])
|
||||
export class ScenarioVersionEntity {
|
||||
@PrimaryGeneratedColumn("uuid")
|
||||
id: string;
|
||||
|
||||
@Column("text")
|
||||
scenarioId: string;
|
||||
|
||||
@ManyToOne(() => ScenarioEntity, { onDelete: "CASCADE" })
|
||||
@JoinColumn({ name: "scenarioId" })
|
||||
scenario: ScenarioEntity;
|
||||
|
||||
@Column({ type: "int" })
|
||||
version: number;
|
||||
|
||||
@Column()
|
||||
name: string;
|
||||
|
||||
@Column("text", { nullable: true })
|
||||
description: string | null;
|
||||
|
||||
@Column({ type: "text", nullable: true })
|
||||
environmentId: string | null;
|
||||
|
||||
@Column({ type: "int", nullable: true })
|
||||
timeoutSeconds: number | null;
|
||||
|
||||
@Column("simple-json")
|
||||
steps: ScenarioStepSnapshot[];
|
||||
|
||||
@CreateDateColumn()
|
||||
createdAt: Date;
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import {
|
||||
Get,
|
||||
HttpCode,
|
||||
Param,
|
||||
ParseIntPipe,
|
||||
ParseUUIDPipe,
|
||||
Patch,
|
||||
Post,
|
||||
@@ -28,11 +29,15 @@ import { ExportEntity } from "./dto/scenario-export.dto";
|
||||
import { UpdateScenarioStepDto } from "./dto/update-scenario-step.dto";
|
||||
import { UpdateScenarioDto } from "./dto/update-scenario.dto";
|
||||
import { ScenarioService } from "./scenario.service";
|
||||
import { E2eExportService } from "./e2e-export.service";
|
||||
|
||||
@ApiTags("scenarios")
|
||||
@Controller("scenarios")
|
||||
export class ScenarioController {
|
||||
constructor(private readonly scenarioService: ScenarioService) {}
|
||||
constructor(
|
||||
private readonly scenarioService: ScenarioService,
|
||||
private readonly e2eExportService: E2eExportService,
|
||||
) {}
|
||||
|
||||
// ── Scenarios ─────────────────────────────────────────────────────────────
|
||||
|
||||
@@ -66,6 +71,13 @@ export class ScenarioController {
|
||||
return this.scenarioService.findAllRuns(query);
|
||||
}
|
||||
|
||||
@Get("run-defaults")
|
||||
@ApiOperation({ summary: "Get server-configured defaults for new runs" })
|
||||
@ApiResponse({ status: 200 })
|
||||
getRunDefaults() {
|
||||
return this.scenarioService.getRunDefaults();
|
||||
}
|
||||
|
||||
@Get(":id")
|
||||
@ApiOperation({ summary: "Get a scenario with its steps" })
|
||||
@ApiResponse({ status: 200 })
|
||||
@@ -94,6 +106,25 @@ export class ScenarioController {
|
||||
return this.scenarioService.remove(id);
|
||||
}
|
||||
|
||||
@Get(":id/versions")
|
||||
@ApiOperation({ summary: "List a scenario's versions, newest first" })
|
||||
@ApiResponse({ status: 200 })
|
||||
@ApiResponse({ status: 404, description: "Scenario not found" })
|
||||
listVersions(@Param("id", ParseUUIDPipe) id: string) {
|
||||
return this.scenarioService.listVersions(id);
|
||||
}
|
||||
|
||||
@Get(":id/versions/:version")
|
||||
@ApiOperation({ summary: "Get one version of a scenario, with its steps" })
|
||||
@ApiResponse({ status: 200 })
|
||||
@ApiResponse({ status: 404, description: "Scenario or version not found" })
|
||||
findVersion(
|
||||
@Param("id", ParseUUIDPipe) id: string,
|
||||
@Param("version", ParseIntPipe) version: number,
|
||||
) {
|
||||
return this.scenarioService.findVersion(id, version);
|
||||
}
|
||||
|
||||
@Get(":id/export")
|
||||
@ApiOperation({ summary: "Export a scenario as portable YAML" })
|
||||
@ApiResponse({ status: 200 })
|
||||
@@ -102,6 +133,8 @@ export class ScenarioController {
|
||||
@Param("id", ParseUUIDPipe) id: string,
|
||||
@Query("includeEnvironment") includeEnvironment: string,
|
||||
@Query("credentialIds") credentialIds: string | string[] | undefined,
|
||||
@Query("version", new ParseIntPipe({ optional: true }))
|
||||
version: number | undefined,
|
||||
@Res({ passthrough: true }) res: Response,
|
||||
) {
|
||||
const credIds: string[] = credentialIds
|
||||
@@ -112,6 +145,7 @@ export class ScenarioController {
|
||||
const entities = await this.scenarioService.exportScenario(id, {
|
||||
includeEnvironment: includeEnvironment === "true",
|
||||
credentialIds: credIds,
|
||||
version,
|
||||
});
|
||||
res.setHeader("Content-Type", "application/yaml; charset=utf-8");
|
||||
// Serialize as YAML stream: each entity separated by a comment header
|
||||
@@ -130,6 +164,23 @@ export class ScenarioController {
|
||||
return parts.join("\n");
|
||||
}
|
||||
|
||||
@Get(":id/export-e2e")
|
||||
@ApiOperation({
|
||||
summary: "Export a scenario as a standalone, plug-and-play Playwright e2e test (zip)",
|
||||
})
|
||||
@ApiResponse({ status: 200, description: "Zip archive" })
|
||||
@ApiResponse({ status: 404, description: "Scenario not found" })
|
||||
async exportE2eTest(
|
||||
@Param("id", ParseUUIDPipe) id: string,
|
||||
@Res() res: Response,
|
||||
) {
|
||||
const { filename, buffer } = await this.e2eExportService.buildE2eTestPackage(id);
|
||||
res.setHeader("Content-Type", "application/zip");
|
||||
res.setHeader("Content-Disposition", `attachment; filename="${filename}"`);
|
||||
res.setHeader("Content-Length", buffer.length);
|
||||
res.send(buffer);
|
||||
}
|
||||
|
||||
// ── Steps ─────────────────────────────────────────────────────────────────
|
||||
|
||||
@Post(":id/steps")
|
||||
@@ -178,6 +229,16 @@ export class ScenarioController {
|
||||
return this.scenarioService.removeStep(id, stepId);
|
||||
}
|
||||
|
||||
@Get(":id/used-snippets")
|
||||
@ApiOperation({
|
||||
summary: "List snippets referenced (directly or transitively) by this scenario's steps",
|
||||
})
|
||||
@ApiResponse({ status: 200 })
|
||||
@ApiResponse({ status: 404, description: "Scenario not found" })
|
||||
getUsedSnippets(@Param("id", ParseUUIDPipe) id: string) {
|
||||
return this.scenarioService.getUsedSnippets(id);
|
||||
}
|
||||
|
||||
// ── Credentials ───────────────────────────────────────────────────────────
|
||||
|
||||
@Get(":id/credentials")
|
||||
@@ -245,6 +306,8 @@ export class ScenarioController {
|
||||
id,
|
||||
dto.environmentId,
|
||||
dto.saveSession,
|
||||
dto.traceMode,
|
||||
dto.version,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -260,6 +323,29 @@ export class ScenarioController {
|
||||
return this.scenarioService.findRun(id, runId, q);
|
||||
}
|
||||
|
||||
@Get(":id/run/:runId/logs/export")
|
||||
@ApiOperation({ summary: "Export run logs as CSV or Markdown" })
|
||||
@ApiResponse({ status: 200 })
|
||||
@ApiResponse({ status: 404, description: "Scenario or run not found" })
|
||||
async exportRunLogs(
|
||||
@Param("id", ParseUUIDPipe) id: string,
|
||||
@Param("runId", ParseUUIDPipe) runId: string,
|
||||
@Query("format") format: string | undefined,
|
||||
@Res({ passthrough: true }) res: Response,
|
||||
) {
|
||||
const fmt = format === "csv" ? "csv" : "md";
|
||||
const content = await this.scenarioService.exportRunLogs(id, runId, fmt);
|
||||
const contentType =
|
||||
fmt === "csv" ? "text/csv; charset=utf-8" : "text/markdown; charset=utf-8";
|
||||
const ext = fmt === "csv" ? "csv" : "md";
|
||||
res.setHeader("Content-Type", contentType);
|
||||
res.setHeader(
|
||||
"Content-Disposition",
|
||||
`attachment; filename="run-${runId}-logs.${ext}"`,
|
||||
);
|
||||
return content;
|
||||
}
|
||||
|
||||
@Post(":id/run/:runId/wait")
|
||||
@HttpCode(200)
|
||||
@ApiOperation({
|
||||
|
||||
@@ -29,6 +29,10 @@ export class ScenarioEntity {
|
||||
@Column({ type: "int", nullable: true })
|
||||
timeoutSeconds: number | null;
|
||||
|
||||
/** Latest version number; incremented whenever the scenario content changes. */
|
||||
@Column({ type: "int", default: 1 })
|
||||
version: number;
|
||||
|
||||
@ManyToOne(() => EnvironmentEntity, { nullable: true, onDelete: "SET NULL", eager: false })
|
||||
@JoinColumn({ name: "environmentId" })
|
||||
environment: EnvironmentEntity | null;
|
||||
|
||||
@@ -14,16 +14,19 @@ import { ScenarioRunLogEntity } from "./scenario-run-log.entity";
|
||||
import { ScenarioRunStepEntity } from "./scenario-run-step.entity";
|
||||
import { ScenarioRunEntity } from "./scenario-run.entity";
|
||||
import { ScenarioSchedulerService } from "./scenario-scheduler.service";
|
||||
import { ScenarioVersionEntity } from "./scenario-version.entity";
|
||||
import { ScenarioStepEntity } from "./scenario-step.entity";
|
||||
import { ScenarioController } from "./scenario.controller";
|
||||
import { ScenarioEntity } from "./scenario.entity";
|
||||
import { ScenarioService } from "./scenario.service";
|
||||
import { E2eExportService } from "./e2e-export.service";
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
TypeOrmModule.forFeature([
|
||||
ScenarioEntity,
|
||||
ScenarioStepEntity,
|
||||
ScenarioVersionEntity,
|
||||
ScenarioRunEntity,
|
||||
ScenarioRunStepEntity,
|
||||
ScenarioRunLogEntity,
|
||||
@@ -40,7 +43,7 @@ import { ScenarioService } from "./scenario.service";
|
||||
FileModule,
|
||||
],
|
||||
controllers: [ScenarioController],
|
||||
providers: [ScenarioService, ScenarioSchedulerService],
|
||||
exports: [ScenarioService],
|
||||
providers: [ScenarioService, ScenarioSchedulerService, E2eExportService],
|
||||
exports: [ScenarioService, E2eExportService],
|
||||
})
|
||||
export class ScenarioModule {}
|
||||
@@ -3,7 +3,9 @@ import {
|
||||
ConflictException,
|
||||
Injectable,
|
||||
NotFoundException,
|
||||
OnModuleInit,
|
||||
} from "@nestjs/common";
|
||||
import { ConfigService } from "@nestjs/config";
|
||||
import { InjectRepository } from "@nestjs/typeorm";
|
||||
import * as fs from "fs/promises";
|
||||
import * as path from "path";
|
||||
@@ -12,11 +14,18 @@ import {
|
||||
PaginatedResult,
|
||||
PaginationQueryDto,
|
||||
} from "../common/dto/pagination.dto";
|
||||
import {
|
||||
parseSnippetRef,
|
||||
resolveUsedSnippetAliases,
|
||||
} from "../common/snippet-usage";
|
||||
import type { AppConfig, TraceMode } from "../config/app.config";
|
||||
import { CredentialEntity } from "../credential/credential.entity";
|
||||
import { EnvironmentEntity } from "../environment/environment.entity";
|
||||
import { FileStorageService } from "../file/file-storage.service";
|
||||
import { ScenarioFileEntity } from "../file/scenario-file.entity";
|
||||
import { ScenarioRunFileEntity } from "../file/scenario-run-file.entity";
|
||||
import { SnippetEntity } from "../snippet/snippet.entity";
|
||||
import { SnippetService } from "../snippet/snippet.service";
|
||||
import { AddScenarioCredentialDto } from "./dto/add-scenario-credential.dto";
|
||||
import { CreateScenarioStepDto } from "./dto/create-scenario-step.dto";
|
||||
import { CreateScenarioDto } from "./dto/create-scenario.dto";
|
||||
@@ -34,6 +43,10 @@ import { ScenarioRunLogEntity } from "./scenario-run-log.entity";
|
||||
import { ScenarioRunStepEntity } from "./scenario-run-step.entity";
|
||||
import { ScenarioRunEntity } from "./scenario-run.entity";
|
||||
import { ScenarioStepEntity } from "./scenario-step.entity";
|
||||
import {
|
||||
ScenarioStepSnapshot,
|
||||
ScenarioVersionEntity,
|
||||
} from "./scenario-version.entity";
|
||||
import { ScenarioEntity } from "./scenario.entity";
|
||||
import { Response } from "express";
|
||||
import type { File as MulterFile } from "multer";
|
||||
@@ -41,13 +54,49 @@ import type { File as MulterFile } from "multer";
|
||||
export { PaginatedResult } from "../common/dto/pagination.dto";
|
||||
export type ScenarioOrderBy = "id" | "name" | "createdAt" | "updatedAt";
|
||||
|
||||
/** The versioned content of a scenario. */
|
||||
type ScenarioContent = Pick<
|
||||
ScenarioVersionEntity,
|
||||
"name" | "description" | "environmentId" | "timeoutSeconds" | "steps"
|
||||
>;
|
||||
|
||||
function contentKey(c: ScenarioContent): string {
|
||||
return JSON.stringify([
|
||||
c.name,
|
||||
c.description ?? null,
|
||||
c.environmentId ?? null,
|
||||
c.timeoutSeconds ?? null,
|
||||
// Step ids are not content: re-created steps with equal content are equal
|
||||
c.steps.map((s) => [s.order, s.title, s.execCode, s.timeoutSeconds]),
|
||||
]);
|
||||
}
|
||||
|
||||
function stepsSnapshot(steps: ScenarioStepEntity[]): ScenarioStepSnapshot[] {
|
||||
return [...steps]
|
||||
.sort((a, b) => a.order - b.order)
|
||||
.map((s) => ({
|
||||
id: s.id,
|
||||
order: s.order,
|
||||
title: s.title,
|
||||
execCode: s.execCode,
|
||||
timeoutSeconds: s.timeoutSeconds,
|
||||
}));
|
||||
}
|
||||
|
||||
export type UsedSnippet = SnippetEntity & {
|
||||
/** Version pinned via `runSnippet("alias@N")`, or null for the latest. */
|
||||
pinnedVersion: number | null;
|
||||
};
|
||||
|
||||
@Injectable()
|
||||
export class ScenarioService {
|
||||
export class ScenarioService implements OnModuleInit {
|
||||
constructor(
|
||||
@InjectRepository(ScenarioEntity)
|
||||
private readonly scenarioRepo: Repository<ScenarioEntity>,
|
||||
@InjectRepository(ScenarioStepEntity)
|
||||
private readonly stepRepo: Repository<ScenarioStepEntity>,
|
||||
@InjectRepository(ScenarioVersionEntity)
|
||||
private readonly versionRepo: Repository<ScenarioVersionEntity>,
|
||||
@InjectRepository(ScenarioRunEntity)
|
||||
private readonly runRepo: Repository<ScenarioRunEntity>,
|
||||
@InjectRepository(ScenarioRunStepEntity)
|
||||
@@ -65,12 +114,97 @@ export class ScenarioService {
|
||||
@InjectRepository(ScenarioRunFileEntity)
|
||||
private readonly scenarioRunFileRepo: Repository<ScenarioRunFileEntity>,
|
||||
private readonly fileStorageService: FileStorageService,
|
||||
private readonly snippetService: SnippetService,
|
||||
private readonly configService: ConfigService<AppConfig, true>,
|
||||
) {}
|
||||
|
||||
async onModuleInit(): Promise<void> {
|
||||
await this.backfillVersions();
|
||||
await this.backfillRunStepSnapshots();
|
||||
}
|
||||
|
||||
/** Records the current content of scenarios that have no row for their current version yet. */
|
||||
private async backfillVersions(): Promise<void> {
|
||||
const scenarios = await this.scenarioRepo.find({ select: { id: true } });
|
||||
for (const { id } of scenarios) await this.commitVersion(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Run steps created before versioning point at the live step instead of
|
||||
* holding a copy of it; copy the live step content into them.
|
||||
*/
|
||||
private async backfillRunStepSnapshots(): Promise<void> {
|
||||
await this.runStepRepo.query(`
|
||||
UPDATE scenario_run_steps SET
|
||||
title = (SELECT title FROM scenario_steps WHERE id = scenarioStepId),
|
||||
execCode = (SELECT execCode FROM scenario_steps WHERE id = scenarioStepId),
|
||||
timeoutSeconds = (SELECT timeoutSeconds FROM scenario_steps WHERE id = scenarioStepId)
|
||||
WHERE title IS NULL AND execCode IS NULL AND timeoutSeconds IS NULL
|
||||
AND scenarioStepId IS NOT NULL
|
||||
AND runId IN (SELECT id FROM scenario_runs WHERE scenarioVersion IS NULL)
|
||||
`);
|
||||
}
|
||||
|
||||
// ── Versions ──────────────────────────────────────────────────────────────
|
||||
|
||||
/**
|
||||
* Snapshots the scenario's current content. The first snapshot is stored as
|
||||
* the scenario's current version; later ones bump the version, unless the
|
||||
* content is unchanged since the latest snapshot.
|
||||
*/
|
||||
private async commitVersion(scenarioId: string): Promise<void> {
|
||||
const scenario = await this.findOne(scenarioId);
|
||||
const content: ScenarioContent = {
|
||||
name: scenario.name,
|
||||
description: scenario.description,
|
||||
environmentId: scenario.environmentId,
|
||||
timeoutSeconds: scenario.timeoutSeconds,
|
||||
steps: stepsSnapshot(scenario.steps),
|
||||
};
|
||||
const latest = await this.versionRepo.findOneBy({
|
||||
scenarioId,
|
||||
version: scenario.version,
|
||||
});
|
||||
if (latest && contentKey(latest) === contentKey(content)) return;
|
||||
const version = latest ? scenario.version + 1 : scenario.version;
|
||||
if (version !== scenario.version) {
|
||||
await this.scenarioRepo.update(scenarioId, { version });
|
||||
}
|
||||
await this.versionRepo.save(
|
||||
this.versionRepo.create({ scenarioId, version, ...content }),
|
||||
);
|
||||
}
|
||||
|
||||
async listVersions(scenarioId: string): Promise<ScenarioVersionEntity[]> {
|
||||
await this.findOne(scenarioId); // 404 guard
|
||||
return this.versionRepo.find({
|
||||
where: { scenarioId },
|
||||
order: { version: "DESC" },
|
||||
});
|
||||
}
|
||||
|
||||
async findVersion(
|
||||
scenarioId: string,
|
||||
version: number,
|
||||
): Promise<ScenarioVersionEntity> {
|
||||
await this.findOne(scenarioId); // 404 guard
|
||||
const row = await this.versionRepo.findOneBy({ scenarioId, version });
|
||||
if (!row) {
|
||||
throw new NotFoundException(
|
||||
`Scenario ${scenarioId} has no version ${version}`,
|
||||
);
|
||||
}
|
||||
return row;
|
||||
}
|
||||
|
||||
// ── Scenarios ─────────────────────────────────────────────────────────────
|
||||
|
||||
create(dto: CreateScenarioDto): Promise<ScenarioEntity> {
|
||||
return this.scenarioRepo.save(this.scenarioRepo.create(dto));
|
||||
async create(dto: CreateScenarioDto): Promise<ScenarioEntity> {
|
||||
const scenario = await this.scenarioRepo.save(
|
||||
this.scenarioRepo.create({ ...dto, version: 1 }),
|
||||
);
|
||||
await this.commitVersion(scenario.id);
|
||||
return this.findOne(scenario.id);
|
||||
}
|
||||
|
||||
async findAll(
|
||||
@@ -138,7 +272,9 @@ export class ScenarioService {
|
||||
async update(id: string, dto: UpdateScenarioDto): Promise<ScenarioEntity> {
|
||||
const scenario = await this.findOne(id);
|
||||
Object.assign(scenario, dto);
|
||||
return this.scenarioRepo.save(scenario);
|
||||
await this.scenarioRepo.save(scenario);
|
||||
await this.commitVersion(id);
|
||||
return this.findOne(id);
|
||||
}
|
||||
|
||||
async remove(id: string): Promise<void> {
|
||||
@@ -178,6 +314,7 @@ export class ScenarioService {
|
||||
}),
|
||||
);
|
||||
await this.normalizeStepOrder(scenarioId);
|
||||
await this.commitVersion(scenarioId);
|
||||
return this.findStep(scenarioId, created.id);
|
||||
}
|
||||
|
||||
@@ -236,6 +373,7 @@ export class ScenarioService {
|
||||
await this.normalizeStepOrder(scenarioId);
|
||||
}
|
||||
|
||||
await this.commitVersion(scenarioId);
|
||||
return this.findStep(scenarioId, stepId);
|
||||
}
|
||||
|
||||
@@ -243,6 +381,7 @@ export class ScenarioService {
|
||||
await this.findStep(scenarioId, stepId);
|
||||
await this.stepRepo.delete(stepId);
|
||||
await this.normalizeStepOrder(scenarioId);
|
||||
await this.commitVersion(scenarioId);
|
||||
}
|
||||
|
||||
// ── Scenario Credentials ──────────────────────────────────────────────────
|
||||
@@ -332,6 +471,28 @@ export class ScenarioService {
|
||||
return map;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the snippets referenced (directly, or transitively via other snippets)
|
||||
* by this scenario's step code, in discovery order - for linking to them from the UI.
|
||||
*/
|
||||
async getUsedSnippets(scenarioId: string): Promise<UsedSnippet[]> {
|
||||
const scenario = await this.findOne(scenarioId);
|
||||
const snippetMap = await this.snippetService.buildSnippetMap();
|
||||
const usedRefs = resolveUsedSnippetAliases(
|
||||
scenario.steps.map((s) => s.execCode ?? ""),
|
||||
snippetMap,
|
||||
).map(parseSnippetRef);
|
||||
if (usedRefs.length === 0) return [];
|
||||
const snippets = await this.snippetService.findByAliases([
|
||||
...new Set(usedRefs.map((r) => r.alias)),
|
||||
]);
|
||||
const byAlias = new Map(snippets.map((s) => [s.alias, s]));
|
||||
return usedRefs.flatMap(({ alias, version }) => {
|
||||
const snippet = byAlias.get(alias);
|
||||
return snippet ? [{ ...snippet, pinnedVersion: version }] : [];
|
||||
});
|
||||
}
|
||||
|
||||
// ── Runs ──────────────────────────────────────────────────────────────────
|
||||
|
||||
async findRuns(
|
||||
@@ -402,11 +563,49 @@ export class ScenarioService {
|
||||
);
|
||||
const logs = await this.runLogRepo.find({
|
||||
where: q?.trim() ? { runId, message: Like(`%${q.trim()}%`) } : { runId },
|
||||
order: { createdAt: "ASC" },
|
||||
order: { seq: "ASC", createdAt: "ASC" },
|
||||
});
|
||||
return Object.assign(run, { logs });
|
||||
}
|
||||
|
||||
async exportRunLogs(
|
||||
scenarioId: string,
|
||||
runId: string,
|
||||
format: "csv" | "md",
|
||||
): Promise<string> {
|
||||
await this.findOne(scenarioId); // 404 guard
|
||||
const run = await this.runRepo.findOne({
|
||||
where: { id: runId, scenarioId },
|
||||
});
|
||||
if (!run)
|
||||
throw new NotFoundException(
|
||||
`Run ${runId} not found in scenario ${scenarioId}`,
|
||||
);
|
||||
const logs = await this.runLogRepo.find({
|
||||
where: { runId },
|
||||
order: { seq: "ASC", createdAt: "ASC" },
|
||||
});
|
||||
|
||||
if (format === "csv") {
|
||||
const escapeCsv = (value: string): string =>
|
||||
/[",\n]/.test(value) ? `"${value.replace(/"/g, '""')}"` : value;
|
||||
const rows = [
|
||||
["Timestamp", "Level", "Message"].map(escapeCsv).join(","),
|
||||
...logs.map((l) =>
|
||||
[l.createdAt.toISOString(), l.level, l.message]
|
||||
.map((v) => escapeCsv(String(v)))
|
||||
.join(","),
|
||||
),
|
||||
];
|
||||
return rows.join("\n");
|
||||
}
|
||||
|
||||
const sections = logs.map(
|
||||
(l) => `## [${l.level}] ${l.createdAt.toISOString()}\n\n${l.message}`,
|
||||
);
|
||||
return [`# Run ${runId} logs`, ...sections].join("\n\n");
|
||||
}
|
||||
|
||||
async waitForRun(
|
||||
scenarioId: string,
|
||||
runId: string,
|
||||
@@ -427,12 +626,22 @@ export class ScenarioService {
|
||||
return this.findRun(scenarioId, runId);
|
||||
}
|
||||
|
||||
getRunDefaults(): { traceMode: TraceMode } {
|
||||
return { traceMode: this.configService.get("PLAYWRIGHT_TRACE_MODE") };
|
||||
}
|
||||
|
||||
async createRun(
|
||||
scenarioId: string,
|
||||
environmentId: string,
|
||||
saveSession = false,
|
||||
traceMode?: TraceMode,
|
||||
version?: number,
|
||||
): Promise<ScenarioRunEntity> {
|
||||
const scenario = await this.findOne(scenarioId);
|
||||
const scenarioVersion = await this.findVersion(
|
||||
scenarioId,
|
||||
version ?? scenario.version,
|
||||
);
|
||||
const environment = await this.environmentRepo.findOneBy({
|
||||
id: environmentId,
|
||||
});
|
||||
@@ -446,14 +655,20 @@ export class ScenarioService {
|
||||
environmentId,
|
||||
status: "pending",
|
||||
saveSession,
|
||||
traceMode: traceMode ?? this.getRunDefaults().traceMode,
|
||||
scenarioVersion: scenarioVersion.version,
|
||||
}),
|
||||
);
|
||||
|
||||
const stepRuns = scenario.steps.map((step, index) =>
|
||||
const liveStepIds = new Set(scenario.steps.map((s) => s.id));
|
||||
const stepRuns = scenarioVersion.steps.map((step, index) =>
|
||||
this.runStepRepo.create({
|
||||
runId: run.id,
|
||||
scenarioStepId: step.id,
|
||||
scenarioStepId: step.id && liveStepIds.has(step.id) ? step.id : null,
|
||||
order: step.order,
|
||||
title: step.title,
|
||||
execCode: step.execCode,
|
||||
timeoutSeconds: step.timeoutSeconds,
|
||||
status: index === 0 ? "pending" : "waiting",
|
||||
description: null,
|
||||
}),
|
||||
@@ -472,9 +687,18 @@ export class ScenarioService {
|
||||
|
||||
async exportScenario(
|
||||
id: string,
|
||||
options: { includeEnvironment: boolean; credentialIds: string[] },
|
||||
options: {
|
||||
includeEnvironment: boolean;
|
||||
credentialIds: string[];
|
||||
/** Version to export; defaults to the latest. */
|
||||
version?: number;
|
||||
},
|
||||
): Promise<ExportEntity[]> {
|
||||
const scenario = await this.findOne(id);
|
||||
const content = await this.findVersion(
|
||||
id,
|
||||
options.version ?? scenario.version,
|
||||
);
|
||||
const entities: ExportEntity[] = [];
|
||||
|
||||
// Include environment entity if requested and linked
|
||||
@@ -521,13 +745,16 @@ export class ScenarioService {
|
||||
const scenarioDto: ScenarioExportDto = {
|
||||
kind: "scenario",
|
||||
id: scenario.id,
|
||||
name: scenario.name,
|
||||
description: scenario.description ?? undefined,
|
||||
environmentId: scenario.environmentId ?? undefined,
|
||||
version: content.version,
|
||||
name: content.name,
|
||||
description: content.description ?? undefined,
|
||||
environmentId: content.environmentId ?? undefined,
|
||||
timeoutSeconds: content.timeoutSeconds ?? undefined,
|
||||
credentials: credentialMappings.length > 0 ? credentialMappings : undefined,
|
||||
steps: scenario.steps.map((s) => ({
|
||||
steps: content.steps.map((s) => ({
|
||||
title: s.title,
|
||||
execCode: s.execCode,
|
||||
...(s.timeoutSeconds != null ? { timeoutSeconds: s.timeoutSeconds } : {}),
|
||||
})),
|
||||
};
|
||||
entities.push(scenarioDto);
|
||||
@@ -608,46 +835,72 @@ export class ScenarioService {
|
||||
throw new BadRequestException("steps must be an array");
|
||||
}
|
||||
|
||||
if (!Number.isInteger(scenarioDto.version) || scenarioDto.version < 1) {
|
||||
throw new BadRequestException("version must be a positive integer");
|
||||
}
|
||||
|
||||
// Restore the exported version: upsert by id + version. An existing
|
||||
// version is left untouched; a new one is stored under its number and
|
||||
// becomes the latest when it is higher than the current latest.
|
||||
const dto = scenarioDto;
|
||||
const content: ScenarioContent = {
|
||||
name: dto.name,
|
||||
description: dto.description ?? null,
|
||||
environmentId: dto.environmentId ?? null,
|
||||
timeoutSeconds: dto.timeoutSeconds ?? null,
|
||||
steps: dto.steps.map((s, index) => ({
|
||||
id: null,
|
||||
order: index + 1,
|
||||
title: s.title ?? null,
|
||||
execCode: s.execCode ?? null,
|
||||
timeoutSeconds: s.timeoutSeconds ?? null,
|
||||
})),
|
||||
};
|
||||
const existing = dto.id
|
||||
? await this.scenarioRepo.findOneBy({ id: dto.id })
|
||||
: null;
|
||||
let scenario: ScenarioEntity;
|
||||
if (dto.id) {
|
||||
const existing = await this.scenarioRepo.findOneBy({ id: dto.id });
|
||||
if (existing) {
|
||||
existing.name = dto.name;
|
||||
existing.description = dto.description ?? null;
|
||||
existing.environmentId = dto.environmentId ?? existing.environmentId;
|
||||
scenario = await this.scenarioRepo.save(existing);
|
||||
await this.stepRepo.delete({ scenarioId: scenario.id });
|
||||
} else {
|
||||
scenario = await this.scenarioRepo.save(
|
||||
this.scenarioRepo.create({
|
||||
id: dto.id,
|
||||
name: dto.name,
|
||||
description: dto.description ?? null,
|
||||
environmentId: dto.environmentId ?? null,
|
||||
}),
|
||||
);
|
||||
}
|
||||
} else {
|
||||
if (!existing) {
|
||||
scenario = await this.scenarioRepo.save(
|
||||
this.scenarioRepo.create({
|
||||
name: dto.name,
|
||||
description: dto.description ?? null,
|
||||
environmentId: dto.environmentId ?? null,
|
||||
...(dto.id ? { id: dto.id } : {}),
|
||||
name: content.name,
|
||||
description: content.description,
|
||||
environmentId: content.environmentId,
|
||||
timeoutSeconds: content.timeoutSeconds,
|
||||
version: dto.version,
|
||||
}),
|
||||
);
|
||||
}
|
||||
if (dto.steps.length > 0) {
|
||||
const steps = dto.steps.map((s, index) =>
|
||||
this.stepRepo.create({
|
||||
scenarioId: scenario.id,
|
||||
order: index,
|
||||
title: s.title ?? null,
|
||||
execCode: s.execCode ?? null,
|
||||
}),
|
||||
);
|
||||
await this.stepRepo.save(steps);
|
||||
await this.normalizeStepOrder(scenario.id);
|
||||
await this.replaceSteps(scenario.id, content.steps);
|
||||
await this.commitVersion(scenario.id);
|
||||
} else {
|
||||
scenario = existing;
|
||||
const hasVersion = await this.versionRepo.existsBy({
|
||||
scenarioId: existing.id,
|
||||
version: dto.version,
|
||||
});
|
||||
if (!hasVersion) {
|
||||
if (dto.version > existing.version) {
|
||||
Object.assign(existing, {
|
||||
name: content.name,
|
||||
description: content.description,
|
||||
environmentId: content.environmentId ?? existing.environmentId,
|
||||
timeoutSeconds: content.timeoutSeconds,
|
||||
version: dto.version,
|
||||
});
|
||||
scenario = await this.scenarioRepo.save(existing);
|
||||
await this.replaceSteps(scenario.id, content.steps);
|
||||
await this.commitVersion(scenario.id);
|
||||
} else {
|
||||
await this.versionRepo.save(
|
||||
this.versionRepo.create({
|
||||
scenarioId: existing.id,
|
||||
version: dto.version,
|
||||
...content,
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
// Restore credential alias mappings
|
||||
if (dto.credentials && dto.credentials.length > 0) {
|
||||
@@ -664,6 +917,26 @@ export class ScenarioService {
|
||||
return this.findOne(scenario.id);
|
||||
}
|
||||
|
||||
private async replaceSteps(
|
||||
scenarioId: string,
|
||||
steps: ScenarioStepSnapshot[],
|
||||
): Promise<void> {
|
||||
await this.stepRepo.delete({ scenarioId });
|
||||
if (steps.length === 0) return;
|
||||
await this.stepRepo.save(
|
||||
steps.map((s) =>
|
||||
this.stepRepo.create({
|
||||
scenarioId,
|
||||
order: s.order,
|
||||
title: s.title,
|
||||
execCode: s.execCode,
|
||||
timeoutSeconds: s.timeoutSeconds,
|
||||
}),
|
||||
),
|
||||
);
|
||||
await this.normalizeStepOrder(scenarioId);
|
||||
}
|
||||
|
||||
// ── Files ─────────────────────────────────────────────────────────────────
|
||||
|
||||
async uploadFile(
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import { ApiProperty, ApiPropertyOptional } from "@nestjs/swagger";
|
||||
import {
|
||||
IsIn,
|
||||
IsInt,
|
||||
Min,
|
||||
IsNotEmpty,
|
||||
IsOptional,
|
||||
IsString,
|
||||
@@ -18,6 +20,11 @@ export class SnippetExportDto {
|
||||
@IsUUID()
|
||||
id?: string;
|
||||
|
||||
@ApiProperty({ description: "Snippet version this export holds" })
|
||||
@IsInt()
|
||||
@Min(1)
|
||||
version: number;
|
||||
|
||||
@ApiPropertyOptional()
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
import {
|
||||
Column,
|
||||
CreateDateColumn,
|
||||
Entity,
|
||||
JoinColumn,
|
||||
ManyToOne,
|
||||
PrimaryGeneratedColumn,
|
||||
Unique,
|
||||
} from "typeorm";
|
||||
import { SnippetEntity } from "./snippet.entity";
|
||||
|
||||
/**
|
||||
* Immutable snapshot of a snippet at one version. The `snippets` table always
|
||||
* holds the latest version. Step code pins a version with
|
||||
* `runSnippet("alias@<version>")`.
|
||||
*/
|
||||
@Entity("snippet_versions")
|
||||
@Unique(["snippetId", "version"])
|
||||
export class SnippetVersionEntity {
|
||||
@PrimaryGeneratedColumn("uuid")
|
||||
id: string;
|
||||
|
||||
@Column("text")
|
||||
snippetId: string;
|
||||
|
||||
@ManyToOne(() => SnippetEntity, { onDelete: "CASCADE" })
|
||||
@JoinColumn({ name: "snippetId" })
|
||||
snippet: SnippetEntity;
|
||||
|
||||
@Column({ type: "int" })
|
||||
version: number;
|
||||
|
||||
@Column()
|
||||
alias: string;
|
||||
|
||||
@Column({ default: "" })
|
||||
title: string;
|
||||
|
||||
@Column("text", { nullable: true })
|
||||
description: string | null;
|
||||
|
||||
@Column("text")
|
||||
code: string;
|
||||
|
||||
@CreateDateColumn()
|
||||
createdAt: Date;
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import {
|
||||
Get,
|
||||
HttpCode,
|
||||
Param,
|
||||
ParseIntPipe,
|
||||
ParseUUIDPipe,
|
||||
Patch,
|
||||
Post,
|
||||
@@ -48,9 +49,31 @@ export class SnippetController {
|
||||
@ApiOperation({ summary: "Export a snippet as a plain object" })
|
||||
@ApiResponse({ status: 200, description: "Snippet export payload" })
|
||||
@ApiResponse({ status: 404, description: "Snippet not found" })
|
||||
async exportSnippet(@Param("id", ParseUUIDPipe) id: string) {
|
||||
async exportSnippet(
|
||||
@Param("id", ParseUUIDPipe) id: string,
|
||||
@Query("version", new ParseIntPipe({ optional: true })) version?: number,
|
||||
) {
|
||||
const snippet = await this.snippetService.findOne(id);
|
||||
return this.snippetService.exportSnippet(snippet);
|
||||
return this.snippetService.exportSnippet(snippet, version);
|
||||
}
|
||||
|
||||
@Get(":id/versions")
|
||||
@ApiOperation({ summary: "List a snippet's versions, newest first" })
|
||||
@ApiResponse({ status: 200, description: "Snippet versions" })
|
||||
@ApiResponse({ status: 404, description: "Snippet not found" })
|
||||
listVersions(@Param("id", ParseUUIDPipe) id: string) {
|
||||
return this.snippetService.listVersions(id);
|
||||
}
|
||||
|
||||
@Get(":id/versions/:version")
|
||||
@ApiOperation({ summary: "Get one version of a snippet" })
|
||||
@ApiResponse({ status: 200, description: "Snippet version" })
|
||||
@ApiResponse({ status: 404, description: "Snippet or version not found" })
|
||||
findVersion(
|
||||
@Param("id", ParseUUIDPipe) id: string,
|
||||
@Param("version", ParseIntPipe) version: number,
|
||||
) {
|
||||
return this.snippetService.findVersion(id, version);
|
||||
}
|
||||
|
||||
@Get(":id")
|
||||
|
||||
@@ -30,6 +30,10 @@ export class SnippetEntity {
|
||||
@Column("text")
|
||||
code: string;
|
||||
|
||||
/** Latest version number; incremented whenever the snippet changes. */
|
||||
@Column({ type: "int", default: 1 })
|
||||
version: number;
|
||||
|
||||
@CreateDateColumn()
|
||||
createdAt: Date;
|
||||
|
||||
|
||||
@@ -2,10 +2,11 @@ import { Module } from "@nestjs/common";
|
||||
import { TypeOrmModule } from "@nestjs/typeorm";
|
||||
import { SnippetController } from "./snippet.controller";
|
||||
import { SnippetEntity } from "./snippet.entity";
|
||||
import { SnippetVersionEntity } from "./snippet-version.entity";
|
||||
import { SnippetService } from "./snippet.service";
|
||||
|
||||
@Module({
|
||||
imports: [TypeOrmModule.forFeature([SnippetEntity])],
|
||||
imports: [TypeOrmModule.forFeature([SnippetEntity, SnippetVersionEntity])],
|
||||
controllers: [SnippetController],
|
||||
providers: [SnippetService],
|
||||
exports: [SnippetService],
|
||||
|
||||
@@ -5,7 +5,7 @@ import {
|
||||
OnModuleInit,
|
||||
} from "@nestjs/common";
|
||||
import { InjectRepository } from "@nestjs/typeorm";
|
||||
import { Repository } from "typeorm";
|
||||
import { In, Not, Repository } from "typeorm";
|
||||
import {
|
||||
PaginatedResult,
|
||||
PaginationQueryDto,
|
||||
@@ -13,8 +13,20 @@ import {
|
||||
import { CreateSnippetDto } from "./dto/create-snippet.dto";
|
||||
import { SnippetExportDto } from "./dto/snippet-export.dto";
|
||||
import { UpdateSnippetDto } from "./dto/update-snippet.dto";
|
||||
import { SnippetVersionEntity } from "./snippet-version.entity";
|
||||
import { SnippetEntity } from "./snippet.entity";
|
||||
|
||||
type SnippetContent = Pick<
|
||||
SnippetEntity,
|
||||
"alias" | "title" | "description" | "code"
|
||||
>;
|
||||
|
||||
const sameContent = (a: SnippetContent, b: SnippetContent): boolean =>
|
||||
a.alias === b.alias &&
|
||||
a.title === b.title &&
|
||||
(a.description ?? null) === (b.description ?? null) &&
|
||||
a.code === b.code;
|
||||
|
||||
export type SnippetOrderBy =
|
||||
| "id"
|
||||
| "alias"
|
||||
@@ -27,6 +39,8 @@ export class SnippetService implements OnModuleInit {
|
||||
constructor(
|
||||
@InjectRepository(SnippetEntity)
|
||||
private readonly repo: Repository<SnippetEntity>,
|
||||
@InjectRepository(SnippetVersionEntity)
|
||||
private readonly versionRepo: Repository<SnippetVersionEntity>,
|
||||
) {}
|
||||
|
||||
async onModuleInit(): Promise<void> {
|
||||
@@ -47,6 +61,32 @@ export class SnippetService implements OnModuleInit {
|
||||
"UPDATE snippets SET title = COALESCE(alias, '') WHERE title IS NULL OR title = ''",
|
||||
);
|
||||
}
|
||||
await this.backfillVersions();
|
||||
}
|
||||
|
||||
/** Records the current content of snippets that have no row for their current version yet. */
|
||||
private async backfillVersions(): Promise<void> {
|
||||
const snippets = await this.repo.find();
|
||||
for (const snippet of snippets) {
|
||||
const exists = await this.versionRepo.existsBy({
|
||||
snippetId: snippet.id,
|
||||
version: snippet.version,
|
||||
});
|
||||
if (!exists) await this.recordVersion(snippet);
|
||||
}
|
||||
}
|
||||
|
||||
private recordVersion(snippet: SnippetEntity): Promise<SnippetVersionEntity> {
|
||||
return this.versionRepo.save(
|
||||
this.versionRepo.create({
|
||||
snippetId: snippet.id,
|
||||
version: snippet.version,
|
||||
alias: snippet.alias,
|
||||
title: snippet.title,
|
||||
description: snippet.description,
|
||||
code: snippet.code,
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
async create(dto: CreateSnippetDto): Promise<SnippetEntity> {
|
||||
@@ -56,14 +96,17 @@ export class SnippetService implements OnModuleInit {
|
||||
`Snippet alias "${dto.alias}" already exists`,
|
||||
);
|
||||
}
|
||||
return this.repo.save(
|
||||
const snippet = await this.repo.save(
|
||||
this.repo.create({
|
||||
alias: dto.alias,
|
||||
title: dto.title,
|
||||
description: dto.description ?? null,
|
||||
code: dto.code,
|
||||
version: 1,
|
||||
}),
|
||||
);
|
||||
await this.recordVersion(snippet);
|
||||
return snippet;
|
||||
}
|
||||
|
||||
async findAll(
|
||||
@@ -96,8 +139,37 @@ export class SnippetService implements OnModuleInit {
|
||||
`Snippet alias "${dto.alias}" already exists`,
|
||||
);
|
||||
}
|
||||
Object.assign(snippet, dto);
|
||||
return this.repo.save(snippet);
|
||||
const next: SnippetContent = {
|
||||
alias: dto.alias ?? snippet.alias,
|
||||
title: dto.title ?? snippet.title,
|
||||
description:
|
||||
dto.description !== undefined ? dto.description : snippet.description,
|
||||
code: dto.code ?? snippet.code,
|
||||
};
|
||||
if (sameContent(snippet, next)) return snippet;
|
||||
Object.assign(snippet, next, { version: snippet.version + 1 });
|
||||
const saved = await this.repo.save(snippet);
|
||||
await this.recordVersion(saved);
|
||||
return saved;
|
||||
}
|
||||
|
||||
// ── Versions ──────────────────────────────────────────────────────────────
|
||||
|
||||
async listVersions(id: string): Promise<SnippetVersionEntity[]> {
|
||||
await this.findOne(id); // 404 guard
|
||||
return this.versionRepo.find({
|
||||
where: { snippetId: id },
|
||||
order: { version: "DESC" },
|
||||
});
|
||||
}
|
||||
|
||||
async findVersion(id: string, version: number): Promise<SnippetVersionEntity> {
|
||||
await this.findOne(id); // 404 guard
|
||||
const row = await this.versionRepo.findOneBy({ snippetId: id, version });
|
||||
if (!row) {
|
||||
throw new NotFoundException(`Snippet ${id} has no version ${version}`);
|
||||
}
|
||||
return row;
|
||||
}
|
||||
|
||||
async remove(id: string): Promise<void> {
|
||||
@@ -105,58 +177,111 @@ export class SnippetService implements OnModuleInit {
|
||||
await this.repo.delete(id);
|
||||
}
|
||||
|
||||
/** Returns an alias→code map for all snippets (used by the executor). */
|
||||
/**
|
||||
* Returns the code map used by the executor: `alias` → latest code, plus
|
||||
* `alias@<version>` → that version's code for every stored version. Pinned
|
||||
* references use the snippet's current alias.
|
||||
*/
|
||||
async buildSnippetMap(): Promise<Record<string, string>> {
|
||||
const { data } = await this.findAll({ limit: 1000 });
|
||||
return Object.fromEntries(data.map((s) => [s.alias, s.code]));
|
||||
const map: Record<string, string> = Object.fromEntries(
|
||||
data.map((s) => [s.alias, s.code]),
|
||||
);
|
||||
if (data.length === 0) return map;
|
||||
const aliasById = new Map(data.map((s) => [s.id, s.alias]));
|
||||
const versions = await this.versionRepo.find({
|
||||
where: { snippetId: In([...aliasById.keys()]) },
|
||||
});
|
||||
for (const v of versions) {
|
||||
map[`${aliasById.get(v.snippetId)}@${v.version}`] = v.code;
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
exportSnippet(snippet: SnippetEntity): SnippetExportDto {
|
||||
/** Returns the snippet entities matching the given aliases (used by executor/executor consumers). */
|
||||
async findByAliases(aliases: string[]): Promise<SnippetEntity[]> {
|
||||
if (aliases.length === 0) return [];
|
||||
return this.repo.find({ where: { alias: In(aliases) } });
|
||||
}
|
||||
|
||||
/** Exports the latest version, or `version` when given. */
|
||||
async exportSnippet(
|
||||
snippet: SnippetEntity,
|
||||
version?: number,
|
||||
): Promise<SnippetExportDto> {
|
||||
const content: SnippetContent & { version: number } =
|
||||
version === undefined || version === snippet.version
|
||||
? snippet
|
||||
: await this.findVersion(snippet.id, version);
|
||||
return {
|
||||
kind: "snippet",
|
||||
id: snippet.id,
|
||||
alias: snippet.alias,
|
||||
title: snippet.title,
|
||||
description: snippet.description,
|
||||
code: snippet.code,
|
||||
version: content.version,
|
||||
alias: content.alias,
|
||||
title: content.title,
|
||||
description: content.description,
|
||||
code: content.code,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Restores the exported version: upsert by id + version. An existing version
|
||||
* is left untouched; a new one is stored under its number and becomes the
|
||||
* latest when it is higher than the current latest.
|
||||
*/
|
||||
async importSnippet(dto: SnippetExportDto): Promise<SnippetEntity> {
|
||||
const alias = dto.alias ?? dto.name;
|
||||
if (!alias) {
|
||||
throw new ConflictException("Snippet alias is required");
|
||||
}
|
||||
const title = dto.title ?? alias;
|
||||
const content: SnippetContent = {
|
||||
alias,
|
||||
title: dto.title ?? alias,
|
||||
description: dto.description ?? null,
|
||||
code: dto.code,
|
||||
};
|
||||
|
||||
if (dto.id) {
|
||||
const existing = await this.repo.findOneBy({ id: dto.id });
|
||||
if (existing) {
|
||||
Object.assign(existing, {
|
||||
alias,
|
||||
title,
|
||||
description: dto.description ?? null,
|
||||
code: dto.code,
|
||||
});
|
||||
return this.repo.save(existing);
|
||||
}
|
||||
return this.repo.save(
|
||||
const existing = dto.id ? await this.repo.findOneBy({ id: dto.id }) : null;
|
||||
if (!existing) {
|
||||
await this.assertAliasFree(alias);
|
||||
const created = await this.repo.save(
|
||||
this.repo.create({
|
||||
id: dto.id,
|
||||
alias,
|
||||
title,
|
||||
description: dto.description ?? null,
|
||||
code: dto.code,
|
||||
...(dto.id ? { id: dto.id } : {}),
|
||||
...content,
|
||||
version: dto.version,
|
||||
}),
|
||||
);
|
||||
await this.recordVersion(created);
|
||||
return created;
|
||||
}
|
||||
return this.repo.save(
|
||||
this.repo.create({
|
||||
alias,
|
||||
title,
|
||||
description: dto.description ?? null,
|
||||
code: dto.code,
|
||||
|
||||
const hasVersion = await this.versionRepo.existsBy({
|
||||
snippetId: existing.id,
|
||||
version: dto.version,
|
||||
});
|
||||
if (hasVersion) return existing;
|
||||
|
||||
await this.versionRepo.save(
|
||||
this.versionRepo.create({
|
||||
snippetId: existing.id,
|
||||
version: dto.version,
|
||||
...content,
|
||||
}),
|
||||
);
|
||||
if (dto.version > existing.version) {
|
||||
if (alias !== existing.alias) await this.assertAliasFree(alias, existing.id);
|
||||
Object.assign(existing, content, { version: dto.version });
|
||||
return this.repo.save(existing);
|
||||
}
|
||||
return existing;
|
||||
}
|
||||
|
||||
private async assertAliasFree(alias: string, exceptId?: string): Promise<void> {
|
||||
const conflict = await this.repo.findOneBy(
|
||||
exceptId ? { alias, id: Not(exceptId) } : { alias },
|
||||
);
|
||||
if (conflict) {
|
||||
throw new ConflictException(`Snippet alias "${alias}" already exists`);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -12,6 +12,16 @@ const makeContext = () => ({
|
||||
cookies: jest.fn().mockResolvedValue([]),
|
||||
addCookies: jest.fn().mockResolvedValue(undefined),
|
||||
addInitScript: jest.fn().mockResolvedValue(undefined),
|
||||
tracing: {
|
||||
start: jest.fn().mockResolvedValue(undefined),
|
||||
// Mimic Playwright writing the trace archive when a path is given
|
||||
stop: jest.fn().mockImplementation(async (opts?: { path?: string }) => {
|
||||
if (opts?.path) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
||||
await require("fs/promises").writeFile(opts.path, "fake trace zip");
|
||||
}
|
||||
}),
|
||||
},
|
||||
});
|
||||
|
||||
const makeBrowser = () => ({
|
||||
|
||||
@@ -38,6 +38,8 @@ import { SessionEntity } from "../src/session/session.entity";
|
||||
import { EnvironmentEntity } from "../src/environment/environment.entity";
|
||||
import { ScenarioEntity } from "../src/scenario/scenario.entity";
|
||||
import { ScenarioStepEntity } from "../src/scenario/scenario-step.entity";
|
||||
import { ScenarioVersionEntity } from "../src/scenario/scenario-version.entity";
|
||||
import { SnippetVersionEntity } from "../src/snippet/snippet-version.entity";
|
||||
import { ScenarioRunEntity } from "../src/scenario/scenario-run.entity";
|
||||
import { ScenarioRunStepEntity } from "../src/scenario/scenario-run-step.entity";
|
||||
import { ScenarioRunLogEntity } from "../src/scenario/scenario-run-log.entity";
|
||||
@@ -68,12 +70,14 @@ export async function buildTestApp(): Promise<INestApplication> {
|
||||
EnvironmentEntity,
|
||||
ScenarioEntity,
|
||||
ScenarioStepEntity,
|
||||
ScenarioVersionEntity,
|
||||
ScenarioRunEntity,
|
||||
ScenarioRunStepEntity,
|
||||
ScenarioRunLogEntity,
|
||||
ScenarioCredentialEntity,
|
||||
CredentialEntity,
|
||||
SnippetEntity,
|
||||
SnippetVersionEntity,
|
||||
FileEntity,
|
||||
ScenarioFileEntity,
|
||||
ScenarioRunFileEntity,
|
||||
|
||||
@@ -133,11 +133,16 @@ describe("Exec Context File Methods Integration Tests", () => {
|
||||
scenarioStepId: string,
|
||||
order = 0,
|
||||
) {
|
||||
// Run steps execute from their own copy of the step content
|
||||
const step = await stepRepo.findOneByOrFail({ id: scenarioStepId });
|
||||
const runStep = await runStepRepo.save(
|
||||
runStepRepo.create({
|
||||
runId,
|
||||
scenarioStepId,
|
||||
order,
|
||||
title: step.title,
|
||||
execCode: step.execCode,
|
||||
timeoutSeconds: step.timeoutSeconds,
|
||||
status: "pending",
|
||||
}),
|
||||
);
|
||||
|
||||
@@ -124,11 +124,16 @@ describe("McpController", () => {
|
||||
}
|
||||
|
||||
async function createRunStep(runId: string, scenarioStepId: string, order = 0) {
|
||||
// Run steps execute from their own copy of the step content
|
||||
const step = await stepRepo.findOneByOrFail({ id: scenarioStepId });
|
||||
return runStepRepo.save(
|
||||
runStepRepo.create({
|
||||
runId,
|
||||
scenarioStepId,
|
||||
order,
|
||||
title: step.title,
|
||||
execCode: step.execCode,
|
||||
timeoutSeconds: step.timeoutSeconds,
|
||||
status: "pending",
|
||||
}),
|
||||
);
|
||||
@@ -588,11 +593,15 @@ describe("McpController", () => {
|
||||
total: number;
|
||||
};
|
||||
|
||||
expect(list.total).toBe(1);
|
||||
expect(list.items).toHaveLength(1);
|
||||
expect(list.items[0].name).toBe("artifact.bin");
|
||||
expect(list.items[0].mimeType).toBe("application/octet-stream");
|
||||
expect(list.items[0].expiresAt).not.toBeNull();
|
||||
// The script's artifact plus the run's Playwright trace
|
||||
expect(list.total).toBe(2);
|
||||
expect(list.items.map((f) => f.name).sort()).toEqual([
|
||||
"artifact.bin",
|
||||
"trace.zip",
|
||||
]);
|
||||
const artifact = list.items.find((f) => f.name === "artifact.bin")!;
|
||||
expect(artifact.mimeType).toBe("application/octet-stream");
|
||||
expect(artifact.expiresAt).not.toBeNull();
|
||||
});
|
||||
|
||||
it("returns MCP error for non-existent scenario", async () => {
|
||||
@@ -621,7 +630,7 @@ describe("McpController", () => {
|
||||
) as {
|
||||
items: Array<{ id: string; name: string; mimeType: string }>;
|
||||
};
|
||||
const file = list.items[0];
|
||||
const file = list.items.find((f) => f.name === "artifact.bin")!;
|
||||
|
||||
const { status, rpc } = await mcpCall("get_run_file_content", {
|
||||
scenarioId: sc.id,
|
||||
@@ -843,4 +852,143 @@ describe("McpController", () => {
|
||||
expect(result.isError).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
// ── Credential CRUD tools ─────────────────────────────────────────────────
|
||||
|
||||
async function createCredential(name: string, data?: string) {
|
||||
const { rpc } = await mcpCall("create_credential", { name, data });
|
||||
return JSON.parse(
|
||||
(rpc.result as { content: { text: string }[] }).content[0].text,
|
||||
) as { id: string; name: string; data: string | null };
|
||||
}
|
||||
|
||||
describe("list_credentials", () => {
|
||||
it("returns a paginated result with a data array", async () => {
|
||||
await createCredential("mcp-list-cred");
|
||||
const { status, rpc } = await mcpCall("list_credentials", {
|
||||
limit: 100,
|
||||
});
|
||||
expect(status).toBe(200);
|
||||
const result = rpc.result as { content: { text: string }[] };
|
||||
const body = JSON.parse(result.content[0].text) as {
|
||||
data: { name: string }[];
|
||||
total: number;
|
||||
};
|
||||
expect(Array.isArray(body.data)).toBe(true);
|
||||
expect(typeof body.total).toBe("number");
|
||||
expect(body.data.some((c) => c.name === "mcp-list-cred")).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe("create_credential", () => {
|
||||
it("creates a credential and returns it with name and data", async () => {
|
||||
const created = await createCredential(
|
||||
"mcp-test-cred",
|
||||
'{"token":"abc123"}',
|
||||
);
|
||||
expect(typeof created.id).toBe("string");
|
||||
expect(created.name).toBe("mcp-test-cred");
|
||||
expect(created.data).toBe('{"token":"abc123"}');
|
||||
});
|
||||
|
||||
it("stores null data when data is omitted", async () => {
|
||||
const created = await createCredential("mcp-test-cred-nodata");
|
||||
expect(created.data).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
describe("get_credential", () => {
|
||||
it("returns the created credential by id", async () => {
|
||||
const created = await createCredential("mcp-get-cred", '{"a":1}');
|
||||
const { status, rpc } = await mcpCall("get_credential", {
|
||||
id: created.id,
|
||||
});
|
||||
expect(status).toBe(200);
|
||||
const result = rpc.result as { content: { text: string }[] };
|
||||
const fetched = JSON.parse(result.content[0].text) as {
|
||||
id: string;
|
||||
name: string;
|
||||
data: string;
|
||||
};
|
||||
expect(fetched.id).toBe(created.id);
|
||||
expect(fetched.name).toBe("mcp-get-cred");
|
||||
expect(fetched.data).toBe('{"a":1}');
|
||||
});
|
||||
|
||||
it("returns an MCP error for a non-existent credential id", async () => {
|
||||
const { status, rpc } = await mcpCall("get_credential", {
|
||||
id: "00000000-0000-0000-0000-000000000000",
|
||||
});
|
||||
expect(status).toBe(200);
|
||||
const result = rpc.result as { isError: boolean };
|
||||
expect(result.isError).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe("update_credential", () => {
|
||||
it("updates name and data of an existing credential", async () => {
|
||||
const created = await createCredential("mcp-upd-cred-orig", '{"v":1}');
|
||||
const { status, rpc } = await mcpCall("update_credential", {
|
||||
id: created.id,
|
||||
name: "mcp-upd-cred-new",
|
||||
data: '{"v":2}',
|
||||
});
|
||||
expect(status).toBe(200);
|
||||
const result = rpc.result as { content: { text: string }[] };
|
||||
const updated = JSON.parse(result.content[0].text) as {
|
||||
name: string;
|
||||
data: string;
|
||||
};
|
||||
expect(updated.name).toBe("mcp-upd-cred-new");
|
||||
expect(updated.data).toBe('{"v":2}');
|
||||
});
|
||||
|
||||
it("leaves data untouched when only name is updated", async () => {
|
||||
const created = await createCredential("mcp-upd-cred-partial", '{"k":1}');
|
||||
const { rpc } = await mcpCall("update_credential", {
|
||||
id: created.id,
|
||||
name: "mcp-upd-cred-partial-new",
|
||||
});
|
||||
const updated = JSON.parse(
|
||||
(rpc.result as { content: { text: string }[] }).content[0].text,
|
||||
) as { name: string; data: string };
|
||||
expect(updated.name).toBe("mcp-upd-cred-partial-new");
|
||||
expect(updated.data).toBe('{"k":1}');
|
||||
});
|
||||
|
||||
it("returns an MCP error for a non-existent credential id", async () => {
|
||||
const { status, rpc } = await mcpCall("update_credential", {
|
||||
id: "00000000-0000-0000-0000-000000000000",
|
||||
name: "Ghost",
|
||||
});
|
||||
expect(status).toBe(200);
|
||||
const result = rpc.result as { isError: boolean };
|
||||
expect(result.isError).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe("delete_credential", () => {
|
||||
it("deletes an existing credential and confirms deletion", async () => {
|
||||
const created = await createCredential("mcp-del-cred");
|
||||
const { status, rpc } = await mcpCall("delete_credential", {
|
||||
id: created.id,
|
||||
});
|
||||
expect(status).toBe(200);
|
||||
const result = rpc.result as { content: { text: string }[] };
|
||||
expect(result.content[0].text).toContain(created.id);
|
||||
|
||||
const getResult = (await mcpCall("get_credential", { id: created.id }))
|
||||
.rpc.result as { isError: boolean };
|
||||
expect(getResult.isError).toBe(true);
|
||||
});
|
||||
|
||||
it("returns an MCP error for a non-existent credential id", async () => {
|
||||
const { status, rpc } = await mcpCall("delete_credential", {
|
||||
id: "00000000-0000-0000-0000-000000000000",
|
||||
});
|
||||
expect(status).toBe(200);
|
||||
const result = rpc.result as { isError: boolean };
|
||||
expect(result.isError).toBe(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,181 @@
|
||||
/**
|
||||
* Integration tests for Playwright trace recording on scenario runs.
|
||||
*
|
||||
* The playwright mock writes a fake archive when tracing.stop() is given a
|
||||
* path, so we can assert that a `trace.zip` run artifact is (or is not)
|
||||
* uploaded depending on the run's trace mode and outcome.
|
||||
*/
|
||||
|
||||
import { INestApplication } from "@nestjs/common";
|
||||
import request from "supertest";
|
||||
import { DataSource } from "typeorm";
|
||||
import { buildTestApp } from "./app.harness";
|
||||
import { TraceMode } from "../src/config/app.config";
|
||||
import { EnvironmentEntity } from "../src/environment/environment.entity";
|
||||
import { ScenarioSchedulerService } from "../src/scenario/scenario-scheduler.service";
|
||||
import { ScenarioService } from "../src/scenario/scenario.service";
|
||||
|
||||
describe("ScenarioSchedulerService Playwright traces", () => {
|
||||
let app: INestApplication;
|
||||
let dataSource: DataSource;
|
||||
let scenarioService: ScenarioService;
|
||||
let scheduler: ScenarioSchedulerService;
|
||||
|
||||
beforeAll(async () => {
|
||||
app = await buildTestApp();
|
||||
dataSource = app.get(DataSource);
|
||||
scenarioService = app.get(ScenarioService);
|
||||
scheduler = app.get(ScenarioSchedulerService);
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
await app.close();
|
||||
});
|
||||
|
||||
// ── helpers ────────────────────────────────────────────────────────────────
|
||||
|
||||
async function runScenario(
|
||||
name: string,
|
||||
execCode: string,
|
||||
traceMode?: TraceMode,
|
||||
): Promise<string> {
|
||||
const sc = await scenarioService.create({ name });
|
||||
await scenarioService.createStep(sc.id, { execCode });
|
||||
const envRepo = dataSource.getRepository(EnvironmentEntity);
|
||||
const env = await envRepo.save(
|
||||
envRepo.create({ name: `${name}-env`, data: {} }),
|
||||
);
|
||||
const run = await scenarioService.createRun(
|
||||
sc.id,
|
||||
env.id,
|
||||
false,
|
||||
traceMode,
|
||||
);
|
||||
await scheduler.pickUpPendingRuns();
|
||||
await scenarioService.waitForRun(sc.id, run.id, 10_000);
|
||||
// The trace is saved after the run reaches its final status; wait for
|
||||
// the scheduler to finish its cleanup for this run.
|
||||
const activeRuns = (scheduler as unknown as { activeRuns: Set<string> })
|
||||
.activeRuns;
|
||||
const deadline = Date.now() + 5_000;
|
||||
while (activeRuns.has(run.id) && Date.now() < deadline) {
|
||||
await new Promise((r) => setTimeout(r, 20));
|
||||
}
|
||||
return run.id;
|
||||
}
|
||||
|
||||
async function traceArtifacts(
|
||||
runId: string,
|
||||
): Promise<{ mimeType: string }[]> {
|
||||
return dataSource.query(
|
||||
`SELECT f.mimeType FROM scenario_run_files rf
|
||||
JOIN files f ON f.id = rf.fileId
|
||||
WHERE rf.runId = ? AND f.originalName = 'trace.zip'`,
|
||||
[runId],
|
||||
);
|
||||
}
|
||||
|
||||
// ── tests ──────────────────────────────────────────────────────────────────
|
||||
|
||||
it("uploads trace.zip for a passing run in 'on' mode", async () => {
|
||||
const runId = await runScenario("trace-on-pass", "return 1;", TraceMode.On);
|
||||
const files = await traceArtifacts(runId);
|
||||
expect(files).toHaveLength(1);
|
||||
expect(files[0].mimeType).toBe("application/zip");
|
||||
});
|
||||
|
||||
it("uploads trace.zip for a failing run in 'retain-on-failure' mode", async () => {
|
||||
const runId = await runScenario(
|
||||
"trace-rof-fail",
|
||||
"throw new Error('boom');",
|
||||
TraceMode.RetainOnFailure,
|
||||
);
|
||||
expect(await traceArtifacts(runId)).toHaveLength(1);
|
||||
});
|
||||
|
||||
it("discards the trace of a passing run in 'retain-on-failure' mode", async () => {
|
||||
const runId = await runScenario(
|
||||
"trace-rof-pass",
|
||||
"return 1;",
|
||||
TraceMode.RetainOnFailure,
|
||||
);
|
||||
expect(await traceArtifacts(runId)).toHaveLength(0);
|
||||
});
|
||||
|
||||
it("does not record a trace in 'off' mode", async () => {
|
||||
const runId = await runScenario(
|
||||
"trace-off-fail",
|
||||
"throw new Error('boom');",
|
||||
TraceMode.Off,
|
||||
);
|
||||
expect(await traceArtifacts(runId)).toHaveLength(0);
|
||||
});
|
||||
|
||||
it("stores the configured default trace mode when none is given", async () => {
|
||||
const runId = await runScenario("trace-default", "return 1;");
|
||||
const [row] = await dataSource.query(
|
||||
`SELECT traceMode FROM scenario_runs WHERE id = ?`,
|
||||
[runId],
|
||||
);
|
||||
expect(row.traceMode).toBe("on");
|
||||
expect(await traceArtifacts(runId)).toHaveLength(1);
|
||||
});
|
||||
|
||||
it("falls back to the configured mode for runs without a stored trace mode", async () => {
|
||||
const sc = await scenarioService.create({ name: "trace-null-mode" });
|
||||
await scenarioService.createStep(sc.id, { execCode: "return 1;" });
|
||||
const envRepo = dataSource.getRepository(EnvironmentEntity);
|
||||
const env = await envRepo.save(
|
||||
envRepo.create({ name: "trace-null-mode-env", data: {} }),
|
||||
);
|
||||
const run = await scenarioService.createRun(sc.id, env.id);
|
||||
await dataSource.query(
|
||||
`UPDATE scenario_runs SET traceMode = NULL WHERE id = ?`,
|
||||
[run.id],
|
||||
);
|
||||
await scheduler.pickUpPendingRuns();
|
||||
await scenarioService.waitForRun(sc.id, run.id, 10_000);
|
||||
const activeRuns = (scheduler as unknown as { activeRuns: Set<string> })
|
||||
.activeRuns;
|
||||
const deadline = Date.now() + 5_000;
|
||||
while (activeRuns.has(run.id) && Date.now() < deadline) {
|
||||
await new Promise((r) => setTimeout(r, 20));
|
||||
}
|
||||
expect(await traceArtifacts(run.id)).toHaveLength(1);
|
||||
});
|
||||
|
||||
describe("HTTP", () => {
|
||||
it("GET /scenarios/run-defaults returns the configured trace mode", async () => {
|
||||
const res = await request(app.getHttpServer()).get(
|
||||
"/scenarios/run-defaults",
|
||||
);
|
||||
expect(res.status).toBe(200);
|
||||
expect(res.body).toEqual({ traceMode: "on" });
|
||||
});
|
||||
|
||||
it("POST /scenarios/:id/run stores the requested trace mode", async () => {
|
||||
const sc = await scenarioService.create({ name: "trace-http" });
|
||||
const envRepo = dataSource.getRepository(EnvironmentEntity);
|
||||
const env = await envRepo.save(
|
||||
envRepo.create({ name: "trace-http-env", data: {} }),
|
||||
);
|
||||
const res = await request(app.getHttpServer())
|
||||
.post(`/scenarios/${sc.id}/run`)
|
||||
.send({ environmentId: env.id, traceMode: "retain-on-failure" });
|
||||
expect(res.status).toBe(201);
|
||||
expect(res.body.traceMode).toBe("retain-on-failure");
|
||||
});
|
||||
|
||||
it("POST /scenarios/:id/run rejects an unknown trace mode", async () => {
|
||||
const sc = await scenarioService.create({ name: "trace-http-bad" });
|
||||
const envRepo = dataSource.getRepository(EnvironmentEntity);
|
||||
const env = await envRepo.save(
|
||||
envRepo.create({ name: "trace-http-bad-env", data: {} }),
|
||||
);
|
||||
const res = await request(app.getHttpServer())
|
||||
.post(`/scenarios/${sc.id}/run`)
|
||||
.send({ environmentId: env.id, traceMode: "sometimes" });
|
||||
expect(res.status).toBe(400);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -676,6 +676,7 @@ describe("ScenarioController", () => {
|
||||
it("creates a new scenario with all steps", async () => {
|
||||
const payload = {
|
||||
name: "imported scenario",
|
||||
version: 1,
|
||||
steps: [
|
||||
{
|
||||
sessionName: "s",
|
||||
@@ -750,13 +751,20 @@ describe("ScenarioController", () => {
|
||||
it("imports with empty steps array", async () => {
|
||||
const res = await request(app.getHttpServer())
|
||||
.post("/scenarios/import")
|
||||
.send({ name: "empty-import", steps: [] })
|
||||
.send({ name: "empty-import", version: 1, steps: [] })
|
||||
.expect(201);
|
||||
|
||||
expect(res.body.name).toBe("empty-import");
|
||||
expect(res.body.steps).toHaveLength(0);
|
||||
});
|
||||
|
||||
it("returns 400 when version is missing", async () => {
|
||||
await request(app.getHttpServer())
|
||||
.post("/scenarios/import")
|
||||
.send({ name: "no-version", steps: [] })
|
||||
.expect(400);
|
||||
});
|
||||
|
||||
it("returns 400 when name is missing", async () => {
|
||||
await request(app.getHttpServer())
|
||||
.post("/scenarios/import")
|
||||
@@ -776,6 +784,7 @@ describe("ScenarioController", () => {
|
||||
.post("/scenarios/import")
|
||||
.send({
|
||||
name: "bad-type",
|
||||
version: 1,
|
||||
steps: [{ type: "unknown", sessionName: "s" }],
|
||||
})
|
||||
.expect(201);
|
||||
|
||||
@@ -0,0 +1,393 @@
|
||||
/**
|
||||
* Integration tests for scenario and snippet versioning:
|
||||
* - versions bump on content changes only
|
||||
* - runs record and execute the scenario version they were created with
|
||||
* - runSnippet("alias@N") pins a snippet version
|
||||
* - export/import carry and restore exact versions
|
||||
*/
|
||||
|
||||
import { INestApplication } from "@nestjs/common";
|
||||
import request from "supertest";
|
||||
import { DataSource } from "typeorm";
|
||||
import { buildTestApp } from "./app.harness";
|
||||
import { CredentialEntity } from "../src/credential/credential.entity";
|
||||
import { EnvironmentEntity } from "../src/environment/environment.entity";
|
||||
import { ScenarioSchedulerService } from "../src/scenario/scenario-scheduler.service";
|
||||
import { ScenarioService } from "../src/scenario/scenario.service";
|
||||
import { SnippetService } from "../src/snippet/snippet.service";
|
||||
|
||||
describe("Versioning", () => {
|
||||
let app: INestApplication;
|
||||
let dataSource: DataSource;
|
||||
let scenarioService: ScenarioService;
|
||||
let snippetService: SnippetService;
|
||||
let scheduler: ScenarioSchedulerService;
|
||||
|
||||
beforeAll(async () => {
|
||||
app = await buildTestApp();
|
||||
dataSource = app.get(DataSource);
|
||||
scenarioService = app.get(ScenarioService);
|
||||
snippetService = app.get(SnippetService);
|
||||
scheduler = app.get(ScenarioSchedulerService);
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
await app.close();
|
||||
});
|
||||
|
||||
// ── helpers ────────────────────────────────────────────────────────────────
|
||||
|
||||
const uniq = () => Math.random().toString(36).slice(2, 8);
|
||||
|
||||
async function createEnvironment(): Promise<string> {
|
||||
const repo = dataSource.getRepository(EnvironmentEntity);
|
||||
const env = await repo.save(
|
||||
repo.create({ name: `env-${uniq()}`, data: {} }),
|
||||
);
|
||||
return env.id;
|
||||
}
|
||||
|
||||
async function versionNumbers(scenarioId: string): Promise<number[]> {
|
||||
return (await scenarioService.listVersions(scenarioId)).map(
|
||||
(v) => v.version,
|
||||
);
|
||||
}
|
||||
|
||||
/** Creates and processes a run; returns it with its step runs. */
|
||||
async function runToCompletion(scenarioId: string, version?: number) {
|
||||
const run = await scenarioService.createRun(
|
||||
scenarioId,
|
||||
await createEnvironment(),
|
||||
false,
|
||||
undefined,
|
||||
version,
|
||||
);
|
||||
await scheduler.pickUpPendingRuns();
|
||||
return scenarioService.waitForRun(scenarioId, run.id, 10_000);
|
||||
}
|
||||
|
||||
const outputs = (run: { stepRuns: { output: string | null }[] }) =>
|
||||
run.stepRuns.map((s) => (s.output ? JSON.parse(s.output) : null));
|
||||
|
||||
// ── scenario versions ─────────────────────────────────────────────────────
|
||||
|
||||
describe("scenario versions", () => {
|
||||
it("starts at version 1 with a stored snapshot", async () => {
|
||||
const sc = await scenarioService.create({ name: `v-${uniq()}` });
|
||||
expect(sc.version).toBe(1);
|
||||
expect(await versionNumbers(sc.id)).toEqual([1]);
|
||||
});
|
||||
|
||||
it("bumps on scenario and step changes, not on no-op updates", async () => {
|
||||
const sc = await scenarioService.create({ name: `bump-${uniq()}` });
|
||||
await scenarioService.update(sc.id, { name: `${sc.name}-renamed` });
|
||||
expect((await scenarioService.findOne(sc.id)).version).toBe(2);
|
||||
|
||||
// Same content again: no new version
|
||||
await scenarioService.update(sc.id, { name: `${sc.name}-renamed` });
|
||||
expect((await scenarioService.findOne(sc.id)).version).toBe(2);
|
||||
|
||||
const step = await scenarioService.createStep(sc.id, {
|
||||
execCode: "return 1;",
|
||||
});
|
||||
expect((await scenarioService.findOne(sc.id)).version).toBe(3);
|
||||
await scenarioService.updateStep(sc.id, step.id, {
|
||||
execCode: "return 2;",
|
||||
});
|
||||
expect((await scenarioService.findOne(sc.id)).version).toBe(4);
|
||||
await scenarioService.removeStep(sc.id, step.id);
|
||||
expect((await scenarioService.findOne(sc.id)).version).toBe(5);
|
||||
|
||||
expect(await versionNumbers(sc.id)).toEqual([5, 4, 3, 2, 1]);
|
||||
const v4 = await scenarioService.findVersion(sc.id, 4);
|
||||
expect(v4.steps.map((s) => s.execCode)).toEqual(["return 2;"]);
|
||||
});
|
||||
|
||||
it("does not bump on credential assignment", async () => {
|
||||
const sc = await scenarioService.create({ name: `cred-${uniq()}` });
|
||||
const credRepo = dataSource.getRepository(CredentialEntity);
|
||||
const cred = await credRepo.save(
|
||||
credRepo.create({ name: "c", data: null }),
|
||||
);
|
||||
await scenarioService.addScenarioCredential(sc.id, {
|
||||
credentialId: cred.id,
|
||||
alias: "c",
|
||||
});
|
||||
expect((await scenarioService.findOne(sc.id)).version).toBe(1);
|
||||
});
|
||||
|
||||
it("exposes versions over HTTP", async () => {
|
||||
const sc = await scenarioService.create({ name: `http-${uniq()}` });
|
||||
await scenarioService.createStep(sc.id, { execCode: "return 1;" });
|
||||
|
||||
const list = await request(app.getHttpServer())
|
||||
.get(`/scenarios/${sc.id}/versions`)
|
||||
.expect(200);
|
||||
expect(list.body.map((v: { version: number }) => v.version)).toEqual([
|
||||
2, 1,
|
||||
]);
|
||||
|
||||
const one = await request(app.getHttpServer())
|
||||
.get(`/scenarios/${sc.id}/versions/2`)
|
||||
.expect(200);
|
||||
expect(one.body.steps).toHaveLength(1);
|
||||
|
||||
await request(app.getHttpServer())
|
||||
.get(`/scenarios/${sc.id}/versions/99`)
|
||||
.expect(404);
|
||||
});
|
||||
});
|
||||
|
||||
// ── runs ──────────────────────────────────────────────────────────────────
|
||||
|
||||
describe("runs", () => {
|
||||
it("runs the latest version by default and records it", async () => {
|
||||
const sc = await scenarioService.create({ name: `run-${uniq()}` });
|
||||
await scenarioService.createStep(sc.id, { execCode: "return 'latest';" });
|
||||
|
||||
const run = await runToCompletion(sc.id);
|
||||
expect(run.scenarioVersion).toBe(2);
|
||||
expect(outputs(run)).toEqual(["latest"]);
|
||||
});
|
||||
|
||||
it("runs an older version's steps when asked", async () => {
|
||||
const sc = await scenarioService.create({ name: `old-${uniq()}` });
|
||||
const step = await scenarioService.createStep(sc.id, {
|
||||
title: "first",
|
||||
execCode: "return 'v2';",
|
||||
});
|
||||
await scenarioService.updateStep(sc.id, step.id, {
|
||||
execCode: "return 'v3';",
|
||||
});
|
||||
await scenarioService.createStep(sc.id, { execCode: "return 'extra';" });
|
||||
|
||||
const run = await runToCompletion(sc.id, 2);
|
||||
expect(run.scenarioVersion).toBe(2);
|
||||
expect(run.stepRuns).toHaveLength(1);
|
||||
expect(run.stepRuns[0].title).toBe("first");
|
||||
expect(run.stepRuns[0].execCode).toBe("return 'v2';");
|
||||
expect(outputs(run)).toEqual(["v2"]);
|
||||
});
|
||||
|
||||
it("rejects a version that does not exist", async () => {
|
||||
const sc = await scenarioService.create({ name: `nov-${uniq()}` });
|
||||
const environmentId = await createEnvironment();
|
||||
await request(app.getHttpServer())
|
||||
.post(`/scenarios/${sc.id}/run`)
|
||||
.send({ environmentId, version: 7 })
|
||||
.expect(404);
|
||||
});
|
||||
|
||||
it("keeps run history when a step is deleted", async () => {
|
||||
const sc = await scenarioService.create({ name: `hist-${uniq()}` });
|
||||
const step = await scenarioService.createStep(sc.id, {
|
||||
execCode: "return 1;",
|
||||
});
|
||||
const run = await runToCompletion(sc.id);
|
||||
await scenarioService.removeStep(sc.id, step.id);
|
||||
|
||||
const after = await scenarioService.findRun(sc.id, run.id);
|
||||
expect(after.stepRuns).toHaveLength(1);
|
||||
expect(after.stepRuns[0].scenarioStepId).toBeNull();
|
||||
expect(after.stepRuns[0].execCode).toBe("return 1;");
|
||||
});
|
||||
});
|
||||
|
||||
// ── snippet versions ──────────────────────────────────────────────────────
|
||||
|
||||
describe("snippet versions", () => {
|
||||
it("bumps on change only and keeps every version", async () => {
|
||||
const alias = `snip-${uniq()}`;
|
||||
const sn = await snippetService.create({
|
||||
alias,
|
||||
title: "t",
|
||||
code: "return 1;",
|
||||
});
|
||||
expect(sn.version).toBe(1);
|
||||
|
||||
await snippetService.update(sn.id, { code: "return 2;" });
|
||||
await snippetService.update(sn.id, { code: "return 2;" }); // no-op
|
||||
expect((await snippetService.findOne(sn.id)).version).toBe(2);
|
||||
|
||||
const versions = await snippetService.listVersions(sn.id);
|
||||
expect(versions.map((v) => [v.version, v.code])).toEqual([
|
||||
[2, "return 2;"],
|
||||
[1, "return 1;"],
|
||||
]);
|
||||
});
|
||||
|
||||
it("runSnippet uses the latest by default and alias@N pins a version", async () => {
|
||||
const alias = `pin-${uniq()}`;
|
||||
const sn = await snippetService.create({
|
||||
alias,
|
||||
title: "t",
|
||||
code: "return 'one';",
|
||||
});
|
||||
await snippetService.update(sn.id, { code: "return 'two';" });
|
||||
|
||||
const sc = await scenarioService.create({ name: `pinned-${uniq()}` });
|
||||
await scenarioService.createStep(sc.id, {
|
||||
execCode: `return [await context.runSnippet("${alias}"), await context.runSnippet("${alias}@1")];`,
|
||||
});
|
||||
|
||||
const run = await runToCompletion(sc.id);
|
||||
expect(run.status).toBe("pass");
|
||||
expect(outputs(run)).toEqual([["two", "one"]]);
|
||||
|
||||
const used = await scenarioService.getUsedSnippets(sc.id);
|
||||
expect(used.map((u) => [u.alias, u.pinnedVersion])).toEqual([
|
||||
[alias, null],
|
||||
[alias, 1],
|
||||
]);
|
||||
});
|
||||
|
||||
it("fails the step for a snippet version that does not exist", async () => {
|
||||
const alias = `missing-${uniq()}`;
|
||||
await snippetService.create({ alias, title: "t", code: "return 1;" });
|
||||
const sc = await scenarioService.create({ name: `miss-${uniq()}` });
|
||||
await scenarioService.createStep(sc.id, {
|
||||
execCode: `return context.runSnippet("${alias}@5");`,
|
||||
});
|
||||
const run = await runToCompletion(sc.id);
|
||||
expect(run.status).toBe("fail");
|
||||
});
|
||||
});
|
||||
|
||||
// ── export / import ───────────────────────────────────────────────────────
|
||||
|
||||
describe("scenario export/import", () => {
|
||||
it("exports the latest version, or the one asked for", async () => {
|
||||
const sc = await scenarioService.create({ name: `exp-${uniq()}` });
|
||||
await scenarioService.createStep(sc.id, { execCode: "return 1;" });
|
||||
|
||||
const latest = await scenarioService.exportScenario(sc.id, {
|
||||
includeEnvironment: false,
|
||||
credentialIds: [],
|
||||
});
|
||||
expect(latest[latest.length - 1]).toMatchObject({
|
||||
version: 2,
|
||||
steps: [{ execCode: "return 1;" }],
|
||||
});
|
||||
|
||||
const first = await scenarioService.exportScenario(sc.id, {
|
||||
includeEnvironment: false,
|
||||
credentialIds: [],
|
||||
version: 1,
|
||||
});
|
||||
expect(first[first.length - 1]).toMatchObject({ version: 1, steps: [] });
|
||||
});
|
||||
|
||||
it("restores exact versions by id + version", async () => {
|
||||
const id = crypto.randomUUID();
|
||||
const base = { kind: "scenario" as const, id, name: "imported" };
|
||||
|
||||
// New scenario: stored under the given version
|
||||
let sc = await scenarioService.importScenario({
|
||||
...base,
|
||||
version: 3,
|
||||
steps: [{ title: null, execCode: "return 3;" }],
|
||||
});
|
||||
expect(sc.version).toBe(3);
|
||||
expect(await versionNumbers(id)).toEqual([3]);
|
||||
|
||||
// Same version again: left untouched
|
||||
sc = await scenarioService.importScenario({
|
||||
...base,
|
||||
name: "changed",
|
||||
version: 3,
|
||||
steps: [],
|
||||
});
|
||||
expect(sc.name).toBe("imported");
|
||||
expect(sc.steps).toHaveLength(1);
|
||||
|
||||
// Lower, missing version: stored, latest unchanged
|
||||
sc = await scenarioService.importScenario({
|
||||
...base,
|
||||
version: 1,
|
||||
steps: [{ title: null, execCode: "return 1;" }],
|
||||
});
|
||||
expect(sc.version).toBe(3);
|
||||
expect(await versionNumbers(id)).toEqual([3, 1]);
|
||||
expect((await scenarioService.findVersion(id, 1)).steps[0].execCode).toBe(
|
||||
"return 1;",
|
||||
);
|
||||
|
||||
// Higher version: becomes the latest
|
||||
sc = await scenarioService.importScenario({
|
||||
...base,
|
||||
name: "v5",
|
||||
version: 5,
|
||||
steps: [{ title: null, execCode: "return 5;" }],
|
||||
});
|
||||
expect(sc.version).toBe(5);
|
||||
expect(sc.name).toBe("v5");
|
||||
expect(sc.steps.map((s) => s.execCode)).toEqual(["return 5;"]);
|
||||
expect(await versionNumbers(id)).toEqual([5, 3, 1]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("snippet export/import", () => {
|
||||
it("export includes the version and import requires it", async () => {
|
||||
const alias = `sexp-${uniq()}`;
|
||||
const sn = await snippetService.create({
|
||||
alias,
|
||||
title: "t",
|
||||
code: "return 1;",
|
||||
});
|
||||
await snippetService.update(sn.id, { code: "return 2;" });
|
||||
|
||||
const latest = await request(app.getHttpServer())
|
||||
.get(`/snippets/${sn.id}/export`)
|
||||
.expect(200);
|
||||
expect(latest.body).toMatchObject({ version: 2, code: "return 2;" });
|
||||
|
||||
const first = await request(app.getHttpServer())
|
||||
.get(`/snippets/${sn.id}/export?version=1`)
|
||||
.expect(200);
|
||||
expect(first.body).toMatchObject({ version: 1, code: "return 1;" });
|
||||
|
||||
await request(app.getHttpServer())
|
||||
.post("/snippets/import")
|
||||
.send({ alias: `noversion-${uniq()}`, code: "return 0;" })
|
||||
.expect(400);
|
||||
});
|
||||
|
||||
it("restores exact versions by id + version", async () => {
|
||||
const id = crypto.randomUUID();
|
||||
const alias = `simp-${uniq()}`;
|
||||
const base = { kind: "snippet" as const, id, alias, title: "t" };
|
||||
|
||||
let sn = await snippetService.importSnippet({
|
||||
...base,
|
||||
version: 2,
|
||||
code: "return 2;",
|
||||
});
|
||||
expect(sn.version).toBe(2);
|
||||
|
||||
sn = await snippetService.importSnippet({
|
||||
...base,
|
||||
version: 2,
|
||||
code: "changed",
|
||||
});
|
||||
expect(sn.code).toBe("return 2;");
|
||||
|
||||
sn = await snippetService.importSnippet({
|
||||
...base,
|
||||
version: 1,
|
||||
code: "return 1;",
|
||||
});
|
||||
expect(sn.version).toBe(2);
|
||||
|
||||
sn = await snippetService.importSnippet({
|
||||
...base,
|
||||
version: 4,
|
||||
code: "return 4;",
|
||||
});
|
||||
expect(sn.version).toBe(4);
|
||||
expect(sn.code).toBe("return 4;");
|
||||
expect(
|
||||
(await snippetService.listVersions(id)).map((v) => v.version),
|
||||
).toEqual([4, 2, 1]);
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user