Compare commits

...
Author SHA1 Message Date
ars9 81164f8494 feat: export e2e tests for a chosen scenario version
CI / changes (pull_request) Successful in 14s
CI / server (pull_request) Successful in 2m25s
CI / client (pull_request) Successful in 1m35s
CI / image (pull_request) Skipped
- GET /scenarios/:id/export-e2e and the export_e2e_test MCP tool take
  an optional version, defaulting to the latest
- build the test project from that version's steps, name and timeout
- put the version in the zip name (<scenario>-vN-e2e-test.zip), the
  generated package name and the README heading
- the Export e2e test button exports the version being viewed
- document the e2e export in scenario.md and mcp.md
2026-10-08 18:37:33 +03:00
ars9 14763103cf chore(release): cut minor release
CI / server (push) Successful in 1m7s
CI / changes (push) Skipped
CI / client (push) Successful in 1m23s
CI / image (push) Successful in 1m59s
- bump version to 1.25.0
- add browser notifications for scenario runs to the changelog
2026-10-07 19:23:01 +03:00
ars9 78f4c35d56 docs(claude): forbid co-author trailers and issue refs in commits
CI / changes (push) Successful in 6s
CI / server (push) Skipped
CI / client (push) Skipped
CI / image (push) Skipped
- keep issue references like Closes #12 for pull request descriptions
2026-10-07 19:22:02 +03:00
ars9 4b050fbdc4 Merge pull request 'Browser notifications' (#14) from feat/browser-notifications into master
CI / changes (push) Successful in 6s
CI / server (push) Successful in 3m4s
CI / client (push) Successful in 1m33s
CI / image (push) Skipped
Reviewed-on: #14
2026-10-07 19:20:59 +03:00
ars9 a93b3ef835 fix(client): keep run notifications connected in Firefox
CI / changes (pull_request) Successful in 6s
CI / server (pull_request) Successful in 1m16s
CI / client (pull_request) Successful in 1m28s
CI / image (pull_request) Skipped
- reopen the run events stream with backoff when the browser closes it for good (Firefox drops quiet connections after a network change)
- enable notifications when the permission is granted outside the bell, unless turned off explicitly
- follow permission changes made in the browser's site settings
- highlight the bell while notifications are on
2026-10-07 19:04:59 +03:00
ars9 d7eb018245 feat: browser notifications for scenario runs
- add RunEventsService and emit run.started / run.finished from the scheduler
- stream run events over SSE at GET /api/v1/scenarios/runs/events with a heartbeat
- add useRunNotifications hook and NotificationToggle (opt-in bell in the side panel footer)
- refresh runs lists when a run finishes
- document the events stream and notifications

Closes #12
2026-10-07 18:20:30 +03:00
ars9 968a8e470b chore(release): cut patch release
CI / server (push) Successful in 1m14s
CI / changes (push) Skipped
CI / client (push) Successful in 1m23s
CI / image (push) Successful in 1m52s
- bump version to 1.24.4
- add changelog entry for versioned export filenames and the
  install script terminal fix
2026-10-07 17:38:11 +03:00
ars9 3c8def3814 Merge pull request 'feat(client): include version in exported scenario and snippet filenames' (#13) from feat/export-version-filename into master
CI / changes (push) Successful in 6s
CI / server (push) Skipped
CI / client (push) Successful in 1m15s
CI / image (push) Skipped
Reviewed-on: #13
2026-10-07 17:36:55 +03:00
ars9 6e5da08719 feat(client): include version in exported scenario and snippet filenames
CI / changes (pull_request) Successful in 10s
CI / server (pull_request) Skipped
CI / client (pull_request) Successful in 1m21s
CI / image (pull_request) Skipped
- request the exact version being exported via ?version=N so file
  content always matches the filename
- name downloads <scenario>-v<N>.yaml and snippet-<alias>-v<N>.yaml
2026-10-07 17:34:21 +03:00
ars9 1abd95f9e1 Merge pull request 'fix(install): read prompts from the terminal and start liqa' (#11) from fix/install-tty into master
CI / changes (push) Successful in 6s
CI / server (push) Skipped
CI / client (push) Skipped
CI / image (push) Skipped
Reviewed-on: #11
2026-10-02 15:53:43 +03:00
28 changed files with 708 additions and 32 deletions

No files matched your search

+25
View File
@@ -2,6 +2,31 @@
All notable changes to this project will be documented in this file.
## 1.25.0 - 2026-10-07
Changes since 1.24.4:
### Added
- Browser notifications for scenario runs: the UI shows "Run started / passed / failed: <scenario>" notifications for runs started from the UI, the REST API, MCP or the scheduler; clicking one opens the run. Turn them on with the bell button in the side panel footer (granting the permission from the browser's prompt or site settings works too). Notifications need a secure context (HTTPS or `localhost`).
- `GET /api/v1/scenarios/runs/events`: a server-sent events stream of run lifecycle events (`run.started`, `run.finished`) with a periodic `ping` heartbeat.
### Changed
- Runs lists refresh as soon as a run finishes while notifications are on.
## 1.24.4 - 2026-10-07
Changes since 1.24.3:
### Changed
- Exported scenario and snippet files include the exported version in their filename: `<scenario name>-v<N>.yaml` and `snippet-<alias>-v<N>.yaml`.
### Fixed
- `scripts/install.sh` reads prompts from the terminal, so `curl ... | bash` installs no longer consume the script's own lines as answers (it falls back to defaults when there is no terminal). It also checks that Docker, the compose plugin and the daemon work, and starts liqa with `docker compose up -d`, printing the manual start command if a check or the start fails.
## 1.24.3 - 2026-10-02
Changes since 1.24.2:
+2
View File
@@ -31,6 +31,8 @@ The live database is `data/liqa.db`. The container applies pending migrations be
Never commit directly to `master` when implementing a feature, chore or bug fix: create a separate branch for the work first, forked from `master`. These commits don't change the version or `CHANGELOG.md`; the branch is merged back to `master` through a pull request. Only release commits (see "Releasing a new version") are made on `master`.
Never add a `Co-Authored-By` trailer to commit messages. Don't put issue references like `Closes #12` in commit messages either; they belong only in the pull request description.
When committing on a work branch, also update the docs affected by the change (`docs/*.md`, `README.md`, `.env.example`, MCP tool descriptions) in the same branch.
## Code quality
@@ -0,0 +1,17 @@
import type { Meta, StoryObj } from '@storybook/react-vite';
import { fn } from 'storybook/test';
import { NotificationToggle } from '../../src/ui/NotificationToggle/NotificationToggle';
const meta: Meta<typeof NotificationToggle> = {
title: 'UI/NotificationToggle',
component: NotificationToggle,
parameters: { layout: 'centered' },
tags: ['autodocs'],
args: { onToggle: fn() },
};
export default meta;
type Story = StoryObj<typeof NotificationToggle>;
export const Off: Story = { args: { state: 'off' } };
export const On: Story = { args: { state: 'on' } };
export const Blocked: Story = { args: { state: 'blocked' } };
+6
View File
@@ -36,6 +36,12 @@
min-height: 100%;
}
.footerButtons {
display: flex;
align-items: center;
gap: var(--space-1);
}
.sideFooter {
margin-top: auto;
padding: var(--space-3) var(--space-2) var(--space-2);
+9 -2
View File
@@ -4,9 +4,10 @@ import { useTranslation } from 'react-i18next';
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';
import { NotificationToggle, SidePanel, ThemeSwitcher } from './ui';
import liqaLogo from './assets/liqa.svg';
import { useManifest } from './hooks/useManifest';
import { useRunNotifications } from './hooks/useRunNotifications';
const EnvironmentsPage = lazy(() =>
import('./pages/environment/EnvironmentsPage').then((m) => ({ default: m.EnvironmentsPage })),
@@ -109,6 +110,7 @@ const NAV: ({ path: string; labelKey: string; Icon: LucideIcon } | { separator:
export default function App() {
const { t } = useTranslation();
const { version } = useManifest();
const notifications = useRunNotifications();
return (
<div className={styles.shell}>
@@ -141,7 +143,12 @@ export default function App() {
</nav>
<div className={styles.sideFooter}>
<ThemeSwitcher />
<div className={styles.footerButtons}>
<ThemeSwitcher />
{notifications && (
<NotificationToggle state={notifications.state} onToggle={notifications.toggle} />
)}
</div>
<div className={styles.version}>
<span
title={
+18 -5
View File
@@ -28,6 +28,9 @@ const BASE_URL = ((import.meta.env.VITE_API_URL as string | undefined) ?? '/api/
'',
);
/** URL of the server-sent events stream of run lifecycle events. */
export const RUN_EVENTS_URL = `${BASE_URL}/scenarios/runs/events`;
async function request<T>(path: string, init?: RequestInit): Promise<T> {
let res: Response;
try {
@@ -123,8 +126,9 @@ export const snippets = {
versions(id: string): Promise<SnippetVersion[]> {
return request(`/snippets/${id}/versions`);
},
exportSnippet(id: string): Promise<unknown> {
return request(`/snippets/${id}/export`);
exportSnippet(id: string, version?: number): Promise<unknown> {
const query = version === undefined ? '' : `?version=${version}`;
return request(`/snippets/${id}/export${query}`);
},
};
@@ -247,7 +251,12 @@ export const scenarios = {
},
exportScenario(
id: string,
options: { includeEnvironment: boolean; credentialIds: string[]; snippetIds: string[] } = {
options: {
includeEnvironment: boolean;
credentialIds: string[];
snippetIds: string[];
version?: number;
} = {
includeEnvironment: false,
credentialIds: [],
snippetIds: [],
@@ -255,6 +264,9 @@ export const scenarios = {
): Promise<string> {
const params = new URLSearchParams();
params.set('includeEnvironment', String(options.includeEnvironment));
if (options.version !== undefined) {
params.set('version', String(options.version));
}
for (const cid of options.credentialIds) {
params.append('credentialIds', cid);
}
@@ -263,8 +275,9 @@ export const scenarios = {
}
return request(`/scenarios/${id}/export?${params.toString()}`);
},
exportE2eTestUrl(id: string): string {
return `${BASE_URL}/scenarios/${id}/export-e2e`;
exportE2eTestUrl(id: string, version?: number): string {
const query = version === undefined ? '' : `?version=${version}`;
return `${BASE_URL}/scenarios/${id}/export-e2e${query}`;
},
usedSnippets(id: string): Promise<UsedSnippet[]> {
return request(`/scenarios/${id}/used-snippets`);
+10
View File
@@ -234,3 +234,13 @@ export interface ImportedItem {
export interface ImportResult {
imported: ImportedItem[];
}
/** Run lifecycle event pushed by the server on `GET /scenarios/runs/events`. */
export interface RunEvent {
type: 'run.started' | 'run.finished';
runId: string;
scenarioId: string;
scenarioName: string;
status: ScenarioRunStatus;
at: string;
}
+174
View File
@@ -0,0 +1,174 @@
import { useCallback, useEffect, useRef, useState } from 'react';
import { useQueryClient } from '@tanstack/react-query';
import { useNavigate } from 'react-router-dom';
import { useTranslation } from 'react-i18next';
import { RUN_EVENTS_URL } from '../api/client';
import type { RunEvent } from '../api/types';
import type { NotificationToggleState } from '../ui';
const STORAGE_KEY = 'liqa-run-notifications';
const RETRY_MIN_MS = 1_000;
const RETRY_MAX_MS = 30_000;
function supported(): boolean {
return typeof window !== 'undefined' && 'Notification' in window && 'EventSource' in window;
}
/** The stored choice: `null` until the user toggles notifications explicitly. */
function readEnabled(): boolean | null {
try {
const value = localStorage.getItem(STORAGE_KEY);
return value === null ? null : value === '1';
} catch {
return null;
}
}
function writeEnabled(enabled: boolean): void {
try {
localStorage.setItem(STORAGE_KEY, enabled ? '1' : '0');
} catch {
// storage unavailable: the choice just doesn't persist
}
}
/**
* Opt-in browser notifications for run start/finish, driven by the server's
* run events stream (so runs started from the API, MCP or the scheduler are
* covered too). Returns `null` when the browser lacks Notification/EventSource.
*/
export function useRunNotifications(): {
state: NotificationToggleState;
toggle: () => void;
} | null {
const isSupported = supported();
const { t } = useTranslation();
const navigate = useNavigate();
const queryClient = useQueryClient();
const [stored, setStored] = useState(readEnabled);
const [permission, setPermission] = useState<NotificationPermission>(() =>
isSupported ? Notification.permission : 'denied',
);
// Permission granted outside the toggle (browser prompt or site settings)
// enables notifications unless the user turned them off explicitly
const enabled = stored ?? permission === 'granted';
// Follow permission changes made in the browser's site settings
useEffect(() => {
if (!isSupported) return;
const sync = () => setPermission(Notification.permission);
let status: PermissionStatus | undefined;
let cancelled = false;
navigator.permissions
?.query({ name: 'notifications' })
.then((s) => {
if (cancelled) return;
status = s;
status.addEventListener('change', sync);
})
.catch(() => {});
window.addEventListener('focus', sync);
return () => {
cancelled = true;
status?.removeEventListener('change', sync);
window.removeEventListener('focus', sync);
};
}, [isSupported]);
// Latest callbacks without reopening the stream when they change
const handlers = useRef({ t, navigate });
useEffect(() => {
handlers.current = { t, navigate };
});
const active = isSupported && enabled && permission === 'granted';
useEffect(() => {
if (!active) return;
let source: EventSource;
let retryTimer: ReturnType<typeof setTimeout> | undefined;
let retryDelay = RETRY_MIN_MS;
const onEvent = (message: MessageEvent<string>) => {
let event: RunEvent;
try {
event = JSON.parse(message.data) as RunEvent;
} catch {
return;
}
if (event.type === 'run.finished') {
void queryClient.invalidateQueries({ queryKey: ['runs'] });
}
const { t: translate, navigate: go } = handlers.current;
const key =
event.type === 'run.started'
? 'run_started'
: event.status === 'pass'
? 'run_pass'
: 'run_fail';
const notification = new Notification(
translate(`notifications.${key}_title`, { scenario: event.scenarioName }),
{
body: translate(`notifications.${key}_body`),
// finished replaces started for the same run
tag: event.runId,
},
);
notification.onclick = () => {
window.focus();
go(`/scenarios/${event.scenarioId}/runs/${event.runId}`);
notification.close();
};
};
const connect = () => {
source = new EventSource(RUN_EVENTS_URL);
source.addEventListener('open', () => {
retryDelay = RETRY_MIN_MS;
});
// The browser retries transient errors itself, but some failures close
// the stream for good (e.g. Firefox drops quiet connections after a
// network change), so reopen it with backoff
source.addEventListener('error', () => {
if (source.readyState !== EventSource.CLOSED) return;
retryTimer = setTimeout(connect, retryDelay);
retryDelay = Math.min(retryDelay * 2, RETRY_MAX_MS);
});
source.addEventListener('run.started', onEvent as EventListener);
source.addEventListener('run.finished', onEvent as EventListener);
};
connect();
return () => {
clearTimeout(retryTimer);
source.close();
};
}, [active, queryClient]);
const toggle = useCallback(() => {
if (!isSupported) return;
if (Notification.permission === 'default') {
void Notification.requestPermission().then((result) => {
setPermission(result);
if (result === 'granted') {
setStored(true);
writeEnabled(true);
}
});
return;
}
if (Notification.permission !== 'granted') {
setPermission(Notification.permission);
return;
}
const next = !enabled;
setStored(next);
writeEnabled(next);
}, [isSupported, enabled]);
if (!isSupported) return null;
return {
state: permission === 'denied' ? 'blocked' : active ? 'on' : 'off',
toggle,
};
}
+11
View File
@@ -235,6 +235,17 @@
"light_mode": "Light mode",
"dark_mode": "Dark mode"
},
"notifications": {
"enable": "Enable browser notifications for runs",
"disable": "Disable browser notifications for runs",
"blocked": "Notifications are blocked in your browser settings",
"run_started_title": "Run started: {{scenario}}",
"run_started_body": "The scenario run is in progress.",
"run_pass_title": "Run passed: {{scenario}}",
"run_pass_body": "All steps passed.",
"run_fail_title": "Run failed: {{scenario}}",
"run_fail_body": "The scenario run failed."
},
"revealable": {
"hidden": "Hidden so secrets aren't exposed on screen.",
"reveal": "Reveal",
@@ -229,12 +229,13 @@ export function ScenarioDetailPage() {
includeEnvironment,
credentialIds: credIds,
snippetIds: Array.from(includedSnippetIds),
version: scenario.version,
});
const blob = new Blob([yamlContent], { type: 'application/yaml' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = `${scenario.name}.yaml`;
a.download = `${scenario.name}-v${scenario.version}.yaml`;
a.click();
URL.revokeObjectURL(url);
setExportModalOpen(false);
@@ -503,7 +504,10 @@ export function ScenarioDetailPage() {
variant="secondary"
size="sm"
onClick={() =>
handleFileDownload(scenarios.exportE2eTestUrl(id!), `${scenario.name}-e2e-test.zip`)
handleFileDownload(
scenarios.exportE2eTestUrl(id!, scenario.version),
`${scenario.name}-v${scenario.version}-e2e-test.zip`,
)
}
>
<FileArchive size={14} />
@@ -51,12 +51,12 @@ export function SnippetDetailPage() {
const handleExport = async () => {
if (!snippet) return;
const data = await snippets.exportSnippet(snippet.id);
const data = await snippets.exportSnippet(snippet.id, snippet.version);
const blob = new Blob([yamlStringify(data)], { type: 'application/yaml' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = `snippet-${snippet.alias}.yaml`;
a.download = `snippet-${snippet.alias}-v${snippet.version}.yaml`;
a.click();
URL.revokeObjectURL(url);
};
@@ -0,0 +1,48 @@
.btn {
display: flex;
align-items: center;
justify-content: center;
width: 28px;
height: 28px;
padding: 0;
background: none;
border: var(--border-width) solid var(--color-border);
border-radius: var(--radius-md);
color: var(--color-text-muted);
cursor: pointer;
flex-shrink: 0;
transition: background var(--transition), color var(--transition), border-color var(--transition);
}
.btn:hover {
background: var(--color-bg-subtle);
color: var(--color-text);
border-color: var(--color-text-muted);
}
.btn:active {
background: var(--color-secondary);
color: var(--color-secondary-fg);
}
.btn:disabled {
opacity: 0.5;
cursor: not-allowed;
}
.btn:disabled:hover {
background: none;
color: var(--color-text-muted);
border-color: var(--color-border);
}
.btn[aria-pressed='true'] {
background: var(--color-primary);
border-color: var(--color-primary);
color: var(--color-primary-fg);
}
.btn[aria-pressed='true']:hover {
background: var(--color-primary-hover);
border-color: var(--color-primary-hover);
}
@@ -0,0 +1,39 @@
import { Bell, BellOff } from 'lucide-react';
import { useTranslation } from 'react-i18next';
import styles from './NotificationToggle.module.css';
/**
* - `on`: notifications are enabled
* - `off`: available, but not enabled (or permission not asked yet)
* - `blocked`: the browser denied the permission
*/
export type NotificationToggleState = 'on' | 'off' | 'blocked';
export interface NotificationToggleProps {
state: NotificationToggleState;
onToggle: () => void;
}
export function NotificationToggle({ state, onToggle }: NotificationToggleProps) {
const { t } = useTranslation();
const label =
state === 'on'
? t('notifications.disable')
: state === 'blocked'
? t('notifications.blocked')
: t('notifications.enable');
return (
<button
type="button"
className={styles.btn}
onClick={onToggle}
disabled={state === 'blocked'}
aria-label={label}
aria-pressed={state === 'on'}
title={label}
>
{state === 'on' ? <Bell size={16} /> : <BellOff size={16} />}
</button>
);
}
+2
View File
@@ -26,6 +26,8 @@ export { Breadcrumbs } from './Breadcrumbs/Breadcrumbs';
export type { BreadcrumbsProps, BreadcrumbItem } from './Breadcrumbs/Breadcrumbs';
export { ThemeSwitcher } from './ThemeSwitcher/ThemeSwitcher';
export { NotificationToggle } from './NotificationToggle/NotificationToggle';
export type { NotificationToggleState } from './NotificationToggle/NotificationToggle';
export { ToastProvider } from './Toast/ToastProvider';
export type { ToastProviderProps } from './Toast/ToastProvider';
+3 -1
View File
@@ -75,8 +75,10 @@ A React 19 + TypeScript SPA. During development it's served by the Vite dev serv
The client calls the server REST endpoints directly — there is no separate BFF layer. Routing uses `BrowserRouter`; the server answers any GET outside `/api`, `/mcp`, `/docs`, `/health` and `/manifest.json` with the client's `index.html`, so client-side routes survive a page refresh.
Pages: scenarios (with steps, versions, credentials, used snippets and files), runs, snippets, credentials, environments, sessions, and the central import page. The sidebar footer contains the theme switcher and the app version.
Pages: scenarios (with steps, versions, credentials, used snippets and files), runs, snippets, credentials, environments, sessions, and the central import page. The sidebar footer contains the theme switcher, the browser notifications toggle and the app version.
`GET /manifest.json` is the server's public configuration for the client: the app `name` and `version`, and settings the UI needs (currently `runLogs.dataLimits`, from `RUN_LOG_DATA_COLLAPSE_BYTES` / `RUN_LOG_DATA_COLLAPSE_LINES`). The client reads it through `client/src/lib/manifest.ts` and the `useManifest()` hook, stale-while-revalidate: the copy cached in `localStorage` (or built-in defaults on first visit) is used right away, and the manifest is refetched once per page load and when the tab becomes visible again after 5 minutes. The server sends it with `Cache-Control: no-cache` and an ETag, so an unchanged manifest costs a 304. Add new client-facing settings to the manifest (`server/src/manifest/`) rather than as build-time Vite variables.
Run notifications: `RunEventsService` (`scenario/`) is an in-process rxjs subject. The scheduler emits `run.started` and `run.finished` (once per run, from the run's single exit points rather than each pass/fail transition), and `GET /api/v1/scenarios/runs/events` streams them as SSE. The `useRunNotifications` hook opens an `EventSource` to it, only while the user has enabled notifications and the browser permission is granted, and shows a `Notification` per event. See [scenario.md](scenario.md#run-events-and-browser-notifications).
See [development.md](development.md) for the full client tech stack and directory layout.
+1 -1
View File
@@ -320,7 +320,7 @@ client/
src/
api/ API client (client.ts) and types (types.ts)
components/ modals/ - run, export, export logs and delete confirmation modals
hooks/ useTheme, usePageTitle, useRunDefaults, useImportFile
hooks/ useTheme, usePageTitle, useRunDefaults, useImportFile, useRunNotifications
i18n/ i18next bootstrap + locales/en.json
lib/ highlight.js setup, API error toast events
pages/ scenario/, run/, snippet/, credential/, environment/, session/, import/
+1 -1
View File
@@ -61,7 +61,7 @@ The server registers the following tools. All entity IDs are UUIDs; list tools a
| `export_scenario` | Export one scenario version (optional `version`, defaults to the latest) |
| `import_scenario` | Import one scenario version; `version` is required (see "Versioning" in [scenario.md](scenario.md)) |
| `import_yaml` | Import any mix of environments, credentials, snippets and scenarios from YAML (see "Import" in [scenario.md](scenario.md)) |
| `export_e2e_test` | Export a scenario as a standalone Playwright test project (zip, base64) |
| `export_e2e_test` | Export one scenario version as a standalone Playwright test project (zip, base64; optional `version`, defaults to the latest) |
Changes to scenario content (fields and steps) create a new scenario version; credential assignments and files are not versioned.
+18
View File
@@ -114,6 +114,10 @@ steps:
execCode: await context.page.goto(context.getEnv("base_url"));
```
### E2e test export
`GET /scenarios/:id/export-e2e` (the "Export e2e test" button, the `export_e2e_test` MCP tool) exports one scenario version as a standalone Playwright test project, zipped as `<scenario>-v<N>-e2e-test.zip`. It takes an optional `version` (default: the latest). Snippets are bundled the same way as in the scenario export: the latest version for plain `runSnippet("alias")` calls, plus each version pinned with `alias@N`. The environment, credentials and files are the scenario's current ones; they are not versioned.
## Playwright traces
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.
@@ -128,6 +132,20 @@ 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.
## Run events and browser notifications
The server publishes run lifecycle events on a server-sent events (SSE) stream, `GET /api/v1/scenarios/runs/events`, regardless of how the run was started (UI, REST API, MCP or the scheduler). Each message is named after its `type` and carries a JSON body:
```json
{ "type": "run.finished", "runId": "...", "scenarioId": "...", "scenarioName": "Login", "status": "pass", "at": "2026-01-01T12:00:00.000Z" }
```
- `run.started` is sent when a run becomes `in_progress` (`status` is `in_progress`).
- `run.finished` is sent exactly once per run, with the final `status` (`pass` or `fail`), including runs that fail during setup, time out, or are failed on server restart.
- A `ping` event is sent every 25 s to keep idle connections open through proxies.
The UI uses this stream for opt-in browser notifications: the bell button in the side panel footer asks for the notification permission (granting it from the browser's own prompt or site settings works too) and then shows "Run started / passed / failed: <scenario>" notifications while the UI is open in a tab; clicking one opens the run. The bell is highlighted while notifications are on; turning them off is stored in the browser's `localStorage`. Browsers only offer notifications in a secure context (HTTPS or `localhost`), so over plain HTTP on another host the bell has no effect. When the permission is blocked, the button is disabled; re-allow it in the browser's site settings. Finished runs also refresh the runs lists immediately.
## Statuses
Run status:
+2 -2
View File
@@ -1,12 +1,12 @@
{
"name": "liqa",
"version": "1.24.3",
"version": "1.25.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "liqa",
"version": "1.24.3",
"version": "1.25.0",
"license": "MIT",
"workspaces": [
"server",
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "liqa",
"version": "1.24.3",
"version": "1.25.0",
"private": true,
"license": "MIT",
"author": "Andrii Arsenin",
+9 -3
View File
@@ -1343,15 +1343,21 @@ export class McpService {
"export_e2e_test",
{
description:
"Export a scenario as a standalone, plug-and-play Playwright e2e test project (package.json, playwright.config.ts, test.spec.ts, .env), zipped and returned as base64",
"Export one version of a scenario as a standalone, plug-and-play Playwright e2e test project (package.json, playwright.config.ts, test.spec.ts, .env), zipped and returned as base64",
inputSchema: {
id: z.uuid().describe("Scenario ID to export"),
version: z
.number()
.int()
.min(1)
.optional()
.describe("Scenario version to export. Defaults to the latest"),
},
},
async ({ id }) => {
async ({ id, version }) => {
try {
const { filename, buffer } =
await this.e2eExportService.buildE2eTestPackage(id);
await this.e2eExportService.buildE2eTestPackage(id, version);
return {
content: [
{
+16 -8
View File
@@ -42,8 +42,16 @@ export class E2eExportService {
private readonly snippetService: SnippetService,
) {}
async buildE2eTestPackage(scenarioId: string): Promise<{ filename: string; buffer: Buffer }> {
/** Builds the package for the latest version, or `version` when given. */
async buildE2eTestPackage(
scenarioId: string,
version?: number,
): Promise<{ filename: string; buffer: Buffer }> {
const scenario = await this.scenarioService.findOne(scenarioId);
const content = await this.scenarioService.findVersion(
scenarioId,
version ?? scenario.version,
);
const [credentialMap, snippetMap, attachedFiles] = await Promise.all([
this.scenarioService.buildCredentialMap(scenarioId),
this.snippetService.buildSnippetMap(),
@@ -51,10 +59,10 @@ export class E2eExportService {
]);
const envData = scenario.environment?.data ?? {};
const slug = slugify(scenario.name);
const slug = `${slugify(content.name)}-v${content.version}`;
const files: Record<string, string | Buffer> = {
"package.json": this.buildPackageJson(slug),
"playwright.config.ts": this.buildPlaywrightConfig(scenario.timeoutSeconds),
"playwright.config.ts": this.buildPlaywrightConfig(content.timeoutSeconds),
".env": this.buildEnvFile(envData),
"credentials.json": JSON.stringify(credentialMap, null, 2) + "\n",
".gitignore": [
@@ -65,7 +73,7 @@ export class E2eExportService {
".env",
"credentials.json",
].join("\n") + "\n",
"README.md": this.buildReadme(scenario.name, scenario.description),
"README.md": this.buildReadme(content.name, content.version, content.description),
};
// Bundle any files attached to the scenario so getScenarioFiles works offline.
@@ -97,7 +105,7 @@ export class E2eExportService {
// Bundle only the snippets actually referenced (directly or transitively via
// other snippets) by this scenario's steps, as individual .js files under snippets/.
const usedAliases = resolveUsedSnippetAliases(
scenario.steps.map((s) => s.execCode ?? ""),
content.steps.map((s) => s.execCode ?? ""),
snippetMap,
);
const snippetManifest: { alias: string; filename: string }[] = [];
@@ -116,7 +124,7 @@ export class E2eExportService {
snippetManifest.push({ alias, filename });
}
files["test.spec.ts"] = this.buildTestSpec(scenario, snippetManifest, fileManifest);
files["test.spec.ts"] = this.buildTestSpec(content, snippetManifest, fileManifest);
const buffer = await this.zip(files);
return { filename: `${slug}-e2e-test.zip`, buffer };
@@ -173,9 +181,9 @@ export default defineConfig({
);
}
private buildReadme(scenarioName: string, description: string | null): string {
private buildReadme(scenarioName: string, version: number, description: string | null): string {
const descriptionSection = description?.trim() ? `${description.trim()}\n\n` : "";
return `# ${scenarioName} - standalone e2e test
return `# ${scenarioName} (v${version}) - standalone e2e test
${descriptionSection}## Setup
+31
View File
@@ -0,0 +1,31 @@
import { Injectable } from "@nestjs/common";
import { Observable, Subject } from "rxjs";
export type RunEventStatus = "pending" | "in_progress" | "pass" | "fail";
export interface RunEvent {
type: "run.started" | "run.finished";
runId: string;
scenarioId: string;
scenarioName: string;
status: RunEventStatus;
/** ISO timestamp of the transition. */
at: string;
}
/**
* In-process event bus for scenario run lifecycle transitions. The scheduler
* emits; the SSE endpoint (and tests) subscribe.
*/
@Injectable()
export class RunEventsService {
private readonly subject = new Subject<RunEvent>();
emit(event: RunEvent): void {
this.subject.next(event);
}
stream(): Observable<RunEvent> {
return this.subject.asObservable();
}
}
@@ -30,6 +30,7 @@ import { SnippetService } from "../snippet/snippet.service";
import { ScenarioRunLogEntity } from "./scenario-run-log.entity";
import { ScenarioRunStepEntity } from "./scenario-run-step.entity";
import { ScenarioRunEntity } from "./scenario-run.entity";
import { RunEventsService } from "./run-events.service";
import { ScenarioService } from "./scenario.service";
interface BrowserHandle {
@@ -80,6 +81,7 @@ export class ScenarioSchedulerService implements OnModuleInit {
private readonly sessionService: SessionService,
private readonly sessionContextService: SessionContextService,
private readonly fileStorageService: FileStorageService,
private readonly runEvents: RunEventsService,
configService: ConfigService<AppConfig, true>,
) {
this.defaultTraceMode = configService.get("PLAYWRIGHT_TRACE_MODE");
@@ -109,7 +111,7 @@ export class ScenarioSchedulerService implements OnModuleInit {
this.failRun(
run.id,
"Run aborted: server restarted and playwright session could not be recovered",
),
).then(() => this.emitFinished(run.id)),
).pipe(
Effect.catchAll((err) =>
Effect.sync(() =>
@@ -149,6 +151,48 @@ export class ScenarioSchedulerService implements OnModuleInit {
this.persistLog(runId, null, "error", reason, "run");
}
/**
* Publishes a run lifecycle event. Never throws: a notification problem
* must not affect the run itself.
*/
private async emitRunEvent(
type: "run.started" | "run.finished",
runId: string,
): Promise<void> {
try {
const run = await this.runRepo.findOneBy({ id: runId });
if (!run) return;
if (type === "run.finished" && run.status !== "pass" && run.status !== "fail") {
return;
}
const scenario = await this.scenarioService
.findOne(run.scenarioId)
.catch(() => null);
this.runEvents.emit({
type,
runId,
scenarioId: run.scenarioId,
scenarioName: scenario?.name ?? run.scenarioId,
status: run.status,
at: new Date().toISOString(),
});
} catch (err) {
this.logger.warn(
`Run #${runId}: failed to emit ${type} event — ${String(err)}`,
);
}
}
/**
* Emits `run.finished` with the run's final status. Called exactly once per
* run, from the single exit point of each run's lifecycle (the `finally` of
* processRunToCompletion, setup failure, stale-run cleanup), never from the
* individual pass/fail transitions.
*/
private emitFinished(runId: string): Promise<void> {
return this.emitRunEvent("run.finished", runId);
}
private persistLog(
runId: string,
stepRunId: string | null,
@@ -214,6 +258,7 @@ export class ScenarioSchedulerService implements OnModuleInit {
run.status = "in_progress";
await this.runRepo.save(run);
this.logger.log(`Run #${run.id} → in_progress`);
await this.emitRunEvent("run.started", run.id);
const credMap = await this.scenarioService
.buildCredentialMap(run.scenarioId)
.catch(() => ({}) as Record<string, unknown>);
@@ -267,6 +312,7 @@ export class ScenarioSchedulerService implements OnModuleInit {
run.id,
`Run setup failed: ${String(err)}`,
).catch(() => {});
await this.emitFinished(run.id);
}),
),
);
@@ -315,6 +361,7 @@ export class ScenarioSchedulerService implements OnModuleInit {
);
await this.failRun(runId, `Unexpected error: ${(err as Error).message}`);
} finally {
await this.emitFinished(runId);
// Before runLogSeq is cleared, so the trace log entry keeps its order
await this.saveTrace(runId);
this.activeRuns.delete(runId);
+35 -2
View File
@@ -11,12 +11,14 @@ import {
Post,
Query,
Res,
Sse,
UseInterceptors,
UploadedFile,
} from "@nestjs/common";
import { FileInterceptor } from "@nestjs/platform-express";
import { ApiOperation, ApiResponse, ApiTags } from "@nestjs/swagger";
import { Response } from "express";
import { interval, map, merge, type Observable } from "rxjs";
import type { File as MulterFile } from "multer";
import { stringify as yamlStringify } from "yaml";
import { AddScenarioCredentialDto } from "./dto/add-scenario-credential.dto";
@@ -28,15 +30,24 @@ import { RunsQueryDto } from "./dto/runs-query.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 { RunEventsService } from "./run-events.service";
import { ScenarioService } from "./scenario.service";
import { E2eExportService } from "./e2e-export.service";
interface SseMessage {
type: string;
data: object;
}
@ApiTags("scenarios")
@Controller("scenarios")
export class ScenarioController {
private static readonly HEARTBEAT_MS = 25_000;
constructor(
private readonly scenarioService: ScenarioService,
private readonly e2eExportService: E2eExportService,
private readonly runEvents: RunEventsService,
) {}
// ── Scenarios ─────────────────────────────────────────────────────────────
@@ -73,6 +84,23 @@ export class ScenarioController {
return this.scenarioService.findAllRuns(query);
}
@Sse("runs/events")
@ApiOperation({
summary:
"Server-sent events stream of run lifecycle events (run.started, run.finished) for all scenarios",
})
@ApiResponse({ status: 200, description: "text/event-stream" })
streamRunEvents(): Observable<SseMessage> {
const events = this.runEvents
.stream()
.pipe(map((event): SseMessage => ({ type: event.type, data: event })));
// Periodic named event so proxies don't drop an idle connection
const heartbeat = interval(ScenarioController.HEARTBEAT_MS).pipe(
map((): SseMessage => ({ type: "ping", data: {} })),
);
return merge(events, heartbeat);
}
@Get("run-defaults")
@ApiOperation({ summary: "Get server-configured defaults for new runs" })
@ApiResponse({ status: 200 })
@@ -175,12 +203,17 @@ export class ScenarioController {
summary: "Export a scenario as a standalone, plug-and-play Playwright e2e test (zip)",
})
@ApiResponse({ status: 200, description: "Zip archive" })
@ApiResponse({ status: 404, description: "Scenario not found" })
@ApiResponse({ status: 404, description: "Scenario or version not found" })
async exportE2eTest(
@Param("id", ParseUUIDPipe) id: string,
@Query("version", new ParseIntPipe({ optional: true }))
version: number | undefined,
@Res() res: Response,
) {
const { filename, buffer } = await this.e2eExportService.buildE2eTestPackage(id);
const { filename, buffer } = await this.e2eExportService.buildE2eTestPackage(
id,
version,
);
res.setHeader("Content-Type", "application/zip");
res.setHeader("Content-Disposition", `attachment; filename="${filename}"`);
res.setHeader("Content-Length", buffer.length);
+7 -1
View File
@@ -13,6 +13,7 @@ import { ScenarioCredentialEntity } from "./scenario-credential.entity";
import { ScenarioRunLogEntity } from "./scenario-run-log.entity";
import { ScenarioRunStepEntity } from "./scenario-run-step.entity";
import { ScenarioRunEntity } from "./scenario-run.entity";
import { RunEventsService } from "./run-events.service";
import { ScenarioSchedulerService } from "./scenario-scheduler.service";
import { ScenarioVersionEntity } from "./scenario-version.entity";
import { ScenarioStepEntity } from "./scenario-step.entity";
@@ -43,7 +44,12 @@ import { E2eExportService } from "./e2e-export.service";
FileModule,
],
controllers: [ScenarioController],
providers: [ScenarioService, ScenarioSchedulerService, E2eExportService],
providers: [
ScenarioService,
ScenarioSchedulerService,
E2eExportService,
RunEventsService,
],
exports: [ScenarioService, E2eExportService],
})
export class ScenarioModule {}
+109
View File
@@ -0,0 +1,109 @@
import { INestApplication } from "@nestjs/common";
import { DataSource } from "typeorm";
import { buildTestApp } from "./app.harness";
import { EnvironmentEntity } from "../src/environment/environment.entity";
import {
RunEvent,
RunEventsService,
} from "../src/scenario/run-events.service";
import { ScenarioController } from "../src/scenario/scenario.controller";
import { ScenarioSchedulerService } from "../src/scenario/scenario-scheduler.service";
import { ScenarioService } from "../src/scenario/scenario.service";
describe("run events", () => {
let app: INestApplication;
let dataSource: DataSource;
let scenarioService: ScenarioService;
let scheduler: ScenarioSchedulerService;
let events: RunEvent[];
let subscription: { unsubscribe(): void };
beforeAll(async () => {
app = await buildTestApp();
dataSource = app.get(DataSource);
scenarioService = app.get(ScenarioService);
scheduler = app.get(ScenarioSchedulerService);
});
beforeEach(() => {
events = [];
subscription = app
.get(RunEventsService)
.stream()
.subscribe((e) => events.push(e));
});
afterEach(() => subscription.unsubscribe());
afterAll(async () => {
await app.close();
});
async function runScenario(name: string, codes: string[]) {
const scenario = await scenarioService.create({ name });
for (const execCode of codes) {
await scenarioService.createStep(scenario.id, { execCode });
}
const repo = dataSource.getRepository(EnvironmentEntity);
const env = await repo.save(
repo.create({ name: `env-${Math.random()}`, data: {} }),
);
const run = await scenarioService.createRun(scenario.id, env.id);
await scheduler.pickUpPendingRuns();
await scenarioService.waitForRun(scenario.id, run.id, 10_000);
// run.finished is emitted just after the status becomes terminal
await waitFor(() => events.some((e) => e.type === "run.finished"));
// give a double emit the chance to show up
await new Promise((r) => setTimeout(r, 200));
return { scenario, run };
}
async function waitFor(cond: () => boolean) {
for (let i = 0; i < 100 && !cond(); i++) {
await new Promise((r) => setTimeout(r, 50));
}
}
it("emits started then finished(pass) for a passing run", async () => {
const { scenario, run } = await runScenario("events-pass", ["return 1;"]);
expect(events.map((e) => [e.type, e.status])).toEqual([
["run.started", "in_progress"],
["run.finished", "pass"],
]);
expect(events[0]).toMatchObject({
runId: run.id,
scenarioId: scenario.id,
scenarioName: "events-pass",
});
expect(Number.isNaN(Date.parse(events[1].at))).toBe(false);
});
it("emits finished(fail) exactly once for a failing run", async () => {
await runScenario("events-fail", ["throw new Error('boom');", "return 2;"]);
expect(events.map((e) => [e.type, e.status])).toEqual([
["run.started", "in_progress"],
["run.finished", "fail"],
]);
});
it("exposes events through the SSE controller stream", () => {
const received: { type: string; data: object }[] = [];
const sub = app
.get(ScenarioController)
.streamRunEvents()
.subscribe((m) => received.push(m));
app.get(RunEventsService).emit({
type: "run.started",
runId: "r",
scenarioId: "s",
scenarioName: "n",
status: "in_progress",
at: new Date().toISOString(),
});
sub.unsubscribe();
expect(received).toHaveLength(1);
expect(received[0].type).toBe("run.started");
});
});
+58
View File
@@ -4,6 +4,7 @@
* - runs record and execute the scenario version they were created with
* - runSnippet("alias@N") pins a snippet version
* - export/import carry and restore exact versions
* - e2e test exports build the requested version
*/
import { INestApplication } from "@nestjs/common";
@@ -12,6 +13,7 @@ import { DataSource } from "typeorm";
import { buildTestApp } from "./app.harness";
import { CredentialEntity } from "../src/credential/credential.entity";
import { EnvironmentEntity } from "../src/environment/environment.entity";
import { E2eExportService } from "../src/scenario/e2e-export.service";
import { ScenarioSchedulerService } from "../src/scenario/scenario-scheduler.service";
import { ScenarioService } from "../src/scenario/scenario.service";
import { SnippetService } from "../src/snippet/snippet.service";
@@ -367,6 +369,62 @@ describe("Versioning", () => {
});
});
describe("e2e test export", () => {
/** Captures the files the next e2e export zips. */
function captureZippedFiles() {
const service = app.get(E2eExportService) as unknown as {
zip: (files: Record<string, string | Buffer>) => Promise<Buffer>;
};
const spy = jest.spyOn(service, "zip");
return () => {
const files = spy.mock.calls[0][0];
spy.mockRestore();
return files;
};
}
it("exports the latest version, or the one asked for", async () => {
const name = `E2e ${uniq()}`;
const slug = name.toLowerCase().replace(" ", "-");
const sc = await scenarioService.create({ name });
await scenarioService.createStep(sc.id, { execCode: "return 'v2';" });
let files = captureZippedFiles();
const latest = await request(app.getHttpServer())
.get(`/scenarios/${sc.id}/export-e2e`)
.expect(200);
expect(latest.headers["content-disposition"]).toBe(
`attachment; filename="${slug}-v2-e2e-test.zip"`,
);
let zipped = files();
expect(zipped["test.spec.ts"]).toContain("return 'v2';");
expect(JSON.parse(zipped["package.json"] as string).name).toBe(
`${slug}-v2-e2e-test`,
);
expect(zipped["README.md"]).toContain(`# ${name} (v2)`);
files = captureZippedFiles();
const first = await request(app.getHttpServer())
.get(`/scenarios/${sc.id}/export-e2e?version=1`)
.expect(200);
expect(first.headers["content-disposition"]).toBe(
`attachment; filename="${slug}-v1-e2e-test.zip"`,
);
zipped = files();
expect(zipped["test.spec.ts"]).not.toContain("return 'v2';");
});
it("rejects a missing or invalid version", async () => {
const sc = await scenarioService.create({ name: `e2e-${uniq()}` });
await request(app.getHttpServer())
.get(`/scenarios/${sc.id}/export-e2e?version=9`)
.expect(404);
await request(app.getHttpServer())
.get(`/scenarios/${sc.id}/export-e2e?version=abc`)
.expect(400);
});
});
describe("snippet export/import", () => {
it("export includes the version and import requires it", async () => {
const alias = `sexp-${uniq()}`;