Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
968a8e470b | ||
|
|
3c8def3814 | ||
|
|
6e5da08719 | ||
|
|
1abd95f9e1 | ||
|
|
d7476f0fe8 | ||
|
|
75bb0af9fd | ||
|
|
0c11e11c27 | ||
|
|
c1924060eb | ||
|
|
28dfce246a | ||
|
|
a0624789ce | ||
|
|
a8d00056ff | ||
|
|
639b80f468 | ||
|
|
718a12c2f4 | ||
|
|
4e55d14599 | ||
|
|
0f84db57f1 | ||
|
|
959b3b70c9 | ||
|
|
2281a8729b | ||
|
|
e3c2c0cebb | ||
|
|
daecf3d539 |
No files matched your search
@@ -32,6 +32,11 @@
|
||||
## (traces often reach ~10 MB per run; can be overridden per run in the run modal)
|
||||
# PLAYWRIGHT_TRACE_MODE=off
|
||||
|
||||
## Run log data blocks whose pretty-printed JSON exceeds either limit start
|
||||
## collapsed in the UI (bytes, lines); served to the client via /manifest.json
|
||||
# RUN_LOG_DATA_COLLAPSE_BYTES=256
|
||||
# RUN_LOG_DATA_COLLAPSE_LINES=5
|
||||
|
||||
## Chromium binary to use instead of Playwright's own (not needed in Docker,
|
||||
## which ships Playwright's chromium-headless-shell)
|
||||
# PLAYWRIGHT_CHROMIUM_EXECUTABLE_PATH=/usr/bin/chromium
|
||||
|
||||
+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,72 @@
|
||||
|
||||
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:
|
||||
|
||||
### Added
|
||||
|
||||
- Large run log data blocks start collapsed behind a "Show data (size, lines)" toggle: data whose pretty-printed JSON is over `RUN_LOG_DATA_COLLAPSE_BYTES` (default 256) bytes or `RUN_LOG_DATA_COLLAPSE_LINES` (default 5) lines. An "Expand data" / "Collapse data" button next to the Logs heading opens or closes all of them.
|
||||
- "Copy logs" button on the run page: copies the currently filtered logs to the clipboard as plain text, with every data block expanded.
|
||||
- `GET /manifest.json`: public client configuration served by the server - the app name and version, and the run log data limits. The UI caches it in `localStorage` and revalidates it on page load and when the tab is refocused after a while.
|
||||
|
||||
### Changed
|
||||
|
||||
- The sidebar footer shows the server's version (from `/manifest.json`); its tooltip suggests reloading the page when it differs from the version the UI was built with.
|
||||
- Run log data blocks are aligned with the context/message column instead of the level column.
|
||||
|
||||
## 1.24.1 - 2026-10-02
|
||||
|
||||
Changes since 1.24.0:
|
||||
|
||||
### Added
|
||||
|
||||
- `context.assert(fn, description, details?)`: optional `details` argument. On failure, the `assertion:fail` log entry stores `{ details, error }` as data (`error` is the exception message when `fn` threw), so large diagnostics such as a response body can stay out of the message. The exported e2e runtime accepts and prints it too.
|
||||
- The "Step N passed" log entry carries the step's return value as data.
|
||||
- File names in the run Artifacts and scenario Files tables link to the file content, opening it in a new tab (shown inline when the browser can display it).
|
||||
|
||||
### Changed
|
||||
|
||||
- For assertion failures, the "Step N failed" and "Snippet X failed" log entries name only the assertion (`Assertion failed: <description>`) instead of repeating the failure details. The step run's description keeps the full message.
|
||||
- Log output shows elapsed time in whole seconds (`+14s`), matching the stored timestamp resolution.
|
||||
|
||||
## 1.24.0 - 2026-10-01
|
||||
|
||||
Changes since 1.23.0:
|
||||
|
||||
### Added
|
||||
|
||||
- Code reference in the UI: a (?) button next to the Code label on the step and snippet create/edit pages opens a modal documenting the script runtime - the globals (`context`, `expect`, `console`, and `args` in snippets) and every `context` member with examples, including pitfalls such as awaiting `getStepOutput()` and `assert()`, and `downloadFile()` not sending the browser's cookies.
|
||||
|
||||
### Changed
|
||||
|
||||
- `Modal` UI component: new `size="lg"` for long, document-like content. Dialogs are now capped to the viewport height and their body scrolls, instead of overflowing the screen.
|
||||
|
||||
## 1.23.0 - 2026-10-01
|
||||
|
||||
Changes since 1.22.2:
|
||||
|
||||
@@ -4,7 +4,7 @@ liqa is a browser automation and QA service for web applications. It stores **sc
|
||||
|
||||
It is an npm workspace with two packages:
|
||||
|
||||
- `server/` - NestJS API + scheduler + MCP server, SQLite via TypeORM; the schema is managed by migrations in `server/src/database/migrations/` (see "Database migrations" in `docs/development.md`). Any entity change needs a generated migration - `test/migrations.spec.ts` fails otherwise. REST API under `/api/v1`, Swagger UI at `/docs`, MCP at `/mcp`, health at `/health`.
|
||||
- `server/` - NestJS API + scheduler + MCP server, SQLite via TypeORM; the schema is managed by migrations in `server/src/database/migrations/` (see "Database migrations" in `docs/development.md`). Any entity change needs a generated migration - `test/migrations.spec.ts` fails otherwise. REST API under `/api/v1`, Swagger UI at `/docs`, MCP at `/mcp`, health at `/health`, public client configuration at `/manifest.json`.
|
||||
- `client/` - React 19 + Vite SPA (i18n strings in `client/src/i18n/locales/en.json`).
|
||||
|
||||
## Docs
|
||||
@@ -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
|
||||
|
||||
---
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
import { useState } from 'react';
|
||||
import type { Meta, StoryObj } from '@storybook/react-vite';
|
||||
import { LogOutput } from '../../src/ui/LogOutput/LogOutput';
|
||||
import { expect, userEvent, within } from 'storybook/test';
|
||||
import { LogOutput, type LogOutputEntry } from '../../src/ui/LogOutput/LogOutput';
|
||||
import { formatLogText } from '../../src/ui/LogOutput/logText';
|
||||
|
||||
const meta: Meta<typeof LogOutput> = {
|
||||
title: 'UI/LogOutput',
|
||||
@@ -113,6 +116,79 @@ export const Scrollable: Story = {
|
||||
},
|
||||
};
|
||||
|
||||
const largeDataEntries: LogOutputEntry[] = [
|
||||
{
|
||||
id: 0,
|
||||
level: 'log',
|
||||
context: 'step:1',
|
||||
message: 'Small payload:',
|
||||
data: JSON.stringify({ status: 200 }),
|
||||
createdAt: secondsAgo(20),
|
||||
},
|
||||
{
|
||||
id: 1,
|
||||
level: 'log',
|
||||
context: 'step:1',
|
||||
message: 'Large payload:',
|
||||
data: JSON.stringify({
|
||||
user: { id: 42, name: 'Jane Doe', roles: ['admin', 'qa'] },
|
||||
token: 'eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiI0MiJ9',
|
||||
}),
|
||||
createdAt: secondsAgo(18),
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
level: 'warn',
|
||||
context: 'step:2',
|
||||
message: 'Another large payload:',
|
||||
data: JSON.stringify(Array.from({ length: 8 }, (_, i) => ({ row: i }))),
|
||||
createdAt: secondsAgo(10),
|
||||
},
|
||||
];
|
||||
|
||||
function LargeDataLog() {
|
||||
const [expanded, setExpanded] = useState(false);
|
||||
return (
|
||||
<div style={{ display: 'flex', flexDirection: 'column', gap: 8, alignItems: 'flex-start' }}>
|
||||
<button type="button" onClick={() => setExpanded((v) => !v)}>
|
||||
{expanded ? 'Collapse all' : 'Expand all'}
|
||||
</button>
|
||||
<LogOutput startTime={secondsAgo(20)} entries={largeDataEntries} dataExpanded={expanded} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
/** Data blocks over the default limits (256 bytes, 5 lines) start collapsed. */
|
||||
export const LargeData: Story = {
|
||||
render: () => <LargeDataLog />,
|
||||
play: async ({ canvasElement }) => {
|
||||
const canvas = within(canvasElement);
|
||||
// Data blocks are syntax-highlighted into separate tokens, so check the log's text
|
||||
const log = canvas.getByRole('log');
|
||||
// Only the small payload is visible initially
|
||||
await expect(log).toHaveTextContent('"status": 200');
|
||||
await expect(log).not.toHaveTextContent('Jane Doe');
|
||||
const toggles = canvas.getAllByRole('button', { name: /^Show data/ });
|
||||
await expect(toggles).toHaveLength(2);
|
||||
|
||||
await userEvent.click(toggles[0]);
|
||||
await expect(log).toHaveTextContent('Jane Doe');
|
||||
await userEvent.click(canvas.getByRole('button', { name: 'Hide data' }));
|
||||
await expect(log).not.toHaveTextContent('Jane Doe');
|
||||
|
||||
await userEvent.click(canvas.getByRole('button', { name: 'Expand all' }));
|
||||
await expect(log).toHaveTextContent('Jane Doe');
|
||||
await expect(canvas.getAllByRole('button', { name: 'Hide data' })).toHaveLength(2);
|
||||
await userEvent.click(canvas.getByRole('button', { name: 'Collapse all' }));
|
||||
await expect(log).not.toHaveTextContent('Jane Doe');
|
||||
|
||||
// The plain-text form always includes every data block
|
||||
const text = formatLogText(largeDataEntries, largeDataEntries[0].createdAt);
|
||||
await expect(text).toContain('[step:1] Large payload:\n {');
|
||||
await expect(text).toContain('"name": "Jane Doe"');
|
||||
},
|
||||
};
|
||||
|
||||
export const Empty: Story = {
|
||||
args: {
|
||||
entries: [],
|
||||
|
||||
@@ -4,13 +4,22 @@ import { expect, userEvent, within } from 'storybook/test';
|
||||
import { Modal } from '../../src/ui/Modal/Modal';
|
||||
import { Button } from '../../src/ui/Button/Button';
|
||||
|
||||
function ModalDemo({ title, body }: { title: string; body: string }) {
|
||||
function ModalDemo({
|
||||
title,
|
||||
body,
|
||||
size,
|
||||
}: {
|
||||
title: string;
|
||||
body: React.ReactNode;
|
||||
size?: 'md' | 'lg';
|
||||
}) {
|
||||
const [open, setOpen] = useState(false);
|
||||
return (
|
||||
<>
|
||||
<Button onClick={() => setOpen(true)}>Open modal</Button>
|
||||
<Modal
|
||||
open={open}
|
||||
size={size}
|
||||
title={title}
|
||||
onClose={() => setOpen(false)}
|
||||
footer={
|
||||
@@ -61,3 +70,29 @@ export const ClosesOnEscapeAndBackdrop: Story = {
|
||||
await expect(canvas.queryByRole('dialog')).not.toBeInTheDocument();
|
||||
},
|
||||
};
|
||||
|
||||
export const Large: Story = {
|
||||
args: {
|
||||
title: 'Code reference',
|
||||
size: 'lg',
|
||||
body: (
|
||||
<>
|
||||
{Array.from({ length: 60 }, (_, i) => (
|
||||
<p key={i}>Paragraph {i + 1} of a long, document-like modal body.</p>
|
||||
))}
|
||||
</>
|
||||
),
|
||||
},
|
||||
play: async ({ canvasElement }) => {
|
||||
const canvas = within(canvasElement);
|
||||
await userEvent.click(canvas.getByRole('button', { name: 'Open modal' }));
|
||||
const dialog = canvas.getByRole('dialog', { name: 'Code reference' });
|
||||
// The dialog stays within the viewport; its body scrolls instead.
|
||||
await expect(dialog.getBoundingClientRect().height).toBeLessThanOrEqual(window.innerHeight);
|
||||
const body = within(dialog).getByText(
|
||||
'Paragraph 1 of a long, document-like modal body.',
|
||||
).parentElement!;
|
||||
await expect(body.scrollHeight).toBeGreaterThan(body.clientHeight);
|
||||
await expect(within(dialog).getByRole('button', { name: 'Confirm' })).toBeVisible();
|
||||
},
|
||||
};
|
||||
+12
-1
@@ -6,6 +6,7 @@ import type { LucideIcon } from 'lucide-react';
|
||||
import styles from './App.module.css';
|
||||
import { SidePanel, ThemeSwitcher } from './ui';
|
||||
import liqaLogo from './assets/liqa.svg';
|
||||
import { useManifest } from './hooks/useManifest';
|
||||
|
||||
const EnvironmentsPage = lazy(() =>
|
||||
import('./pages/environment/EnvironmentsPage').then((m) => ({ default: m.EnvironmentsPage })),
|
||||
@@ -107,6 +108,7 @@ const NAV: ({ path: string; labelKey: string; Icon: LucideIcon } | { separator:
|
||||
|
||||
export default function App() {
|
||||
const { t } = useTranslation();
|
||||
const { version } = useManifest();
|
||||
|
||||
return (
|
||||
<div className={styles.shell}>
|
||||
@@ -141,7 +143,16 @@ export default function App() {
|
||||
<div className={styles.sideFooter}>
|
||||
<ThemeSwitcher />
|
||||
<div className={styles.version}>
|
||||
v{__APP_VERSION__} ·{' '}
|
||||
<span
|
||||
title={
|
||||
version !== __APP_VERSION__
|
||||
? t('nav.version_mismatch', { client: __APP_VERSION__ })
|
||||
: undefined
|
||||
}
|
||||
>
|
||||
v{version}
|
||||
</span>{' '}
|
||||
·{' '}
|
||||
<a
|
||||
className={styles.versionLink}
|
||||
href="/licenses.txt"
|
||||
|
||||
@@ -123,8 +123,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 +248,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 +261,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);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
.helpButton {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 2px;
|
||||
border: none;
|
||||
border-radius: var(--radius-sm);
|
||||
background: none;
|
||||
color: var(--color-text-muted);
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.helpButton:hover {
|
||||
color: var(--color-primary);
|
||||
}
|
||||
|
||||
.helpButton:focus-visible {
|
||||
outline: none;
|
||||
box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.35);
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
import { useState } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { CircleHelp, X } from 'lucide-react';
|
||||
import { Modal, Button, MarkdownContent } from '../../ui';
|
||||
import content from './code-help.md?raw';
|
||||
import styles from './CodeHelpModal.module.css';
|
||||
|
||||
export interface CodeHelpModalProps {
|
||||
open: boolean;
|
||||
onClose: () => void;
|
||||
}
|
||||
|
||||
/** Reference for the script runtime (`context`, `expect`, ...) available to step and snippet code. */
|
||||
export function CodeHelpModal({ open, onClose }: CodeHelpModalProps) {
|
||||
const { t } = useTranslation();
|
||||
|
||||
return (
|
||||
<Modal
|
||||
open={open}
|
||||
size="lg"
|
||||
title={t('code_help.title')}
|
||||
onClose={onClose}
|
||||
footer={
|
||||
<Button variant="secondary" onClick={onClose}>
|
||||
<X size={14} />
|
||||
{t('code_help.close')}
|
||||
</Button>
|
||||
}
|
||||
>
|
||||
<MarkdownContent content={content} />
|
||||
</Modal>
|
||||
);
|
||||
}
|
||||
|
||||
/** A (?) button that opens the {@link CodeHelpModal}; place it next to a code field label. */
|
||||
export function CodeHelpButton() {
|
||||
const { t } = useTranslation();
|
||||
const [open, setOpen] = useState(false);
|
||||
|
||||
return (
|
||||
<>
|
||||
<button
|
||||
type="button"
|
||||
className={styles.helpButton}
|
||||
onClick={() => setOpen(true)}
|
||||
aria-label={t('code_help.open')}
|
||||
title={t('code_help.open')}
|
||||
>
|
||||
<CircleHelp size={16} />
|
||||
</button>
|
||||
<CodeHelpModal open={open} onClose={() => setOpen(false)} />
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,195 @@
|
||||
Step code and snippet code are the **body of an async function**. Use `await` freely; whatever you `return` becomes the step (or snippet) output.
|
||||
|
||||
```js
|
||||
async (context) => {
|
||||
// your code here
|
||||
}
|
||||
```
|
||||
|
||||
All steps of a run share one browser, one browser context and one page, so state carries over from step to step: the current URL, cookies, local storage, open dialogs.
|
||||
|
||||
A step **passes** when its code returns, and **fails** when it throws or exceeds its timeout. When a step fails, the remaining steps are cancelled, and a screenshot and the page HTML are saved to the run's files.
|
||||
|
||||
## Globals
|
||||
|
||||
| Name | Description |
|
||||
| --- | --- |
|
||||
| `context` | The run context, described below. |
|
||||
| `expect` | Playwright's [`expect`](https://playwright.dev/docs/test-assertions), with auto-retrying web assertions. |
|
||||
| `console` | Writes to the run log: `log`/`info` → `log`, plus `warn`, `error` and `debug`. |
|
||||
| `args` | **Snippets only.** The extra arguments passed to `context.runSnippet(name, ...args)`. |
|
||||
|
||||
Code runs in the server process with Node.js. It is trusted code, not sandboxed.
|
||||
|
||||
## Browser
|
||||
|
||||
### `context.page`
|
||||
|
||||
The Playwright [`Page`](https://playwright.dev/docs/api/class-page) of the run.
|
||||
|
||||
```js
|
||||
await context.page.goto(context.getEnv("base_url"));
|
||||
await context.page.getByRole("button", { name: "Sign in" }).click();
|
||||
await expect(context.page.locator("h1")).toHaveText("Dashboard");
|
||||
```
|
||||
|
||||
### `context.browser`
|
||||
|
||||
The Playwright [`BrowserContext`](https://playwright.dev/docs/api/class-browsercontext) the page belongs to. Use it for cookies, storage state, extra pages and HTTP requests that share the browser's cookies.
|
||||
|
||||
```js
|
||||
const cookies = await context.browser.cookies();
|
||||
const res = await context.browser.request.get(context.getEnv("api_url") + "/me");
|
||||
```
|
||||
|
||||
### `context.dumpDom(selector?)` → `Promise<DomNode>`
|
||||
|
||||
Returns a simplified tree of the live DOM, starting at `selector` (default `"body"`). Decorative and layout elements are filtered out. The tree keeps landmarks, interactive elements, and elements with `role`, `data-testid`, `data-qa`, `data-action` or `data-element-id`. Each node has `tag` and `children`, plus `role`, `testid`, `id`, `name`, `type`, `text`, `href`, `checked`, `disabled`, etc. when they are present. This is useful for finding selectors without a screenshot.
|
||||
|
||||
If nothing matches `selector`, it returns a node with `tag: "ERROR"` instead of throwing.
|
||||
|
||||
```js
|
||||
context.log("Login form:", await context.dumpDom("form"));
|
||||
```
|
||||
|
||||
## Environment
|
||||
|
||||
### `context.env`
|
||||
|
||||
A copy of the selected environment's key/value map, `{}` when there is none. A missing key reads as `undefined`.
|
||||
|
||||
### `context.getEnv(key)` → `string`
|
||||
|
||||
Returns the environment value for `key`, and **throws** if it is not defined. Prefer it over `context.env[key]` for required settings: the step then fails with a clear message.
|
||||
|
||||
```js
|
||||
const baseUrl = context.getEnv("base_url");
|
||||
const locale = context.env.locale ?? "en";
|
||||
```
|
||||
|
||||
## Credentials
|
||||
|
||||
### `context.getCredential(alias)` → `unknown`
|
||||
|
||||
Returns the payload of the credential assigned to this scenario under `alias` (see **Credentials** on the scenario page). JSON data is returned parsed, anything else as a string. **Throws** if no credential has that alias.
|
||||
|
||||
```js
|
||||
const { username, password } = context.getCredential("admin");
|
||||
await context.page.getByLabel("Username").fill(username);
|
||||
await context.page.getByLabel("Password").fill(password);
|
||||
```
|
||||
|
||||
## Step outputs
|
||||
|
||||
### `context.getStepOutput(order)` → `Promise<unknown>`
|
||||
|
||||
Returns the output (the return value) of another step in the same run. **It is async, so `await` it.**
|
||||
|
||||
- A positive `order` is absolute: `1` is the first step.
|
||||
- A negative `order` is relative: `-1` is the previous step.
|
||||
|
||||
Returns `null` if that step does not exist, has not run, or returned nothing. A step's output is stored as JSON, so only JSON-serializable values come back as they were returned (no functions, `Date` becomes a string, Playwright objects are not usable).
|
||||
|
||||
```js
|
||||
// step 2
|
||||
return { orderId: await context.page.locator("#order-id").textContent() };
|
||||
|
||||
// step 3
|
||||
const { orderId } = await context.getStepOutput(-1);
|
||||
```
|
||||
|
||||
## Logging
|
||||
|
||||
### `context.log(...args)`, `context.warn(...args)`, `context.error(...args)`, `context.debug(...args)`
|
||||
|
||||
Write an entry with that level to the run log. `console.*` does the same. Strings, numbers and booleans are joined with spaces into the message. Objects and arrays are kept separate as structured **data**, shown pretty-printed under the message: one object is stored as is, several are stored as an array.
|
||||
|
||||
```js
|
||||
context.log("Created user", user.id, user); // message "Created user 42", data = user
|
||||
```
|
||||
|
||||
Every entry is tagged with where it came from: `step:<N>`, or `snippet:<alias>` while a snippet runs.
|
||||
|
||||
## Assertions
|
||||
|
||||
### `context.assert(fn, description, details?)` → `Promise<void>`
|
||||
|
||||
Runs `fn` (sync or async) and requires it to return exactly `true`.
|
||||
|
||||
- On success, it logs `description` (tagged `assertion:pass`).
|
||||
- If `fn` returns anything else or throws, it logs `Assertion failed: <description>` as an error (tagged `assertion:fail`) and throws, which fails the step. The entry's data holds `details` (if given) and the exception message as `error` (if `fn` threw).
|
||||
|
||||
Await it, or a failure will not stop the step.
|
||||
|
||||
```js
|
||||
await context.assert(
|
||||
async () => (await context.page.locator(".cart-item").count()) === 3,
|
||||
"Cart contains 3 items",
|
||||
);
|
||||
```
|
||||
|
||||
Pass large diagnostics (e.g. a response body) as `details` rather than in `description`, so the message stays short:
|
||||
|
||||
```js
|
||||
await context.assert(() => response.ok(), "Validation must pass", {
|
||||
status: response.status(),
|
||||
body: await response.json(),
|
||||
});
|
||||
```
|
||||
|
||||
Use `expect` instead for assertions that wait and retry until the page matches, e.g. `await expect(locator).toBeVisible()`.
|
||||
|
||||
## Snippets
|
||||
|
||||
### `context.runSnippet(name, ...args)` → `Promise<unknown>`
|
||||
|
||||
Runs a stored snippet with the same `context` (same page, environment and credentials) and returns the snippet's return value. Extra arguments are available inside the snippet as `args`.
|
||||
|
||||
- `name` is the snippet alias, which runs its latest version.
|
||||
- `alias@<version>` (e.g. `login@3`) pins a specific version.
|
||||
|
||||
Start, finish and failure are logged. If the snippet throws, the error propagates and fails the calling step unless you catch it. Snippets can call other snippets.
|
||||
|
||||
```js
|
||||
// step code
|
||||
const user = await context.runSnippet("login", "admin", { remember: true });
|
||||
|
||||
// snippet "login"
|
||||
const [alias, opts] = args;
|
||||
const { username, password } = context.getCredential(alias);
|
||||
// ...
|
||||
return { username };
|
||||
```
|
||||
|
||||
## Files
|
||||
|
||||
### `context.getScenarioFiles(opts?)` → `Promise<{ items, total }>`
|
||||
|
||||
Lists the files uploaded to this scenario (see **Files** on the scenario page). `opts` takes `limit` and `offset` for paging. Each item has `id`, `name`, `mimeType`, `size`, `sha256` and `path`, the absolute path on the server's disk, which you can pass to Playwright:
|
||||
|
||||
```js
|
||||
const { items } = await context.getScenarioFiles();
|
||||
const doc = items.find((f) => f.name === "contract.pdf");
|
||||
await context.page.locator("input[type=file]").setInputFiles(doc.path);
|
||||
```
|
||||
|
||||
### `context.downloadFile(url, opts?)` → `Promise<FileInfo>`
|
||||
|
||||
Fetches `url` on the server and saves the response as a file of the current run. It returns the same fields as a scenario file (`id`, `name`, `mimeType`, `size`, `sha256`, `path`).
|
||||
|
||||
- `opts`: `method`, `headers`, `body` (a string) and `filename`. Without `filename`, the last segment of the URL path is used, and the MIME type is derived from the file extension.
|
||||
- Redirects are followed. Any final status other than 200 throws. The limits are 100 MB and a 30 s timeout.
|
||||
- `url` may be a `data:` URI (`data:<type>;base64,<data>` or `data:<type>,<percent-encoded>`), which saves content generated in the script without a network request. Pass `filename` in this case.
|
||||
- Only works during a real scenario run. It throws in ad-hoc execution such as the `exec_code` MCP tool.
|
||||
- This is a server-side request: it does **not** send the browser's cookies. Pass them in `headers` if the URL needs a session.
|
||||
|
||||
```js
|
||||
await context.downloadFile(
|
||||
"data:application/json;base64," + btoa(JSON.stringify(report)),
|
||||
{ filename: "report.json" },
|
||||
);
|
||||
```
|
||||
|
||||
## Timeouts
|
||||
|
||||
Each step has its own timeout, or else the scenario's timeout, or else 60 s. The whole run fails once it exceeds the scenario's timeout (600 s by default). That check happens between steps.
|
||||
@@ -6,3 +6,5 @@ export { RunScenarioModal } from './RunScenarioModal';
|
||||
export type { RunScenarioModalProps } from './RunScenarioModal';
|
||||
export { ExportLogsModal } from './ExportLogsModal';
|
||||
export type { ExportLogsModalProps, LogExportFormat } from './ExportLogsModal';
|
||||
export { CodeHelpModal, CodeHelpButton } from './CodeHelpModal';
|
||||
export type { CodeHelpModalProps } from './CodeHelpModal';
|
||||
@@ -0,0 +1,10 @@
|
||||
import { useSyncExternalStore } from 'react';
|
||||
import { getManifest, subscribeManifest, type Manifest } from '../lib/manifest';
|
||||
|
||||
/**
|
||||
* Public client configuration from the server's /manifest.json: the cached
|
||||
* copy (or defaults) at first, updated once the fresh one arrives.
|
||||
*/
|
||||
export function useManifest(): Manifest {
|
||||
return useSyncExternalStore(subscribeManifest, getManifest);
|
||||
}
|
||||
@@ -12,6 +12,11 @@
|
||||
"confirm_remove_credential": "Are you sure you want to remove this credential from scenario?",
|
||||
"save_session": "Save session"
|
||||
},
|
||||
"code_help": {
|
||||
"open": "Code reference",
|
||||
"title": "Code reference",
|
||||
"close": "Close"
|
||||
},
|
||||
"errors": {
|
||||
"not_found": "Not found",
|
||||
"not_found_session": "Session {{id}} does not exist or has been deleted.",
|
||||
@@ -23,6 +28,7 @@
|
||||
},
|
||||
"nav": {
|
||||
"licenses": "Licenses",
|
||||
"version_mismatch": "Server version; this page was built for v{{client}}. Reload to update.",
|
||||
"environments": "Environments",
|
||||
"credentials": "Credentials",
|
||||
"snippets": "Snippets",
|
||||
@@ -298,6 +304,14 @@
|
||||
"log_message": "Message",
|
||||
"log_time": "Time",
|
||||
"action_download_logs": "Download logs",
|
||||
"action_copy_logs": "Copy logs",
|
||||
"logs_copied": "Logs copied to clipboard",
|
||||
"logs_copy_failed": "Could not copy logs to clipboard",
|
||||
"logs_expand_data": "Expand data",
|
||||
"logs_collapse_data": "Collapse data",
|
||||
"logs_show_data_one": "Show data ({{size}}, {{count}} line)",
|
||||
"logs_show_data_other": "Show data ({{size}}, {{count}} lines)",
|
||||
"logs_hide_data": "Hide data",
|
||||
"action_repeat": "Repeat run",
|
||||
"repeat_no_environment": "The environment used by this run no longer exists",
|
||||
"export_logs_modal_title": "Export logs",
|
||||
|
||||
@@ -0,0 +1,122 @@
|
||||
import { DEFAULT_LOG_DATA_LIMITS, type LogDataLimits } from '../ui/LogOutput/logText';
|
||||
|
||||
/** Public client configuration served by the server at /manifest.json. */
|
||||
export interface Manifest {
|
||||
name: string;
|
||||
/** Server version; can differ from the client build's __APP_VERSION__ until the page is reloaded. */
|
||||
version: string;
|
||||
runLogs: {
|
||||
dataLimits: LogDataLimits;
|
||||
};
|
||||
}
|
||||
|
||||
export const DEFAULT_MANIFEST: Manifest = {
|
||||
name: 'liqa',
|
||||
version: __APP_VERSION__,
|
||||
runLogs: { dataLimits: DEFAULT_LOG_DATA_LIMITS },
|
||||
};
|
||||
|
||||
const STORAGE_KEY = 'liqa-manifest';
|
||||
/** A tab coming back into view refetches the manifest if it is older than this. */
|
||||
const REFRESH_AFTER_MS = 5 * 60 * 1000;
|
||||
|
||||
// Served next to the API's /api/v1 (so "/manifest.json" by default, or on
|
||||
// VITE_API_URL's origin when the client talks to another server)
|
||||
const MANIFEST_URL = new URL(
|
||||
'../../manifest.json',
|
||||
new URL(
|
||||
`${(import.meta.env.VITE_API_URL ?? '/api/v1').replace(/\/$/, '')}/`,
|
||||
window.location.href,
|
||||
),
|
||||
).toString();
|
||||
|
||||
/** Fills fields missing from `raw` (e.g. a manifest cached by an older version) with defaults. */
|
||||
function normalize(raw: unknown): Manifest | null {
|
||||
if (typeof raw !== 'object' || raw === null) return null;
|
||||
const m = raw as Partial<Manifest>;
|
||||
const limits: Partial<LogDataLimits> = m.runLogs?.dataLimits ?? {};
|
||||
const num = (v: unknown, fallback: number) => (typeof v === 'number' && v >= 0 ? v : fallback);
|
||||
return {
|
||||
name: typeof m.name === 'string' ? m.name : DEFAULT_MANIFEST.name,
|
||||
version: typeof m.version === 'string' ? m.version : DEFAULT_MANIFEST.version,
|
||||
runLogs: {
|
||||
dataLimits: {
|
||||
bytes: num(limits.bytes, DEFAULT_LOG_DATA_LIMITS.bytes),
|
||||
lines: num(limits.lines, DEFAULT_LOG_DATA_LIMITS.lines),
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
// Storage can be unavailable (private mode, blocked site data): the manifest
|
||||
// then just comes from the network on every page load
|
||||
function readCache(): Manifest | null {
|
||||
try {
|
||||
const stored = localStorage.getItem(STORAGE_KEY);
|
||||
return stored ? normalize(JSON.parse(stored)) : null;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
function writeCache(manifest: Manifest) {
|
||||
try {
|
||||
localStorage.setItem(STORAGE_KEY, JSON.stringify(manifest));
|
||||
} catch {
|
||||
// ignore, see readCache
|
||||
}
|
||||
}
|
||||
|
||||
let current: Manifest = readCache() ?? DEFAULT_MANIFEST;
|
||||
let fetchedAt = 0;
|
||||
let inFlight: Promise<void> | null = null;
|
||||
const listeners = new Set<() => void>();
|
||||
|
||||
/**
|
||||
* Fetches the manifest and notifies subscribers if it changed. Failures are
|
||||
* silent: the cached (or default) manifest stays in use.
|
||||
*/
|
||||
export function refreshManifest(): Promise<void> {
|
||||
inFlight ??= fetch(MANIFEST_URL, { headers: { Accept: 'application/json' } })
|
||||
.then((res) => (res.ok ? res.json() : null))
|
||||
.then((raw: unknown) => {
|
||||
const next = normalize(raw);
|
||||
if (!next) return;
|
||||
fetchedAt = Date.now();
|
||||
writeCache(next);
|
||||
if (JSON.stringify(next) !== JSON.stringify(current)) {
|
||||
current = next;
|
||||
listeners.forEach((l) => l());
|
||||
}
|
||||
})
|
||||
.catch(() => undefined)
|
||||
.finally(() => {
|
||||
inFlight = null;
|
||||
});
|
||||
return inFlight;
|
||||
}
|
||||
|
||||
function onVisibilityChange() {
|
||||
if (document.visibilityState === 'visible' && Date.now() - fetchedAt > REFRESH_AFTER_MS) {
|
||||
void refreshManifest();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Stale-while-revalidate: subscribers get the localStorage copy right away,
|
||||
* and the manifest is refetched once per page load (the server answers 304
|
||||
* while it is unchanged) and when the tab becomes visible again after a while.
|
||||
*/
|
||||
export function subscribeManifest(listener: () => void): () => void {
|
||||
if (listeners.size === 0) document.addEventListener('visibilitychange', onVisibilityChange);
|
||||
listeners.add(listener);
|
||||
if (fetchedAt === 0) void refreshManifest();
|
||||
return () => {
|
||||
listeners.delete(listener);
|
||||
if (listeners.size === 0) document.removeEventListener('visibilitychange', onVisibilityChange);
|
||||
};
|
||||
}
|
||||
|
||||
export function getManifest(): Manifest {
|
||||
return current;
|
||||
}
|
||||
@@ -255,6 +255,12 @@
|
||||
color: var(--color-text);
|
||||
}
|
||||
|
||||
.labelRow {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--space-1);
|
||||
}
|
||||
|
||||
.textarea {
|
||||
width: 100%;
|
||||
padding: var(--space-2) var(--space-3);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { useEffect, useRef, useState, useCallback } from 'react';
|
||||
import { useEffect, useMemo, useRef, useState, useCallback } from 'react';
|
||||
import { useNavigate, useParams, Link } from 'react-router-dom';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { useManifest } from '../../hooks/useManifest';
|
||||
import { usePageTitle } from '../../hooks/usePageTitle';
|
||||
import { runs, runFiles } from '../../api';
|
||||
import type {
|
||||
@@ -25,6 +26,8 @@ import {
|
||||
Card,
|
||||
CodeBlock,
|
||||
DescriptionList,
|
||||
formatLogText,
|
||||
hasLargeData,
|
||||
LogOutput,
|
||||
Search,
|
||||
Table,
|
||||
@@ -38,6 +41,7 @@ import {
|
||||
ChevronDown,
|
||||
ChevronRight,
|
||||
ClipboardList,
|
||||
Copy,
|
||||
Activity,
|
||||
Download,
|
||||
Trash2,
|
||||
@@ -81,6 +85,7 @@ function RunDetail() {
|
||||
const { id, runId } = useParams<{ id: string; runId: string }>();
|
||||
const navigate = useNavigate();
|
||||
const toast = useToast();
|
||||
const logDataLimits = useManifest().runLogs.dataLimits;
|
||||
|
||||
const [scenario, setScenario] = useState<Scenario | null>(null);
|
||||
const [run, setRun] = useState<ScenarioRunDetail | null>(null);
|
||||
@@ -102,6 +107,7 @@ function RunDetail() {
|
||||
const [pendingDeleteFile, setPendingDeleteFile] = useState<FileMetadata | null>(null);
|
||||
const [deletingFile, setDeletingFile] = useState(false);
|
||||
const [repeating, setRepeating] = useState(false);
|
||||
const [logDataExpanded, setLogDataExpanded] = useState(false);
|
||||
const logSearchRef = useRef('');
|
||||
const pollRef = useRef<ReturnType<typeof setInterval> | null>(null);
|
||||
|
||||
@@ -144,6 +150,33 @@ function RunDetail() {
|
||||
}
|
||||
};
|
||||
|
||||
const logEntries = useMemo(
|
||||
() =>
|
||||
(run?.logs ?? []).map((l) => ({
|
||||
id: l.id,
|
||||
level: l.level,
|
||||
context: l.context,
|
||||
message: l.message,
|
||||
data: l.data,
|
||||
createdAt: l.createdAt,
|
||||
})),
|
||||
[run?.logs],
|
||||
);
|
||||
const logsHaveLargeData = useMemo(
|
||||
() => hasLargeData(logEntries, logDataLimits),
|
||||
[logEntries, logDataLimits],
|
||||
);
|
||||
|
||||
// Copies the (filtered) logs as plain text with every data block expanded
|
||||
const handleCopyLogs = async () => {
|
||||
try {
|
||||
await navigator.clipboard.writeText(formatLogText(logEntries, run?.createdAt));
|
||||
toast.success(t('runs.logs_copied'));
|
||||
} catch {
|
||||
toast.error(t('runs.logs_copy_failed'));
|
||||
}
|
||||
};
|
||||
|
||||
const handleRepeatRun = async () => {
|
||||
if (!id || !run?.environmentId) return;
|
||||
setRepeating(true);
|
||||
@@ -516,7 +549,22 @@ function RunDetail() {
|
||||
{run.logs.length > 0 && (
|
||||
<div className={styles.stepsSection}>
|
||||
<div className={styles.sectionHeadingRow}>
|
||||
<h2 className={styles.sectionHeading}>{t('runs.logs_heading')}</h2>
|
||||
<div style={{ display: 'flex', alignItems: 'center', gap: '8px' }}>
|
||||
<h2 className={styles.sectionHeading} style={{ margin: 0 }}>
|
||||
{t('runs.logs_heading')}
|
||||
</h2>
|
||||
{logsHaveLargeData && (
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
aria-expanded={logDataExpanded}
|
||||
onClick={() => setLogDataExpanded((v) => !v)}
|
||||
>
|
||||
{logDataExpanded ? <ChevronDown size={14} /> : <ChevronRight size={14} />}
|
||||
{logDataExpanded ? t('runs.logs_collapse_data') : t('runs.logs_expand_data')}
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
<div style={{ display: 'flex', alignItems: 'center', gap: '8px' }}>
|
||||
<Search
|
||||
value={logSearch}
|
||||
@@ -527,19 +575,25 @@ function RunDetail() {
|
||||
<Download size={14} />
|
||||
{t('runs.action_download_logs')}
|
||||
</Button>
|
||||
<Button variant="secondary" size="sm" onClick={handleCopyLogs}>
|
||||
<Copy size={14} />
|
||||
{t('runs.action_copy_logs')}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
<LogOutput
|
||||
startTime={run.createdAt}
|
||||
maxHeight={480}
|
||||
entries={run.logs.map((l) => ({
|
||||
id: l.id,
|
||||
level: l.level,
|
||||
context: l.context,
|
||||
message: l.message,
|
||||
data: l.data,
|
||||
createdAt: l.createdAt,
|
||||
}))}
|
||||
entries={logEntries}
|
||||
dataLimits={logDataLimits}
|
||||
dataExpanded={logDataExpanded}
|
||||
showDataLabel={({ bytes, lines }) =>
|
||||
t('runs.logs_show_data', {
|
||||
size: bytes < 1024 ? `${bytes} B` : `${(bytes / 1024).toFixed(1)} KB`,
|
||||
count: lines,
|
||||
})
|
||||
}
|
||||
hideDataLabel={t('runs.logs_hide_data')}
|
||||
emptyMessage=""
|
||||
/>
|
||||
</div>
|
||||
@@ -554,7 +608,23 @@ function RunDetail() {
|
||||
rowKey={(f) => f.id}
|
||||
columns={
|
||||
[
|
||||
{ key: 'name', header: t('files.name'), render: (f) => f.name },
|
||||
{
|
||||
key: 'name',
|
||||
header: t('files.name'),
|
||||
// Served inline, so the browser shows what it can (images, text, PDF).
|
||||
render: (f) =>
|
||||
isFileExpired(f) ? (
|
||||
f.name
|
||||
) : (
|
||||
<a
|
||||
href={runFiles.contentUrl(id!, runId!, f.id)}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
>
|
||||
{f.name}
|
||||
</a>
|
||||
),
|
||||
},
|
||||
{
|
||||
key: 'mimeType',
|
||||
header: t('files.mimeType'),
|
||||
|
||||
@@ -6,6 +6,7 @@ import { X, Save, ClipboardList } from 'lucide-react';
|
||||
import { scenarios, steps } from '../../api';
|
||||
import type { Scenario } from '../../api';
|
||||
import { Breadcrumbs, Button, Card, Input, CodeEditor, useToast } from '../../ui';
|
||||
import { CodeHelpButton } from '../../components/modals';
|
||||
import styles from '../Page.module.css';
|
||||
|
||||
export function CreateStepPage() {
|
||||
@@ -77,7 +78,10 @@ export function CreateStepPage() {
|
||||
onChange={(e) => setTitle(e.target.value)}
|
||||
/>
|
||||
<div className={styles.formField}>
|
||||
<label className={styles.fieldLabel}>{t('steps.form_exec_code')}</label>
|
||||
<div className={styles.labelRow}>
|
||||
<label className={styles.fieldLabel}>{t('steps.form_exec_code')}</label>
|
||||
<CodeHelpButton />
|
||||
</div>
|
||||
<CodeEditor value={execCode} onChange={setExecCode} rows={6} />
|
||||
</div>
|
||||
<Input
|
||||
|
||||
@@ -6,6 +6,7 @@ import { X, Save, ClipboardList } from 'lucide-react';
|
||||
import { scenarios, steps } from '../../api';
|
||||
import type { Scenario, ScenarioStep } from '../../api';
|
||||
import { Breadcrumbs, Button, Card, Input, CodeEditor, useToast } from '../../ui';
|
||||
import { CodeHelpButton } from '../../components/modals';
|
||||
import styles from '../Page.module.css';
|
||||
|
||||
export function EditStepPage() {
|
||||
@@ -89,7 +90,10 @@ export function EditStepPage() {
|
||||
onChange={(e) => setTitle(e.target.value)}
|
||||
/>
|
||||
<div className={styles.formField}>
|
||||
<label className={styles.fieldLabel}>{t('steps.form_exec_code')}</label>
|
||||
<div className={styles.labelRow}>
|
||||
<label className={styles.fieldLabel}>{t('steps.form_exec_code')}</label>
|
||||
<CodeHelpButton />
|
||||
</div>
|
||||
<CodeEditor value={execCode} onChange={setExecCode} rows={6} />
|
||||
</div>
|
||||
<Input
|
||||
|
||||
@@ -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);
|
||||
@@ -761,7 +762,19 @@ export function ScenarioDetailPage() {
|
||||
{
|
||||
key: 'name',
|
||||
header: t('files.name'),
|
||||
render: (f) => f.name,
|
||||
// Served inline, so the browser shows what it can (images, text, PDF).
|
||||
render: (f) =>
|
||||
isFileExpired(f) ? (
|
||||
f.name
|
||||
) : (
|
||||
<a
|
||||
href={scenarioFiles.contentUrl(id!, f.id)}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
>
|
||||
{f.name}
|
||||
</a>
|
||||
),
|
||||
},
|
||||
{
|
||||
key: 'mimeType',
|
||||
|
||||
@@ -5,6 +5,7 @@ import { usePageTitle } from '../../hooks/usePageTitle';
|
||||
import { X, Save, Braces } from 'lucide-react';
|
||||
import { snippets } from '../../api';
|
||||
import { Breadcrumbs, Button, Card, Input, CodeEditor, useToast } from '../../ui';
|
||||
import { CodeHelpButton } from '../../components/modals';
|
||||
import styles from '../Page.module.css';
|
||||
|
||||
export function CreateSnippetPage() {
|
||||
@@ -107,10 +108,13 @@ export function CreateSnippetPage() {
|
||||
/>
|
||||
</div>
|
||||
<div className={styles.formField}>
|
||||
<label className={styles.fieldLabel}>
|
||||
{t('snippets.form_code')}
|
||||
<span className={styles.requiredMark}> *</span>
|
||||
</label>
|
||||
<div className={styles.labelRow}>
|
||||
<label className={styles.fieldLabel}>
|
||||
{t('snippets.form_code')}
|
||||
<span className={styles.requiredMark}> *</span>
|
||||
</label>
|
||||
<CodeHelpButton />
|
||||
</div>
|
||||
<CodeEditor
|
||||
value={code}
|
||||
onChange={(v) => {
|
||||
|
||||
@@ -6,6 +6,7 @@ import { X, Save, Braces } from 'lucide-react';
|
||||
import { snippets } from '../../api';
|
||||
import type { Snippet } from '../../api';
|
||||
import { Breadcrumbs, Button, Card, Input, CodeEditor, useToast } from '../../ui';
|
||||
import { CodeHelpButton } from '../../components/modals';
|
||||
import styles from '../Page.module.css';
|
||||
|
||||
export function EditSnippetPage() {
|
||||
@@ -134,10 +135,13 @@ export function EditSnippetPage() {
|
||||
/>
|
||||
</div>
|
||||
<div className={styles.formField}>
|
||||
<label className={styles.fieldLabel}>
|
||||
{t('snippets.form_code')}
|
||||
<span className={styles.requiredMark}> *</span>
|
||||
</label>
|
||||
<div className={styles.labelRow}>
|
||||
<label className={styles.fieldLabel}>
|
||||
{t('snippets.form_code')}
|
||||
<span className={styles.requiredMark}> *</span>
|
||||
</label>
|
||||
<CodeHelpButton />
|
||||
</div>
|
||||
<CodeEditor
|
||||
value={code}
|
||||
onChange={(v) => {
|
||||
|
||||
@@ -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);
|
||||
};
|
||||
|
||||
@@ -7,6 +7,8 @@
|
||||
overflow: auto;
|
||||
font-family: var(--font-mono, ui-monospace, 'Cascadia Code', 'Fira Code', monospace);
|
||||
font-size: var(--font-size-xs);
|
||||
/* Where the context/message column starts: timestamp + level + their gaps */
|
||||
--log-body-offset: calc(7em + 4.5em + 2 * var(--space-2));
|
||||
}
|
||||
|
||||
.empty {
|
||||
@@ -36,7 +38,7 @@
|
||||
}
|
||||
|
||||
.data {
|
||||
margin: 0 0 var(--space-1) calc(7em + var(--space-2));
|
||||
margin: 0 0 var(--space-1) var(--log-body-offset);
|
||||
border: var(--border-width) solid var(--color-border);
|
||||
border-radius: var(--radius-sm);
|
||||
background: var(--color-bg);
|
||||
@@ -120,3 +122,26 @@
|
||||
.error .level {
|
||||
color: var(--color-error-fg);
|
||||
}
|
||||
|
||||
.dataToggle {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: var(--space-1);
|
||||
align-self: flex-start;
|
||||
margin-left: var(--log-body-offset);
|
||||
padding: 0;
|
||||
border: none;
|
||||
background: none;
|
||||
font: inherit;
|
||||
color: var(--color-text);
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.dataToggle svg {
|
||||
flex: 0 0 auto;
|
||||
color: var(--color-primary-text);
|
||||
}
|
||||
|
||||
.dataToggle:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
@@ -1,4 +1,14 @@
|
||||
import { useMemo, useState } from 'react';
|
||||
import { ChevronDown, ChevronRight } from 'lucide-react';
|
||||
import { CodeBlock } from '../CodeBlock/CodeBlock';
|
||||
import {
|
||||
DEFAULT_LOG_DATA_LIMITS,
|
||||
exceedsLimits,
|
||||
formatElapsed,
|
||||
measureData,
|
||||
prettyData,
|
||||
type LogDataLimits,
|
||||
} from './logText';
|
||||
import styles from './LogOutput.module.css';
|
||||
|
||||
export type LogOutputLevel = 'debug' | 'log' | 'warn' | 'error';
|
||||
@@ -22,22 +32,24 @@ export interface LogOutputProps {
|
||||
maxHeight?: string | number;
|
||||
emptyMessage?: string;
|
||||
className?: string;
|
||||
/** Data blocks whose pretty-printed JSON exceeds either limit start collapsed behind a toggle. */
|
||||
dataLimits?: LogDataLimits;
|
||||
/**
|
||||
* Expands (true) or collapses (false) every large data block. Changing it
|
||||
* discards the per-entry toggles made since the last change.
|
||||
*/
|
||||
dataExpanded?: boolean;
|
||||
/** Label of a collapsed data block's toggle, e.g. "Show data (1.2 KB, 40 lines)". */
|
||||
showDataLabel?: (size: { bytes: number; lines: number }) => string;
|
||||
hideDataLabel?: string;
|
||||
}
|
||||
|
||||
/** "+12.345s" (or "-" if before startTime, e.g. clock skew). */
|
||||
function formatElapsed(deltaMs: number): string {
|
||||
const sign = deltaMs < 0 ? '-' : '+';
|
||||
return `${sign}${(Math.abs(deltaMs) / 1000).toFixed(3)}s`;
|
||||
function formatBytes(bytes: number): string {
|
||||
return bytes < 1024 ? `${bytes} B` : `${(bytes / 1024).toFixed(1)} KB`;
|
||||
}
|
||||
|
||||
/** Pretty-prints `data` if it's valid JSON, otherwise returns it as-is. */
|
||||
function prettyData(data: string): string {
|
||||
try {
|
||||
return JSON.stringify(JSON.parse(data), null, 2);
|
||||
} catch {
|
||||
return data;
|
||||
}
|
||||
}
|
||||
const defaultShowDataLabel = ({ bytes, lines }: { bytes: number; lines: number }) =>
|
||||
`Show data (${formatBytes(bytes)}, ${lines} ${lines === 1 ? 'line' : 'lines'})`;
|
||||
|
||||
/** Terminal-style log viewer: one line per entry, color-coded by level. */
|
||||
export function LogOutput({
|
||||
@@ -46,7 +58,39 @@ export function LogOutput({
|
||||
maxHeight,
|
||||
emptyMessage = 'No logs.',
|
||||
className,
|
||||
dataLimits = DEFAULT_LOG_DATA_LIMITS,
|
||||
dataExpanded = false,
|
||||
showDataLabel = defaultShowDataLabel,
|
||||
hideDataLabel = 'Hide data',
|
||||
}: LogOutputProps) {
|
||||
// Per-entry toggles, reset whenever dataExpanded changes
|
||||
const [toggled, setToggled] = useState<Set<LogOutputEntry['id']>>(() => new Set());
|
||||
const [prevDataExpanded, setPrevDataExpanded] = useState(dataExpanded);
|
||||
if (prevDataExpanded !== dataExpanded) {
|
||||
setPrevDataExpanded(dataExpanded);
|
||||
setToggled(new Set());
|
||||
}
|
||||
|
||||
const dataBlocks = useMemo(() => {
|
||||
const blocks = new Map<
|
||||
LogOutputEntry['id'],
|
||||
{ pretty: string; bytes: number; lines: number }
|
||||
>();
|
||||
for (const entry of entries) {
|
||||
if (!entry.data) continue;
|
||||
const pretty = prettyData(entry.data);
|
||||
blocks.set(entry.id, { pretty, ...measureData(pretty) });
|
||||
}
|
||||
return blocks;
|
||||
}, [entries]);
|
||||
|
||||
const toggle = (id: LogOutputEntry['id']) =>
|
||||
setToggled((prev) => {
|
||||
const next = new Set(prev);
|
||||
if (!next.delete(id)) next.add(id);
|
||||
return next;
|
||||
});
|
||||
|
||||
if (entries.length === 0) {
|
||||
return <div className={styles.empty}>{emptyMessage}</div>;
|
||||
}
|
||||
@@ -62,6 +106,9 @@ export function LogOutput({
|
||||
>
|
||||
{entries.map((entry) => {
|
||||
const entryMs = new Date(entry.createdAt).getTime();
|
||||
const block = dataBlocks.get(entry.id);
|
||||
const large = block != null && exceedsLimits(block, dataLimits);
|
||||
const open = !large || dataExpanded !== toggled.has(entry.id);
|
||||
return (
|
||||
<div key={entry.id} className={[styles.line, styles[entry.level]].join(' ')}>
|
||||
<div className={styles.lineHeader}>
|
||||
@@ -72,9 +119,24 @@ export function LogOutput({
|
||||
{entry.context && <span className={styles.context}>{entry.context}</span>}
|
||||
<span className={styles.message}>{entry.message}</span>
|
||||
</div>
|
||||
{entry.data && (
|
||||
{block && large && (
|
||||
<button
|
||||
type="button"
|
||||
className={styles.dataToggle}
|
||||
aria-expanded={open}
|
||||
onClick={() => toggle(entry.id)}
|
||||
>
|
||||
{open ? (
|
||||
<ChevronDown size={14} strokeWidth={3} aria-hidden="true" />
|
||||
) : (
|
||||
<ChevronRight size={14} strokeWidth={3} aria-hidden="true" />
|
||||
)}
|
||||
{open ? hideDataLabel : showDataLabel(block)}
|
||||
</button>
|
||||
)}
|
||||
{block && open && (
|
||||
<div className={styles.data}>
|
||||
<CodeBlock code={prettyData(entry.data)} language="json" />
|
||||
<CodeBlock code={block.pretty} language="json" />
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
import type { LogOutputEntry } from './LogOutput';
|
||||
|
||||
/** Data blocks above either limit start collapsed. */
|
||||
export interface LogDataLimits {
|
||||
/** UTF-8 byte size of the pretty-printed data. */
|
||||
bytes: number;
|
||||
/** Line count of the pretty-printed data. */
|
||||
lines: number;
|
||||
}
|
||||
|
||||
export const DEFAULT_LOG_DATA_LIMITS: LogDataLimits = { bytes: 256, lines: 5 };
|
||||
|
||||
const encoder = new TextEncoder();
|
||||
|
||||
/**
|
||||
* "+12s" (or "-" if before startTime, e.g. clock skew). Log timestamps are
|
||||
* stored with second resolution, so fractions would be noise.
|
||||
*/
|
||||
export function formatElapsed(deltaMs: number): string {
|
||||
const sign = deltaMs < 0 ? '-' : '+';
|
||||
return `${sign}${Math.round(Math.abs(deltaMs) / 1000)}s`;
|
||||
}
|
||||
|
||||
/** Pretty-prints `data` if it's valid JSON, otherwise returns it as-is. */
|
||||
export function prettyData(data: string): string {
|
||||
try {
|
||||
return JSON.stringify(JSON.parse(data), null, 2);
|
||||
} catch {
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
/** Byte size and line count of an already pretty-printed data block. */
|
||||
export function measureData(pretty: string): { bytes: number; lines: number } {
|
||||
return { bytes: encoder.encode(pretty).length, lines: pretty.split('\n').length };
|
||||
}
|
||||
|
||||
export function exceedsLimits(size: { bytes: number; lines: number }, limits: LogDataLimits) {
|
||||
return size.bytes > limits.bytes || size.lines > limits.lines;
|
||||
}
|
||||
|
||||
/** True if any entry's data block exceeds the limits (i.e. renders collapsed by default). */
|
||||
export function hasLargeData(
|
||||
entries: Pick<LogOutputEntry, 'data'>[],
|
||||
limits: LogDataLimits = DEFAULT_LOG_DATA_LIMITS,
|
||||
): boolean {
|
||||
return entries.some((e) => e.data && exceedsLimits(measureData(prettyData(e.data)), limits));
|
||||
}
|
||||
|
||||
/**
|
||||
* Plain-text rendering of the log, one entry per line with every data block
|
||||
* pretty-printed and indented below its line (e.g. for copying to the clipboard).
|
||||
*/
|
||||
export function formatLogText(
|
||||
entries: LogOutputEntry[],
|
||||
startTime?: string | number | Date,
|
||||
): string {
|
||||
if (entries.length === 0) return '';
|
||||
const startMs = new Date(startTime ?? entries[0].createdAt).getTime();
|
||||
return entries
|
||||
.map((entry) => {
|
||||
const elapsed = formatElapsed(new Date(entry.createdAt).getTime() - startMs);
|
||||
const context = entry.context ? ` [${entry.context}]` : '';
|
||||
const header = `${elapsed.padStart(6)} ${entry.level.toUpperCase().padEnd(5)}${context} ${entry.message}`;
|
||||
if (!entry.data) return header;
|
||||
const data = prettyData(entry.data)
|
||||
.split('\n')
|
||||
.map((line) => ` ${line}`)
|
||||
.join('\n');
|
||||
return `${header}\n${data}`;
|
||||
})
|
||||
.join('\n');
|
||||
}
|
||||
@@ -16,6 +16,13 @@
|
||||
border-radius: var(--radius-lg);
|
||||
box-shadow: 0 20px 48px color-mix(in srgb, #000 28%, transparent);
|
||||
overflow: hidden;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
max-height: 100%;
|
||||
}
|
||||
|
||||
.lg {
|
||||
width: min(880px, 100%);
|
||||
}
|
||||
|
||||
.header {
|
||||
@@ -31,6 +38,7 @@
|
||||
.body {
|
||||
padding: var(--space-2) var(--space-5) var(--space-4);
|
||||
color: var(--color-text-muted);
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.footer {
|
||||
|
||||
@@ -7,9 +7,11 @@ export interface ModalProps {
|
||||
children?: React.ReactNode;
|
||||
onClose: () => void;
|
||||
footer?: React.ReactNode;
|
||||
/** `lg` widens the dialog for long, document-like content. */
|
||||
size?: 'md' | 'lg';
|
||||
}
|
||||
|
||||
export function Modal({ open, title, children, onClose, footer }: ModalProps) {
|
||||
export function Modal({ open, title, children, onClose, footer, size = 'md' }: ModalProps) {
|
||||
useEffect(() => {
|
||||
if (!open) return;
|
||||
const onKeyDown = (event: KeyboardEvent) => {
|
||||
@@ -24,7 +26,7 @@ export function Modal({ open, title, children, onClose, footer }: ModalProps) {
|
||||
return (
|
||||
<div className={styles.overlay} role="presentation" onClick={onClose}>
|
||||
<div
|
||||
className={styles.dialog}
|
||||
className={size === 'lg' ? `${styles.dialog} ${styles.lg}` : styles.dialog}
|
||||
role="dialog"
|
||||
aria-modal="true"
|
||||
aria-label={title}
|
||||
@@ -33,7 +35,10 @@ export function Modal({ open, title, children, onClose, footer }: ModalProps) {
|
||||
<div className={styles.header}>
|
||||
<h3 className={styles.title}>{title}</h3>
|
||||
</div>
|
||||
<div className={styles.body}>{children}</div>
|
||||
{/* Long (lg) content scrolls; make it focusable so the keyboard can scroll it. */}
|
||||
<div className={styles.body} tabIndex={size === 'lg' ? 0 : undefined}>
|
||||
{children}
|
||||
</div>
|
||||
{footer && <div className={styles.footer}>{footer}</div>}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -72,3 +72,5 @@ export type { UuidBadgeProps } from './UuidBadge/UuidBadge';
|
||||
|
||||
export { LogOutput } from './LogOutput/LogOutput';
|
||||
export type { LogOutputProps, LogOutputEntry, LogOutputLevel } from './LogOutput/LogOutput';
|
||||
export { DEFAULT_LOG_DATA_LIMITS, formatLogText, hasLargeData } from './LogOutput/logText';
|
||||
export type { LogDataLimits } from './LogOutput/logText';
|
||||
@@ -11,6 +11,7 @@
|
||||
│ Routes / built client (ServeStaticModule) │
|
||||
│ /api/v1 REST API /docs Swagger UI │
|
||||
│ /mcp MCP tools /health health check │
|
||||
│ /manifest.json public client configuration │
|
||||
│ │
|
||||
│ McpService MCP tools → services below │
|
||||
│ ScenarioService scenarios, steps, versions, runs │
|
||||
@@ -72,8 +73,10 @@ See [scenario.md](scenario.md) for versioning, runs and import/export rules.
|
||||
|
||||
A React 19 + TypeScript SPA. During development it's served by the Vite dev server; in the Docker image the server serves the built client from the same origin as the API.
|
||||
|
||||
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` and `/health` with the client's `index.html`, so client-side routes survive a page refresh.
|
||||
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 (injected from the workspace root `package.json` at build time).
|
||||
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.
|
||||
|
||||
`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.
|
||||
|
||||
See [development.md](development.md) for the full client tech stack and directory layout.
|
||||
+9
-8
@@ -37,6 +37,8 @@ All settings are validated at startup by `server/src/config/app.config.ts`.
|
||||
| `SESSION_IDLE_TIMEOUT_MINUTES` | `30` | Idle timeout before open sessions are closed |
|
||||
| `SESSION_DELETE_CLOSED_DAYS` | `7` | Retention period for closed sessions |
|
||||
| `PLAYWRIGHT_TRACE_MODE` | `off` | Default Playwright trace mode for runs: `on`, `retain-on-failure` or `off` (see [scenario.md](scenario.md)) |
|
||||
| `RUN_LOG_DATA_COLLAPSE_BYTES` | `256` | Run log `data` blocks whose pretty-printed JSON is over this many bytes start collapsed in the UI (exposed via `/manifest.json`) |
|
||||
| `RUN_LOG_DATA_COLLAPSE_LINES` | `5` | Same, for the number of lines |
|
||||
| `CLIENT_DIR` | *(empty)* | Directory with the built client to serve at `/` (the Docker image sets it to `client`); empty means the server doesn't serve the UI |
|
||||
| `PLAYWRIGHT_CHROMIUM_EXECUTABLE_PATH` | _(Playwright default)_ | Path to a Chromium binary to use instead of Playwright's own. Not set in Docker: the image ships Playwright's `chromium-headless-shell` (matching the Playwright version) under `PLAYWRIGHT_BROWSERS_PATH=/ms-playwright`. |
|
||||
|
||||
@@ -243,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).
|
||||
|
||||
@@ -271,7 +272,7 @@ Build and start in one step:
|
||||
docker compose up -d --build
|
||||
```
|
||||
|
||||
Everything is served by the single `liqa` container at **http://localhost:13000**: the UI at `/`, the REST API at `/api/v1`, MCP at `/mcp`, Swagger at `/docs` and health at `/health`. Unknown paths outside those routes get the client's `index.html`, so client-side routes survive a page refresh.
|
||||
Everything is served by the single `liqa` container at **http://localhost:13000**: the UI at `/`, the REST API at `/api/v1`, MCP at `/mcp`, Swagger at `/docs`, health at `/health` and the client's public configuration at `/manifest.json`. Unknown paths outside those routes get the client's `index.html`, so client-side routes survive a page refresh.
|
||||
|
||||
When switching from the old two-container setup (`server` + `client`), remove the old containers with `docker compose up -d --build --remove-orphans`.
|
||||
|
||||
@@ -346,4 +347,4 @@ client/
|
||||
|
||||
Light/dark theme is toggled by the `ThemeSwitcher` button in the sidebar footer. The selection is persisted to `localStorage` and applied as `data-theme` on `<html>` before React mounts (anti-FOUC inline script in `index.html`).
|
||||
|
||||
The sidebar footer also shows the app version read from the workspace root `package.json` and injected via Vite `define`.
|
||||
The sidebar footer also shows the server's app version from `/manifest.json` (see [architecture.md](architecture.md#client-client)), falling back to the client build's version (read from the workspace root `package.json` and injected via Vite `define`). If the two differ, the version's tooltip suggests reloading the page.
|
||||
+9
-3
@@ -32,10 +32,10 @@ Available on `context`:
|
||||
- `context.env`: shallow copy of the environment's key/value map
|
||||
- `context.getEnv(key)`: environment value lookup (throws if missing)
|
||||
- `context.getCredential(alias)`: payload of the credential assigned to the scenario under `alias` (parsed JSON when the data is JSON; throws if missing)
|
||||
- `context.getStepOutput(order)`: output of a previous step by absolute order (`1`, `2`, ...) or relative (`-1` = previous step); `null` if there is none
|
||||
- `context.getStepOutput(order)`: async (`await` it); output of a previous step by absolute order (`1`, `2`, ...) or relative (`-1` = previous step); `null` if there is none
|
||||
- `context.dumpDom(selector?)`: simplified DOM snapshot of the page (or of one element)
|
||||
- `context.log(...args)`, `context.warn(...args)`, `context.error(...args)`, `context.debug(...args)`: run log entries
|
||||
- `context.assert(() => boolean, description)`: runs the arrow function and requires it to return `true`. Logs `description` (as a `log` entry on success, as an `error` entry on failure or exception), then throws to stop the step if the function returned anything other than `true` or threw
|
||||
- `context.assert(() => boolean, description, details?)`: runs the arrow function and requires it to return `true`. Logs `description` (as a `log` entry on success, as an `error` entry on failure or exception), then throws to stop the step if the function returned anything other than `true` or threw. On failure, the log entry's data holds `details` (if given) and the exception message (as `error`, if the function threw)
|
||||
- `context.runSnippet(name, ...args)`: runs stored snippet code with the same context; the snippet receives the extra arguments as `...args`. `name` is the snippet alias for its latest version, or `alias@<version>` (e.g. `login@3`) to pin a specific version. Snippet start/finish/failure is logged
|
||||
- `context.getScenarioFiles(opts?)`: list files uploaded to the scenario (`limit`, `offset`), including their path on disk
|
||||
- `context.downloadFile(url, opts?)`: fetch `url` and save the result as a run file (requires a real scenario run — throws when invoked ad hoc, e.g. via the `exec_code` MCP tool). `opts` may include `method`, `headers`, `body`, `filename`. `url` also accepts a `data:` URI (`data:<mediaType>;base64,<data>` or `data:<mediaType>,<percent-encoded data>`) to save content generated in-script (e.g. a credential JWT) directly, without an actual network fetch.
|
||||
@@ -47,17 +47,21 @@ Also in scope:
|
||||
|
||||
Code is syntax-checked before it runs, and executes in the server process: it's trusted code, not sandboxed.
|
||||
|
||||
The step and snippet editors have a (?) button next to the Code label that opens a reference of this runtime in the UI. Its content is [client/src/components/modals/code-help.md](../client/src/components/modals/code-help.md): keep it in sync with this section when the `context` API changes.
|
||||
|
||||
## Run logs
|
||||
|
||||
Each run log entry (`level`, `message`, `createdAt`) also carries a `context`: where the message was generated. Contexts:
|
||||
|
||||
- `step:<N>`: the step a log entry belongs to, including the automatic "Step N started / passed / failed" entries
|
||||
- `step:<N>`: the step a log entry belongs to, including the automatic "Step N started / passed / failed" entries ("Step N passed" carries the step's return value as `data`; "Step N failed" for an assertion failure names only the assertion, whose details are in the `assertion:fail` entry)
|
||||
- `snippet:<alias>`: entries logged while `context.runSnippet(alias, ...)` is running, including its own automatic "started"/"finished"/"failed" entries. A snippet calling another snippet tags entries with the innermost running snippet's alias
|
||||
- `assertion:pass` / `assertion:fail`: `context.assert()`'s own log entry
|
||||
- `run`: run-level entries not tied to a step (e.g. a scenario timeout, or the Playwright trace upload notice)
|
||||
|
||||
`context.log`/`warn`/`error` (and `console.log`/etc.) split their arguments: strings/numbers/booleans are joined into `message`, while object/array arguments are kept out of it and stored as `data` (JSON), so `message` stays a stable string regardless of an object's shape. With one object argument `data` is that object; with more than one, `data` is an array of them. E.g. `context.log("Saved credential as run file:", fileMeta)` logs `message: "Saved credential as run file:"` with `fileMeta` as `data`, shown pretty-printed and separately from the message in the UI.
|
||||
|
||||
On the run page, a `data` block whose pretty-printed JSON is over 256 bytes or 5 lines starts collapsed behind a "Show data" toggle (set by `RUN_LOG_DATA_COLLAPSE_BYTES` / `RUN_LOG_DATA_COLLAPSE_LINES` and passed to the UI via `/manifest.json`). The "Expand data" / "Collapse data" button next to the Logs heading opens or closes all of them. "Copy logs" copies the currently filtered logs to the clipboard as plain text, with every `data` block expanded.
|
||||
|
||||
`GET /scenarios/:id/runs/:runId?q=...` and the exported CSV/Markdown logs (`GET /scenarios/:id/runs/:runId/export`) match `q` against both `message` and `context`.
|
||||
|
||||
## Versioning
|
||||
@@ -151,3 +155,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.23.0",
|
||||
"version": "1.24.4",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "liqa",
|
||||
"version": "1.23.0",
|
||||
"version": "1.24.4",
|
||||
"license": "MIT",
|
||||
"workspaces": [
|
||||
"server",
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "liqa",
|
||||
"version": "1.23.0",
|
||||
"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)."
|
||||
@@ -12,6 +12,7 @@ import { EnvironmentModule } from "./environment/environment.module";
|
||||
import { FileModule } from "./file/file.module";
|
||||
import { HealthModule } from "./health/health.module";
|
||||
import { ImportModule } from "./import/import.module";
|
||||
import { ManifestModule } from "./manifest/manifest.module";
|
||||
import { McpModule } from "./mcp/mcp.module";
|
||||
import { ScenarioModule } from "./scenario/scenario.module";
|
||||
import { SnippetModule } from "./snippet/snippet.module";
|
||||
@@ -43,6 +44,7 @@ import { SnippetModule } from "./snippet/snippet.module";
|
||||
ImportModule,
|
||||
McpModule,
|
||||
HealthModule,
|
||||
ManifestModule,
|
||||
],
|
||||
})
|
||||
export class AppModule {}
|
||||
@@ -18,6 +18,31 @@ export interface ExecResult {
|
||||
result: unknown;
|
||||
}
|
||||
|
||||
/**
|
||||
* Thrown by `context.assert`. Its `message` includes the failure reason;
|
||||
* `summary` doesn't, so failure reports that follow the `assertion:fail` log
|
||||
* entry (which already holds the details) can stay short.
|
||||
*/
|
||||
export class AssertionFailedError extends Error {
|
||||
constructor(
|
||||
message: string,
|
||||
readonly summary: string,
|
||||
) {
|
||||
super(message);
|
||||
this.name = "AssertionFailedError";
|
||||
}
|
||||
}
|
||||
|
||||
/** The `AssertionFailedError` behind `err` (directly or via `cause`), if any. */
|
||||
export function findAssertionFailure(
|
||||
err: unknown,
|
||||
): AssertionFailedError | null {
|
||||
for (let e = err; e instanceof Error; e = (e as { cause?: unknown }).cause) {
|
||||
if (e instanceof AssertionFailedError) return e;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
export type ScriptLogger = (
|
||||
level: "debug" | "log" | "warn" | "error",
|
||||
message: string,
|
||||
@@ -50,11 +75,13 @@ export interface ScriptContext {
|
||||
/**
|
||||
* Runs `fn` and requires it to return `true`. Logs the outcome under
|
||||
* `description`, then throws if `fn` returned anything other than `true`
|
||||
* or threw an exception.
|
||||
* or threw an exception. On failure, `details` (and the exception message,
|
||||
* if any) are stored as the log entry's data.
|
||||
*/
|
||||
assert: (
|
||||
fn: () => boolean | Promise<boolean>,
|
||||
description: string,
|
||||
details?: unknown,
|
||||
) => Promise<void>;
|
||||
/** Runs a named snippet with the same context, plus any extra positional args. */
|
||||
runSnippet: (alias: string, ...args: unknown[]) => Promise<unknown>;
|
||||
@@ -194,6 +221,7 @@ export class CodeExecutorService {
|
||||
assert: async (
|
||||
fn: () => boolean | Promise<boolean>,
|
||||
description: string,
|
||||
details?: unknown,
|
||||
): Promise<void> => {
|
||||
let passed: boolean;
|
||||
let failureReason: string | undefined;
|
||||
@@ -210,8 +238,18 @@ export class CodeExecutorService {
|
||||
const message = failureReason
|
||||
? `Assertion failed: ${description} (${failureReason})`
|
||||
: `Assertion failed: ${description}`;
|
||||
emit("error", message, "assertion:fail");
|
||||
throw new Error(message);
|
||||
const failureData =
|
||||
failureReason !== undefined || details !== undefined
|
||||
? {
|
||||
...(failureReason !== undefined && { error: failureReason }),
|
||||
...(details !== undefined && { details }),
|
||||
}
|
||||
: undefined;
|
||||
emit("error", message, "assertion:fail", failureData);
|
||||
throw new AssertionFailedError(
|
||||
message,
|
||||
`Assertion failed: ${description}`,
|
||||
);
|
||||
},
|
||||
getStepOutput: getStepOutput ?? (() => Promise.resolve(null)),
|
||||
getCredential: (alias: string): unknown => {
|
||||
@@ -262,7 +300,7 @@ export class CodeExecutorService {
|
||||
} catch (err) {
|
||||
emit(
|
||||
"error",
|
||||
`Snippet "${alias}" failed: ${(err as Error).message}`,
|
||||
`Snippet "${alias}" failed: ${findAssertionFailure(err)?.summary ?? (err as Error).message}`,
|
||||
snippetContext,
|
||||
);
|
||||
throw err;
|
||||
|
||||
@@ -9,6 +9,7 @@ const SERVER_ROUTES = [
|
||||
"/docs{*path}",
|
||||
"/health",
|
||||
"/healthz",
|
||||
"/manifest.json",
|
||||
];
|
||||
|
||||
/**
|
||||
|
||||
@@ -64,6 +64,16 @@ export class AppConfig {
|
||||
@IsEnum(TraceMode)
|
||||
// Off by default: traces with screenshots and snapshots easily reach ~10 MB per run
|
||||
PLAYWRIGHT_TRACE_MODE: TraceMode = TraceMode.Off;
|
||||
|
||||
/** Run log data blocks over this many bytes (pretty-printed) start collapsed in the UI. */
|
||||
@IsInt()
|
||||
@Min(0)
|
||||
RUN_LOG_DATA_COLLAPSE_BYTES: number = 256;
|
||||
|
||||
/** Run log data blocks over this many lines (pretty-printed) start collapsed in the UI. */
|
||||
@IsInt()
|
||||
@Min(0)
|
||||
RUN_LOG_DATA_COLLAPSE_LINES: number = 5;
|
||||
}
|
||||
|
||||
export function validateAppConfig(config: Record<string, unknown>): AppConfig {
|
||||
|
||||
@@ -51,6 +51,7 @@ async function bootstrap() {
|
||||
{ path: "health", method: RequestMethod.ALL },
|
||||
{ path: "healthz", method: RequestMethod.ALL },
|
||||
{ path: "mcp", method: RequestMethod.ALL },
|
||||
{ path: "manifest.json", method: RequestMethod.ALL },
|
||||
],
|
||||
});
|
||||
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
import { Controller, Get, Header } from "@nestjs/common";
|
||||
import { ConfigService } from "@nestjs/config";
|
||||
import { ApiOkResponse, ApiOperation, ApiTags } from "@nestjs/swagger";
|
||||
import { AppConfig } from "../config/app.config";
|
||||
import { ManifestDto } from "./manifest.dto";
|
||||
|
||||
@ApiTags("manifest")
|
||||
@Controller()
|
||||
export class ManifestController {
|
||||
constructor(private readonly config: ConfigService<AppConfig, true>) {}
|
||||
|
||||
@Get("manifest.json")
|
||||
// Clients cache the manifest themselves; the browser just revalidates it (ETag)
|
||||
@Header("Cache-Control", "no-cache")
|
||||
@ApiOperation({ summary: "Public client configuration and app version" })
|
||||
@ApiOkResponse({ type: ManifestDto })
|
||||
manifest(): ManifestDto {
|
||||
return {
|
||||
name: this.config.get("APP_NAME"),
|
||||
version: this.config.get("APP_VERSION"),
|
||||
runLogs: {
|
||||
dataLimits: {
|
||||
bytes: this.config.get("RUN_LOG_DATA_COLLAPSE_BYTES"),
|
||||
lines: this.config.get("RUN_LOG_DATA_COLLAPSE_LINES"),
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
import { ApiProperty } from "@nestjs/swagger";
|
||||
|
||||
export class RunLogDataLimitsDto {
|
||||
@ApiProperty({
|
||||
description: "Data blocks over this many bytes (pretty-printed) start collapsed",
|
||||
example: 256,
|
||||
})
|
||||
bytes!: number;
|
||||
|
||||
@ApiProperty({
|
||||
description: "Data blocks over this many lines (pretty-printed) start collapsed",
|
||||
example: 5,
|
||||
})
|
||||
lines!: number;
|
||||
}
|
||||
|
||||
export class RunLogsManifestDto {
|
||||
@ApiProperty({ type: RunLogDataLimitsDto })
|
||||
dataLimits!: RunLogDataLimitsDto;
|
||||
}
|
||||
|
||||
export class ManifestDto {
|
||||
@ApiProperty({ example: "liqa" })
|
||||
name!: string;
|
||||
|
||||
@ApiProperty({ example: "1.4.0" })
|
||||
version!: string;
|
||||
|
||||
@ApiProperty({ type: RunLogsManifestDto })
|
||||
runLogs!: RunLogsManifestDto;
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
import { Module } from "@nestjs/common";
|
||||
import { ManifestController } from "./manifest.controller";
|
||||
|
||||
@Module({
|
||||
controllers: [ManifestController],
|
||||
})
|
||||
export class ManifestModule {}
|
||||
@@ -370,7 +370,11 @@ function buildContext(page: Page, browser: BrowserContext, stepOutputs: StepOutp
|
||||
log: (...args: unknown[]) => console.log(...args),
|
||||
warn: (...args: unknown[]) => console.warn(...args),
|
||||
error: (...args: unknown[]) => console.error(...args),
|
||||
assert: async (fn: () => boolean | Promise<boolean>, description: string): Promise<void> => {
|
||||
assert: async (
|
||||
fn: () => boolean | Promise<boolean>,
|
||||
description: string,
|
||||
details?: unknown,
|
||||
): Promise<void> => {
|
||||
let passed: boolean;
|
||||
let failureReason: string | undefined;
|
||||
try {
|
||||
@@ -386,7 +390,11 @@ function buildContext(page: Page, browser: BrowserContext, stepOutputs: StepOutp
|
||||
const message = failureReason
|
||||
? \`Assertion failed: \${description} (\${failureReason})\`
|
||||
: \`Assertion failed: \${description}\`;
|
||||
console.error(message);
|
||||
if (details !== undefined) {
|
||||
console.error(message, details);
|
||||
} else {
|
||||
console.error(message);
|
||||
}
|
||||
throw new Error(message);
|
||||
},
|
||||
getStepOutput: async (order: number): Promise<unknown> => {
|
||||
|
||||
@@ -13,7 +13,10 @@ import { Repository } from "typeorm";
|
||||
import { type AppConfig, TraceMode } from "../config/app.config";
|
||||
import { FileStorageService } from "../file/file-storage.service";
|
||||
import type { ScriptLogger } from "../code-executor/code-executor.service";
|
||||
import { CodeExecutorService } from "../code-executor/code-executor.service";
|
||||
import {
|
||||
CodeExecutorService,
|
||||
findAssertionFailure,
|
||||
} from "../code-executor/code-executor.service";
|
||||
import { ExecContextBuilder } from "../code-executor/exec-context.builder";
|
||||
import { traceStorage } from "../common/trace-context";
|
||||
import { TraceLogger } from "../common/trace-logger";
|
||||
@@ -446,7 +449,11 @@ export class ScenarioSchedulerService implements OnModuleInit {
|
||||
} catch (err) {
|
||||
const msg = (err as Error).message ?? String(err);
|
||||
this.logger.error(`StepRun #${stepRun.id} threw: ${msg}`);
|
||||
await this.failStepRun(stepRun, msg);
|
||||
await this.failStepRun(
|
||||
stepRun,
|
||||
msg,
|
||||
findAssertionFailure(err)?.summary,
|
||||
);
|
||||
} finally {
|
||||
clearTimeout(timeoutId);
|
||||
}
|
||||
@@ -571,6 +578,7 @@ export class ScenarioSchedulerService implements OnModuleInit {
|
||||
"log",
|
||||
`Step ${stepRun.order} passed`,
|
||||
`step:${stepRun.order}`,
|
||||
output,
|
||||
);
|
||||
|
||||
// Find the next waiting step in this run (next by order)
|
||||
@@ -600,9 +608,14 @@ export class ScenarioSchedulerService implements OnModuleInit {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* `logSummary` replaces `description` in the "Step N failed" log entry, e.g.
|
||||
* for assertion failures whose details are already logged.
|
||||
*/
|
||||
private async failStepRun(
|
||||
stepRun: ScenarioRunStepEntity,
|
||||
description: string,
|
||||
logSummary?: string,
|
||||
): Promise<void> {
|
||||
stepRun.status = "fail";
|
||||
stepRun.description = description;
|
||||
@@ -612,7 +625,7 @@ export class ScenarioSchedulerService implements OnModuleInit {
|
||||
stepRun.runId,
|
||||
stepRun.id,
|
||||
"error",
|
||||
`Step ${stepRun.order} failed: ${description}`,
|
||||
`Step ${stepRun.order} failed: ${logSummary ?? description}`,
|
||||
`step:${stepRun.order}`,
|
||||
);
|
||||
|
||||
|
||||
@@ -44,6 +44,7 @@ import { EnvironmentModule } from "../src/environment/environment.module";
|
||||
import { ScenarioModule } from "../src/scenario/scenario.module";
|
||||
import { McpModule } from "../src/mcp/mcp.module";
|
||||
import { HealthController } from "../src/health/health.controller";
|
||||
import { ManifestController } from "../src/manifest/manifest.controller";
|
||||
import { HttpExceptionFilter } from "../src/filters/http-exception.filter";
|
||||
import { LoggingInterceptor } from "../src/interceptors/logging.interceptor";
|
||||
import { validateAppConfig } from "../src/config/app.config";
|
||||
@@ -74,7 +75,7 @@ export async function buildTestApp(): Promise<INestApplication> {
|
||||
ImportModule,
|
||||
McpModule,
|
||||
],
|
||||
controllers: [HealthController],
|
||||
controllers: [HealthController, ManifestController],
|
||||
}).compile();
|
||||
|
||||
const app = module.createNestApplication<NestExpressApplication>();
|
||||
|
||||
@@ -35,6 +35,11 @@ class RootRoutesController {
|
||||
return { status: "ok" };
|
||||
}
|
||||
|
||||
@Get("manifest.json")
|
||||
manifest() {
|
||||
return { version: "1.0.0" };
|
||||
}
|
||||
|
||||
@Post("mcp")
|
||||
mcp() {
|
||||
return { jsonrpc: "2.0" };
|
||||
@@ -59,6 +64,7 @@ async function buildApp(clientDir: string): Promise<INestApplication> {
|
||||
exclude: [
|
||||
{ path: "health", method: RequestMethod.ALL },
|
||||
{ path: "mcp", method: RequestMethod.ALL },
|
||||
{ path: "manifest.json", method: RequestMethod.ALL },
|
||||
],
|
||||
});
|
||||
await app.init();
|
||||
@@ -132,6 +138,12 @@ describe("Client static serving", () => {
|
||||
expect(res.text).not.toContain("liqa</html>");
|
||||
});
|
||||
|
||||
it("leaves /manifest.json to the server", async () => {
|
||||
await request(app.getHttpServer())
|
||||
.get("/manifest.json")
|
||||
.expect(200, { version: "1.0.0" });
|
||||
});
|
||||
|
||||
it("serves nothing when no client directory is configured", async () => {
|
||||
const bare = await buildApp("");
|
||||
await request(bare.getHttpServer()).get("/").expect(404);
|
||||
|
||||
@@ -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,40 @@
|
||||
import { INestApplication } from "@nestjs/common";
|
||||
import request from "supertest";
|
||||
import { appPackage } from "../src/common/app-package";
|
||||
import { buildTestApp } from "./app.harness";
|
||||
|
||||
describe("GET /manifest.json", () => {
|
||||
let app: INestApplication;
|
||||
|
||||
afterEach(async () => {
|
||||
delete process.env.RUN_LOG_DATA_COLLAPSE_BYTES;
|
||||
delete process.env.RUN_LOG_DATA_COLLAPSE_LINES;
|
||||
await app?.close();
|
||||
});
|
||||
|
||||
it("returns the app version and default run log data limits", async () => {
|
||||
app = await buildTestApp();
|
||||
const res = await request(app.getHttpServer())
|
||||
.get("/manifest.json")
|
||||
.expect(200);
|
||||
|
||||
expect(res.body).toEqual({
|
||||
name: appPackage().name,
|
||||
version: appPackage().version,
|
||||
runLogs: { dataLimits: { bytes: 256, lines: 5 } },
|
||||
});
|
||||
expect(res.headers["cache-control"]).toBe("no-cache");
|
||||
expect(res.headers["etag"]).toBeDefined();
|
||||
});
|
||||
|
||||
it("takes the run log data limits from the configuration", async () => {
|
||||
process.env.RUN_LOG_DATA_COLLAPSE_BYTES = "1024";
|
||||
process.env.RUN_LOG_DATA_COLLAPSE_LINES = "20";
|
||||
app = await buildTestApp();
|
||||
const res = await request(app.getHttpServer())
|
||||
.get("/manifest.json")
|
||||
.expect(200);
|
||||
|
||||
expect(res.body.runLogs.dataLimits).toEqual({ bytes: 1024, lines: 20 });
|
||||
});
|
||||
});
|
||||
@@ -208,4 +208,83 @@ describe("ScenarioRunStepEntity.output + context.getStepOutput", () => {
|
||||
expect(JSON.parse(rows[2].output as string)).toEqual([1, 2, 3, 4]);
|
||||
});
|
||||
});
|
||||
// ── run log data ───────────────────────────────────────────────────────────
|
||||
|
||||
describe("run log data", () => {
|
||||
async function logRows(
|
||||
runId: string,
|
||||
context: string,
|
||||
): Promise<Array<{ message: string; data: string | null }>> {
|
||||
return dataSource.query(
|
||||
`SELECT message, data FROM scenario_run_logs WHERE runId = '${runId}' AND context = '${context}' ORDER BY seq`,
|
||||
);
|
||||
}
|
||||
|
||||
it("attaches the step output to the 'Step N passed' entry", async () => {
|
||||
await seedSession();
|
||||
const scId = await createScenario("log-step-output");
|
||||
await createStep(scId, 0, 'return { token: "abc" };');
|
||||
|
||||
const runId = await runScenario(scId);
|
||||
const rows = await logRows(runId, "step:1");
|
||||
const passed = rows.find((r) => r.message === "Step 1 passed");
|
||||
|
||||
expect(JSON.parse(passed!.data as string)).toEqual({ token: "abc" });
|
||||
});
|
||||
|
||||
it("stores assertion failure details as log data", async () => {
|
||||
await seedSession();
|
||||
const scId = await createScenario("log-assert-details");
|
||||
await createStep(
|
||||
scId,
|
||||
0,
|
||||
'await context.assert(() => false, "Validation must pass", { status: 500 });',
|
||||
);
|
||||
|
||||
const runId = await runScenario(scId);
|
||||
const [row] = await logRows(runId, "assertion:fail");
|
||||
|
||||
expect(row.message).toBe("Assertion failed: Validation must pass");
|
||||
expect(JSON.parse(row.data as string)).toEqual({
|
||||
details: { status: 500 },
|
||||
});
|
||||
});
|
||||
|
||||
it("keeps the 'Step N failed' entry of an assertion failure short", async () => {
|
||||
await seedSession();
|
||||
const scId = await createScenario("log-assert-step-fail");
|
||||
await createStep(
|
||||
scId,
|
||||
0,
|
||||
'await context.assert(() => { throw new Error("boom"); }, "Must not throw");',
|
||||
);
|
||||
|
||||
const runId = await runScenario(scId);
|
||||
const rows = await logRows(runId, "step:1");
|
||||
const failed = rows.find((r) => r.message.startsWith("Step 1 failed:"));
|
||||
|
||||
expect(failed!.message).toBe(
|
||||
"Step 1 failed: Assertion failed: Must not throw",
|
||||
);
|
||||
const stepRow = await dataSource.query(
|
||||
`SELECT description FROM scenario_run_steps WHERE runId = '${runId}'`,
|
||||
);
|
||||
expect(stepRow[0].description).toContain("(boom)");
|
||||
});
|
||||
|
||||
it("stores the exception message of a throwing assertion as log data", async () => {
|
||||
await seedSession();
|
||||
const scId = await createScenario("log-assert-throw");
|
||||
await createStep(
|
||||
scId,
|
||||
0,
|
||||
'await context.assert(() => { throw new Error("boom"); }, "Must not throw");',
|
||||
);
|
||||
|
||||
const runId = await runScenario(scId);
|
||||
const [row] = await logRows(runId, "assertion:fail");
|
||||
|
||||
expect(JSON.parse(row.data as string)).toEqual({ error: "boom" });
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user