Compare commits
13
Commits
v1.24.2
...
4b050fbdc4
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4b050fbdc4 | ||
|
|
a93b3ef835 | ||
|
|
d7eb018245 | ||
|
|
968a8e470b | ||
|
|
3c8def3814 | ||
|
|
6e5da08719 | ||
|
|
1abd95f9e1 | ||
|
|
d7476f0fe8 | ||
|
|
75bb0af9fd | ||
|
|
0c11e11c27 | ||
|
|
c1924060eb | ||
|
|
28dfce246a | ||
|
|
a0624789ce |
No files matched your search
+23
-41
@@ -1,9 +1,8 @@
|
||||
# Code quality checks on master and pull requests. The server and client jobs
|
||||
# only run when their directory (or shared root files) changed. On a push to
|
||||
# master, also builds the Docker image and pushes it to this Gitea instance's
|
||||
# container registry, tagged with the root package.json version and `latest`
|
||||
# - unless that version's image already exists in the registry, in which case
|
||||
# the push is skipped.
|
||||
# only run when their directory (or shared root files) changed. On a release
|
||||
# tag push (vX.Y.Z), runs both jobs unconditionally and then builds the Docker
|
||||
# image and pushes it to this Gitea instance's container registry, tagged with
|
||||
# the version and `latest`. The tag must match the root package.json version.
|
||||
#
|
||||
# Needs a repository (or owner) secret REGISTRY_TOKEN: a Gitea access token
|
||||
# with package write access for the repository owner. The registry host is
|
||||
@@ -15,13 +14,16 @@ name: CI
|
||||
on:
|
||||
push:
|
||||
branches: [master]
|
||||
tags: ['v[0-9]+.[0-9]+.[0-9]+']
|
||||
pull_request:
|
||||
|
||||
env:
|
||||
REGISTRY: git.hq.ars9.space
|
||||
|
||||
jobs:
|
||||
# Not needed on tag pushes: server and client always run there
|
||||
changes:
|
||||
if: ${{ !startsWith(github.ref, 'refs/tags/') }}
|
||||
runs-on: ubuntu-latest
|
||||
outputs:
|
||||
server: ${{ steps.filter.outputs.server }}
|
||||
@@ -45,7 +47,10 @@ jobs:
|
||||
|
||||
server:
|
||||
needs: changes
|
||||
if: needs.changes.outputs.server == 'true'
|
||||
# changes is skipped on tag pushes, hence !cancelled()
|
||||
if: |
|
||||
!cancelled() &&
|
||||
(startsWith(github.ref, 'refs/tags/') || needs.changes.outputs.server == 'true')
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
@@ -65,7 +70,10 @@ jobs:
|
||||
|
||||
client:
|
||||
needs: changes
|
||||
if: needs.changes.outputs.client == 'true'
|
||||
# changes is skipped on tag pushes, hence !cancelled()
|
||||
if: |
|
||||
!cancelled() &&
|
||||
(startsWith(github.ref, 'refs/tags/') || needs.changes.outputs.client == 'true')
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
@@ -83,46 +91,20 @@ jobs:
|
||||
- name: Storybook tests
|
||||
run: npm run -w client test:storybook
|
||||
|
||||
# Skips the image job if the registry already has this version's image
|
||||
version:
|
||||
if: github.event_name == 'push'
|
||||
image:
|
||||
needs: [server, client]
|
||||
if: ${{ !failure() && !cancelled() && startsWith(github.ref, 'refs/tags/') }}
|
||||
runs-on: ubuntu-latest
|
||||
outputs:
|
||||
version: ${{ steps.check.outputs.version }}
|
||||
changed: ${{ steps.check.outputs.changed }}
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- id: check
|
||||
env:
|
||||
REGISTRY_TOKEN: ${{ secrets.REGISTRY_TOKEN }}
|
||||
OWNER: ${{ github.repository_owner }}
|
||||
- name: Check the tag matches package.json
|
||||
run: |
|
||||
version=$(node -p "require('./package.json').version")
|
||||
image="${REGISTRY}/$(echo "${GITHUB_REPOSITORY}" | tr '[:upper:]' '[:lower:]')"
|
||||
echo "$REGISTRY_TOKEN" | docker login "$REGISTRY" -u "$OWNER" --password-stdin
|
||||
if docker manifest inspect "${image}:${version}" >/dev/null 2>&1; then
|
||||
echo "version ${version}: image already in registry, skipping"
|
||||
echo "changed=false" >> "$GITHUB_OUTPUT"
|
||||
else
|
||||
echo "version ${version}: not in registry, building"
|
||||
echo "changed=true" >> "$GITHUB_OUTPUT"
|
||||
if [ "${GITHUB_REF_NAME}" != "v${version}" ]; then
|
||||
echo "tag ${GITHUB_REF_NAME} does not match package.json version ${version}"
|
||||
exit 1
|
||||
fi
|
||||
echo "version=${version}" >> "$GITHUB_OUTPUT"
|
||||
|
||||
image:
|
||||
needs: [server, client, version]
|
||||
# server/client may be skipped when their paths didn't change
|
||||
if: |
|
||||
!failure() && !cancelled() &&
|
||||
github.event_name == 'push' &&
|
||||
needs.version.outputs.changed == 'true' &&
|
||||
(needs.server.result == 'success' || needs.server.result == 'skipped') &&
|
||||
(needs.client.result == 'success' || needs.client.result == 'skipped')
|
||||
runs-on: ubuntu-latest
|
||||
env:
|
||||
VERSION: ${{ needs.version.outputs.version }}
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
echo "VERSION=${version}" >> "$GITHUB_ENV"
|
||||
- name: Log in to the registry
|
||||
env:
|
||||
REGISTRY_TOKEN: ${{ secrets.REGISTRY_TOKEN }}
|
||||
|
||||
@@ -2,6 +2,30 @@
|
||||
|
||||
All notable changes to this project will be documented in this file.
|
||||
|
||||
## 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:
|
||||
|
||||
### Added
|
||||
|
||||
- `examples/` directory with ready-to-import example resources. The first one, `examples/self-test`, is a scenario that tests the liqa instance it runs on: it creates a temporary scenario through the REST API, runs it, checks the run and its page in the UI, and cleans up. It uses an environment, a credential, snippets and assertions.
|
||||
|
||||
### Changed
|
||||
|
||||
- CI builds and pushes the Docker image only when a `vX.Y.Z` release tag is pushed, not on every merge to `master`.
|
||||
|
||||
## 1.24.2 - 2026-10-02
|
||||
|
||||
Changes since 1.24.1:
|
||||
|
||||
@@ -14,6 +14,7 @@ It is an npm workspace with two packages:
|
||||
- [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
|
||||
- [examples/](examples/README.md) - ready-to-import example resources (YAML); `server/test/examples.spec.ts` imports each file, so keep them in sync with the import format
|
||||
- [CHANGELOG.md](CHANGELOG.md) - release notes per version
|
||||
- [Dockerfile](Dockerfile) - single image: builds client and server, runtime serves both
|
||||
- [.env.example](.env.example) - all configuration variables (validated in `server/src/config/app.config.ts`)
|
||||
@@ -28,7 +29,9 @@ The live database is `data/liqa.db`. The container applies pending migrations be
|
||||
|
||||
## Branching
|
||||
|
||||
Never commit directly to `master` when implementing a feature, chore or bug fix: create a separate branch for the work first. Only version-bump release commits (see "Committing a new version") are made on `master`.
|
||||
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`.
|
||||
|
||||
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
|
||||
|
||||
@@ -47,17 +50,18 @@ cd client && npm run lint && npm run build && npm run test:storybook
|
||||
- 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
|
||||
## Releasing a new version
|
||||
|
||||
When asked to commit:
|
||||
A release is cut on `master` after one or more work branches have been merged (their pull request checks are already green). CI builds and pushes the Docker image only when a `vX.Y.Z` tag is pushed, not on merges.
|
||||
|
||||
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.
|
||||
When asked to release:
|
||||
|
||||
1. Make sure you're on an up-to-date, clean `master` (`git switch master && git pull`), and collect the changes since the last release: `git log --oneline "$(git describe --tags --abbrev=0)"..HEAD`.
|
||||
2. **Ask which version to bump** - major, minor or patch - and propose a sensible default based on those 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).
|
||||
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. **Tag the version commit** with an annotated tag `v<version>` whose message is that version's `CHANGELOG.md` entry, verbatim (from its `## <version>` heading up to the next version's heading). Commits without a version bump get no tag. `--cleanup=whitespace` is required: the default cleanup strips lines starting with `#`, which would drop the entry's headings:
|
||||
5. Commit only these release changes on `master`. 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.
|
||||
6. **Tag the release commit** with an annotated tag `v<version>` whose message is that version's `CHANGELOG.md` entry, verbatim (from its `## <version>` heading up to the next version's heading). `--cleanup=whitespace` is required: the default cleanup strips lines starting with `#`, which would drop the entry's headings:
|
||||
|
||||
```bash
|
||||
v=<version>
|
||||
@@ -65,5 +69,5 @@ When asked to commit:
|
||||
| git tag -a "v$v" --cleanup=whitespace -F -
|
||||
```
|
||||
|
||||
Don't push the tag; tell the user to push with `git push --follow-tags`, which also pushes annotated tags.
|
||||
8. **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. **Ask the user before pushing**, then push the commit and the tag together with `git push --follow-tags` (it also pushes annotated tags). The tag push triggers the image build; it fails if the tag doesn't match the `package.json` version.
|
||||
8. **Ask the user whether to rebuild and restart the docker compose containers** (`docker compose up -d --build`); don't do it without confirmation.
|
||||
@@ -14,6 +14,8 @@ No configuration is needed: every setting has a default. To override one, copy `
|
||||
|
||||
Everything is served from one container at **http://localhost:13000**: the UI at `/`, the REST API at `/api/v1`, MCP at `/mcp`, Swagger at `/docs`. Data is kept in `./data/`.
|
||||
|
||||
To see it work, import and run the [self-test example](examples/self-test/): a scenario that tests liqa itself using an environment, a credential and snippets.
|
||||
|
||||
---
|
||||
|
||||
## Installation
|
||||
@@ -49,6 +51,7 @@ Scenarios, snippets, environments and credentials can be exported as YAML and im
|
||||
- [docs/scenario.md](docs/scenario.md) - runs, the script `context` API, versioning, import/export, Playwright traces
|
||||
- [docs/mcp.md](docs/mcp.md) - MCP tool reference
|
||||
- [docs/development.md](docs/development.md) - setup, configuration, running, testing, linting, Docker
|
||||
- [examples/](examples/) - ready-to-import example scenarios
|
||||
- [CHANGELOG.md](CHANGELOG.md) - release notes
|
||||
|
||||
---
|
||||
|
||||
@@ -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' } };
|
||||
@@ -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
@@ -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={
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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,
|
||||
};
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
@@ -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>
|
||||
);
|
||||
}
|
||||
@@ -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';
|
||||
|
||||
@@ -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.
|
||||
+6
-7
@@ -245,13 +245,12 @@ Before adding a dependency, check its license is compatible with MIT distributio
|
||||
|
||||
## CI (Gitea Actions)
|
||||
|
||||
`.gitea/workflows/ci.yml` runs on pushes to `master` and on pull requests:
|
||||
`.gitea/workflows/ci.yml` runs on pushes to `master`, on pull requests and on release tags (`vX.Y.Z`):
|
||||
|
||||
- **changes**: detects which of `server/` and `client/` changed (via `dorny/paths-filter`), also treating root `package.json`/`package-lock.json` and the workflow file itself as affecting both.
|
||||
- **server** (skipped if nothing under `server/` changed): lint (no warnings allowed), type-check, tests, build.
|
||||
- **client** (skipped if nothing under `client/` changed): lint (no warnings allowed), build, Storybook tests in headless Chromium.
|
||||
- **version** (pushes to `master` only): reads `version` from the root `package.json` and checks the registry for an existing `<registry>/<owner>/<repo>:<version>` image; skips the image job if that tag is already present.
|
||||
- **image** (pushes to `master` only): when the version job found no existing image for the current version, and the server/client jobs passed or were skipped, builds the Docker image and pushes it to the Gitea container registry set by `REGISTRY` at the top of the workflow (`git.hq.ars9.space`) as `<registry>/<owner>/<repo>:<version>` and `:latest`.
|
||||
- **changes** (not on tags): detects which of `server/` and `client/` changed (via `dorny/paths-filter`), also treating root `package.json`/`package-lock.json` and the workflow file itself as affecting both.
|
||||
- **server** (skipped if nothing under `server/` changed; always runs on tags): lint (no warnings allowed), type-check, tests, build.
|
||||
- **client** (skipped if nothing under `client/` changed; always runs on tags): lint (no warnings allowed), build, Storybook tests in headless Chromium.
|
||||
- **image** (release tags only): after the server and client jobs pass, checks that the tag matches the root `package.json` version (`v<version>`), builds the Docker image and pushes it to the Gitea container registry set by `REGISTRY` at the top of the workflow (`git.hq.ars9.space`) as `<registry>/<owner>/<repo>:<version>` and `:latest`. Merges to `master` don't build images.
|
||||
|
||||
The image job logs in as the repository owner with the `REGISTRY_TOKEN` secret: a Gitea access token with package write access (Settings → Applications → token with `write:package`), added under the repository's Settings → Actions → Secrets. It runs `docker` on the runner, so the runner must give jobs access to a Docker daemon (act_runner mounts the host's Docker socket into job containers by default).
|
||||
|
||||
@@ -321,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/
|
||||
|
||||
@@ -128,6 +128,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:
|
||||
@@ -155,3 +169,5 @@ Run-step status:
|
||||
5. Assign credentials to scenario aliases when needed
|
||||
6. Run scenario
|
||||
7. Wait for run completion and inspect run logs/outputs
|
||||
|
||||
The [self-test example](../examples/self-test/) follows these steps through the REST API, and can be imported as a complete, working scenario.
|
||||
@@ -0,0 +1,9 @@
|
||||
# Examples
|
||||
|
||||
Ready-to-import liqa resources. Each example is a directory with a YAML file to import (the Import page in the UI, `POST /api/v1/import`, or the `import_yaml` MCP tool; see [Import](../docs/scenario.md#import)) and a README on how to run it.
|
||||
|
||||
| Example | What it shows |
|
||||
|---|---|
|
||||
| [self-test](self-test/) | A scenario that tests the liqa instance it runs on: creates a scenario through the REST API, runs it, checks the run and its page in the UI, and cleans up. Uses an environment, a credential, snippets and assertions |
|
||||
|
||||
`server/test/examples.spec.ts` imports every YAML file in this directory and checks that its code parses, so the examples keep up with the import format.
|
||||
@@ -0,0 +1,55 @@
|
||||
# Self-test
|
||||
|
||||
A scenario that tests the liqa instance it runs on. It drives liqa through its own REST API and web UI: it creates a small scenario, runs it, checks the result and deletes it again. It shows the main liqa features in one place:
|
||||
|
||||
- an **environment** with the URLs and test values the steps read with `context.getEnv()`
|
||||
- a **credential**, assigned to the scenario as `fixture` and read with `context.getCredential()`
|
||||
- three **snippets**, called with `context.runSnippet()`, one of them from the other two
|
||||
- **assertions** (`context.assert()` and Playwright's `expect`), step outputs (`context.getStepOutput()`) and run logs
|
||||
|
||||
Everything is in [self-test.yaml](self-test.yaml).
|
||||
|
||||
## Run it
|
||||
|
||||
1. Start liqa with the default docker compose deployment (`docker compose up -d --build` at the repo root). It's served at http://localhost:13000.
|
||||
2. Import [self-test.yaml](self-test.yaml): open **Import** in the UI and pick the file, or run
|
||||
|
||||
```bash
|
||||
curl -X POST http://localhost:13000/api/v1/import \
|
||||
-H 'Content-Type: application/yaml' \
|
||||
--data-binary @examples/self-test/self-test.yaml
|
||||
```
|
||||
|
||||
Every item has a fixed id, so importing the file again updates the same resources instead of adding copies.
|
||||
3. Open the **liqa self-test** scenario and click **Run**. Its default environment, `liqa-self-test`, is preselected.
|
||||
|
||||
The run takes a few seconds. The run page shows every assertion as a log entry, and the target scenario's run while it exists.
|
||||
|
||||
## What's in the file
|
||||
|
||||
| Kind | Name | Purpose |
|
||||
|---|---|---|
|
||||
| Environment | `liqa-self-test` | `liqa_url` (REST API base), `ui_url` (web UI base), `temp_prefix` (name prefix of the temporary resources), `greeting` (test value) |
|
||||
| Credential | `liqa-self-test-fixture` | Test data (`username`, `token`) that the self-test passes on to the scenario it creates. It's not a real secret |
|
||||
| Snippet | `liqa-api` | `runSnippet("liqa-api", method, path, body?)`: calls `liqa_url` + `/api/v1` + `path`, returns the parsed JSON and throws on an error status |
|
||||
| Snippet | `liqa-run-and-wait` | `runSnippet("liqa-run-and-wait", scenarioId, environmentId)`: starts a run and returns it once it has finished. Uses `liqa-api` |
|
||||
| Snippet | `self-test-cleanup` | Deletes every scenario, credential and environment whose name starts with `temp_prefix` and returns how many it deleted. Uses `liqa-api` |
|
||||
| Scenario | `liqa self-test` | The self-test itself (below) |
|
||||
|
||||
The scenario's steps:
|
||||
|
||||
1. **Check the instance is up**: checks `GET /health`, then runs `self-test-cleanup` to remove anything a failed earlier run left behind (and logs a warning if it found some).
|
||||
2. **Create the target scenario**: creates a temporary environment, a temporary credential (holding the `fixture` credential's data) and the target scenario `[self-test] target scenario`, and assigns the credential to it as `secret`. The target has two steps: one reads `greeting` and the `secret` token, the other renders the greeting on a page and checks it with `expect`.
|
||||
3. **Run the target scenario**: runs it with `liqa-run-and-wait` and checks the result: the run and both steps passed, the step outputs hold the greeting and the token's length, and the target logged its passing assertion.
|
||||
4. **Check the run in the UI**: opens the target's run page at `ui_url` and checks that it shows the scenario name and the assertion.
|
||||
5. **Clean up**: runs `self-test-cleanup` again, and checks that it deleted the three temporary resources and that the target scenario is gone.
|
||||
|
||||
## Addresses
|
||||
|
||||
Steps run inside the liqa server, so `liqa_url` and `ui_url` are addresses as seen from the server, not from your machine. In the docker compose deployment the server listens on port 3000 inside the container, published as 13000 on the host, so both are `http://localhost:3000`.
|
||||
|
||||
When running the server locally (`npm run start:dev`, see [docs/development.md](../../docs/development.md)), `liqa_url` stays `http://localhost:3000`. The UI is then served by the Vite dev server: set `ui_url` to `http://localhost:5173`.
|
||||
|
||||
## When it fails
|
||||
|
||||
A failed step stops the run, so the temporary resources (named `[self-test] ...`) are left in place to inspect. The next self-test run deletes them in its first step.
|
||||
@@ -0,0 +1,280 @@
|
||||
# liqa self-test example: a scenario that tests the liqa instance it runs on.
|
||||
#
|
||||
# Import this file (Import page in the UI, POST /api/v1/import with
|
||||
# Content-Type: application/yaml, or the import_yaml MCP tool), then run the
|
||||
# "liqa self-test" scenario. See README.md next to this file.
|
||||
#
|
||||
# Every item has a fixed id, so importing the file again updates the same
|
||||
# resources instead of creating duplicates.
|
||||
---
|
||||
# Environment: where the liqa under test is reachable from the liqa server
|
||||
kind: environment
|
||||
id: 418eacb0-ab16-4ad6-ab50-c0274fdc49f1
|
||||
name: liqa-self-test
|
||||
description: >-
|
||||
The liqa instance the self-test scenario runs against. Steps run inside the
|
||||
liqa server (the Docker container), so the compose deployment published at
|
||||
http://localhost:13000 is reached at its in-container port 3000.
|
||||
data:
|
||||
# REST API base (without /api/v1)
|
||||
liqa_url: http://localhost:3000
|
||||
# Web UI base; use http://localhost:5173 with the Vite dev server
|
||||
ui_url: http://localhost:3000
|
||||
# Name prefix of the temporary resources the self-test creates and deletes
|
||||
temp_prefix: "[self-test] "
|
||||
# Value the target scenario reads from its own (temporary) environment
|
||||
greeting: Hello from the liqa self-test
|
||||
---
|
||||
# Credential: test data handed over to the temporary target scenario
|
||||
kind: credential
|
||||
id: b0c9ccab-6743-4ac1-9017-d99e0f5d7474
|
||||
name: liqa-self-test-fixture
|
||||
data: '{"username":"self-test-user","token":"not-a-real-secret-0123456789"}'
|
||||
---
|
||||
# Snippet: liqa-api
|
||||
kind: snippet
|
||||
id: f9d2612c-266c-411a-9483-5d860599f208
|
||||
version: 1
|
||||
alias: liqa-api
|
||||
title: Call the liqa REST API
|
||||
description: >-
|
||||
`context.runSnippet("liqa-api", method, path, body?)` sends a request to
|
||||
`liqa_url` + `/api/v1` + path and returns the parsed JSON response (`null`
|
||||
for an empty body). Throws on a non-2xx status.
|
||||
code: |
|
||||
const [method, path, body] = args;
|
||||
const url = context.getEnv("liqa_url") + "/api/v1" + path;
|
||||
const response = await context.page.request.fetch(url, {
|
||||
method,
|
||||
data: body,
|
||||
// POST /scenarios/:id/run/:runId/wait blocks until the run finishes
|
||||
timeout: 120_000,
|
||||
failOnStatusCode: false,
|
||||
});
|
||||
const text = await response.text();
|
||||
if (!response.ok()) {
|
||||
throw new Error(`${method} ${path} returned ${response.status()}: ${text}`);
|
||||
}
|
||||
return text ? JSON.parse(text) : null;
|
||||
---
|
||||
# Snippet: liqa-run-and-wait
|
||||
kind: snippet
|
||||
id: b36c1075-2700-421f-a2e7-ab1a80adb7e7
|
||||
version: 1
|
||||
alias: liqa-run-and-wait
|
||||
title: Run a scenario and wait for it
|
||||
description: >-
|
||||
`context.runSnippet("liqa-run-and-wait", scenarioId, environmentId)` starts
|
||||
a run of the scenario's latest version and returns the finished run (with
|
||||
its step runs and logs). Uses the liqa-api snippet.
|
||||
code: |
|
||||
const [scenarioId, environmentId] = args;
|
||||
const run = await context.runSnippet(
|
||||
"liqa-api",
|
||||
"POST",
|
||||
`/scenarios/${scenarioId}/run`,
|
||||
{ environmentId },
|
||||
);
|
||||
context.log(`Started run ${run.id}, waiting for it to finish`);
|
||||
return context.runSnippet(
|
||||
"liqa-api",
|
||||
"POST",
|
||||
`/scenarios/${scenarioId}/run/${run.id}/wait`,
|
||||
);
|
||||
---
|
||||
# Snippet: self-test-cleanup
|
||||
kind: snippet
|
||||
id: f99e3b17-d28d-4a80-8ae4-f7e8252e0be5
|
||||
version: 1
|
||||
alias: self-test-cleanup
|
||||
title: Delete temporary self-test resources
|
||||
description: >-
|
||||
Deletes every scenario, credential and environment whose name starts with
|
||||
the `temp_prefix` environment value, and returns how many were deleted.
|
||||
Uses the liqa-api snippet.
|
||||
code: |
|
||||
const prefix = context.getEnv("temp_prefix");
|
||||
let deleted = 0;
|
||||
// Scenarios first: they reference the credentials and environments
|
||||
for (const path of ["/scenarios", "/credentials", "/environments"]) {
|
||||
const page = await context.runSnippet("liqa-api", "GET", `${path}?limit=1000`);
|
||||
for (const item of page.data.filter((i) => i.name.startsWith(prefix))) {
|
||||
await context.runSnippet("liqa-api", "DELETE", `${path}/${item.id}`);
|
||||
context.log(`Deleted ${path.slice(1, -1)} "${item.name}"`);
|
||||
deleted += 1;
|
||||
}
|
||||
}
|
||||
return deleted;
|
||||
---
|
||||
# Scenario: liqa self-test
|
||||
kind: scenario
|
||||
id: 571b2894-dacc-4428-b459-4e3fefac5908
|
||||
version: 1
|
||||
name: liqa self-test
|
||||
description: |
|
||||
Tests the liqa instance it runs on, through its REST API and web UI:
|
||||
|
||||
1. checks that the instance is up and removes leftovers of earlier runs
|
||||
2. creates a temporary environment, credential and two-step target scenario
|
||||
3. runs the target scenario, waits for it and checks its step outputs and logs
|
||||
4. opens the finished run in the web UI
|
||||
5. deletes the temporary resources
|
||||
|
||||
Uses the `liqa-api`, `liqa-run-and-wait` and `self-test-cleanup` snippets and
|
||||
the `fixture` credential. See `examples/self-test/README.md`.
|
||||
environmentId: 418eacb0-ab16-4ad6-ab50-c0274fdc49f1
|
||||
timeoutSeconds: 300
|
||||
credentials:
|
||||
- credentialId: b0c9ccab-6743-4ac1-9017-d99e0f5d7474
|
||||
alias: fixture
|
||||
steps:
|
||||
- title: Check the instance is up
|
||||
execCode: |
|
||||
const response = await context.page.request.get(
|
||||
context.getEnv("liqa_url") + "/health",
|
||||
);
|
||||
const health = await response.json();
|
||||
context.assert(() => response.ok(), "Health endpoint responds", {
|
||||
status: response.status(),
|
||||
});
|
||||
context.assert(() => health.status === "ok", "Health status is ok", health);
|
||||
|
||||
// A failed earlier run may have left its temporary resources behind
|
||||
const deleted = await context.runSnippet("self-test-cleanup");
|
||||
if (deleted > 0) {
|
||||
context.warn(`Deleted ${deleted} leftover resource(s) of an earlier run`);
|
||||
}
|
||||
return health;
|
||||
- title: Create the target scenario
|
||||
execCode: |
|
||||
const prefix = context.getEnv("temp_prefix");
|
||||
const api = (method, path, body) =>
|
||||
context.runSnippet("liqa-api", method, path, body);
|
||||
|
||||
const environment = await api("POST", "/environments", {
|
||||
name: `${prefix}environment`,
|
||||
data: { greeting: context.getEnv("greeting") },
|
||||
});
|
||||
// Hand the fixture credential over to the target scenario
|
||||
const fixture = context.getCredential("fixture");
|
||||
const credential = await api("POST", "/credentials", {
|
||||
name: `${prefix}credential`,
|
||||
data: JSON.stringify(fixture),
|
||||
});
|
||||
const scenario = await api("POST", "/scenarios", {
|
||||
name: `${prefix}target scenario`,
|
||||
description: "Temporary scenario created by the liqa self-test",
|
||||
environmentId: environment.id,
|
||||
timeoutSeconds: 60,
|
||||
});
|
||||
await api("POST", `/scenarios/${scenario.id}/credentials`, {
|
||||
credentialId: credential.id,
|
||||
alias: "secret",
|
||||
});
|
||||
|
||||
await api("POST", `/scenarios/${scenario.id}/steps`, {
|
||||
title: "Read the environment and credential",
|
||||
execCode: `
|
||||
const secret = context.getCredential("secret");
|
||||
context.assert(() => typeof secret.token === "string", "Credential has a token");
|
||||
// Return the token length, not the token: step outputs are not secret
|
||||
return { greeting: context.getEnv("greeting"), tokenLength: secret.token.length };
|
||||
`,
|
||||
});
|
||||
await api("POST", `/scenarios/${scenario.id}/steps`, {
|
||||
title: "Render the greeting",
|
||||
execCode: `
|
||||
const { greeting } = await context.getStepOutput(-1);
|
||||
await context.page.setContent("<h1>" + greeting + "</h1>");
|
||||
await expect(context.page.locator("h1")).toHaveText(greeting);
|
||||
return { heading: await context.page.locator("h1").textContent() };
|
||||
`,
|
||||
});
|
||||
|
||||
const created = await api("GET", `/scenarios/${scenario.id}`);
|
||||
context.assert(
|
||||
() => created.steps.length === 2,
|
||||
"Target scenario has 2 steps",
|
||||
{ steps: created.steps.length },
|
||||
);
|
||||
context.log(`Created target scenario ${scenario.id}`);
|
||||
return {
|
||||
scenarioId: scenario.id,
|
||||
scenarioName: scenario.name,
|
||||
environmentId: environment.id,
|
||||
credentialId: credential.id,
|
||||
};
|
||||
- title: Run the target scenario
|
||||
timeoutSeconds: 150
|
||||
execCode: |
|
||||
const { scenarioId, environmentId } = await context.getStepOutput(-1);
|
||||
const run = await context.runSnippet(
|
||||
"liqa-run-and-wait",
|
||||
scenarioId,
|
||||
environmentId,
|
||||
);
|
||||
context.assert(() => run.status === "pass", "Target run passed", {
|
||||
status: run.status,
|
||||
errors: run.logs.filter((l) => l.level === "error").map((l) => l.message),
|
||||
});
|
||||
context.assert(
|
||||
() => run.stepRuns.every((s) => s.status === "pass"),
|
||||
"All target steps passed",
|
||||
run.stepRuns.map((s) => ({ order: s.order, status: s.status })),
|
||||
);
|
||||
|
||||
const [read, render] = run.stepRuns.map((s) => JSON.parse(s.output));
|
||||
const greeting = context.getEnv("greeting");
|
||||
context.assert(
|
||||
() => read.greeting === greeting,
|
||||
"Target read the greeting from its environment",
|
||||
read,
|
||||
);
|
||||
context.assert(
|
||||
() => read.tokenLength === context.getCredential("fixture").token.length,
|
||||
"Target read the token from its credential",
|
||||
);
|
||||
context.assert(
|
||||
() => render.heading === greeting,
|
||||
"Target rendered the greeting",
|
||||
render,
|
||||
);
|
||||
context.assert(
|
||||
() =>
|
||||
run.logs.some(
|
||||
(l) =>
|
||||
l.context === "assertion:pass" &&
|
||||
l.message === "Credential has a token",
|
||||
),
|
||||
"Target logged its passed assertion",
|
||||
);
|
||||
return { runId: run.id };
|
||||
- title: Check the run in the UI
|
||||
execCode: |
|
||||
const { scenarioId, scenarioName } = await context.getStepOutput(2);
|
||||
const { runId } = await context.getStepOutput(3);
|
||||
const page = context.page;
|
||||
await page.goto(
|
||||
`${context.getEnv("ui_url")}/scenarios/${scenarioId}/runs/${runId}`,
|
||||
);
|
||||
await expect(page.getByText(scenarioName).first()).toBeVisible();
|
||||
await expect(page.getByText("Credential has a token").first()).toBeVisible();
|
||||
context.log(`Run page checked: ${page.url()}`);
|
||||
return { url: page.url() };
|
||||
- title: Clean up
|
||||
execCode: |
|
||||
const { scenarioId } = await context.getStepOutput(2);
|
||||
const deleted = await context.runSnippet("self-test-cleanup");
|
||||
context.assert(() => deleted === 3, "Deleted the 3 temporary resources", {
|
||||
deleted,
|
||||
});
|
||||
|
||||
const response = await context.page.request.get(
|
||||
`${context.getEnv("liqa_url")}/api/v1/scenarios/${scenarioId}`,
|
||||
);
|
||||
context.assert(
|
||||
() => response.status() === 404,
|
||||
"Target scenario is gone",
|
||||
{ status: response.status() },
|
||||
);
|
||||
return { deleted };
|
||||
Generated
+2
-2
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "liqa",
|
||||
"version": "1.24.2",
|
||||
"version": "1.24.4",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "liqa",
|
||||
"version": "1.24.2",
|
||||
"version": "1.24.4",
|
||||
"license": "MIT",
|
||||
"workspaces": [
|
||||
"server",
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "liqa",
|
||||
"version": "1.24.2",
|
||||
"version": "1.24.4",
|
||||
"private": true,
|
||||
"license": "MIT",
|
||||
"author": "Andrii Arsenin",
|
||||
|
||||
+48
-9
@@ -6,14 +6,20 @@ set -euo pipefail
|
||||
|
||||
REGISTRY_IMAGE="git.hq.ars9.space/ars9/liqa"
|
||||
|
||||
read -rp "Install directory [./liqa]: " install_dir
|
||||
install_dir="${install_dir:-./liqa}"
|
||||
# Prompt on the terminal, not stdin: under `curl ... | bash` stdin is the
|
||||
# script itself, so a plain `read` would consume the script's own lines.
|
||||
# Without a terminal, the default is used.
|
||||
ask() {
|
||||
local prompt="$1" default="$2" answer=""
|
||||
if { : </dev/tty; } 2>/dev/null; then
|
||||
read -rp "$prompt [$default]: " answer </dev/tty
|
||||
fi
|
||||
echo "${answer:-$default}"
|
||||
}
|
||||
|
||||
read -rp "Port to expose [13000]: " port
|
||||
port="${port:-13000}"
|
||||
|
||||
read -rp "Version to install [latest]: " version
|
||||
version="${version:-latest}"
|
||||
install_dir="$(ask "Install directory" "./liqa")"
|
||||
port="$(ask "Port to expose" "13000")"
|
||||
version="$(ask "Version to install" "latest")"
|
||||
|
||||
mkdir -p "$install_dir/data"
|
||||
|
||||
@@ -35,5 +41,38 @@ EOF
|
||||
echo "Wrote $compose_file"
|
||||
echo "Created $install_dir/data"
|
||||
echo
|
||||
echo "To start liqa:"
|
||||
echo " cd $install_dir && docker compose up -d"
|
||||
|
||||
start_hint() {
|
||||
echo "Once that is fixed, start liqa with:" >&2
|
||||
echo " cd $install_dir && docker compose up -d" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
if ! command -v docker >/dev/null 2>&1; then
|
||||
echo "Error: docker is not installed. Install Docker Engine with the Compose plugin:" >&2
|
||||
echo " https://docs.docker.com/engine/install/" >&2
|
||||
start_hint
|
||||
elif ! docker compose version >/dev/null 2>&1; then
|
||||
echo "Error: the Docker Compose plugin (docker compose) is not available. Install it:" >&2
|
||||
echo " https://docs.docker.com/compose/install/linux/" >&2
|
||||
start_hint
|
||||
elif ! docker compose -f "$compose_file" config --quiet >/dev/null 2>&1; then
|
||||
echo "Error: docker compose rejected $compose_file:" >&2
|
||||
docker compose -f "$compose_file" config --quiet >&2 || true
|
||||
start_hint
|
||||
elif ! docker info >/dev/null 2>&1; then
|
||||
echo "Error: can't reach the Docker daemon. Make sure it is running and that" >&2
|
||||
echo "your user may use it (e.g. is in the docker group), or use sudo." >&2
|
||||
start_hint
|
||||
fi
|
||||
|
||||
cd "$install_dir"
|
||||
if ! docker compose up -d; then
|
||||
echo >&2
|
||||
echo "Error: docker compose up failed." >&2
|
||||
start_hint
|
||||
fi
|
||||
|
||||
echo
|
||||
echo "liqa is running at http://localhost:$port"
|
||||
echo "Manage it from $install_dir with docker compose (ps, logs, down, pull)."
|
||||
@@ -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);
|
||||
|
||||
@@ -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 })
|
||||
|
||||
@@ -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 {}
|
||||
@@ -0,0 +1,83 @@
|
||||
/**
|
||||
* Keeps the files in `examples/` importable: every YAML file there must pass
|
||||
* `POST /import`, and all its step and snippet code must parse.
|
||||
*/
|
||||
import * as fs from "node:fs";
|
||||
import * as path from "node:path";
|
||||
import { INestApplication } from "@nestjs/common";
|
||||
import request from "supertest";
|
||||
import { buildTestApp } from "./app.harness";
|
||||
import { ImportService } from "../src/import/import.service";
|
||||
|
||||
const EXAMPLES_DIR = path.resolve(__dirname, "../../examples");
|
||||
|
||||
function findYamlFiles(dir: string): string[] {
|
||||
return fs.readdirSync(dir, { withFileTypes: true }).flatMap((entry) => {
|
||||
const full = path.join(dir, entry.name);
|
||||
if (entry.isDirectory()) return findYamlFiles(full);
|
||||
return /\.ya?ml$/.test(entry.name) ? [full] : [];
|
||||
});
|
||||
}
|
||||
|
||||
const AsyncFunction = Object.getPrototypeOf(async () => {})
|
||||
.constructor as new (...args: string[]) => unknown;
|
||||
|
||||
interface ExampleItem {
|
||||
kind: string;
|
||||
code?: string;
|
||||
steps?: { title?: string; execCode?: string }[];
|
||||
}
|
||||
|
||||
describe("Examples", () => {
|
||||
let app: INestApplication;
|
||||
let importService: ImportService;
|
||||
|
||||
beforeAll(async () => {
|
||||
app = await buildTestApp();
|
||||
importService = app.get(ImportService);
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
await app.close();
|
||||
});
|
||||
|
||||
const files = findYamlFiles(EXAMPLES_DIR);
|
||||
|
||||
it("has example files", () => {
|
||||
expect(files.length).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
describe.each(files.map((f) => [path.relative(EXAMPLES_DIR, f), f]))(
|
||||
"%s",
|
||||
(_name, file) => {
|
||||
const yaml = fs.readFileSync(file, "utf8");
|
||||
|
||||
it("imports", async () => {
|
||||
const res = await request(app.getHttpServer())
|
||||
.post("/import")
|
||||
.set("Content-Type", "application/yaml")
|
||||
.send(yaml)
|
||||
.expect(201);
|
||||
expect(res.body.imported.length).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
it("has code that parses", () => {
|
||||
const items = importService.parseYaml(yaml) as ExampleItem[];
|
||||
for (const item of items) {
|
||||
// Same shape as the executor: snippets get `...args`
|
||||
if (item.code != null) {
|
||||
expect(
|
||||
() => new AsyncFunction("context", "...args", item.code!),
|
||||
).not.toThrow();
|
||||
}
|
||||
for (const step of item.steps ?? []) {
|
||||
if (step.execCode == null) continue;
|
||||
expect(
|
||||
() => new AsyncFunction("context", step.execCode!),
|
||||
).not.toThrow();
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
);
|
||||
});
|
||||
@@ -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");
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user