Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8935783371 | ||
|
|
cf56840df9 | ||
|
|
1c5c906cbb | ||
|
|
ac12301818 | ||
|
|
84dba6d670 |
No files matched your search
+2
-1
@@ -17,4 +17,5 @@ SESSION_IDLE_TIMEOUT_MINUTES=30
|
||||
SESSION_DELETE_CLOSED_DAYS=7
|
||||
|
||||
# Playwright trace recording for scenario runs: on | retain-on-failure | off
|
||||
PLAYWRIGHT_TRACE_MODE=on
|
||||
# (traces often reach ~10 MB per run; can be overridden per run in the run modal)
|
||||
PLAYWRIGHT_TRACE_MODE=off
|
||||
@@ -2,6 +2,38 @@
|
||||
|
||||
All notable changes to this project will be documented in this file.
|
||||
|
||||
## 1.18.0 - 2026-09-30
|
||||
|
||||
Changes since 1.17.0:
|
||||
|
||||
### Added
|
||||
|
||||
- Added a central import: `POST /import`, an Import page in the UI, and the `import_yaml` MCP tool. It takes YAML made of `---`-separated documents, each holding one exported item or a list of items (JSON is accepted too), with any mix of environments, credentials, snippets and scenarios. All items are validated before anything is imported, and they are imported in dependency order (environments, credentials, snippets, scenarios), so a scenario can reference an environment or credential from the same file.
|
||||
|
||||
### Changed
|
||||
|
||||
- The Import buttons on the scenario, snippet, credential and environment list pages use the central import. When the file holds exactly one item of the page's kind, that item is opened; otherwise the Import page shows everything that was imported.
|
||||
|
||||
### Fixed
|
||||
|
||||
- Scenario exports that included the environment or credentials were not valid YAML (all entities were written into one document). Each entity is now a separate `---` document.
|
||||
|
||||
## 1.17.0 - 2026-09-30
|
||||
|
||||
Changes since 1.16.1:
|
||||
|
||||
### Added
|
||||
|
||||
- Files can be deleted from a run: a delete button (with confirmation) in the Files section of the run detail page, `DELETE /scenarios/:id/runs/:runId/files/:fileId`, and the `delete_run_file` MCP tool. The stored file is removed once no scenario or run references it.
|
||||
|
||||
## 1.16.1 - 2026-09-30
|
||||
|
||||
Changes since 1.16.0:
|
||||
|
||||
### Changed
|
||||
|
||||
- Playwright traces are now off by default (`PLAYWRIGHT_TRACE_MODE` defaults to `off`), since a trace often reaches ~10 MB per run. Traces can still be enabled per run in the run modal, via `traceMode` in `POST /scenarios/:id/run`, or for all runs by setting `PLAYWRIGHT_TRACE_MODE`.
|
||||
|
||||
## 1.16.0 - 2026-09-30
|
||||
|
||||
Changes since 1.15.0:
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
# liqa
|
||||
|
||||
liqa (liquio-qa-bot) is a QA automation service for Liquio environments. It stores **scenarios** (ordered Playwright steps), **snippets** (reusable code run via `context.runSnippet`), **environments**, **credentials** and **sessions**, and runs scenarios in headless Chromium. Scenarios and snippets are versioned; each run records the scenario version it executed.
|
||||
|
||||
It is an npm workspace with two packages:
|
||||
|
||||
- `server/` - NestJS API + scheduler + MCP server, SQLite via TypeORM (`synchronize: true`, so entity changes alter the schema on startup - there are no migrations). REST API under `/api/v1`, Swagger UI at `/docs`, MCP at `/mcp`, health at `/health`.
|
||||
- `client/` - React 19 + Vite SPA (i18n strings in `client/src/i18n/locales/en.json`).
|
||||
|
||||
## Docs
|
||||
|
||||
- [README.md](README.md) - overview
|
||||
- [docs/architecture.md](docs/architecture.md) - services and modules
|
||||
- [docs/development.md](docs/development.md) - local setup, running, testing, Docker
|
||||
- [docs/scenario.md](docs/scenario.md) - scenario execution, script `context` API, versioning, export/import, Playwright traces
|
||||
- [docs/mcp.md](docs/mcp.md) - MCP tool reference
|
||||
- [CHANGELOG.md](CHANGELOG.md) - release notes per version
|
||||
- [.env.example](.env.example) - all configuration variables (validated in `server/src/config/app.config.ts`)
|
||||
|
||||
## Default deployment (docker compose)
|
||||
|
||||
`compose.yaml` at the repo root runs two containers:
|
||||
|
||||
| Service | URL | Notes |
|
||||
|---|---|---|
|
||||
| `server` | http://localhost:13000 | Built from `server/Dockerfile`; reads `.env`; mounts `./data` (SQLite DB `data/liqa.db` + stored files) and `./keys` |
|
||||
| `client` | http://localhost:13001 | Built from `client/Dockerfile`; nginx serves the SPA and proxies `/api/` to `server:3000` |
|
||||
|
||||
Rebuild and restart: `docker compose up -d --build`. Check with `docker compose ps`, `curl localhost:13000/health` and `docker compose logs server`.
|
||||
|
||||
The live database is `data/liqa.db`. Because the schema is synced on startup, back it up before deploying entity changes.
|
||||
|
||||
## Code quality
|
||||
|
||||
Before committing, run and pass all of these (and report the results):
|
||||
|
||||
```bash
|
||||
# server
|
||||
cd server && npm run lint && npx tsc --noEmit -p tsconfig.json && npm test && npm run build
|
||||
# client
|
||||
cd client && npm run lint && npm run build
|
||||
```
|
||||
|
||||
- Lint must stay clean in both packages (no errors, no warnings).
|
||||
- Don't run prettier over whole existing files; several aren't prettier-clean and it produces unrelated diffs. Format only new files or the lines you changed.
|
||||
- Server tests use an in-memory DB, a Playwright mock (`server/test/__mocks__/playwright.ts`), and a temporary files directory per test app (see `server/test/app.harness.ts`).
|
||||
- Import Node.js built-in modules with the `node:` prefix (`node:fs`, `node:path`, `node:crypto`, ...).
|
||||
|
||||
## Committing a new version
|
||||
|
||||
When asked to commit:
|
||||
|
||||
1. **Ask which version to bump** - major, minor or patch - and propose a sensible default based on the changes: patch for fixes and small behavior/default tweaks, minor for new features, major for breaking changes (e.g. changed API or export/import formats that old clients or files can't use).
|
||||
2. Run the code quality checks above.
|
||||
3. Bump `version` in the root `package.json` and in both places at the top of `package-lock.json` (the root entry and `packages[""]`). `server/package.json` and `client/package.json` keep their own versions; don't bump them.
|
||||
4. Add a `## <version> - <YYYY-MM-DD>` entry at the top of `CHANGELOG.md` ("Changes since <previous version>:", then `### Added` / `### Changed` / `### Fixed`). Mark breaking changes with **Breaking:**.
|
||||
5. Update the docs affected by the change (`docs/*.md`, `README.md`, `.env.example`, MCP tool descriptions).
|
||||
6. Build the commit message with the `/git-commit` skill if it is available, following its format and rules. Otherwise use a conventional commit message (`type(scope): subject`, then a bullet list body). Either way, put the version bump in the body as a bullet (e.g. `- bump version to <version>`), not in the subject line. This overrides the skill's rule of putting versions in the subject. Then make the commit with that message.
|
||||
7. **After committing, ask the user whether to rebuild and restart the docker compose containers** (`docker compose up -d --build`); don't do it without confirmation.
|
||||
+7
-1
@@ -1,7 +1,7 @@
|
||||
import { lazy, Suspense } from 'react';
|
||||
import { NavLink, Navigate, Route, Routes } from 'react-router-dom';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { Globe, Monitor, ClipboardList, Activity, KeyRound, Braces } from 'lucide-react';
|
||||
import { Globe, Monitor, ClipboardList, Activity, KeyRound, Braces, Upload } from 'lucide-react';
|
||||
import type { LucideIcon } from 'lucide-react';
|
||||
import styles from './App.module.css';
|
||||
import { SidePanel, ThemeSwitcher } from './ui';
|
||||
@@ -89,6 +89,9 @@ const EditSnippetPage = lazy(() =>
|
||||
const SnippetDetailPage = lazy(() =>
|
||||
import('./pages/snippet/SnippetDetailPage').then((m) => ({ default: m.SnippetDetailPage })),
|
||||
);
|
||||
const ImportPage = lazy(() =>
|
||||
import('./pages/import/ImportPage').then((m) => ({ default: m.ImportPage })),
|
||||
);
|
||||
|
||||
const NAV: ({ path: string; labelKey: string; Icon: LucideIcon } | { separator: true })[] = [
|
||||
{ path: '/runs', labelKey: 'nav.runs', Icon: Activity },
|
||||
@@ -98,6 +101,8 @@ const NAV: ({ path: string; labelKey: string; Icon: LucideIcon } | { separator:
|
||||
{ path: '/snippets', labelKey: 'nav.snippets', Icon: Braces },
|
||||
{ path: '/credentials', labelKey: 'nav.credentials', Icon: KeyRound },
|
||||
{ path: '/environments', labelKey: 'nav.environments', Icon: Globe },
|
||||
{ separator: true },
|
||||
{ path: '/import', labelKey: 'nav.import', Icon: Upload },
|
||||
];
|
||||
|
||||
export default function App() {
|
||||
@@ -163,6 +168,7 @@ export default function App() {
|
||||
<Route path="/credentials/:id/edit" element={<EditCredentialPage />} />
|
||||
<Route path="/credentials/:id" element={<CredentialDetailPage />} />
|
||||
<Route path="/snippets" element={<SnippetsPage />} />
|
||||
<Route path="/import" element={<ImportPage />} />
|
||||
<Route path="/snippets/new" element={<CreateSnippetPage />} />
|
||||
<Route path="/snippets/:id/edit" element={<EditSnippetPage />} />
|
||||
<Route path="/snippets/:id" element={<SnippetDetailPage />} />
|
||||
|
||||
+22
-24
@@ -4,6 +4,7 @@ import type {
|
||||
Environment,
|
||||
FileMetadata,
|
||||
FileListResponse,
|
||||
ImportResult,
|
||||
RunDefaults,
|
||||
ScenarioCredential,
|
||||
Session,
|
||||
@@ -88,12 +89,6 @@ export const credentials = {
|
||||
exportCredential(id: string): Promise<unknown> {
|
||||
return request(`/credentials/${id}/export`);
|
||||
},
|
||||
importCredential(payload: unknown): Promise<Credential> {
|
||||
return request('/credentials/import', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify(payload),
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
// ── Snippets ──────────────────────────────────────────────────────────────────
|
||||
@@ -131,12 +126,6 @@ export const snippets = {
|
||||
exportSnippet(id: string): Promise<unknown> {
|
||||
return request(`/snippets/${id}/export`);
|
||||
},
|
||||
importSnippet(payload: unknown): Promise<Snippet> {
|
||||
return request('/snippets/import', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify(payload),
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
// ── Environments ──────────────────────────────────────────────────────────────
|
||||
@@ -169,12 +158,6 @@ export const environments = {
|
||||
exportEnvironment(id: string): Promise<unknown> {
|
||||
return request(`/environments/${id}/export`);
|
||||
},
|
||||
importEnvironment(payload: unknown): Promise<Environment> {
|
||||
return request('/environments/import', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify(payload),
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
// ── Sessions ──────────────────────────────────────────────────────────────────
|
||||
@@ -276,12 +259,6 @@ export const scenarios = {
|
||||
}
|
||||
return request(`/scenarios/${id}/export?${params.toString()}`);
|
||||
},
|
||||
importScenario(payload: unknown): Promise<Scenario> {
|
||||
return request('/scenarios/import', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify(payload),
|
||||
});
|
||||
},
|
||||
exportE2eTestUrl(id: string): string {
|
||||
return `${BASE_URL}/scenarios/${id}/export-e2e`;
|
||||
},
|
||||
@@ -409,4 +386,25 @@ export const runFiles = {
|
||||
contentUrl(scenarioId: string, runId: string, fileId: string): string {
|
||||
return `${BASE_URL}/scenarios/${scenarioId}/runs/${runId}/files/${fileId}/content`;
|
||||
},
|
||||
remove(scenarioId: string, runId: string, fileId: string): Promise<void> {
|
||||
return request(`/scenarios/${scenarioId}/runs/${runId}/files/${fileId}`, {
|
||||
method: 'DELETE',
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
// ── Import ────────────────────────────────────────────────────────────────────
|
||||
|
||||
export const imports = {
|
||||
/**
|
||||
* Imports any mix of environments, credentials, snippets and scenarios from
|
||||
* YAML (`---`-separated documents, each one item or a list of items).
|
||||
*/
|
||||
yaml(text: string): Promise<ImportResult> {
|
||||
return request('/import', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/yaml' },
|
||||
body: text,
|
||||
});
|
||||
},
|
||||
};
|
||||
@@ -214,3 +214,19 @@ export interface FileListResponse {
|
||||
items: FileMetadata[];
|
||||
total: number;
|
||||
}
|
||||
|
||||
// ── Import ────────────────────────────────────────────────────────────────────
|
||||
|
||||
export type ImportKind = 'environment' | 'credential' | 'snippet' | 'scenario';
|
||||
|
||||
export interface ImportedItem {
|
||||
kind: ImportKind;
|
||||
id: string;
|
||||
name: string;
|
||||
/** Version stored for versioned kinds (snippets, scenarios). */
|
||||
version?: number;
|
||||
}
|
||||
|
||||
export interface ImportResult {
|
||||
imported: ImportedItem[];
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
import type { ChangeEvent } from 'react';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { imports } from '../api';
|
||||
import type { ImportedItem, ImportKind } from '../api';
|
||||
import { useToast } from '../ui';
|
||||
|
||||
/** Detail page path of an imported item. */
|
||||
export function importedItemPath(item: ImportedItem): string {
|
||||
return `/${item.kind}s/${item.id}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a file input `onChange` handler that imports the chosen YAML file
|
||||
* through the central import. When the file holds exactly one item of `kind`
|
||||
* (e.g. a scenario export with its environment), opens that item; otherwise
|
||||
* opens the import page with the full result.
|
||||
*/
|
||||
export function useImportFile(kind: ImportKind) {
|
||||
const navigate = useNavigate();
|
||||
const toast = useToast();
|
||||
const { t } = useTranslation();
|
||||
|
||||
return async (e: ChangeEvent<HTMLInputElement>) => {
|
||||
const file = e.target.files?.[0];
|
||||
if (!file) return;
|
||||
e.target.value = '';
|
||||
try {
|
||||
const result = await imports.yaml(await file.text());
|
||||
const own = result.imported.filter((item) => item.kind === kind);
|
||||
if (own.length === 1) {
|
||||
if (result.imported.length > 1) {
|
||||
toast.success(t('import.imported_count', { count: result.imported.length }));
|
||||
}
|
||||
navigate(importedItemPath(own[0]));
|
||||
} else {
|
||||
navigate('/import', { state: { results: [{ fileName: file.name, result }] } });
|
||||
}
|
||||
} catch {
|
||||
// error toast is already emitted by the API client
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -28,7 +28,24 @@
|
||||
"keys": "Keys",
|
||||
"sessions": "Sessions",
|
||||
"scenarios": "Scenarios",
|
||||
"runs": "Runs"
|
||||
"runs": "Runs",
|
||||
"import": "Import"
|
||||
},
|
||||
"import": {
|
||||
"title": "Import",
|
||||
"action_choose": "Choose files",
|
||||
"description": "Import exported environments, credentials, snippets and scenarios. Each YAML file may hold several items as ---separated documents, and each document may hold one item or a list of items. JSON files work too.",
|
||||
"description_validation": "Every item in a file is checked before anything is imported: if one item is invalid, nothing from that file is imported. Items are imported in dependency order (environments, credentials, snippets, scenarios), and snippets and scenarios keep the version they were exported with.",
|
||||
"imported_count_one": "Imported {{count}} item",
|
||||
"imported_count_other": "Imported {{count}} items",
|
||||
"col_file": "File",
|
||||
"col_kind": "Kind",
|
||||
"col_name": "Name",
|
||||
"col_version": "Version",
|
||||
"kind_environment": "Environment",
|
||||
"kind_credential": "Credential",
|
||||
"kind_snippet": "Snippet",
|
||||
"kind_scenario": "Scenario"
|
||||
},
|
||||
"environments": {
|
||||
"title": "Environments",
|
||||
@@ -334,6 +351,10 @@
|
||||
"expiresAtLabel": "Expires At (optional)",
|
||||
"createdAt": "Created",
|
||||
"download": "Download",
|
||||
"delete": "Delete",
|
||||
"deleteTitle": "Delete file",
|
||||
"confirmDelete": "Are you sure you want to delete \"{{name}}\" from this run?",
|
||||
"deleteSuccess": "File deleted",
|
||||
"expiredTooltip": "File is expired",
|
||||
"empty": "No files uploaded.",
|
||||
"totalCount": "Total: {{count}} file(s)",
|
||||
|
||||
@@ -2,8 +2,8 @@ import { useEffect, useRef, useState } from 'react';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { usePageTitle } from '../../hooks/usePageTitle';
|
||||
import { useImportFile } from '../../hooks/useImportFile';
|
||||
import { Settings, Pencil, Trash2, Plus, Download, KeyRound } from 'lucide-react';
|
||||
import { parse as yamlParse } from 'yaml';
|
||||
import { credentials } from '../../api';
|
||||
import type { Credential } from '../../api';
|
||||
import {
|
||||
@@ -102,7 +102,6 @@ function AddCredentialCard() {
|
||||
export function CredentialsPage() {
|
||||
const { t } = useTranslation();
|
||||
usePageTitle(t('credentials.title'));
|
||||
const navigate = useNavigate();
|
||||
const [items, setItems] = useState<Credential[]>([]);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [deleteId, setDeleteId] = useState<string | null>(null);
|
||||
@@ -136,19 +135,7 @@ export function CredentialsPage() {
|
||||
}
|
||||
};
|
||||
|
||||
const handleImport = async (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||
const file = e.target.files?.[0];
|
||||
if (!file) return;
|
||||
e.target.value = '';
|
||||
try {
|
||||
const text = await file.text();
|
||||
const payload = yamlParse(text) as unknown;
|
||||
const imported = await credentials.importCredential(payload);
|
||||
navigate(`/credentials/${imported.id}`);
|
||||
} catch {
|
||||
// Import errors are silently ignored
|
||||
}
|
||||
};
|
||||
const handleImport = useImportFile('credential');
|
||||
|
||||
return (
|
||||
<div>
|
||||
|
||||
@@ -2,8 +2,8 @@ import { useEffect, useRef, useState } from 'react';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { usePageTitle } from '../../hooks/usePageTitle';
|
||||
import { useImportFile } from '../../hooks/useImportFile';
|
||||
import { Settings, ExternalLink, Pencil, Trash2, Plus, Globe, Download } from 'lucide-react';
|
||||
import { parse as yamlParse } from 'yaml';
|
||||
import { stringify as yamlStringify } from 'yaml';
|
||||
import { environments } from '../../api';
|
||||
import type { Environment } from '../../api';
|
||||
@@ -119,7 +119,6 @@ function AddEnvironmentCard() {
|
||||
export function EnvironmentsPage() {
|
||||
const { t } = useTranslation();
|
||||
usePageTitle(t('environments.title'));
|
||||
const navigate = useNavigate();
|
||||
const [items, setItems] = useState<Environment[]>([]);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [deleteId, setDeleteId] = useState<string | null>(null);
|
||||
@@ -153,19 +152,7 @@ export function EnvironmentsPage() {
|
||||
}
|
||||
};
|
||||
|
||||
const handleImport = async (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||
const file = e.target.files?.[0];
|
||||
if (!file) return;
|
||||
e.target.value = '';
|
||||
try {
|
||||
const text = await file.text();
|
||||
const payload = yamlParse(text) as unknown;
|
||||
const imported = await environments.importEnvironment(payload);
|
||||
navigate(`/environments/${imported.id}`);
|
||||
} catch {
|
||||
// Import errors are silently ignored
|
||||
}
|
||||
};
|
||||
const handleImport = useImportFile('environment');
|
||||
|
||||
return (
|
||||
<div>
|
||||
|
||||
@@ -0,0 +1,116 @@
|
||||
import { useRef, useState, type ChangeEvent } from 'react';
|
||||
import { useLocation, useNavigate } from 'react-router-dom';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { Upload } from 'lucide-react';
|
||||
import { usePageTitle } from '../../hooks/usePageTitle';
|
||||
import { importedItemPath } from '../../hooks/useImportFile';
|
||||
import { imports } from '../../api';
|
||||
import type { ImportedItem, ImportResult } from '../../api';
|
||||
import { Badge, Breadcrumbs, Button, Card, Table, type TableColumn } from '../../ui';
|
||||
import styles from '../Page.module.css';
|
||||
|
||||
interface FileResult {
|
||||
fileName: string;
|
||||
result: ImportResult;
|
||||
}
|
||||
|
||||
type Row = ImportedItem & { fileName: string; rowKey: string };
|
||||
|
||||
export function ImportPage() {
|
||||
const { t } = useTranslation();
|
||||
usePageTitle(t('import.title'));
|
||||
const navigate = useNavigate();
|
||||
const location = useLocation();
|
||||
const fileInputRef = useRef<HTMLInputElement>(null);
|
||||
// List pages hand over the result of an import they ran
|
||||
const [results, setResults] = useState<FileResult[]>(
|
||||
() => (location.state as { results?: FileResult[] } | null)?.results ?? [],
|
||||
);
|
||||
const [importing, setImporting] = useState(false);
|
||||
|
||||
const handleFiles = async (e: ChangeEvent<HTMLInputElement>) => {
|
||||
const files = Array.from(e.target.files ?? []);
|
||||
e.target.value = '';
|
||||
if (files.length === 0) return;
|
||||
setImporting(true);
|
||||
const next: FileResult[] = [];
|
||||
try {
|
||||
for (const file of files) {
|
||||
try {
|
||||
next.push({ fileName: file.name, result: await imports.yaml(await file.text()) });
|
||||
} catch {
|
||||
// error toast is already emitted by the API client; nothing from
|
||||
// this file was imported, continue with the next one
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
setResults(next);
|
||||
setImporting(false);
|
||||
}
|
||||
};
|
||||
|
||||
const rows: Row[] = results.flatMap(({ fileName, result }) =>
|
||||
result.imported.map((item, i) => ({ ...item, fileName, rowKey: `${fileName}-${i}` })),
|
||||
);
|
||||
|
||||
const columns: TableColumn<Row>[] = [
|
||||
{ key: 'fileName', header: t('import.col_file'), render: (r) => r.fileName },
|
||||
{
|
||||
key: 'kind',
|
||||
header: t('import.col_kind'),
|
||||
width: 120,
|
||||
render: (r) => <Badge variant="neutral">{t(`import.kind_${r.kind}`)}</Badge>,
|
||||
},
|
||||
{ key: 'name', header: t('import.col_name'), render: (r) => r.name },
|
||||
{
|
||||
key: 'version',
|
||||
header: t('import.col_version'),
|
||||
width: 90,
|
||||
render: (r) =>
|
||||
r.version != null ? `v${r.version}` : <span className={styles.muted}>–</span>,
|
||||
},
|
||||
];
|
||||
|
||||
return (
|
||||
<div>
|
||||
<div className={styles.pageToolbar}>
|
||||
<Breadcrumbs items={[{ label: t('import.title'), icon: <Upload size={14} /> }]} />
|
||||
<div className={styles.toolbarActions}>
|
||||
<input
|
||||
ref={fileInputRef}
|
||||
type="file"
|
||||
accept=".yaml,.yml,.json"
|
||||
multiple
|
||||
style={{ display: 'none' }}
|
||||
onChange={handleFiles}
|
||||
/>
|
||||
<Button size="sm" onClick={() => fileInputRef.current?.click()} disabled={importing}>
|
||||
<Upload size={14} />
|
||||
{t('import.action_choose')}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<Card>
|
||||
<p>{t('import.description')}</p>
|
||||
<p className={styles.muted}>{t('import.description_validation')}</p>
|
||||
</Card>
|
||||
|
||||
{rows.length > 0 && (
|
||||
<div className={styles.stepsSection}>
|
||||
<h2 className={styles.sectionHeading}>
|
||||
{t('import.imported_count', { count: rows.length })}
|
||||
</h2>
|
||||
<Table<Row>
|
||||
columns={columns}
|
||||
data={rows}
|
||||
rowKey={(r) => r.rowKey}
|
||||
loading={false}
|
||||
emptyMessage=""
|
||||
onRowClick={(r) => navigate(importedItemPath(r))}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -14,7 +14,11 @@ import type {
|
||||
FileMetadata,
|
||||
} from '../../api';
|
||||
import { scenarios } from '../../api';
|
||||
import { ExportLogsModal, type LogExportFormat } from '../../components/modals';
|
||||
import {
|
||||
DeleteConfirmationModal,
|
||||
ExportLogsModal,
|
||||
type LogExportFormat,
|
||||
} from '../../components/modals';
|
||||
import {
|
||||
AutoRefreshIndicator,
|
||||
Badge,
|
||||
@@ -38,6 +42,7 @@ import {
|
||||
ClipboardList,
|
||||
Activity,
|
||||
Download,
|
||||
Trash2,
|
||||
RotateCcw,
|
||||
} from 'lucide-react';
|
||||
import styles from '../Page.module.css';
|
||||
@@ -103,6 +108,8 @@ function RunDetail() {
|
||||
const [exportLogsOpen, setExportLogsOpen] = useState(false);
|
||||
const [exportLogsFormat, setExportLogsFormat] = useState<LogExportFormat>('md');
|
||||
const [exportingLogs, setExportingLogs] = useState(false);
|
||||
const [pendingDeleteFile, setPendingDeleteFile] = useState<FileMetadata | null>(null);
|
||||
const [deletingFile, setDeletingFile] = useState(false);
|
||||
const [repeating, setRepeating] = useState(false);
|
||||
const logSearchRef = useRef('');
|
||||
const LOG_PAGE_SIZE = 25;
|
||||
@@ -167,6 +174,21 @@ function RunDetail() {
|
||||
}
|
||||
};
|
||||
|
||||
const handleDeleteFile = async () => {
|
||||
if (!id || !runId || !pendingDeleteFile) return;
|
||||
setDeletingFile(true);
|
||||
try {
|
||||
await runFiles.remove(id, runId, pendingDeleteFile.id);
|
||||
toast.success(t('files.deleteSuccess'));
|
||||
setPendingDeleteFile(null);
|
||||
await loadArtifacts();
|
||||
} catch {
|
||||
// error toast is already emitted by the API client
|
||||
} finally {
|
||||
setDeletingFile(false);
|
||||
}
|
||||
};
|
||||
|
||||
const manualRefresh = () => {
|
||||
if (!id || !runId) return;
|
||||
runs
|
||||
@@ -611,6 +633,21 @@ function RunDetail() {
|
||||
);
|
||||
},
|
||||
},
|
||||
{
|
||||
key: 'delete',
|
||||
header: '',
|
||||
render: (f) => (
|
||||
<Button
|
||||
variant="secondary"
|
||||
size="sm"
|
||||
title={t('files.delete')}
|
||||
aria-label={t('files.delete')}
|
||||
onClick={() => setPendingDeleteFile(f)}
|
||||
>
|
||||
<Trash2 size={14} />
|
||||
</Button>
|
||||
),
|
||||
},
|
||||
] satisfies TableColumn<FileMetadata>[]
|
||||
}
|
||||
emptyMessage={t('files.empty')}
|
||||
@@ -628,6 +665,15 @@ function RunDetail() {
|
||||
onExport={handleExportLogs}
|
||||
isExporting={exportingLogs}
|
||||
/>
|
||||
|
||||
<DeleteConfirmationModal
|
||||
open={pendingDeleteFile != null}
|
||||
title={t('files.deleteTitle')}
|
||||
message={t('files.confirmDelete', { name: pendingDeleteFile?.name ?? '' })}
|
||||
onClose={() => setPendingDeleteFile(null)}
|
||||
onConfirm={handleDeleteFile}
|
||||
isDeleting={deletingFile}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -82,7 +82,7 @@ export function ScenarioDetailPage() {
|
||||
const [runVersions, setRunVersions] = useState<ScenarioVersion[]>([]);
|
||||
// null = latest
|
||||
const [runVersion, setRunVersion] = useState<number | null>(null);
|
||||
const traceMode = traceModeOverride ?? runDefaults?.traceMode ?? 'on';
|
||||
const traceMode = traceModeOverride ?? runDefaults?.traceMode ?? 'off';
|
||||
const [envs, setEnvs] = useState<Environment[]>([]);
|
||||
const [selectedEnvId, setSelectedEnvId] = useState('');
|
||||
const envInitRef = useRef(false);
|
||||
@@ -99,7 +99,6 @@ export function ScenarioDetailPage() {
|
||||
|
||||
// Files state
|
||||
const [files, setFiles] = useState<FileMetadata[]>([]);
|
||||
const [filesTotal, setFilesTotal] = useState(0);
|
||||
const [filesLoading, setFilesLoading] = useState(false);
|
||||
const [uploadOpen, setUploadOpen] = useState(false);
|
||||
const [uploadFile, setUploadFile] = useState<File | null>(null);
|
||||
@@ -114,7 +113,6 @@ export function ScenarioDetailPage() {
|
||||
try {
|
||||
const result = await scenarioFiles.list(id);
|
||||
setFiles(result.items);
|
||||
setFilesTotal(result.total);
|
||||
} finally {
|
||||
setFilesLoading(false);
|
||||
}
|
||||
|
||||
@@ -2,8 +2,8 @@ import { useCallback, useEffect, useRef, useState } from 'react';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { usePageTitle } from '../../hooks/usePageTitle';
|
||||
import { useImportFile } from '../../hooks/useImportFile';
|
||||
import { Play, Plus, Trash2, Download, ClipboardList } from 'lucide-react';
|
||||
import { parse as yamlParse } from 'yaml';
|
||||
import { environments, scenarios } from '../../api';
|
||||
import type { Environment, Scenario, ScenarioVersion, TraceMode } from '../../api';
|
||||
import { RunScenarioModal } from '../../components/modals';
|
||||
@@ -56,7 +56,7 @@ export function ScenariosPage() {
|
||||
const [runVersions, setRunVersions] = useState<ScenarioVersion[]>([]);
|
||||
// null = latest
|
||||
const [runVersion, setRunVersion] = useState<number | null>(null);
|
||||
const traceMode = traceModeOverride ?? runDefaults?.traceMode ?? 'on';
|
||||
const traceMode = traceModeOverride ?? runDefaults?.traceMode ?? 'off';
|
||||
const [envs, setEnvs] = useState<Environment[]>([]);
|
||||
const [selectedEnvId, setSelectedEnvId] = useState('');
|
||||
|
||||
@@ -159,19 +159,7 @@ export function ScenariosPage() {
|
||||
}
|
||||
};
|
||||
|
||||
const handleImport = async (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||
const file = e.target.files?.[0];
|
||||
if (!file) return;
|
||||
e.target.value = '';
|
||||
try {
|
||||
const text = await file.text();
|
||||
const payload = yamlParse(text) as unknown;
|
||||
const imported = await scenarios.importScenario(payload);
|
||||
navigate(`/scenarios/${imported.id}`);
|
||||
} catch {
|
||||
// Import errors are silently ignored
|
||||
}
|
||||
};
|
||||
const handleImport = useImportFile('scenario');
|
||||
|
||||
const columns: TableColumn<Scenario>[] = [
|
||||
{ key: 'id', header: t('scenarios.col_id'), render: (s) => <UuidBadge id={s.id} />, width: 60 },
|
||||
|
||||
@@ -2,8 +2,8 @@ import { useEffect, useRef, useState } from 'react';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { usePageTitle } from '../../hooks/usePageTitle';
|
||||
import { useImportFile } from '../../hooks/useImportFile';
|
||||
import { Settings, Pencil, Trash2, Plus, Download, Braces } from 'lucide-react';
|
||||
import { parse as yamlParse } from 'yaml';
|
||||
import { snippets } from '../../api';
|
||||
import type { Snippet } from '../../api';
|
||||
import {
|
||||
@@ -117,7 +117,6 @@ function AddSnippetCard() {
|
||||
export function SnippetsPage() {
|
||||
const { t } = useTranslation();
|
||||
usePageTitle(t('snippets.title'));
|
||||
const navigate = useNavigate();
|
||||
const [items, setItems] = useState<Snippet[]>([]);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [deleteId, setDeleteId] = useState<string | null>(null);
|
||||
@@ -151,19 +150,7 @@ export function SnippetsPage() {
|
||||
}
|
||||
};
|
||||
|
||||
const handleImport = async (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||
const file = e.target.files?.[0];
|
||||
if (!file) return;
|
||||
e.target.value = '';
|
||||
try {
|
||||
const text = await file.text();
|
||||
const payload = yamlParse(text) as unknown;
|
||||
const imported = await snippets.importSnippet(payload);
|
||||
navigate(`/snippets/${imported.id}`);
|
||||
} catch {
|
||||
// Import errors are silently ignored
|
||||
}
|
||||
};
|
||||
const handleImport = useImportFile('snippet');
|
||||
|
||||
return (
|
||||
<div>
|
||||
|
||||
File renamed without changes.
+3
-1
@@ -51,6 +51,7 @@ The server currently registers the following tools.
|
||||
| `wait_for_scenario_run` | Wait until run is `pass` or `fail` |
|
||||
| `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`) |
|
||||
| `import_yaml` | Import any mix of environments, credentials, snippets and scenarios from YAML (see "Import" in `scenario.md`) |
|
||||
|
||||
## Snippets
|
||||
|
||||
@@ -77,7 +78,8 @@ The server currently registers the following tools.
|
||||
| Tool | Description |
|
||||
|---|---|
|
||||
| `list_run_files` | List files (artifacts) created during a scenario run (paginated) |
|
||||
| `get_run_file_content` | Retrieve run artifact content as base64 with metadata; run artifacts are read-only and inherit expiry from the run artifact subsystem |
|
||||
| `get_run_file_content` | Retrieve run artifact content as base64 with metadata; run artifact content can't be modified and inherits expiry from the run artifact subsystem |
|
||||
| `delete_run_file` | Delete a file from a run; the stored file is removed once no scenario or run references it (also `DELETE /scenarios/:id/runs/:runId/files/:fileId` and the delete button on the run detail page) |
|
||||
|
||||
## Binary Content Handling
|
||||
|
||||
|
||||
+37
-3
@@ -61,15 +61,49 @@ Exports hold exactly one version and always include its `version` number (the la
|
||||
- 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.
|
||||
|
||||
## Import
|
||||
|
||||
`POST /import` (the Import page in the UI, and the Import buttons on the list pages; the `import_yaml` MCP tool) imports any mix of environments, credentials, snippets and scenarios.
|
||||
|
||||
- Send YAML with `Content-Type: application/yaml`. A file is a stream of `---`-separated documents; each document holds one exported item or a list of items. JSON is valid YAML, and a JSON body (one item or an array) is accepted too.
|
||||
- Every item needs a `kind`: `environment`, `credential`, `snippet` or `scenario`. Snippets and scenarios also need `version` (see above).
|
||||
- All items are validated before anything is imported, so one invalid item means nothing from that request is imported. The error lists every invalid item by its position.
|
||||
- Items are imported in dependency order - environments, credentials, snippets, scenarios - regardless of their order in the file, so a scenario can reference an environment or credential from the same file.
|
||||
- The response lists what was imported: `{ imported: [{ kind, id, name, version? }] }`.
|
||||
|
||||
A scenario export (`GET /scenarios/:id/export`, optionally with its environment and credentials) is in this format, one document per entity, and can be imported back as is.
|
||||
|
||||
```yaml
|
||||
---
|
||||
# Environment: staging
|
||||
kind: environment
|
||||
id: 5b0c…
|
||||
name: staging
|
||||
data:
|
||||
base_url: https://staging.example
|
||||
---
|
||||
# Scenario: Login flow
|
||||
kind: scenario
|
||||
id: 9e1f…
|
||||
version: 3
|
||||
name: Login flow
|
||||
environmentId: 5b0c…
|
||||
steps:
|
||||
- title: Open login page
|
||||
execCode: await context.page.goto(context.getEnv("base_url"));
|
||||
```
|
||||
|
||||
## 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.
|
||||
A run can record 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
|
||||
- `on`: keep the trace of every run
|
||||
- `retain-on-failure`: keep traces only for runs that failed
|
||||
- `off`: do not record traces
|
||||
- `off` (default): do not record traces
|
||||
|
||||
Traces are off by default because they often reach ~10 MB per run.
|
||||
|
||||
Traces are run artifacts, so they expire after `FILE_RUN_EXPIRATION_DAYS` like other run files.
|
||||
|
||||
|
||||
Generated
+2
-2
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "liqa",
|
||||
"version": "1.16.0",
|
||||
"version": "1.18.0",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "liqa",
|
||||
"version": "1.16.0",
|
||||
"version": "1.18.0",
|
||||
"workspaces": [
|
||||
"server",
|
||||
"client"
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "liqa",
|
||||
"version": "1.16.0",
|
||||
"version": "1.18.0",
|
||||
"private": true,
|
||||
"workspaces": [
|
||||
"server",
|
||||
|
||||
@@ -13,6 +13,7 @@ import { FileModule } from "./file/file.module";
|
||||
import { ScenarioFileEntity } from "./file/scenario-file.entity";
|
||||
import { ScenarioRunFileEntity } from "./file/scenario-run-file.entity";
|
||||
import { HealthModule } from "./health/health.module";
|
||||
import { ImportModule } from "./import/import.module";
|
||||
import { McpModule } from "./mcp/mcp.module";
|
||||
import { ScenarioCredentialEntity } from "./scenario/scenario-credential.entity";
|
||||
import { ScenarioRunLogEntity } from "./scenario/scenario-run-log.entity";
|
||||
@@ -66,6 +67,7 @@ import { SnippetModule } from "./snippet/snippet.module";
|
||||
ScenarioModule,
|
||||
SnippetModule,
|
||||
FileModule,
|
||||
ImportModule,
|
||||
McpModule,
|
||||
HealthModule,
|
||||
],
|
||||
|
||||
@@ -6,7 +6,7 @@ import {
|
||||
import { expect as playwrightExpect } from "@playwright/test";
|
||||
import { parse } from "acorn";
|
||||
import type { BrowserContext, Page } from "playwright";
|
||||
import { URL } from "url";
|
||||
import { URL } from "node:url";
|
||||
import { downloadFile as downloadFileImpl } from "../common/file-downloader";
|
||||
import { TraceLogger } from "../common/trace-logger";
|
||||
import type { EnvironmentData } from "../environment/environment.entity";
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
import type { NestExpressApplication } from "@nestjs/platform-express";
|
||||
|
||||
/** Content types accepted as raw YAML text (e.g. by `POST /import`). */
|
||||
export const YAML_CONTENT_TYPES = [
|
||||
"application/yaml",
|
||||
"application/x-yaml",
|
||||
"text/yaml",
|
||||
"text/x-yaml",
|
||||
];
|
||||
|
||||
/** Registers body parsers beyond Nest's default JSON/urlencoded ones. */
|
||||
export function configureBodyParsers(app: NestExpressApplication): void {
|
||||
app.useBodyParser("text", { type: YAML_CONTENT_TYPES, limit: "10mb" });
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
import * as https from "https";
|
||||
import * as http from "http";
|
||||
import { URL } from "url";
|
||||
import * as https from "node:https";
|
||||
import * as http from "node:http";
|
||||
import { URL } from "node:url";
|
||||
|
||||
const MAX_FILE_SIZE = 100 * 1024 * 1024; // 100 MB
|
||||
const TIMEOUT_MS = 30000; // 30 seconds
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { AsyncLocalStorage } from "async_hooks";
|
||||
import { AsyncLocalStorage } from "node:async_hooks";
|
||||
|
||||
export interface TraceStore {
|
||||
traceId: string;
|
||||
|
||||
@@ -56,7 +56,8 @@ export class AppConfig {
|
||||
FILE_CLEANUP_CRON: string = "0 3 * * *";
|
||||
|
||||
@IsEnum(TraceMode)
|
||||
PLAYWRIGHT_TRACE_MODE: TraceMode = TraceMode.On;
|
||||
// Off by default: traces with screenshots and snapshots easily reach ~10 MB per run
|
||||
PLAYWRIGHT_TRACE_MODE: TraceMode = TraceMode.Off;
|
||||
}
|
||||
|
||||
export function validateAppConfig(config: Record<string, unknown>): AppConfig {
|
||||
|
||||
@@ -2,9 +2,9 @@ import { Injectable, OnModuleInit } from "@nestjs/common";
|
||||
import { ConfigService } from "@nestjs/config";
|
||||
import { SchedulerRegistry } from "@nestjs/schedule";
|
||||
import { InjectRepository } from "@nestjs/typeorm";
|
||||
import * as crypto from "crypto";
|
||||
import * as fs from "fs/promises";
|
||||
import * as path from "path";
|
||||
import * as crypto from "node:crypto";
|
||||
import * as fs from "node:fs/promises";
|
||||
import * as path from "node:path";
|
||||
import { CronJob } from "cron";
|
||||
import { Repository } from "typeorm";
|
||||
import { TraceLogger } from "../common/trace-logger";
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
import { BadRequestException, Body, Controller, Post } from "@nestjs/common";
|
||||
import {
|
||||
ApiBody,
|
||||
ApiConsumes,
|
||||
ApiOperation,
|
||||
ApiResponse,
|
||||
ApiTags,
|
||||
} from "@nestjs/swagger";
|
||||
import { YAML_CONTENT_TYPES } from "../common/body-parsers";
|
||||
import { ImportService } from "./import.service";
|
||||
|
||||
@ApiTags("import")
|
||||
@Controller("import")
|
||||
export class ImportController {
|
||||
constructor(private readonly importService: ImportService) {}
|
||||
|
||||
@Post()
|
||||
@ApiOperation({
|
||||
summary:
|
||||
"Import any mix of environments, credentials, snippets and scenarios",
|
||||
description:
|
||||
"Send YAML (Content-Type application/yaml): `---`-separated documents, each holding one exported item or a list of them. " +
|
||||
"A JSON array of items (or a single item) is accepted too. Every item needs a `kind`. " +
|
||||
"All items are validated before anything is imported, then imported in dependency order: environments, credentials, snippets, scenarios.",
|
||||
})
|
||||
@ApiConsumes(...YAML_CONTENT_TYPES, "application/json")
|
||||
@ApiBody({ schema: { type: "string" } })
|
||||
@ApiResponse({ status: 201, description: "Imported items" })
|
||||
@ApiResponse({
|
||||
status: 400,
|
||||
description: "Invalid YAML or items; nothing was imported",
|
||||
})
|
||||
import(@Body() body: unknown) {
|
||||
if (typeof body === "string") {
|
||||
return this.importService.importYaml(body);
|
||||
}
|
||||
if (Array.isArray(body)) return this.importService.importItems(body);
|
||||
if (body && typeof body === "object" && Object.keys(body).length > 0) {
|
||||
return this.importService.importItems([body]);
|
||||
}
|
||||
throw new BadRequestException(
|
||||
"Send YAML with Content-Type application/yaml, or a JSON item or array of items",
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
import { Module } from "@nestjs/common";
|
||||
import { CredentialModule } from "../credential/credential.module";
|
||||
import { EnvironmentModule } from "../environment/environment.module";
|
||||
import { ScenarioModule } from "../scenario/scenario.module";
|
||||
import { SnippetModule } from "../snippet/snippet.module";
|
||||
import { ImportController } from "./import.controller";
|
||||
import { ImportService } from "./import.service";
|
||||
|
||||
@Module({
|
||||
imports: [EnvironmentModule, CredentialModule, SnippetModule, ScenarioModule],
|
||||
controllers: [ImportController],
|
||||
providers: [ImportService],
|
||||
exports: [ImportService],
|
||||
})
|
||||
export class ImportModule {}
|
||||
@@ -0,0 +1,176 @@
|
||||
import { BadRequestException, Injectable } from "@nestjs/common";
|
||||
import { ClassConstructor, plainToInstance } from "class-transformer";
|
||||
import { validateSync, ValidationError } from "class-validator";
|
||||
import { parseAllDocuments } from "yaml";
|
||||
import { CredentialExportDto } from "../credential/dto/credential-export.dto";
|
||||
import { CredentialService } from "../credential/credential.service";
|
||||
import { EnvironmentExportDto } from "../environment/dto/environment-export.dto";
|
||||
import { EnvironmentService } from "../environment/environment.service";
|
||||
import { ScenarioExportDto } from "../scenario/dto/scenario-export.dto";
|
||||
import { ScenarioService } from "../scenario/scenario.service";
|
||||
import { SnippetExportDto } from "../snippet/dto/snippet-export.dto";
|
||||
import { SnippetService } from "../snippet/snippet.service";
|
||||
|
||||
export type ImportKind = "environment" | "credential" | "snippet" | "scenario";
|
||||
|
||||
/** Import order: later kinds may reference earlier ones (scenarios → environments/credentials). */
|
||||
const KIND_ORDER: ImportKind[] = [
|
||||
"environment",
|
||||
"credential",
|
||||
"snippet",
|
||||
"scenario",
|
||||
];
|
||||
|
||||
const DTO_BY_KIND: Record<ImportKind, ClassConstructor<object>> = {
|
||||
environment: EnvironmentExportDto,
|
||||
credential: CredentialExportDto,
|
||||
snippet: SnippetExportDto,
|
||||
scenario: ScenarioExportDto,
|
||||
};
|
||||
|
||||
export interface ImportedItem {
|
||||
kind: ImportKind;
|
||||
id: string;
|
||||
name: string;
|
||||
/** Version stored for versioned kinds (snippets, scenarios). */
|
||||
version?: number;
|
||||
}
|
||||
|
||||
export interface ImportResult {
|
||||
imported: ImportedItem[];
|
||||
}
|
||||
|
||||
function formatErrors(errors: ValidationError[], prefix = ""): string[] {
|
||||
return errors.flatMap((e) => {
|
||||
const field = prefix ? `${prefix}.${e.property}` : e.property;
|
||||
return [
|
||||
...Object.values(e.constraints ?? {}).map((msg) => `${field}: ${msg}`),
|
||||
...formatErrors(e.children ?? [], field),
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Imports any mix of exported environments, credentials, snippets and
|
||||
* scenarios in one go. Each item must carry its `kind`.
|
||||
*/
|
||||
@Injectable()
|
||||
export class ImportService {
|
||||
constructor(
|
||||
private readonly environmentService: EnvironmentService,
|
||||
private readonly credentialService: CredentialService,
|
||||
private readonly snippetService: SnippetService,
|
||||
private readonly scenarioService: ScenarioService,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* Parses a YAML stream: `---`-separated documents, each holding a single
|
||||
* item or a list of items. JSON is valid YAML, so JSON input works too.
|
||||
*/
|
||||
parseYaml(text: string): unknown[] {
|
||||
const docs = parseAllDocuments(text);
|
||||
const items: unknown[] = [];
|
||||
docs.forEach((doc, index) => {
|
||||
if (doc.errors.length > 0) {
|
||||
throw new BadRequestException(
|
||||
`YAML document ${index + 1}: ${doc.errors[0].message}`,
|
||||
);
|
||||
}
|
||||
const value: unknown = doc.toJS();
|
||||
if (value == null) return; // empty document, e.g. a trailing `---`
|
||||
items.push(...(Array.isArray(value) ? value : [value]));
|
||||
});
|
||||
return items;
|
||||
}
|
||||
|
||||
async importYaml(text: string): Promise<ImportResult> {
|
||||
return this.importItems(this.parseYaml(text));
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates every item before importing any, then imports them in
|
||||
* dependency order (environments, credentials, snippets, scenarios).
|
||||
*/
|
||||
async importItems(items: unknown[]): Promise<ImportResult> {
|
||||
if (items.length === 0) {
|
||||
throw new BadRequestException("Nothing to import");
|
||||
}
|
||||
|
||||
const errors: string[] = [];
|
||||
const validated: { kind: ImportKind; dto: object }[] = [];
|
||||
items.forEach((item, index) => {
|
||||
const label = `Item ${index + 1}`;
|
||||
if (item == null || typeof item !== "object" || Array.isArray(item)) {
|
||||
errors.push(`${label}: must be an object`);
|
||||
return;
|
||||
}
|
||||
const kind = (item as { kind?: unknown }).kind;
|
||||
if (typeof kind !== "string" || !(kind in DTO_BY_KIND)) {
|
||||
errors.push(
|
||||
`${label}: kind must be one of ${KIND_ORDER.join(", ")} (got ${JSON.stringify(kind)})`,
|
||||
);
|
||||
return;
|
||||
}
|
||||
const dto = plainToInstance(DTO_BY_KIND[kind as ImportKind], item);
|
||||
const itemErrors = formatErrors(validateSync(dto, { whitelist: true }));
|
||||
if (itemErrors.length > 0) {
|
||||
errors.push(`${label} (${kind}): ${itemErrors.join("; ")}`);
|
||||
return;
|
||||
}
|
||||
validated.push({ kind: kind as ImportKind, dto });
|
||||
});
|
||||
if (errors.length > 0) {
|
||||
throw new BadRequestException(errors);
|
||||
}
|
||||
|
||||
const imported: ImportedItem[] = [];
|
||||
for (const kind of KIND_ORDER) {
|
||||
for (const item of validated.filter((v) => v.kind === kind)) {
|
||||
imported.push(await this.importOne(kind, item.dto));
|
||||
}
|
||||
}
|
||||
return { imported };
|
||||
}
|
||||
|
||||
private async importOne(
|
||||
kind: ImportKind,
|
||||
dto: object,
|
||||
): Promise<ImportedItem> {
|
||||
switch (kind) {
|
||||
case "environment": {
|
||||
const env = await this.environmentService.importEnvironment(
|
||||
dto as EnvironmentExportDto,
|
||||
);
|
||||
return { kind, id: env.id, name: env.name };
|
||||
}
|
||||
case "credential": {
|
||||
const cred = await this.credentialService.importCredential(
|
||||
dto as CredentialExportDto,
|
||||
);
|
||||
return { kind, id: cred.id, name: cred.name };
|
||||
}
|
||||
case "snippet": {
|
||||
const snippet = await this.snippetService.importSnippet(
|
||||
dto as SnippetExportDto,
|
||||
);
|
||||
return {
|
||||
kind,
|
||||
id: snippet.id,
|
||||
name: snippet.alias,
|
||||
version: snippet.version,
|
||||
};
|
||||
}
|
||||
case "scenario": {
|
||||
const scenario = await this.scenarioService.importScenario(
|
||||
dto as ScenarioExportDto,
|
||||
);
|
||||
return {
|
||||
kind,
|
||||
id: scenario.id,
|
||||
name: scenario.name,
|
||||
version: scenario.version,
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,7 @@ import {
|
||||
Injectable,
|
||||
NestInterceptor,
|
||||
} from "@nestjs/common";
|
||||
import * as crypto from "crypto";
|
||||
import * as crypto from "node:crypto";
|
||||
import type { Request } from "express";
|
||||
import { Observable } from "rxjs";
|
||||
import { traceStorage } from "../common/trace-context";
|
||||
|
||||
+4
-1
@@ -1,9 +1,11 @@
|
||||
import { RequestMethod, ValidationPipe } from "@nestjs/common";
|
||||
import { ConfigService } from "@nestjs/config";
|
||||
import { NestFactory } from "@nestjs/core";
|
||||
import type { NestExpressApplication } from "@nestjs/platform-express";
|
||||
import { DocumentBuilder, SwaggerModule } from "@nestjs/swagger";
|
||||
import { name as pkgName, version as pkgVersion } from "../package.json";
|
||||
import { AppModule } from "./app.module";
|
||||
import { configureBodyParsers } from "./common/body-parsers";
|
||||
import { TraceLogger } from "./common/trace-logger";
|
||||
import { AppConfig } from "./config/app.config";
|
||||
import { HttpExceptionFilter } from "./filters/http-exception.filter";
|
||||
@@ -28,7 +30,7 @@ process.on("unhandledRejection", (reason) => {
|
||||
async function bootstrap() {
|
||||
const API_PREFIX = "api/v1";
|
||||
const logger = new TraceLogger("Bootstrap");
|
||||
const app = await NestFactory.create(AppModule, {
|
||||
const app = await NestFactory.create<NestExpressApplication>(AppModule, {
|
||||
logger: new TraceLogger("Bootstrap", { timestamp: true }),
|
||||
});
|
||||
|
||||
@@ -40,6 +42,7 @@ async function bootstrap() {
|
||||
],
|
||||
});
|
||||
|
||||
configureBodyParsers(app);
|
||||
app.useGlobalPipes(new ValidationPipe({ transform: true }));
|
||||
app.useGlobalFilters(new HttpExceptionFilter());
|
||||
app.useGlobalInterceptors(new TraceInterceptor(), new LoggingInterceptor());
|
||||
|
||||
@@ -6,6 +6,7 @@ import { EnvironmentModule } from "../environment/environment.module";
|
||||
import { ScenarioModule } from "../scenario/scenario.module";
|
||||
import { SessionModule } from "../session/session.module";
|
||||
import { SnippetModule } from "../snippet/snippet.module";
|
||||
import { ImportModule } from "../import/import.module";
|
||||
import { McpController } from "./mcp.controller";
|
||||
import { McpService } from "./mcp.service";
|
||||
|
||||
@@ -18,6 +19,7 @@ import { McpService } from "./mcp.service";
|
||||
CodeExecutorModule,
|
||||
ScenarioModule,
|
||||
SnippetModule,
|
||||
ImportModule,
|
||||
],
|
||||
controllers: [McpController],
|
||||
providers: [McpService],
|
||||
|
||||
@@ -14,6 +14,7 @@ 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 { ImportService } from "../import/import.service";
|
||||
|
||||
import pkg from "../../package.json";
|
||||
|
||||
@@ -29,6 +30,7 @@ export class McpService {
|
||||
private readonly scenarioService: ScenarioService,
|
||||
private readonly e2eExportService: E2eExportService,
|
||||
private readonly snippetService: SnippetService,
|
||||
private readonly importService: ImportService,
|
||||
) {}
|
||||
|
||||
private createServer(): McpServer {
|
||||
@@ -1307,6 +1309,35 @@ export class McpService {
|
||||
},
|
||||
);
|
||||
|
||||
server.registerTool(
|
||||
"import_yaml",
|
||||
{
|
||||
description:
|
||||
"Import any mix of exported environments, credentials, snippets and scenarios from YAML: `---`-separated documents, each holding one item or a list of items, each with a `kind`. All items are validated before anything is imported; versioned items (snippets, scenarios) must include `version`",
|
||||
inputSchema: {
|
||||
yaml: z.string().describe("YAML text, e.g. the content of an export file"),
|
||||
},
|
||||
},
|
||||
async ({ yaml }) => {
|
||||
try {
|
||||
const result = await this.importService.importYaml(yaml);
|
||||
return {
|
||||
content: [{ type: "text" as const, text: JSON.stringify(result) }],
|
||||
};
|
||||
} catch (err) {
|
||||
const response = (err as { getResponse?: () => unknown }).getResponse?.();
|
||||
const message =
|
||||
response && typeof response === "object" && "message" in response
|
||||
? JSON.stringify((response as { message: unknown }).message)
|
||||
: (err as Error).message;
|
||||
return {
|
||||
isError: true,
|
||||
content: [{ type: "text" as const, text: message }],
|
||||
};
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
server.registerTool(
|
||||
"export_e2e_test",
|
||||
{
|
||||
@@ -1407,12 +1438,12 @@ export class McpService {
|
||||
};
|
||||
}
|
||||
|
||||
// Create a mock Multer file object for the service
|
||||
// Build the subset of a Multer file object the service uses
|
||||
const file = {
|
||||
buffer,
|
||||
originalname: name,
|
||||
mimetype: mimeType || "application/octet-stream",
|
||||
} as any;
|
||||
};
|
||||
|
||||
// Call the service method
|
||||
const result = await this.scenarioService.uploadFile(
|
||||
@@ -1556,6 +1587,37 @@ export class McpService {
|
||||
},
|
||||
);
|
||||
|
||||
server.registerTool(
|
||||
"delete_run_file",
|
||||
{
|
||||
description:
|
||||
"Delete a file from a run. The stored file is removed once nothing else references it",
|
||||
inputSchema: {
|
||||
scenarioId: z.uuid().describe("Scenario ID"),
|
||||
runId: z.uuid().describe("Run ID"),
|
||||
fileId: z.uuid().describe("File ID (from list_run_files)"),
|
||||
},
|
||||
},
|
||||
async ({ scenarioId, runId, fileId }) => {
|
||||
try {
|
||||
await this.scenarioService.deleteRunFile(scenarioId, runId, fileId);
|
||||
return {
|
||||
content: [
|
||||
{
|
||||
type: "text" as const,
|
||||
text: `File ${fileId} deleted from run ${runId}`,
|
||||
},
|
||||
],
|
||||
};
|
||||
} catch (err) {
|
||||
return {
|
||||
isError: true,
|
||||
content: [{ type: "text" as const, text: (err as Error).message }],
|
||||
};
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
server.registerTool(
|
||||
"get_run_file_content",
|
||||
{
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
import { Injectable } from "@nestjs/common";
|
||||
// archiver is a CommonJS `export =` function without a `default` export, and
|
||||
// esModuleInterop is off, so TypeScript's import-require form is the one that works
|
||||
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
||||
import archiver = require("archiver");
|
||||
import { resolveUsedSnippetAliases } from "../common/snippet-usage";
|
||||
import { SnippetService } from "../snippet/snippet.service";
|
||||
@@ -145,7 +148,7 @@ export class E2eExportService {
|
||||
const timeoutMs = (scenarioTimeoutSeconds ?? DEFAULT_SCENARIO_TIMEOUT_SEC) * 1000;
|
||||
return `import { defineConfig } from "@playwright/test";
|
||||
import * as dotenv from "dotenv";
|
||||
import * as path from "path";
|
||||
import * as path from "node:path";
|
||||
|
||||
dotenv.config({ path: path.resolve(__dirname, ".env") });
|
||||
|
||||
@@ -232,13 +235,13 @@ the scenario are bundled under \`files/\` and served locally by
|
||||
|
||||
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";
|
||||
import * as fs from "node:fs";
|
||||
import * as path from "node:path";
|
||||
import * as crypto from "node:crypto";
|
||||
import * as http from "node:http";
|
||||
import * as https from "node:https";
|
||||
import { URL } from "node:url";
|
||||
import { randomUUID } from "node:crypto";
|
||||
|
||||
// Credential data resolved from this scenario's aliases at export time.
|
||||
// Stored in credentials.json (gitignored) - contains sensitive values.
|
||||
|
||||
@@ -2,10 +2,10 @@ 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 * as crypto from "node:crypto";
|
||||
import * as fs from "node:fs/promises";
|
||||
import * as os from "node:os";
|
||||
import * as path from "node:path";
|
||||
import { Effect } from "effect";
|
||||
import type { Browser, BrowserContext, Page } from "playwright";
|
||||
import { chromium } from "playwright";
|
||||
|
||||
@@ -25,7 +25,7 @@ import { CreateScenarioStepDto } from "./dto/create-scenario-step.dto";
|
||||
import { CreateScenarioDto } from "./dto/create-scenario.dto";
|
||||
import { ScenarioQueryDto } from "./dto/pagination-query.dto";
|
||||
import { RunsQueryDto } from "./dto/runs-query.dto";
|
||||
import { ExportEntity } from "./dto/scenario-export.dto";
|
||||
import { ExportEntity, ScenarioExportDto } 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";
|
||||
@@ -52,7 +52,9 @@ export class ScenarioController {
|
||||
@ApiOperation({ summary: "Import a scenario from an export payload (single object or array)" })
|
||||
@ApiResponse({ status: 201, description: "Scenario imported" })
|
||||
importScenario(@Body() payload: unknown) {
|
||||
return this.scenarioService.importScenario(payload as any);
|
||||
return this.scenarioService.importScenario(
|
||||
payload as ScenarioExportDto | ExportEntity[],
|
||||
);
|
||||
}
|
||||
|
||||
@Get()
|
||||
@@ -148,20 +150,20 @@ export class ScenarioController {
|
||||
version,
|
||||
});
|
||||
res.setHeader("Content-Type", "application/yaml; charset=utf-8");
|
||||
// Serialize as YAML stream: each entity separated by a comment header
|
||||
// Serialize as a YAML stream: one `---` document per entity, each with a
|
||||
// comment naming it. POST /import reads this format back.
|
||||
const kindLabels: Record<string, string> = {
|
||||
environment: "Environment",
|
||||
credential: "Credential",
|
||||
scenario: "Scenario",
|
||||
};
|
||||
const parts = (entities as ExportEntity[]).map((entity) => {
|
||||
const label = kindLabels[entity.kind ?? ""] ?? entity.kind ?? "Entity";
|
||||
const comment = `# --- ${label}: ${
|
||||
(entity as any).name ?? (entity as any).id ?? ""
|
||||
} ---`;
|
||||
return `${comment}\n${yamlStringify(entity)}`;
|
||||
});
|
||||
return parts.join("\n");
|
||||
return (entities as ExportEntity[])
|
||||
.map((entity) => {
|
||||
const label = kindLabels[entity.kind ?? ""] ?? entity.kind ?? "Entity";
|
||||
const comment = `# ${label}: ${entity.name ?? entity.id ?? ""}`;
|
||||
return `---\n${comment}\n${yamlStringify(entity)}`;
|
||||
})
|
||||
.join("");
|
||||
}
|
||||
|
||||
@Get(":id/export-e2e")
|
||||
@@ -434,4 +436,17 @@ export class ScenarioController {
|
||||
) {
|
||||
return this.scenarioService.getRunFileContent(id, runId, fileId, res);
|
||||
}
|
||||
|
||||
@Delete(":id/runs/:runId/files/:fileId")
|
||||
@HttpCode(204)
|
||||
@ApiOperation({ summary: "Delete a file from a run" })
|
||||
@ApiResponse({ status: 204, description: "File deleted" })
|
||||
@ApiResponse({ status: 404, description: "Scenario, run, or file not found" })
|
||||
deleteRunFile(
|
||||
@Param("id", ParseUUIDPipe) id: string,
|
||||
@Param("runId", ParseUUIDPipe) runId: string,
|
||||
@Param("fileId", ParseUUIDPipe) fileId: string,
|
||||
) {
|
||||
return this.scenarioService.deleteRunFile(id, runId, fileId);
|
||||
}
|
||||
}
|
||||
@@ -7,8 +7,8 @@ import {
|
||||
} from "@nestjs/common";
|
||||
import { ConfigService } from "@nestjs/config";
|
||||
import { InjectRepository } from "@nestjs/typeorm";
|
||||
import * as fs from "fs/promises";
|
||||
import * as path from "path";
|
||||
import * as fs from "node:fs/promises";
|
||||
import * as path from "node:path";
|
||||
import { Like, Repository } from "typeorm";
|
||||
import {
|
||||
PaginatedResult,
|
||||
@@ -21,7 +21,10 @@ import {
|
||||
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 {
|
||||
FileMetadata,
|
||||
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";
|
||||
@@ -83,6 +86,12 @@ function stepsSnapshot(steps: ScenarioStepEntity[]): ScenarioStepSnapshot[] {
|
||||
}));
|
||||
}
|
||||
|
||||
/** File metadata as returned by the scenario/run file listing endpoints. */
|
||||
export interface FileListResult {
|
||||
items: Omit<FileMetadata, "path">[];
|
||||
total: number;
|
||||
}
|
||||
|
||||
export type UsedSnippet = SnippetEntity & {
|
||||
/** Version pinned via `runSnippet("alias@N")`, or null for the latest. */
|
||||
pinnedVersion: number | null;
|
||||
@@ -941,9 +950,9 @@ export class ScenarioService implements OnModuleInit {
|
||||
|
||||
async uploadFile(
|
||||
scenarioId: string,
|
||||
file: MulterFile,
|
||||
file: Pick<MulterFile, "buffer" | "originalname" | "mimetype">,
|
||||
expiresAtStr?: string,
|
||||
): Promise<any> {
|
||||
): Promise<Omit<FileMetadata, "path" | "sha256">> {
|
||||
// Verify scenario exists
|
||||
await this.findOne(scenarioId);
|
||||
|
||||
@@ -990,7 +999,7 @@ export class ScenarioService implements OnModuleInit {
|
||||
scenarioId: string,
|
||||
limit?: number,
|
||||
offset?: number,
|
||||
): Promise<any> {
|
||||
): Promise<FileListResult> {
|
||||
// Verify scenario exists
|
||||
await this.findOne(scenarioId);
|
||||
|
||||
@@ -1088,7 +1097,7 @@ export class ScenarioService implements OnModuleInit {
|
||||
runId: string,
|
||||
limit?: number,
|
||||
offset?: number,
|
||||
): Promise<any> {
|
||||
): Promise<FileListResult> {
|
||||
// Verify scenario and run exist
|
||||
await this.findOne(scenarioId);
|
||||
const run = await this.runRepo.findOneBy({ id: runId, scenarioId });
|
||||
@@ -1116,6 +1125,28 @@ export class ScenarioService implements OnModuleInit {
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a file from a run. The stored file itself is deleted once no
|
||||
* scenario or run references it any more.
|
||||
*/
|
||||
async deleteRunFile(
|
||||
scenarioId: string,
|
||||
runId: string,
|
||||
fileId: string,
|
||||
): Promise<void> {
|
||||
await this.findOne(scenarioId); // 404 guard
|
||||
const run = await this.runRepo.findOneBy({ id: runId, scenarioId });
|
||||
if (!run) {
|
||||
throw new NotFoundException(`Run ${runId} not found in scenario ${scenarioId}`);
|
||||
}
|
||||
const link = await this.scenarioRunFileRepo.findOneBy({ runId, fileId });
|
||||
if (!link) {
|
||||
throw new NotFoundException(`File ${fileId} not found in run ${runId}`);
|
||||
}
|
||||
await this.scenarioRunFileRepo.delete(link.id);
|
||||
await this.fileStorageService.deleteFile(fileId);
|
||||
}
|
||||
|
||||
async getRunFileContent(
|
||||
scenarioId: string,
|
||||
runId: string,
|
||||
|
||||
@@ -18,7 +18,7 @@ const makeContext = () => ({
|
||||
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");
|
||||
await require("node:fs/promises").writeFile(opts.path, "fake trace zip");
|
||||
}
|
||||
}),
|
||||
},
|
||||
|
||||
@@ -1,8 +1,16 @@
|
||||
import { INestApplication, ValidationPipe } from "@nestjs/common";
|
||||
import * as fs from "node:fs";
|
||||
import * as os from "node:os";
|
||||
import * as path from "node:path";
|
||||
import { Test, TestingModule } from "@nestjs/testing";
|
||||
import { TypeOrmModule } from "@nestjs/typeorm";
|
||||
import { ConfigModule } from "@nestjs/config";
|
||||
import type { NestExpressApplication } from "@nestjs/platform-express";
|
||||
import { ScheduleModule } from "@nestjs/schedule";
|
||||
|
||||
import { configureBodyParsers } from "../src/common/body-parsers";
|
||||
import { ImportModule } from "../src/import/import.module";
|
||||
|
||||
jest.mock("@nestjs/common", () => {
|
||||
const actual = jest.requireActual("@nestjs/common");
|
||||
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
||||
@@ -55,6 +63,11 @@ import { ScenarioFileEntity } from "../src/file/scenario-file.entity";
|
||||
import { ScenarioRunFileEntity } from "../src/file/scenario-run-file.entity";
|
||||
|
||||
export async function buildTestApp(): Promise<INestApplication> {
|
||||
// Each test app stores files in its own temp dir: suites run in parallel and
|
||||
// some clean up their files dir, which must not affect other suites.
|
||||
const filesDir = fs.mkdtempSync(path.join(os.tmpdir(), "liqa-test-files-"));
|
||||
process.env.FILES_DIR = filesDir;
|
||||
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
imports: [
|
||||
ConfigModule.forRoot({
|
||||
@@ -89,15 +102,23 @@ export async function buildTestApp(): Promise<INestApplication> {
|
||||
SessionModule,
|
||||
EnvironmentModule,
|
||||
ScenarioModule,
|
||||
ImportModule,
|
||||
McpModule,
|
||||
],
|
||||
controllers: [HealthController],
|
||||
}).compile();
|
||||
|
||||
const app = module.createNestApplication();
|
||||
const app = module.createNestApplication<NestExpressApplication>();
|
||||
configureBodyParsers(app);
|
||||
app.useGlobalPipes(new ValidationPipe({ transform: true, whitelist: true }));
|
||||
app.useGlobalFilters(new HttpExceptionFilter());
|
||||
app.useGlobalInterceptors(new LoggingInterceptor());
|
||||
await app.init();
|
||||
|
||||
const close = app.close.bind(app);
|
||||
app.close = async () => {
|
||||
await close();
|
||||
fs.rmSync(filesDir, { recursive: true, force: true });
|
||||
};
|
||||
return app;
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
import { INestApplication } from "@nestjs/common";
|
||||
import { getRepositoryToken } from "@nestjs/typeorm";
|
||||
import * as http from "http";
|
||||
import * as fs from "fs/promises";
|
||||
import * as http from "node:http";
|
||||
import * as fs from "node:fs/promises";
|
||||
import { Repository } from "typeorm";
|
||||
import { buildTestApp } from "./app.harness";
|
||||
import { FileStorageService } from "../src/file/file-storage.service";
|
||||
@@ -13,6 +13,7 @@ import { ScenarioStepEntity } from "../src/scenario/scenario-step.entity";
|
||||
import { ScenarioRunEntity } from "../src/scenario/scenario-run.entity";
|
||||
import { ScenarioRunStepEntity } from "../src/scenario/scenario-run-step.entity";
|
||||
import { ScenarioSchedulerService } from "../src/scenario/scenario-scheduler.service";
|
||||
import type { AddressInfo } from "node:net";
|
||||
|
||||
describe("Exec Context File Methods Integration Tests", () => {
|
||||
let app: INestApplication;
|
||||
@@ -57,7 +58,7 @@ describe("Exec Context File Methods Integration Tests", () => {
|
||||
|
||||
// Start a test HTTP server for downloadFile tests
|
||||
testServer = await createTestServer();
|
||||
testServerUrl = `http://localhost:${(testServer.address() as any).port}`;
|
||||
testServerUrl = `http://localhost:${(testServer.address() as AddressInfo).port}`;
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
@@ -69,7 +70,7 @@ describe("Exec Context File Methods Integration Tests", () => {
|
||||
// Clean up files directory
|
||||
try {
|
||||
await fs.rm(filesDir, { recursive: true, force: true });
|
||||
} catch (err) {
|
||||
} catch {
|
||||
// Ignore errors if directory doesn't exist
|
||||
}
|
||||
|
||||
@@ -223,7 +224,9 @@ describe("Exec Context File Methods Integration Tests", () => {
|
||||
expect(output.total).toBeGreaterThanOrEqual(1);
|
||||
|
||||
// Find the uploaded file in the output
|
||||
const foundFile = output.items.find((f: any) => f.id === uploadedFile.id);
|
||||
const foundFile = output.items.find(
|
||||
(f: { id: string; name: string }) => f.id === uploadedFile.id,
|
||||
);
|
||||
expect(foundFile).toBeDefined();
|
||||
expect(foundFile.name).toBe("test-file.txt");
|
||||
expect(foundFile.mimeType).toBe("text/plain");
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
import { INestApplication } from "@nestjs/common";
|
||||
import { getRepositoryToken } from "@nestjs/typeorm";
|
||||
import request from "supertest";
|
||||
import * as fs from "fs/promises";
|
||||
import * as fs from "node:fs/promises";
|
||||
import { Repository } from "typeorm";
|
||||
import { buildTestApp } from "./app.harness";
|
||||
import { FileStorageService } from "../src/file/file-storage.service";
|
||||
import { FileEntity } from "../src/file/file.entity";
|
||||
import { ScenarioRunFileEntity } from "../src/file/scenario-run-file.entity";
|
||||
import { ScenarioEntity } from "../src/scenario/scenario.entity";
|
||||
import { ScenarioRunEntity } from "../src/scenario/scenario-run.entity";
|
||||
|
||||
@@ -15,6 +16,7 @@ describe("File Controller Integration Tests", () => {
|
||||
let fileRepo: Repository<FileEntity>;
|
||||
let scenarioRepo: Repository<ScenarioEntity>;
|
||||
let runRepo: Repository<ScenarioRunEntity>;
|
||||
let runFileRepo: Repository<ScenarioRunFileEntity>;
|
||||
let filesDir: string;
|
||||
|
||||
beforeAll(async () => {
|
||||
@@ -27,6 +29,9 @@ describe("File Controller Integration Tests", () => {
|
||||
runRepo = app.get<Repository<ScenarioRunEntity>>(
|
||||
getRepositoryToken(ScenarioRunEntity),
|
||||
);
|
||||
runFileRepo = app.get<Repository<ScenarioRunFileEntity>>(
|
||||
getRepositoryToken(ScenarioRunFileEntity),
|
||||
);
|
||||
|
||||
// Get the files directory from the service
|
||||
filesDir = fileStorageService.getAbsolutePath("");
|
||||
@@ -36,7 +41,7 @@ describe("File Controller Integration Tests", () => {
|
||||
// Clean up files directory
|
||||
try {
|
||||
await fs.rm(filesDir, { recursive: true, force: true });
|
||||
} catch (err) {
|
||||
} catch {
|
||||
// Ignore errors if directory doesn't exist
|
||||
}
|
||||
await app.close();
|
||||
@@ -146,7 +151,9 @@ describe("File Controller Integration Tests", () => {
|
||||
expect(res.body.items.length).toBeGreaterThanOrEqual(1);
|
||||
expect(res.body.total).toBeGreaterThanOrEqual(1);
|
||||
|
||||
const file = res.body.items.find((f: any) => f.name === "listed.txt");
|
||||
const file = res.body.items.find(
|
||||
(f: { id: string; name: string }) => f.name === "listed.txt",
|
||||
);
|
||||
expect(file).toBeDefined();
|
||||
expect(file.id).toBeDefined();
|
||||
expect(file.mimeType).toBe("text/plain");
|
||||
@@ -274,7 +281,9 @@ describe("File Controller Integration Tests", () => {
|
||||
expect(Array.isArray(res.body.items)).toBe(true);
|
||||
expect(res.body.total).toBeGreaterThanOrEqual(1);
|
||||
|
||||
const artifact = res.body.items.find((f: any) => f.id === savedFile.id);
|
||||
const artifact = res.body.items.find(
|
||||
(f: { id: string; name: string; size: number }) => f.id === savedFile.id,
|
||||
);
|
||||
expect(artifact).toBeDefined();
|
||||
expect(artifact.name).toBe("artifact.txt");
|
||||
expect(artifact.size).toBe(fileBuffer.length);
|
||||
@@ -335,12 +344,83 @@ describe("File Controller Integration Tests", () => {
|
||||
});
|
||||
});
|
||||
|
||||
// ── DELETE /scenarios/:id/runs/:runId/files/:fileId ───────────────────────
|
||||
|
||||
describe("DELETE /scenarios/:id/runs/:runId/files/:fileId", () => {
|
||||
async function createArtifact(runId: string, name = "to-delete.txt") {
|
||||
return fileStorageService.createAndSaveRunArtifact(
|
||||
runId,
|
||||
Buffer.from("delete me"),
|
||||
name,
|
||||
"text/plain",
|
||||
);
|
||||
}
|
||||
|
||||
it("removes the file from the run and deletes the stored file", async () => {
|
||||
const scenario = await createScenario("run-file-delete");
|
||||
const run = await createRun(scenario.id);
|
||||
const file = await createArtifact(run.id);
|
||||
const physicalPath = fileStorageService.getAbsolutePath(file.filePath);
|
||||
|
||||
await request(app.getHttpServer())
|
||||
.delete(`/scenarios/${scenario.id}/runs/${run.id}/files/${file.id}`)
|
||||
.expect(204);
|
||||
|
||||
const list = await request(app.getHttpServer())
|
||||
.get(`/scenarios/${scenario.id}/runs/${run.id}/files`)
|
||||
.expect(200);
|
||||
expect(list.body.items).toHaveLength(0);
|
||||
expect(await fileRepo.findOneBy({ id: file.id })).toBeNull();
|
||||
await expect(fs.access(physicalPath)).rejects.toThrow();
|
||||
});
|
||||
|
||||
it("keeps the stored file while another run still references it", async () => {
|
||||
const scenario = await createScenario("run-file-delete-shared");
|
||||
const run = await createRun(scenario.id);
|
||||
const otherRun = await createRun(scenario.id);
|
||||
const file = await createArtifact(run.id, "shared.txt");
|
||||
await runFileRepo.save(
|
||||
runFileRepo.create({ runId: otherRun.id, fileId: file.id }),
|
||||
);
|
||||
|
||||
await request(app.getHttpServer())
|
||||
.delete(`/scenarios/${scenario.id}/runs/${run.id}/files/${file.id}`)
|
||||
.expect(204);
|
||||
|
||||
expect(await fileRepo.findOneBy({ id: file.id })).not.toBeNull();
|
||||
await request(app.getHttpServer())
|
||||
.get(
|
||||
`/scenarios/${scenario.id}/runs/${otherRun.id}/files/${file.id}/content`,
|
||||
)
|
||||
.expect(200);
|
||||
});
|
||||
|
||||
it("returns 404 for a file that belongs to a different run", async () => {
|
||||
const scenario = await createScenario("run-file-delete-mismatch");
|
||||
const run = await createRun(scenario.id);
|
||||
const otherRun = await createRun(scenario.id);
|
||||
const file = await createArtifact(otherRun.id);
|
||||
|
||||
await request(app.getHttpServer())
|
||||
.delete(`/scenarios/${scenario.id}/runs/${run.id}/files/${file.id}`)
|
||||
.expect(404);
|
||||
expect(await fileRepo.findOneBy({ id: file.id })).not.toBeNull();
|
||||
});
|
||||
|
||||
it("returns 404 when the run does not exist", async () => {
|
||||
const scenario = await createScenario("run-file-delete-no-run");
|
||||
await request(app.getHttpServer())
|
||||
.delete(
|
||||
`/scenarios/${scenario.id}/runs/00000000-0000-0000-0000-000000000000/files/00000000-0000-0000-0000-000000000000`,
|
||||
)
|
||||
.expect(404);
|
||||
});
|
||||
});
|
||||
|
||||
// ── File cleanup ───────────────────────────────────────────────────────────
|
||||
|
||||
describe("File cleanup", () => {
|
||||
it("removes expired files from disk and database", async () => {
|
||||
const scenario = await createScenario("cleanup-test");
|
||||
|
||||
// Upload a file with a past expiration date
|
||||
const fileBuffer = Buffer.from("to be cleaned up");
|
||||
const savedFile = await fileStorageService.saveFile(
|
||||
@@ -367,13 +447,11 @@ describe("File Controller Integration Tests", () => {
|
||||
fail("File should have been deleted");
|
||||
} catch (err) {
|
||||
// Expected: file not found
|
||||
expect((err as any).code).toBe("ENOENT");
|
||||
expect((err as NodeJS.ErrnoException).code).toBe("ENOENT");
|
||||
}
|
||||
});
|
||||
|
||||
it("does not delete files with future expiration dates", async () => {
|
||||
const scenario = await createScenario("no-cleanup-test");
|
||||
|
||||
// Upload a file with a future expiration date
|
||||
const fileBuffer = Buffer.from("should not be cleaned");
|
||||
const futureDate = new Date(Date.now() + 24 * 60 * 60 * 1000);
|
||||
@@ -397,8 +475,6 @@ describe("File Controller Integration Tests", () => {
|
||||
});
|
||||
|
||||
it("does not delete files without expiration dates", async () => {
|
||||
const scenario = await createScenario("no-expire-test");
|
||||
|
||||
// Upload a file without expiration
|
||||
const fileBuffer = Buffer.from("permanent file");
|
||||
const savedFile = await fileStorageService.saveFile(
|
||||
|
||||
@@ -0,0 +1,219 @@
|
||||
/**
|
||||
* Integration tests for the central import (`POST /import`) and the
|
||||
* multi-document YAML scenario export it reads back.
|
||||
*/
|
||||
|
||||
import { INestApplication } from "@nestjs/common";
|
||||
import request from "supertest";
|
||||
import { DataSource } from "typeorm";
|
||||
import { parseAllDocuments } from "yaml";
|
||||
import { buildTestApp } from "./app.harness";
|
||||
import { CredentialEntity } from "../src/credential/credential.entity";
|
||||
import { EnvironmentEntity } from "../src/environment/environment.entity";
|
||||
import { ScenarioService } from "../src/scenario/scenario.service";
|
||||
|
||||
describe("Central import", () => {
|
||||
let app: INestApplication;
|
||||
let dataSource: DataSource;
|
||||
let scenarioService: ScenarioService;
|
||||
|
||||
beforeAll(async () => {
|
||||
app = await buildTestApp();
|
||||
dataSource = app.get(DataSource);
|
||||
scenarioService = app.get(ScenarioService);
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
await app.close();
|
||||
});
|
||||
|
||||
const uniq = () => Math.random().toString(36).slice(2, 8);
|
||||
|
||||
function postYaml(yaml: string) {
|
||||
return request(app.getHttpServer())
|
||||
.post("/import")
|
||||
.set("Content-Type", "application/yaml")
|
||||
.send(yaml);
|
||||
}
|
||||
|
||||
it("imports every kind from a multi-document YAML in dependency order", async () => {
|
||||
const envId = crypto.randomUUID();
|
||||
const credId = crypto.randomUUID();
|
||||
const snippetAlias = `imp-${uniq()}`;
|
||||
// Scenario first in the file: it references the environment and credential
|
||||
const yaml = `---
|
||||
kind: scenario
|
||||
name: imported-${uniq()}
|
||||
version: 1
|
||||
environmentId: ${envId}
|
||||
credentials:
|
||||
- credentialId: ${credId}
|
||||
alias: main
|
||||
steps:
|
||||
- title: use snippet
|
||||
execCode: return context.runSnippet("${snippetAlias}");
|
||||
---
|
||||
kind: snippet
|
||||
alias: ${snippetAlias}
|
||||
title: Imported snippet
|
||||
version: 2
|
||||
code: return 1;
|
||||
---
|
||||
kind: credential
|
||||
id: ${credId}
|
||||
name: imported-cred
|
||||
data: '{"token":"t"}'
|
||||
---
|
||||
kind: environment
|
||||
id: ${envId}
|
||||
name: imported-env-${uniq()}
|
||||
data:
|
||||
base_url: https://example.test
|
||||
`;
|
||||
const res = await postYaml(yaml).expect(201);
|
||||
const kinds = res.body.imported.map((i: { kind: string }) => i.kind);
|
||||
expect(kinds).toEqual(["environment", "credential", "snippet", "scenario"]);
|
||||
|
||||
const scenario = res.body.imported[3];
|
||||
expect(scenario.version).toBe(1);
|
||||
const sc = await scenarioService.findOne(scenario.id);
|
||||
expect(sc.environmentId).toBe(envId);
|
||||
expect(sc.scenarioCredentials.map((c) => c.credentialId)).toEqual([credId]);
|
||||
expect(res.body.imported[2]).toMatchObject({
|
||||
name: snippetAlias,
|
||||
version: 2,
|
||||
});
|
||||
});
|
||||
|
||||
it("accepts a document holding a list of items", async () => {
|
||||
const yaml = `- kind: credential
|
||||
name: list-a-${uniq()}
|
||||
- kind: credential
|
||||
name: list-b-${uniq()}
|
||||
`;
|
||||
const res = await postYaml(yaml).expect(201);
|
||||
expect(res.body.imported).toHaveLength(2);
|
||||
});
|
||||
|
||||
it("accepts a JSON array", async () => {
|
||||
const res = await request(app.getHttpServer())
|
||||
.post("/import")
|
||||
.send([{ kind: "credential", name: `json-${uniq()}` }])
|
||||
.expect(201);
|
||||
expect(res.body.imported[0].kind).toBe("credential");
|
||||
});
|
||||
|
||||
it("imports nothing when any item is invalid", async () => {
|
||||
const envName = `not-imported-${uniq()}`;
|
||||
const yaml = `---
|
||||
kind: environment
|
||||
name: ${envName}
|
||||
data: {}
|
||||
---
|
||||
kind: snippet
|
||||
alias: no-version-${uniq()}
|
||||
code: return 1;
|
||||
---
|
||||
kind: gadget
|
||||
name: what
|
||||
`;
|
||||
const res = await postYaml(yaml).expect(400);
|
||||
const message = JSON.stringify(res.body);
|
||||
expect(message).toContain("Item 2 (snippet)");
|
||||
expect(message).toContain("version");
|
||||
expect(message).toContain("Item 3");
|
||||
const envRepo = dataSource.getRepository(EnvironmentEntity);
|
||||
expect(await envRepo.findOneBy({ name: envName })).toBeNull();
|
||||
});
|
||||
|
||||
it("rejects invalid YAML", async () => {
|
||||
const res = await postYaml("kind: scenario\n bad: [indent").expect(400);
|
||||
expect(JSON.stringify(res.body)).toContain("YAML document 1");
|
||||
});
|
||||
|
||||
it("rejects an empty body", async () => {
|
||||
await postYaml("").expect(400);
|
||||
});
|
||||
|
||||
describe("scenario export round trip", () => {
|
||||
it("exports one YAML document per entity and imports it back", async () => {
|
||||
const envRepo = dataSource.getRepository(EnvironmentEntity);
|
||||
const env = await envRepo.save(
|
||||
envRepo.create({ name: `rt-env-${uniq()}`, data: { a: "1" } }),
|
||||
);
|
||||
const credRepo = dataSource.getRepository(CredentialEntity);
|
||||
const cred = await credRepo.save(
|
||||
credRepo.create({ name: "rt-cred", data: null }),
|
||||
);
|
||||
const sc = await scenarioService.create({
|
||||
name: `rt-${uniq()}`,
|
||||
environmentId: env.id,
|
||||
});
|
||||
await scenarioService.createStep(sc.id, { execCode: "return 1;" });
|
||||
await scenarioService.addScenarioCredential(sc.id, {
|
||||
credentialId: cred.id,
|
||||
alias: "c",
|
||||
});
|
||||
|
||||
const exported = await request(app.getHttpServer())
|
||||
.get(
|
||||
`/scenarios/${sc.id}/export?includeEnvironment=true&credentialIds=${cred.id}`,
|
||||
)
|
||||
.expect(200);
|
||||
const docs = parseAllDocuments(exported.text);
|
||||
expect(docs.map((d) => d.errors)).toEqual([[], [], []]);
|
||||
expect(docs.map((d) => (d.toJS() as { kind: string }).kind)).toEqual([
|
||||
"environment",
|
||||
"credential",
|
||||
"scenario",
|
||||
]);
|
||||
|
||||
const res = await postYaml(exported.text).expect(201);
|
||||
expect(res.body.imported.map((i: { id: string }) => i.id)).toEqual([
|
||||
env.id,
|
||||
cred.id,
|
||||
sc.id,
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("import_yaml MCP tool", () => {
|
||||
async function mcpCall(name: string, args: Record<string, unknown>) {
|
||||
const res = await request(app.getHttpServer())
|
||||
.post("/mcp")
|
||||
.set("Accept", "application/json, text/event-stream")
|
||||
.send({
|
||||
jsonrpc: "2.0",
|
||||
id: 1,
|
||||
method: "tools/call",
|
||||
params: { name, arguments: args },
|
||||
});
|
||||
const text = res.text.startsWith("event:")
|
||||
? res.text
|
||||
.split("\n")
|
||||
.find((l) => l.startsWith("data:"))!
|
||||
.slice(5)
|
||||
: res.text;
|
||||
return JSON.parse(text).result as {
|
||||
isError?: boolean;
|
||||
content: { text: string }[];
|
||||
};
|
||||
}
|
||||
|
||||
it("imports items from YAML text", async () => {
|
||||
const result = await mcpCall("import_yaml", {
|
||||
yaml: `kind: credential\nname: mcp-${uniq()}\n`,
|
||||
});
|
||||
expect(result.isError).toBeFalsy();
|
||||
expect(JSON.parse(result.content[0].text).imported).toHaveLength(1);
|
||||
});
|
||||
|
||||
it("returns the validation errors as an MCP error", async () => {
|
||||
const result = await mcpCall("import_yaml", {
|
||||
yaml: `kind: snippet\nalias: x\ncode: return 1;\n`,
|
||||
});
|
||||
expect(result.isError).toBe(true);
|
||||
expect(result.content[0].text).toContain("version");
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,7 +1,7 @@
|
||||
import { INestApplication } from "@nestjs/common";
|
||||
import { getRepositoryToken } from "@nestjs/typeorm";
|
||||
import request from "supertest";
|
||||
import * as http from "http";
|
||||
import * as http from "node:http";
|
||||
import { Repository } from "typeorm";
|
||||
import { buildTestApp } from "./app.harness";
|
||||
import { ScenarioEntity } from "../src/scenario/scenario.entity";
|
||||
@@ -9,6 +9,7 @@ import { ScenarioStepEntity } from "../src/scenario/scenario-step.entity";
|
||||
import { ScenarioRunEntity } from "../src/scenario/scenario-run.entity";
|
||||
import { ScenarioRunStepEntity } from "../src/scenario/scenario-run-step.entity";
|
||||
import { ScenarioSchedulerService } from "../src/scenario/scenario-scheduler.service";
|
||||
import type { AddressInfo } from "node:net";
|
||||
|
||||
/**
|
||||
* MCP controller integration tests.
|
||||
@@ -50,7 +51,7 @@ describe("McpController", () => {
|
||||
|
||||
// Start a test HTTP server for downloadFile tests
|
||||
testServer = await createTestServer();
|
||||
testServerUrl = `http://localhost:${(testServer.address() as any).port}`;
|
||||
testServerUrl = `http://localhost:${(testServer.address() as AddressInfo).port}`;
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
@@ -593,12 +594,8 @@ describe("McpController", () => {
|
||||
total: number;
|
||||
};
|
||||
|
||||
// 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",
|
||||
]);
|
||||
// Traces are off by default, so the script's artifact is the only file
|
||||
expect(list.total).toBe(1);
|
||||
const artifact = list.items.find((f) => f.name === "artifact.bin")!;
|
||||
expect(artifact.mimeType).toBe("application/octet-stream");
|
||||
expect(artifact.expiresAt).not.toBeNull();
|
||||
@@ -615,6 +612,42 @@ describe("McpController", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("delete_run_file", () => {
|
||||
it("deletes a run artifact so it is no longer listed", async () => {
|
||||
const { sc, run } = await createRunArtifactFixture("mcp-run-file-delete");
|
||||
const listFiles = async () =>
|
||||
JSON.parse(
|
||||
(
|
||||
(await mcpCall("list_run_files", { scenarioId: sc.id, runId: run.id }))
|
||||
.rpc.result as { content: { text: string }[] }
|
||||
).content[0].text,
|
||||
) as { items: Array<{ id: string; name: string }>; total: number };
|
||||
|
||||
const file = (await listFiles()).items.find((f) => f.name === "artifact.bin")!;
|
||||
const { status, rpc } = await mcpCall("delete_run_file", {
|
||||
scenarioId: sc.id,
|
||||
runId: run.id,
|
||||
fileId: file.id,
|
||||
});
|
||||
expect(status).toBe(200);
|
||||
const result = rpc.result as { isError?: boolean; content: { text: string }[] };
|
||||
expect(result.isError).toBeFalsy();
|
||||
expect(result.content[0].text).toContain(file.id);
|
||||
expect((await listFiles()).items.map((f) => f.id)).not.toContain(file.id);
|
||||
});
|
||||
|
||||
it("returns an MCP error for a file not in the run", async () => {
|
||||
const { sc, run } = await createRunArtifactFixture("mcp-run-file-delete-missing");
|
||||
const { status, rpc } = await mcpCall("delete_run_file", {
|
||||
scenarioId: sc.id,
|
||||
runId: run.id,
|
||||
fileId: "00000000-0000-0000-0000-000000000000",
|
||||
});
|
||||
expect(status).toBe(200);
|
||||
expect((rpc.result as { isError: boolean }).isError).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe("get_run_file_content", () => {
|
||||
it("returns run artifact bytes as base64 for a valid file", async () => {
|
||||
const { sc, run } = await createRunArtifactFixture("mcp-run-file-content-test");
|
||||
|
||||
@@ -111,14 +111,17 @@ describe("ScenarioSchedulerService Playwright traces", () => {
|
||||
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;");
|
||||
it("stores the configured default trace mode (off) when none is given", async () => {
|
||||
const runId = await runScenario(
|
||||
"trace-default",
|
||||
"throw new Error('boom');",
|
||||
);
|
||||
const [row] = await dataSource.query(
|
||||
`SELECT traceMode FROM scenario_runs WHERE id = ?`,
|
||||
[runId],
|
||||
);
|
||||
expect(row.traceMode).toBe("on");
|
||||
expect(await traceArtifacts(runId)).toHaveLength(1);
|
||||
expect(row.traceMode).toBe("off");
|
||||
expect(await traceArtifacts(runId)).toHaveLength(0);
|
||||
});
|
||||
|
||||
it("falls back to the configured mode for runs without a stored trace mode", async () => {
|
||||
@@ -128,7 +131,13 @@ describe("ScenarioSchedulerService Playwright traces", () => {
|
||||
const env = await envRepo.save(
|
||||
envRepo.create({ name: "trace-null-mode-env", data: {} }),
|
||||
);
|
||||
const run = await scenarioService.createRun(sc.id, env.id);
|
||||
const run = await scenarioService.createRun(
|
||||
sc.id,
|
||||
env.id,
|
||||
false,
|
||||
TraceMode.On,
|
||||
);
|
||||
// Legacy runs have no stored mode; they must use the configured default (off)
|
||||
await dataSource.query(
|
||||
`UPDATE scenario_runs SET traceMode = NULL WHERE id = ?`,
|
||||
[run.id],
|
||||
@@ -141,7 +150,7 @@ describe("ScenarioSchedulerService Playwright traces", () => {
|
||||
while (activeRuns.has(run.id) && Date.now() < deadline) {
|
||||
await new Promise((r) => setTimeout(r, 20));
|
||||
}
|
||||
expect(await traceArtifacts(run.id)).toHaveLength(1);
|
||||
expect(await traceArtifacts(run.id)).toHaveLength(0);
|
||||
});
|
||||
|
||||
describe("HTTP", () => {
|
||||
@@ -150,7 +159,7 @@ describe("ScenarioSchedulerService Playwright traces", () => {
|
||||
"/scenarios/run-defaults",
|
||||
);
|
||||
expect(res.status).toBe(200);
|
||||
expect(res.body).toEqual({ traceMode: "on" });
|
||||
expect(res.body).toEqual({ traceMode: "off" });
|
||||
});
|
||||
|
||||
it("POST /scenarios/:id/run stores the requested trace mode", async () => {
|
||||
|
||||
Reference in new issue
Block a user