Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e586ab9bd9 | ||
|
|
68415f805b | ||
|
|
a4bfa3117f |
No files matched your search
@@ -7,3 +7,4 @@ node_modules
|
||||
**/*.log
|
||||
data
|
||||
keys
|
||||
**/*.tsbuildinfo
|
||||
+6
-1
@@ -7,7 +7,8 @@ KEYS_DIR=keys
|
||||
# SQLite database path
|
||||
DB_PATH=data/sessions.db
|
||||
|
||||
# Playwright executable (set in Docker; leave empty to use system default)
|
||||
# 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
|
||||
|
||||
# Session lifecycle
|
||||
@@ -19,3 +20,7 @@ SESSION_DELETE_CLOSED_DAYS=7
|
||||
# Playwright trace recording for scenario runs: on | retain-on-failure | off
|
||||
# (traces often reach ~10 MB per run; can be overridden per run in the run modal)
|
||||
PLAYWRIGHT_TRACE_MODE=off
|
||||
|
||||
# Directory with the built client to serve at / (set to "client" in the Docker image;
|
||||
# leave empty to not serve the UI, e.g. when using the Vite dev server)
|
||||
# CLIENT_DIR=
|
||||
@@ -2,6 +2,37 @@
|
||||
|
||||
All notable changes to this project will be documented in this file.
|
||||
|
||||
## 1.19.2 - 2026-09-30
|
||||
|
||||
Changes since 1.19.1:
|
||||
|
||||
### Fixed
|
||||
|
||||
- Running a scenario from its detail page could preselect the first environment in the list instead of the scenario's default environment, depending on whether the environment list or the scenario loaded first. The default environment is now chosen when the run modal opens.
|
||||
- Made the run status filter test deterministic; it could fail when the scheduler picked up the test's pending run mid-test.
|
||||
|
||||
## 1.19.1 - 2026-09-30
|
||||
|
||||
Changes since 1.19.0:
|
||||
|
||||
### Changed
|
||||
|
||||
- Upgraded to Node.js 24: the Docker image is based on `node:24-slim`, and the root `package.json` declares `"engines": { "node": ">=24" }`.
|
||||
- The server reads the app name and version (startup log, Swagger, MCP server info, `APP_NAME`/`APP_VERSION`) from the workspace root `package.json`. Previously local runs reported the server workspace's own `liqa-server` / `1.0.0`; the server workspace no longer has a version.
|
||||
|
||||
### Fixed
|
||||
|
||||
- Tests using a local HTTP server bind to `127.0.0.1` instead of `localhost`, which could resolve to an unreachable `::1` inside Docker containers.
|
||||
|
||||
## 1.19.0 - 2026-09-30
|
||||
|
||||
Changes since 1.18.0:
|
||||
|
||||
### Changed
|
||||
|
||||
- **Breaking (deployment):** the whole application now runs from a single image and container. The server serves the built client itself (new `CLIENT_DIR` setting, set by the image) next to the API, MCP and Swagger, so the UI moved from http://localhost:13001 to **http://localhost:13000**. The root `Dockerfile` replaces `server/Dockerfile`, `client/Dockerfile` and `client/nginx.conf`, and `compose.yaml` has a single `liqa` service. When upgrading, run `docker compose up -d --build --remove-orphans` to remove the old `server` and `client` containers.
|
||||
- The image uses Playwright's headless-only Chromium build (`chromium-headless-shell`, always matching the installed Playwright version) with only the libraries it needs, instead of Debian's desktop `chromium` package. Fonts are now DejaVu and Liberation (metric-compatible with Arial/Times) instead of Noto. Together with clearing the npm cache, this shrinks the image from 1.76 GB to 1.07 GB.
|
||||
|
||||
## 1.18.0 - 2026-09-30
|
||||
|
||||
Changes since 1.17.0:
|
||||
|
||||
@@ -15,18 +15,14 @@ It is an npm workspace with two packages:
|
||||
- [docs/scenario.md](docs/scenario.md) - scenario execution, script `context` API, versioning, export/import, Playwright traces
|
||||
- [docs/mcp.md](docs/mcp.md) - MCP tool reference
|
||||
- [CHANGELOG.md](CHANGELOG.md) - release notes per version
|
||||
- [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`)
|
||||
|
||||
## Default deployment (docker compose)
|
||||
|
||||
`compose.yaml` at the repo root runs two containers:
|
||||
`compose.yaml` at the repo root runs a single `liqa` container, built from the root `Dockerfile`, at http://localhost:13000. The server serves everything: the UI at `/` (the built client, via `CLIENT_DIR`), the REST API at `/api/v1`, MCP at `/mcp`, Swagger at `/docs`. It reads `.env` and mounts `./data` (SQLite DB `data/liqa.db` + stored files) and `./keys`.
|
||||
|
||||
| Service | URL | Notes |
|
||||
|---|---|---|
|
||||
| `server` | http://localhost:13000 | Built from `server/Dockerfile`; reads `.env`; mounts `./data` (SQLite DB `data/liqa.db` + stored files) and `./keys` |
|
||||
| `client` | http://localhost:13001 | Built from `client/Dockerfile`; nginx serves the SPA and proxies `/api/` to `server:3000` |
|
||||
|
||||
Rebuild and restart: `docker compose up -d --build`. Check with `docker compose ps`, `curl localhost:13000/health` and `docker compose logs server`.
|
||||
Rebuild and restart: `docker compose up -d --build`. Check with `docker compose ps`, `curl localhost:13000/health` and `docker compose logs liqa`.
|
||||
|
||||
The live database is `data/liqa.db`. Because the schema is synced on startup, back it up before deploying entity changes.
|
||||
|
||||
|
||||
+87
@@ -0,0 +1,87 @@
|
||||
# Single image serving the whole application: the NestJS server (API, MCP,
|
||||
# scheduler) also serves the built client, so one container is enough.
|
||||
|
||||
# ── Client build ──────────────────────────────────────────────────────────────
|
||||
FROM node:24-slim AS client-build
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# Root lockfile + workspace manifest so npm ci can resolve the full graph
|
||||
COPY package*.json ./
|
||||
COPY client/package.json ./client/
|
||||
RUN npm ci -w client
|
||||
|
||||
COPY client ./client
|
||||
RUN npm run -w client build
|
||||
|
||||
# ── Server build ──────────────────────────────────────────────────────────────
|
||||
FROM node:24-slim AS server-build
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
COPY package*.json ./
|
||||
COPY server/package.json ./server/
|
||||
RUN npm ci -w server
|
||||
|
||||
COPY server/nest-cli.json ./server/
|
||||
COPY server/tsconfig*.json ./server/
|
||||
COPY server/src ./server/src
|
||||
RUN npm run -w server build
|
||||
|
||||
# ── Runtime ───────────────────────────────────────────────────────────────────
|
||||
FROM node:24-slim AS runtime
|
||||
|
||||
# Shared libraries chrome-headless-shell links against (from `ldd`), plus
|
||||
# fontconfig and basic fonts for text rendering. Playwright's `--with-deps`
|
||||
# would also pull in xvfb (with Mesa/LLVM) and extra font packages, which
|
||||
# headless-only use doesn't need.
|
||||
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||
ca-certificates \
|
||||
fontconfig \
|
||||
fonts-dejavu-core \
|
||||
fonts-liberation \
|
||||
libasound2 \
|
||||
libatk-bridge2.0-0 \
|
||||
libatk1.0-0 \
|
||||
libatspi2.0-0 \
|
||||
libdbus-1-3 \
|
||||
libexpat1 \
|
||||
libgbm1 \
|
||||
libglib2.0-0 \
|
||||
libnspr4 \
|
||||
libnss3 \
|
||||
libx11-6 \
|
||||
libxcb1 \
|
||||
libxcomposite1 \
|
||||
libxdamage1 \
|
||||
libxext6 \
|
||||
libxfixes3 \
|
||||
libxkbcommon0 \
|
||||
libxrandr2 \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
COPY package*.json ./
|
||||
COPY server/package.json ./server/
|
||||
|
||||
# Playwright's headless-only Chromium build, matching the installed Playwright
|
||||
# version. All browser launches are headless, so the full desktop Chromium
|
||||
# (GTK, Mesa/LLVM, icon themes) isn't needed.
|
||||
ENV PLAYWRIGHT_BROWSERS_PATH=/ms-playwright
|
||||
RUN npm ci --omit=dev -w server \
|
||||
&& npx playwright install --only-shell chromium \
|
||||
&& npm cache clean --force
|
||||
|
||||
COPY --from=server-build /app/server/dist ./dist
|
||||
COPY --from=client-build /app/client/dist ./client
|
||||
|
||||
# Serve the built client at / (see server/src/common/client-static.ts)
|
||||
ENV CLIENT_DIR=client
|
||||
|
||||
# Runtime directories (keys and SQLite DB mounted via volumes)
|
||||
RUN mkdir -p data
|
||||
|
||||
EXPOSE 3000
|
||||
|
||||
CMD ["node", "dist/main"]
|
||||
@@ -1,20 +0,0 @@
|
||||
# ── Build stage ───────────────────────────────────────────────────────────────
|
||||
FROM node:22-slim AS builder
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# Copy root lockfile + workspace manifests so npm ci can resolve the full graph
|
||||
COPY package*.json ./
|
||||
COPY client/package.json ./client/
|
||||
RUN npm ci -w client
|
||||
|
||||
COPY client ./client
|
||||
RUN npm run -w client build
|
||||
|
||||
# ── Runtime stage ─────────────────────────────────────────────────────────────
|
||||
FROM nginx:alpine AS runtime
|
||||
|
||||
COPY --from=builder /app/client/dist /usr/share/nginx/html
|
||||
COPY client/nginx.conf /etc/nginx/conf.d/default.conf
|
||||
|
||||
EXPOSE 80
|
||||
@@ -1,17 +0,0 @@
|
||||
server {
|
||||
listen 80;
|
||||
root /usr/share/nginx/html;
|
||||
index index.html;
|
||||
|
||||
location /api/ {
|
||||
proxy_pass http://server:3000;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
}
|
||||
|
||||
location / {
|
||||
try_files $uri $uri/ /index.html;
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
import { useEffect, useRef, useState, useCallback, SubmitEvent } from 'react';
|
||||
import { useEffect, useState, useCallback, SubmitEvent } from 'react';
|
||||
import { useNavigate, useParams } from 'react-router-dom';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { usePageTitle } from '../../hooks/usePageTitle';
|
||||
@@ -85,7 +85,6 @@ export function ScenarioDetailPage() {
|
||||
const traceMode = traceModeOverride ?? runDefaults?.traceMode ?? 'off';
|
||||
const [envs, setEnvs] = useState<Environment[]>([]);
|
||||
const [selectedEnvId, setSelectedEnvId] = useState('');
|
||||
const envInitRef = useRef(false);
|
||||
const [pendingDelete, setPendingDelete] = useState<
|
||||
{ type: 'scenario' } | { type: 'step'; id: string } | { type: 'credential'; id: string } | null
|
||||
>(null);
|
||||
@@ -144,14 +143,23 @@ export function ScenarioDetailPage() {
|
||||
.catch(() => {});
|
||||
}, [id, loadFiles]);
|
||||
|
||||
// Default selected env to scenario's linked environment (or first env) once both are loaded
|
||||
useEffect(() => {
|
||||
if (envInitRef.current || envs.length === 0) return;
|
||||
envInitRef.current = true;
|
||||
const openRunModal = () => {
|
||||
// Preselect the scenario's default environment (or the first one) when the
|
||||
// modal opens: by then both are loaded, and it follows default env edits
|
||||
const preferred = scenario?.environmentId ?? null;
|
||||
const exists = preferred ? envs.some((e) => e.id === preferred) : false;
|
||||
setSelectedEnvId(exists ? preferred! : envs[0].id);
|
||||
}, [scenario, envs]);
|
||||
setSelectedEnvId(exists ? preferred! : (envs[0]?.id ?? ''));
|
||||
setTraceModeOverride(null);
|
||||
setRunVersion(null);
|
||||
setRunVersions([]);
|
||||
if (id) {
|
||||
scenarios
|
||||
.versions(id)
|
||||
.then(setRunVersions)
|
||||
.catch(() => undefined);
|
||||
}
|
||||
setRunModalOpen(true);
|
||||
};
|
||||
|
||||
const reloadScenario = async () => {
|
||||
if (!id) return;
|
||||
@@ -470,21 +478,7 @@ export function ScenarioDetailPage() {
|
||||
/>
|
||||
{scenario && (
|
||||
<div className={styles.toolbarActions}>
|
||||
<Button
|
||||
size="sm"
|
||||
onClick={() => {
|
||||
setTraceModeOverride(null);
|
||||
setRunVersion(null);
|
||||
setRunVersions([]);
|
||||
if (id) {
|
||||
scenarios
|
||||
.versions(id)
|
||||
.then(setRunVersions)
|
||||
.catch(() => undefined);
|
||||
}
|
||||
setRunModalOpen(true);
|
||||
}}
|
||||
>
|
||||
<Button size="sm" onClick={openRunModal}>
|
||||
<Play size={14} />
|
||||
{t('scenarios.action_run')}
|
||||
</Button>
|
||||
|
||||
+2
-10
@@ -1,9 +1,9 @@
|
||||
services:
|
||||
server:
|
||||
liqa:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: server/Dockerfile
|
||||
ports:
|
||||
# UI, REST API (/api/v1), MCP (/mcp) and Swagger (/docs)
|
||||
- "13000:3000"
|
||||
env_file:
|
||||
- .env
|
||||
@@ -13,11 +13,3 @@ services:
|
||||
# mount key files into the container
|
||||
- ./keys:/app/keys
|
||||
restart: unless-stopped
|
||||
|
||||
client:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: client/Dockerfile
|
||||
ports:
|
||||
- "13001:80"
|
||||
restart: unless-stopped
|
||||
@@ -41,9 +41,9 @@ MCP client (AI agent / VS Code Copilot)
|
||||
|
||||
## Client (`client/`)
|
||||
|
||||
A React 19 + TypeScript SPA served separately by Vite during development. In Docker Compose the same build artefacts are served statically alongside the API.
|
||||
A React 19 + TypeScript SPA served by the Vite dev server during development. In the Docker image the server serves the built client itself (`ServeStaticModule`, see `server/src/common/client-static.ts`), from the same origin as the API.
|
||||
|
||||
The client calls the server REST endpoints directly — there is no separate BFF layer. Routing uses HashRouter so the Vite proxy and server-side routes are never ambiguous.
|
||||
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 sidebar footer contains the theme switcher and the app version (injected from the workspace root `package.json` at build time).
|
||||
|
||||
|
||||
+10
-3
@@ -2,7 +2,7 @@
|
||||
|
||||
## Prerequisites
|
||||
|
||||
- Node.js 20+
|
||||
- Node.js 24+ (required by `engines` in `package.json`; the Docker image uses Node.js 24)
|
||||
- Docker + Docker Compose
|
||||
|
||||
The repository is a **npm workspace monorepo** with two packages:
|
||||
@@ -30,7 +30,8 @@ Copy `.env.example` to `.env` and fill in the required values before running.
|
||||
| `DB_PATH` | `data/sessions.db` | SQLite database file |
|
||||
| `SESSION_IDLE_TIMEOUT_MINUTES` | `30` | Idle timeout before open sessions are closed |
|
||||
| `SESSION_DELETE_CLOSED_DAYS` | `7` | Retention period for closed sessions |
|
||||
| `PLAYWRIGHT_CHROMIUM_EXECUTABLE_PATH` | _(Playwright default)_ | Path to Chromium binary. Set automatically in Docker (`/usr/bin/chromium`). |
|
||||
| `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`. |
|
||||
|
||||
---
|
||||
|
||||
@@ -163,6 +164,10 @@ Both workspaces target zero errors. Run lint before committing.
|
||||
|
||||
## Building the container
|
||||
|
||||
The root `Dockerfile` builds a single image with the whole application: it builds the client and the server in separate stages, and the runtime image runs the server, which also serves the built client (`CLIENT_DIR`).
|
||||
|
||||
The runtime image uses Playwright's headless-only Chromium build (`chromium-headless-shell`) with just the shared libraries it links against, plus DejaVu and Liberation fonts (Liberation is metric-compatible with Arial/Times, so pages lay out as they would with those fonts). All browser launches are headless, so the full desktop Chromium isn't installed. If a new Playwright version needs another library, `ldd` on the `chrome-headless-shell` binary in the image lists what's missing.
|
||||
|
||||
```bash
|
||||
docker compose build
|
||||
```
|
||||
@@ -189,7 +194,9 @@ Build and start in one step:
|
||||
docker compose up -d --build
|
||||
```
|
||||
|
||||
The server API is exposed at **http://localhost:13000**.
|
||||
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.
|
||||
|
||||
When switching from the old two-container setup (`server` + `client`), remove the old containers with `docker compose up -d --build --remove-orphans`.
|
||||
|
||||
SQLite data is persisted in `./data/` and key files are mounted from `./keys/` — both directories are volume-mounted into the container.
|
||||
|
||||
|
||||
Generated
+34
-4
@@ -1,16 +1,19 @@
|
||||
{
|
||||
"name": "liqa",
|
||||
"version": "1.18.0",
|
||||
"version": "1.19.2",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "liqa",
|
||||
"version": "1.18.0",
|
||||
"version": "1.19.2",
|
||||
"workspaces": [
|
||||
"server",
|
||||
"client"
|
||||
]
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=24"
|
||||
}
|
||||
},
|
||||
"client": {
|
||||
"name": "liqa-client",
|
||||
@@ -3387,6 +3390,33 @@
|
||||
"tslib": "^2.1.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@nestjs/serve-static": {
|
||||
"version": "5.0.5",
|
||||
"resolved": "https://registry.npmjs.org/@nestjs/serve-static/-/serve-static-5.0.5.tgz",
|
||||
"integrity": "sha512-AhYx3N9aMwR2cb0w5Nlb5nHNYiAcF74ea/D/xna+PxlXwjmwGN/PpC/5fuMtOwmPBMgOTxNPOnB8C9LDZBSgyw==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"path-to-regexp": "8.4.2"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@fastify/static": "^8.0.4 || ^9.0.0",
|
||||
"@nestjs/common": "^11.0.2",
|
||||
"@nestjs/core": "^11.0.2",
|
||||
"express": "^5.0.1",
|
||||
"fastify": "^5.2.1"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"@fastify/static": {
|
||||
"optional": true
|
||||
},
|
||||
"express": {
|
||||
"optional": true
|
||||
},
|
||||
"fastify": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/@nestjs/swagger": {
|
||||
"version": "11.2.6",
|
||||
"resolved": "https://registry.npmjs.org/@nestjs/swagger/-/swagger-11.2.6.tgz",
|
||||
@@ -16666,7 +16696,6 @@
|
||||
},
|
||||
"server": {
|
||||
"name": "liqa-server",
|
||||
"version": "1.0.0",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"@modelcontextprotocol/sdk": "^1.29.0",
|
||||
@@ -16676,6 +16705,7 @@
|
||||
"@nestjs/core": "^11.1.18",
|
||||
"@nestjs/platform-express": "^11.1.18",
|
||||
"@nestjs/schedule": "^6.1.1",
|
||||
"@nestjs/serve-static": "^5.0.5",
|
||||
"@nestjs/swagger": "^11.2.6",
|
||||
"@nestjs/typeorm": "^11.0.1",
|
||||
"@playwright/test": "^1.59.1",
|
||||
|
||||
+4
-1
@@ -1,7 +1,10 @@
|
||||
{
|
||||
"name": "liqa",
|
||||
"version": "1.18.0",
|
||||
"version": "1.19.2",
|
||||
"private": true,
|
||||
"engines": {
|
||||
"node": ">=24"
|
||||
},
|
||||
"workspaces": [
|
||||
"server",
|
||||
"client"
|
||||
|
||||
@@ -1,42 +0,0 @@
|
||||
# ── Build stage ──────────────────────────────────────────────────────────────
|
||||
FROM node:22-slim AS builder
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
COPY package*.json ./
|
||||
COPY server/package.json ./server/
|
||||
RUN npm ci -w server
|
||||
|
||||
COPY server/nest-cli.json ./server/
|
||||
COPY server/tsconfig*.json ./server/
|
||||
COPY server/src ./server/src
|
||||
RUN npm run -w server build
|
||||
|
||||
# ── Runtime stage ─────────────────────────────────────────────────────────────
|
||||
FROM node:22-slim AS runtime
|
||||
|
||||
# Playwright / Chromium system dependencies
|
||||
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||
chromium \
|
||||
fonts-noto \
|
||||
ca-certificates \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# Tell Playwright to use the system Chromium instead of downloading its own
|
||||
ENV PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1
|
||||
ENV PLAYWRIGHT_CHROMIUM_EXECUTABLE_PATH=/usr/bin/chromium
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
COPY package*.json ./
|
||||
COPY server/package.json ./server/
|
||||
RUN npm ci --omit=dev -w server
|
||||
|
||||
COPY --from=builder /app/server/dist ./dist
|
||||
|
||||
# Runtime directories (keys and SQLite DB mounted via volumes)
|
||||
RUN mkdir -p data
|
||||
|
||||
EXPOSE 3000
|
||||
|
||||
CMD ["node", "dist/main"]
|
||||
+2
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "liqa-server",
|
||||
"version": "1.0.0",
|
||||
"private": true,
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"build": "nest build",
|
||||
@@ -25,6 +25,7 @@
|
||||
"@nestjs/core": "^11.1.18",
|
||||
"@nestjs/platform-express": "^11.1.18",
|
||||
"@nestjs/schedule": "^6.1.1",
|
||||
"@nestjs/serve-static": "^5.0.5",
|
||||
"@nestjs/swagger": "^11.2.6",
|
||||
"@nestjs/typeorm": "^11.0.1",
|
||||
"@playwright/test": "^1.59.1",
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
import { Module } from "@nestjs/common";
|
||||
import { ConfigModule, ConfigService } from "@nestjs/config";
|
||||
import { ScheduleModule } from "@nestjs/schedule";
|
||||
import { ServeStaticModule } from "@nestjs/serve-static";
|
||||
import { TypeOrmModule } from "@nestjs/typeorm";
|
||||
import { BrowserModule } from "./browser/browser.module";
|
||||
import { clientStaticOptions } from "./common/client-static";
|
||||
import { AppConfig, validateAppConfig } from "./config/app.config";
|
||||
import { CredentialEntity } from "./credential/credential.entity";
|
||||
import { CredentialModule } from "./credential/credential.module";
|
||||
@@ -36,6 +38,11 @@ import { SnippetModule } from "./snippet/snippet.module";
|
||||
validate: validateAppConfig,
|
||||
}),
|
||||
ScheduleModule.forRoot(),
|
||||
ServeStaticModule.forRootAsync({
|
||||
inject: [ConfigService],
|
||||
useFactory: (config: ConfigService<AppConfig, true>) =>
|
||||
clientStaticOptions(config.get("CLIENT_DIR")),
|
||||
}),
|
||||
TypeOrmModule.forRootAsync({
|
||||
inject: [ConfigService],
|
||||
useFactory: (config: ConfigService<AppConfig, true>) => ({
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
import * as fs from "node:fs";
|
||||
import * as path from "node:path";
|
||||
|
||||
export interface AppPackage {
|
||||
name: string;
|
||||
version: string;
|
||||
}
|
||||
|
||||
let cached: AppPackage | undefined;
|
||||
|
||||
/**
|
||||
* Name and version of the application, read from the workspace root
|
||||
* `package.json` (the one declaring `workspaces`) - the single source of the
|
||||
* app version. Found by walking up from this file, which covers both the repo
|
||||
* (`server/src/common` → repo root) and the Docker image
|
||||
* (`/app/dist/common` → `/app/package.json`).
|
||||
*/
|
||||
export function appPackage(): AppPackage {
|
||||
if (cached) return cached;
|
||||
let dir = __dirname;
|
||||
for (;;) {
|
||||
const file = path.join(dir, "package.json");
|
||||
if (fs.existsSync(file)) {
|
||||
const pkg = JSON.parse(fs.readFileSync(file, "utf8")) as Partial<
|
||||
AppPackage & { workspaces: unknown }
|
||||
>;
|
||||
if (pkg.workspaces && pkg.name && pkg.version) {
|
||||
cached = { name: pkg.name, version: pkg.version };
|
||||
return cached;
|
||||
}
|
||||
}
|
||||
const parent = path.dirname(dir);
|
||||
if (parent === dir) {
|
||||
throw new Error(
|
||||
`Workspace root package.json (with "workspaces", "name" and "version") not found above ${__dirname}`,
|
||||
);
|
||||
}
|
||||
dir = parent;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
import type { ServeStaticModuleOptions } from "@nestjs/serve-static";
|
||||
import type { ServerResponse } from "node:http";
|
||||
import * as path from "node:path";
|
||||
|
||||
/** Server routes that must never fall back to the client's index.html. */
|
||||
const SERVER_ROUTES = [
|
||||
"/api/{*path}",
|
||||
"/mcp{*path}",
|
||||
"/docs{*path}",
|
||||
"/health",
|
||||
"/healthz",
|
||||
];
|
||||
|
||||
/**
|
||||
* Serves the built client (SPA) from `clientDir`: static files as they are,
|
||||
* any other GET outside the server routes gets index.html so client-side
|
||||
* routes survive a page refresh. Returns no options (nothing served) when
|
||||
* `clientDir` is empty, e.g. in tests and local development.
|
||||
*/
|
||||
export function clientStaticOptions(
|
||||
clientDir: string,
|
||||
): ServeStaticModuleOptions[] {
|
||||
if (!clientDir) return [];
|
||||
return [
|
||||
{
|
||||
rootPath: path.resolve(clientDir),
|
||||
exclude: SERVER_ROUTES,
|
||||
serveStaticOptions: {
|
||||
setHeaders: (res: ServerResponse, filePath: string) => {
|
||||
// Vite emits content-hashed files under assets/; index.html must
|
||||
// always be revalidated so a new deploy is picked up immediately
|
||||
const cacheControl = filePath.includes(`${path.sep}assets${path.sep}`)
|
||||
? "public, max-age=31536000, immutable"
|
||||
: "no-cache";
|
||||
res.setHeader("Cache-Control", cacheControl);
|
||||
},
|
||||
},
|
||||
},
|
||||
];
|
||||
}
|
||||
@@ -8,7 +8,7 @@ import {
|
||||
validateSync,
|
||||
} from "class-validator";
|
||||
|
||||
import pkg from "../../package.json";
|
||||
import { appPackage } from "../common/app-package";
|
||||
|
||||
export enum TraceMode {
|
||||
On = "on",
|
||||
@@ -26,10 +26,10 @@ export class AppConfig {
|
||||
PORT: number = 3000;
|
||||
|
||||
@IsString()
|
||||
APP_NAME: string = pkg.name;
|
||||
APP_NAME: string = appPackage().name;
|
||||
|
||||
@IsString()
|
||||
APP_VERSION: string = pkg.version;
|
||||
APP_VERSION: string = appPackage().version;
|
||||
|
||||
@IsString()
|
||||
KEYS_DIR: string = "keys";
|
||||
@@ -55,6 +55,10 @@ export class AppConfig {
|
||||
@IsString()
|
||||
FILE_CLEANUP_CRON: string = "0 3 * * *";
|
||||
|
||||
/** Directory with the built client to serve at `/`; empty to not serve it. */
|
||||
@IsString()
|
||||
CLIENT_DIR: string = "";
|
||||
|
||||
@IsEnum(TraceMode)
|
||||
// Off by default: traces with screenshots and snapshots easily reach ~10 MB per run
|
||||
PLAYWRIGHT_TRACE_MODE: TraceMode = TraceMode.Off;
|
||||
|
||||
+2
-1
@@ -3,8 +3,8 @@ import { ConfigService } from "@nestjs/config";
|
||||
import { NestFactory } from "@nestjs/core";
|
||||
import type { NestExpressApplication } from "@nestjs/platform-express";
|
||||
import { DocumentBuilder, SwaggerModule } from "@nestjs/swagger";
|
||||
import { name as pkgName, version as pkgVersion } from "../package.json";
|
||||
import { AppModule } from "./app.module";
|
||||
import { appPackage } from "./common/app-package";
|
||||
import { configureBodyParsers } from "./common/body-parsers";
|
||||
import { TraceLogger } from "./common/trace-logger";
|
||||
import { AppConfig } from "./config/app.config";
|
||||
@@ -28,6 +28,7 @@ process.on("unhandledRejection", (reason) => {
|
||||
});
|
||||
|
||||
async function bootstrap() {
|
||||
const { name: pkgName, version: pkgVersion } = appPackage();
|
||||
const API_PREFIX = "api/v1";
|
||||
const logger = new TraceLogger("Bootstrap");
|
||||
const app = await NestFactory.create<NestExpressApplication>(AppModule, {
|
||||
|
||||
@@ -16,7 +16,7 @@ import { E2eExportService } from "../scenario/e2e-export.service";
|
||||
import { SnippetService } from "../snippet/snippet.service";
|
||||
import { ImportService } from "../import/import.service";
|
||||
|
||||
import pkg from "../../package.json";
|
||||
import { appPackage } from "../common/app-package";
|
||||
|
||||
@Injectable()
|
||||
export class McpService {
|
||||
@@ -34,7 +34,8 @@ export class McpService {
|
||||
) {}
|
||||
|
||||
private createServer(): McpServer {
|
||||
const server = new McpServer({ name: pkg.name, version: pkg.version });
|
||||
const { name, version } = appPackage();
|
||||
const server = new McpServer({ name, version });
|
||||
this.registerTools(server);
|
||||
return server;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
import * as fs from "node:fs";
|
||||
import * as path from "node:path";
|
||||
import { appPackage } from "../src/common/app-package";
|
||||
import { validateAppConfig } from "../src/config/app.config";
|
||||
|
||||
describe("appPackage", () => {
|
||||
const root = JSON.parse(
|
||||
fs.readFileSync(path.resolve(__dirname, "../../package.json"), "utf8"),
|
||||
) as { name: string; version: string; workspaces: string[] };
|
||||
|
||||
it("reads name and version from the workspace root package.json", () => {
|
||||
expect(root.workspaces).toContain("server");
|
||||
expect(appPackage()).toEqual({ name: root.name, version: root.version });
|
||||
});
|
||||
|
||||
it("feeds APP_NAME and APP_VERSION", () => {
|
||||
const config = validateAppConfig({});
|
||||
expect(config.APP_NAME).toBe(root.name);
|
||||
expect(config.APP_VERSION).toBe(root.version);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,141 @@
|
||||
/**
|
||||
* Tests serving the built client alongside the server routes: static files,
|
||||
* the index.html fallback for client-side routes, and that server routes are
|
||||
* never answered with index.html.
|
||||
*/
|
||||
|
||||
import {
|
||||
Controller,
|
||||
Get,
|
||||
INestApplication,
|
||||
Module,
|
||||
Post,
|
||||
RequestMethod,
|
||||
} from "@nestjs/common";
|
||||
import { ServeStaticModule } from "@nestjs/serve-static";
|
||||
import { NestFactory } from "@nestjs/core";
|
||||
import * as fs from "node:fs";
|
||||
import * as os from "node:os";
|
||||
import * as path from "node:path";
|
||||
import request from "supertest";
|
||||
import { clientStaticOptions } from "../src/common/client-static";
|
||||
|
||||
@Controller("things")
|
||||
class ThingsController {
|
||||
@Get()
|
||||
list() {
|
||||
return [{ id: 1 }];
|
||||
}
|
||||
}
|
||||
|
||||
@Controller()
|
||||
class RootRoutesController {
|
||||
@Get("health")
|
||||
health() {
|
||||
return { status: "ok" };
|
||||
}
|
||||
|
||||
@Post("mcp")
|
||||
mcp() {
|
||||
return { jsonrpc: "2.0" };
|
||||
}
|
||||
}
|
||||
|
||||
async function buildApp(clientDir: string): Promise<INestApplication> {
|
||||
// NestFactory (as in main.ts) rather than Test.createTestingModule: the
|
||||
// serve-static module picks its HTTP loader while the module compiles,
|
||||
// which needs the HTTP adapter to exist already.
|
||||
@Module({
|
||||
imports: [ServeStaticModule.forRoot(...clientStaticOptions(clientDir))],
|
||||
controllers: [ThingsController, RootRoutesController],
|
||||
})
|
||||
class ClientStaticTestModule {}
|
||||
|
||||
const app = await NestFactory.create(ClientStaticTestModule, {
|
||||
logger: false,
|
||||
});
|
||||
// Same prefix setup as main.ts
|
||||
app.setGlobalPrefix("api/v1", {
|
||||
exclude: [
|
||||
{ path: "health", method: RequestMethod.ALL },
|
||||
{ path: "mcp", method: RequestMethod.ALL },
|
||||
],
|
||||
});
|
||||
await app.init();
|
||||
return app;
|
||||
}
|
||||
|
||||
describe("Client static serving", () => {
|
||||
let clientDir: string;
|
||||
let app: INestApplication;
|
||||
|
||||
beforeAll(async () => {
|
||||
clientDir = fs.mkdtempSync(path.join(os.tmpdir(), "liqa-client-"));
|
||||
fs.mkdirSync(path.join(clientDir, "assets"));
|
||||
fs.writeFileSync(path.join(clientDir, "index.html"), "<html>liqa</html>");
|
||||
fs.writeFileSync(
|
||||
path.join(clientDir, "assets", "app-abc123.js"),
|
||||
"console.log(1);",
|
||||
);
|
||||
app = await buildApp(clientDir);
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
await app.close();
|
||||
fs.rmSync(clientDir, { recursive: true, force: true });
|
||||
});
|
||||
|
||||
it("serves index.html at / without caching", async () => {
|
||||
const res = await request(app.getHttpServer()).get("/").expect(200);
|
||||
expect(res.text).toBe("<html>liqa</html>");
|
||||
expect(res.headers["cache-control"]).toBe("no-cache");
|
||||
});
|
||||
|
||||
it("serves index.html for client-side routes", async () => {
|
||||
const res = await request(app.getHttpServer())
|
||||
.get("/scenarios/123/runs/456")
|
||||
.expect(200);
|
||||
expect(res.text).toBe("<html>liqa</html>");
|
||||
expect(res.headers["cache-control"]).toBe("no-cache");
|
||||
});
|
||||
|
||||
it("serves hashed assets as immutable", async () => {
|
||||
const res = await request(app.getHttpServer())
|
||||
.get("/assets/app-abc123.js")
|
||||
.expect(200);
|
||||
expect(res.text).toBe("console.log(1);");
|
||||
expect(res.headers["cache-control"]).toContain("immutable");
|
||||
});
|
||||
|
||||
it("leaves API routes to the server", async () => {
|
||||
const res = await request(app.getHttpServer())
|
||||
.get("/api/v1/things")
|
||||
.expect(200);
|
||||
expect(res.body).toEqual([{ id: 1 }]);
|
||||
});
|
||||
|
||||
it("returns the server's 404 for unknown API routes, not index.html", async () => {
|
||||
const res = await request(app.getHttpServer())
|
||||
.get("/api/v1/nope")
|
||||
.expect(404);
|
||||
expect(res.text).not.toContain("liqa</html>");
|
||||
});
|
||||
|
||||
it("leaves /health and /mcp to the server", async () => {
|
||||
await request(app.getHttpServer())
|
||||
.get("/health")
|
||||
.expect(200, { status: "ok" });
|
||||
await request(app.getHttpServer())
|
||||
.post("/mcp")
|
||||
.expect(201, { jsonrpc: "2.0" });
|
||||
const res = await request(app.getHttpServer()).get("/mcp");
|
||||
expect(res.text).not.toContain("liqa</html>");
|
||||
});
|
||||
|
||||
it("serves nothing when no client directory is configured", async () => {
|
||||
const bare = await buildApp("");
|
||||
await request(bare.getHttpServer()).get("/").expect(404);
|
||||
await request(bare.getHttpServer()).get("/api/v1/things").expect(200);
|
||||
await bare.close();
|
||||
});
|
||||
});
|
||||
@@ -58,7 +58,7 @@ describe("Exec Context File Methods Integration Tests", () => {
|
||||
|
||||
// Start a test HTTP server for downloadFile tests
|
||||
testServer = await createTestServer();
|
||||
testServerUrl = `http://localhost:${(testServer.address() as AddressInfo).port}`;
|
||||
testServerUrl = `http://127.0.0.1:${(testServer.address() as AddressInfo).port}`;
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
@@ -94,7 +94,9 @@ describe("Exec Context File Methods Integration Tests", () => {
|
||||
}
|
||||
});
|
||||
|
||||
server.listen(0, "localhost", () => {
|
||||
// Explicit IPv4: "localhost" may bind ::1, which is unreachable in some
|
||||
// containers (e.g. Docker without IPv6)
|
||||
server.listen(0, "127.0.0.1", () => {
|
||||
resolve(server);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -51,7 +51,7 @@ describe("McpController", () => {
|
||||
|
||||
// Start a test HTTP server for downloadFile tests
|
||||
testServer = await createTestServer();
|
||||
testServerUrl = `http://localhost:${(testServer.address() as AddressInfo).port}`;
|
||||
testServerUrl = `http://127.0.0.1:${(testServer.address() as AddressInfo).port}`;
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
@@ -78,7 +78,9 @@ describe("McpController", () => {
|
||||
}
|
||||
});
|
||||
|
||||
server.listen(0, "localhost", () => {
|
||||
// Explicit IPv4: "localhost" may bind ::1, which is unreachable in some
|
||||
// containers (e.g. Docker without IPv6)
|
||||
server.listen(0, "127.0.0.1", () => {
|
||||
resolve(server);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -550,22 +550,27 @@ describe("ScenarioController", () => {
|
||||
it("filters by status", async () => {
|
||||
const sc = await createScenario();
|
||||
await createStep(sc.id, { order: 0 });
|
||||
await createRun(sc.id);
|
||||
const run = await createRun(sc.id);
|
||||
// Put the run in a final state directly: a pending run would be picked
|
||||
// up by the scheduler (@Interval) and could change status mid-test
|
||||
await app
|
||||
.get(DataSource)
|
||||
.query(`UPDATE scenario_runs SET status = 'fail' WHERE id = ?`, [
|
||||
run.id,
|
||||
]);
|
||||
|
||||
const pendingRes = await request(app.getHttpServer())
|
||||
.get(`/scenarios/${sc.id}/runs?status=pending`)
|
||||
const failRes = await request(app.getHttpServer())
|
||||
.get(`/scenarios/${sc.id}/runs?status=fail`)
|
||||
.expect(200);
|
||||
expect(failRes.body.total).toBe(1);
|
||||
expect(failRes.body.data[0].id).toBe(run.id);
|
||||
|
||||
expect(pendingRes.body.total).toBeGreaterThanOrEqual(1);
|
||||
pendingRes.body.data.forEach((r: { status: string }) =>
|
||||
expect(r.status).toBe("pending"),
|
||||
);
|
||||
|
||||
const passRes = await request(app.getHttpServer())
|
||||
.get(`/scenarios/${sc.id}/runs?status=pass`)
|
||||
.expect(200);
|
||||
|
||||
expect(passRes.body.total).toBe(0);
|
||||
for (const status of ["pending", "pass"]) {
|
||||
const res = await request(app.getHttpServer())
|
||||
.get(`/scenarios/${sc.id}/runs?status=${status}`)
|
||||
.expect(200);
|
||||
expect(res.body.total).toBe(0);
|
||||
}
|
||||
});
|
||||
|
||||
it("returns 400 for invalid status filter", async () => {
|
||||
|
||||
Reference in new issue
Block a user