Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a328ef5ea7 | ||
|
|
7d366e6368 | ||
|
|
5ea1e38f25 | ||
|
|
d99bb75fc2 | ||
|
|
d79415cbb3 |
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
|
||||
|
||||
|
||||
@@ -2,6 +2,46 @@
|
||||
|
||||
All notable changes to this project will be documented in this file.
|
||||
|
||||
## 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:
|
||||
|
||||
@@ -4,6 +4,7 @@ import type {
|
||||
Environment,
|
||||
FileMetadata,
|
||||
FileListResponse,
|
||||
RunDefaults,
|
||||
ScenarioCredential,
|
||||
Session,
|
||||
Scenario,
|
||||
@@ -12,6 +13,7 @@ import type {
|
||||
ScenarioRunStep,
|
||||
ScenarioStep,
|
||||
Snippet,
|
||||
TraceMode,
|
||||
} from './types';
|
||||
import { emitApiErrorToast } from '../lib/toast-events';
|
||||
|
||||
@@ -222,12 +224,20 @@ 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,
|
||||
): Promise<ScenarioRun> {
|
||||
return request(`/scenarios/${id}/run`, {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ environmentId, saveSession }),
|
||||
body: JSON.stringify({ environmentId, saveSession, traceMode }),
|
||||
});
|
||||
},
|
||||
runDefaults(): Promise<RunDefaults> {
|
||||
return request('/scenarios/run-defaults');
|
||||
},
|
||||
getRun(scenarioId: string, runId: string): Promise<ScenarioRunDetail> {
|
||||
return request(`/scenarios/${scenarioId}/run/${runId}`);
|
||||
},
|
||||
|
||||
@@ -98,6 +98,12 @@ export interface Scenario {
|
||||
|
||||
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 +111,10 @@ 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?: Pick<Scenario, 'id' | 'name'>;
|
||||
environment?: Pick<Environment, 'id' | 'name'>;
|
||||
session?: { id: string; sessionName: string };
|
||||
|
||||
@@ -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, TraceMode } from '../../api';
|
||||
|
||||
const TRACE_MODES: TraceMode[] = ['on', 'retain-on-failure', 'off'];
|
||||
|
||||
export interface RunScenarioModalProps {
|
||||
open: boolean;
|
||||
@@ -10,6 +12,9 @@ export interface RunScenarioModalProps {
|
||||
onEnvSelect: (envId: string) => void;
|
||||
saveSessionFlag: boolean;
|
||||
onSaveSessionChange: (flag: boolean) => void;
|
||||
traceMode: TraceMode;
|
||||
defaultTraceMode: TraceMode | null;
|
||||
onTraceModeChange: (mode: TraceMode) => void;
|
||||
onClose: () => void;
|
||||
onRun: () => void;
|
||||
isRunning: boolean;
|
||||
@@ -23,6 +28,9 @@ export function RunScenarioModal({
|
||||
onEnvSelect,
|
||||
saveSessionFlag,
|
||||
onSaveSessionChange,
|
||||
traceMode,
|
||||
defaultTraceMode,
|
||||
onTraceModeChange,
|
||||
onClose,
|
||||
onRun,
|
||||
isRunning,
|
||||
@@ -73,6 +81,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>
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
@@ -185,6 +185,11 @@
|
||||
"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_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",
|
||||
@@ -248,6 +253,7 @@
|
||||
"field_steps": "Steps",
|
||||
"field_created": "Started",
|
||||
"field_updated": "Updated",
|
||||
"field_trace": "Playwright trace",
|
||||
"steps_heading": "Step runs",
|
||||
"step_title": "Title",
|
||||
"logs_heading": "Logs",
|
||||
@@ -261,6 +267,8 @@
|
||||
"log_message": "Message",
|
||||
"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)",
|
||||
|
||||
@@ -28,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> = {
|
||||
@@ -66,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);
|
||||
@@ -88,6 +103,7 @@ export function RunDetailPage() {
|
||||
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);
|
||||
@@ -131,6 +147,25 @@ export function RunDetailPage() {
|
||||
}
|
||||
};
|
||||
|
||||
const handleRepeatRun = async () => {
|
||||
if (!id || !run?.environmentId) return;
|
||||
setRepeating(true);
|
||||
try {
|
||||
const newRun = await scenarios.run(
|
||||
id,
|
||||
run.environmentId,
|
||||
run.saveSession,
|
||||
run.traceMode ?? 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
|
||||
@@ -384,12 +419,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>}
|
||||
@@ -413,6 +463,14 @@ 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.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',
|
||||
|
||||
@@ -30,6 +30,7 @@ import type {
|
||||
Environment,
|
||||
FileMetadata,
|
||||
Snippet,
|
||||
TraceMode,
|
||||
} from '../../api';
|
||||
import {
|
||||
Breadcrumbs,
|
||||
@@ -46,7 +47,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() {
|
||||
@@ -73,6 +75,10 @@ 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 traceMode = traceModeOverride ?? runDefaults?.traceMode ?? 'on';
|
||||
const [envs, setEnvs] = useState<Environment[]>([]);
|
||||
const [selectedEnvId, setSelectedEnvId] = useState('');
|
||||
const envInitRef = useRef(false);
|
||||
@@ -164,7 +170,12 @@ 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,
|
||||
);
|
||||
toast.success(t('scenarios.run_started'));
|
||||
navigate(`/scenarios/${id}/runs/${run.id}`);
|
||||
setRunModalOpen(false);
|
||||
@@ -456,7 +467,13 @@ export function ScenarioDetailPage() {
|
||||
/>
|
||||
{scenario && (
|
||||
<div className={styles.toolbarActions}>
|
||||
<Button size="sm" onClick={() => setRunModalOpen(true)}>
|
||||
<Button
|
||||
size="sm"
|
||||
onClick={() => {
|
||||
setTraceModeOverride(null);
|
||||
setRunModalOpen(true);
|
||||
}}
|
||||
>
|
||||
<Play size={14} />
|
||||
{t('scenarios.action_run')}
|
||||
</Button>
|
||||
@@ -826,44 +843,20 @@ 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}
|
||||
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, 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,10 @@ 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 traceMode = traceModeOverride ?? runDefaults?.traceMode ?? 'on';
|
||||
const [envs, setEnvs] = useState<Environment[]>([]);
|
||||
const [selectedEnvId, setSelectedEnvId] = useState('');
|
||||
|
||||
@@ -104,6 +109,7 @@ export function ScenariosPage() {
|
||||
|
||||
const openRunModal = (id: string) => {
|
||||
setRunScenarioId(id);
|
||||
setTraceModeOverride(null);
|
||||
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 +120,12 @@ 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,
|
||||
);
|
||||
toast.success(t('scenarios.run_started'));
|
||||
navigate(`/scenarios/${runScenarioId}/runs/${run.id}`);
|
||||
setRunScenarioId(null);
|
||||
@@ -271,44 +282,20 @@ 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}
|
||||
traceMode={traceMode}
|
||||
defaultTraceMode={runDefaults?.traceMode ?? null}
|
||||
onTraceModeChange={setTraceModeOverride}
|
||||
onClose={() => setRunScenarioId(null)}
|
||||
onRun={handleRun}
|
||||
isRunning={running}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -43,6 +43,18 @@ Available in scope:
|
||||
|
||||
`validateCode` additionally receives `result` in scope, which is the value returned by `execCode`.
|
||||
|
||||
## 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
+2
-2
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "liqa",
|
||||
"version": "1.10.1",
|
||||
"version": "1.15.0",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "liqa",
|
||||
"version": "1.10.1",
|
||||
"version": "1.15.0",
|
||||
"workspaces": [
|
||||
"server",
|
||||
"client"
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "liqa",
|
||||
"version": "1.11.0",
|
||||
"version": "1.15.0",
|
||||
"private": true,
|
||||
"workspaces": [
|
||||
"server",
|
||||
|
||||
@@ -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,6 +7,7 @@ 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";
|
||||
@@ -275,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(
|
||||
@@ -779,14 +940,21 @@ 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",
|
||||
),
|
||||
},
|
||||
},
|
||||
async ({ id, environmentId, saveSession }) => {
|
||||
async ({ id, environmentId, saveSession, traceMode }) => {
|
||||
try {
|
||||
const run = await this.scenarioService.createRun(
|
||||
id,
|
||||
environmentId,
|
||||
saveSession,
|
||||
traceMode,
|
||||
);
|
||||
return {
|
||||
content: [{ type: "text" as const, text: JSON.stringify(run) }],
|
||||
|
||||
@@ -1,4 +1,11 @@
|
||||
import { IsBoolean, IsNotEmpty, IsOptional, IsUUID } from "class-validator";
|
||||
import {
|
||||
IsBoolean,
|
||||
IsEnum,
|
||||
IsNotEmpty,
|
||||
IsOptional,
|
||||
IsUUID,
|
||||
} from "class-validator";
|
||||
import { TraceMode } from "../../config/app.config";
|
||||
|
||||
export class CreateScenarioRunDto {
|
||||
@IsUUID()
|
||||
@@ -8,4 +15,8 @@ export class CreateScenarioRunDto {
|
||||
@IsBoolean()
|
||||
@IsOptional()
|
||||
saveSession?: boolean;
|
||||
|
||||
@IsEnum(TraceMode)
|
||||
@IsOptional()
|
||||
traceMode?: TraceMode;
|
||||
}
|
||||
@@ -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";
|
||||
@@ -47,6 +48,10 @@ export class ScenarioRunEntity {
|
||||
@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";
|
||||
@@ -29,6 +34,7 @@ interface BrowserHandle {
|
||||
browser: Browser;
|
||||
context: BrowserContext;
|
||||
page: Page;
|
||||
tracing: boolean;
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
@@ -49,6 +55,9 @@ export class ScenarioSchedulerService implements OnModuleInit {
|
||||
// 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;
|
||||
@@ -69,7 +78,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({
|
||||
@@ -208,6 +220,10 @@ export class ScenarioSchedulerService implements OnModuleInit {
|
||||
.catch(() => null);
|
||||
this.runScenarioTimeouts.set(run.id, scenario?.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),
|
||||
@@ -221,6 +237,7 @@ 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)}`,
|
||||
@@ -279,12 +296,15 @@ 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);
|
||||
}
|
||||
@@ -431,9 +451,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;
|
||||
@@ -453,6 +485,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(
|
||||
@@ -515,6 +594,8 @@ export class ScenarioSchedulerService implements OnModuleInit {
|
||||
`Step ${(stepRun.scenarioStep as ScenarioStepEntity | undefined)?.order ?? "?"} failed: ${description}`,
|
||||
);
|
||||
|
||||
await this.dumpPageOnFailure(stepRun);
|
||||
|
||||
// Cancel all remaining waiting/pending step runs in this run
|
||||
await this.runStepRepo
|
||||
.createQueryBuilder()
|
||||
@@ -534,4 +615,51 @@ 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 step = stepRun.scenarioStep as ScenarioStepEntity | undefined;
|
||||
const namePrefix = `step-${step?.order ?? stepRun.id}-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 ${step?.order ?? "?"} failed: page dump uploaded to run files`,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -70,6 +70,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 })
|
||||
@@ -276,6 +283,7 @@ export class ScenarioController {
|
||||
id,
|
||||
dto.environmentId,
|
||||
dto.saveSession,
|
||||
dto.traceMode,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import {
|
||||
Injectable,
|
||||
NotFoundException,
|
||||
} from "@nestjs/common";
|
||||
import { ConfigService } from "@nestjs/config";
|
||||
import { InjectRepository } from "@nestjs/typeorm";
|
||||
import * as fs from "fs/promises";
|
||||
import * as path from "path";
|
||||
@@ -13,6 +14,7 @@ import {
|
||||
PaginationQueryDto,
|
||||
} from "../common/dto/pagination.dto";
|
||||
import { 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";
|
||||
@@ -69,6 +71,7 @@ export class ScenarioService {
|
||||
private readonly scenarioRunFileRepo: Repository<ScenarioRunFileEntity>,
|
||||
private readonly fileStorageService: FileStorageService,
|
||||
private readonly snippetService: SnippetService,
|
||||
private readonly configService: ConfigService<AppConfig, true>,
|
||||
) {}
|
||||
|
||||
// ── Scenarios ─────────────────────────────────────────────────────────────
|
||||
@@ -488,10 +491,15 @@ 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,
|
||||
): Promise<ScenarioRunEntity> {
|
||||
const scenario = await this.findOne(scenarioId);
|
||||
const environment = await this.environmentRepo.findOneBy({
|
||||
@@ -507,6 +515,7 @@ export class ScenarioService {
|
||||
environmentId,
|
||||
status: "pending",
|
||||
saveSession,
|
||||
traceMode: traceMode ?? this.getRunDefaults().traceMode,
|
||||
}),
|
||||
);
|
||||
|
||||
|
||||
@@ -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 = () => ({
|
||||
|
||||
@@ -588,11 +588,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 +625,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 +847,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);
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user