* ui : move Models, MCP and Settings to a sidebar footer The sidebar's actions split in two: New chat, Search and Projects stay at its top, and Models, MCP and Settings move to a footer at its bottom, under a thin rule, in the expanded sidebar and its collapsed strip alike. On a phone the footer keeps clear of the home indicator, and Models stays desktop-only as before. The search dialog still lists every action. Assisted-by: Claude (Opus 5.5 Medium) * ui : group the sidebar footer in an inset surface The design system gains inset-group-surface, for rows grouped inside a glass panel: white on the light glass and a faint tint of the text colour on the dark one, with the sidebar's own ambient edge, no inner highlight, a faint wide shade under it and the card radius. It is matte-glass pointed at its own component tokens, like the sidebar and chat form surfaces, and reads as part of the panel: no tight contact shadow or solid border like a button, no inset shade like a field. The sidebar footer uses it in place of the rule above Models, MCP and Settings. DESIGN.md and the Surfaces page document it. Assisted-by: Claude (Opus 5.5 Medium) * ui : give the sidebar's logo button the add button's key look Whenever the sidebar shows, open or peeking, its logo button takes the same key as the chat form's add button (matte-key, white in light mode, a light tint in dark), in place of its own muted fill. While the sidebar is hidden the logo has no fill and no shadow, and hover and focus never change the fill. It keeps its round shape and its own size. Assisted-by: Claude (Opus 5.5 Medium) * ui : put search in a round key at the top of the phone sidebar On a phone the sidebar's Search row moves to a round key at the right end of its top row, across from the logo, with the same key look as the logo and the chat form's add button. It opens search as the row did. Desktop keeps the Search row. Assisted-by: Claude (Opus 5.5 Medium) * ui : size the phone sidebar for a thumb and list its footer with the actions On a phone the sidebar's actions and rows are 48px tall at 17px, flush one under the other with 16px corners, its section headings 15px and grey, and its groups 28px apart. MCP and Settings join the top actions there: the footer is a desktop pattern. Assisted-by: Claude (Opus 5.5 Medium) * ui : mark the selected sidebar row with a tinted inset surface Assisted-by: Claude (Opus 5.5 Medium) * ui: keep the phone sidebar's round keys white on the grey page Assisted-by: Claude (Opus 5.5 Medium) * ui : open Settings and MCP as pages on a phone, dialogs elsewhere On a phone the sidebar opens them at #/settings and #/mcp-servers, with the menu key and a title like any phone page. Pinned under the status bar, Settings' section tabs fill the screen above them in the page's colour. Assisted-by: Claude (Opus 5.5 Medium) * ui : open a phone sidebar's pages behind it, settled before they slide back A tap in the phone sidebar now opens its page while the current one is still aside and slides back once it has rendered, instead of swapping pages mid-slide. The slid page's fixed bars are pinned again as the page under them changes, the lock ends with the slide itself, and a phone's new chat shows its form and greeting at once, without the move and entry they have on a desktop. Assisted-by: Claude (Opus 5.5 Medium) * ui: style the sidebar footer group and the selected row with master's classes until the design system lands Assisted-by: Claude (Opus 5.5 Medium) * ui: add GlassKey with master's styles for the phone sidebar's round keys Assisted-by: Claude (Opus 5.5 Medium) * ui: center the top edge of a new chat's form on the screen The form rested 42px below the middle up to 2xl and 6px above it past that; one drop, from the resting card's height, now puts its top edge on the middle at every width from md up. Assisted-by: Claude (Opus 5.5 Medium) * ui: round the sidebar's action rows concentric with the footer group The sidebar stacks four surfaces: the page, the sidebar, the footer group inset in it and a row in the group. app.css now names the group's radius and padding, and derives the row radius from them (16px less 4px), so the footer's rows run parallel to its corners; the actions at the top of the sidebar share that radius. The footer moves to its own component, the README documents the pattern, and a client test holds the rule on the rendered footer. A selected action row was bg-accent, the same grey as a hovered row in light and darker than the footer's fill in dark, so it read as hovered or not at all; it is now raised and edged, while a hover only tints. Assisted-by: Claude (Opus 5.5 Medium) * ui: import demo chats through the Settings page on a phone A phone opens Settings as a page now, not a dialog, so the demo harness waited for a dialog that never came and every phone demo with traces failed; it now imports through whichever of the two opens. Assisted-by: Claude (Opus 5.5 Medium) * ui: count the sidebar's rows from their items in the surface test The test expected three footer rows and two top actions, which the stacked PRs change as they add Projects, Library and Servers; it now expects as many rows as the sidebar has items. Assisted-by: Claude (Opus 5.5 Medium) * ui: add a line on Meta+Enter off macOS too The chat form takes Meta+Enter as Ctrl+Enter and leaves the newline to the editor, but the editor bound only Mod-Enter, which is Ctrl off macOS, so on Linux Meta+Enter neither sent nor added a line. This failed the client test on CI's Linux runners, on master too. Assisted-by: Claude (Opus 5.5 Medium)
512 lines
17 KiB
TypeScript
512 lines
17 KiB
TypeScript
import { demoMcpServerSettings } from './fixtures/demo-config.ts';
|
|
import { generateTrace } from './fixtures/traces.ts';
|
|
import { ScreencastRecorder } from './recorder.ts';
|
|
import { type CDPSession, type Locator, type Page, test as base } from '@playwright/test';
|
|
import { execFileSync } from 'node:child_process';
|
|
import { appendFileSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
import { basename, join, resolve } from 'node:path';
|
|
|
|
const VIDEOS_DIR = resolve(import.meta.dirname, 'videos');
|
|
/** How long a demo waits for the app to be ready before it starts recording. */
|
|
const APP_READY_TIMEOUT_MS = 90000;
|
|
/** How far below the viewport's top a pinch has to start for Chromium to zoom at all. */
|
|
const ZOOM_TOP_INSET_PX = 64;
|
|
|
|
/**
|
|
* Draws a fake cursor and click ripples, since recorded videos don't include
|
|
* the OS pointer, and a fingertip per touch, so a pinch shows as two fingers.
|
|
* Runs in the page via addInitScript.
|
|
*/
|
|
function installCursorOverlay(): void {
|
|
const mount = () => {
|
|
const style = document.createElement('style');
|
|
|
|
style.textContent = `
|
|
#demo-cursor { position: fixed; top: 0; left: 0; z-index: 2147483647; pointer-events: none;
|
|
width: 22px; height: 22px; margin: -3px 0 0 -3px; transition: transform 80ms ease-out; }
|
|
#demo-cursor.down { transform: scale(0.85); }
|
|
.demo-ripple { position: fixed; z-index: 2147483646; pointer-events: none; width: 36px; height: 36px;
|
|
margin: -18px 0 0 -18px; border-radius: 50%; background: rgba(59, 130, 246, 0.35);
|
|
animation: demo-ripple 450ms ease-out forwards; }
|
|
@keyframes demo-ripple { from { transform: scale(0.3); opacity: 1; } to { transform: scale(1.4); opacity: 0; } }
|
|
#demo-caption { position: fixed; left: 50%; top: 72px; z-index: 2147483647; pointer-events: none;
|
|
transform: translate(-50%, -8px); opacity: 0; transition: opacity 200ms ease, transform 200ms ease;
|
|
max-width: 80%; padding: 10px 18px; border-radius: 10px; background: rgba(17, 17, 17, 0.88);
|
|
color: #fff; font: 500 18px/1.4 system-ui, sans-serif; text-align: center; }
|
|
#demo-caption.visible { opacity: 1; transform: translate(-50%, 0); }
|
|
.demo-finger { position: fixed; z-index: 2147483646; pointer-events: none; width: 40px; height: 40px;
|
|
margin: -20px 0 0 -20px; border-radius: 50%; background: rgba(59, 130, 246, 0.3);
|
|
border: 2px solid rgba(59, 130, 246, 0.55); transition: opacity 200ms ease; }
|
|
`;
|
|
document.head.appendChild(style);
|
|
|
|
const cursor = document.createElement('div');
|
|
|
|
cursor.id = 'demo-cursor';
|
|
cursor.innerHTML = `<svg viewBox="0 0 24 24" width="22" height="22"><path d="M4 2l16 10.5-7 1.5-3.5 6.5z"
|
|
fill="#111" stroke="#fff" stroke-width="1.5" stroke-linejoin="round"/></svg>`;
|
|
document.documentElement.appendChild(cursor);
|
|
|
|
const caption = document.createElement('div');
|
|
|
|
caption.id = 'demo-caption';
|
|
document.documentElement.appendChild(caption);
|
|
|
|
document.addEventListener(
|
|
'mousemove',
|
|
(e) => (cursor.style.translate = `${e.clientX}px ${e.clientY}px`),
|
|
true
|
|
);
|
|
document.addEventListener(
|
|
'mousedown',
|
|
(e) => {
|
|
cursor.classList.add('down');
|
|
const ripple = document.createElement('div');
|
|
|
|
ripple.className = 'demo-ripple';
|
|
ripple.style.left = `${e.clientX}px`;
|
|
ripple.style.top = `${e.clientY}px`;
|
|
document.documentElement.appendChild(ripple);
|
|
setTimeout(() => ripple.remove(), 500);
|
|
},
|
|
true
|
|
);
|
|
document.addEventListener('mouseup', () => cursor.classList.remove('down'), true);
|
|
|
|
const fingers: HTMLDivElement[] = [];
|
|
const placeFingers = (e: TouchEvent) => {
|
|
Array.from(e.touches).forEach((touch, i) => {
|
|
const finger = (fingers[i] ??= Object.assign(document.createElement('div'), {
|
|
className: 'demo-finger'
|
|
}));
|
|
|
|
finger.style.left = `${touch.clientX}px`;
|
|
finger.style.top = `${touch.clientY}px`;
|
|
finger.style.opacity = '1';
|
|
document.documentElement.appendChild(finger);
|
|
});
|
|
fingers.slice(e.touches.length).forEach((finger) => (finger.style.opacity = '0'));
|
|
};
|
|
|
|
for (const type of ['touchstart', 'touchmove', 'touchend', 'touchcancel']) {
|
|
document.addEventListener(type, placeFingers as EventListener, {
|
|
capture: true,
|
|
passive: true
|
|
});
|
|
}
|
|
};
|
|
|
|
if (document.readyState === 'loading') {
|
|
document.addEventListener('DOMContentLoaded', mount);
|
|
} else {
|
|
mount();
|
|
}
|
|
}
|
|
|
|
/** Seeds UI settings once per demo, so later reloads keep what the demo changed. */
|
|
function seedSettings(config: Record<string, unknown>): void {
|
|
const key = 'LlamaUi.config';
|
|
|
|
if (localStorage.getItem(key) === null) {
|
|
localStorage.setItem(key, JSON.stringify(config));
|
|
}
|
|
}
|
|
|
|
/** Seeded randomness, so a demo moves the same way on every recording. */
|
|
function createRandom(seed: string): () => number {
|
|
let state = [...seed].reduce((h, c) => Math.imul(h ^ c.charCodeAt(0), 2654435761), 1);
|
|
|
|
return () => {
|
|
state = (state + 0x6d2b79f5) | 0;
|
|
|
|
let t = Math.imul(state ^ (state >>> 15), 1 | state);
|
|
|
|
t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t;
|
|
|
|
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
|
|
};
|
|
}
|
|
|
|
const easeInOut = (t: number) => (t < 0.5 ? 4 * t * t * t : 1 - (-2 * t + 2) ** 3 / 2);
|
|
|
|
/**
|
|
* Drives the page like a person: the cursor glides along a slight arc with
|
|
* Fitts-like durations, settles briefly before pressing, and typing and pauses
|
|
* vary a little.
|
|
*/
|
|
export class Demo {
|
|
private cdp: CDPSession | undefined;
|
|
private readonly page: Page;
|
|
private readonly random: () => number;
|
|
private x = 0;
|
|
private y = 0;
|
|
|
|
/** Shows a caption at the top of the frame for `ms`, clear of the chat form. */
|
|
async caption(text: string, ms = 2200): Promise<void> {
|
|
await this.page.evaluate((t) => {
|
|
const el = document.getElementById('demo-caption');
|
|
|
|
if (!el) return;
|
|
|
|
el.textContent = t;
|
|
el.classList.add('visible');
|
|
}, text);
|
|
await this.page.waitForTimeout(ms);
|
|
await this.page.evaluate(() =>
|
|
document.getElementById('demo-caption')?.classList.remove('visible')
|
|
);
|
|
await this.page.waitForTimeout(250);
|
|
}
|
|
|
|
async click(target: Locator, ms = 400): Promise<void> {
|
|
await this.moveTo(target);
|
|
await this.page.waitForTimeout(this.between(80, 160));
|
|
await this.page.mouse.down();
|
|
await this.page.waitForTimeout(this.between(50, 90));
|
|
await this.page.mouse.up();
|
|
await this.pause(ms);
|
|
}
|
|
|
|
constructor(page: Page, seed: string) {
|
|
this.page = page;
|
|
this.random = createRandom(seed);
|
|
|
|
const viewport = page.viewportSize();
|
|
|
|
this.x = (viewport?.width ?? 0) / 2;
|
|
this.y = (viewport?.height ?? 0) / 2;
|
|
}
|
|
|
|
async hover(target: Locator, ms = 350): Promise<void> {
|
|
await this.moveTo(target);
|
|
await this.pause(ms);
|
|
}
|
|
|
|
/** Glides the cursor to a point near the center of `target`. */
|
|
async moveTo(target: Locator): Promise<void> {
|
|
await target.scrollIntoViewIfNeeded();
|
|
const box = await target.boundingBox();
|
|
|
|
if (!box) throw new Error(`demo: ${target} has no bounding box`);
|
|
|
|
const x = box.x + box.width * this.between(0.4, 0.6);
|
|
const y = box.y + box.height * this.between(0.4, 0.6);
|
|
const dx = x - this.x;
|
|
const dy = y - this.y;
|
|
const distance = Math.hypot(dx, dy);
|
|
const duration = 110 + 55 * Math.log2(distance / 40 + 1);
|
|
// bow the path a little to one side, like a wrist turning
|
|
const bow = distance * this.between(-0.08, 0.08);
|
|
const fromX = this.x;
|
|
const fromY = this.y;
|
|
const started = Date.now();
|
|
|
|
for (;;) {
|
|
const t = Math.min((Date.now() - started) / duration, 1);
|
|
const p = easeInOut(t);
|
|
const arc = Math.sin(Math.PI * p) * bow;
|
|
|
|
this.x = fromX + dx * p - (dy / (distance || 1)) * arc;
|
|
this.y = fromY + dy * p + (dx / (distance || 1)) * arc;
|
|
await this.page.mouse.move(this.x, this.y);
|
|
|
|
if (t === 1) break;
|
|
|
|
await this.page.waitForTimeout(8);
|
|
}
|
|
}
|
|
|
|
/** Waits about `ms`, varied by up to 15% so pauses don't feel metronomic. */
|
|
async pause(ms = 800): Promise<void> {
|
|
await this.page.waitForTimeout(ms * this.between(0.85, 1.15));
|
|
}
|
|
|
|
async press(key: string, ms = 600): Promise<void> {
|
|
await this.page.keyboard.press(key);
|
|
await this.pause(ms);
|
|
}
|
|
|
|
/** Scrolls the wheel over `target` by `dy` pixels (negative scrolls up), in small steps like a trackpad. */
|
|
async scroll(target: Locator, dy: number, ms = 500): Promise<void> {
|
|
await this.moveTo(target);
|
|
|
|
const step = Math.sign(dy) * 40;
|
|
|
|
for (let done = 0; Math.abs(done) < Math.abs(dy); done += step) {
|
|
await this.page.mouse.wheel(0, step);
|
|
await this.page.waitForTimeout(16);
|
|
}
|
|
|
|
await this.pause(ms);
|
|
}
|
|
|
|
/** Types quickly with uneven key timing, a little slower after spaces and punctuation. */
|
|
async type(target: Locator, text: string, ms = 500): Promise<void> {
|
|
await this.click(target, 200);
|
|
|
|
for (const char of text) {
|
|
await this.page.keyboard.type(char);
|
|
await this.page.waitForTimeout(
|
|
this.between(15, 45) + (/[\s.,!?]/.test(char) ? this.between(20, 60) : 0)
|
|
);
|
|
}
|
|
|
|
await this.pause(ms);
|
|
}
|
|
|
|
/**
|
|
* Pinches in on `target`, a control or a point in the viewport, holds about `ms`, and pinches
|
|
* back out to 1x: a two-finger zoom onto a detail too small to read in the frame. On a touch
|
|
* device the fingertips show.
|
|
*/
|
|
async zoom(target: Locator | { x: number; y: number }, scale = 2.5, ms = 1400): Promise<void> {
|
|
const point = 'x' in target ? target : await this.center(target);
|
|
// a pinch anchored in the viewport's top band does not zoom at all
|
|
const at = { x: point.x, y: Math.max(point.y, ZOOM_TOP_INSET_PX) };
|
|
const viewport = this.page.viewportSize() ?? { height: 0, width: 0 };
|
|
const middle = { x: viewport.width / 2, y: viewport.height / 2 };
|
|
|
|
await this.pinch(at, scale, 1400);
|
|
|
|
// One near the bottom edge overshoots its ratio, and a pinch there again misses too. A small
|
|
// pinch from the middle evens it out, drawing the detail toward the middle, so it stays in view
|
|
const reached = await this.pageScale();
|
|
|
|
if (Math.abs(reached / scale - 1) > 0.03) await this.pinch(middle, scale / reached, 1400);
|
|
|
|
await this.liftFingers();
|
|
await this.pause(ms);
|
|
|
|
// back to exactly 1x, which the next gesture needs, in one quick pinch from the middle of
|
|
// the viewport, and another for what is left when one lands short
|
|
for (let tries = 0; ; tries++) {
|
|
const current = await this.pageScale();
|
|
|
|
if (current <= 1.001) break;
|
|
|
|
if (tries === 4) throw new Error(`demo: zoom stuck at ${current.toFixed(3)}x`);
|
|
|
|
await this.pinch(middle, 1 / current, 1800);
|
|
}
|
|
|
|
await this.liftFingers();
|
|
await this.pause(200);
|
|
}
|
|
|
|
private between(min: number, max: number): number {
|
|
return min + (max - min) * this.random();
|
|
}
|
|
|
|
private async center(target: Locator): Promise<{ x: number; y: number }> {
|
|
const box = await target.boundingBox();
|
|
|
|
if (!box) throw new Error(`demo: ${target} has no bounding box`);
|
|
|
|
return { x: box.x + box.width / 2, y: box.y + box.height / 2 };
|
|
}
|
|
|
|
/** A pinch that reaches the screen's edge can end without its last touchend reaching the page. */
|
|
private async liftFingers(): Promise<void> {
|
|
await this.page.evaluate(() =>
|
|
document
|
|
.querySelectorAll<HTMLElement>('.demo-finger')
|
|
.forEach((finger) => (finger.style.opacity = '0'))
|
|
);
|
|
}
|
|
|
|
private pageScale(): Promise<number> {
|
|
return this.page.evaluate(() => window.visualViewport?.scale ?? 1);
|
|
}
|
|
|
|
/**
|
|
* A two-finger pinch by `factor` around `at`, in viewport pixels. While zoomed in, the gesture
|
|
* reads its position in page-scale units, so it is divided by the scale the page is at.
|
|
*/
|
|
private async pinch(at: { x: number; y: number }, factor: number, speed: number): Promise<void> {
|
|
const cdp = await this.session();
|
|
const current = await this.pageScale();
|
|
|
|
await cdp.send('Input.synthesizePinchGesture', {
|
|
gestureSourceType: 'touch',
|
|
relativeSpeed: speed,
|
|
scaleFactor: factor,
|
|
x: at.x / current,
|
|
y: at.y / current
|
|
});
|
|
}
|
|
|
|
private async session(): Promise<CDPSession> {
|
|
this.cdp ??= await this.page.context().newCDPSession(this.page);
|
|
|
|
return this.cdp;
|
|
}
|
|
}
|
|
|
|
interface DemoOptions {
|
|
/** Path the demo starts from. */
|
|
startPath: string;
|
|
/** Extra UI settings merged into the seeded config. */
|
|
settings: Record<string, unknown>;
|
|
/**
|
|
* Conversations imported before the demo starts: built-in traces from
|
|
* fixtures/traces.ts, or `<name>.jsonl` files from DEMO_TRACES_DATASET.
|
|
*/
|
|
traces: string[];
|
|
}
|
|
|
|
/** Reads a trace by name, generating built-in ones and downloading the rest. */
|
|
function loadTrace(name: string, dir: string): string {
|
|
const generated = generateTrace(name);
|
|
|
|
if (generated) return generated;
|
|
|
|
const dataset = process.env.DEMO_TRACES_DATASET;
|
|
|
|
if (!dataset)
|
|
throw new Error(`demo: no built-in trace "${name}" and DEMO_TRACES_DATASET is not set`);
|
|
|
|
execFileSync(
|
|
'hf',
|
|
['download', dataset, `${name}.jsonl`, '--repo-type', 'dataset', '--local-dir', dir],
|
|
{ stdio: 'inherit' }
|
|
);
|
|
|
|
return readFileSync(join(dir, `${name}.jsonl`), 'utf8');
|
|
}
|
|
|
|
/** Imports conversations through Settings > Import/Export, like a user would. */
|
|
async function importTraces(page: Page, file: string): Promise<void> {
|
|
// the expanded sidebar adds the shortcut to the name
|
|
const settings = page.getByRole('button', { name: /^Settings(\s|$)/ }).first();
|
|
const reachable = (target: Locator) =>
|
|
target.click({ timeout: 2000, trial: true }).then(
|
|
() => true,
|
|
() => false
|
|
);
|
|
// a collapsed sidebar can sit under the page: on a phone the page's menu key slides it aside,
|
|
// on a desktop its logo expands it
|
|
const keys = [
|
|
page.locator('xpath=//button[@aria-label="Expand navigation"][not(ancestor::aside)]'),
|
|
page.locator('aside button[aria-label="Expand navigation"]')
|
|
];
|
|
|
|
// a few rounds, as a cold dev server reloads the page once it has optimized its dependencies,
|
|
// which can land right after a key opened the sidebar and close it again
|
|
for (let round = 0; round < 3 && !(await reachable(settings)); round++) {
|
|
for (const key of keys) {
|
|
if (await reachable(settings)) break;
|
|
|
|
if ((await key.count()) > 0 && (await reachable(key.first()))) await key.first().click();
|
|
}
|
|
}
|
|
|
|
await settings.click();
|
|
|
|
// a dialog on a desktop or tablet, a page of its own on a phone
|
|
const settingsView = page
|
|
.getByRole('dialog')
|
|
.or(page.getByRole('heading', { exact: true, level: 1, name: 'Settings' }));
|
|
|
|
await settingsView.first().waitFor();
|
|
|
|
const scope = (await page.getByRole('dialog').count()) > 0 ? page.getByRole('dialog') : page;
|
|
|
|
await scope.getByText('Import/Export', { exact: true }).filter({ visible: true }).click();
|
|
|
|
const chooser = page.waitForEvent('filechooser');
|
|
|
|
await scope.getByRole('button', { name: 'Import conversations' }).click();
|
|
await (await chooser).setFiles(file);
|
|
await page.getByRole('button', { name: /^Import \(\d+\)$/ }).click();
|
|
await page.getByRole('heading', { name: /^Imported \d+ conversation/ }).waitFor();
|
|
|
|
// the app remembers the sidebar the import expanded; a demo starts with it collapsed, as on a
|
|
// first visit
|
|
await page.evaluate(() => {
|
|
for (const key of Object.keys(localStorage)) {
|
|
if (key.endsWith('.sidebarExpanded')) localStorage.removeItem(key);
|
|
}
|
|
});
|
|
}
|
|
|
|
export const test = base.extend<DemoOptions & { demo: Demo }>({
|
|
demo: async ({ page }, use, testInfo) => {
|
|
await use(new Demo(page, `${testInfo.file}:${testInfo.title}`));
|
|
},
|
|
page: async ({ page, settings, startPath, traces }, use, testInfo) => {
|
|
await page.addInitScript(installCursorOverlay);
|
|
await page.addInitScript(seedSettings, {
|
|
mcpServers: JSON.stringify(demoMcpServerSettings()),
|
|
...settings
|
|
});
|
|
|
|
if (traces.length > 0) {
|
|
const dir = testInfo.outputPath('traces');
|
|
const file = join(dir, 'import.jsonl');
|
|
|
|
mkdirSync(dir, { recursive: true });
|
|
writeFileSync(file, traces.map((name) => loadTrace(name, dir)).join('\n'));
|
|
await page.goto('/');
|
|
await page
|
|
.getByRole('textbox', { name: 'Type a message...' })
|
|
.waitFor({ timeout: APP_READY_TIMEOUT_MS });
|
|
await importTraces(page, file);
|
|
}
|
|
|
|
await page.goto(startPath);
|
|
|
|
// a hash route after the import doesn't reload, which the conversations list needs
|
|
if (traces.length > 0) await page.reload();
|
|
|
|
// a fresh checkout's dev server optimizes its dependencies on the first load and reloads the
|
|
// page, which can take well past an action's timeout; the recording has not started yet
|
|
await page
|
|
.getByRole('textbox', { name: 'Type a message...' })
|
|
.waitFor({ timeout: APP_READY_TIMEOUT_MS });
|
|
|
|
const viewport = page.viewportSize();
|
|
|
|
if (viewport) await page.mouse.move(viewport.width / 2, viewport.height / 2);
|
|
|
|
// let MCP connections and fonts settle before the recording starts
|
|
await page.waitForTimeout(1500);
|
|
|
|
const recorder = new ScreencastRecorder(testInfo.outputPath('frames'));
|
|
|
|
await recorder.start(page);
|
|
await use(page);
|
|
await recorder.stop();
|
|
await page.close();
|
|
|
|
if (testInfo.status !== testInfo.expectedStatus) return;
|
|
|
|
const file = basename(testInfo.file).replace(/\.demo\.ts$/, '');
|
|
const name = testInfo.title === 'demo' ? file : `${file}--${slugify(testInfo.title)}`;
|
|
const mp4 = resolve(VIDEOS_DIR, `${name}.mp4`);
|
|
|
|
mkdirSync(VIDEOS_DIR, { recursive: true });
|
|
recorder.encode(mp4);
|
|
// the CLI reads which videos a script made, in order, with their titles
|
|
appendFileSync(
|
|
resolve(VIDEOS_DIR, `${file}.videos.jsonl`),
|
|
`${JSON.stringify({ mp4, title: testInfo.title })}\n`
|
|
);
|
|
console.log(`demo video: ${mp4}`);
|
|
},
|
|
|
|
settings: [{}, { option: true }],
|
|
|
|
startPath: ['/', { option: true }],
|
|
|
|
traces: [[], { option: true }]
|
|
});
|
|
|
|
export { expect } from '@playwright/test';
|
|
|
|
function slugify(text: string): string {
|
|
return text
|
|
.toLowerCase()
|
|
.replace(/[^a-z0-9]+/g, '-')
|
|
.replace(/^-|-$/g, '');
|
|
}
|