Compare commits

...
4 Commits
Author SHA1 Message Date
ars9 2129708819 feat(ui): color-code uuid badges and highlight them on hover
- show a circle colored by the first 6 hex digits of the uuid,
  bordered with the badge text color for contrast in both themes
- lighten the uuid badge background on hover
- let Badge accept a className
- add a storybook story with six sample uuids and a randomize button
- bump version to 1.21.0
2026-10-01 10:23:50 +03:00
ars9 6e9b99e415 fix(ui): meet wcag aa text contrast in both themes
- add --color-primary-text for lime used as text or icon color
- stop dimming the idle refresh label with opacity
- darken the light danger button and lighten the dark danger hover
- define syntax highlighting colors per theme as --hl-* tokens
- darken light muted text slightly
- add a storybook contrast page, fail storybook tests on a11y violations
  and show live token values in the colors story
- bump version to 1.20.2
2026-09-30 22:27:06 +03:00
ars9 8aadbd25fb chore(deps): update dependencies and bring storybook up to date
- update client and server dependencies within their ranges, keeping
  all playwright packages aligned at 1.63
- fix code flagged by react-hooks 7.1: refs written during render and
  synchronous setState in effects
- add stories for the ui components that had none, with interaction
  tests, and cover all DescriptionList layouts
- drop the unused mdx stories pattern
- run the storybook tests as part of the pre-commit checks
- bump version to 1.20.1
2026-09-30 22:05:21 +03:00
ars9 9f341719ef feat(database): manage the schema with typeorm migrations
- replace synchronize with migrations, starting with a generated initial
  migration that adopts databases created by synchronize
- apply pending migrations in the docker container before the server,
  and refuse to start the server while migrations are pending
- share one entity list and data source between app, migration runner,
  typeorm cli and tests; tests run the real migrations
- add migration:run, migration:show and migration:generate scripts and
  a test that fails when entities and migrations differ
- exit with code 1 when startup fails
- bump version to 1.20.0
2026-09-30 21:45:42 +03:00
44 changed files with 6088 additions and 3717 deletions

No files matched your search

+65
View File
@@ -2,6 +2,71 @@
All notable changes to this project will be documented in this file.
## 1.21.0 - 2026-10-01
Changes since 1.20.2:
### Added
- UUID badges show a small colored circle in front of the short id. Its color comes from the first 6 hex digits of the UUID, so the same id always gets the same color, and its border uses the badge text color to stay visible in both themes.
- UUID badges get lighter on hover to show they can be clicked.
- `Badge` accepts an optional `className`.
- A Storybook "Colors" story for UuidBadge with six sample ids and a button to randomize them.
## 1.20.2 - 2026-09-30
Changes since 1.20.1:
### Fixed
- Text contrast now meets WCAG AA (4.5:1) in both themes:
- the "Live" refresh label and the table sort icon use a new `--color-primary-text` token (dark lime in the light theme) instead of the light lime brand color;
- the idle refresh label is no longer dimmed with opacity;
- the light theme's danger button is a little darker, and the dark theme's danger hover is lighter so its dark text stays readable;
- syntax highlighting colors are defined per theme (`--hl-*` tokens), darker in the light theme;
- muted text is slightly darker in the light theme.
### Added
- A Storybook "Accessibility / Contrast" page that measures the contrast of the most contrast-prone components in both themes.
- Storybook accessibility checks now fail the tests on violations (`a11y.test: 'error'`). The Colors story shows each token's current value per theme and includes the syntax colors.
## 1.20.1 - 2026-09-30
Changes since 1.20.0:
### Added
- Storybook stories for AutoRefreshIndicator, CodeBlock, CodeEditor, MarkdownContent, Modal, Notification, Search, Textarea, Toast and UuidBadge, with interaction tests where the component has behavior. The DescriptionList story covers all four layouts.
### Changed
- Updated all client and server dependencies to the latest versions within their ranges, including React 19.3, Storybook 10.6, NestJS 11.2, TypeORM 0.3.31 and Playwright 1.63 (the Docker image now ships HeadlessChrome 153).
- The Storybook tests are part of the pre-commit checks.
### Fixed
- Code flagged by the stricter React hooks lint rules: the runs list no longer writes refs during render, and the scenario list, scenario files and sessions list no longer set state synchronously inside effects.
## 1.20.0 - 2026-09-30
Changes since 1.19.3:
### Added
- Database migrations: the SQLite schema is now managed by TypeORM migrations (`server/src/database/migrations/`) instead of `synchronize`. The Docker container applies pending migrations before starting the server, and the server refuses to start while migrations are pending.
- `npm -w server run migration:run`, `migration:show` and `migration:generate` scripts; the workflow for schema changes is described in `docs/development.md`.
- A test that fails when an entity changes without a matching migration.
### Changed
- Databases created before migrations (by `synchronize`) are adopted automatically: the initial migration is recorded as applied without changing them.
- Tests now build their database from the migrations instead of `synchronize`.
### Fixed
- Startup failures were logged but the process exited with code 0; they now exit with code 1.
## 1.19.3 - 2026-09-30
Changes since 1.19.2:
+4 -3
View File
@@ -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 (`synchronize: true`, so entity changes alter the schema on startup - there are no migrations). 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`.
- `client/` - React 19 + Vite SPA (i18n strings in `client/src/i18n/locales/en.json`).
## Docs
@@ -24,7 +24,7 @@ It is an npm workspace with two packages:
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.
The live database is `data/liqa.db`. The container applies pending migrations before starting the server, so back it up before deploying a release with new migrations.
## Code quality
@@ -34,10 +34,11 @@ Before committing, run and pass all of these (and report the results):
# server
cd server && npm run lint && npx tsc --noEmit -p tsconfig.json && npm test && npm run build
# client
cd client && npm run lint && npm run build
cd client && npm run lint && npm run build && npm run test:storybook
```
- Lint must stay clean in both packages (no errors, no warnings).
- `test:storybook` runs every story in `client/.storybook/stories/` in headless Chromium (needs `npx playwright install --only-shell chromium` once, and again after Playwright updates). Add or update a story when adding or changing a `client/src/ui/` component.
- Don't run prettier over whole existing files; several aren't prettier-clean and it produces unrelated diffs. Format only new files or the lines you changed.
- 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`, ...).
+3 -1
View File
@@ -87,4 +87,6 @@ RUN mkdir -p data
EXPOSE 3000
CMD ["node", "dist/main"]
# Apply pending database migrations, then start the server (which refuses to
# start while migrations are pending)
CMD ["sh", "-c", "node dist/database/migrate && exec node dist/main"]
+1 -1
View File
@@ -12,7 +12,7 @@ function getAbsolutePath(value: string) {
return dirname(fileURLToPath(import.meta.resolve(`${value}/package.json`)));
}
const config: StorybookConfig = {
stories: ['./stories/**/*.mdx', './stories/**/*.stories.@(js|jsx|mjs|ts|tsx)'],
stories: ['./stories/**/*.stories.@(js|jsx|mjs|ts|tsx)'],
addons: [
getAbsolutePath('@storybook/addon-vitest'),
getAbsolutePath('@storybook/addon-a11y'),
+2 -1
View File
@@ -37,7 +37,8 @@ const preview: Preview = {
},
},
a11y: {
test: 'todo',
// Accessibility violations (e.g. color contrast) fail the story's test
test: 'error',
},
},
};
@@ -0,0 +1,25 @@
import type { Meta, StoryObj } from '@storybook/react-vite';
import { expect, fn, userEvent, within } from 'storybook/test';
import { AutoRefreshIndicator } from '../../src/ui/AutoRefreshIndicator/AutoRefreshIndicator';
const meta: Meta<typeof AutoRefreshIndicator> = {
title: 'UI/AutoRefreshIndicator',
component: AutoRefreshIndicator,
parameters: { layout: 'centered' },
tags: ['autodocs'],
args: { onClick: fn() },
};
export default meta;
type Story = StoryObj<typeof AutoRefreshIndicator>;
export const Active: Story = { args: { active: true, pulseKey: 1 } };
export const Idle: Story = { args: { active: false } };
export const Errored: Story = { args: { active: false, error: true } };
export const ClickToRefresh: Story = {
args: { active: false },
play: async ({ args, canvasElement }) => {
await userEvent.click(within(canvasElement).getByRole('button'));
await expect(args.onClick).toHaveBeenCalled();
},
};
@@ -0,0 +1,33 @@
import type { Meta, StoryObj } from '@storybook/react-vite';
import { expect } from 'storybook/test';
import { CodeBlock } from '../../src/ui/CodeBlock/CodeBlock';
const meta: Meta<typeof CodeBlock> = {
title: 'UI/CodeBlock',
component: CodeBlock,
parameters: { layout: 'padded' },
tags: ['autodocs'],
};
export default meta;
type Story = StoryObj<typeof CodeBlock>;
export const JavaScript: Story = {
args: {
language: 'javascript',
code: "const url = context.getEnv('BASE_URL');\nawait context.page.goto(url);\nreturn await context.page.title();",
},
play: async ({ canvasElement }) => {
// Highlighting splits the code into many spans: check the whole text and
// that highlighting actually happened
const code = canvasElement.querySelector('code');
await expect(code).toHaveTextContent('await context.page.goto(url);');
await expect(code?.querySelector('.hljs-keyword')).not.toBeNull();
},
};
export const Json: Story = {
args: {
language: 'json',
code: JSON.stringify({ status: 'pass', output: { title: 'Dashboard' } }, null, 2),
},
};
@@ -0,0 +1,35 @@
import React, { useState } from 'react';
import type { Meta, StoryObj } from '@storybook/react-vite';
import { CodeEditor, type CodeEditorProps } from '../../src/ui/CodeEditor/CodeEditor';
// Monaco is loaded from a CDN at runtime, so these stories only check that the
// editor mounts; they have no interaction tests.
function ControlledEditor(
props: Omit<CodeEditorProps, 'value' | 'onChange'> & { initial: string },
) {
const { initial, ...rest } = props;
const [value, setValue] = useState(initial);
return <CodeEditor {...rest} value={value} onChange={setValue} />;
}
const meta: Meta<typeof ControlledEditor> = {
title: 'UI/CodeEditor',
component: ControlledEditor,
parameters: { layout: 'padded' },
tags: ['autodocs'],
};
export default meta;
type Story = StoryObj<typeof ControlledEditor>;
export const JavaScript: Story = {
args: {
language: 'javascript',
rows: 8,
initial:
"await context.page.goto(context.getEnv('BASE_URL'));\nreturn await context.page.title();",
},
};
export const WithError: Story = {
args: { language: 'javascript', rows: 4, error: true, initial: 'await context.page.goto(' },
};
+45 -4
View File
@@ -1,10 +1,16 @@
import React from 'react';
import React, { useLayoutEffect, useRef, useState } from 'react';
import type { Meta, StoryObj } from '@storybook/react-vite';
const palette = [
{ name: 'Atlantis', token: '--color-primary', hex: '#9DD341', role: 'Primary / Action' },
{
name: 'Atlantis text',
token: '--color-primary-text',
hex: '#496904',
role: 'Primary as text / icon',
},
{ name: 'Outer Space', token: '--color-text', hex: '#2D3339', role: 'Text / Surface' },
{ name: 'Kimberly', token: '--color-text-muted', hex: '#6650C0', role: 'Muted text / Info' },
{ name: 'Kimberly', token: '--color-text-muted', hex: '#634DBD', role: 'Muted text / Info' },
{ name: 'Powder Ash', token: '--color-border', hex: '#AFBFB9', role: 'Border / Neutral' },
];
@@ -23,12 +29,23 @@ const semanticColors = [
{ name: 'Running fg', token: '--color-running-fg', hex: '#6B4A00' },
];
const syntaxColors = [
{ name: 'Comment', token: '--hl-comment', hex: '#4F6557' },
{ name: 'Keyword', token: '--hl-keyword', hex: '#764E99' },
{ name: 'String / title', token: '--hl-string', hex: '#4F6821' },
{ name: 'Number', token: '--hl-number', hex: '#895403' },
{ name: 'Function', token: '--hl-function', hex: '#056980' },
{ name: 'Variable / params', token: '--hl-variable', hex: '#815354' },
{ name: 'Property', token: '--hl-property', hex: '#1D6971' },
{ name: 'Meta', token: '--hl-meta', hex: '#615B7E' },
];
const surfaceColors = [
{ name: 'Background', token: '--color-bg', hex: '#E6EDEA' },
{ name: 'Background subtle', token: '--color-bg-subtle', hex: '#D8E2DE' },
{ name: 'Secondary', token: '--color-secondary', hex: '#EDF1EF' },
{ name: 'Secondary hover', token: '--color-secondary-hover', hex: '#DFE6E3' },
{ name: 'Danger', token: '--color-danger', hex: '#D94F4F' },
{ name: 'Danger', token: '--color-danger', hex: '#CE4546' },
{ name: 'Primary fg', token: '--color-primary-fg', hex: '#2D3339' },
];
@@ -43,8 +60,27 @@ function Swatch({
hex: string;
role?: string;
}) {
// Show the token's current value (per theme) rather than a hard-coded copy
const ref = useRef<HTMLDivElement>(null);
const [value, setValue] = useState(hex);
useLayoutEffect(() => {
const read = () => {
if (!ref.current) return;
const resolved = getComputedStyle(ref.current).getPropertyValue(token).trim();
if (resolved) setValue(resolved.toUpperCase());
};
read();
// Re-read when the theme toolbar switches data-theme on <html>
const observer = new MutationObserver(read);
observer.observe(document.documentElement, {
attributes: true,
attributeFilter: ['data-theme'],
});
return () => observer.disconnect();
}, [token]);
return (
<div
ref={ref}
style={{
display: 'flex',
flexDirection: 'column',
@@ -72,7 +108,7 @@ function Swatch({
</div>
)}
<div style={{ fontSize: 11, fontFamily: 'monospace', color: 'var(--color-text-muted)' }}>
{hex}
{value}
</div>
<div style={{ fontSize: 11, fontFamily: 'monospace', color: 'var(--color-text-muted)' }}>
{token}
@@ -128,6 +164,11 @@ function ColorPalette() {
<Swatch key={c.token} {...c} />
))}
</Section>
<Section title="Syntax highlighting">
{syntaxColors.map((c) => (
<Swatch key={c.token} {...c} />
))}
</Section>
</div>
);
}
@@ -13,7 +13,7 @@ export default meta;
type Story = StoryObj<typeof ContextMenu>;
const trigger = (
<Button variant="ghost" size="sm">
<Button variant="ghost" size="sm" aria-label="Actions">
<Settings size={16} />
</Button>
);
@@ -0,0 +1,330 @@
import React, { useLayoutEffect, useRef, useState } from 'react';
import type { Meta, StoryObj } from '@storybook/react-vite';
import { AutoRefreshIndicator } from '../../src/ui/AutoRefreshIndicator/AutoRefreshIndicator';
import { Button } from '../../src/ui/Button/Button';
import { CodeBlock } from '../../src/ui/CodeBlock/CodeBlock';
/*
* Text contrast review page (WCAG AA: 4.5:1 for normal text, 3:1 for large
* text) for the components where contrast is easiest to get wrong: light
* brand colors used as text, dimmed labels, colored buttons and syntax
* highlighting. Every sample is the real component, shown in both themes, and
* the contrast of each piece of text is measured live from the rendered
* colors - so this page stays accurate as the design tokens change.
*/
// ── Contrast measurement ─────────────────────────────────────────────────────
type Rgba = [number, number, number, number];
function parseColor(value: string): Rgba {
const parts = value.match(/[\d.]+/g)?.map(Number) ?? [0, 0, 0];
return [parts[0], parts[1], parts[2], parts[3] ?? 1];
}
function luminance([r, g, b]: Rgba): number {
const channel = (c: number) => {
const s = c / 255;
return s <= 0.03928 ? s / 12.92 : ((s + 0.055) / 1.055) ** 2.4;
};
return 0.2126 * channel(r) + 0.7152 * channel(g) + 0.0722 * channel(b);
}
function contrast(a: Rgba, b: Rgba): number {
const [hi, lo] = [luminance(a), luminance(b)].sort((x, y) => y - x);
return (hi + 0.05) / (lo + 0.05);
}
/** Blends `top` over an opaque `bottom`. */
function blend(top: Rgba, bottom: Rgba): Rgba {
const a = top[3];
return [0, 1, 2].map((i) => top[i] * a + bottom[i] * (1 - a)).concat(1) as Rgba;
}
/** Product of the `opacity` of `el` and its ancestors (e.g. a dimmed idle label). */
function opacityChain(el: Element): number {
let opacity = 1;
for (let node: Element | null = el; node; node = node.parentElement) {
opacity *= parseFloat(getComputedStyle(node).opacity);
}
return opacity;
}
/** The opaque color behind `el`, from its own and its ancestors' backgrounds. */
function effectiveBackground(el: Element): Rgba {
const layers: Rgba[] = [];
for (let node: Element | null = el; node; node = node.parentElement) {
const bg = parseColor(getComputedStyle(node).backgroundColor);
bg[3] *= opacityChain(node);
if (bg[3] > 0) layers.push(bg);
if (bg[3] >= 1) break;
}
return layers.reduceRight<Rgba>((under, layer) => blend(layer, under), [255, 255, 255, 1]);
}
const hex = ([r, g, b]: Rgba) =>
'#' + [r, g, b].map((c) => Math.round(c).toString(16).padStart(2, '0')).join('');
interface Measurement {
text: string;
fg: string;
bg: string;
ratio: number;
required: number;
}
/** Measures every element that directly contains visible text. */
function measure(root: HTMLElement): Measurement[] {
const seen = new Set<string>();
const results: Measurement[] = [];
for (const el of Array.from(root.querySelectorAll<HTMLElement>('*'))) {
const text = Array.from(el.childNodes)
.filter((n) => n.nodeType === Node.TEXT_NODE)
.map((n) => n.textContent ?? '')
.join('')
.trim();
if (!text || el.closest('[aria-hidden="true"]')) continue;
const style = getComputedStyle(el);
const fontSize = parseFloat(style.fontSize);
const bold = Number(style.fontWeight) >= 700;
// WCAG "large text": at least 24px, or 18.66px bold
const required = fontSize >= 24 || (bold && fontSize >= 18.66) ? 3 : 4.5;
const bgColor = effectiveBackground(el);
const fg = parseColor(style.color);
fg[3] *= opacityChain(el);
const fgColor = blend(fg, bgColor);
const key = `${hex(fgColor)}|${hex(bgColor)}|${required}`;
if (seen.has(key)) continue;
seen.add(key);
results.push({
text: text.length > 28 ? `${text.slice(0, 28)}…` : text,
fg: hex(fgColor),
bg: hex(bgColor),
ratio: contrast(fgColor, bgColor),
required,
});
}
return results.sort((a, b) => a.ratio / a.required - b.ratio / b.required);
}
function Readout({ items }: { items: Measurement[] }) {
return (
<table style={{ width: '100%', borderCollapse: 'collapse', fontSize: 12, marginTop: 8 }}>
<tbody>
{items.map((m) => {
const pass = m.ratio >= m.required;
return (
<tr
key={`${m.fg}${m.bg}${m.required}`}
style={{ borderTop: '1px solid var(--color-border)' }}
>
<td style={{ padding: '4px 6px' }}>
<span
style={{
display: 'inline-block',
padding: '1px 6px',
borderRadius: 3,
background: m.bg,
color: m.fg,
fontFamily: 'monospace',
}}
>
{m.text}
</span>
</td>
<td
style={{
padding: '4px 6px',
fontFamily: 'monospace',
color: 'var(--color-text-muted)',
}}
>
{m.fg} on {m.bg}
</td>
<td
style={{
padding: '4px 6px',
textAlign: 'right',
fontWeight: 700,
whiteSpace: 'nowrap',
color: pass ? 'var(--color-text)' : 'var(--color-danger)',
}}
>
{m.ratio.toFixed(2)}:1 {pass ? '✓' : `✗ needs ${m.required}:1`}
</td>
</tr>
);
})}
</tbody>
</table>
);
}
/** Renders a sample and measures its text contrast after layout. */
function Sample({ children }: { children: React.ReactNode }) {
const ref = useRef<HTMLDivElement>(null);
const [items, setItems] = useState<Measurement[]>([]);
useLayoutEffect(() => {
const el = ref.current;
if (!el) return;
// Measure after the theme/styles have applied
const frame = requestAnimationFrame(() => setItems(measure(el)));
return () => cancelAnimationFrame(frame);
}, []);
return (
<div>
<div ref={ref}>{children}</div>
<Readout items={items} />
</div>
);
}
// ── Page ─────────────────────────────────────────────────────────────────────
// Covers every syntax color: comment, keyword, string, number, function
// (title), params, property
const JS_CODE = [
'// Open the app and wait for the dashboard',
'async function openDashboard(context, timeoutMs) {',
" const url = context.getEnv('BASE_URL');",
' await context.page.goto(url, { timeout: timeoutMs ?? 30000 });',
' return context.page.title();',
'}',
].join('\n');
const JSON_CODE = JSON.stringify(
{ status: 'pass', attempts: 2, cached: false, output: { title: 'Dashboard' } },
null,
2,
);
interface Issue {
title: string;
note: string;
render: () => React.ReactNode;
}
const ISSUES: Issue[] = [
{
title: 'AutoRefreshIndicator label',
note: 'Active ("Live", --color-primary-text), idle and error labels (runs pages).',
render: () => (
<div style={{ display: 'flex', gap: 12, flexWrap: 'wrap' }}>
<AutoRefreshIndicator active pulseKey={1} />
<AutoRefreshIndicator active={false} />
<AutoRefreshIndicator active={false} error />
</div>
),
},
{
title: 'Danger button',
note: 'Danger, primary and secondary buttons (text on colored backgrounds).',
render: () => (
<div style={{ display: 'flex', gap: 8, flexWrap: 'wrap' }}>
<Button variant="danger">Delete</Button>
<Button variant="danger" size="sm">
Delete
</Button>
<Button variant="primary">Run</Button>
<Button variant="secondary">Cancel</Button>
</div>
),
},
{
title: 'Code highlighting - JavaScript',
note: 'All --hl-* syntax colors on the page background (step code, snippets).',
render: () => <CodeBlock language="javascript" code={JS_CODE} />,
},
{
title: 'Code highlighting - JSON',
note: 'Keys, strings, numbers and literals in JSON step outputs.',
render: () => <CodeBlock language="json" code={JSON_CODE} />,
},
{
title: 'Muted text',
note: '--color-text-muted on both background shades (hints, table headers, descriptions).',
render: () => (
<div style={{ display: 'flex', gap: 8 }}>
{['var(--color-bg)', 'var(--color-bg-subtle)'].map((bg) => (
<span
key={bg}
style={{
background: bg,
color: 'var(--color-text-muted)',
padding: '4px 8px',
fontSize: 13,
}}
>
Last run 2 minutes ago
</span>
))}
</div>
),
},
];
function Panel({ theme }: { theme: 'light' | 'dark' }) {
return (
<section
// The dark tokens apply under [data-theme="dark"]; light is the page default
data-theme={theme === 'dark' ? 'dark' : undefined}
style={{
flex: '1 1 420px',
minWidth: 0,
padding: 16,
borderRadius: 8,
background: 'var(--color-bg)',
color: 'var(--color-text)',
border: '1px solid var(--color-border)',
}}
>
<h2 style={{ margin: '0 0 12px', fontSize: 16 }}>
{theme === 'dark' ? 'Dark theme' : 'Light theme'}
</h2>
{ISSUES.map((issue) => (
<div key={issue.title} style={{ marginBottom: 24 }}>
<h3 style={{ margin: '0 0 2px', fontSize: 14 }}>{issue.title}</h3>
<p style={{ margin: '0 0 8px', fontSize: 12, color: 'var(--color-text-muted)' }}>
{issue.note}
</p>
<Sample>{issue.render()}</Sample>
</div>
))}
</section>
);
}
function ContrastPage() {
return (
<div style={{ padding: 16 }}>
<p
style={{
margin: '0 0 16px',
fontSize: 13,
color: 'var(--color-text-muted)',
maxWidth: 820,
}}
>
Text contrast of the components where it's easiest to get wrong (WCAG AA: 4.5:1 for normal
text, 3:1 for large text). Each row is a piece of text in the sample, measured from its
rendered colors, worst first.
</p>
<div style={{ display: 'flex', gap: 16, flexWrap: 'wrap', alignItems: 'flex-start' }}>
<Panel theme="light" />
<Panel theme="dark" />
</div>
</div>
);
}
const meta: Meta<typeof ContrastPage> = {
title: 'Accessibility/Contrast',
component: ContrastPage,
// a11y checks use the project default ('error' in preview.tsx)
parameters: { layout: 'fullscreen' },
// The light panel relies on the page default (light) theme
globals: { theme: 'light' },
};
export default meta;
type Story = StoryObj<typeof ContrastPage>;
export const Overview: Story = {};
@@ -15,7 +15,7 @@ const meta: Meta<typeof DescriptionList> = {
),
],
argTypes: {
layout: { control: 'select', options: ['inline', 'compact'] },
layout: { control: 'select', options: ['inline', 'compact', 'comfortable', 'grid'] },
},
};
export default meta;
@@ -35,6 +35,14 @@ export const Compact: Story = {
args: { items: urlItems, layout: 'compact' },
};
export const Comfortable: Story = {
args: { items: urlItems, layout: 'comfortable' },
};
export const Grid: Story = {
args: { items: urlItems, layout: 'grid' },
};
export const WithLinks: Story = {
args: {
layout: 'inline',
@@ -0,0 +1,35 @@
import type { Meta, StoryObj } from '@storybook/react-vite';
import { expect, within } from 'storybook/test';
import { MarkdownContent } from '../../src/ui/MarkdownContent/MarkdownContent';
const meta: Meta<typeof MarkdownContent> = {
title: 'UI/MarkdownContent',
component: MarkdownContent,
parameters: { layout: 'padded' },
tags: ['autodocs'],
};
export default meta;
type Story = StoryObj<typeof MarkdownContent>;
export const Description: Story = {
args: {
content: [
'## Login flow',
'',
'Logs in with the **test user** and checks the dashboard.',
'',
'- Uses the `BASE_URL` environment value',
'- Needs the `user` credential alias',
'',
'```js',
"await context.page.goto(context.getEnv('BASE_URL'));",
'```',
].join('\n'),
},
play: async ({ canvasElement }) => {
const canvas = within(canvasElement);
await expect(canvas.getByRole('heading', { name: 'Login flow' })).toBeInTheDocument();
await expect(canvas.getByText('test user').tagName).toBe('STRONG');
await expect(canvas.getAllByRole('listitem')).toHaveLength(2);
},
};
@@ -0,0 +1,63 @@
import React, { useState } from 'react';
import type { Meta, StoryObj } from '@storybook/react-vite';
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 }) {
const [open, setOpen] = useState(false);
return (
<>
<Button onClick={() => setOpen(true)}>Open modal</Button>
<Modal
open={open}
title={title}
onClose={() => setOpen(false)}
footer={
<>
<Button variant="secondary" onClick={() => setOpen(false)}>
Cancel
</Button>
<Button onClick={() => setOpen(false)}>Confirm</Button>
</>
}
>
{body}
</Modal>
</>
);
}
const meta: Meta<typeof ModalDemo> = {
title: 'UI/Modal',
component: ModalDemo,
parameters: { layout: 'centered' },
tags: ['autodocs'],
args: { title: 'Delete scenario', body: 'This deletes the scenario, its versions and its runs.' },
};
export default meta;
type Story = StoryObj<typeof ModalDemo>;
export const Default: Story = {
play: async ({ canvasElement }) => {
const canvas = within(canvasElement);
await userEvent.click(canvas.getByRole('button', { name: 'Open modal' }));
const dialog = canvas.getByRole('dialog', { name: 'Delete scenario' });
await expect(dialog).toHaveTextContent('its versions and its runs');
await userEvent.click(within(dialog).getByRole('button', { name: 'Cancel' }));
await expect(canvas.queryByRole('dialog')).not.toBeInTheDocument();
},
};
export const ClosesOnEscapeAndBackdrop: Story = {
play: async ({ canvasElement }) => {
const canvas = within(canvasElement);
await userEvent.click(canvas.getByRole('button', { name: 'Open modal' }));
await userEvent.keyboard('{Escape}');
await expect(canvas.queryByRole('dialog')).not.toBeInTheDocument();
await userEvent.click(canvas.getByRole('button', { name: 'Open modal' }));
await userEvent.click(canvas.getByRole('presentation'));
await expect(canvas.queryByRole('dialog')).not.toBeInTheDocument();
},
};
@@ -0,0 +1,30 @@
import type { Meta, StoryObj } from '@storybook/react-vite';
import { Notification } from '../../src/ui/Notification/Notification';
const meta: Meta<typeof Notification> = {
title: 'UI/Notification',
component: Notification,
parameters: { layout: 'padded' },
tags: ['autodocs'],
argTypes: {
variant: { control: 'select', options: ['info', 'success', 'error', 'warning', 'note'] },
},
};
export default meta;
type Story = StoryObj<typeof Notification>;
export const Info: Story = {
args: {
variant: 'info',
title: 'Traces are off',
children: 'Enable them per run in the run modal.',
},
};
export const Success: Story = { args: { variant: 'success', children: 'Scenario imported.' } };
export const Error: Story = {
args: { variant: 'error', title: 'Run failed', children: 'Step 2 timed out after 60s.' },
};
export const Warning: Story = {
args: { variant: 'warning', children: 'The environment of this run no longer exists.' },
};
export const Note: Story = { args: { variant: 'note', children: 'Pinned snippet version: v3.' } };
@@ -0,0 +1,34 @@
import React, { useState } from 'react';
import type { Meta, StoryObj } from '@storybook/react-vite';
import { expect, userEvent, within } from 'storybook/test';
import { Search } from '../../src/ui/Search/Search';
function ControlledSearch({ placeholder }: { placeholder?: string }) {
const [value, setValue] = useState('');
return (
<div>
<Search value={value} onChange={setValue} placeholder={placeholder} />
<p data-testid="query">{value}</p>
</div>
);
}
const meta: Meta<typeof ControlledSearch> = {
title: 'UI/Search',
component: ControlledSearch,
parameters: { layout: 'centered' },
tags: ['autodocs'],
};
export default meta;
type Story = StoryObj<typeof ControlledSearch>;
export const Default: Story = {};
export const Typing: Story = {
args: { placeholder: 'Filter logs…' },
play: async ({ canvasElement }) => {
const canvas = within(canvasElement);
await userEvent.type(canvas.getByPlaceholderText('Filter logs…'), 'timeout');
await expect(canvas.getByTestId('query')).toHaveTextContent('timeout');
},
};
@@ -0,0 +1,37 @@
import type { Meta, StoryObj } from '@storybook/react-vite';
import { expect, within } from 'storybook/test';
import { Textarea } from '../../src/ui/Textarea/Textarea';
const meta: Meta<typeof Textarea> = {
title: 'UI/Textarea',
component: Textarea,
parameters: { layout: 'centered' },
tags: ['autodocs'],
decorators: [
(Story) => (
<div style={{ width: 360 }}>
<Story />
</div>
),
],
};
export default meta;
type Story = StoryObj<typeof Textarea>;
export const Default: Story = {
args: { label: 'Description', placeholder: 'Describe this scenario', rows: 4 },
};
export const WithHint: Story = {
args: { label: 'Description', hint: 'Markdown is supported.', rows: 4 },
};
export const WithError: Story = {
args: { label: 'Description', error: 'Description is too long.', rows: 4 },
play: async ({ canvasElement }) => {
const canvas = within(canvasElement);
const textarea = canvas.getByLabelText('Description');
await expect(textarea).toHaveAttribute('aria-invalid', 'true');
await expect(canvas.getByRole('alert')).toHaveTextContent('Description is too long.');
},
};
@@ -0,0 +1,41 @@
import React from 'react';
import type { Meta, StoryObj } from '@storybook/react-vite';
import { expect, userEvent, within } from 'storybook/test';
import { ToastProvider } from '../../src/ui/Toast/ToastProvider';
import { useToast } from '../../src/ui/Toast/useToast';
import { Button } from '../../src/ui/Button/Button';
function ToastButtons() {
const toast = useToast();
return (
<div style={{ display: 'flex', gap: 8 }}>
<Button onClick={() => toast.success('Scenario run started')}>Success</Button>
<Button variant="danger" onClick={() => toast.error('Environment not found')}>
Error
</Button>
<Button variant="secondary" onClick={() => toast.info('Traces are off')}>
Info
</Button>
</div>
);
}
const meta: Meta<typeof ToastProvider> = {
title: 'UI/Toast',
component: ToastProvider,
parameters: { layout: 'centered' },
tags: ['autodocs'],
args: { durationMs: 3500, children: <ToastButtons /> },
};
export default meta;
type Story = StoryObj<typeof ToastProvider>;
export const Default: Story = {};
export const ShowsToast: Story = {
play: async ({ canvasElement }) => {
const canvas = within(canvasElement);
await userEvent.click(canvas.getByRole('button', { name: 'Success' }));
await expect(await within(document.body).findByText('Scenario run started')).toBeVisible();
},
};
@@ -0,0 +1,63 @@
import type { Meta, StoryObj } from '@storybook/react-vite';
import { useState } from 'react';
import { expect, within } from 'storybook/test';
import { Button } from '../../src/ui/Button/Button';
import { UuidBadge } from '../../src/ui/UuidBadge/UuidBadge';
const meta: Meta<typeof UuidBadge> = {
title: 'UI/UuidBadge',
component: UuidBadge,
parameters: { layout: 'centered' },
tags: ['autodocs'],
};
export default meta;
type Story = StoryObj<typeof UuidBadge>;
export const Default: Story = {
args: { id: '61d2b1c2-7664-4dca-974f-436c2ee90b2e' },
play: async ({ canvasElement }) => {
// Shows a shortened id and keeps the full one in the tooltip
const badge = within(canvasElement).getByTitle('61d2b1c2-7664-4dca-974f-436c2ee90b2e');
await expect(badge).toHaveTextContent('61d2…0b2e');
},
};
const SAMPLE_IDS = [
'61d2b1c2-7664-4dca-974f-436c2ee90b2e',
'e83f0a5d-1b9c-4f27-8d6e-2a4c9b7f1e03',
'0c7a94f1-3e52-4b8d-a1f6-9d2e5c8b4a70',
'f4b21e8c-9a07-4c63-b5d2-7e1f0a3c6d98',
'8d5e3a10-c4f7-4e29-9b81-5f6a2d0c7e14',
'2a9fc067-58d3-4a1e-86b4-c3e7f19d5b2a',
];
function Gallery() {
const [ids, setIds] = useState(SAMPLE_IDS);
return (
<div style={{ display: 'flex', flexDirection: 'column', alignItems: 'flex-start', gap: 12 }}>
<div style={{ display: 'flex', flexWrap: 'wrap', gap: 16 }}>
{ids.map((id) => (
<UuidBadge key={id} id={id} />
))}
</div>
<Button
size="sm"
variant="secondary"
onClick={() => setIds(ids.map(() => crypto.randomUUID()))}
>
Randomize
</Button>
</div>
);
}
export const Colors: Story = {
render: () => <Gallery />,
play: async ({ canvasElement }) => {
// Each sample id gets its own badge
const canvas = within(canvasElement);
for (const id of SAMPLE_IDS) {
await expect(canvas.getByTitle(id)).toBeInTheDocument();
}
},
};
+6 -4
View File
@@ -68,10 +68,12 @@ export function RunsPage() {
const sortDirRef = useRef(sortDir);
const pageRef = useRef(page);
const pageSizeRef = useRef(pageSize);
sortByRef.current = sortBy;
sortDirRef.current = sortDir;
pageRef.current = page;
pageSizeRef.current = pageSize;
useEffect(() => {
sortByRef.current = sortBy;
sortDirRef.current = sortDir;
pageRef.current = page;
pageSizeRef.current = pageSize;
}, [sortBy, sortDir, page, pageSize]);
const load = useCallback(
(orderBy: string, orderDir: SortDirection, p: number, limit: number) => {
@@ -98,7 +98,7 @@ export function ScenarioDetailPage() {
// Files state
const [files, setFiles] = useState<FileMetadata[]>([]);
const [filesLoading, setFilesLoading] = useState(false);
const [filesLoading, setFilesLoading] = useState(true);
const [uploadOpen, setUploadOpen] = useState(false);
const [uploadFile, setUploadFile] = useState<File | null>(null);
const [uploadExpiresAt, setUploadExpiresAt] = useState('');
@@ -106,9 +106,10 @@ export function ScenarioDetailPage() {
const [usedSnippets, setUsedSnippets] = useState<UsedSnippet[]>([]);
const loadFiles = useCallback(async () => {
// Fetches the files; `filesLoading` starts as true for the fetch from the
// load effect, and `loadFiles` sets it for reloads (e.g. after an upload)
const fetchFiles = useCallback(async () => {
if (!id) return;
setFilesLoading(true);
try {
const result = await scenarioFiles.list(id);
setFiles(result.items);
@@ -117,6 +118,11 @@ export function ScenarioDetailPage() {
}
}, [id]);
const loadFiles = async () => {
setFilesLoading(true);
await fetchFiles();
};
useEffect(() => {
if (!id) return;
void scenarios
@@ -126,7 +132,7 @@ export function ScenarioDetailPage() {
setScenarioCreds(s.scenarioCredentials ?? []);
})
.finally(() => setLoading(false));
void loadFiles();
void fetchFiles();
scenarios
.usedSnippets(id)
.then(setUsedSnippets)
@@ -141,7 +147,7 @@ export function ScenarioDetailPage() {
setEnvs(r.data);
})
.catch(() => {});
}, [id, loadFiles]);
}, [id, fetchFiles]);
const openRunModal = () => {
// Preselect the scenario's default environment (or the first one) when the
+10 -4
View File
@@ -68,9 +68,10 @@ export function ScenariosPage() {
const [pageSize, setPageSize] = useState(10);
const [total, setTotal] = useState(0);
const load = useCallback(
// Fetches a page; `loading` starts as true for the initial fetch from the
// effect, and `load` sets it for later ones (no setState inside the effect)
const fetchPage = useCallback(
(orderBy: string, orderDir: SortDirection, p: number, limit: number) => {
setLoading(true);
Promise.all([
scenarios.list(p, limit, orderBy, orderDir === 'asc' ? 'ASC' : 'DESC'),
environments.list(1, 200),
@@ -88,9 +89,14 @@ export function ScenariosPage() {
[toast],
);
const load = (orderBy: string, orderDir: SortDirection, p: number, limit: number) => {
setLoading(true);
fetchPage(orderBy, orderDir, p, limit);
};
useEffect(() => {
load('updatedAt', 'desc', 1, 10);
}, [load]);
fetchPage('updatedAt', 'desc', 1, 10);
}, [fetchPage]);
const handleSort = (key: string, dir: SortDirection) => {
setSortBy(key);
+8 -3
View File
@@ -23,7 +23,9 @@ export function SessionsPage() {
usePageTitle(t('sessions.title'));
const navigate = useNavigate();
const [items, setItems] = useState<Session[]>([]);
const [loading, setLoading] = useState(true);
// Loading until the current query's result has arrived (derived, so the
// loading effect doesn't have to set state synchronously)
const [loadedQuery, setLoadedQuery] = useState<string | null>(null);
const [deleteId, setDeleteId] = useState<string | null>(null);
const [deleting, setDeleting] = useState(false);
const [sortBy, setSortBy] = useState('id');
@@ -32,15 +34,18 @@ export function SessionsPage() {
const [pageSize, setPageSize] = useState(10);
const [total, setTotal] = useState(0);
const query = `${sortBy}|${sortDir}|${page}|${pageSize}`;
const loading = loadedQuery !== query;
const load = useCallback((orderBy: string, orderDir: SortDirection, p: number, limit: number) => {
setLoading(true);
const key = `${orderBy}|${orderDir}|${p}|${limit}`;
sessions
.list(p, limit, orderBy, orderDir === 'asc' ? 'ASC' : 'DESC')
.then((res) => {
setItems(res.data);
setTotal(res.total);
})
.finally(() => setLoading(false));
.finally(() => setLoadedQuery(key));
}, []);
useEffect(() => {
@@ -71,7 +71,7 @@
}
.active .label {
color: var(--color-primary);
color: var(--color-primary-text);
font-weight: 600;
}
@@ -83,8 +83,8 @@
}
.inactive .label {
/* Not dimmed with opacity: muted text already reads as inactive and keeps 4.5:1 */
color: var(--color-text-muted);
opacity: 0.5;
}
/* ── Error state ──────────────────────────────────────────── */
+3 -2
View File
@@ -6,12 +6,13 @@ export type BadgeVariant = 'success' | 'error' | 'warning' | 'info' | 'neutral'
export interface BadgeProps {
variant?: BadgeVariant;
dot?: boolean;
className?: string;
children: React.ReactNode;
}
export function Badge({ variant = 'neutral', dot = false, children }: BadgeProps) {
export function Badge({ variant = 'neutral', dot = false, className, children }: BadgeProps) {
return (
<span className={[styles.badge, styles[variant]].join(' ')}>
<span className={[styles.badge, styles[variant], className].filter(Boolean).join(' ')}>
{dot && <span className={styles.dot} aria-hidden="true" />}
{children}
</span>
+8 -8
View File
@@ -18,7 +18,7 @@
.code :global(.hljs-comment),
.code :global(.hljs-quote) {
color: var(--hl-comment, #6A8072);
color: var(--hl-comment);
font-style: italic;
}
@@ -27,7 +27,7 @@
.code :global(.hljs-built_in),
.code :global(.hljs-name),
.code :global(.hljs-tag) {
color: var(--hl-keyword, #A67DCC);
color: var(--hl-keyword);
}
.code :global(.hljs-string),
@@ -39,32 +39,32 @@
.code :global(.hljs-template-variable),
.code :global(.hljs-type),
.code :global(.hljs-addition) {
color: var(--hl-string, #9BB870);
color: var(--hl-string);
}
.code :global(.hljs-number),
.code :global(.hljs-regexp),
.code :global(.hljs-link) {
color: var(--hl-number, #E8A85F);
color: var(--hl-number);
}
.code :global(.hljs-function),
.code :global(.hljs-title.hljs-function_) {
color: var(--hl-function, #5BB8D4);
color: var(--hl-function);
}
.code :global(.hljs-variable),
.code :global(.hljs-params) {
color: var(--hl-variable, #D4A0A0);
color: var(--hl-variable);
}
.code :global(.hljs-property) {
color: var(--hl-property, #79C0C8);
color: var(--hl-property);
}
.code :global(.hljs-deletion),
.code :global(.hljs-meta) {
color: var(--hl-meta, #A9A3C9);
color: var(--hl-meta);
}
.code :global(.hljs-emphasis) {
+1 -1
View File
@@ -49,7 +49,7 @@
.sortIconActive {
opacity: 1;
color: var(--color-primary);
color: var(--color-primary-text);
}
[data-theme="dark"] .th {
@@ -4,6 +4,23 @@
position: relative;
}
.badge {
transition: background var(--transition);
}
.badge:hover {
background: color-mix(in srgb, var(--color-neutral-bg) 85%, white);
}
.swatch {
width: 8px;
height: 8px;
border-radius: 50%;
border: 1px solid currentColor;
box-sizing: border-box;
flex-shrink: 0;
}
.button {
all: unset;
cursor: pointer;
+10 -1
View File
@@ -7,9 +7,15 @@ export interface UuidBadgeProps {
id: string;
}
function uuidColor(id: string): string | null {
const hex = id.replace(/-/g, '').slice(0, 6);
return /^[0-9a-f]{6}$/i.test(hex) ? `#${hex}` : null;
}
export function UuidBadge({ id }: UuidBadgeProps) {
const [copied, setCopied] = useState(false);
const short = `${id.slice(0, 4)}…${id.slice(-4)}`;
const color = uuidColor(id);
const handleClick = (e: React.MouseEvent) => {
e.stopPropagation();
@@ -21,7 +27,10 @@ export function UuidBadge({ id }: UuidBadgeProps) {
return (
<span className={styles.wrapper} title={copied ? 'Copied!' : id}>
<Badge variant="neutral">
<Badge variant="neutral" className={styles.badge}>
{color && (
<span className={styles.swatch} style={{ background: color }} aria-hidden="true" />
)}
<button type="button" className={styles.button} onClick={handleClick}>
{short}
</button>
+27 -4
View File
@@ -11,6 +11,8 @@
--color-primary-hover: #8ABD2E;
--color-primary-active: #77A320;
--color-primary-fg: #2D3339; /* Outer Space on bright green */
/* Primary as text/icon color on light surfaces (Atlantis is too light for text) */
--color-primary-text: #496904;
/* Secondary — Kimberly tint */
--color-secondary: #EDEAF8;
@@ -19,8 +21,8 @@
--color-secondary-fg: #6650C0; /* Kimberly */
--color-secondary-border: #B8B0E0;
/* Danger */
--color-danger: #D94F4F;
/* Danger (white text needs >= 4.5:1) */
--color-danger: #CE4546;
--color-danger-hover: #C03A3A;
--color-danger-fg: #ffffff;
@@ -43,11 +45,21 @@
--color-link-hover: #3D2F80;
--color-text: #2D3339;
--color-text-muted: #6650C0; /* Kimberly */
--color-text-muted: #634DBD; /* Kimberly, a touch darker for 4.5:1 on bg-subtle */
--color-border: #AFBFB9; /* Powder Ash */
--color-bg: #E6EDEA; /* Powder Ash tint */
--color-bg-subtle: #D8E2DE; /* Powder Ash tint, 1 step darker */
/* Syntax highlighting (CodeBlock); each >= 4.5:1 on bg and bg-subtle */
--hl-comment: #4F6557;
--hl-keyword: #764E99;
--hl-string: #4F6821;
--hl-number: #895403;
--hl-function: #056980;
--hl-variable: #815354;
--hl-property: #1D6971;
--hl-meta: #615B7E;
/* Spacing */
--space-1: 4px;
--space-2: 8px;
@@ -112,6 +124,7 @@ a:hover {
--color-primary-hover: #AEDE55;
--color-primary-active: #8ABD2E;
--color-primary-fg: #1A1F24;
--color-primary-text: #9DD341;
/* Secondary — dark Kimberly tint */
--color-secondary: #2A2548;
@@ -122,7 +135,7 @@ a:hover {
/* Danger */
--color-danger: #E06060;
--color-danger-hover: #CC4A4A;
--color-danger-hover: #F06E6D; /* lighter, so the dark text keeps >= 4.5:1 */
--color-danger-fg: #1A1F24;
/* Semantic */
@@ -148,4 +161,14 @@ a:hover {
--color-border: #3D4850;
--color-bg: #1A1F24; /* deeper than Outer Space */
--color-bg-subtle: #2D3339; /* Outer Space */
/* Syntax highlighting (CodeBlock); each >= 4.5:1 on bg and bg-subtle */
--hl-comment: #8AA192;
--hl-keyword: #B38ADA;
--hl-string: #9BB870;
--hl-number: #E8A85F;
--hl-function: #5BB8D4;
--hl-variable: #D4A0A0;
--hl-property: #79C0C8;
--hl-meta: #A9A3C9;
}
+2 -1
View File
@@ -50,6 +50,7 @@ Everything runs in one container built from the root `Dockerfile`: the server se
Cross-cutting pieces:
- `config/app.config.ts` - all settings, validated at startup (see `.env.example`).
- `database/` - the entity list, TypeORM data source options (shared by the app, the migration runner and the TypeORM CLI), the migration runner and the migrations.
- `common/app-package.ts` - app name and version, read from the workspace root `package.json`.
- `common/client-static.ts` - serving the built client, with the `index.html` fallback for client-side routes.
- `common/body-parsers.ts` - YAML request bodies (`application/yaml`) for the import endpoint.
@@ -57,7 +58,7 @@ Cross-cutting pieces:
## Data
SQLite via TypeORM with `synchronize: true`: entity changes alter the schema on startup, and there are no migrations. The main tables:
SQLite via TypeORM. The schema is managed by migrations (`server/src/database/migrations/`, registered in `migrations/index.ts`); `synchronize` is off. The Docker container applies pending migrations (`node dist/database/migrate`) before starting the server, and the server refuses to start while migrations are pending. See "Database migrations" in [development.md](development.md). The main tables:
- `scenarios` / `scenario_steps` hold the **latest** version of each scenario; `scenario_versions` holds a snapshot of every version (content + steps).
- `snippets` holds the latest version of each snippet; `snippet_versions` holds every version. Step code pins a version with `runSnippet("alias@N")`.
+30
View File
@@ -86,6 +86,36 @@ The built files are emitted to `client/dist/`.
---
## Database migrations
The SQLite schema is managed by TypeORM migrations in `server/src/database/migrations/`; `synchronize` is off.
- **Docker:** the container applies pending migrations before starting the server.
- **Locally:** build, then apply them before starting the server (it refuses to start while migrations are pending):
```bash
npm -w server run build
npm -w server run migration:run # apply pending migrations to DB_PATH
npm -w server run migration:show # list migrations and whether they're applied
```
The scripts run from `server/`, so `DB_PATH` (default `data/liqa.db`) is relative to it, and they read `server/.env` if present, like the server does.
**Changing the schema** (adding or changing an entity):
1. Change the entity and build (`npm -w server run build`).
2. Make sure your local database is on the latest migration (`migration:run`).
3. Generate a migration from the difference between the entities and that database:
```bash
npm -w server run migration:generate -- src/database/migrations/AddSomething
```
4. Review the generated file, then add its class to `MIGRATIONS` in `src/database/migrations/index.ts` (they're listed explicitly, oldest first).
5. Run the tests: `test/migrations.spec.ts` checks that the migrations produce exactly the schema the entities describe, and fails if an entity change has no migration.
The initial migration (`Initial…`) adopts databases created before migrations existed (by `synchronize`): if the tables already exist, it's only recorded as applied.
## Running tests
### Server (Jest)
+4629 -3596
View File
File diff suppressed because it is too large. Load diff
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "liqa",
"version": "1.19.3",
"version": "1.21.0",
"private": true,
"engines": {
"node": ">=24"
+3
View File
@@ -7,6 +7,9 @@
"start": "nest start",
"start:dev": "nest start --watch",
"start:prod": "node dist/main",
"migration:run": "node dist/database/migrate",
"migration:show": "typeorm migration:show -d dist/database/data-source.js",
"migration:generate": "typeorm migration:generate -d dist/database/data-source.js",
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
"lint": "eslint \"src/**/*.ts\" \"test/**/*.ts\"",
"lint:fix": "eslint --fix \"src/**/*.ts\" \"test/**/*.ts\"",
+3 -37
View File
@@ -5,29 +5,15 @@ import { ServeStaticModule } from "@nestjs/serve-static";
import { TypeOrmModule } from "@nestjs/typeorm";
import { BrowserModule } from "./browser/browser.module";
import { clientStaticOptions } from "./common/client-static";
import { dataSourceOptions } from "./database/data-source";
import { AppConfig, validateAppConfig } from "./config/app.config";
import { CredentialEntity } from "./credential/credential.entity";
import { CredentialModule } from "./credential/credential.module";
import { EnvironmentEntity } from "./environment/environment.entity";
import { EnvironmentModule } from "./environment/environment.module";
import { FileEntity } from "./file/file.entity";
import { FileModule } from "./file/file.module";
import { ScenarioFileEntity } from "./file/scenario-file.entity";
import { ScenarioRunFileEntity } from "./file/scenario-run-file.entity";
import { HealthModule } from "./health/health.module";
import { ImportModule } from "./import/import.module";
import { McpModule } from "./mcp/mcp.module";
import { ScenarioCredentialEntity } from "./scenario/scenario-credential.entity";
import { ScenarioRunLogEntity } from "./scenario/scenario-run-log.entity";
import { ScenarioRunStepEntity } from "./scenario/scenario-run-step.entity";
import { ScenarioRunEntity } from "./scenario/scenario-run.entity";
import { ScenarioStepEntity } from "./scenario/scenario-step.entity";
import { ScenarioVersionEntity } from "./scenario/scenario-version.entity";
import { SnippetVersionEntity } from "./snippet/snippet-version.entity";
import { ScenarioEntity } from "./scenario/scenario.entity";
import { ScenarioModule } from "./scenario/scenario.module";
import { SessionEntity } from "./session/session.entity";
import { SnippetEntity } from "./snippet/snippet.entity";
import { SnippetModule } from "./snippet/snippet.module";
@Module({
@@ -45,28 +31,8 @@ import { SnippetModule } from "./snippet/snippet.module";
}),
TypeOrmModule.forRootAsync({
inject: [ConfigService],
useFactory: (config: ConfigService<AppConfig, true>) => ({
type: "better-sqlite3",
database: config.get("DB_PATH"),
entities: [
SessionEntity,
EnvironmentEntity,
CredentialEntity,
ScenarioEntity,
ScenarioStepEntity,
ScenarioVersionEntity,
ScenarioRunEntity,
ScenarioRunStepEntity,
ScenarioRunLogEntity,
ScenarioCredentialEntity,
SnippetEntity,
SnippetVersionEntity,
FileEntity,
ScenarioFileEntity,
ScenarioRunFileEntity,
],
synchronize: true,
}),
useFactory: (config: ConfigService<AppConfig, true>) =>
dataSourceOptions(config.get("DB_PATH")),
}),
BrowserModule,
EnvironmentModule,
+31
View File
@@ -0,0 +1,31 @@
import * as fs from "node:fs";
import { DataSource, type DataSourceOptions } from "typeorm";
import { validateAppConfig } from "../config/app.config";
import { ENTITIES } from "./entities";
import { MIGRATIONS } from "./migrations";
/**
* TypeORM options shared by the app, the migration runner and the TypeORM
* CLI. The schema is managed by migrations only (`synchronize: false`).
*/
export function dataSourceOptions(database: string): DataSourceOptions {
return {
type: "better-sqlite3",
database,
entities: ENTITIES,
migrations: MIGRATIONS,
synchronize: false,
};
}
// Outside Nest (migration runner, TypeORM CLI) nothing loads .env; load it
// like ConfigModule does: optional, and without overriding set variables
if (fs.existsSync(".env")) process.loadEnvFile(".env");
/**
* Data source for the TypeORM CLI and `migrate.ts`, using DB_PATH from the
* environment or .env (default `data/liqa.db`).
*/
export default new DataSource(
dataSourceOptions(validateAppConfig(process.env).DB_PATH),
);
+34
View File
@@ -0,0 +1,34 @@
import { CredentialEntity } from "../credential/credential.entity";
import { EnvironmentEntity } from "../environment/environment.entity";
import { FileEntity } from "../file/file.entity";
import { ScenarioFileEntity } from "../file/scenario-file.entity";
import { ScenarioRunFileEntity } from "../file/scenario-run-file.entity";
import { ScenarioCredentialEntity } from "../scenario/scenario-credential.entity";
import { ScenarioRunLogEntity } from "../scenario/scenario-run-log.entity";
import { ScenarioRunStepEntity } from "../scenario/scenario-run-step.entity";
import { ScenarioRunEntity } from "../scenario/scenario-run.entity";
import { ScenarioStepEntity } from "../scenario/scenario-step.entity";
import { ScenarioVersionEntity } from "../scenario/scenario-version.entity";
import { ScenarioEntity } from "../scenario/scenario.entity";
import { SessionEntity } from "../session/session.entity";
import { SnippetVersionEntity } from "../snippet/snippet-version.entity";
import { SnippetEntity } from "../snippet/snippet.entity";
/** Every TypeORM entity of the app (used by the app, the migrations CLI and tests). */
export const ENTITIES = [
SessionEntity,
EnvironmentEntity,
CredentialEntity,
ScenarioEntity,
ScenarioStepEntity,
ScenarioVersionEntity,
ScenarioRunEntity,
ScenarioRunStepEntity,
ScenarioRunLogEntity,
ScenarioCredentialEntity,
SnippetEntity,
SnippetVersionEntity,
FileEntity,
ScenarioFileEntity,
ScenarioRunFileEntity,
];
+24
View File
@@ -0,0 +1,24 @@
import dataSource from "./data-source";
/**
* Applies pending migrations to the database at DB_PATH, then exits. Runs
* before the server in the Docker image (`node dist/database/migrate`).
*/
async function migrate(): Promise<void> {
await dataSource.initialize();
try {
const applied = await dataSource.runMigrations({ transaction: "each" });
console.log(
applied.length > 0
? `Applied ${applied.length} migration(s): ${applied.map((m) => m.name).join(", ")}`
: "Database schema is up to date",
);
} finally {
await dataSource.destroy();
}
}
migrate().catch((err: unknown) => {
console.error("Migration failed:", err);
process.exit(1);
});
@@ -0,0 +1,277 @@
import { MigrationInterface, QueryRunner } from "typeorm";
/**
* Initial schema. Databases created before migrations existed (by TypeORM
* `synchronize`) already have this schema: for them this migration only gets
* recorded as applied, and later migrations run from there.
*/
export class Initial1790793447827 implements MigrationInterface {
name = "Initial1790793447827";
public async up(queryRunner: QueryRunner): Promise<void> {
if (await queryRunner.hasTable("scenarios")) return;
await queryRunner.query(
`CREATE TABLE "credentials" ("id" varchar PRIMARY KEY NOT NULL, "name" varchar NOT NULL, "data" text, "lastUsedAt" datetime, "createdAt" datetime NOT NULL DEFAULT (datetime('now')), "updatedAt" datetime NOT NULL DEFAULT (datetime('now')))`,
);
await queryRunner.query(
`CREATE TABLE "environments" ("id" varchar PRIMARY KEY NOT NULL, "name" varchar NOT NULL, "description" text, "data" text NOT NULL, "createdAt" datetime NOT NULL DEFAULT (datetime('now')), "updatedAt" datetime NOT NULL DEFAULT (datetime('now')), CONSTRAINT "UQ_9d00da4836959b86d7590f60c57" UNIQUE ("name"))`,
);
await queryRunner.query(
`CREATE TABLE "files" ("id" varchar PRIMARY KEY NOT NULL, "originalName" varchar NOT NULL, "mimeType" varchar NOT NULL, "size" integer NOT NULL, "sha256" varchar NOT NULL, "filePath" varchar NOT NULL, "expiresAt" datetime, "createdAt" datetime NOT NULL DEFAULT (datetime('now')))`,
);
await queryRunner.query(
`CREATE TABLE "scenario_credentials" ("id" varchar PRIMARY KEY NOT NULL, "scenarioId" varchar NOT NULL, "credentialId" varchar NOT NULL, "alias" varchar NOT NULL, "createdAt" datetime NOT NULL DEFAULT (datetime('now')), CONSTRAINT "UQ_02756536236c408dbb58b3fc964" UNIQUE ("scenarioId", "alias"))`,
);
await queryRunner.query(
`CREATE TABLE "scenario_steps" ("id" varchar PRIMARY KEY NOT NULL, "scenarioId" varchar NOT NULL, "order" integer NOT NULL DEFAULT (0), "title" text, "execCode" text, "timeoutSeconds" integer, "createdAt" datetime NOT NULL DEFAULT (datetime('now')), "updatedAt" datetime NOT NULL DEFAULT (datetime('now')))`,
);
await queryRunner.query(
`CREATE TABLE "scenarios" ("id" varchar PRIMARY KEY NOT NULL, "name" varchar NOT NULL, "description" text, "environmentId" varchar, "timeoutSeconds" integer, "version" integer NOT NULL DEFAULT (1), "createdAt" datetime NOT NULL DEFAULT (datetime('now')), "updatedAt" datetime NOT NULL DEFAULT (datetime('now')))`,
);
await queryRunner.query(
`CREATE TABLE "scenario_files" ("id" varchar PRIMARY KEY NOT NULL, "scenarioId" varchar NOT NULL, "fileId" varchar NOT NULL, "createdAt" datetime NOT NULL DEFAULT (datetime('now')))`,
);
await queryRunner.query(
`CREATE TABLE "sessions" ("id" varchar PRIMARY KEY NOT NULL, "sessionName" varchar NOT NULL, "token" text NOT NULL, "cookies" text NOT NULL, "localStorage" text NOT NULL DEFAULT ('{}'), "status" varchar NOT NULL DEFAULT ('closed'), "lastUsedAt" datetime, "createdAt" datetime NOT NULL DEFAULT (datetime('now')), "updatedAt" datetime NOT NULL DEFAULT (datetime('now')), CONSTRAINT "UQ_b8f17f1ce30f015f494188c50bb" UNIQUE ("sessionName"))`,
);
await queryRunner.query(
`CREATE TABLE "scenario_run_steps" ("id" varchar PRIMARY KEY NOT NULL, "runId" varchar NOT NULL, "scenarioStepId" varchar, "title" text, "execCode" text, "timeoutSeconds" integer, "status" text NOT NULL DEFAULT ('waiting'), "order" integer NOT NULL DEFAULT (0), "description" text, "output" text, "createdAt" datetime NOT NULL DEFAULT (datetime('now')), "updatedAt" datetime NOT NULL DEFAULT (datetime('now')))`,
);
await queryRunner.query(
`CREATE TABLE "scenario_runs" ("id" varchar PRIMARY KEY NOT NULL, "scenarioId" varchar NOT NULL, "environmentId" varchar, "sessionId" varchar, "scenarioVersion" integer, "status" text NOT NULL DEFAULT ('pending'), "saveSession" boolean NOT NULL DEFAULT (0), "traceMode" text, "createdAt" datetime NOT NULL DEFAULT (datetime('now')), "updatedAt" datetime NOT NULL DEFAULT (datetime('now')))`,
);
await queryRunner.query(
`CREATE TABLE "scenario_run_files" ("id" varchar PRIMARY KEY NOT NULL, "runId" varchar NOT NULL, "fileId" varchar NOT NULL, "createdAt" datetime NOT NULL DEFAULT (datetime('now')))`,
);
await queryRunner.query(
`CREATE TABLE "scenario_run_logs" ("id" varchar PRIMARY KEY NOT NULL, "runId" varchar NOT NULL, "stepRunId" varchar, "level" text NOT NULL DEFAULT ('log'), "message" text NOT NULL, "seq" integer NOT NULL DEFAULT (0), "createdAt" datetime NOT NULL DEFAULT (datetime('now')))`,
);
await queryRunner.query(
`CREATE TABLE "scenario_versions" ("id" varchar PRIMARY KEY NOT NULL, "scenarioId" varchar NOT NULL, "version" integer NOT NULL, "name" varchar NOT NULL, "description" text, "environmentId" text, "timeoutSeconds" integer, "steps" text NOT NULL, "createdAt" datetime NOT NULL DEFAULT (datetime('now')), CONSTRAINT "UQ_e1a56dce2b7e0379bb5bbdf8c1f" UNIQUE ("scenarioId", "version"))`,
);
await queryRunner.query(
`CREATE TABLE "snippets" ("id" varchar PRIMARY KEY NOT NULL, "alias" varchar, "title" varchar NOT NULL DEFAULT (''), "description" text, "code" text NOT NULL, "version" integer NOT NULL DEFAULT (1), "createdAt" datetime NOT NULL DEFAULT (datetime('now')), "updatedAt" datetime NOT NULL DEFAULT (datetime('now')), CONSTRAINT "UQ_bd062c68591ae917b720eb3427c" UNIQUE ("alias"))`,
);
await queryRunner.query(
`CREATE TABLE "snippet_versions" ("id" varchar PRIMARY KEY NOT NULL, "snippetId" varchar NOT NULL, "version" integer NOT NULL, "alias" varchar NOT NULL, "title" varchar NOT NULL DEFAULT (''), "description" text, "code" text NOT NULL, "createdAt" datetime NOT NULL DEFAULT (datetime('now')), CONSTRAINT "UQ_2487f4aabeb20c4192ee30e09a2" UNIQUE ("snippetId", "version"))`,
);
await queryRunner.query(
`CREATE TABLE "temporary_scenario_credentials" ("id" varchar PRIMARY KEY NOT NULL, "scenarioId" varchar NOT NULL, "credentialId" varchar NOT NULL, "alias" varchar NOT NULL, "createdAt" datetime NOT NULL DEFAULT (datetime('now')), CONSTRAINT "UQ_02756536236c408dbb58b3fc964" UNIQUE ("scenarioId", "alias"), CONSTRAINT "FK_37f19dadd8e524b22a807ece1a9" FOREIGN KEY ("scenarioId") REFERENCES "scenarios" ("id") ON DELETE CASCADE ON UPDATE NO ACTION, CONSTRAINT "FK_96676b988693d5ca2923782530c" FOREIGN KEY ("credentialId") REFERENCES "credentials" ("id") ON DELETE CASCADE ON UPDATE NO ACTION)`,
);
await queryRunner.query(
`INSERT INTO "temporary_scenario_credentials"("id", "scenarioId", "credentialId", "alias", "createdAt") SELECT "id", "scenarioId", "credentialId", "alias", "createdAt" FROM "scenario_credentials"`,
);
await queryRunner.query(`DROP TABLE "scenario_credentials"`);
await queryRunner.query(
`ALTER TABLE "temporary_scenario_credentials" RENAME TO "scenario_credentials"`,
);
await queryRunner.query(
`CREATE TABLE "temporary_scenario_steps" ("id" varchar PRIMARY KEY NOT NULL, "scenarioId" varchar NOT NULL, "order" integer NOT NULL DEFAULT (0), "title" text, "execCode" text, "timeoutSeconds" integer, "createdAt" datetime NOT NULL DEFAULT (datetime('now')), "updatedAt" datetime NOT NULL DEFAULT (datetime('now')), CONSTRAINT "FK_4bab3637cc3bf37677bb01c7446" FOREIGN KEY ("scenarioId") REFERENCES "scenarios" ("id") ON DELETE CASCADE ON UPDATE NO ACTION)`,
);
await queryRunner.query(
`INSERT INTO "temporary_scenario_steps"("id", "scenarioId", "order", "title", "execCode", "timeoutSeconds", "createdAt", "updatedAt") SELECT "id", "scenarioId", "order", "title", "execCode", "timeoutSeconds", "createdAt", "updatedAt" FROM "scenario_steps"`,
);
await queryRunner.query(`DROP TABLE "scenario_steps"`);
await queryRunner.query(
`ALTER TABLE "temporary_scenario_steps" RENAME TO "scenario_steps"`,
);
await queryRunner.query(
`CREATE TABLE "temporary_scenarios" ("id" varchar PRIMARY KEY NOT NULL, "name" varchar NOT NULL, "description" text, "environmentId" varchar, "timeoutSeconds" integer, "version" integer NOT NULL DEFAULT (1), "createdAt" datetime NOT NULL DEFAULT (datetime('now')), "updatedAt" datetime NOT NULL DEFAULT (datetime('now')), CONSTRAINT "FK_ffdcf9186d95114f0dab068e20a" FOREIGN KEY ("environmentId") REFERENCES "environments" ("id") ON DELETE SET NULL ON UPDATE NO ACTION)`,
);
await queryRunner.query(
`INSERT INTO "temporary_scenarios"("id", "name", "description", "environmentId", "timeoutSeconds", "version", "createdAt", "updatedAt") SELECT "id", "name", "description", "environmentId", "timeoutSeconds", "version", "createdAt", "updatedAt" FROM "scenarios"`,
);
await queryRunner.query(`DROP TABLE "scenarios"`);
await queryRunner.query(
`ALTER TABLE "temporary_scenarios" RENAME TO "scenarios"`,
);
await queryRunner.query(
`CREATE TABLE "temporary_scenario_files" ("id" varchar PRIMARY KEY NOT NULL, "scenarioId" varchar NOT NULL, "fileId" varchar NOT NULL, "createdAt" datetime NOT NULL DEFAULT (datetime('now')), CONSTRAINT "FK_c41719984235f8984d1c6b92ef5" FOREIGN KEY ("scenarioId") REFERENCES "scenarios" ("id") ON DELETE CASCADE ON UPDATE NO ACTION, CONSTRAINT "FK_67013a49e7948fb530a7d956e2b" FOREIGN KEY ("fileId") REFERENCES "files" ("id") ON DELETE CASCADE ON UPDATE NO ACTION)`,
);
await queryRunner.query(
`INSERT INTO "temporary_scenario_files"("id", "scenarioId", "fileId", "createdAt") SELECT "id", "scenarioId", "fileId", "createdAt" FROM "scenario_files"`,
);
await queryRunner.query(`DROP TABLE "scenario_files"`);
await queryRunner.query(
`ALTER TABLE "temporary_scenario_files" RENAME TO "scenario_files"`,
);
await queryRunner.query(
`CREATE TABLE "temporary_scenario_run_steps" ("id" varchar PRIMARY KEY NOT NULL, "runId" varchar NOT NULL, "scenarioStepId" varchar, "title" text, "execCode" text, "timeoutSeconds" integer, "status" text NOT NULL DEFAULT ('waiting'), "order" integer NOT NULL DEFAULT (0), "description" text, "output" text, "createdAt" datetime NOT NULL DEFAULT (datetime('now')), "updatedAt" datetime NOT NULL DEFAULT (datetime('now')), CONSTRAINT "FK_213c27405af3433011121babb58" FOREIGN KEY ("runId") REFERENCES "scenario_runs" ("id") ON DELETE CASCADE ON UPDATE NO ACTION, CONSTRAINT "FK_e84cd4c7725bdc5dfd09d18d92f" FOREIGN KEY ("scenarioStepId") REFERENCES "scenario_steps" ("id") ON DELETE SET NULL ON UPDATE NO ACTION)`,
);
await queryRunner.query(
`INSERT INTO "temporary_scenario_run_steps"("id", "runId", "scenarioStepId", "title", "execCode", "timeoutSeconds", "status", "order", "description", "output", "createdAt", "updatedAt") SELECT "id", "runId", "scenarioStepId", "title", "execCode", "timeoutSeconds", "status", "order", "description", "output", "createdAt", "updatedAt" FROM "scenario_run_steps"`,
);
await queryRunner.query(`DROP TABLE "scenario_run_steps"`);
await queryRunner.query(
`ALTER TABLE "temporary_scenario_run_steps" RENAME TO "scenario_run_steps"`,
);
await queryRunner.query(
`CREATE TABLE "temporary_scenario_runs" ("id" varchar PRIMARY KEY NOT NULL, "scenarioId" varchar NOT NULL, "environmentId" varchar, "sessionId" varchar, "scenarioVersion" integer, "status" text NOT NULL DEFAULT ('pending'), "saveSession" boolean NOT NULL DEFAULT (0), "traceMode" text, "createdAt" datetime NOT NULL DEFAULT (datetime('now')), "updatedAt" datetime NOT NULL DEFAULT (datetime('now')), CONSTRAINT "FK_1d2c2595dfff133de062f9c692a" FOREIGN KEY ("scenarioId") REFERENCES "scenarios" ("id") ON DELETE CASCADE ON UPDATE NO ACTION, CONSTRAINT "FK_5076ffbd1b4fa71f5de011eba1f" FOREIGN KEY ("environmentId") REFERENCES "environments" ("id") ON DELETE SET NULL ON UPDATE NO ACTION, CONSTRAINT "FK_068b01cdfa49095433f245d6708" FOREIGN KEY ("sessionId") REFERENCES "sessions" ("id") ON DELETE SET NULL ON UPDATE NO ACTION)`,
);
await queryRunner.query(
`INSERT INTO "temporary_scenario_runs"("id", "scenarioId", "environmentId", "sessionId", "scenarioVersion", "status", "saveSession", "traceMode", "createdAt", "updatedAt") SELECT "id", "scenarioId", "environmentId", "sessionId", "scenarioVersion", "status", "saveSession", "traceMode", "createdAt", "updatedAt" FROM "scenario_runs"`,
);
await queryRunner.query(`DROP TABLE "scenario_runs"`);
await queryRunner.query(
`ALTER TABLE "temporary_scenario_runs" RENAME TO "scenario_runs"`,
);
await queryRunner.query(
`CREATE TABLE "temporary_scenario_run_files" ("id" varchar PRIMARY KEY NOT NULL, "runId" varchar NOT NULL, "fileId" varchar NOT NULL, "createdAt" datetime NOT NULL DEFAULT (datetime('now')), CONSTRAINT "FK_5fc35a4bfc42d7566a0f7706902" FOREIGN KEY ("runId") REFERENCES "scenario_runs" ("id") ON DELETE CASCADE ON UPDATE NO ACTION, CONSTRAINT "FK_637619025bdb0b6a89fae6e178d" FOREIGN KEY ("fileId") REFERENCES "files" ("id") ON DELETE CASCADE ON UPDATE NO ACTION)`,
);
await queryRunner.query(
`INSERT INTO "temporary_scenario_run_files"("id", "runId", "fileId", "createdAt") SELECT "id", "runId", "fileId", "createdAt" FROM "scenario_run_files"`,
);
await queryRunner.query(`DROP TABLE "scenario_run_files"`);
await queryRunner.query(
`ALTER TABLE "temporary_scenario_run_files" RENAME TO "scenario_run_files"`,
);
await queryRunner.query(
`CREATE TABLE "temporary_scenario_run_logs" ("id" varchar PRIMARY KEY NOT NULL, "runId" varchar NOT NULL, "stepRunId" varchar, "level" text NOT NULL DEFAULT ('log'), "message" text NOT NULL, "seq" integer NOT NULL DEFAULT (0), "createdAt" datetime NOT NULL DEFAULT (datetime('now')), CONSTRAINT "FK_dde48478a42823e583a360dd468" FOREIGN KEY ("runId") REFERENCES "scenario_runs" ("id") ON DELETE CASCADE ON UPDATE NO ACTION, CONSTRAINT "FK_62d82b9fce3a6a2947ed1136c67" FOREIGN KEY ("stepRunId") REFERENCES "scenario_run_steps" ("id") ON DELETE SET NULL ON UPDATE NO ACTION)`,
);
await queryRunner.query(
`INSERT INTO "temporary_scenario_run_logs"("id", "runId", "stepRunId", "level", "message", "seq", "createdAt") SELECT "id", "runId", "stepRunId", "level", "message", "seq", "createdAt" FROM "scenario_run_logs"`,
);
await queryRunner.query(`DROP TABLE "scenario_run_logs"`);
await queryRunner.query(
`ALTER TABLE "temporary_scenario_run_logs" RENAME TO "scenario_run_logs"`,
);
await queryRunner.query(
`CREATE TABLE "temporary_scenario_versions" ("id" varchar PRIMARY KEY NOT NULL, "scenarioId" varchar NOT NULL, "version" integer NOT NULL, "name" varchar NOT NULL, "description" text, "environmentId" text, "timeoutSeconds" integer, "steps" text NOT NULL, "createdAt" datetime NOT NULL DEFAULT (datetime('now')), CONSTRAINT "UQ_e1a56dce2b7e0379bb5bbdf8c1f" UNIQUE ("scenarioId", "version"), CONSTRAINT "FK_f5ccfb45c7847cfab74cf4f17b6" FOREIGN KEY ("scenarioId") REFERENCES "scenarios" ("id") ON DELETE CASCADE ON UPDATE NO ACTION)`,
);
await queryRunner.query(
`INSERT INTO "temporary_scenario_versions"("id", "scenarioId", "version", "name", "description", "environmentId", "timeoutSeconds", "steps", "createdAt") SELECT "id", "scenarioId", "version", "name", "description", "environmentId", "timeoutSeconds", "steps", "createdAt" FROM "scenario_versions"`,
);
await queryRunner.query(`DROP TABLE "scenario_versions"`);
await queryRunner.query(
`ALTER TABLE "temporary_scenario_versions" RENAME TO "scenario_versions"`,
);
await queryRunner.query(
`CREATE TABLE "temporary_snippet_versions" ("id" varchar PRIMARY KEY NOT NULL, "snippetId" varchar NOT NULL, "version" integer NOT NULL, "alias" varchar NOT NULL, "title" varchar NOT NULL DEFAULT (''), "description" text, "code" text NOT NULL, "createdAt" datetime NOT NULL DEFAULT (datetime('now')), CONSTRAINT "UQ_2487f4aabeb20c4192ee30e09a2" UNIQUE ("snippetId", "version"), CONSTRAINT "FK_0d3a004957c9553619be11635fd" FOREIGN KEY ("snippetId") REFERENCES "snippets" ("id") ON DELETE CASCADE ON UPDATE NO ACTION)`,
);
await queryRunner.query(
`INSERT INTO "temporary_snippet_versions"("id", "snippetId", "version", "alias", "title", "description", "code", "createdAt") SELECT "id", "snippetId", "version", "alias", "title", "description", "code", "createdAt" FROM "snippet_versions"`,
);
await queryRunner.query(`DROP TABLE "snippet_versions"`);
await queryRunner.query(
`ALTER TABLE "temporary_snippet_versions" RENAME TO "snippet_versions"`,
);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "snippet_versions" RENAME TO "temporary_snippet_versions"`,
);
await queryRunner.query(
`CREATE TABLE "snippet_versions" ("id" varchar PRIMARY KEY NOT NULL, "snippetId" varchar NOT NULL, "version" integer NOT NULL, "alias" varchar NOT NULL, "title" varchar NOT NULL DEFAULT (''), "description" text, "code" text NOT NULL, "createdAt" datetime NOT NULL DEFAULT (datetime('now')), CONSTRAINT "UQ_2487f4aabeb20c4192ee30e09a2" UNIQUE ("snippetId", "version"))`,
);
await queryRunner.query(
`INSERT INTO "snippet_versions"("id", "snippetId", "version", "alias", "title", "description", "code", "createdAt") SELECT "id", "snippetId", "version", "alias", "title", "description", "code", "createdAt" FROM "temporary_snippet_versions"`,
);
await queryRunner.query(`DROP TABLE "temporary_snippet_versions"`);
await queryRunner.query(
`ALTER TABLE "scenario_versions" RENAME TO "temporary_scenario_versions"`,
);
await queryRunner.query(
`CREATE TABLE "scenario_versions" ("id" varchar PRIMARY KEY NOT NULL, "scenarioId" varchar NOT NULL, "version" integer NOT NULL, "name" varchar NOT NULL, "description" text, "environmentId" text, "timeoutSeconds" integer, "steps" text NOT NULL, "createdAt" datetime NOT NULL DEFAULT (datetime('now')), CONSTRAINT "UQ_e1a56dce2b7e0379bb5bbdf8c1f" UNIQUE ("scenarioId", "version"))`,
);
await queryRunner.query(
`INSERT INTO "scenario_versions"("id", "scenarioId", "version", "name", "description", "environmentId", "timeoutSeconds", "steps", "createdAt") SELECT "id", "scenarioId", "version", "name", "description", "environmentId", "timeoutSeconds", "steps", "createdAt" FROM "temporary_scenario_versions"`,
);
await queryRunner.query(`DROP TABLE "temporary_scenario_versions"`);
await queryRunner.query(
`ALTER TABLE "scenario_run_logs" RENAME TO "temporary_scenario_run_logs"`,
);
await queryRunner.query(
`CREATE TABLE "scenario_run_logs" ("id" varchar PRIMARY KEY NOT NULL, "runId" varchar NOT NULL, "stepRunId" varchar, "level" text NOT NULL DEFAULT ('log'), "message" text NOT NULL, "seq" integer NOT NULL DEFAULT (0), "createdAt" datetime NOT NULL DEFAULT (datetime('now')))`,
);
await queryRunner.query(
`INSERT INTO "scenario_run_logs"("id", "runId", "stepRunId", "level", "message", "seq", "createdAt") SELECT "id", "runId", "stepRunId", "level", "message", "seq", "createdAt" FROM "temporary_scenario_run_logs"`,
);
await queryRunner.query(`DROP TABLE "temporary_scenario_run_logs"`);
await queryRunner.query(
`ALTER TABLE "scenario_run_files" RENAME TO "temporary_scenario_run_files"`,
);
await queryRunner.query(
`CREATE TABLE "scenario_run_files" ("id" varchar PRIMARY KEY NOT NULL, "runId" varchar NOT NULL, "fileId" varchar NOT NULL, "createdAt" datetime NOT NULL DEFAULT (datetime('now')))`,
);
await queryRunner.query(
`INSERT INTO "scenario_run_files"("id", "runId", "fileId", "createdAt") SELECT "id", "runId", "fileId", "createdAt" FROM "temporary_scenario_run_files"`,
);
await queryRunner.query(`DROP TABLE "temporary_scenario_run_files"`);
await queryRunner.query(
`ALTER TABLE "scenario_runs" RENAME TO "temporary_scenario_runs"`,
);
await queryRunner.query(
`CREATE TABLE "scenario_runs" ("id" varchar PRIMARY KEY NOT NULL, "scenarioId" varchar NOT NULL, "environmentId" varchar, "sessionId" varchar, "scenarioVersion" integer, "status" text NOT NULL DEFAULT ('pending'), "saveSession" boolean NOT NULL DEFAULT (0), "traceMode" text, "createdAt" datetime NOT NULL DEFAULT (datetime('now')), "updatedAt" datetime NOT NULL DEFAULT (datetime('now')))`,
);
await queryRunner.query(
`INSERT INTO "scenario_runs"("id", "scenarioId", "environmentId", "sessionId", "scenarioVersion", "status", "saveSession", "traceMode", "createdAt", "updatedAt") SELECT "id", "scenarioId", "environmentId", "sessionId", "scenarioVersion", "status", "saveSession", "traceMode", "createdAt", "updatedAt" FROM "temporary_scenario_runs"`,
);
await queryRunner.query(`DROP TABLE "temporary_scenario_runs"`);
await queryRunner.query(
`ALTER TABLE "scenario_run_steps" RENAME TO "temporary_scenario_run_steps"`,
);
await queryRunner.query(
`CREATE TABLE "scenario_run_steps" ("id" varchar PRIMARY KEY NOT NULL, "runId" varchar NOT NULL, "scenarioStepId" varchar, "title" text, "execCode" text, "timeoutSeconds" integer, "status" text NOT NULL DEFAULT ('waiting'), "order" integer NOT NULL DEFAULT (0), "description" text, "output" text, "createdAt" datetime NOT NULL DEFAULT (datetime('now')), "updatedAt" datetime NOT NULL DEFAULT (datetime('now')))`,
);
await queryRunner.query(
`INSERT INTO "scenario_run_steps"("id", "runId", "scenarioStepId", "title", "execCode", "timeoutSeconds", "status", "order", "description", "output", "createdAt", "updatedAt") SELECT "id", "runId", "scenarioStepId", "title", "execCode", "timeoutSeconds", "status", "order", "description", "output", "createdAt", "updatedAt" FROM "temporary_scenario_run_steps"`,
);
await queryRunner.query(`DROP TABLE "temporary_scenario_run_steps"`);
await queryRunner.query(
`ALTER TABLE "scenario_files" RENAME TO "temporary_scenario_files"`,
);
await queryRunner.query(
`CREATE TABLE "scenario_files" ("id" varchar PRIMARY KEY NOT NULL, "scenarioId" varchar NOT NULL, "fileId" varchar NOT NULL, "createdAt" datetime NOT NULL DEFAULT (datetime('now')))`,
);
await queryRunner.query(
`INSERT INTO "scenario_files"("id", "scenarioId", "fileId", "createdAt") SELECT "id", "scenarioId", "fileId", "createdAt" FROM "temporary_scenario_files"`,
);
await queryRunner.query(`DROP TABLE "temporary_scenario_files"`);
await queryRunner.query(
`ALTER TABLE "scenarios" RENAME TO "temporary_scenarios"`,
);
await queryRunner.query(
`CREATE TABLE "scenarios" ("id" varchar PRIMARY KEY NOT NULL, "name" varchar NOT NULL, "description" text, "environmentId" varchar, "timeoutSeconds" integer, "version" integer NOT NULL DEFAULT (1), "createdAt" datetime NOT NULL DEFAULT (datetime('now')), "updatedAt" datetime NOT NULL DEFAULT (datetime('now')))`,
);
await queryRunner.query(
`INSERT INTO "scenarios"("id", "name", "description", "environmentId", "timeoutSeconds", "version", "createdAt", "updatedAt") SELECT "id", "name", "description", "environmentId", "timeoutSeconds", "version", "createdAt", "updatedAt" FROM "temporary_scenarios"`,
);
await queryRunner.query(`DROP TABLE "temporary_scenarios"`);
await queryRunner.query(
`ALTER TABLE "scenario_steps" RENAME TO "temporary_scenario_steps"`,
);
await queryRunner.query(
`CREATE TABLE "scenario_steps" ("id" varchar PRIMARY KEY NOT NULL, "scenarioId" varchar NOT NULL, "order" integer NOT NULL DEFAULT (0), "title" text, "execCode" text, "timeoutSeconds" integer, "createdAt" datetime NOT NULL DEFAULT (datetime('now')), "updatedAt" datetime NOT NULL DEFAULT (datetime('now')))`,
);
await queryRunner.query(
`INSERT INTO "scenario_steps"("id", "scenarioId", "order", "title", "execCode", "timeoutSeconds", "createdAt", "updatedAt") SELECT "id", "scenarioId", "order", "title", "execCode", "timeoutSeconds", "createdAt", "updatedAt" FROM "temporary_scenario_steps"`,
);
await queryRunner.query(`DROP TABLE "temporary_scenario_steps"`);
await queryRunner.query(
`ALTER TABLE "scenario_credentials" RENAME TO "temporary_scenario_credentials"`,
);
await queryRunner.query(
`CREATE TABLE "scenario_credentials" ("id" varchar PRIMARY KEY NOT NULL, "scenarioId" varchar NOT NULL, "credentialId" varchar NOT NULL, "alias" varchar NOT NULL, "createdAt" datetime NOT NULL DEFAULT (datetime('now')), CONSTRAINT "UQ_02756536236c408dbb58b3fc964" UNIQUE ("scenarioId", "alias"))`,
);
await queryRunner.query(
`INSERT INTO "scenario_credentials"("id", "scenarioId", "credentialId", "alias", "createdAt") SELECT "id", "scenarioId", "credentialId", "alias", "createdAt" FROM "temporary_scenario_credentials"`,
);
await queryRunner.query(`DROP TABLE "temporary_scenario_credentials"`);
await queryRunner.query(`DROP TABLE "snippet_versions"`);
await queryRunner.query(`DROP TABLE "snippets"`);
await queryRunner.query(`DROP TABLE "scenario_versions"`);
await queryRunner.query(`DROP TABLE "scenario_run_logs"`);
await queryRunner.query(`DROP TABLE "scenario_run_files"`);
await queryRunner.query(`DROP TABLE "scenario_runs"`);
await queryRunner.query(`DROP TABLE "scenario_run_steps"`);
await queryRunner.query(`DROP TABLE "sessions"`);
await queryRunner.query(`DROP TABLE "scenario_files"`);
await queryRunner.query(`DROP TABLE "scenarios"`);
await queryRunner.query(`DROP TABLE "scenario_steps"`);
await queryRunner.query(`DROP TABLE "scenario_credentials"`);
await queryRunner.query(`DROP TABLE "files"`);
await queryRunner.query(`DROP TABLE "environments"`);
await queryRunner.query(`DROP TABLE "credentials"`);
}
}
+7
View File
@@ -0,0 +1,7 @@
import { Initial1790793447827 } from "./1790793447827-Initial";
/**
* All migrations, oldest first. Listed explicitly (instead of a glob) so the
* same list works from compiled JS, ts-jest and the TypeORM CLI.
*/
export const MIGRATIONS = [Initial1790793447827];
+19 -1
View File
@@ -1,6 +1,7 @@
import { RequestMethod, ValidationPipe } from "@nestjs/common";
import { ConfigService } from "@nestjs/config";
import { NestFactory } from "@nestjs/core";
import { DataSource } from "typeorm";
import type { NestExpressApplication } from "@nestjs/platform-express";
import { DocumentBuilder, SwaggerModule } from "@nestjs/swagger";
import { AppModule } from "./app.module";
@@ -36,6 +37,15 @@ async function bootstrap() {
logger: new TraceLogger("Bootstrap", { timestamp: true }),
});
// The schema is managed by migrations; refuse to run against an outdated one.
// Checked before app.init(), i.e. before any module touches the tables.
if (await app.get(DataSource).showMigrations()) {
throw new Error(
"The database has pending migrations. Run `npm -w server run migration:run` " +
"(the Docker image runs them automatically before starting the server).",
);
}
app.setGlobalPrefix(API_PREFIX, {
exclude: [
{ path: "health", method: RequestMethod.ALL },
@@ -77,4 +87,12 @@ async function bootstrap() {
logger.log(`MCP endpoint available at http://localhost:${port}/mcp`);
}
bootstrap();
// Startup failures (pending migrations, port in use, ...) must stop the
// process with an error code; the handlers above only keep a running server alive
bootstrap().catch((err: unknown) => {
processLogger.error(
`Startup failed: ${err instanceof Error ? err.message : String(err)}`,
err instanceof Error ? err.stack : undefined,
);
process.exit(1);
});
+4 -35
View File
@@ -9,6 +9,7 @@ import type { NestExpressApplication } from "@nestjs/platform-express";
import { ScheduleModule } from "@nestjs/schedule";
import { configureBodyParsers } from "../src/common/body-parsers";
import { dataSourceOptions } from "../src/database/data-source";
import { ImportModule } from "../src/import/import.module";
jest.mock("@nestjs/common", () => {
@@ -42,25 +43,10 @@ import { SessionModule } from "../src/session/session.module";
import { EnvironmentModule } from "../src/environment/environment.module";
import { ScenarioModule } from "../src/scenario/scenario.module";
import { McpModule } from "../src/mcp/mcp.module";
import { SessionEntity } from "../src/session/session.entity";
import { EnvironmentEntity } from "../src/environment/environment.entity";
import { ScenarioEntity } from "../src/scenario/scenario.entity";
import { ScenarioStepEntity } from "../src/scenario/scenario-step.entity";
import { ScenarioVersionEntity } from "../src/scenario/scenario-version.entity";
import { SnippetVersionEntity } from "../src/snippet/snippet-version.entity";
import { ScenarioRunEntity } from "../src/scenario/scenario-run.entity";
import { ScenarioRunStepEntity } from "../src/scenario/scenario-run-step.entity";
import { ScenarioRunLogEntity } from "../src/scenario/scenario-run-log.entity";
import { ScenarioCredentialEntity } from "../src/scenario/scenario-credential.entity";
import { CredentialEntity } from "../src/credential/credential.entity";
import { SnippetEntity } from "../src/snippet/snippet.entity";
import { HealthController } from "../src/health/health.controller";
import { HttpExceptionFilter } from "../src/filters/http-exception.filter";
import { LoggingInterceptor } from "../src/interceptors/logging.interceptor";
import { validateAppConfig } from "../src/config/app.config";
import { FileEntity } from "../src/file/file.entity";
import { ScenarioFileEntity } from "../src/file/scenario-file.entity";
import { ScenarioRunFileEntity } from "../src/file/scenario-run-file.entity";
export async function buildTestApp(): Promise<INestApplication> {
// Each test app stores files in its own temp dir: suites run in parallel and
@@ -75,27 +61,10 @@ export async function buildTestApp(): Promise<INestApplication> {
ignoreEnvFile: true,
validate: validateAppConfig,
}),
// The real migrations, not synchronize, so tests use the schema production gets
TypeOrmModule.forRoot({
type: "better-sqlite3",
database: ":memory:",
entities: [
SessionEntity,
EnvironmentEntity,
ScenarioEntity,
ScenarioStepEntity,
ScenarioVersionEntity,
ScenarioRunEntity,
ScenarioRunStepEntity,
ScenarioRunLogEntity,
ScenarioCredentialEntity,
CredentialEntity,
SnippetEntity,
SnippetVersionEntity,
FileEntity,
ScenarioFileEntity,
ScenarioRunFileEntity,
],
synchronize: true,
...dataSourceOptions(":memory:"),
migrationsRun: true,
}),
ScheduleModule.forRoot(),
BrowserModule,
+65
View File
@@ -0,0 +1,65 @@
/**
* The schema is managed by migrations. These tests fail when an entity
* changes without a matching migration, and cover adopting databases that
* were created by `synchronize` before migrations existed.
*/
import { DataSource } from "typeorm";
import { dataSourceOptions } from "../src/database/data-source";
import { MIGRATIONS } from "../src/database/migrations";
async function pendingSchemaChanges(dataSource: DataSource): Promise<string[]> {
const sql = await dataSource.driver.createSchemaBuilder().log();
return sql.upQueries.map((q) => q.query);
}
describe("Database migrations", () => {
it("migrations produce exactly the schema the entities describe", async () => {
const dataSource = new DataSource(dataSourceOptions(":memory:"));
await dataSource.initialize();
try {
await dataSource.runMigrations();
expect(await dataSource.showMigrations()).toBe(false);
// If this fails, generate a migration: see "Database migrations" in docs/development.md
expect(await pendingSchemaChanges(dataSource)).toEqual([]);
} finally {
await dataSource.destroy();
}
});
it("adopts a database created by synchronize", async () => {
const dataSource = new DataSource({
...dataSourceOptions(":memory:"),
synchronize: true,
});
await dataSource.initialize();
try {
await dataSource.query(
`INSERT INTO scenarios (id, name, version) VALUES ('11111111-1111-4111-8111-111111111111', 'kept', 1)`,
);
const applied = await dataSource.runMigrations();
expect(applied.map((m) => m.name)).toEqual(MIGRATIONS.map((m) => m.name));
expect(await dataSource.showMigrations()).toBe(false);
expect(await pendingSchemaChanges(dataSource)).toEqual([]);
const [row] = await dataSource.query(`SELECT name FROM scenarios`);
expect(row.name).toBe("kept");
} finally {
await dataSource.destroy();
}
});
it("can revert the initial migration", async () => {
const dataSource = new DataSource(dataSourceOptions(":memory:"));
await dataSource.initialize();
try {
await dataSource.runMigrations();
await dataSource.undoLastMigration();
const tables = await dataSource.query(
`SELECT name FROM sqlite_master WHERE type = 'table' AND name NOT IN ('migrations', 'sqlite_sequence')`,
);
expect(tables).toEqual([]);
} finally {
await dataSource.destroy();
}
});
});