The all-in-one local AI studio for your desktop: chat, image and video generation and a coding agent in one free, open source app. Windows and Linux. No Docker, no terminal, no cloud required.
TypeScript agentai-chatai-studioall-in-onecoding-agentdesktop-appfluximage-generationlinuxllmlocal-ailocal-llmopen-sourceprivacyself-hostedstable-diffusionuncensoreduncensored-aivideo-generationwindows
import { test, expect, type Page } from '@playwright/test'
import { tauriMockInit, DEFAULT_ASSISTANT_REPLY, DEFAULT_MODEL_NAME, type TauriMockOptions } from './support/tauri-mock'
import { routeCloud, seedOnboardingDone, cloudSwitch } from './support/cloud-mock'
import { mlxCalls, comfyCalls } from './support/recorded'
import { openCharacterTraining } from './support/character-hub'
/**
* Character training on a Mac (src-tauri/src/commands/mlx_train.rs,
* src/api/mlx-train.ts).
*
* Until 3.0.8 the Train tab of Character Studio on a Mac only said that
* training does not run there. With the MLX image engine and Z-Image Turbo
* it trains: the photos of the board, the trigger word and the steps go to
* Rust, the run reports its steps, Stop ends it, and the character lands in
* the Mac's LoRA folder, where the Use shelf lists it. The Windows trainer
* (start_character_training) is never called on a Mac.
*/
const MAC: TauriMockOptions = { assistantReply: DEFAULT_ASSISTANT_REPLY, modelName: DEFAULT_MODEL_NAME, platform: 'mac' }
const ZIMAGE_MAC: TauriMockOptions = { ...MAC, mlx: { engineInstalled: true, mfluxEngineInstalled: true, installedImages: ['z-image-turbo-4bit'] } }
// A real picture, one pixel wide: the board decodes what it is handed.
const ONE_PIXEL_PNG = Buffer.from(
'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z8BQDwAEhQGAhKmMIQAAAABJRU5ErkJggg==',
'base64',
)
async function openTrainTab(page: Page, opts: TauriMockOptions) {
await page.addInitScript(tauriMockInit, opts)
await seedOnboardingDone(page)
await routeCloud(page, { license: 'active', access: true, mediaLive: true })
await page.setViewportSize({ width: 1440, height: 900 })
await page.goto('/')
await expect(cloudSwitch(page)).toBeVisible({ timeout: 20_000 })
await page.getByRole('button', { name: /^Create$/ }).click()
await openCharacterTraining(page)
}
async function addPhotos(page: Page, n: number) {
const files = Array.from({ length: n }, (_, i) => ({ name: `photo-${i}.png`, mimeType: 'image/png', buffer: ONE_PIXEL_PNG }))
await page.locator('input[type="file"][accept="image/*"]').first().setInputFiles(files)
}
// One second of a 64x64 test pattern, VP8 in WebM: the clip of
// create-save-character.spec.ts, so the frames are real decoded pictures.
const CLIP = Buffer.from('GkXfo59ChoEBQveBAULygQRC84EIQoKEd2VibUKHgQJChYECGFOAZwEAAAAAAAw2EU2bdLpNu4tTq4QVSalmU6yBoU27i1OrhBZUrmtTrIHYTbuMU6uEElTDZ1OsggElTbuMU6uEHFO7a1Osggwg7AEAAAAAAABZAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAVSalmsirXsYMPQkBNgI1MYXZmNjIuMTIuMTAyV0GNTGF2ZjYyLjEyLjEwMkSJiECPQAAAAAAAFlSua8iuAQAAAAAAAD/XgQFzxYjedgJYAgf9DZyBACK1nIN1bmSIgQCGhVZfVlA4g4EBI+ODhAvrwgDgkLCBQLqBQJqBAlWwhFW5gQESVMNn/HNzoGPAgGfImkWjh0VOQ09ERVJEh41MYXZmNjIuMTIuMTAyc3PWY8CLY8WI3nYCWAIH/Q1nyKFFo4dFTkNPREVSRIeUTGF2YzYyLjI4LjEwMiBsaWJ2cHhnyKFFo4hEVVJBVElPTkSHkzAwOjAwOjAxLjAwMDAwMDAwMAAfQ7Z1SnTngQCjRU+BAACAMCEAnQEqQABAAABHCIWFiIWEiAICAnW6JQs+gfhX+zX9y+Qmmvwf7O/pTyQ5aOjj5D+Fv+A///w5/0vSA/op/SfxS7QPmB/in8g/pP+A9+L0A+gD/Lv4DwAP7Aejd/2P738An6t/5j/IfAJ/JP5L8/HKA9gp/FfwX9mfbj8s/Dz9u+nC9Oc4b9YvrP48fkB7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nsgAFvIFs6TQU77QaZqkhjMwIepJo3uJLUt9Apt8MYPQMrfrr5Da18lCGD80XVU7ZIB5xGGfMayFW2AAQkmMjmUyxc8kX8kT8+Ntb6L2J0XphewTXQAFj7DQRDHRAAcU7trkbuPs4EAt4r3gQHxggGm8IED', 'base64')
const VIDEO_ITEM = {
id: 'mac-video-1', type: 'video', filename: '', subfolder: '', localPath: '/tmp/lu-e2e/mlx-video/clip.webm', prompt: 'a red fox on a hill',
negativePrompt: '', model: 'ltx-2.3', modelType: 'ltx', seed: 7, steps: 8, cfgScale: 1, sampler: '', scheduler: '',
width: 64, height: 64, batchSize: 1, createdAt: 1_760_000_000_000,
intent: 'video',
}
const calls = async (page: Page, cmd: string) => (await mlxCalls(page)).filter((c) => c.cmd === cmd)
test('mac with Z-Image Turbo: Train new trains the character locally and it lands on the Use shelf', async ({ page }) => {
await openTrainTab(page, { ...ZIMAGE_MAC, mlx: { ...ZIMAGE_MAC.mlx, trainPolls: 2 } })
const controls = page.getByTestId('mac-train-controls')
await expect(controls).toBeVisible({ timeout: 15_000 })
// The board, the hint and the controls tell one story: this Mac trains,
// with the limits its trainer holds (mlx_train.rs MIN_PHOTOS, MAX_PHOTOS).
await expect(page.getByText('Drop 4 to 100 photos of your character here')).toBeVisible()
await expect(page.getByText(/does not run on a Mac/)).toHaveCount(0)
await expect(page.getByTestId('mac-train-note')).toHaveCount(0)
// The first run fetches the training adapter, and the line says so.
await expect(page.getByTestId('mac-train-hint')).toContainText('downloads a 340 MB training adapter')
await expect(page.getByTestId('mac-train-hint')).toContainText('Standard, 1200 steps')
await controls.getByPlaceholder('Trigger word, e.g. davechar').fill('luxfox')
await addPhotos(page, 4)
// How-it-works film (15.10.2026): the board said "Training runs on your
// GPU" and the model chip named the picked image model, "MLX SD Turbo".
await expect(page.getByText("Training runs on this Mac and lands the character in the Mac's LoRA folder.")).toBeVisible()
await expect(page.getByText(/runs on your GPU/)).toHaveCount(0)
await expect(page.getByTestId('mac-train-base')).toHaveText('Trains on Z-Image Turbo')
await expect(controls).toContainText('4/100 photos')
await page.getByRole('button', { name: /^Create$/ }).last().click()
await expect.poll(async () => (await calls(page, 'mlx_train_start')).length, { timeout: 30_000 }).toBe(1)
const [clear] = await calls(page, 'mlx_train_clear')
expect(clear.raw.set).toBe('luxfox')
const staged = await calls(page, 'mlx_train_stage')
expect(staged).toHaveLength(4)
for (const s of staged) {
expect(s.raw.set).toBe('luxfox')
// The trigger word leads every caption: the engine has no other way to
// tie the token to the character.
expect(s.raw.caption).toBe('luxfox, a photo of luxfox')
expect(s.raw.bytes).toBe(ONE_PIXEL_PNG.length)
}
const [start] = await calls(page, 'mlx_train_start')
expect(start.raw).toMatchObject({ set: 'luxfox', trigger: 'luxfox', steps: 1200 })
expect(typeof start.raw.run).toBe('string')
// Through: the tab turns to Use, and the new character is on the shelf.
// In the Character area: the stage turns to Image, and the new character
// is one of its tabs.
await expect(page.getByRole('radio', { name: 'Character Studio', exact: true })).toHaveAttribute('aria-checked', 'true', { timeout: 20_000 })
await expect(page.getByRole('tab', { name: /^luxfox/ })).toBeVisible({ timeout: 10_000 })
await expect(page.getByText(/Training failed/)).toHaveCount(0)
// The Windows trainer and ComfyUI are never asked.
const names = await page.evaluate(() => ((window as unknown as { __TAURI_CALLS__?: Array<{ cmd: string }> }).__TAURI_CALLS__ ?? []).map((c) => c.cmd))
expect(names).not.toContain('start_character_training')
expect(names).not.toContain('stage_training_image')
expect(await comfyCalls(page)).toHaveLength(0)
})
test('mac: Stop ends the training in Rust and is no error', async ({ page }) => {
await openTrainTab(page, { ...ZIMAGE_MAC, mlx: { ...ZIMAGE_MAC.mlx, trainPolls: 400 } })
await page.getByTestId('mac-train-controls').getByPlaceholder('Trigger word, e.g. davechar').fill('luxfox')
await addPhotos(page, 5)
await page.getByRole('button', { name: /^Create$/ }).last().click()
await expect.poll(async () => (await calls(page, 'mlx_train_start')).length, { timeout: 30_000 }).toBe(1)
await expect(page.getByText(/Training \d+\/\d+/).first()).toBeVisible({ timeout: 15_000 })
// The stop button of a running Create.
await page.getByRole('button', { name: /^Cancel$/ }).first().click()
await expect.poll(async () => (await calls(page, 'mlx_train_cancel')).length, { timeout: 15_000 }).toBeGreaterThanOrEqual(1)
const [cancel] = await calls(page, 'mlx_train_cancel')
const [start] = await calls(page, 'mlx_train_start')
expect(cancel.raw.run).toBe(start.raw.run)
await expect(page.getByRole('button', { name: /^Create$/ }).last()).toBeVisible({ timeout: 15_000 })
await expect(page.getByText(/Training failed/)).toHaveCount(0)
})
test('mac without Z-Image Turbo: the Train tab says what it needs and Create does not train', async ({ page }) => {
await openTrainTab(page, { ...MAC, mlx: { engineInstalled: true, installedImages: ['sd-turbo'] } })
await expect(page.getByTestId('mac-train-note')).toContainText('needs Z-Image Turbo', { timeout: 15_000 })
// GH #194: the inputs stay, the missing install sits above them with its button.
const controls = page.getByTestId('mac-train-controls')
await expect(controls.getByRole('button', { name: 'Install Z-Image Turbo' })).toBeVisible()
await controls.getByPlaceholder('Trigger word, e.g. davechar').fill('luxfox')
await addPhotos(page, 5)
await page.getByRole('button', { name: /^Create$/ }).last().click()
await expect(page.getByText(/Install it in the Model Manager, then hit Create again/)).toBeVisible({ timeout: 15_000 })
expect(await calls(page, 'mlx_train_start')).toHaveLength(0)
})
test('mac: frames of a video go through Use frames for a character into the Mac training', async ({ page }) => {
// A video the Mac made earlier: in the gallery, its file on the Mac's disk.
await page.addInitScript(([item, clip]) => {
if (!window.localStorage.getItem('create-store')) {
window.localStorage.setItem('create-store', JSON.stringify({ state: { gallery: [item] }, version: 2 }))
}
(window as unknown as { __E2E_MEDIA_FILES__: Record<string, string> }).__E2E_MEDIA_FILES__ = { [String(item.localPath)]: clip }
}, [VIDEO_ITEM, CLIP.toString('base64')] as const)
await openTrainTab(page, { ...ZIMAGE_MAC, mlx: { ...ZIMAGE_MAC.mlx, trainPolls: 2 } })
// The video in the large view, and its frames picked in the window.
await page.getByRole('radio', { name: 'Image', exact: true }).click()
await page.getByRole('button', { name: 'Open the gallery' }).click()
await page.locator('aside button:has(video)').click()
await page.getByTitle('Use frames of this video for a character').click({ force: true })
const dialog = page.getByRole('dialog', { name: 'Use frames for a character' })
await expect(dialog.getByTestId('character-frames').locator('img')).toHaveCount(8, { timeout: 20_000 })
await dialog.getByRole('button', { name: 'Untick frame 1' }).click()
await dialog.getByRole('button', { name: 'Train with 7 frames' }).click()
await expect(dialog).toHaveCount(0)
// They land on the Train tab of the Mac, which trains them here.
await expect(page.locator('[data-hub-training]')).toContainText('Train a model')
const controls = page.getByTestId('mac-train-controls')
await expect(controls).toContainText('7/100 photos', { timeout: 15_000 })
await controls.getByPlaceholder('Trigger word, e.g. davechar').fill('foxclip')
await page.getByRole('button', { name: /^Create$/ }).last().click()
await expect.poll(async () => (await calls(page, 'mlx_train_start')).length, { timeout: 30_000 }).toBe(1)
const staged = await calls(page, 'mlx_train_stage')
expect(staged).toHaveLength(7)
for (const s of staged) expect(Number(s.raw.bytes)).toBeGreaterThan(100)
const [start] = await calls(page, 'mlx_train_start')
expect(start.raw).toMatchObject({ set: 'foxclip', trigger: 'foxclip' })
// The new character is one of the tabs of the stage of the Character area.
await expect(page.getByRole('radio', { name: 'Character Studio', exact: true })).toHaveAttribute('aria-checked', 'true', { timeout: 20_000 })
await expect(page.getByRole('tab', { name: /^foxclip/ })).toBeVisible({ timeout: 10_000 })
})