diff --git a/.env.example b/.env.example index 226c447..cd5d119 100644 --- a/.env.example +++ b/.env.example @@ -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 diff --git a/CLAUDE.md b/CLAUDE.md index feea5d9..72e4131 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -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 diff --git a/client/.storybook/stories/LogOutput.stories.tsx b/client/.storybook/stories/LogOutput.stories.tsx index dbe88de..41b1540 100644 --- a/client/.storybook/stories/LogOutput.stories.tsx +++ b/client/.storybook/stories/LogOutput.stories.tsx @@ -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 = { 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 ( +
+ + +
+ ); +} + +/** Data blocks over the default limits (256 bytes, 5 lines) start collapsed. */ +export const LargeData: Story = { + render: () => , + 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: [], diff --git a/client/src/App.tsx b/client/src/App.tsx index 0cb1543..7af36dd 100644 --- a/client/src/App.tsx +++ b/client/src/App.tsx @@ -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 (
@@ -141,7 +143,16 @@ export default function App() {
- v{__APP_VERSION__} ·{' '} + + v{version} + {' '} + ·{' '} ; + const limits: Partial = 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 | 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 { + 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; +} diff --git a/client/src/pages/run/RunDetailPage.tsx b/client/src/pages/run/RunDetailPage.tsx index aec105c..7ba1998 100644 --- a/client/src/pages/run/RunDetailPage.tsx +++ b/client/src/pages/run/RunDetailPage.tsx @@ -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(null); const [run, setRun] = useState(null); @@ -102,6 +107,7 @@ function RunDetail() { const [pendingDeleteFile, setPendingDeleteFile] = useState(null); const [deletingFile, setDeletingFile] = useState(false); const [repeating, setRepeating] = useState(false); + const [logDataExpanded, setLogDataExpanded] = useState(false); const logSearchRef = useRef(''); const pollRef = useRef | 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 && (
-

{t('runs.logs_heading')}

+
+

+ {t('runs.logs_heading')} +

+ {logsHaveLargeData && ( + + )} +
{t('runs.action_download_logs')} +
({ - 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="" />
diff --git a/client/src/ui/LogOutput/LogOutput.module.css b/client/src/ui/LogOutput/LogOutput.module.css index 33bae68..b7beb37 100644 --- a/client/src/ui/LogOutput/LogOutput.module.css +++ b/client/src/ui/LogOutput/LogOutput.module.css @@ -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; +} diff --git a/client/src/ui/LogOutput/LogOutput.tsx b/client/src/ui/LogOutput/LogOutput.tsx index 86bc78f..349bcef 100644 --- a/client/src/ui/LogOutput/LogOutput.tsx +++ b/client/src/ui/LogOutput/LogOutput.tsx @@ -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,25 +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; } -/** - * "+12s" (or "-" if before startTime, e.g. clock skew). Log timestamps are - * stored with second resolution, so fractions would be noise. - */ -function formatElapsed(deltaMs: number): string { - const sign = deltaMs < 0 ? '-' : '+'; - return `${sign}${Math.round(Math.abs(deltaMs) / 1000)}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({ @@ -49,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>(() => 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
{emptyMessage}
; } @@ -65,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 (
@@ -75,9 +119,24 @@ export function LogOutput({ {entry.context && {entry.context}} {entry.message}
- {entry.data && ( + {block && large && ( + + )} + {block && open && (
- +
)}
diff --git a/client/src/ui/LogOutput/logText.ts b/client/src/ui/LogOutput/logText.ts new file mode 100644 index 0000000..7fd3c35 --- /dev/null +++ b/client/src/ui/LogOutput/logText.ts @@ -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[], + 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'); +} diff --git a/client/src/ui/index.ts b/client/src/ui/index.ts index 7e98da9..3d2e9d1 100644 --- a/client/src/ui/index.ts +++ b/client/src/ui/index.ts @@ -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'; diff --git a/docs/architecture.md b/docs/architecture.md index de6ac32..beed6d3 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -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. diff --git a/docs/development.md b/docs/development.md index a59809a..82ba9f6 100644 --- a/docs/development.md +++ b/docs/development.md @@ -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`. | @@ -271,7 +273,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 +348,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 `` 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. diff --git a/docs/scenario.md b/docs/scenario.md index 09eef8a..94b2a61 100644 --- a/docs/scenario.md +++ b/docs/scenario.md @@ -60,6 +60,8 @@ Each run log entry (`level`, `message`, `createdAt`) also carries a `context`: w `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 diff --git a/server/src/app.module.ts b/server/src/app.module.ts index 1468ebe..e3108d6 100644 --- a/server/src/app.module.ts +++ b/server/src/app.module.ts @@ -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 {} diff --git a/server/src/common/client-static.ts b/server/src/common/client-static.ts index 449258e..b1dc605 100644 --- a/server/src/common/client-static.ts +++ b/server/src/common/client-static.ts @@ -9,6 +9,7 @@ const SERVER_ROUTES = [ "/docs{*path}", "/health", "/healthz", + "/manifest.json", ]; /** diff --git a/server/src/config/app.config.ts b/server/src/config/app.config.ts index cd25e37..7227944 100644 --- a/server/src/config/app.config.ts +++ b/server/src/config/app.config.ts @@ -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): AppConfig { diff --git a/server/src/main.ts b/server/src/main.ts index 9f6b28c..cc17762 100644 --- a/server/src/main.ts +++ b/server/src/main.ts @@ -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 }, ], }); diff --git a/server/src/manifest/manifest.controller.ts b/server/src/manifest/manifest.controller.ts new file mode 100644 index 0000000..6d5ff51 --- /dev/null +++ b/server/src/manifest/manifest.controller.ts @@ -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) {} + + @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"), + }, + }, + }; + } +} diff --git a/server/src/manifest/manifest.dto.ts b/server/src/manifest/manifest.dto.ts new file mode 100644 index 0000000..0894dab --- /dev/null +++ b/server/src/manifest/manifest.dto.ts @@ -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; +} diff --git a/server/src/manifest/manifest.module.ts b/server/src/manifest/manifest.module.ts new file mode 100644 index 0000000..6b875bb --- /dev/null +++ b/server/src/manifest/manifest.module.ts @@ -0,0 +1,7 @@ +import { Module } from "@nestjs/common"; +import { ManifestController } from "./manifest.controller"; + +@Module({ + controllers: [ManifestController], +}) +export class ManifestModule {} diff --git a/server/test/app.harness.ts b/server/test/app.harness.ts index 357c38b..27f4975 100644 --- a/server/test/app.harness.ts +++ b/server/test/app.harness.ts @@ -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 { ImportModule, McpModule, ], - controllers: [HealthController], + controllers: [HealthController, ManifestController], }).compile(); const app = module.createNestApplication(); diff --git a/server/test/client-static.spec.ts b/server/test/client-static.spec.ts index 6efcae1..be93b3d 100644 --- a/server/test/client-static.spec.ts +++ b/server/test/client-static.spec.ts @@ -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 { 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"); }); + 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); diff --git a/server/test/manifest.spec.ts b/server/test/manifest.spec.ts new file mode 100644 index 0000000..7526d45 --- /dev/null +++ b/server/test/manifest.spec.ts @@ -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 }); + }); +});