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
/**
* Create on the phone, strand 3. Everything runs against the cloud that is
* mocked in this file: account, catalog, upload, job queue, price, trained
* characters. Not one request leaves the machine and nothing is charged.
*
* Run it in the foreground:
* LU_E2E_PORT=5373 npx playwright test --project=mobile create
* Screenshots (they write into the repo, so they are opt in):
* LU_MOBILE_SHOTS=1 LU_E2E_PORT=5373 npx playwright test --project=mobile create -g screenshots
*/
import path from 'node:path'
import { fileURLToPath } from 'node:url'
import { deflateSync } from 'node:zlib'
import { expect, test, type Locator, type Page, type Route } from '@playwright/test'
import { readFileSync } from 'node:fs'
import { SIZES, declareAdult, measureLayout, screensLoaded, shellUrl, watchErrors, type OpenOptions } from './support'
import { cubeGlb } from '../../src/lib/three/glb-build'
import { THREE_D_SCHEMAS, THREE_D_STUDIO, MESH_TEXT, MESH_VIEWS, threeDCatalogEntries } from '../../src/mobile/screens/create/__tests__/fixtures/three-d-models'
// ---------- test media ----------
const CRC = (() => {
const t = new Uint32Array(256)
for (let n = 0; n < 256; n++) {
let c = n
for (let k = 0; k < 8; k++) c = c & 1 ? 0xedb88320 ^ (c >>> 1) : c >>> 1
t[n] = c >>> 0
}
return t
})()
function crc32(buf: Buffer): number {
let c = 0xffffffff
for (const b of buf) c = CRC[(c ^ b) & 0xff] ^ (c >>> 8)
return (c ^ 0xffffffff) >>> 0
}
function chunk(type: string, data: Buffer): Buffer {
const len = Buffer.alloc(4)
len.writeUInt32BE(data.length)
const body = Buffer.concat([Buffer.from(type, 'ascii'), data])
const crc = Buffer.alloc(4)
crc.writeUInt32BE(crc32(body))
return Buffer.concat([len, body, crc])
}
/** A real PNG with a colour gradient, so a decoder, a canvas and a thumbnail all have something to show. */
function png(width: number, height: number, tint = 0): Buffer {
const raw = Buffer.alloc((width * 3 + 1) * height)
for (let y = 0; y < height; y++) {
const row = y * (width * 3 + 1)
raw[row] = 0
for (let x = 0; x < width; x++) {
raw[row + 1 + x * 3] = (40 + Math.round((x / width) * 180) + tint) & 0xff
raw[row + 2 + x * 3] = (60 + Math.round((y / height) * 150)) & 0xff
raw[row + 3 + x * 3] = (120 + tint * 2) & 0xff
}
}
const head = Buffer.alloc(13)
head.writeUInt32BE(width, 0)
head.writeUInt32BE(height, 4)
head[8] = 8
head[9] = 2
return Buffer.concat([Buffer.from([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]), chunk('IHDR', head), chunk('IDAT', deflateSync(raw)), chunk('IEND', Buffer.alloc(0))])
}
/** One second of silence. */
function wav(): Buffer {
const samples = 8000
const b = Buffer.alloc(44 + samples)
b.write('RIFF', 0)
b.writeUInt32LE(36 + samples, 4)
b.write('WAVEfmt ', 8)
b.writeUInt32LE(16, 16)
b.writeUInt16LE(1, 20)
b.writeUInt16LE(1, 22)
b.writeUInt32LE(8000, 24)
b.writeUInt32LE(8000, 28)
b.writeUInt16LE(1, 32)
b.writeUInt16LE(8, 34)
b.write('data', 36)
b.writeUInt32LE(samples, 40)
b.fill(128, 44)
return b
}
/** One second of test picture, 64 by 36, VP8. Chromium of the test run plays it. */
const WEBM = Buffer.from(
'GkXfo59ChoEBQveBAULygQRC84EIQoKEd2VibUKHgQJChYECGFOAZwEAAAAAAAn0EU2bdLpNu4tTq4QVSalmU6yBoU27i1OrhBZUrmtTrIHYTbuMU6uEElTDZ1OsggElTbuMU6uEHFO7a1Osggne7AEAAAAAAABZAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAVSalmsirXsYMPQkBNgI1MYXZmNjIuMTIuMTAyV0GNTGF2ZjYyLjEyLjEwMkSJiECPQAAAAAAAFlSua8iuAQAAAAAAAD/XgQFzxYh+8hSLERtD5ZyBACK1nIN1bmSIgQCGhVZfVlA4g4EBI+ODhAvrwgDgkLCBQLqBJJqBAlWwhFW5gQESVMNn/HNzoGPAgGfImkWjh0VOQ09ERVJEh41MYXZmNjIuMTIuMTAyc3PWY8CLY8WIfvIUixEbQ+VnyKFFo4dFTkNPREVSRIeUTGF2YzYyLjI4LjEwMiBsaWJ2cHhnyKFFo4hEVVJBVElPTkSHkzAwOjAwOjAxLjAwMDAwMDAwMAAfQ7Z1SDLngQCjQ5aBAACAcBcAnQEqQAAkAABHCIWFiIWEiAICDJA/gD+gJnRwXVs4Z+JP6q/ATRX4t9hv09y1jgj+Rfhj/M/e3/cucU/kH4Y9oHzA/wH+P/4T/Ne81/K/5n1gP9d/rfWA+gD+qvpE/qr8An62/47+7/AD/If6bmAPZd/Q/xa/V2zbynn4d/lXmF/61+RU9u8QuoF/DP47/cPzZ/tnIS/pX7X3nPpJI7MUNVdaRFECoY8i90Fy9ickBmX2TzRUarNRcAZ+gX7Ul45zkqD+//FuA8I7X/SBj6ufjyhng3XN+4ysMRc4Jv4R+R4Z3988QH+43LPDcN720eA0c9LyKPnQ4KFcESMJA6DLUrYvtmiq0jJe8Hf7Cxt1SPL2PzbuOwB6QYl07SFjM6wjtWrT/+qbqFwdoJYm/B5iceAv32//a4cFBu1xxTr+y+B1vkJjXr9If7JwrQdIhx3qLXBQr+rPji4f//8Hppe8LSxRv/KaLHg3NJDiq5Q+Jc9u5B/4r4v/tMP/7tqar+ubSV8LAEAs3hY3O0aaCQNDEEYUgwloU6AsoI75sILrTUEAsu7qW5mYILajbtTIV+QOPtCg0S63Q0zBO0vFaXV2MNH/iAymG/bL0JmBRs2H4uiWLtCzE9H//8dAF+GBCGshMsV1GRCY59ZaugAspVb//6vH1F/inT0QY7HkOCv/7cAbujnWRFFij7MPiFht18o43/M//808c+z++5m+TwToDqsABHaV1jo7J1IIXGtPKegviVDCVDOIdwmUGnv+LSEpV8WkL9heRBWhLCh+ONGkWEX7ZLz7okCrPDRmcLwagBHxKLAtoE3agB3bxGfLRiqqZO3dT+vcauntFKoQAADWwGbPcFvOSnc0BIvJdh8rwUL/7zILapeGZDpDn8z+NW9Fld9T2f2vvN2bsolPwRwASNcgaEPX63jEcYBrtIZoxZ/OnIyTxzQXCyNJi1pwPepUSbB8KCNK//3/KVfNbKSzoPRDKKM+ZjfZ7M05x/iJGnL3NOCiP0oLPZNGbJ4NCDhHdS1TmO7mLUehzV4F7zvnFDo///sC6qkpyPP0c3yWUACLmJwyvOOaBZDmIek++nP/+nSe6lUWuja4O5pSNrg9E0UrB4fN0FhDrRM/klejYCu0R81WxFwrROR3Z56/kVGb6hDp8Ssknic26u+/gc8TOGd/J0nfrgLej90uqdJDtUFtvgFyo1Mou1Giur7oUwCjQRyBAMgA8QMAABAQABgMh7w2sJKv/Dm5UP1VUzWEZaeWAVREZtunUrkbFb4CQAABq0Bx5YZJ4BYfegxdNyRH+ge6wmbMY3swnPJ4JczkJn/BuC3kXx/V/KfGt//iuZAY0cFv/W7lrmYEGCFqtg1cmt0MJNBTJu3R5AvdVH0Z+eBFRGfkbqzO5grzyYi7a6GvOhHIuuILWCZ7mKEDe4JDaJkMJ5Rn8Bv8gBH+bJPq0vwur2NzWByE7zPstF45ATtZI5Zf/sn0v4IQtLoVEwqPTZwSRvgnDc1fRG0wfVgz60foTZdkSXYSn4gOoeVdvNDDY6AKL8hpE/cAOIAAAFQAABcAxYAb8AAAAAAABebkADwDD4AAIwFYBm4SAB0wAKNBLIEBkADxAgAGEBAAGAb8bgBCoFkoHLjRUrWNgqsXSMs5VPXh46gQSf6Tc9Gw+ZUz3Vi3J1Yu0EGO/jyITFYYfmIj8EJ/ww/+WPgH5BnxdRrZtCf/iunTFC2cyZDQF3UKDju0Uw5DXfgPtACz9HZvMBK4NNYf3fAvkhXvEvqJRmypklVnwqVQf2IV7qxKVhQ9qd+W8J7ZG62HoGEXIntiOqQN875gCxrPRKXmBfR7rpQ/0PYkvQUyNP3pBO6+A9ZwmH4HliY/XtwwaMOBzJoZJG+DDo/eCGr1sK4GycwEn7dLkK+pt7GgM1wRPLIng2/9YpStJbu2zq+JAApmD+VWeYAT6gAAD7DCABpgBPxBmBOsQ6QAAAuwwgAAEKA8SyAC8BJBAM7ifGIABVAAAKNBI4ECWADxAgAAEBAAGAbX44DiMwsMDJzYjvMWN/3CGss5UtYSOoC3tuvtI06nPjIlrbOrF2ggx3rpdZMIFhjS/48p2LDJiFdNzADbEJ/+LSsf5Fo3byPzHS4OjfaNXJrdExSFkMMaX757oz2Ix/Wv/9m6YfKAhGXxTdpAZTNJ9ga8SIufjC1wrrcejuI2kIh5n7HIr4NoDlsnl23UG+lRzrxwhbQUK30bQPczHkC9fPKuLuVcQvfCDt7FIuZcF58cp7d4HggFraOjEjU6gB0nRL6ck7/6lQzi0JEKtP/54TV8ePP9SuH8P9rnm4ksJC0ewwobR7gSZ9kgSQBuAAACBtgx+yHgAAVwIUAAAAABAASfAA8AngTYAAD6ACT7pDpAAAhwAKNBH4EDIACRAgAAEBAAGABtEJQAp9YHSQ+tAPu6QMs5T2f9nW0aQN07Isa9IC6nWEz1jT/iY7tMVMbQyC4/8B3I0Pcf1lSHwJpXQbyGpIcBov/xaV0l6OsR8UE9z556pBe9oyYa78CNg4D/sbQ+MtKXvTOIGzo5+anL8IFAfQwZRyrY+/BXbgym5K1NoR4IfD+wni4WnFw4J91ob6UycWcnadseg9Qhvt70PHnOmGKKlrADzyLxgYIooxA5ynQkPii0YjeI5RQqECBUS0BiN1fD2agFy9SzmZJ3/0PBDwhaz/8Mx/I2Bi8bCy1OWgqGp3sh8mpil+TU+gABPxAACaL1lgAABd/AKgvAAwgVAAAAAAJ48BtgAAAaoACsAAHxwAAAHFO7a5G7j7OBALeK94EB8YIBpvCBAw==',
'base64',
)
/** A cut-out as Remove background gives it: RGBA, see-through around a solid square in the middle. */
function pngCutOut(width: number, height: number): Buffer {
const raw = Buffer.alloc((width * 4 + 1) * height)
for (let y = 0; y < height; y++) {
const row = y * (width * 4 + 1)
raw[row] = 0
for (let x = 0; x < width; x++) {
const inside = x > width / 4 && x < (width * 3) / 4 && y > height / 4 && y < (height * 3) / 4
raw.set(inside ? [200, 80, 60, 255] : [0, 0, 0, 0], row + 1 + x * 4)
}
}
const head = Buffer.alloc(13)
head.writeUInt32BE(width, 0)
head.writeUInt32BE(height, 4)
head[8] = 8
head[9] = 6
return Buffer.concat([Buffer.from([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]), chunk('IHDR', head), chunk('IDAT', deflateSync(raw)), chunk('IEND', Buffer.alloc(0))])
}
const RESULT_PNG = png(256, 256, 30)
/** A finished 3D model: the hand built cube of the 3D tests. */
const GLB = Buffer.from(cubeGlb())
const photo = (name: string, tint = 0, w = 640, h = 480) => ({ name, mimeType: 'image/png', buffer: png(w, h, tint) })
const clip = (name = 'clip.webm') => ({ name, mimeType: 'video/webm', buffer: WEBM })
const sound = (name = 'voice.wav') => ({ name, mimeType: 'audio/wav', buffer: wav() })
// ---------- the mocked cloud ----------
const CORS: Record<string, string> = {
'access-control-allow-origin': '*',
'access-control-allow-headers': '*',
'access-control-allow-methods': 'GET,POST,PUT,PATCH,DELETE,OPTIONS',
}
const USER = { id: 'e2e-user-1', email: '[email protected]', aud: 'authenticated', role: 'authenticated' }
const PHONE_UA = 'Mozilla/5.0 (Linux; Android 14; Pixel 8) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Mobile Safari/537.36'
/** What /api/jobs/catalog answers: one or two models per tool, all with a price. */
const CATALOG_MODELS: Record<string, unknown>[] = [
{ id: 'z-image-turbo', label: 'Z-Image Turbo (fast)', kind: 'image', credits: { base: 300 }, tier: 'best', weights: 'open' },
{ id: 'flux-dev', label: 'Flux Dev (quality)', kind: 'image', edit: true, cfg: true, negative_prompt: true, credits: { base: 1200 }, tier: 'older', weights: 'open' },
{ id: 'qwen-image-edit', label: 'Qwen Image Edit (no mask needed)', kind: 'image', ops: ['edit'], maskless: true, credits: { base: 900 }, tier: 'older', weights: 'open' },
{ id: 'wan-2.2-720p', label: 'Wan 2.2 720p', kind: 'video', t2v: true, i2v: true, negative_prompt: true, clip: { short: 5, long: 8 }, credits: { base: 40000, long: 64000 }, tier: 'older', weights: 'open' },
{ id: 'z-image-lora-trainer', label: 'Z-Image Character Training', kind: 'image', ops: ['lora-train'], credits: { base: 60000 }, tier: 'best', weights: 'open' },
{ id: 'flux-lora-trainer', label: 'Flux Character Training', kind: 'image', ops: ['lora-train'], credits: { base: 80000 }, tier: 'older', weights: 'open' },
{ id: 'z-image-turbo-lora', label: 'Z-Image Turbo + Character', kind: 'image', ops: ['generate'], lora: true, credits: { base: 500 }, tier: 'best', weights: 'open' },
{ id: 'infinitetalk-fast', label: 'InfiniteTalk (photo avatar)', kind: 'video', ops: ['lipsync'], lipsync_source: 'image', t2v: false, i2v: false, credits: { base: 20000 }, tier: 'standard', weights: 'open' },
{ id: 'qwen3-tts', label: 'Qwen3 TTS (voices)', kind: 'audio', ops: ['tts'], credits: { base: 800 }, tier: 'standard', weights: 'open' },
{ id: 'qwen3-tts-design', label: 'Qwen3 TTS Voice Design', kind: 'audio', ops: ['tts'], credits: { base: 800 }, tier: 'standard', weights: 'open' },
{ id: 'ace-step-1.5', label: 'ACE-Step 1.5', kind: 'audio', ops: ['music'], lyrics: true, credits: { base: 1800, per_s: 30 }, tier: 'standard', weights: 'open' },
// ltx-2-extend and wan-2.2-animate are retired since 24.10.2026 (src/lib/render/retired-models.ts): their successors.
{ id: 'wan-3.0-extend', label: 'Wan 3.0 Extend', kind: 'video', ops: ['studio'], quote_required: true, tier: 'standard', weights: 'closed' },
{ id: 'wan-2.2-animate-2', label: 'Wan 2.2 Animate 2', kind: 'video', ops: ['studio'], quote_required: true, tier: 'standard', weights: 'open' },
]
/** A model whose price the server confirms before every run. */
const STUDIO_EDIT_MODEL = { id: 'seedream-5-edit', label: 'Seedream 5 Edit', kind: 'image', ops: ['studio'], quote_required: true, tier: 'best', weights: 'closed' }
/** A talking model that re-voices a clip instead of a portrait. */
const CLIP_SYNC_MODEL = { id: 'latentsync', label: 'LatentSync (clip)', kind: 'video', ops: ['lipsync'], lipsync_source: 'video', t2v: false, i2v: false, credits: { base: 15000 }, tier: 'older', weights: 'open' }
/** The presenter of the provider: 500 names, most of them with a face. */
const HEYGEN_MODEL = { id: 'heygen-twin', label: 'HeyGen Presenter', kind: 'video', ops: ['studio'], quote_required: true, tier: 'standard', weights: 'closed' }
/** Image to video with style LoRAs, a list field. */
const LORA_MODEL = { id: 'open-video-lora', label: 'OpenVideo + Style LoRA', kind: 'video', adult: true, ops: ['studio'], quote_required: true, tier: 'standard', weights: 'closed' }
const STUDIO_MODEL = { id: 'nucleus-image', label: 'Nucleus', kind: 'image', adult: true, ops: ['studio'], quote_required: true, tier: 'standard', weights: 'open-family' }
interface MockJob {
id: string
kind: 'image' | 'video' | 'audio' | '3d'
model: string
op: string
prompt: string
status: 'queued' | 'running' | 'succeeded' | 'failed' | 'canceled'
error: string | null
cost: number
gets: number
}
type Reply = { status: number; body: unknown } | 'abort'
/** The state of the mocked cloud of one test. Tests change it to stage a case and read it to see what was sent. */
class Cloud {
signedIn = true
license: 'active' | 'none' = 'active'
pastDue = false
credits = 2_000_000
trainings = 2
studio = false
/** Jobs stay "running" while this is set. */
hold = false
/** How the next jobs end. */
outcome: { status: 'succeeded' } | { status: 'failed'; error: string } = { status: 'succeeded' }
/** One shot answers for the next submits, uploads and price checks. */
submitReplies: Reply[] = []
uploadReplies: Reply[] = []
quoteReplies: Reply[] = []
quoteCredits = 1500
/** The price check answers 500 while this is set. */
quoteDown = false
/** Result addresses signed before this number answer 403, like an expired link. */
validFrom = 0
private sig = 1
/** The result is gone for good (the retention sweep ran). */
resultsGone = false
/** The picture every image result shows. */
resultPng: Buffer = RESULT_PNG
/** The line is dead: every request to the cloud fails. */
down = false
/** Every answer of the queue is slowed down by this. */
delayMs = 0
/** The price list answers 503 while this is set. */
catalogDown = false
/** Another price list than the usual one. */
models: Record<string, unknown>[] | null = null
/** Result files do not load while this is set (the job itself still answers). */
mediaDown = false
/** What the helper model answers to "Improve my prompt". */
improved = ''
/** Every chat call that reached the cloud. */
chats: unknown[] = []
loras: { id: string; name: string; trigger_word: string; base_family: string; created_at: string }[] = []
lorasFail = false
/** Deleting a character answers 500 while this is set. */
loraDeleteFail = false
/** What a Cancel answers instead of cancelling: 409 is "a GPU already took it". */
cancelStatus: number | null = null
/** The line drops once this many uploads went through. */
uploadDropAt: number | null = null
/** The limits for uploads the price list names, in bytes per kind. */
uploadLimits: Record<string, number> | null = null
/** The helper model for "Improve my prompt" does not answer while this is set. */
chatDown = false
jobs = new Map<string, MockJob>()
submits: { kind: string; model: string; prompt: string; params: Record<string, unknown> }[] = []
uploads: { role: string; bytes: number; head: number[] }[] = []
/** The bytes of every uploaded mask. */
masks: Buffer[] = []
/** The bytes of every uploaded source photo. */
sources: Buffer[] = []
cancels: string[] = []
deletedLoras: string[] = []
quotes: unknown[] = []
paths: string[] = []
private n = 0
resign(): void {
this.sig++
this.validFrom = this.sig
}
release(): void {
this.hold = false
}
private resultUrl(job: MockJob): string {
const ext = job.kind === 'image' ? 'png' : job.kind === 'video' ? 'webm' : job.kind === '3d' ? 'glb' : 'wav'
return `https://lu-labs.ai/mock-result/${job.id}.${ext}?sig=${this.sig}`
}
private view(job: MockJob): Record<string, unknown> {
if (!this.hold && (job.status === 'queued' || job.status === 'running')) {
job.status = this.outcome.status
job.error = this.outcome.status === 'failed' ? this.outcome.error : null
if (job.status === 'succeeded' && job.op === 'lora-train') {
const params = this.submits.find((s) => s.params.client_request_id === job.id.replace('job-', 'req-'))?.params ?? this.submits[this.submits.length - 1]?.params ?? {}
this.loras.unshift({ id: `lora-${job.id}`, name: String(params.name ?? params.trigger_word ?? 'character'), trigger_word: String(params.trigger_word ?? 'oxlu'), base_family: 'z-image', created_at: new Date().toISOString() })
}
} else if (job.status === 'queued') job.status = 'running'
job.gets++
return {
id: job.id,
kind: job.kind,
model: job.model,
provider: null,
status: job.status,
result_url: job.status === 'succeeded' && !this.resultsGone ? this.resultUrl(job) : null,
attestation: null,
cost_units: job.cost,
created_at: new Date(Date.now() - 4000).toISOString(),
completed_at: job.status === 'succeeded' ? new Date().toISOString() : null,
error: job.error,
prompt: job.prompt,
}
}
private quota(): Record<string, unknown> {
return {
tier: 'hosted-max',
period: '2026-10',
limits: { credits: 2_550_000 },
costs: { image: 1200, video: 40000 },
used: { credits_used: 2_550_000 - this.credits },
remaining: { credits: this.credits },
topup: { credits: 0 },
video: { limit: 1_500_000, used: 0, remaining: 1_500_000 },
trainings: { limit: 2, used: 2 - this.trainings, remaining: this.trainings },
}
}
private priceOf(submit: { kind: string; model: string; params: Record<string, unknown> }): number {
const m = CATALOG_MODELS.find((x) => x.id === submit.model) as { credits?: { base: number } } | undefined
if (submit.model === STUDIO_MODEL.id || submit.model === STUDIO_EDIT_MODEL.id) return this.quoteCredits
const op = String(submit.params.op)
if (op === 'removebg') return 1000
if (op === 'eraser') return 2500
if (op === 'upscale') return submit.kind === 'video' ? 2500 : 1000
return m?.credits?.base ?? 1200
}
async install(page: Page): Promise<void> {
const json = (status: number, body: unknown) => ({ status, headers: { ...CORS, 'content-type': 'application/json' }, body: JSON.stringify(body) })
const answer = async (route: Route, reply: Reply) => (reply === 'abort' ? route.abort('connectionfailed') : route.fulfill(json(reply.status, reply.body)))
await page.route('**/auth/v1/**', async (route) => {
const req = route.request()
if (req.method() === 'OPTIONS') return route.fulfill({ status: 204, headers: CORS })
const url = req.url()
if (url.includes('/token')) {
return route.fulfill(json(200, { access_token: 'e2e-access-token', token_type: 'bearer', expires_in: 3600, expires_at: Math.floor(Date.now() / 1000) + 3600, refresh_token: 'e2e-refresh-token', user: USER }))
}
if (url.includes('/user')) return route.fulfill(json(200, USER))
return route.fulfill(json(200, {}))
})
await page.route('https://lu-labs.ai/**', async (route) => {
const req = route.request()
if (req.method() === 'OPTIONS') return route.fulfill({ status: 204, headers: CORS })
const url = new URL(req.url())
const p = url.pathname
if (this.down) return route.abort('internetdisconnected')
this.paths.push(`${req.method()} ${p}`)
if (this.delayMs && p.startsWith('/api/jobs')) await new Promise((r) => setTimeout(r, this.delayMs))
if (p.startsWith('/mock-result/')) {
if (this.mediaDown) return route.abort('connectionfailed')
if (Number(url.searchParams.get('sig') ?? 0) < this.validFrom || this.resultsGone) return route.fulfill({ status: 403, headers: CORS, body: 'expired' })
const body = p.endsWith('.png') ? this.resultPng : p.endsWith('.webm') ? WEBM : p.endsWith('.glb') ? GLB : wav()
const type = p.endsWith('.png') ? 'image/png' : p.endsWith('.webm') ? 'video/webm' : p.endsWith('.glb') ? 'model/gltf-binary' : 'audio/wav'
return route.fulfill({ status: 200, headers: { ...CORS, 'content-type': type, 'accept-ranges': 'bytes', 'cache-control': 'no-store' }, body })
}
if (p === '/api/me') {
if (!this.signedIn) return route.fulfill(json(401, { error: 'not signed in' }))
return route.fulfill(json(200, { user: { id: USER.id, email: USER.email }, license: this.license === 'active' ? { status: 'active', tier: 'hosted-max', access: true, paidPlan: true, pastDue: this.pastDue, pastDueTier: this.pastDue ? 'hosted' : null } : { status: 'none' }, profile: null }))
}
if (p === '/api/jobs/quota') return route.fulfill(json(200, this.quota()))
if (p === '/api/inference/v1/chat/completions') {
this.chats.push(req.postDataJSON())
if (this.chatDown) return route.fulfill(json(503, { error: 'unavailable' }))
const chunk = (delta: Record<string, unknown>, finish: string | null) => `data: ${JSON.stringify({ id: 'chat-1', object: 'chat.completion.chunk', choices: [{ index: 0, delta, finish_reason: finish }] })}\n\n`
return route.fulfill({ status: 200, headers: { ...CORS, 'content-type': 'text/event-stream' }, body: `${chunk({ role: 'assistant', content: this.improved }, null)}${chunk({}, 'stop')}data: [DONE]\n\n` })
}
if (p === '/api/jobs/catalog') {
if (this.catalogDown) return route.fulfill(json(503, { error: 'unavailable' }))
return route.fulfill(
json(200, {
models: this.models ?? (this.studio ? [...CATALOG_MODELS, STUDIO_MODEL, STUDIO_EDIT_MODEL] : CATALOG_MODELS),
ops: { removebg: 1000, eraser: 2500, upscale_image: 1000, upscale_video_per_s: 500, upscale_video_min: 2500 },
voice: { stt: 600, tts_per_1k_chars: 8000 },
media_live: true,
tier: 'hosted-max',
monthly_credits: 2_550_000,
...(this.uploadLimits ? { upload_limits: this.uploadLimits } : {}),
}),
)
}
if (p === '/api/inference/v1/models') return route.fulfill(json(200, { object: 'list', data: [] }))
if (p === '/api/jobs/runtime') return route.fulfill(json(200, { runtimes: {} }))
if (p === '/api/account/content-policy') return route.fulfill(json(200, { policy: 'soft', ageConfirmedAt: null, ageConfirmationRequired: true }))
if (p === '/api/jobs/studio-quote') {
this.quotes.push(req.postDataJSON())
if (this.quoteDown) return route.fulfill(json(500, { error: 'boom' }))
const reply = this.quoteReplies.shift()
if (reply) return answer(route, reply)
return route.fulfill(json(200, { credits: this.quoteCredits }))
}
if (p === '/api/loras' && req.method() === 'GET') {
if (this.lorasFail) return route.fulfill(json(503, { error: 'unavailable' }))
return route.fulfill(json(200, { loras: this.loras }))
}
if (p.startsWith('/api/loras/') && req.method() === 'DELETE') {
const id = decodeURIComponent(p.slice('/api/loras/'.length))
if (this.loraDeleteFail) return route.fulfill(json(500, { error: 'boom' }))
this.deletedLoras.push(id)
this.loras = this.loras.filter((l) => l.id !== id)
return route.fulfill(json(200, { ok: true }))
}
if (p === '/api/jobs/upload') {
const reply = this.uploadReplies.shift()
if (reply) return answer(route, reply)
if (this.uploadDropAt !== null && this.uploads.length >= this.uploadDropAt) return route.abort('connectionfailed')
const body = req.postDataBuffer() ?? Buffer.alloc(0)
const role = url.searchParams.get('role') ?? ''
this.uploads.push({ role, bytes: body.length, head: [...body.subarray(0, 4)] })
if (role === 'mask') this.masks.push(Buffer.from(body))
if (role === 'source') this.sources.push(Buffer.from(body))
return route.fulfill(json(200, { path: `inputs/${role}-${this.uploads.length}` }))
}
if (p === '/api/jobs' && req.method() === 'POST') {
const reply = this.submitReplies.shift()
if (reply) return answer(route, reply)
const submit = req.postDataJSON() as { kind: 'image' | 'video' | 'audio' | '3d'; model: string; prompt: string; params: Record<string, unknown> }
this.submits.push(submit)
const count = typeof submit.params.count === 'number' ? submit.params.count : 1
const cost = this.priceOf(submit)
const made: MockJob[] = []
for (let i = 0; i < count; i++) {
const job: MockJob = { id: `job-${++this.n}`, kind: submit.kind, model: submit.model, op: String(submit.params.op), prompt: submit.prompt, status: 'queued', error: null, cost, gets: 0 }
this.jobs.set(job.id, job)
made.push(job)
}
this.credits -= cost * count
if (String(submit.params.op) === 'lora-train') this.trainings = Math.max(0, this.trainings - 1)
return route.fulfill(json(200, { id: made[0].id, quota: { cost, used: 2_550_000 - this.credits, limit: 2_550_000 }, ...(count > 1 ? { jobs: made.map((j) => ({ id: j.id, status: 'queued', cost })), requested: count } : {}) }))
}
const cancel = /^\/api\/jobs\/([^/]+)\/cancel$/.exec(p)
if (cancel) {
const job = this.jobs.get(decodeURIComponent(cancel[1]))
if (!job) return route.fulfill(json(404, { error: 'not found' }))
if (this.cancelStatus !== null) return route.fulfill(json(this.cancelStatus, { error: 'job is no longer cancelable' }))
this.cancels.push(job.id)
job.status = 'canceled'
this.credits += job.cost
return route.fulfill(json(200, { status: 'canceled', refunded: true }))
}
const one = /^\/api\/jobs\/([^/]+)$/.exec(p)
if (one && req.method() === 'GET') {
const job = this.jobs.get(decodeURIComponent(one[1]))
if (!job) return route.fulfill(json(404, { error: 'not found' }))
return route.fulfill(json(200, { job: this.view(job) }))
}
return route.fulfill(json(404, { error: `no mock for ${p}` }))
})
}
}
interface SeedOptions extends OpenOptions {
/** The user already agreed to send content to the cloud. Default true. */
consent?: boolean
/** How this build may speak about buying. Mapped to the store preset that has this rule (open, play, appstore). */
policy?: { purchase?: 'links' | 'text-only' | 'none' }
/** The app mode saved on the phone. Default cloud. */
appMode?: 'cloud' | 'local'
/** The note about how long results are kept was read. Default true, so it does not cover the stage. */
retentionSeen?: boolean
/** The setting that shows what LU Cloud can do to people without it. Default on. */
teasers?: boolean
}
/** Put the saved state of a signed in phone in place, once per test (a reload keeps what the app wrote since). */
async function seed(page: Page, cloud: Cloud, options: SeedOptions = {}): Promise<void> {
await page.addInitScript(
(o) => {
const w = window as unknown as { __shared: { name: string; type: string; size: number }[] }
w.__shared = []
Object.defineProperty(navigator, 'canShare', { configurable: true, value: () => true })
Object.defineProperty(navigator, 'share', {
configurable: true,
value: async (data: ShareData) => {
for (const f of data.files ?? []) w.__shared.push({ name: f.name, type: f.type, size: f.size })
},
})
if (localStorage.getItem('lu-e2e-seeded')) return
localStorage.setItem('lu-e2e-seeded', '1')
if (o.signedIn) {
localStorage.setItem(
'lu-cloud-session',
JSON.stringify({ access_token: 'e2e-access-token', token_type: 'bearer', expires_in: 3600, expires_at: Math.floor(Date.now() / 1000) + 3600, refresh_token: 'e2e-refresh-token', user: o.user }),
)
}
localStorage.setItem('chat-settings', JSON.stringify({ state: { settings: { appMode: o.appMode, ...(o.teasers ? {} : { cloudTeasersEnabled: false }) }, personas: [] }, version: 21 }))
if (o.consent) localStorage.setItem('lu-mobile-ai-consent', JSON.stringify({ v: 2, agreedAt: new Date().toISOString() }))
if (o.retentionSeen) localStorage.setItem('lu_cloud_notice', JSON.stringify({ state: { retentionNoticeSeen: true }, version: 0 }))
},
{ signedIn: cloud.signedIn, user: USER, appMode: options.appMode ?? 'cloud', consent: options.consent !== false, retentionSeen: options.retentionSeen !== false, teasers: options.teasers !== false },
)
}
async function openCreate(page: Page, cloud: Cloud, options: SeedOptions = {}): Promise<void> {
await cloud.install(page)
await seed(page, cloud, options)
// The store presets with a purchase rule other than "links" also ask for the age once; these tests are not about that.
const store = options.policy?.purchase === 'text-only' ? 'play' : options.policy?.purchase === 'none' ? 'appstore' : undefined
if (store) await declareAdult(page)
await page.goto(shellUrl({ ...options, store: options.store ?? store }))
await page.getByTestId('m-app').waitFor()
await screensLoaded(page)
if (options.route) return
// A cold start lands in a new chat. One step back is the list with the tab bar.
await page.getByTestId('m-page-back').tap()
await page.getByTestId('m-nav-create').tap()
await screensLoaded(page)
await page.getByTestId('m-create-screen').waitFor()
}
const stage = (page: Page) => page.getByTestId('m-create-stage')
const tid = (page: Page, id: string) => page.getByTestId(id)
/** Tap something that opens the file picker and hand it files. */
async function pick(page: Page, opener: Locator, files: { name: string; mimeType: string; buffer: Buffer }[]): Promise<void> {
const [chooser] = await Promise.all([page.waitForEvent('filechooser'), opener.tap()])
await chooser.setFiles(files)
}
/**
* Prompt v2 (c19cc0cad): no tool row above the field and no model chip beside it. "What" and "Model" are the first
* rows of the run settings, which the settings button under the field opens.
*/
async function openRunRow(page: Page, row: 'm-create-tools-all' | 'm-create-model'): Promise<void> {
await tid(page, 'm-create-settings').tap()
await tid(page, row).tap()
}
async function chooseTool(page: Page, tool: string): Promise<void> {
await openRunRow(page, 'm-create-tools-all')
await tid(page, `m-create-tools-${tool}`).tap()
await expect(stage(page)).toHaveAttribute('data-m-tool', tool)
}
async function addSource(page: Page, files: { name: string; mimeType: string; buffer: Buffer }[]): Promise<void> {
await tid(page, 'm-create-add-source').tap()
await pick(page, tid(page, 'm-create-source-library'), files)
// The sheet stays until the photo is decoded. A user goes on when it is gone, and so does the test:
// the next tap must not race the sheet that is about to close.
await expect(tid(page, 'm-sheet-source')).toHaveCount(0)
}
async function typePrompt(page: Page, text: string): Promise<void> {
await tid(page, 'm-create-prompt').fill(text)
}
async function run(page: Page): Promise<void> {
try {
await expect(tid(page, 'm-create-generate')).toBeEnabled()
} catch (err) {
// Say why Create is held back, the bare "not enabled" does not.
const why = await tid(page, 'm-create-blocked').first().evaluate((el) => `${el.getAttribute('data-m-reason')}: ${el.textContent}`).catch(() => 'no reason on screen')
const price = await tid(page, 'm-create-price').first().getAttribute('data-state').catch(() => null)
throw new Error(`Create stays blocked (${why}; price ${price}). ${String(err).slice(0, 200)}`)
}
await tid(page, 'm-create-generate').tap()
}
async function expectResult(page: Page, kind: 'image' | 'video' | 'audio'): Promise<string> {
const result = tid(page, 'm-create-result')
await expect(result).toBeVisible({ timeout: 20_000 })
await expect(result).toHaveAttribute('data-m-kind', kind)
return (await result.getAttribute('data-m-id')) ?? ''
}
async function galleryCount(page: Page): Promise<number> {
return page.evaluate(() => {
const raw = localStorage.getItem('create-store') ?? localStorage.getItem('lu-create') ?? ''
try {
return (JSON.parse(raw) as { state: { gallery: unknown[] } }).state.gallery.length
} catch {
return -1
}
})
}
// Every test brings its own cloud and its own page, so they can run side by side.
test.describe.configure({ mode: 'parallel' })
test.use({ userAgent: PHONE_UA })
/** The back arrow of the page on top. Two pages are mounted at a time, so the arrow is asked for by its page. */
async function back(page: Page, screen: string): Promise<void> {
await tid(page, screen).getByTestId('m-page-back').tap()
}
async function pickModel(page: Page, id: string): Promise<void> {
await openRunRow(page, 'm-create-model')
await page.locator(`[role="radio"][data-m-id="${id}"]`).tap()
await expect(tid(page, 'm-sheet-create-model')).toHaveCount(0)
}
async function expectLayout(page: Page, where: string): Promise<void> {
const layout = await measureLayout(page)
expect(layout, where).toEqual({ overflow: [], small: [], pageScrolls: false })
}
/** The back arrow of the page on top, whichever that is. */
const topBack = (page: Page) => page.locator('.m-page:not([data-m-hidden]) [data-testid="m-page-back"]').last()
/** After a restart the app opens where it was, or in a chat: go to the root of Create. */
async function toCreate(page: Page): Promise<void> {
for (let i = 0; i < 6 && !(await tid(page, 'm-nav-create').isVisible()); i++) await topBack(page).tap()
if (!(await tid(page, 'm-create-screen').isVisible())) await tid(page, 'm-nav-create').tap()
await screensLoaded(page)
await tid(page, 'm-create-screen').waitFor()
}
/**
* A new start opens a new chat (round 57). The tab Create keeps its pages: back to the chat list, then the tab,
* and the page that was open there is on top again.
*/
async function backToCreateTab(page: Page): Promise<void> {
await expect(tid(page, 'm-chat-screen')).toBeVisible()
await topBack(page).tap()
await tid(page, 'm-nav-create').tap()
await screensLoaded(page)
}
/** The shelf of characters is the page on top (the page that was left is gone), with a training on it. */
async function onShelf(page: Page): Promise<void> {
await expect(tid(page, 'm-create-character-new-screen')).toHaveCount(0)
await expect(page.locator('.m-page:not([data-m-hidden]) [data-testid="m-create-training"]')).toBeVisible()
}
/** What the draft of Create holds on the phone: the words and the slots of the kept files. */
async function draftOnDisk(page: Page): Promise<{ prompt: string; intent: string; files: string[] }> {
return page.evaluate(async () => {
let words: { prompt?: string; intent?: string } = {}
try {
words = JSON.parse(localStorage.getItem('lu-create-draft') ?? '{}')
} catch {
words = {}
}
const files = await new Promise<string[]>((resolve) => {
const open = indexedDB.open('lu-create-draft', 1)
open.onupgradeneeded = () => open.result.createObjectStore('files', { keyPath: 'slot' })
open.onerror = () => resolve([])
open.onsuccess = () => {
const req = open.result.transaction('files').objectStore('files').getAllKeys()
req.onsuccess = () => {
open.result.close()
resolve((req.result as string[]).sort())
}
req.onerror = () => resolve([])
}
})
return { prompt: words.prompt ?? '', intent: words.intent ?? '', files }
})
}
type BridgeCase = 'ok' | 'no-space' | 'denied' | 'broken' | 'stale-once'
/** A native bridge that stands in for the phone: it records what it was asked and fails the way the case says. */
async function installBridge(page: Page, how: BridgeCase): Promise<void> {
await page.evaluate(async (mode) => {
const w = window as unknown as { __bridge: { downloads: string[]; photos: { path: string; kind?: string }[]; dropped: string[] } }
w.__bridge = { downloads: [], photos: [], dropped: [] }
const spec = '/src/mobile/platform/bridge.ts'
const mod = (await import(/* @vite-ignore */ spec)) as { __setBridgeForTests: (b: unknown) => void }
mod.__setBridgeForTests({
downloadToTemp: async (url: string) => {
w.__bridge.downloads.push(url)
if (mode === 'stale-once' && w.__bridge.downloads.length === 1) throw new Error('Download failed (HTTP 403)')
return { path: `/tmp/e2e-${w.__bridge.downloads.length}` }
},
saveToPhotos: async (path: string, kind?: string) => {
if (mode === 'no-space') throw new Error('write failed: No space left on device (os error 28)')
if (mode === 'denied') throw new Error('Photo library access was denied')
if (mode === 'broken') throw new Error('PHPhotosErrorDomain 3302')
w.__bridge.photos.push({ path, kind })
return { saved: true }
},
deleteTempFile: async (path: string) => {
w.__bridge.dropped.push(path)
return true
},
})
}, how)
}
async function bridgeCalls(page: Page): Promise<{ downloads: string[]; photos: { path: string; kind?: string }[]; dropped: string[] }> {
return page.evaluate(() => (window as unknown as { __bridge: { downloads: string[]; photos: { path: string; kind?: string }[]; dropped: string[] } }).__bridge)
}
/** Runs in the page: a JPEG of the given size with a gradient, as base64. */
async function jpegInPage({ w, h }: { w: number; h: number }): Promise<string> {
const canvas = document.createElement('canvas')
canvas.width = w
canvas.height = h
const ctx = canvas.getContext('2d')!
const g = ctx.createLinearGradient(0, 0, w, h)
g.addColorStop(0, '#204080')
g.addColorStop(1, '#e0a040')
ctx.fillStyle = g
ctx.fillRect(0, 0, w, h)
const blob = await new Promise<Blob>((resolve) => canvas.toBlob((b) => resolve(b!), 'image/jpeg', 0.9))
const bytes = new Uint8Array(await blob.arrayBuffer())
let binary = ''
for (let i = 0; i < bytes.length; i += 0x8000) binary += String.fromCharCode(...bytes.subarray(i, i + 0x8000))
return btoa(binary)
}
/** Put the note a camera writes into a JPEG: "show me turned" (EXIF orientation, 6 is a quarter turn). */
function withExifOrientation(jpeg: Buffer, orientation: number): Buffer {
const tiff = Buffer.alloc(26)
tiff.write('II', 0, 'ascii')
tiff.writeUInt16LE(42, 2)
tiff.writeUInt32LE(8, 4)
tiff.writeUInt16LE(1, 8)
tiff.writeUInt16LE(0x0112, 10)
tiff.writeUInt16LE(3, 12)
tiff.writeUInt32LE(1, 14)
tiff.writeUInt16LE(orientation, 18)
tiff.writeUInt32LE(0, 22)
const body = Buffer.concat([Buffer.from('Exif\0\0', 'binary'), tiff])
const head = Buffer.alloc(4)
head.writeUInt16BE(0xffe1, 0)
head.writeUInt16BE(body.length + 2, 2)
return Buffer.concat([jpeg.subarray(0, 2), head, body, jpeg.subarray(2)])
}
/** Console errors that are not the browser reporting a mocked failure. */
const real = (errors: string[]) => errors.filter((e) => !/Failed to load resource|net::ERR_/i.test(e))
type Frac = [number, number]
/** One finger on the mask editor: down, along the points, up. Points are shares of the frame. */
async function paint(page: Page, points: Frac[], pointerId = 1): Promise<void> {
await page.evaluate(
({ pts, id }) => {
const el = document.querySelector('[data-testid="m-create-mask-canvas"]')
if (!el) throw new Error('no mask canvas')
const r = el.getBoundingClientRect()
const send = (type: string, p: number[]) =>
el.dispatchEvent(new PointerEvent(type, { pointerId: id, pointerType: 'touch', isPrimary: true, bubbles: true, cancelable: true, clientX: r.left + p[0] * r.width, clientY: r.top + p[1] * r.height }))
send('pointerdown', pts[0])
for (const p of pts.slice(1)) send('pointermove', p)
send('pointerup', pts[pts.length - 1])
},
{ pts: points, id: pointerId },
)
}
/** Two fingers: both down, both move, both up. */
async function pinch(page: Page, from: [Frac, Frac], to: [Frac, Frac]): Promise<void> {
await page.evaluate(
({ a, b }) => {
const el = document.querySelector('[data-testid="m-create-mask-canvas"]')
if (!el) throw new Error('no mask canvas')
const r = el.getBoundingClientRect()
const send = (type: string, id: number, p: number[]) =>
el.dispatchEvent(new PointerEvent(type, { pointerId: id, pointerType: 'touch', isPrimary: id === 1, bubbles: true, cancelable: true, clientX: r.left + p[0] * r.width, clientY: r.top + p[1] * r.height }))
send('pointerdown', 1, a[0])
send('pointerdown', 2, a[1])
for (let i = 1; i <= 4; i++) {
const k = i / 4
send('pointermove', 1, [a[0][0] + (b[0][0] - a[0][0]) * k, a[0][1] + (b[0][1] - a[0][1]) * k])
send('pointermove', 2, [a[1][0] + (b[1][0] - a[1][0]) * k, a[1][1] + (b[1][1] - a[1][1]) * k])
}
send('pointerup', 1, b[0])
send('pointerup', 2, b[1])
},
{ a: from, b: to },
)
}
/** How much of the working mask layer on screen is painted, 0 to 1. */
async function paintedShare(page: Page): Promise<number> {
return page.evaluate(() => {
const c = document.querySelector<HTMLCanvasElement>('[data-testid="m-create-mask-layer"]')
const ctx = c?.getContext('2d')
if (!c || !ctx) return -1
const data = ctx.getImageData(0, 0, c.width, c.height).data
let n = 0
for (let i = 3; i < data.length; i += 4) if (data[i] > 24) n++
return n / (data.length / 4)
})
}
/** Decode an uploaded mask in the browser and count its white pixels. */
async function whiteShare(page: Page, bytes: Buffer): Promise<{ width: number; height: number; white: number }> {
return page.evaluate(async (b64) => {
const img = new Image()
await new Promise<void>((resolve, reject) => {
img.onload = () => resolve()
img.onerror = () => reject(new Error('mask is not an image'))
img.src = `data:image/png;base64,${b64}`
})
const c = document.createElement('canvas')
c.width = img.naturalWidth
c.height = img.naturalHeight
const ctx = c.getContext('2d')!
ctx.drawImage(img, 0, 0)
const data = ctx.getImageData(0, 0, c.width, c.height).data
let n = 0
for (let i = 0; i < data.length; i += 4) if (data[i] > 200) n++
return { width: c.width, height: c.height, white: n / (data.length / 4) }
}, bytes.toString('base64'))
}
test.use({ userAgent: PHONE_UA })
for (const size of SIZES) {
test.describe(`create ${size.name}`, () => {
test.use({ viewport: { width: size.width, height: size.height } })
// ---------- one run per tool ----------
test('image: prompt, price, run, result, gallery', async ({ page }) => {
const cloud = new Cloud()
const errors = watchErrors(page)
await openCreate(page, cloud)
await expect(stage(page)).toHaveAttribute('data-state', 'empty')
await expect(tid(page, 'm-create-credits')).toContainText('2,000,000')
await expect(tid(page, 'm-create-blocked')).toContainText('Describe what you want first')
await expect(tid(page, 'm-create-generate')).toBeDisabled()
await expectLayout(page, 'K1 empty')
// No examples (round 45): one line says what the tool wants, the prompt starts empty.
await expect(tid(page, 'm-create-example')).toHaveCount(0)
await expect(tid(page, 'm-create-empty')).toHaveText('Describe what you want to see.')
await expect(tid(page, 'm-create-prompt')).toHaveValue('')
await typePrompt(page, 'a red fox in the snow')
await expect(tid(page, 'm-create-price')).toHaveText('300')
await expect(tid(page, 'm-create-settings')).toContainText('1 image')
await run(page)
const id = await expectResult(page, 'image')
expect(cloud.submits).toHaveLength(1)
expect(cloud.submits[0]).toMatchObject({ kind: 'image', model: 'z-image-turbo', prompt: 'a red fox in the snow', params: { op: 'generate' } })
await expect(tid(page, 'm-create-credits')).toContainText('1,999,700')
await expectLayout(page, 'K1 result')
// The result is in the gallery and opens in the viewer.
await tid(page, 'm-create-gallery').tap()
await expect(tid(page, 'm-create-gallery-item')).toHaveCount(1)
await expect(tid(page, 'm-create-gallery-item')).toHaveAttribute('data-m-id', id)
await expectLayout(page, 'K6')
await tid(page, 'm-create-gallery-item').tap()
await expect(tid(page, 'm-create-item-screen')).toBeVisible()
await expect(tid(page, 'm-create-item-stage').locator('img')).toBeVisible()
await expectLayout(page, 'K7')
expect(real(errors())).toEqual([])
})
test('image: the model sheet searches, shows prices and picks; the settings change the run', async ({ page }) => {
const cloud = new Cloud()
await openCreate(page, cloud)
await openRunRow(page, 'm-create-model')
await expect(tid(page, 'm-sheet-create-model')).toBeVisible()
await expectLayout(page, 'K3')
await expect(tid(page, 'm-create-model-cheapest')).toHaveAttribute('data-m-id', 'z-image-turbo')
await tid(page, 'm-create-model-search').fill('flux')
await expect(page.locator('[role="radio"][data-m-id]')).toHaveCount(1)
await expect(page.locator('[role="radio"][data-m-id="flux-dev"]')).toContainText('1,200')
await tid(page, 'm-create-model-search').fill('nothing like this')
await expect(tid(page, 'm-create-model-none')).toBeVisible()
await tid(page, 'm-create-model-search-clear').tap()
await tid(page, 'm-create-model-price-open').first().tap()
await expect(tid(page, 'm-create-model-price')).toBeVisible()
await tid(page, 'm-sheet-back').tap()
await page.locator('[role="radio"][data-m-id="flux-dev"]').tap()
await expect(tid(page, 'm-create-settings')).toContainText('Flux Dev')
await typePrompt(page, 'a lighthouse')
await expect(tid(page, 'm-create-price')).toHaveText('1,200')
await tid(page, 'm-create-settings').tap()
await expect(tid(page, 'm-sheet-run-settings')).toBeVisible()
await expectLayout(page, 'K4')
await tid(page, 'm-create-aspect-16x9').tap()
await tid(page, 'm-create-quality-high').tap()
await tid(page, 'm-create-negative-open').tap()
await tid(page, 'm-create-negative').fill('blurry')
await tid(page, 'm-sheet-back').tap()
await expect(tid(page, 'm-create-settings-price')).toContainText('1,200')
await tid(page, 'm-sheet-close').tap()
await expect(tid(page, 'm-create-settings')).toContainText('16:9')
await expect(tid(page, 'm-create-settings')).toContainText('High')
await run(page)
await expectResult(page, 'image')
const p = cloud.submits[0].params
expect(cloud.submits[0].model).toBe('flux-dev')
expect(p.negative_prompt).toBe('blurry')
expect(Number(p.width) / Number(p.height)).toBeCloseTo(16 / 9, 1)
})
test('image: several images in one run', async ({ page }) => {
const cloud = new Cloud()
await openCreate(page, cloud)
await typePrompt(page, 'three foxes')
await tid(page, 'm-create-settings').tap()
await tid(page, 'm-create-count-3').tap()
await tid(page, 'm-sheet-close').tap()
await expect(tid(page, 'm-create-settings')).toContainText('3 images')
await expect(tid(page, 'm-create-price')).toHaveText('900')
await run(page)
await expectResult(page, 'image')
expect(cloud.submits[0].params.count).toBe(3)
await expect(tid(page, 'm-create-result-thumb')).toHaveCount(3)
await tid(page, 'm-create-result-thumb').nth(2).tap()
await expect(tid(page, 'm-create-result-thumb').nth(2)).toHaveAttribute('aria-current', 'true')
await tid(page, 'm-create-gallery').tap()
await expect(tid(page, 'm-create-gallery-item')).toHaveCount(3)
})
test('the prompt history brings an earlier prompt back', async ({ page }) => {
const cloud = new Cloud()
await openCreate(page, cloud)
await typePrompt(page, 'first idea')
await run(page)
await expectResult(page, 'image')
await typePrompt(page, 'second idea')
await tid(page, 'm-create-settings').tap()
await tid(page, 'm-create-history-open').tap()
await expect(tid(page, 'm-create-history-row')).toHaveCount(1)
await tid(page, 'm-create-history-row').tap()
await expect(tid(page, 'm-create-prompt')).toHaveValue('first idea')
})
test('edit without a mask: a model that changes the whole image', async ({ page }) => {
const cloud = new Cloud()
await openCreate(page, cloud)
await chooseTool(page, 'edit')
await expect(tid(page, 'm-create-source-empty')).toBeVisible()
await expect(tid(page, 'm-create-blocked')).toContainText('Add a photo first')
await addSource(page, [photo('beach.png')])
await expect(tid(page, 'm-create-source')).toBeVisible()
await pickModel(page, 'qwen-image-edit')
await expect(tid(page, 'm-create-mask-state')).toBeVisible()
await typePrompt(page, 'make it sunset')
await run(page)
await expectResult(page, 'image')
expect(cloud.uploads.map((u) => u.role)).toEqual(['source'])
expect(cloud.uploads[0].head).toEqual([0x89, 0x50, 0x4e, 0x47])
expect(cloud.submits[0]).toMatchObject({ model: 'qwen-image-edit', params: { op: 'edit', source_path: 'inputs/source-1' } })
expect(cloud.submits[0].params.mask_path).toBeUndefined()
})
test('edit with a painted mask: the mask is exported at the source size and is not empty', async ({ page }) => {
const cloud = new Cloud()
await openCreate(page, cloud)
await chooseTool(page, 'edit')
await addSource(page, [photo('room.png', 0, 800, 600)])
await pickModel(page, 'flux-dev')
await typePrompt(page, 'a red sofa')
await expect(tid(page, 'm-create-blocked')).toContainText('Paint the area first')
await expect(tid(page, 'm-create-generate')).toBeDisabled()
await tid(page, 'm-create-paint-mask').tap()
await expect(tid(page, 'm-create-mask-screen')).toHaveAttribute('data-state', 'ready')
await expectLayout(page, 'K9')
await expect(tid(page, 'm-create-mask-done')).toBeDisabled()
await expect(tid(page, 'm-create-mask-hint')).toContainText('Paint')
await paint(page, [[0.3, 0.5], [0.4, 0.5], [0.5, 0.5], [0.6, 0.5], [0.7, 0.5]])
await expect(tid(page, 'm-create-mask-hint')).toHaveCount(0)
await expect(tid(page, 'm-create-mask-canvas')).toHaveAttribute('data-m-painted', '1')
expect(await paintedShare(page)).toBeGreaterThan(0.005)
await tid(page, 'm-create-mask-done').tap()
await expect(tid(page, 'm-create-source')).toHaveAttribute('data-state', 'masked')
await run(page)
await expectResult(page, 'image')
expect(cloud.uploads.map((u) => u.role).sort()).toEqual(['mask', 'source'])
expect(cloud.submits[0].params.mask_path).toBeTruthy()
expect(cloud.masks).toHaveLength(1)
const mask = await whiteShare(page, cloud.masks[0])
expect([mask.width, mask.height]).toEqual([800, 600])
expect(mask.white).toBeGreaterThan(0.005)
expect(mask.white).toBeLessThan(0.5)
})
test('mask editor: one finger paints, two fingers zoom and move, undo, redo, eraser, invert, clear', async ({ page }) => {
const cloud = new Cloud()
await openCreate(page, cloud)
await chooseTool(page, 'eraser')
await addSource(page, [photo('street.png', 10, 1200, 900)])
await tid(page, 'm-create-paint-mask').tap()
const canvas = tid(page, 'm-create-mask-canvas')
await expect(tid(page, 'm-create-mask-screen')).toHaveAttribute('data-state', 'ready')
await expect(canvas).toHaveAttribute('data-m-work', '1200x900')
await expect(tid(page, 'm-create-mask-undo')).toBeDisabled()
await paint(page, [[0.3, 0.45], [0.5, 0.45], [0.7, 0.45]])
const one = await paintedShare(page)
expect(one).toBeGreaterThan(0)
await paint(page, [[0.3, 0.55], [0.5, 0.55], [0.7, 0.55]])
const two = await paintedShare(page)
expect(two).toBeGreaterThan(one)
await expect(canvas).toHaveAttribute('data-m-steps', '2')
// Undo takes the second stroke back, redo brings it again.
await tid(page, 'm-create-mask-undo').tap()
await expect(canvas).toHaveAttribute('data-m-steps', '1')
expect(await paintedShare(page)).toBeCloseTo(one, 3)
await tid(page, 'm-create-mask-redo').tap()
expect(await paintedShare(page)).toBeCloseTo(two, 3)
// A bigger brush paints more.
await tid(page, 'm-create-mask-size').focus()
for (let i = 0; i < 12; i++) await page.keyboard.press('ArrowRight')
await paint(page, [[0.3, 0.3], [0.7, 0.3]])
const three = await paintedShare(page)
expect(three - two).toBeGreaterThan(one)
// The eraser removes paint.
await tid(page, 'm-create-mask-eraser').tap()
await paint(page, [[0.3, 0.3], [0.7, 0.3]])
expect(await paintedShare(page)).toBeLessThan(three)
// Invert flips the layer, clear empties it.
const before = await paintedShare(page)
await tid(page, 'm-create-mask-invert').tap()
expect(await paintedShare(page)).toBeCloseTo(1 - before, 2)
await tid(page, 'm-create-mask-wipe').tap()
expect(await paintedShare(page)).toBe(0)
await expect(tid(page, 'm-create-mask-done')).toBeDisabled()
await tid(page, 'm-create-mask-undo').tap()
expect(await paintedShare(page)).toBeGreaterThan(0.5)
await tid(page, 'm-create-mask-undo').tap()
// Two fingers zoom and do not paint.
const steps = await canvas.getAttribute('data-m-steps')
await pinch(page, [[0.4, 0.5], [0.6, 0.5]], [[0.2, 0.5], [0.8, 0.5]])
await expect(canvas).toHaveAttribute('data-m-zoom', '3.00')
await expect(canvas).toHaveAttribute('data-m-steps', steps ?? '')
// Two fingers moving together shift the zoomed image.
await pinch(page, [[0.4, 0.5], [0.6, 0.5]], [[0.5, 0.5], [0.7, 0.5]])
expect((await canvas.getAttribute('data-m-pan')) ?? '0,0').not.toBe('0,0')
// Painting while zoomed lands where the finger is: the centre of the frame is painted in the layer under it.
await tid(page, 'm-create-mask-brush').tap()
const zoomed = await paintedShare(page)
await paint(page, [[0.5, 0.5], [0.52, 0.5]])
expect(await paintedShare(page)).toBeGreaterThan(zoomed)
await tid(page, 'm-create-mask-fit').tap()
await expect(canvas).toHaveAttribute('data-m-zoom', '1.00')
await expectLayout(page, 'K9 painted')
// Cancel with paint asks first.
await tid(page, 'm-create-mask-cancel').tap()
await expect(tid(page, 'm-dialog-discard')).toBeVisible()
await tid(page, 'm-dialog-cancel').tap()
await tid(page, 'm-create-mask-done').tap()
await expect(tid(page, 'm-create-source')).toHaveAttribute('data-state', 'masked')
})
test('erase an object: needs a painted area, then runs', async ({ page }) => {
const cloud = new Cloud()
await openCreate(page, cloud)
await chooseTool(page, 'eraser')
await addSource(page, [photo('park.png')])
await expect(tid(page, 'm-create-blocked')).toContainText('Paint the area first')
await tid(page, 'm-create-paint-mask').tap()
await expect(tid(page, 'm-create-mask-screen')).toHaveAttribute('data-state', 'ready')
await paint(page, [[0.45, 0.5], [0.55, 0.5]])
await tid(page, 'm-create-mask-done').tap()
await expect(tid(page, 'm-create-price')).toHaveText('2,500')
await run(page)
await expectResult(page, 'image')
expect(cloud.submits[0].params.op).toBe('eraser')
expect(cloud.uploads.map((u) => u.role).sort()).toEqual(['mask', 'source'])
})
for (const tool of [
{ id: 'removebg', op: 'removebg', price: '1,000' },
{ id: 'upscale', op: 'upscale', price: '1,000' },
]) {
test(`${tool.id}: a photo in, a result out`, async ({ page }) => {
const cloud = new Cloud()
await openCreate(page, cloud)
await chooseTool(page, tool.id)
await expect(tid(page, 'm-create-prompt')).toHaveCount(0)
// Prompt v2: the fixed model is the row "Model" of the run settings.
await tid(page, 'm-create-settings').tap()
await expect(tid(page, 'm-create-model-fixed')).toBeVisible()
await tid(page, 'm-sheet-close').tap()
await addSource(page, [photo('cat.png')])
if (tool.id === 'upscale') await tid(page, 'm-create-enhance-4k').tap()
await expect(tid(page, 'm-create-price')).toHaveText(tool.price)
await run(page)
await expectResult(page, 'image')
expect(cloud.submits[0].params.op).toBe(tool.op)
if (tool.id === 'upscale') expect(cloud.submits[0].params.target_resolution).toBe('4k')
expect(cloud.uploads.map((u) => u.role)).toEqual(['source'])
await expectLayout(page, `K1 ${tool.id}`)
})
}
test('video from text: length from the model, result plays', async ({ page }) => {
const cloud = new Cloud()
await openCreate(page, cloud)
await chooseTool(page, 'video')
await typePrompt(page, 'waves on a beach')
await expect(tid(page, 'm-create-price')).toHaveText('40,000')
await tid(page, 'm-create-settings').tap()
await expect(tid(page, 'm-create-aspect')).toHaveCount(0)
await tid(page, 'm-create-length-8').tap()
await tid(page, 'm-sheet-close').tap()
await expect(tid(page, 'm-create-price')).toHaveText('64,000')
await run(page)
await expectResult(page, 'video')
expect(cloud.submits[0]).toMatchObject({ kind: 'video', model: 'wan-2.2-720p' })
await expect(tid(page, 'm-create-result').locator('video')).toBeVisible()
await expectLayout(page, 'K1 video result')
await tid(page, 'm-create-result-fullscreen').tap()
await expect(tid(page, 'm-create-item-video')).toBeVisible()
})
test('animate an image: a photo and a prompt become a clip', async ({ page }) => {
const cloud = new Cloud()
await openCreate(page, cloud)
await chooseTool(page, 'animate')
await addSource(page, [photo('portrait.png')])
await typePrompt(page, 'she smiles')
await run(page)
await expectResult(page, 'video')
expect(cloud.uploads.map((u) => u.role)).toEqual(['source'])
expect(cloud.submits[0].kind).toBe('video')
})
test('music: text and length, the result is sound', async ({ page }) => {
const cloud = new Cloud()
await openCreate(page, cloud)
await chooseTool(page, 'music')
await expect(tid(page, 'm-create-music')).toBeVisible()
// Round 57 (David): Length and the text choice stand on the stage, no grey card around them.
const box = await tid(page, 'm-create-music').evaluate((el) => {
const cs = getComputedStyle(el)
return { bg: cs.backgroundColor, border: cs.borderTopWidth, pad: cs.paddingLeft }
})
expect(box).toEqual({ bg: 'rgba(0, 0, 0, 0)', border: '0px', pad: '0px' })
await typePrompt(page, 'calm piano')
await run(page)
await expectResult(page, 'audio')
expect(cloud.submits[0]).toMatchObject({ kind: 'audio', model: 'ace-step-1.5', params: { op: 'music' } })
await expect(tid(page, 'm-create-result').locator('audio')).toBeVisible()
await expectLayout(page, 'K1 music result')
})
test('talking: a portrait and a voice made from text become a clip', async ({ page }) => {
const cloud = new Cloud()
await openCreate(page, cloud)
await chooseTool(page, 'lipsync')
await expect(tid(page, 'm-create-blocked')).toContainText('Add a portrait first')
await addSource(page, [photo('face.png')])
await expect(tid(page, 'm-create-blocked')).toContainText('Add a voice first')
await tid(page, 'm-create-voice-text').fill('Hello, this is a test.')
await tid(page, 'm-create-voice-speak').tap()
await expect(tid(page, 'm-create-voice')).toHaveAttribute('data-state', 'ready', { timeout: 20_000 })
expect(cloud.submits[0]).toMatchObject({ kind: 'audio', params: { op: 'tts' } })
await expectLayout(page, 'K1 talking')
await run(page)
await expectResult(page, 'video')
expect(cloud.submits[1]).toMatchObject({ kind: 'video', model: 'infinitetalk-fast', params: { op: 'lipsync' } })
})
test('talking: a sound file from the phone works as the voice', async ({ page }) => {
const cloud = new Cloud()
await openCreate(page, cloud)
await chooseTool(page, 'lipsync')
await addSource(page, [photo('face.png')])
await pick(page, tid(page, 'm-create-voice-file'), [sound()])
await expect(tid(page, 'm-create-voice')).toHaveAttribute('data-state', 'ready')
await run(page)
await expectResult(page, 'video')
expect(cloud.uploads.map((u) => u.role).sort()).toEqual(['audio', 'source'])
})
test('extend a video: a clip of the gallery gets longer', async ({ page }) => {
const cloud = new Cloud()
await openCreate(page, cloud)
await chooseTool(page, 'video')
await typePrompt(page, 'a train passes')
await run(page)
await expectResult(page, 'video')
await chooseTool(page, 'extend')
await expect(tid(page, 'm-create-blocked')).toContainText('Pick a clip first')
await tid(page, 'm-create-extend-pick').tap()
await expect(tid(page, 'm-create-gallery-pick-screen')).toBeVisible()
await tid(page, 'm-create-gallery-item').tap()
await tid(page, 'm-create-gallery-use').tap()
await expect(tid(page, 'm-create-extend')).toHaveAttribute('data-state', 'ready')
await typePrompt(page, 'the train disappears')
await run(page)
await expectResult(page, 'video')
// The successor of ltx-2-extend is a studio model: it runs as op "studio" and takes the clip as an upload.
expect(cloud.submits[1]).toMatchObject({ kind: 'video', model: 'wan-3.0-extend', prompt: 'the train disappears', params: { op: 'studio' } })
expect(String(cloud.submits[1].params.video_path)).toMatch(/^inputs\//)
})
test('motion: a portrait follows a motion video', async ({ page }) => {
const cloud = new Cloud()
await openCreate(page, cloud)
await chooseTool(page, 'motion')
await addSource(page, [photo('dancer.png')])
await expect(tid(page, 'm-create-blocked')).toContainText('Add a motion video first')
await pick(page, tid(page, 'm-create-motion-video-add'), [clip()])
await expect(tid(page, 'm-create-motion-video')).toHaveAttribute('data-state', 'ready')
await run(page)
await expectResult(page, 'video')
expect(cloud.uploads.map((u) => u.role).sort()).toEqual(['source', 'video'])
// The successor of wan-2.2-animate is a studio model: op "studio", the portrait and the clip as uploads.
expect(cloud.submits[0]).toMatchObject({ model: 'wan-2.2-animate-2', params: { op: 'studio' } })
expect(cloud.submits[0].params).toMatchObject({ source_path: expect.stringMatching(/^inputs\//), video_path: expect.stringMatching(/^inputs\//) })
})
test('enhance a video from the viewer', async ({ page }) => {
const cloud = new Cloud()
await openCreate(page, cloud)
await chooseTool(page, 'video')
await typePrompt(page, 'clouds')
await run(page)
await expectResult(page, 'video')
await tid(page, 'm-create-result-fullscreen').tap()
await tid(page, 'm-create-item-enhance').tap()
await expect(tid(page, 'm-sheet-create-enhance')).toBeVisible()
await expectLayout(page, 'enhance sheet')
await tid(page, 'm-create-enhance-1080p').tap()
await tid(page, 'm-create-enhance-render').tap()
await expect.poll(() => cloud.submits.length, { timeout: 20_000 }).toBe(2)
expect(cloud.submits[1]).toMatchObject({ kind: 'video', params: { op: 'upscale', target_resolution: '1080p' } })
await expect.poll(() => galleryCount(page), { timeout: 20_000 }).toBe(2)
})
test('character: train from photos, see the training, use the character', async ({ page }) => {
const cloud = new Cloud()
cloud.hold = true
await openCreate(page, cloud)
await chooseTool(page, 'character')
await tid(page, 'm-create-characters-open').tap()
await expect(tid(page, 'm-create-characters-empty')).toBeVisible()
await expectLayout(page, 'K10 empty')
await tid(page, 'm-create-character-new').tap()
await expect(tid(page, 'm-create-character-new-screen')).toBeVisible()
// Too few photos and no name: the button says why.
await pick(page, tid(page, 'm-create-char-add'), [photo('a.png', 1), photo('b.png', 2), photo('c.png', 3)])
await expect(tid(page, 'm-create-char-photo')).toHaveCount(3)
await tid(page, 'm-create-train').tap()
await expect(tid(page, 'm-create-train')).toContainText('Give the character a name')
await tid(page, 'm-create-char-name').fill('mia')
await tid(page, 'm-create-train').tap()
await expect(tid(page, 'm-create-char-too-few')).toContainText('Add at least 4 photos')
expect(cloud.submits).toHaveLength(0)
await pick(page, tid(page, 'm-create-char-add'), [photo('d.png', 4), photo('e.png', 5)])
await tid(page, 'm-create-char-photo-remove').first().tap()
await expect(tid(page, 'm-create-char-photo')).toHaveCount(4)
await expect(tid(page, 'm-create-train')).toContainText('60,000 credits')
await expectLayout(page, 'K11')
await tid(page, 'm-create-train').tap()
await expect(tid(page, 'm-create-train-running')).toBeVisible()
await expect.poll(() => cloud.submits.length, { timeout: 20_000 }).toBe(1)
expect(cloud.uploads.filter((u) => u.role === 'train')).toHaveLength(4)
expect(cloud.submits[0]).toMatchObject({ model: 'z-image-lora-trainer', params: { op: 'lora-train', trigger_word: 'mia' } })
expect((cloud.submits[0].params.image_paths as string[]).length).toBe(4)
// The shelf shows the training with its Cancel.
await back(page, 'm-create-character-new-screen')
await expect(tid(page, 'm-create-training')).toBeVisible()
await expect(tid(page, 'm-create-training-cancel')).toBeVisible()
await expectLayout(page, 'K10 training')
cloud.release()
await expect(tid(page, 'm-create-character')).toHaveCount(1, { timeout: 20_000 })
await expect(tid(page, 'm-create-training')).toHaveCount(0)
await expect(tid(page, 'm-create-character')).toContainText('mia')
// Pick it: back on Create, the next run uses it.
await tid(page, 'm-create-character').tap()
await expect(tid(page, 'm-create-screen')).toBeVisible()
await expect(tid(page, 'm-create-characters-open')).toContainText('mia')
await typePrompt(page, 'mia at the beach')
await run(page)
await expectResult(page, 'image')
const use = cloud.submits[1]
expect(use).toMatchObject({ kind: 'image', model: 'z-image-turbo-lora', params: { op: 'generate' } })
expect(use.params.loras).toEqual([expect.objectContaining({ id: 'lora-job-1' })])
})
test('characters: rename on this phone, delete on the account, failed load can be retried', async ({ page }) => {
const cloud = new Cloud()
cloud.loras = [{ id: 'l1', name: 'nova', trigger_word: 'nova', base_family: 'z-image', created_at: '2026-10-01T10:00:00Z' }]
cloud.lorasFail = true
await openCreate(page, cloud)
await chooseTool(page, 'character')
await tid(page, 'm-create-characters-open').tap()
await expect(tid(page, 'm-create-characters-failed')).toBeVisible()
cloud.lorasFail = false
await tid(page, 'm-create-characters-retry').tap()
await expect(tid(page, 'm-create-character')).toContainText('nova')
await tid(page, 'm-create-character-more').tap()
await tid(page, 'm-create-character-rename').tap()
await tid(page, 'm-dialog-field').fill('Nova the cat')
await tid(page, 'm-dialog-confirm').tap()
await expect(tid(page, 'm-create-character')).toContainText('Nova the cat')
await tid(page, 'm-create-character-more').tap()
await tid(page, 'm-create-character-delete').tap()
await tid(page, 'm-dialog-confirm').tap()
await expect(tid(page, 'm-create-characters-empty')).toBeVisible()
expect(cloud.deletedLoras).toEqual(['l1'])
})
// ---------- cancel, restart, deadline ----------
test('cancel: the job is cancelled on the server and the input stays', async ({ page }) => {
const cloud = new Cloud()
cloud.hold = true
await openCreate(page, cloud)
await typePrompt(page, 'a slow picture')
await run(page)
await expect(tid(page, 'm-create-running')).toBeVisible()
await expect(stage(page)).toHaveAttribute('data-state', 'running')
await expect.poll(() => cloud.submits.length).toBe(1)
await expectLayout(page, 'K1 running')
await tid(page, 'm-create-cancel').tap()
await expect.poll(() => cloud.cancels).toEqual(['job-1'])
await expect(stage(page)).toHaveAttribute('data-state', 'empty')
await expect(tid(page, 'm-create-prompt')).toHaveValue('a slow picture')
await expect(tid(page, 'm-create-credits')).toContainText('2,000,000')
expect(await galleryCount(page)).toBe(0)
})
test('restart in the middle of a run: the job is picked up and its result lands', async ({ page }) => {
const cloud = new Cloud()
cloud.hold = true
await openCreate(page, cloud)
await typePrompt(page, 'survives a restart')
await run(page)
await expect(tid(page, 'm-create-running')).toBeVisible()
await expect.poll(() => cloud.jobs.get('job-1')?.gets ?? 0).toBeGreaterThan(0)
// The app is closed and opened again.
await page.reload()
await page.getByTestId('m-app').waitFor()
await screensLoaded(page)
if (!(await tid(page, 'm-create-screen').isVisible())) {
if (await tid(page, 'm-page-back').first().isVisible()) await tid(page, 'm-page-back').first().tap()
await tid(page, 'm-nav-create').tap()
}
await expect(tid(page, 'm-create-pending')).toBeVisible()
await expect(tid(page, 'm-create-pending')).toContainText('Still rendering')
expect(cloud.submits).toHaveLength(1)
cloud.release()
await expect(tid(page, 'm-toast-create-resumed')).toBeVisible({ timeout: 20_000 })
await expectResult(page, 'image')
await expect(tid(page, 'm-create-pending')).toHaveCount(0)
expect(await galleryCount(page)).toBe(1)
// Nothing was booked a second time.
expect(cloud.submits).toHaveLength(1)
})
test('deadline: a run that takes too long says so and still lands later', async ({ page }) => {
const cloud = new Cloud()
cloud.hold = true
await openCreate(page, cloud)
await typePrompt(page, 'takes forever')
await page.clock.install()
await run(page)
await expect(tid(page, 'm-create-running')).toBeVisible()
await expect.poll(() => cloud.jobs.get('job-1')?.gets ?? 0).toBeGreaterThan(0)
await page.clock.runFor(16 * 60_000)
await expect(tid(page, 'm-create-error')).toBeVisible()
await expect(tid(page, 'm-create-error')).toContainText('Still rendering')
await expect(tid(page, 'm-create-error')).toContainText('lands in your gallery')
await expect(tid(page, 'm-create-error-action')).toHaveText('Open gallery')
await expect(tid(page, 'm-create-pending')).toBeVisible()
cloud.release()
await page.clock.runFor(61_000)
await expectResult(page, 'image')
expect(cloud.submits).toHaveLength(1)
})
// ---------- what can go wrong ----------
test('credits: too few before the run, nothing is sent', async ({ page }) => {
const cloud = new Cloud()
cloud.credits = 100
await openCreate(page, cloud)
await typePrompt(page, 'no money')
await expect(tid(page, 'm-create-blocked')).toContainText('Not enough credits')
await tid(page, 'm-create-generate').tap()
// The sheet of strand 5 opens where the paid call would fail. Nothing was sent.
await expect(tid(page, 'm-sheet-credits')).toBeVisible()
expect(cloud.submits).toHaveLength(0)
await tid(page, 'm-sheet-close').tap()
await expect(tid(page, 'm-create-prompt')).toHaveValue('no money')
})
test('credits: used up at the server, the sheet opens and a notice stays', async ({ page }) => {
const cloud = new Cloud()
await openCreate(page, cloud)
await typePrompt(page, 'no money')
cloud.submitReplies.push({ status: 429, body: { error: 'credits exhausted', code: 'credits_exhausted' } })
await run(page)
await expect(tid(page, 'm-sheet-credits')).toBeVisible()
await tid(page, 'm-sheet-close').tap()
await expect(tid(page, 'm-create-error')).toContainText("You're out of credits")
await expect(tid(page, 'm-create-error')).toContainText('not started')
await expect(tid(page, 'm-create-error-action')).toHaveText('See plans')
await expect(tid(page, 'm-create-prompt')).toHaveValue('no money')
await expectLayout(page, 'K1 credits error')
})
test('price changed: the new price is shown and the second tap books it', async ({ page }) => {
const cloud = new Cloud()
cloud.studio = true
await openCreate(page, cloud)
await pickModel(page, 'nucleus-image')
await typePrompt(page, 'a quoted picture')
await expect(tid(page, 'm-create-price')).toHaveText('1,500')
await expect(tid(page, 'm-create-price')).toHaveAttribute('data-state', 'known')
expect(cloud.quotes.length).toBeGreaterThan(0)
cloud.quoteCredits = 2100
await run(page)
await expect(tid(page, 'm-create-error')).toContainText('The price changed')
await expect(tid(page, 'm-create-error')).toContainText('2,100')
await expect(tid(page, 'm-create-error')).toContainText('Nothing was charged')
expect(cloud.submits).toHaveLength(0)
await expect(tid(page, 'm-create-price')).toHaveText('2,100')
await run(page)
await expectResult(page, 'image')
expect(cloud.submits).toHaveLength(1)
expect(cloud.submits[0].params.max_credits).toBe(2100)
})
test('price: a check that fails blocks the run and can be tried again', async ({ page }) => {
const cloud = new Cloud()
cloud.studio = true
cloud.quoteDown = true
await openCreate(page, cloud)
await pickModel(page, 'nucleus-image')
await typePrompt(page, 'a quoted picture')
await expect(tid(page, 'm-create-price')).toHaveAttribute('data-state', 'unavailable', { timeout: 20_000 })
await expect(tid(page, 'm-create-generate')).toBeDisabled()
await expect(tid(page, 'm-create-blocked')).toContainText('Price could not be confirmed')
await tid(page, 'm-create-settings').tap()
await expect(tid(page, 'm-create-settings-price-retry')).toBeVisible()
// While the server is still down the button asks again and the state stays honest.
const asked = cloud.quotes.length
await tid(page, 'm-create-settings-price-retry').tap()
await expect.poll(() => cloud.quotes.length).toBeGreaterThan(asked)
await expect(tid(page, 'm-create-settings-price')).toHaveAttribute('data-state', /unavailable|checking/)
// Server back: the next press (or the app's own next check, whichever is first) brings the price.
cloud.quoteDown = false
await expect(async () => {
const retry = tid(page, 'm-create-settings-price-retry')
if (await retry.count()) await retry.tap({ timeout: 1500 }).catch(() => undefined)
await expect(tid(page, 'm-create-settings-price')).toContainText('1,500', { timeout: 1500 })
}).toPass({ timeout: 20_000 })
await tid(page, 'm-sheet-close').tap()
await expect(tid(page, 'm-create-price')).toHaveText('1,500')
await expect(tid(page, 'm-create-generate')).toBeEnabled()
})
test('network: lost during the upload, nothing is booked, try again works', async ({ page }) => {
const cloud = new Cloud()
await openCreate(page, cloud)
await chooseTool(page, 'removebg')
await addSource(page, [photo('cat.png')])
cloud.uploadReplies.push('abort')
await run(page)
await expect(tid(page, 'm-create-error')).toContainText('No connection to LU Cloud')
await expect(tid(page, 'm-create-error')).toContainText('nothing was charged')
expect(cloud.submits).toHaveLength(0)
await expect(tid(page, 'm-create-source')).toBeVisible()
await tid(page, 'm-create-error-action').tap()
await expectResult(page, 'image')
expect(cloud.submits).toHaveLength(1)
})
test('network: lost during the submit, the run is asked again and then says so', async ({ page }) => {
const cloud = new Cloud()
await openCreate(page, cloud)
await typePrompt(page, 'no line')
cloud.submitReplies.push('abort', 'abort', 'abort')
await run(page)
await expect(tid(page, 'm-create-error')).toContainText('No connection to LU Cloud', { timeout: 20_000 })
expect(cloud.paths.filter((p) => p === 'POST /api/jobs')).toHaveLength(3)
expect(cloud.submits).toHaveLength(0)
await expect(tid(page, 'm-create-prompt')).toHaveValue('no line')
await tid(page, 'm-create-error-action').tap()
await expectResult(page, 'image')
})
test('network: lost while waiting, the job goes on and lands when the line is back', async ({ page, context }) => {
const cloud = new Cloud()
cloud.hold = true
await openCreate(page, cloud)
await typePrompt(page, 'line drops')
await page.clock.install()
await run(page)
await expect(tid(page, 'm-create-running')).toBeVisible()
await expect.poll(() => cloud.jobs.get('job-1')?.gets ?? 0).toBeGreaterThan(0)
cloud.down = true
await context.setOffline(true)
for (let i = 0; i < 8; i++) await page.clock.runFor(10_000)
await expect(tid(page, 'm-create-error')).toContainText('Connection lost', { timeout: 20_000 })
await expect(tid(page, 'm-create-generate')).toBeDisabled()
await expect(tid(page, 'm-create-blocked')).toContainText('No internet')
cloud.release()
cloud.down = false
await context.setOffline(false)
await page.clock.runFor(5_000)
await expectResult(page, 'image')
expect(cloud.submits).toHaveLength(1)
})
test('offline before the run: the button says why and nothing is sent', async ({ page, context }) => {
const cloud = new Cloud()
await openCreate(page, cloud)
await typePrompt(page, 'offline')
await context.setOffline(true)
await expect(tid(page, 'm-create-blocked')).toContainText('No internet')
await expect(tid(page, 'm-create-generate')).toBeDisabled()
await expectLayout(page, 'K1 offline')
await context.setOffline(false)
await expect(tid(page, 'm-create-generate')).toBeEnabled()
})
test('files: too large, wrong kind, a photo format the phone cannot read, and HEIC', async ({ page }) => {
const cloud = new Cloud()
await openCreate(page, cloud)
await chooseTool(page, 'removebg')
// Too large: refused on the phone, with the size.
await tid(page, 'm-create-add-source').tap()
await pick(page, tid(page, 'm-create-source-library'), [{ name: 'huge.png', mimeType: 'image/png', buffer: Buffer.alloc(31 * 1024 * 1024, 1) }])
await expect(tid(page, 'm-create-source-error')).toContainText('The limit is 30 MB')
await expect(tid(page, 'm-create-source-error')).toContainText('Choose a smaller one')
await expectLayout(page, 'K5 error')
// Not an image at all.
await pick(page, tid(page, 'm-create-source-file'), [{ name: 'notes.pdf', mimeType: 'application/pdf', buffer: Buffer.from('%PDF-1.4') }])
await expect(tid(page, 'm-create-source-error')).toContainText('not a photo')
// A HEIC this WebView cannot decode: said so, with the next step.
await pick(page, tid(page, 'm-create-source-library'), [{ name: 'IMG_0001.HEIC', mimeType: 'image/heic', buffer: Buffer.from('not a real heic file at all') }])
await expect(tid(page, 'm-create-source-error')).toContainText('HEIC')
expect(cloud.uploads).toHaveLength(0)
// A HEIC the WebView can decode is taken, encoded as JPEG and uploaded.
await pick(page, tid(page, 'm-create-source-library'), [{ name: 'IMG_0002.HEIC', mimeType: 'image/heic', buffer: png(320, 240) }])
await expect(tid(page, 'm-create-source')).toBeVisible()
await run(page)
await expectResult(page, 'image')
expect(cloud.uploads[0].head.slice(0, 2)).toEqual([0xff, 0xd8])
})
test('a very large photo is scaled down before it is sent', async ({ page }) => {
const cloud = new Cloud()
await openCreate(page, cloud)
await chooseTool(page, 'removebg')
await addSource(page, [photo('pano.png', 0, 6000, 1500)])
await expect(tid(page, 'm-create-source')).toContainText('4096')
await expect(tid(page, 'm-create-source')).toContainText('1024')
})
test('upload refused by the server as too large: the notice says what to do', async ({ page }) => {
const cloud = new Cloud()
await openCreate(page, cloud)
await chooseTool(page, 'removebg')
await addSource(page, [photo('cat.png')])
cloud.uploadReplies.push({ status: 413, body: { error: 'File too large for upload.' } })
await run(page)
await expect(tid(page, 'm-create-error')).toContainText('This file is too large')
await expect(tid(page, 'm-create-error-action')).toHaveText('Choose another')
cloud.uploadReplies.push({ status: 415, body: { error: 'Unsupported file type.' } })
await tid(page, 'm-create-error-dismiss').tap()
await run(page)
await expect(tid(page, 'm-create-error')).toContainText('This file type is not supported')
})
test('content policy: a blocked prompt is said under the field and nothing is charged', async ({ page }) => {
const cloud = new Cloud()
await openCreate(page, cloud)
await typePrompt(page, 'something the server refuses')
cloud.submitReplies.push({ status: 400, body: { error: 'This prompt was blocked by the content policy.' } })
await run(page)
await expect(tid(page, 'm-create-prompt-blocked')).toBeVisible()
await expect(tid(page, 'm-create-prompt')).toHaveValue('something the server refuses')
await expect(tid(page, 'm-create-credits')).toContainText('2,000,000')
await expectLayout(page, 'K1 policy')
// A job the server ends for the same reason.
cloud.outcome = { status: 'failed', error: 'Blocked by the provider safety filter.' }
await typePrompt(page, 'another try')
await run(page)
await expect(tid(page, 'm-create-error')).toContainText('blocked by the content policy')
await expect(tid(page, 'm-create-error')).toContainText('not charged')
})
test('a failed run says so, keeps the input and can be tried again', async ({ page }) => {
const cloud = new Cloud()
cloud.outcome = { status: 'failed', error: 'The GPU ran out of memory.' }
await openCreate(page, cloud)
await typePrompt(page, 'fails once')
await run(page)
await expect(tid(page, 'm-create-error')).toContainText('This run failed. You were not charged.')
await expect(tid(page, 'm-create-error')).toContainText('The GPU ran out of memory.')
await expect(stage(page)).toHaveAttribute('data-state', 'failed')
cloud.outcome = { status: 'succeeded' }
await tid(page, 'm-create-error-action').tap()
await expectResult(page, 'image')
})
test('signed out at the server: the notice leads to the account, the prompt stays', async ({ page }) => {
const cloud = new Cloud()
await openCreate(page, cloud)
await typePrompt(page, 'who am I')
cloud.submitReplies.push({ status: 401, body: { error: 'unauthorized' } })
await run(page)
await expect(tid(page, 'm-create-error')).toContainText('You are signed out', { timeout: 20_000 })
await expect(tid(page, 'm-create-error-action')).toHaveText('Sign in')
await expect(tid(page, 'm-create-prompt')).toHaveValue('who am I')
})
test('result address expired: it is signed again; a result that is gone says so', async ({ page }) => {
const cloud = new Cloud()
await openCreate(page, cloud)
await typePrompt(page, 'kept for a while')
await run(page)
await expectResult(page, 'image')
// An hour later the address no longer answers.
cloud.resign()
await tid(page, 'm-create-gallery').tap()
const tile = tid(page, 'm-create-gallery-tile')
await expect(tile).toHaveAttribute('data-state', 'ok', { timeout: 20_000 })
await expect(tile.locator('img')).toHaveJSProperty('complete', true)
await expect.poll(() => tile.locator('img').evaluate((img: HTMLImageElement) => img.naturalWidth)).toBeGreaterThan(0)
expect(cloud.paths.filter((p) => p === 'GET /api/jobs/job-1').length).toBeGreaterThan(1)
// Seven days later the cloud copy is deleted.
cloud.resultsGone = true
await page.reload()
await page.getByTestId('m-app').waitFor()
await screensLoaded(page)
await backToCreateTab(page)
await expect(tid(page, 'm-create-gallery-tile')).toHaveAttribute('data-state', 'expired', { timeout: 20_000 })
await expectLayout(page, 'K6 expired')
await tid(page, 'm-create-gallery-item').tap()
await expect(tid(page, 'm-create-item-state')).toContainText('Expired')
await expect(tid(page, 'm-create-item-save')).toBeDisabled()
await tid(page, 'm-create-item-close').tap()
await tid(page, 'm-create-gallery-remove').tap()
await expect(tid(page, 'm-create-gallery-empty')).toBeVisible()
})
// ---------- save, share, use again ----------
test('save and share go through the platform seam', async ({ page }) => {
const cloud = new Cloud()
await openCreate(page, cloud)
await typePrompt(page, 'worth keeping')
await run(page)
await expectResult(page, 'image')
const [download] = await Promise.all([page.waitForEvent('download'), tid(page, 'm-create-result-save').tap()])
expect(download.suggestedFilename()).toMatch(/^lu-\d{8}-\d{4}-\w+\.png$/)
await expect(tid(page, 'm-toast-create-saved')).toBeVisible()
await tid(page, 'm-create-result-share').tap()
await expect.poll(() => page.evaluate(() => (window as unknown as { __shared: { name: string; type: string; size: number }[] }).__shared)).toHaveLength(1)
const shared = await page.evaluate(() => (window as unknown as { __shared: { name: string; type: string; size: number }[] }).__shared[0])
expect(shared.type).toBe('image/png')
expect(shared.size).toBe(RESULT_PNG.length)
await expect(tid(page, 'm-toast-create-shared')).toBeVisible()
// The same from the viewer.
await tid(page, 'm-create-result-open').tap()
const [again] = await Promise.all([page.waitForEvent('download'), tid(page, 'm-create-item-save').tap()])
expect(again.suggestedFilename()).toMatch(/\.png$/)
await tid(page, 'm-create-item-share').tap()
await expect.poll(() => page.evaluate(() => (window as unknown as { __shared: unknown[] }).__shared.length)).toBe(2)
})
test('Feinschliff: a cut-out has a checkerboard behind it on the stage and in the result view, not around it', async ({ page }) => {
const cloud = new Cloud()
await openCreate(page, cloud)
await typePrompt(page, 'a solid picture')
await run(page)
await expectResult(page, 'image')
// A solid picture covers the board completely: nothing of it shows (the corner pixel is the picture).
await expect(tid(page, 'm-create-result-open').getByTestId('m-create-checker')).toHaveCount(1)
cloud.resultPng = pngCutOut(300, 200)
await chooseTool(page, 'removebg')
await addSource(page, [photo('cat.png')])
await run(page)
const board = tid(page, 'm-create-result-open').getByTestId('m-create-checker')
await expect(board).toBeVisible({ timeout: 20_000 })
// The board lies under the picture only: its size is the size the picture is drawn in.
const pic = await tid(page, 'm-create-result-open').locator('img').boundingBox()
const box = await board.boundingBox()
expect(Math.abs((box!.width / box!.height) - 1.5)).toBeLessThan(0.02)
expect(box!.width).toBeLessThanOrEqual(pic!.width + 1)
expect(box!.height).toBeLessThanOrEqual(pic!.height + 1)
expect(await tid(page, 'm-create-result-open').locator('img').evaluate((el) => getComputedStyle(el).backgroundColor)).toBe('rgba(0, 0, 0, 0)')
await page.screenshot({ path: test.info().outputPath('cut-out-stage.png') })
await tid(page, 'm-create-result-open').tap()
const inViewer = tid(page, 'm-create-item-stage').getByTestId('m-create-checker')
await expect(inViewer).toBeVisible()
const v = await inViewer.boundingBox()
expect(Math.abs((v!.width / v!.height) - 1.5)).toBeLessThan(0.02)
await page.screenshot({ path: test.info().outputPath('cut-out-viewer.png') })
})
test('a result becomes the source of the next tool', async ({ page }) => {
const cloud = new Cloud()
await openCreate(page, cloud)
await typePrompt(page, 'first picture')
await run(page)
await expectResult(page, 'image')
await tid(page, 'm-create-result-edit').tap()
await expect(stage(page)).toHaveAttribute('data-m-tool', 'edit')
await expect(tid(page, 'm-create-source')).toBeVisible()
await expect(tid(page, 'm-create-source')).toContainText('256')
// From the result sheet: remove the background of it.
await tid(page, 'm-create-gallery').tap()
await tid(page, 'm-create-gallery-item').tap()
await tid(page, 'm-create-item-more').tap()
await expect(tid(page, 'm-sheet-result')).toBeVisible()
await expectLayout(page, 'K8')
await tid(page, 'm-create-result-removebg').tap()
await expect(tid(page, 'm-create-screen')).toBeVisible()
await expect(stage(page)).toHaveAttribute('data-m-tool', 'removebg')
await expect(tid(page, 'm-create-source')).toBeVisible()
await run(page)
await expectResult(page, 'image')
expect(cloud.uploads.map((u) => u.role)).toEqual(['source'])
// The source sheet offers the gallery too.
await tid(page, 'm-create-source-remove').tap()
await tid(page, 'm-create-add-source').tap()
await tid(page, 'm-create-source-gallery').tap()
await expect(tid(page, 'm-create-gallery-pick-screen')).toBeVisible()
await tid(page, 'm-create-gallery-item').first().tap()
await tid(page, 'm-create-gallery-use').tap()
await expect(tid(page, 'm-create-source')).toBeVisible()
})
// ---------- gallery and viewer ----------
test('gallery: filter, select several, save and delete', async ({ page }) => {
const cloud = new Cloud()
await openCreate(page, cloud)
await typePrompt(page, 'two pictures')
await tid(page, 'm-create-settings').tap()
await tid(page, 'm-create-count-2').tap()
await tid(page, 'm-sheet-close').tap()
await run(page)
await expectResult(page, 'image')
await chooseTool(page, 'music')
await typePrompt(page, 'a tune')
await run(page)
await expectResult(page, 'audio')
await tid(page, 'm-create-gallery').tap()
await expect(tid(page, 'm-create-gallery-item')).toHaveCount(3)
await tid(page, 'm-create-gallery-filter-audio').tap()
await expect(tid(page, 'm-create-gallery-item')).toHaveCount(1)
await tid(page, 'm-create-gallery-filter-video').tap()
await expect(tid(page, 'm-create-gallery-empty')).toBeVisible()
await tid(page, 'm-create-gallery-filter-image').tap()
await expect(tid(page, 'm-create-gallery-item')).toHaveCount(2)
await tid(page, 'm-create-gallery-filter-all').tap()
await tid(page, 'm-create-gallery-select').tap()
await expect(tid(page, 'm-create-gallery-delete')).toBeDisabled()
await tid(page, 'm-create-gallery-item').nth(0).tap()
await tid(page, 'm-create-gallery-item').nth(1).tap()
await expect(tid(page, 'm-create-gallery-selbar')).toContainText('2')
await expectLayout(page, 'K6 selecting')
const downloads: string[] = []
page.on('download', (d) => downloads.push(d.suggestedFilename()))
await tid(page, 'm-create-gallery-save').tap()
await expect(tid(page, 'm-toast-create-saved')).toBeVisible()
expect(downloads).toHaveLength(2)
await tid(page, 'm-create-gallery-select').tap()
await tid(page, 'm-create-gallery-item').nth(0).tap()
await tid(page, 'm-create-gallery-item').nth(2).tap()
await tid(page, 'm-create-gallery-delete').tap()
await expect(tid(page, 'm-dialog-create-gallery-delete')).toBeVisible()
await tid(page, 'm-dialog-cancel').tap()
await expect(tid(page, 'm-create-gallery-item')).toHaveCount(3)
await tid(page, 'm-create-gallery-delete').tap()
await tid(page, 'm-dialog-confirm').tap()
await expect(tid(page, 'm-create-gallery-item')).toHaveCount(1)
expect(await galleryCount(page)).toBe(1)
})
test('gallery with 200 entries: tiles ask for their media only near the screen', async ({ page }) => {
const cloud = new Cloud()
await openCreate(page, cloud)
await typePrompt(page, 'the first of many')
await run(page)
await expectResult(page, 'image')
await expect.poll(() => galleryCount(page)).toBe(1)
await page.evaluate(() => {
const store = JSON.parse(localStorage.getItem('create-store') ?? '{}') as { state: { gallery: Record<string, unknown>[] } }
const first = store.state.gallery[0]
store.state.gallery = Array.from({ length: 200 }, (_, i) => ({ ...first, id: i === 0 ? first.id : `copy-${i}`, createdAt: Date.now() - i * 1000 }))
localStorage.setItem('create-store', JSON.stringify(store))
})
await page.reload()
await page.getByTestId('m-app').waitFor()
await screensLoaded(page)
if (!(await tid(page, 'm-create-screen').isVisible())) {
if (await tid(page, 'm-page-back').first().isVisible()) await tid(page, 'm-page-back').first().tap()
await tid(page, 'm-nav-create').tap()
}
await tid(page, 'm-create-gallery').tap()
await expect(tid(page, 'm-create-gallery-grid')).toHaveAttribute('data-m-count', '200')
await expect(tid(page, 'm-create-gallery-item')).toHaveCount(200)
const grid = tid(page, 'm-create-gallery-grid')
await expect(grid.locator('img').first()).toBeVisible()
const early = await grid.locator('img').count()
expect(early).toBeGreaterThan(0)
expect(early).toBeLessThan(80)
// Scrolling to the end brings the last tiles in.
const started = Date.now()
await tid(page, 'm-create-gallery-item').last().scrollIntoViewIfNeeded()
await expect(tid(page, 'm-create-gallery-tile').last().locator('img')).toBeVisible()
expect(Date.now() - started).toBeLessThan(5000)
await expectLayout(page, 'K6 200')
})
// Check 4 on Android, F13: the stage of the viewer took a tap and did nothing.
test('viewer: one tap on the picture gives it the whole screen, one more brings the bars back, a double tap still zooms', async ({ page }) => {
const cloud = new Cloud()
await openCreate(page, cloud)
await typePrompt(page, 'whole screen')
await run(page)
await expectResult(page, 'image')
await tid(page, 'm-create-result-open').tap()
const frame = tid(page, 'm-create-item-stage')
const screen = tid(page, 'm-create-item-screen')
await expect(frame.locator('img')).toBeVisible()
const before = (await frame.boundingBox())!.height
await frame.tap()
await expect(screen).toHaveAttribute('data-m-whole', '')
await expect(tid(page, 'm-create-item-close')).toBeHidden()
await expect(tid(page, 'm-create-item-save')).toBeHidden()
expect((await frame.boundingBox())!.height).toBeGreaterThan(before + 40)
await page.waitForTimeout(350)
await frame.tap()
await expect(screen).not.toHaveAttribute('data-m-whole', '')
await expect(tid(page, 'm-create-item-close')).toBeVisible()
await expect(tid(page, 'm-create-item-save')).toBeVisible()
// Two quick taps: the bars are where they were, and the picture is zoomed.
await page.waitForTimeout(350)
await frame.tap()
await frame.tap()
await expect(frame).toHaveAttribute('data-m-zoom', '2.50')
await expect(screen).not.toHaveAttribute('data-m-whole', '')
})
test('viewer: zoom with two fingers and the button, step through, show the prompt', async ({ page }) => {
const cloud = new Cloud()
await openCreate(page, cloud)
await typePrompt(page, 'look closer')
await tid(page, 'm-create-settings').tap()
await tid(page, 'm-create-count-2').tap()
await tid(page, 'm-sheet-close').tap()
await run(page)
await expectResult(page, 'image')
await tid(page, 'm-create-result-open').tap()
const frame = tid(page, 'm-create-item-stage')
await expect(frame.locator('img')).toBeVisible()
await expect(frame).toHaveAttribute('data-m-zoom', '1.00')
await tid(page, 'm-create-item-zoom').tap()
await expect(frame).toHaveAttribute('data-m-zoom', '2.50')
await tid(page, 'm-create-item-zoom').tap()
await expect(frame).toHaveAttribute('data-m-zoom', '1.00')
await page.evaluate(() => {
const el = document.querySelector('[data-testid="m-create-item-stage"]')!
const r = el.getBoundingClientRect()
const send = (type: string, id: number, x: number) =>
el.dispatchEvent(new PointerEvent(type, { pointerId: id, pointerType: 'touch', bubbles: true, clientX: r.left + x * r.width, clientY: r.top + r.height / 2 }))
send('pointerdown', 1, 0.4)
send('pointerdown', 2, 0.6)
send('pointermove', 1, 0.3)
send('pointermove', 2, 0.7)
send('pointerup', 1, 0.3)
send('pointerup', 2, 0.7)
})
await expect(frame).toHaveAttribute('data-m-zoom', '2.00')
await tid(page, 'm-create-item-zoom').tap()
await expect(tid(page, 'm-create-item-position')).toContainText('of 2')
const first = await tid(page, 'm-create-item-position').textContent()
await tid(page, first?.startsWith('1') ? 'm-create-item-next' : 'm-create-item-prev').tap()
await expect(tid(page, 'm-create-item-position')).not.toHaveText(first ?? '')
await tid(page, 'm-create-item-prompt').tap()
await expect(tid(page, 'm-create-item-prompt-text')).toContainText('look closer')
await expectLayout(page, 'K7 prompt')
await tid(page, 'm-create-item-more').tap()
await tid(page, 'm-create-result-delete').tap()
await tid(page, 'm-dialog-confirm').tap()
await expect.poll(() => galleryCount(page)).toBe(1)
})
// ---------- store rules: report, consent, buying ----------
test('report: every result can be reported, the report stays on the phone', async ({ page }) => {
const cloud = new Cloud()
await openCreate(page, cloud)
await typePrompt(page, 'reportable')
await run(page)
await expectResult(page, 'image')
const reports = () => page.evaluate(() => JSON.parse(localStorage.getItem('lu-mobile-report-queue') ?? '[]') as { kind: string; contentId: string; model: string; source: string }[])
/** The report sheet of the scaffold: pick a reason, send. */
const sendReport = async () => {
await expect(tid(page, 'm-sheet-report')).toBeVisible()
await page.locator('[data-testid^="m-report-reason-"]').first().tap()
await tid(page, 'm-report-send').tap()
await expect(tid(page, 'm-sheet-report')).toHaveCount(0)
}
await tid(page, 'm-create-result-report').tap()
await expect(tid(page, 'm-sheet-report')).toBeVisible()
await expectLayout(page, 'report sheet')
await tid(page, 'm-sheet-close').tap()
await expect(tid(page, 'm-sheet-report')).toHaveCount(0)
expect(await reports()).toHaveLength(0)
await tid(page, 'm-create-result-report').tap()
await sendReport()
await expect(page.locator('[data-testid^="m-toast-report-"]')).toBeVisible()
expect(await reports()).toEqual([expect.objectContaining({ kind: 'image', contentId: 'job-1', model: 'z-image-turbo', source: 'cloud' })])
// The viewer and the result sheet have the action too.
await tid(page, 'm-create-result-open').tap()
await tid(page, 'm-create-item-report').tap()
await sendReport()
await expect.poll(async () => (await reports()).length).toBe(2)
await tid(page, 'm-create-item-more').tap()
await tid(page, 'm-create-result-report-row').tap()
await sendReport()
await expect.poll(async () => (await reports()).length).toBe(3)
// Nothing about it went to the server.
expect(cloud.paths.filter((p) => /report|flag|abuse/i.test(p))).toEqual([])
})
test('report: sound and video carry the action as well', async ({ page }) => {
const cloud = new Cloud()
await openCreate(page, cloud)
await chooseTool(page, 'video')
await typePrompt(page, 'a clip')
await run(page)
await expectResult(page, 'video')
await expect(tid(page, 'm-create-result-report')).toBeVisible()
await tid(page, 'm-create-result-fullscreen').tap()
await expect(tid(page, 'm-create-item-report')).toBeVisible()
await tid(page, 'm-create-item-close').tap()
await chooseTool(page, 'music')
await typePrompt(page, 'a tune')
await run(page)
await expectResult(page, 'audio')
await tid(page, 'm-create-result-report').tap()
await page.locator('[data-testid^="m-report-reason-"]').first().tap()
await tid(page, 'm-report-send').tap()
await expect(tid(page, 'm-sheet-report')).toHaveCount(0)
const stored = await page.evaluate(() => JSON.parse(localStorage.getItem('lu-mobile-report-queue') ?? '[]') as { kind: string }[])
expect(stored.map((r) => r.kind)).toEqual(['audio'])
})
test('consent: asked before the first cloud job; a no starts nothing and keeps the input', async ({ page }) => {
const cloud = new Cloud()
await openCreate(page, cloud, { consent: false })
await typePrompt(page, 'ask me first')
await run(page)
await expect(tid(page, 'm-sheet-ai-consent')).toBeVisible()
await expectLayout(page, 'consent sheet')
await tid(page, 'm-consent-decline').tap()
await expect(stage(page)).toHaveAttribute('data-state', 'empty')
await expect(tid(page, 'm-create-prompt')).toHaveValue('ask me first')
expect(cloud.submits).toHaveLength(0)
expect(cloud.uploads).toHaveLength(0)
await run(page)
await tid(page, 'm-consent-agree').tap()
await expectResult(page, 'image')
expect(cloud.submits).toHaveLength(1)
// Agreed once: the next run starts at once.
await run(page)
await expect.poll(() => cloud.submits.length).toBe(2)
await expect(tid(page, 'm-sheet-ai-consent')).toHaveCount(0)
})
for (const mode of ['links', 'text-only', 'none'] as const) {
test(`buying, mode ${mode}: the empty wallet follows the store rule`, async ({ page }) => {
const cloud = new Cloud()
await openCreate(page, cloud, { policy: { purchase: mode } })
await typePrompt(page, 'no credits')
cloud.submitReplies.push({ status: 429, body: { error: 'credits exhausted', code: 'credits_exhausted' } })
await run(page)
// The sheet about the empty wallet belongs to strand 5 and follows the same rule there. Here it is only closed.
await expect(tid(page, 'm-sheet-credits')).toBeVisible()
await tid(page, 'm-sheet-close').tap()
await expect(tid(page, 'm-sheet-credits')).toHaveCount(0)
const notice = tid(page, 'm-create-error')
await expect(notice).toBeVisible()
await expect(page.locator('[data-m-kind="credits"]')).toHaveAttribute('data-m-purchase', mode)
if (mode === 'links') {
await expect(tid(page, 'm-create-error-action')).toHaveText('See plans')
} else {
await expect(tid(page, 'm-create-error-action')).toHaveCount(0)
await expect(notice.locator('a')).toHaveCount(0)
const text = (await notice.textContent()) ?? ''
if (mode === 'text-only') expect(text).toContain('Plans and credits are available on lu-labs.ai.')
else expect(text).not.toMatch(/plan|buy|upgrade|top.?up|purchase|price|web/i)
}
await expectLayout(page, `credits ${mode}`)
})
test(`buying, mode ${mode}: no plan on the account`, async ({ page }) => {
const cloud = new Cloud()
cloud.license = 'none'
await openCreate(page, cloud, { policy: { purchase: mode } })
const gate = tid(page, 'm-create-gate')
await expect(gate).toHaveAttribute('data-state', 'no-plan')
await expect(gate).toHaveAttribute('data-m-purchase', mode)
await expect(tid(page, 'm-create-gate-action')).toHaveCount(mode === 'links' ? 1 : 0)
const text = (await gate.textContent()) ?? ''
if (mode === 'none') expect(text).not.toMatch(/plan|buy|upgrade|purchase|price/i)
if (mode === 'text-only') expect(text).toContain('Plans and credits are available on lu-labs.ai.')
await expectLayout(page, `gate no plan ${mode}`)
await tid(page, 'm-create-gate-showcase').tap()
await expect(tid(page, 'm-create-showcase-screen')).toBeVisible()
await expect(tid(page, 'm-create-showcase-plans')).toHaveCount(mode === 'links' ? 1 : 0)
await expect(tid(page, 'm-create-showcase-plans-text')).toHaveCount(mode === 'text-only' ? 1 : 0)
if (mode === 'links') {
await tid(page, 'm-create-showcase-plans').tap()
await expect(tid(page, 'm-cloud-screen')).toBeVisible()
}
})
}
// ---------- the gate ----------
test('not signed in: the cloud gate instead of a dead page, and the showcase', async ({ page }) => {
const cloud = new Cloud()
cloud.signedIn = false
await openCreate(page, cloud)
await expect(tid(page, 'm-create-gate')).toHaveAttribute('data-state', 'signed-out')
await expect(tid(page, 'm-create-prompt')).toHaveCount(0)
await expectLayout(page, 'K1 gate')
await tid(page, 'm-create-gate-showcase').tap()
await expect(tid(page, 'm-create-showcase-screen')).toBeVisible()
await expect(tid(page, 'm-create-showcase-card')).toHaveCount(12)
// The first card shows a picture that loads, not an icon on a colour field.
const firstArt = page.locator('[data-testid="m-create-showcase-card"][data-m-id="image"] img')
await expect(firstArt).toHaveCount(1)
await expect.poll(() => firstArt.evaluate((el) => (el as HTMLImageElement).naturalWidth)).toBeGreaterThan(0)
await expectLayout(page, 'K13')
await tid(page, 'm-create-showcase-cloud').tap()
await expect(tid(page, 'm-cloud-screen')).toBeVisible()
expect(cloud.submits).toHaveLength(0)
})
test('cloud switched off: the gate leads to the cloud page', async ({ page }) => {
const cloud = new Cloud()
await openCreate(page, cloud, { appMode: 'local' })
await expect(tid(page, 'm-create-gate')).toHaveAttribute('data-state', 'cloud-off')
await tid(page, 'm-create-gate-action').tap()
await expect(tid(page, 'm-cloud-screen')).toBeVisible()
})
// ---------- every remaining control leads somewhere ----------
test('tools: What in the run settings switches the tool, the source card opens the source sheet', async ({ page }) => {
const cloud = new Cloud()
await openCreate(page, cloud)
// Prompt v2: no tool row above the field. The tool is the first part of the summary and the row "What".
await expect(tid(page, 'm-create-tools')).toHaveCount(0)
for (const tool of ['video', 'removebg', 'upscale', 'eraser', 'animate', 'character', 'lipsync', 'music', 'extend', 'motion', 'image']) {
await chooseTool(page, tool)
await openRunRow(page, 'm-create-tools-all')
await expect(tid(page, `m-create-tools-${tool}`)).toHaveAttribute('aria-checked', 'true')
await tid(page, 'm-sheet-close').tap()
}
// The four tools whose names the sweep of the acceptance frame refuses carry the mark on the element in the
// sheet. The other tools do not (acceptance Android, N9).
const MARKED = ['animate', 'eraser', 'extend', 'removebg']
const marksOf = (prefix: string) =>
page.evaluate(
({ prefix, names }) => names.map((name) => document.querySelector(`[data-testid="${prefix}-${name}"]`)?.getAttribute('data-m-risk') ?? null),
{ prefix, names: [...MARKED, 'image', 'video', 'upscale'] },
)
await openRunRow(page, 'm-create-tools-all')
await expect(tid(page, 'm-create-tools-grid')).toBeVisible()
expect(await marksOf('m-create-tools')).toEqual(['paid', 'paid', 'paid', 'paid', null, null, null])
await tid(page, 'm-sheet-close').tap()
await expect(tid(page, 'm-create-tools-grid')).toHaveCount(0)
// Count and quality of an image run.
await tid(page, 'm-create-settings').tap()
await tid(page, 'm-create-count-4').tap()
await tid(page, 'm-create-quality-draft').tap()
await tid(page, 'm-sheet-close').tap()
await expect(tid(page, 'm-create-settings')).toContainText('4 images')
await expect(tid(page, 'm-create-settings')).toContainText('Draft')
await tid(page, 'm-create-settings').tap()
await tid(page, 'm-create-count-1').tap()
await tid(page, 'm-create-quality-standard').tap()
await tid(page, 'm-sheet-close').tap()
await expect(tid(page, 'm-create-settings')).toContainText('1 image')
await expect(tid(page, 'm-create-settings')).toContainText('Standard')
await chooseTool(page, 'edit')
await tid(page, 'm-create-source-add').tap()
await expect(tid(page, 'm-sheet-source')).toBeVisible()
// The camera is the first way in.
await pick(page, tid(page, 'm-create-source-take'), [photo('shot.png')])
await expect(tid(page, 'm-create-source')).toContainText('640')
// The source opens large and closes again.
await tid(page, 'm-create-source-open').tap()
await expect(tid(page, 'm-create-item-screen')).toBeVisible()
await tid(page, 'm-create-item-close').tap()
await expect(tid(page, 'm-create-screen')).toBeVisible()
// A painted mask can be taken off again.
await tid(page, 'm-create-paint-mask').tap()
await expect(tid(page, 'm-create-mask-screen')).toHaveAttribute('data-state', 'ready')
await paint(page, [[0.4, 0.5], [0.6, 0.5]])
await tid(page, 'm-create-mask-done').tap()
await expect(tid(page, 'm-create-source')).toHaveAttribute('data-state', 'masked')
await tid(page, 'm-create-mask-remove').tap()
await expect(tid(page, 'm-create-source')).toHaveAttribute('data-state', 'plain')
})
test('improve my prompt: the helper model rewrites the prompt before the run', async ({ page }) => {
const cloud = new Cloud()
cloud.improved = 'a red fox in deep snow, golden hour, 85mm, shallow depth of field'
await openCreate(page, cloud)
await typePrompt(page, 'a fox')
await tid(page, 'm-create-settings').tap()
await tid(page, 'm-create-improve').tap()
await expect(tid(page, 'm-create-improve')).toHaveAttribute('aria-checked', 'true')
await tid(page, 'm-sheet-close').tap()
await run(page)
await expectResult(page, 'image')
expect(cloud.chats).toHaveLength(1)
expect(JSON.stringify(cloud.chats[0])).toContain('a fox')
expect(cloud.submits[0].prompt).toBe(cloud.improved)
// What the user typed stays in the field, the result shows what was rendered.
await expect(tid(page, 'm-create-prompt')).toHaveValue('a fox')
await tid(page, 'm-create-result-open').tap()
await tid(page, 'm-create-item-prompt').tap()
await expect(tid(page, 'm-create-item-prompt-text')).toContainText('golden hour')
await tid(page, 'm-create-item-prompt-copy').tap()
await expect(tid(page, 'm-toast-create-copied')).toBeVisible()
})
test('prompt history: one entry can be removed, all can be cleared', async ({ page }) => {
const cloud = new Cloud()
await openCreate(page, cloud)
for (const text of ['first idea', 'second idea']) {
await typePrompt(page, text)
await run(page)
await expectResult(page, 'image')
}
await tid(page, 'm-create-settings').tap()
await tid(page, 'm-create-history-open').tap()
await expect(tid(page, 'm-create-history-row')).toHaveCount(2)
await tid(page, 'm-create-history-remove').first().tap()
await expect(tid(page, 'm-create-history-row')).toHaveCount(1)
await tid(page, 'm-create-history-clear').tap()
await expect(tid(page, 'm-dialog-create-history-clear')).toBeVisible()
await tid(page, 'm-dialog-confirm').tap()
await expect(tid(page, 'm-create-history-empty')).toBeVisible()
})
test('run settings: strength of an edit and the size of Enhance reach the server', async ({ page }) => {
const cloud = new Cloud()
await openCreate(page, cloud)
await chooseTool(page, 'edit')
await pickModel(page, 'qwen-image-edit')
await addSource(page, [photo('room.png')])
await typePrompt(page, 'make it night')
await tid(page, 'm-create-settings').tap()
await tid(page, 'm-create-strength').fill('0.3')
await tid(page, 'm-sheet-close').tap()
await run(page)
await expectResult(page, 'image')
expect(Number(cloud.submits[0].params.denoise ?? cloud.submits[0].params.strength)).toBeCloseTo(0.3, 2)
await chooseTool(page, 'upscale')
await tid(page, 'm-create-settings').tap()
await tid(page, 'm-create-size-8k').tap()
await tid(page, 'm-sheet-close').tap()
await expect(tid(page, 'm-create-settings')).toContainText('8K')
await expect(tid(page, 'm-create-enhance-8k')).toHaveAttribute('aria-checked', 'true')
await tid(page, 'm-create-enhance-2k').tap()
await expect(tid(page, 'm-create-settings')).toContainText('2K')
await tid(page, 'm-create-settings').tap()
await expect(tid(page, 'm-create-size-2k')).toHaveAttribute('aria-checked', 'true')
await tid(page, 'm-create-size-4k').tap()
await tid(page, 'm-create-size-2k').tap()
await tid(page, 'm-sheet-close').tap()
await expect(tid(page, 'm-create-settings')).toContainText('2K')
await tid(page, 'm-create-enhance-8k').tap()
await expect(tid(page, 'm-create-settings')).toContainText('8K')
await tid(page, 'm-create-enhance-2k').tap()
await run(page)
await expectResult(page, 'image')
expect(cloud.submits[1].params).toMatchObject({ op: 'upscale', target_resolution: '2k' })
// A tool without settings says so instead of showing an empty sheet.
await chooseTool(page, 'removebg')
await tid(page, 'm-create-settings').tap()
await expect(tid(page, 'm-create-settings-none')).toBeVisible()
})
test('model settings: the controls of a model that brings its own', async ({ page }) => {
const cloud = new Cloud()
cloud.studio = true
await openCreate(page, cloud)
await pickModel(page, 'nucleus-image')
await typePrompt(page, 'a quoted picture')
await tid(page, 'm-create-settings').tap()
await tid(page, 'm-create-model-settings-open').tap()
await expect(tid(page, 'm-create-model-settings')).toBeVisible()
await expectLayout(page, 'K4 model settings')
await tid(page, 'm-create-opt-aspect-ratio').tap()
await expect(tid(page, 'm-create-opt-picker')).toBeVisible()
await tid(page, 'm-create-opt-choice').filter({ hasText: '16:9' }).tap()
await expect(tid(page, 'm-create-opt-aspect-ratio')).toContainText('16:9')
await tid(page, 'm-create-opt-output-format').getByRole('radio', { name: 'jpeg' }).tap()
await tid(page, 'm-create-opt-seed-random').tap()
await expect(tid(page, 'm-create-opt-seed')).not.toHaveValue('0')
const seed = Number(await tid(page, 'm-create-opt-seed').inputValue())
await tid(page, 'm-create-opt-guidance-scale').fill('5')
await tid(page, 'm-sheet-close').tap()
await expect(tid(page, 'm-create-price')).toHaveText('1,500', { timeout: 20_000 })
await run(page)
await expectResult(page, 'image')
const sent = JSON.stringify(cloud.submits[0].params)
expect(sent).toContain('16:9')
expect(sent).toContain('jpeg')
expect(sent).toContain(String(seed))
expect(JSON.stringify(cloud.quotes.at(-1))).toContain('16:9')
})
test('presenter: tiles with faces, grouped by person, the whole list on the way down, search', async ({ page }) => {
const cloud = new Cloud()
cloud.models = [...CATALOG_MODELS, HEYGEN_MODEL]
await openCreate(page, cloud)
await chooseTool(page, 'lipsync')
await pickModel(page, 'heygen-twin')
await tid(page, 'm-create-settings').tap()
await tid(page, 'm-create-model-settings-open').tap()
// The row shows the face of the presenter the model starts with.
const row = tid(page, 'm-create-opt-avatar')
await expect(row).toContainText('Abigail Sofa Front')
await expect(row.locator('img')).toHaveAttribute('src', /\/heygen-avatars\/abigail-sofa-front\.webp$/)
await row.tap()
const picker = tid(page, 'm-create-presenter-picker')
await expect(picker).toBeVisible()
// All 500 of the provider's list, not the first 200: a part is drawn, the rest follows.
expect(Number(await picker.getAttribute('data-m-total'))).toBe(500)
const faces = tid(page, 'm-create-presenter-face')
const first = await faces.count()
expect(first).toBeGreaterThanOrEqual(60)
expect(first).toBeLessThan(500)
// A face is a picture that really loaded.
const img = faces.first().locator('img')
await expect.poll(() => img.evaluate((el: HTMLImageElement) => el.complete && el.naturalWidth > 0)).toBe(true)
await expect(tid(page, 'm-create-presenter-person').first()).toContainText('Abigail')
await expectLayout(page, 'K4 presenter')
// The last entry of the list is reachable by scrolling alone.
await expect
.poll(
async () => {
await faces.last().scrollIntoViewIfNeeded()
return faces.count()
},
{ timeout: 30_000 },
)
.toBe(500)
await expect(tid(page, 'm-create-opt-more')).toHaveCount(0)
// Search by name, the person stands as a head above her scenes.
await tid(page, 'm-create-presenter-search').fill('annie')
await expect(tid(page, 'm-create-presenter-person')).toHaveCount(1)
await expect(tid(page, 'm-create-presenter-person')).toContainText('Annie')
const pickName = await faces.nth(1).getAttribute('data-m-id')
await faces.nth(1).tap()
await expect(picker).toHaveCount(0)
await expect(row).toContainText(String(pickName))
await row.tap()
await expect(page.locator(`[data-testid="m-create-presenter-face"][data-m-id="${pickName}"]`)).toHaveAttribute('aria-checked', 'true')
await tid(page, 'm-create-presenter-search').fill('zzzz')
await expect(tid(page, 'm-create-presenter-none')).toBeVisible()
})
test('list fields: style LoRAs are added, changed, weighted and removed, and go into the run', async ({ page }) => {
const cloud = new Cloud()
cloud.models = [...CATALOG_MODELS, LORA_MODEL]
await openCreate(page, cloud)
await chooseTool(page, 'animate')
await addSource(page, [photo('figure.png', 4)])
await pickModel(page, 'open-video-lora')
await typePrompt(page, 'she turns her head')
await tid(page, 'm-create-settings').tap()
await tid(page, 'm-create-model-settings-open').tap()
// A list field is a row that opens its editor, never a locked line.
const row = tid(page, 'm-create-opt-loras')
await expect(row).toBeEnabled()
await expect(row).toContainText('None')
await expect(tid(page, 'm-create-model-settings')).not.toContainText('cannot be set')
await row.tap()
await expect(tid(page, 'm-create-opt-list')).toBeVisible()
await expect(tid(page, 'm-create-opt-list-hint')).toContainText('up to 3')
await tid(page, 'm-create-opt-list-add').tap()
await tid(page, 'm-create-opt-list-add').tap()
await expect(tid(page, 'm-create-opt-list-row')).toHaveCount(2)
await expectLayout(page, 'K4 style LoRAs')
// Change the second one to another style.
await tid(page, 'm-create-opt-list-pick').nth(1).tap()
await tid(page, 'm-create-opt-choice').filter({ hasText: 'hardcut' }).tap()
await expect(tid(page, 'm-create-opt-list-row').nth(1)).toHaveAttribute('data-m-id', 'hardcut')
// Its strength.
await tid(page, 'm-create-opt-list-strength').nth(1).focus()
await page.keyboard.press('ArrowLeft')
await page.keyboard.press('ArrowLeft')
// A third, then the list is full and says so; remove the first.
await tid(page, 'm-create-opt-list-add').tap()
await expect(tid(page, 'm-create-opt-list-row')).toHaveCount(3)
await expect(tid(page, 'm-create-opt-list-add')).toBeDisabled()
await expect(tid(page, 'm-create-opt-list-add')).toContainText('3 is the most')
await tid(page, 'm-create-opt-list-remove').first().tap()
await expect(tid(page, 'm-create-opt-list-row')).toHaveCount(2)
await tid(page, 'm-sheet-back').tap()
await expect(row).toContainText('hardcut')
await tid(page, 'm-sheet-close').tap()
await expect(tid(page, 'm-create-price')).toHaveText('1,500', { timeout: 20_000 })
await run(page)
await expectResult(page, 'video')
const sent = cloud.submits[0].params.studio_options as { loras?: { path: string; scale: number }[] }
expect(sent.loras).toHaveLength(2)
expect(sent.loras?.[0]).toMatchObject({ path: 'hardcut', scale: 0.8 })
expect(JSON.stringify(cloud.quotes.at(-1))).toContain('hardcut')
})
test('music: the second text and the length go into the run', async ({ page }) => {
const cloud = new Cloud()
await openCreate(page, cloud)
await chooseTool(page, 'music')
await typePrompt(page, 'calm piano')
await tid(page, 'm-create-music-second').tap()
await tid(page, 'm-create-music-text').fill('la la la')
await tid(page, 'm-create-music-main').tap()
await expect(tid(page, 'm-create-music-text')).toHaveCount(0)
const before = await tid(page, 'm-create-price').textContent()
await tid(page, 'm-create-music-length').fill('120')
await expect(tid(page, 'm-create-price')).not.toHaveText(before ?? '')
await expect(tid(page, 'm-create-settings')).toContainText('2 min')
await run(page)
await expectResult(page, 'audio')
const sent = JSON.stringify(cloud.submits[0].params)
expect(sent).toContain('la la la')
expect(sent).toContain('120')
})
test('talking: a described voice, a named voice, a voice of the gallery, and taking it off', async ({ page }) => {
const cloud = new Cloud()
await openCreate(page, cloud)
await chooseTool(page, 'lipsync')
await addSource(page, [photo('face.png')])
await tid(page, 'm-create-voice-text').fill('Hello there.')
// Another tab unmounts the page. The words typed for the voice are still there afterwards.
await tid(page, 'm-nav-models').tap()
await tid(page, 'm-nav-create').tap()
await expect(tid(page, 'm-create-voice-text')).toHaveValue('Hello there.')
await tid(page, 'm-create-voice-mode-design').tap()
await tid(page, 'm-create-voice-description').fill('a warm old storyteller')
await tid(page, 'm-create-voice-speak').tap()
await expect(tid(page, 'm-create-voice')).toHaveAttribute('data-state', 'ready', { timeout: 20_000 })
expect(cloud.submits[0]).toMatchObject({ kind: 'audio', model: 'qwen3-tts-design', params: { op: 'tts' } })
expect(JSON.stringify(cloud.submits[0].params)).toContain('a warm old storyteller')
await tid(page, 'm-create-voice-remove').tap()
await expect(tid(page, 'm-create-voice')).toHaveAttribute('data-state', 'empty')
await tid(page, 'm-create-voice-text').fill('Hello again.')
await tid(page, 'm-create-voice-mode-speak').tap()
await tid(page, 'm-create-voice-name-dylan').tap()
await tid(page, 'm-create-voice-speak').tap()
await expect(tid(page, 'm-create-voice')).toHaveAttribute('data-state', 'ready', { timeout: 20_000 })
expect(cloud.submits[1]).toMatchObject({ kind: 'audio', model: 'qwen3-tts', params: { op: 'tts', voice: 'Dylan' } })
await tid(page, 'm-create-voice-remove').tap()
// A voice made earlier comes back from the gallery.
await tid(page, 'm-create-voice-gallery').tap()
await expect(tid(page, 'm-create-gallery-pick-screen')).toBeVisible()
await tid(page, 'm-create-gallery-item').first().tap()
await tid(page, 'm-create-gallery-use').tap()
await expect(tid(page, 'm-create-voice')).toHaveAttribute('data-state', 'ready')
await tid(page, 'm-create-voice-remove').tap()
// And from the result sheet of a sound.
await tid(page, 'm-create-gallery').tap()
await tid(page, 'm-create-gallery-item').first().tap()
await expect(tid(page, 'm-create-item-audio')).toBeVisible()
await tid(page, 'm-create-item-more').tap()
await tid(page, 'm-create-result-use-voice').tap()
await expect(tid(page, 'm-create-screen')).toBeVisible()
await expect(tid(page, 'm-create-voice')).toHaveAttribute('data-state', 'ready')
expect(cloud.submits).toHaveLength(2)
})
test('result sheet of an image: every row leads to its tool, a figure is kept as a character', async ({ page }) => {
const cloud = new Cloud()
await openCreate(page, cloud)
await typePrompt(page, 'a knight')
await run(page)
await expectResult(page, 'image')
await tid(page, 'm-create-result-animate').tap()
await expect(stage(page)).toHaveAttribute('data-m-tool', 'animate')
await expect(tid(page, 'm-create-source')).toBeVisible()
const openSheet = async () => {
await tid(page, 'm-create-gallery').tap()
await tid(page, 'm-create-gallery-item').first().tap()
await tid(page, 'm-create-item-more').tap()
await expect(tid(page, 'm-sheet-result')).toBeVisible()
}
await openSheet()
await tid(page, 'm-create-result-enhance').tap()
await expect(tid(page, 'm-create-screen')).toBeVisible()
await expect(stage(page)).toHaveAttribute('data-m-tool', 'upscale')
await openSheet()
await tid(page, 'm-create-result-animate-row').tap()
await expect(stage(page)).toHaveAttribute('data-m-tool', 'animate')
await openSheet()
await tid(page, 'm-create-result-use-source').tap()
await expect(stage(page)).toHaveAttribute('data-m-tool', 'edit')
await expect(tid(page, 'm-create-source')).toContainText('256')
await openSheet()
await tid(page, 'm-create-result-edit-mask').tap()
await expect(tid(page, 'm-create-mask-screen')).toHaveAttribute('data-state', 'ready')
await tid(page, 'm-create-mask-cancel').tap()
await expect(stage(page)).toHaveAttribute('data-m-tool', 'edit')
// Keep the figure, find it again in the source sheet, delete it.
await openSheet()
await tid(page, 'm-create-result-save-character').tap()
await expect(tid(page, 'm-create-save-character')).toBeVisible()
await expect(tid(page, 'm-create-save-character-save')).toBeEnabled({ timeout: 20_000 })
await tid(page, 'm-create-save-character-save').tap()
await expect(tid(page, 'm-create-save-character-error')).toBeVisible()
await tid(page, 'm-create-save-character-name').fill('Sir Test')
await tid(page, 'm-create-save-character-save').tap()
await expect(tid(page, 'm-toast-create-character-saved')).toBeVisible()
await tid(page, 'm-create-item-close').tap()
await back(page, 'm-create-gallery-screen')
await tid(page, 'm-create-source-remove').tap()
await tid(page, 'm-create-add-source').tap()
await tid(page, 'm-create-source-saved').tap()
await expect(tid(page, 'm-create-saved-row')).toHaveCount(1)
await expect(tid(page, 'm-create-saved-row')).toContainText('Sir Test')
await tid(page, 'm-create-saved-row').tap()
await expect(tid(page, 'm-create-source')).toBeVisible()
await tid(page, 'm-create-add-source').tap()
await tid(page, 'm-create-source-saved').tap()
await tid(page, 'm-create-saved-delete').tap()
await expect(tid(page, 'm-dialog-create-saved-delete')).toBeVisible()
await tid(page, 'm-dialog-confirm').tap()
await expect(tid(page, 'm-create-saved-empty')).toBeVisible()
expect(cloud.submits).toHaveLength(1)
})
// D-VW (check of package 17 on Android): after a phase with a full phone the web view refuses every write to
// IndexedDB until LU restarts. Saving a character then said the words of the engine; now it says what helps.
test('a character that IndexedDB refuses says that LU needs a restart', async ({ page }) => {
const cloud = new Cloud()
await openCreate(page, cloud)
await typePrompt(page, 'a knight')
await run(page)
await expectResult(page, 'image')
await tid(page, 'm-create-gallery').tap()
await tid(page, 'm-create-gallery-item').first().tap()
await tid(page, 'm-create-item-more').tap()
await tid(page, 'm-create-result-save-character').tap()
await expect(tid(page, 'm-create-save-character-save')).toBeEnabled({ timeout: 20_000 })
await page.evaluate(() => {
const original = IDBDatabase.prototype.transaction
IDBDatabase.prototype.transaction = function (this: IDBDatabase, ...args: Parameters<IDBDatabase['transaction']>) {
if (this.name === 'lu-saved-characters') throw new DOMException("Failed to execute 'transaction' on 'IDBDatabase': The database connection is closing.", 'InvalidStateError')
return original.apply(this, args)
} as IDBDatabase['transaction']
})
await tid(page, 'm-create-save-character-name').fill('Sir Test')
await tid(page, 'm-create-save-character-save').tap()
await expect(tid(page, 'm-create-save-character-error')).toContainText('LU could not save the character. LU needs a restart before it can save again.')
await expect(tid(page, 'm-toast-create-character-saved')).toHaveCount(0)
})
test('result sheet of a clip: extend, enhance, frames for a character', async ({ page }) => {
const cloud = new Cloud()
await openCreate(page, cloud)
await chooseTool(page, 'video')
await typePrompt(page, 'a train passes')
await run(page)
await expectResult(page, 'video')
await tid(page, 'm-create-result-extend').tap()
await expect(stage(page)).toHaveAttribute('data-m-tool', 'extend')
await expect(tid(page, 'm-create-extend')).toHaveAttribute('data-state', 'ready')
await tid(page, 'm-create-extend-remove').tap()
await expect(tid(page, 'm-create-extend')).toHaveAttribute('data-state', 'empty')
const openSheet = async () => {
await tid(page, 'm-create-gallery').tap()
await tid(page, 'm-create-gallery-item').first().tap()
await tid(page, 'm-create-item-more').tap()
await expect(tid(page, 'm-sheet-result')).toBeVisible()
}
await openSheet()
await tid(page, 'm-create-result-extend-row').tap()
await expect(tid(page, 'm-create-screen')).toBeVisible()
await expect(tid(page, 'm-create-extend')).toHaveAttribute('data-state', 'ready')
await openSheet()
await tid(page, 'm-create-result-enhance-video').tap()
await expect(tid(page, 'm-sheet-create-enhance')).toBeVisible()
await tid(page, 'm-create-enhance-720p').tap()
await expect(tid(page, 'm-create-enhance-720p')).toHaveAttribute('aria-checked', 'true')
await tid(page, 'm-sheet-create-enhance').getByTestId('m-sheet-close').tap()
await expect(tid(page, 'm-sheet-create-enhance')).toHaveCount(0)
if (!(await tid(page, 'm-sheet-result').isVisible())) await tid(page, 'm-create-item-more').tap()
await tid(page, 'm-create-result-save-character').tap()
await expect(tid(page, 'm-create-save-character-frame')).toBeEnabled({ timeout: 20_000 })
await tid(page, 'm-create-save-character-name').fill('Train')
await tid(page, 'm-create-save-character-save').tap()
await expect(tid(page, 'm-create-save-character-error')).toContainText('frame')
await tid(page, 'm-create-save-character-frame').tap()
await expect(tid(page, 'm-create-save-character-frame-remove')).toHaveCount(1)
await tid(page, 'm-create-save-character-frame-remove').tap()
await expect(tid(page, 'm-create-save-character-frame-remove')).toHaveCount(0)
await tid(page, 'm-create-save-character-frame').tap()
await expect(tid(page, 'm-create-save-character-frame-remove')).toHaveCount(1)
await tid(page, 'm-create-save-character-save').tap()
await expect(tid(page, 'm-toast-create-character-saved')).toBeVisible()
expect(cloud.submits).toHaveLength(1)
})
test('running: the stage tells the phase, cancel on the stage refunds, a lost line is said', async ({ page, context }) => {
const cloud = new Cloud()
cloud.hold = true
await openCreate(page, cloud)
await typePrompt(page, 'a slow picture')
await run(page)
await expect(tid(page, 'm-create-running-line')).toContainText(/Rendering|In line|Sending/)
await expect.poll(() => cloud.submits.length).toBe(1)
await context.setOffline(true)
await expect(tid(page, 'm-create-running-offline')).toBeVisible()
await context.setOffline(false)
await expect(tid(page, 'm-create-running-offline')).toHaveCount(0)
await tid(page, 'm-create-cancel-refund').tap()
await expect.poll(() => cloud.cancels).toEqual(['job-1'])
await expect(stage(page)).toHaveAttribute('data-state', 'empty')
await expect(tid(page, 'm-create-credits')).toContainText('2,000,000')
})
test('a picked up job: the note can be put away', async ({ page }) => {
const cloud = new Cloud()
cloud.hold = true
await openCreate(page, cloud)
await typePrompt(page, 'survives a restart')
await run(page)
await expect.poll(() => cloud.jobs.get('job-1')?.gets ?? 0).toBeGreaterThan(0)
await page.reload()
await page.getByTestId('m-app').waitFor()
await screensLoaded(page)
if (!(await tid(page, 'm-create-screen').isVisible())) {
if (await tid(page, 'm-page-back').first().isVisible()) await tid(page, 'm-page-back').first().tap()
await tid(page, 'm-nav-create').tap()
}
await expect(tid(page, 'm-create-pending')).toBeVisible()
await expect(tid(page, 'm-create-pending-ok')).toBeVisible()
await tid(page, 'm-create-pending-ok').tap()
await expect(tid(page, 'm-create-pending-ok')).toHaveCount(0)
// The job itself is still on the way and stays on screen.
await expect(tid(page, 'm-create-pending')).toBeVisible()
})
test('an open invoice is said on the stage and leads to the account page', async ({ page }) => {
const cloud = new Cloud()
cloud.pastDue = true
await page.addInitScript(() => {
const w = window as unknown as { __opened: string[] }
w.__opened = []
window.open = (url?: string | URL) => {
w.__opened.push(String(url))
return null
}
})
await openCreate(page, cloud)
await expect(tid(page, 'm-create-pastdue')).toBeVisible()
await expectLayout(page, 'K1 past due')
await tid(page, 'm-create-pastdue-action').tap()
await expect.poll(() => page.evaluate(() => (window as unknown as { __opened: string[] }).__opened)).toEqual(['https://lu-labs.ai/account'])
})
test('an open invoice in a build without buying: a neutral line, no button', async ({ page }) => {
const cloud = new Cloud()
cloud.pastDue = true
await openCreate(page, cloud, { policy: { purchase: 'none' } })
await expect(tid(page, 'm-create-pastdue')).toBeVisible()
await expect(tid(page, 'm-create-pastdue-action')).toHaveCount(0)
})
test('cloud teasers off: the gate is quiet and leads to the settings', async ({ page }) => {
const cloud = new Cloud()
cloud.signedIn = false
await openCreate(page, cloud, { teasers: false })
await expect(tid(page, 'm-create-gate')).toHaveAttribute('data-state', 'quiet')
await expect(tid(page, 'm-create-gate-showcase')).toHaveCount(0)
await tid(page, 'm-create-gate-settings').tap()
await expect(tid(page, 'm-nav-settings')).toHaveAttribute('aria-selected', 'true')
})
test('content policy of the account: the note under the prompt leads to the setting', async ({ page }) => {
const cloud = new Cloud()
await openCreate(page, cloud)
await typePrompt(page, 'something for adults')
cloud.submitReplies.push({ status: 403, body: { error: 'Content policy blocked this request. Change it in your account.' } })
await run(page)
await expect(tid(page, 'm-create-prompt-blocked')).toBeVisible()
await expect(tid(page, 'm-create-prompt')).toHaveValue('something for adults')
await tid(page, 'm-create-prompt-blocked-action').tap()
await expect(tid(page, 'm-settings-content-policy-screen')).toBeVisible()
})
test('model sheet: a price list that did not load says so and loads again; a tool without a model is not offered', async ({ page }) => {
const cloud = new Cloud()
cloud.catalogDown = true
await openCreate(page, cloud)
await openRunRow(page, 'm-create-model')
await expect(tid(page, 'm-create-model-stale')).toBeVisible()
await expect(tid(page, 'm-create-model-list')).toBeVisible()
cloud.catalogDown = false
cloud.models = CATALOG_MODELS.filter((m) => m.kind !== 'audio')
// Still down: the button does not end in silence.
cloud.catalogDown = true
await tid(page, 'm-create-model-refresh').tap()
await expect(tid(page, 'm-toast-create-model-refresh-failed')).toContainText('could not be updated', { timeout: 20_000 })
await expect(tid(page, 'm-create-model-stale')).toBeVisible()
cloud.catalogDown = false
await tid(page, 'm-create-model-refresh').tap()
await expect(tid(page, 'm-create-model-stale')).toHaveCount(0, { timeout: 20_000 })
await expect(tid(page, 'm-create-model-row').or(tid(page, 'm-create-model-cheapest')).first()).toBeVisible()
await tid(page, 'm-sheet-close').tap()
// A tool the price list has no model for is not offered at all.
await openRunRow(page, 'm-create-tools-all')
await expect(tid(page, 'm-create-tools-grid')).toBeVisible()
await expect(tid(page, 'm-create-tools-music')).toHaveCount(0)
await expect(tid(page, 'm-create-tools-video')).toBeVisible()
})
test('viewer: a result that is not there any more leads back to the gallery', async ({ page }) => {
const cloud = new Cloud()
await openCreate(page, cloud, { route: '/create/item/nothing-here' })
await expect(tid(page, 'm-create-item-missing')).toBeVisible()
await tid(page, 'm-create-item-to-gallery').tap()
await expect(tid(page, 'm-create-gallery-screen')).toBeVisible()
await expect(tid(page, 'm-create-gallery-empty')).toBeVisible()
})
test('viewer: media that does not load can be asked for again', async ({ page }) => {
const cloud = new Cloud()
await openCreate(page, cloud)
await typePrompt(page, 'flaky line')
await run(page)
await expectResult(page, 'image')
cloud.mediaDown = true
await page.reload()
await page.getByTestId('m-app').waitFor()
await screensLoaded(page)
if (!(await tid(page, 'm-create-screen').isVisible())) {
if (await tid(page, 'm-page-back').first().isVisible()) await tid(page, 'm-page-back').first().tap()
await tid(page, 'm-nav-create').tap()
}
await tid(page, 'm-create-gallery').tap()
await tid(page, 'm-create-gallery-item').tap()
await expect(tid(page, 'm-create-media-retry')).toBeVisible({ timeout: 20_000 })
cloud.mediaDown = false
await tid(page, 'm-create-media-retry').tap()
await expect(tid(page, 'm-create-item-stage').locator('img')).toBeVisible({ timeout: 20_000 })
})
test('mask editor without a source: it asks for one, and the sample of the developer build opens the editor', async ({ page }) => {
const cloud = new Cloud()
await openCreate(page, cloud, { route: '/create/mask' })
await expect(tid(page, 'm-create-mask-empty')).toBeVisible()
await tid(page, 'm-create-mask-add-source').tap()
await expect(tid(page, 'm-sheet-source')).toBeVisible()
await tid(page, 'm-sheet-close').tap()
await tid(page, 'm-create-mask-sample').tap()
await expect(tid(page, 'm-create-mask-screen')).toHaveAttribute('data-state', 'ready', { timeout: 20_000 })
await paint(page, [[0.3, 0.5], [0.7, 0.5]])
await expect(tid(page, 'm-create-mask-canvas')).toHaveAttribute('data-m-painted', '1')
})
test('new character: the model family, waiting for Wi-Fi, cancel, and a lost upload', async ({ page }) => {
const cloud = new Cloud()
cloud.hold = true
await page.addInitScript(() => {
const fns = new Set<() => void>()
const c = { type: 'cellular', addEventListener: (_n: string, fn: () => void) => fns.add(fn), removeEventListener: (_n: string, fn: () => void) => fns.delete(fn) }
Object.defineProperty(navigator, 'connection', { configurable: true, value: c })
;(window as unknown as { __connection: (t: string) => void }).__connection = (t) => {
c.type = t
for (const fn of fns) fn()
}
})
await openCreate(page, cloud)
await chooseTool(page, 'character')
await tid(page, 'm-create-characters-open').tap()
await tid(page, 'm-create-character-new').tap()
await tid(page, 'm-create-char-name').fill('mia')
await pick(page, tid(page, 'm-create-char-add'), [photo('a.png', 1), photo('b.png', 2), photo('c.png', 3), photo('d.png', 4)])
await expect(tid(page, 'm-create-char-count')).toContainText('4')
await tid(page, 'm-create-char-base').filter({ hasText: 'Flux' }).tap()
await expect(tid(page, 'm-create-train')).toContainText('80,000 credits')
await tid(page, 'm-create-char-base').filter({ hasText: 'Z-Image' }).tap()
await expect(tid(page, 'm-create-train')).toContainText('60,000 credits')
// On mobile data the upload can wait for Wi-Fi.
await expect(tid(page, 'm-create-char-data')).toHaveAttribute('data-m-connection', 'cellular')
await tid(page, 'm-create-char-wifi').tap()
await tid(page, 'm-create-train').tap()
await expect(tid(page, 'm-create-train-waiting')).toBeVisible()
expect(cloud.uploads).toHaveLength(0)
await tid(page, 'm-create-train-wait-cancel').tap()
await expect(tid(page, 'm-create-train-waiting')).toHaveCount(0)
await tid(page, 'm-create-train').tap()
await expect(tid(page, 'm-create-train-waiting')).toBeVisible()
// Wi-Fi comes back, but the line drops in the upload: said, and tried again by hand.
cloud.uploadReplies.push('abort', 'abort', 'abort', 'abort', 'abort', 'abort', 'abort', 'abort')
await page.evaluate(() => (window as unknown as { __connection: (t: string) => void }).__connection('wifi'))
await expect(tid(page, 'm-create-train-error')).toBeVisible({ timeout: 30_000 })
expect(cloud.submits).toHaveLength(0)
cloud.uploadReplies.length = 0
await tid(page, 'm-create-train-retry').tap()
await expect.poll(() => cloud.submits.length, { timeout: 20_000 }).toBe(1)
await expect(tid(page, 'm-create-train-training')).toBeVisible({ timeout: 20_000 })
await tid(page, 'm-create-train-cancel').tap()
await expect.poll(() => cloud.cancels).toEqual(['job-1'])
await expect(tid(page, 'm-create-train-running')).toHaveCount(0)
// Stopped, not trained: the page stays with its photos and says nothing about a finished character.
await expect(tid(page, 'm-create-character-new-screen')).toBeVisible()
await expect(tid(page, 'm-toast-create-character-trained')).toHaveCount(0)
await expect(tid(page, 'm-create-char-photo')).not.toHaveCount(0)
})
test('prompt styles for clips: the length is kept and applied', async ({ page }) => {
const cloud = new Cloud()
await openCreate(page, cloud)
await tid(page, 'm-create-styles-all').tap()
await tid(page, 'm-create-style-new').tap()
await tid(page, 'm-create-style-name').fill('Long pan')
await tid(page, 'm-create-style-text').fill('slow pan')
await tid(page, 'm-create-style-quality').filter({ hasText: 'High' }).tap()
await tid(page, 'm-create-style-for-video').tap()
await expect(tid(page, 'm-create-style-quality')).toHaveCount(0)
await tid(page, 'm-create-style-seconds').filter({ hasText: '8' }).tap()
await tid(page, 'm-create-style-for-image').tap()
await expect(tid(page, 'm-create-style-seconds')).toHaveCount(0)
await tid(page, 'm-create-style-for-video').tap()
await tid(page, 'm-create-style-seconds').filter({ hasText: '8' }).tap()
await tid(page, 'm-create-style-save').tap()
const card = tid(page, 'm-create-style-card').filter({ hasText: 'Long pan' })
await expect(card).toContainText('Video')
await card.tap()
await expect(tid(page, 'm-create-screen')).toBeVisible()
await expect(stage(page)).toHaveAttribute('data-m-tool', 'video')
await expect(tid(page, 'm-create-settings')).toContainText('8 s')
})
test('showcase while signed in: it leads back to Create', async ({ page }) => {
const cloud = new Cloud()
await openCreate(page, cloud, { route: '/create/showcase' })
await expect(tid(page, 'm-create-showcase-actions')).toHaveAttribute('data-state', 'open', { timeout: 20_000 })
await tid(page, 'm-create-showcase-open').tap()
await expect(tid(page, 'm-create-screen')).toBeVisible()
})
test('batch page: empty it asks for photos; done it says what ran and leads back', async ({ page }) => {
const cloud = new Cloud()
await openCreate(page, cloud)
await chooseTool(page, 'removebg')
await addSource(page, [photo('a.png', 1), photo('b.png', 2)])
await tid(page, 'm-create-batch-row').tap()
await expect(tid(page, 'm-create-batch-what')).toContainText('1,000 credits')
// One photo is no batch: taking one of two away leaves the page empty and the other as the source.
await tid(page, 'm-create-batch-remove').first().tap()
await expect(tid(page, 'm-create-batch-empty')).toBeVisible()
await pick(page, tid(page, 'm-create-batch-add'), [photo('only.png', 9)])
await expect(tid(page, 'm-toast-create-batch-need-two')).toBeVisible()
await pick(page, tid(page, 'm-create-batch-add'), [photo('c.png', 3), photo('d.png', 4)])
await expect(tid(page, 'm-create-batch-item')).toHaveCount(2)
await tid(page, 'm-create-batch-start').tap()
await expect(tid(page, 'm-create-batch-report')).toContainText('2', { timeout: 30_000 })
await tid(page, 'm-create-batch-back').tap()
await expect(tid(page, 'm-create-screen')).toBeVisible()
expect(cloud.submits).toHaveLength(2)
})
test('batch with a prompt: the page shows the words every image gets', async ({ page }) => {
const cloud = new Cloud()
cloud.hold = true
await openCreate(page, cloud)
await chooseTool(page, 'edit')
await pickModel(page, 'qwen-image-edit')
await typePrompt(page, 'make it winter')
await addSource(page, [photo('a.png', 1), photo('b.png', 2), photo('c.png', 3)])
await tid(page, 'm-create-batch-row').tap()
await expect(tid(page, 'm-create-batch-prompt')).toContainText('make it winter')
await tid(page, 'm-create-batch-start').tap()
await expect(tid(page, 'm-create-batch-progress')).toBeVisible({ timeout: 20_000 })
await expect.poll(() => cloud.submits.length, { timeout: 20_000 }).toBe(1)
expect(cloud.submits[0].prompt).toBe('make it winter')
await tid(page, 'm-create-batch-stop').tap()
cloud.release()
await expect(tid(page, 'm-create-batch-report')).toBeVisible({ timeout: 30_000 })
expect(cloud.submits).toHaveLength(1)
})
test('a model that reads several photos: reference photos, and a long choice list with search', async ({ page }) => {
const cloud = new Cloud()
cloud.studio = true
await openCreate(page, cloud)
await chooseTool(page, 'edit')
await pickModel(page, 'seedream-5-edit')
await addSource(page, [photo('room.png')])
await expect(tid(page, 'm-create-references')).toBeVisible()
await pick(page, tid(page, 'm-create-reference-add'), [photo('lamp.png', 3), photo('chair.png', 5)])
await expect(tid(page, 'm-create-reference-remove')).toHaveCount(2)
await tid(page, 'm-create-reference-remove').first().tap()
await expect(tid(page, 'm-create-reference-remove')).toHaveCount(1)
await expectLayout(page, 'K1 references')
await typePrompt(page, 'put the lamp into the room')
await tid(page, 'm-create-settings').tap()
await tid(page, 'm-create-model-settings-open').tap()
await tid(page, 'm-create-opt-aspect-ratio').tap()
await expect(tid(page, 'm-create-opt-picker')).toBeVisible()
const all = await tid(page, 'm-create-opt-choice').count()
expect(all).toBeGreaterThan(8)
await tid(page, 'm-create-opt-search').fill('16:9')
await expect(tid(page, 'm-create-opt-choice')).toHaveCount(1)
await tid(page, 'm-create-opt-choice').tap()
await expect(tid(page, 'm-create-opt-aspect-ratio')).toContainText('16:9')
await tid(page, 'm-create-opt-aspect-ratio').tap()
await tid(page, 'm-create-opt-choice-auto').tap()
await expect(tid(page, 'm-create-opt-aspect-ratio')).toContainText('Automatic')
await tid(page, 'm-create-opt-aspect-ratio').tap()
await tid(page, 'm-create-opt-search').fill('16:9')
await tid(page, 'm-create-opt-choice').tap()
await tid(page, 'm-sheet-close').tap()
await expect(tid(page, 'm-create-price')).toHaveText('1,500', { timeout: 20_000 })
await run(page)
await expectResult(page, 'image')
expect(cloud.uploads).toHaveLength(2)
expect(JSON.stringify(cloud.submits[0].params)).toContain('16:9')
})
test('talking with a model that re-voices a clip, and files of the wrong kind', async ({ page }) => {
const cloud = new Cloud()
cloud.models = [...CATALOG_MODELS, CLIP_SYNC_MODEL]
await openCreate(page, cloud)
await chooseTool(page, 'lipsync')
// A photo is no voice.
await pick(page, tid(page, 'm-create-voice-file'), [photo('not-a-voice.png')])
await expect(tid(page, 'm-create-voice-error')).toBeVisible()
await pickModel(page, 'latentsync')
await expect(tid(page, 'm-create-clip')).toHaveAttribute('data-state', 'empty')
await expect(tid(page, 'm-create-source-empty')).toHaveCount(0)
await pick(page, tid(page, 'm-create-clip-add'), [photo('not-a-clip.png')])
await expect(tid(page, 'm-create-clip-error')).toBeVisible()
await pick(page, tid(page, 'm-create-clip-add'), [clip()])
await expect(tid(page, 'm-create-clip')).toHaveAttribute('data-state', 'ready')
await expect(tid(page, 'm-create-clip-error')).toHaveCount(0)
await tid(page, 'm-create-clip-remove').tap()
await expect(tid(page, 'm-create-clip')).toHaveAttribute('data-state', 'empty')
await pick(page, tid(page, 'm-create-clip-add'), [clip()])
await pick(page, tid(page, 'm-create-voice-file'), [sound()])
await run(page)
await expectResult(page, 'video')
expect(cloud.uploads.map((u) => u.role).sort()).toEqual(['audio', 'video'])
expect(cloud.submits[0]).toMatchObject({ model: 'latentsync', params: { op: 'lipsync' } })
// Motion: the same card, the same answers.
await chooseTool(page, 'motion')
await pick(page, tid(page, 'm-create-motion-video-add'), [photo('not-a-clip.png')])
await expect(tid(page, 'm-create-motion-video-error')).toBeVisible()
await pick(page, tid(page, 'm-create-motion-video-add'), [clip()])
await expect(tid(page, 'm-create-motion-video')).toHaveAttribute('data-state', 'ready')
await tid(page, 'm-create-motion-video-remove').tap()
await expect(tid(page, 'm-create-motion-video')).toHaveAttribute('data-state', 'empty')
})
test('save as prompt style from the run settings: it is kept, and a name that is taken is refused', async ({ page }) => {
const cloud = new Cloud()
await openCreate(page, cloud)
await typePrompt(page, 'soft light, 35mm')
await tid(page, 'm-create-settings').tap()
await tid(page, 'm-create-aspect-3x4').tap()
await tid(page, 'm-create-save-style').tap()
await expect(tid(page, 'm-dialog-create-style-name')).toBeVisible()
await tid(page, 'm-dialog-field').fill('Moody')
await tid(page, 'm-dialog-confirm').tap()
await expect(tid(page, 'm-toast-create-style-saved')).toBeVisible()
await tid(page, 'm-create-save-style').tap()
await tid(page, 'm-dialog-field').fill('Moody')
await tid(page, 'm-dialog-confirm').tap()
await expect(tid(page, 'm-toast-create-style-problem')).toBeVisible()
await tid(page, 'm-sheet-close').tap()
await expect(page.locator('[data-testid="m-create-style"]').filter({ hasText: 'Moody' })).toHaveCount(1)
await tid(page, 'm-create-styles-all').tap()
await expect(tid(page, 'm-create-style-card').filter({ hasText: 'Moody' })).toContainText('3:4')
})
test('training: the shelf stops a running training; a training the server refuses says so', async ({ page }) => {
const cloud = new Cloud()
cloud.hold = true
await openCreate(page, cloud)
await chooseTool(page, 'character')
await tid(page, 'm-create-characters-open').tap()
await tid(page, 'm-create-character-new').tap()
await tid(page, 'm-create-char-name').fill('mia')
// More photos than fit: the rest is left out and said.
await pick(page, tid(page, 'm-create-char-add'), Array.from({ length: 32 }, (_, i) => photo(`p${i}.png`, i, 96, 96)))
await expect(tid(page, 'm-toast-create-photos-too-many')).toBeVisible({ timeout: 20_000 })
await expect(tid(page, 'm-create-char-photo')).toHaveCount(30)
cloud.submitReplies.push({ status: 400, body: { error: 'Training images could not be read.' } })
await tid(page, 'm-create-train').tap()
await expect(tid(page, 'm-create-train-error')).toBeVisible({ timeout: 30_000 })
await expect(tid(page, 'm-create-train-error')).toContainText('not charged')
await tid(page, 'm-create-train-error-dismiss').tap()
await expect(tid(page, 'm-create-train-error')).toHaveCount(0)
// The same again, this time through the button of the notice.
cloud.submitReplies.push({ status: 400, body: { error: 'Training images could not be read.' } })
await tid(page, 'm-create-train').tap()
await expect(tid(page, 'm-create-train-error')).toBeVisible({ timeout: 30_000 })
await tid(page, 'm-create-train-error-action').tap()
await expect.poll(() => cloud.submits.length, { timeout: 30_000 }).toBe(1)
await back(page, 'm-create-character-new-screen')
await expect(tid(page, 'm-create-training')).toHaveAttribute('data-state', 'training', { timeout: 20_000 })
await tid(page, 'm-create-training-cancel').tap()
await expect.poll(() => cloud.cancels).toEqual(['job-1'])
await expect(tid(page, 'm-toast-create-training-cancelled')).toBeVisible()
await expect(tid(page, 'm-create-training')).toHaveCount(0)
// A stopped training is not a trained one. The page of the new character used to take the end of
// the run for success: it toasted "trained" (over this toast or under it, whichever came last, which
// is why this test was red on the Linux runner only) and left the shelf.
await expect(tid(page, 'm-create-characters-screen')).toBeVisible()
await expect(tid(page, 'm-toast-create-character-trained')).toHaveCount(0)
await page.waitForTimeout(1000)
await expect(tid(page, 'm-create-characters-screen')).toBeVisible()
await expect(tid(page, 'm-toast-create-character-trained')).toHaveCount(0)
})
test('the note about how long results are kept shows once; the credits chip opens the account', async ({ page }) => {
const cloud = new Cloud()
await openCreate(page, cloud, { retentionSeen: false })
await expect(tid(page, 'm-create-retention')).toHaveCount(0)
await typePrompt(page, 'kept for seven days')
await run(page)
await expectResult(page, 'image')
await expect(tid(page, 'm-create-retention')).toContainText('7 days')
await tid(page, 'm-create-retention-ok').tap()
await expect(tid(page, 'm-create-retention')).toHaveCount(0)
await run(page)
await expectResult(page, 'image')
await expect(tid(page, 'm-create-retention')).toHaveCount(0)
await tid(page, 'm-create-credits').tap()
await expect(tid(page, 'm-account-screen')).toBeVisible()
})
// ---------- prompt styles, batch ----------
// ---------- guided presets (K12) ----------
test('guided presets: the list, and a preset of two steps whose first result is the input of the second', async ({ page }) => {
const cloud = new Cloud()
await openCreate(page, cloud)
await tid(page, 'm-create-presets-open').tap()
await expect(tid(page, 'm-create-presets-screen')).toBeVisible()
const cards = tid(page, 'm-create-preset-card')
await expect(cards).toHaveCount(15)
// A card says how many steps and from which price, and its picture really loaded.
const avatar = page.locator('[data-testid="m-create-preset-card"][data-m-id="talking-avatar"]')
await expect(avatar).toContainText('Talking Avatar')
await expect(avatar.getByTestId('m-create-preset-facts')).toContainText('2 steps')
await expect(avatar.getByTestId('m-create-preset-facts')).toContainText('credits')
await expect.poll(() => cards.first().locator('img').evaluate((el: HTMLImageElement) => el.complete && el.naturalWidth > 0)).toBe(true)
await expectLayout(page, 'K12 presets')
await tid(page, 'm-create-presets-kind-audio').tap()
await expect(cards).toHaveCount(1)
await tid(page, 'm-create-presets-kind-all').tap()
await avatar.tap()
const preset = tid(page, 'm-create-preset')
await expect(preset).toHaveAttribute('data-m-step', '0')
await expect(tid(page, 'm-create-preset-step')).toHaveCount(2)
await expect(page.locator('[data-testid="m-create-preset-step"][data-state="now"]')).toContainText('Create the voice')
// No price and no start before the step has what it needs, and it says what that is.
const go = tid(page, 'm-create-preset-generate')
await expect(go).toBeDisabled()
await expect(tid(page, 'm-create-preset-price')).toHaveAttribute('data-state', 'needs')
await tid(page, 'm-create-preset-prompt').fill('Good morning, here is the news.')
await expect(tid(page, 'm-create-preset-price')).toHaveAttribute('data-state', 'known', { timeout: 20_000 })
await expectLayout(page, 'K12 step one')
await go.tap()
const result = tid(page, 'm-create-preset-result')
await expect(result).toBeVisible({ timeout: 20_000 })
await expect(result).toHaveAttribute('data-m-kind', 'audio')
expect(cloud.submits).toHaveLength(1)
expect(cloud.submits[0].prompt).toBe('Good morning, here is the news.')
expect(cloud.submits[0].params.label).toBe('Talking Avatar · Create the voice')
expect(Number(cloud.submits[0].params.max_credits)).toBeGreaterThan(0)
expect(String(cloud.submits[0].params.client_request_id)).toMatch(/[0-9a-f-]{36}/)
expect(await galleryCount(page)).toBe(1)
// Next step: the voice is there by itself, only the portrait is missing.
await tid(page, 'm-create-preset-next').tap()
await expect(preset).toHaveAttribute('data-m-step', '1')
const voice = page.locator('[data-testid="m-create-preset-input"][data-m-id="audio_path"]')
await expect(voice).toHaveAttribute('data-state', 'set', { timeout: 20_000 })
await expect(voice).toContainText('From the step before')
expect(cloud.uploads.map((u) => u.role)).toEqual(['audio'])
const portrait = page.locator('[data-testid="m-create-preset-input"][data-m-id="source_path"]')
await expect(portrait).toHaveAttribute('data-state', 'empty')
await expect(tid(page, 'm-create-preset-price')).toContainText('Add image to see the price')
await pick(page, portrait.getByTestId('m-create-preset-input-file'), [photo('speaker.png', 3)])
await expect(portrait).toHaveAttribute('data-state', 'set', { timeout: 20_000 })
await expect(tid(page, 'm-create-preset-price-value')).toHaveText('1,500 credits', { timeout: 20_000 })
await expectLayout(page, 'K12 step two')
await go.tap()
await expect(result).toHaveAttribute('data-m-kind', 'video', { timeout: 20_000 })
expect(cloud.submits).toHaveLength(2)
expect(cloud.submits[1].model).toBe('infinitetalk')
expect(cloud.submits[1].params).toMatchObject({ op: 'studio', audio_path: 'inputs/audio-1', source_path: 'inputs/source-2', label: 'Talking Avatar', max_credits: 1500 })
// The last step is the end: no "Next step", the gallery holds both results.
await expect(tid(page, 'm-create-preset-next')).toHaveCount(0)
await expect(tid(page, 'm-create-preset-done')).toBeVisible()
expect(await galleryCount(page)).toBe(2)
// The main page did not lose its tool or model to the preset.
await back(page, 'm-create-preset-screen')
await back(page, 'm-create-presets-screen')
await expect(stage(page)).toHaveAttribute('data-m-tool', 'image')
})
test('guided presets: style LoRAs on a step, a prompt idea, Cancel refunds, Start over clears', async ({ page }) => {
const cloud = new Cloud()
await openCreate(page, cloud)
await openRunRow(page, 'm-create-tools-all')
await tid(page, 'm-create-tools-presets').tap()
await page.locator('[data-testid="m-create-preset-card"][data-m-id="your-character"]').tap()
const preset = tid(page, 'm-create-preset')
await expect(preset).toHaveAttribute('data-m-model', 'open-video-lora')
await expect(tid(page, 'm-create-preset-step-title')).toHaveText('Animate your reference')
await expect(tid(page, 'm-create-preset-model')).toContainText('OpenVideo')
const image = tid(page, 'm-create-preset-input').first()
await pick(page, image.getByTestId('m-create-preset-input-file'), [photo('figure.png', 4)])
await expect(image).toHaveAttribute('data-state', 'set', { timeout: 20_000 })
await tid(page, 'm-create-preset-prompt').fill('she turns her head')
// A prompt idea joins the text, it does not replace it.
await tid(page, 'm-create-preset-ideas').tap()
await tid(page, 'm-create-preset-idea').first().tap()
await expect(tid(page, 'm-sheet-create-preset')).toHaveCount(0)
await expect(tid(page, 'm-create-preset-prompt')).toHaveValue(/^she turns her head, .+/)
// The list field of the model is usable right on the step.
await tid(page, 'm-create-opt-loras').tap()
await tid(page, 'm-create-opt-list-add').tap()
await expect(tid(page, 'm-create-opt-list-row')).toHaveCount(1)
await expectLayout(page, 'K12 style LoRAs')
await tid(page, 'm-sheet-close').tap()
await expect(tid(page, 'm-create-preset-price-value')).toHaveText('1,500 credits', { timeout: 20_000 })
expect(JSON.stringify(cloud.quotes.at(-1))).toContain('loras')
cloud.hold = true
await tid(page, 'm-create-preset-generate').tap()
await expect(tid(page, 'm-create-preset-running')).toBeVisible({ timeout: 20_000 })
await expect(preset).toHaveAttribute('data-state', 'running')
await tid(page, 'm-create-preset-cancel').tap()
await expect.poll(() => cloud.cancels.length).toBe(1)
await expect(preset).toHaveAttribute('data-state', 'input', { timeout: 20_000 })
await expect(tid(page, 'm-create-preset-error')).toHaveCount(0)
expect((cloud.submits[0].params.studio_options as { loras?: unknown[] }).loras).toHaveLength(1)
// Nothing was lost by the cancel.
await expect(tid(page, 'm-create-preset-prompt')).toHaveValue(/she turns her head/)
await expect(image).toHaveAttribute('data-state', 'set')
await tid(page, 'm-create-preset-start-over').tap()
await tid(page, 'm-dialog-confirm').tap()
await expect(tid(page, 'm-create-preset-prompt')).toHaveValue('')
await expect(image).toHaveAttribute('data-state', 'empty')
})
test('guided presets: a store that caps the content policy does not offer the presets without refusals', async ({ page }) => {
const cloud = new Cloud()
await openCreate(page, cloud, { policy: { purchase: 'none' } })
await tid(page, 'm-create-presets-open').tap()
const cards = tid(page, 'm-create-preset-card')
await expect(cards).toHaveCount(9)
await expect(page.locator('[data-testid="m-create-preset-card"][data-m-id="spicy-character"]')).toHaveCount(0)
await expect(tid(page, 'm-create-presets-kind-horror')).toHaveCount(0)
// The way to the prompt building blocks is on this page too.
await tid(page, 'm-create-presets-styles').tap()
await expect(tid(page, 'm-create-styles-screen')).toBeVisible()
})
test('prompt styles: the rail applies one; the page makes, edits and deletes your own', async ({ page }) => {
const cloud = new Cloud()
await openCreate(page, cloud)
await typePrompt(page, 'a harbour')
await page.locator('[data-testid="m-create-style"][data-m-id="b-cinematic"]').tap()
await expect(tid(page, 'm-create-prompt')).toHaveValue('a harbour, cinematic lighting, shallow depth of field, film grain')
await expect(tid(page, 'm-create-settings')).toContainText('16:9')
await tid(page, 'm-create-styles-all').tap()
await expect(tid(page, 'm-create-styles-screen')).toBeVisible()
await expectLayout(page, 'K12')
await tid(page, 'm-create-style-new').tap()
await tid(page, 'm-create-style-save').tap()
await expect(tid(page, 'm-create-style-form')).toContainText('Give the style a name')
await tid(page, 'm-create-style-name').fill('Moody')
await tid(page, 'm-create-style-text').fill('soft light, 35mm')
await tid(page, 'm-create-style-aspect').filter({ hasText: '3:4' }).tap()
await expectLayout(page, 'K12 form')
await tid(page, 'm-create-style-save').tap()
const mine = tid(page, 'm-create-style-card').filter({ hasText: 'Moody' })
await expect(mine).toHaveCount(1)
await tid(page, 'm-create-style-edit').tap()
await tid(page, 'm-create-style-name').fill('Moody portrait')
await tid(page, 'm-create-style-save').tap()
await expect(tid(page, 'm-create-style-card').filter({ hasText: 'Moody portrait' })).toHaveCount(1)
await tid(page, 'm-create-style-card').filter({ hasText: 'Moody portrait' }).tap()
await expect(tid(page, 'm-create-screen')).toBeVisible()
await expect(tid(page, 'm-create-prompt')).toHaveValue(/soft light, 35mm$/)
await expect(tid(page, 'm-create-settings')).toContainText('3:4')
await tid(page, 'm-create-styles-all').tap()
await tid(page, 'm-create-style-remove').tap()
await tid(page, 'm-dialog-confirm').tap()
await expect(tid(page, 'm-create-styles-none')).toBeVisible()
})
test('batch: several photos run one after the other, each result opens', async ({ page }) => {
const cloud = new Cloud()
await openCreate(page, cloud)
await chooseTool(page, 'removebg')
await addSource(page, [photo('a.png', 1), photo('b.png', 2), photo('c.png', 3)])
await expect(tid(page, 'm-create-batch-row')).toContainText('3')
await tid(page, 'm-create-generate').tap()
await expect(tid(page, 'm-create-batch-screen')).toBeVisible()
await expect(tid(page, 'm-create-batch-item')).toHaveCount(3)
await expect(tid(page, 'm-create-batch-start')).toContainText('3,000 credits')
await expectLayout(page, 'K14')
expect(cloud.submits).toHaveLength(0)
// One more, one less.
await pick(page, tid(page, 'm-create-batch-add'), [photo('d.png', 4)])
await expect(tid(page, 'm-create-batch-item')).toHaveCount(4)
await expect(tid(page, 'm-create-batch-start')).toContainText('4,000 credits')
await tid(page, 'm-create-batch-remove').last().tap()
await expect(tid(page, 'm-create-batch-item')).toHaveCount(3)
await tid(page, 'm-create-batch-start').tap()
await expect(tid(page, 'm-create-batch-result')).toHaveCount(3, { timeout: 30_000 })
await expect(tid(page, 'm-create-batch-report')).toContainText('All 3 images are done')
expect(cloud.submits).toHaveLength(3)
expect(cloud.uploads.filter((u) => u.role === 'source')).toHaveLength(3)
await tid(page, 'm-create-batch-result').first().tap()
await expect(tid(page, 'm-create-item-screen')).toBeVisible()
expect(await galleryCount(page)).toBe(3)
})
test('batch: stop after this one leaves the rest in the list and books nothing for it', async ({ page }) => {
const cloud = new Cloud()
await openCreate(page, cloud)
await chooseTool(page, 'removebg')
await addSource(page, [photo('a.png', 1), photo('b.png', 2), photo('c.png', 3)])
await tid(page, 'm-create-generate').tap()
cloud.hold = true
await tid(page, 'm-create-batch-start').tap()
await expect(tid(page, 'm-create-batch-stop')).toBeVisible()
await expect.poll(() => cloud.submits.length).toBe(1)
await expect(tid(page, 'm-create-batch-item').first()).toHaveAttribute('data-state', 'running')
await expectLayout(page, 'K14 running')
await tid(page, 'm-create-batch-stop').tap()
await expect(tid(page, 'm-create-batch-stop')).toBeDisabled()
cloud.release()
await expect(tid(page, 'm-create-batch-report')).toContainText('1 of 3 images are done', { timeout: 30_000 })
await expect(tid(page, 'm-create-batch-report')).toContainText('Stopped')
await expect(tid(page, 'm-create-batch-item')).toHaveCount(2)
await expect(tid(page, 'm-create-batch-result')).toHaveCount(1)
expect(cloud.submits).toHaveLength(1)
await expect(tid(page, 'm-create-batch-start')).toContainText('2,000 credits')
})
test('batch: the credits cover only a part, the page says how many', async ({ page }) => {
const cloud = new Cloud()
cloud.credits = 2500
await openCreate(page, cloud)
await chooseTool(page, 'removebg')
await addSource(page, [photo('a.png', 1), photo('b.png', 2), photo('c.png', 3)])
await tid(page, 'm-create-generate').tap()
await expect(tid(page, 'm-create-batch-covers')).toContainText('2 of 3')
})
// ---------- round 2: save into Photos, the pick route, phone photos, the draft, error paths ----------
test('save into Photos: by the address of the result, and every way it fails has its sentence', async ({ page }) => {
const cloud = new Cloud()
await openCreate(page, cloud)
await typePrompt(page, 'worth keeping')
await run(page)
await expectResult(page, 'image')
const fetched = () => cloud.paths.filter((p) => p.startsWith('GET /mock-result/')).length
// The native side fetches the address itself and adds the file to Photos. No bytes pass through the page.
await installBridge(page, 'ok')
const before = fetched()
await tid(page, 'm-create-result-save').tap()
await expect(tid(page, 'm-toast-create-saved')).toContainText('Photos')
const calls = await bridgeCalls(page)
expect(calls.downloads).toHaveLength(1)
expect(calls.downloads[0]).toContain('/mock-result/job-1.png')
expect(calls.photos).toEqual([{ path: '/tmp/e2e-1', kind: 'image' }])
expect(calls.dropped).toEqual(['/tmp/e2e-1'])
expect(fetched()).toBe(before)
await expect(tid(page, 'm-toast-create-saved')).toHaveCount(0, { timeout: 15_000 })
// No storage left on the phone.
await installBridge(page, 'no-space')
await tid(page, 'm-create-result-save').tap()
await expect(tid(page, 'm-toast-create-save-storage')).toContainText('out of storage')
await expect(tid(page, 'm-toast-create-save-storage')).toContainText('Free up')
await expectLayout(page, 'save: no storage')
await expect(tid(page, 'm-toast-create-save-storage')).toHaveCount(0, { timeout: 15_000 })
// Photos is not allowed for LU.
await installBridge(page, 'denied')
await tid(page, 'm-create-result-save').tap()
await expect(tid(page, 'm-toast-create-save-denied')).toContainText('system settings')
await expect(tid(page, 'm-toast-create-save-denied')).toHaveCount(0, { timeout: 15_000 })
// Anything else is a failure with the way out, never a silent success.
await installBridge(page, 'broken')
await tid(page, 'm-create-result-save').tap()
await expect(tid(page, 'm-toast-create-save-failed')).toBeVisible()
await expect(tid(page, 'm-toast-create-saved')).toHaveCount(0)
await expect(tid(page, 'm-toast-create-save-failed')).toHaveCount(0, { timeout: 15_000 })
// The address is too old: it is signed again once and the fresh one is saved.
await installBridge(page, 'stale-once')
await tid(page, 'm-create-result-save').tap()
await expect(tid(page, 'm-toast-create-saved')).toBeVisible()
expect((await bridgeCalls(page)).downloads).toHaveLength(2)
})
test('the gallery as a picker has an address of its own', async ({ page }) => {
const cloud = new Cloud()
await openCreate(page, cloud, { route: '/create/gallery/pick/voice' })
await expect(tid(page, 'm-create-gallery-pick-screen')).toBeVisible()
await expect(page.locator('.m-page[data-route="/create/gallery/pick/:purpose"]')).toHaveCount(1)
await expect(tid(page, 'm-create-gallery-screen')).toHaveCount(0)
await expectLayout(page, 'K6 as a picker, empty')
})
test('the picker with a purpose nobody knows is the picker for a source, not a broken page', async ({ page }) => {
const cloud = new Cloud()
await openCreate(page, cloud, { route: '/create/gallery/pick/whatever' })
await expect(tid(page, 'm-create-gallery-pick-screen')).toBeVisible()
})
test('a phone photo that lies on its side is turned upright before it is sent', async ({ page }) => {
const cloud = new Cloud()
await openCreate(page, cloud)
await chooseTool(page, 'removebg')
// A JPEG as a phone camera writes it: 640 by 480 pixels, and a note that says "turn me by 90 degrees".
const jpeg = withExifOrientation(Buffer.from(await page.evaluate(jpegInPage, { w: 640, h: 480 }), 'base64'), 6)
await addSource(page, [{ name: 'IMG_2042.jpg', mimeType: 'image/jpeg', buffer: jpeg }])
await expect(tid(page, 'm-create-source')).toBeVisible()
await expect(tid(page, 'm-create-source')).toContainText('480')
await run(page)
await expectResult(page, 'image')
// What went up is upright: higher than wide, and the note is gone with the turn.
const sent = cloud.sources[0]
const size = await page.evaluate(async (b64) => {
const bytes = Uint8Array.from(atob(b64), (c) => c.charCodeAt(0))
const bmp = await createImageBitmap(new Blob([bytes]), { imageOrientation: 'none' })
return { w: bmp.width, h: bmp.height }
}, sent.toString('base64'))
expect(size).toEqual({ w: 480, h: 640 })
})
test('the limit for a file is the one the price list names', async ({ page }) => {
const cloud = new Cloud()
cloud.uploadLimits = { image: 2 * 1024 * 1024 }
await openCreate(page, cloud)
await chooseTool(page, 'removebg')
await tid(page, 'm-create-add-source').tap()
await pick(page, tid(page, 'm-create-source-library'), [{ name: 'big.png', mimeType: 'image/png', buffer: Buffer.alloc(3 * 1024 * 1024, 1) }])
await expect(tid(page, 'm-create-source-error')).toContainText('The limit is 2 MB')
expect(cloud.uploads).toHaveLength(0)
})
test('new character: the upload goes on where it stopped', async ({ page }) => {
const cloud = new Cloud()
cloud.hold = true
await openCreate(page, cloud)
await chooseTool(page, 'character')
await tid(page, 'm-create-characters-open').tap()
await tid(page, 'm-create-character-new').tap()
await tid(page, 'm-create-char-name').fill('mia')
await pick(page, tid(page, 'm-create-char-add'), [photo('a.png', 1), photo('b.png', 2), photo('c.png', 3), photo('d.png', 4), photo('e.png', 5)])
await expect(tid(page, 'm-create-char-photo')).toHaveCount(5)
// The line drops after the third photo.
cloud.uploadDropAt = 3
await tid(page, 'm-create-train').tap()
await expect(tid(page, 'm-create-train-error')).toBeVisible({ timeout: 30_000 })
await expect(tid(page, 'm-create-train-error')).toContainText('not charged')
await expect(tid(page, 'm-create-train-error')).toContainText('3 of 5 photos are already uploaded')
await expectLayout(page, 'K11 upload stopped')
expect(cloud.submits).toHaveLength(0)
expect(cloud.uploads).toHaveLength(3)
// Try again sends the two that are missing, not all five.
cloud.uploadDropAt = null
await tid(page, 'm-create-train-retry').tap()
await expect.poll(() => cloud.submits.length, { timeout: 20_000 }).toBe(1)
expect(cloud.uploads.filter((u) => u.role === 'train')).toHaveLength(5)
expect(cloud.submits[0].params.image_paths).toEqual(['inputs/train-1', 'inputs/train-2', 'inputs/train-3', 'inputs/train-4', 'inputs/train-5'])
})
test('a training that already started cannot be stopped, and both places say so', async ({ page }) => {
const cloud = new Cloud()
cloud.hold = true
cloud.cancelStatus = 409
await openCreate(page, cloud)
await chooseTool(page, 'character')
await tid(page, 'm-create-characters-open').tap()
await tid(page, 'm-create-character-new').tap()
await tid(page, 'm-create-char-name').fill('mia')
await pick(page, tid(page, 'm-create-char-add'), [photo('a.png', 1), photo('b.png', 2), photo('c.png', 3), photo('d.png', 4)])
await tid(page, 'm-create-train').tap()
await expect(tid(page, 'm-create-train-training')).toBeVisible({ timeout: 20_000 })
// On the page of the training.
await tid(page, 'm-create-train-cancel').tap()
await expect(tid(page, 'm-create-train-cannot-stop')).toContainText('can no longer be stopped')
await expect(tid(page, 'm-create-train-cannot-stop')).toContainText('is charged')
await expect(tid(page, 'm-create-train-running')).toBeVisible()
await expectLayout(page, 'K11 cannot stop')
expect(cloud.cancels).toEqual([])
// On the shelf: no "Training cancelled", the card stays.
await back(page, 'm-create-character-new-screen')
await onShelf(page)
await tid(page, 'm-create-training-cancel').tap()
await expect(tid(page, 'm-toast-create-training-cannot-stop')).toContainText('cannot be stopped')
await expect(tid(page, 'm-toast-create-training-cancelled')).toHaveCount(0)
await expect(tid(page, 'm-create-training')).toBeVisible()
// It finishes, and the character is there.
cloud.release()
await expect(tid(page, 'm-create-character')).toHaveCount(1, { timeout: 20_000 })
await expect(tid(page, 'm-create-character')).toContainText('mia')
await expect(tid(page, 'm-create-training')).toHaveCount(0)
})
test('a training picked up after a restart: a Cancel that does not get through says so and stops nothing', async ({ page }) => {
const cloud = new Cloud()
cloud.hold = true
await openCreate(page, cloud)
await chooseTool(page, 'character')
await tid(page, 'm-create-characters-open').tap()
await tid(page, 'm-create-character-new').tap()
await tid(page, 'm-create-char-name').fill('mia')
await pick(page, tid(page, 'm-create-char-add'), [photo('a.png', 1), photo('b.png', 2), photo('c.png', 3), photo('d.png', 4)])
await tid(page, 'm-create-train').tap()
await expect.poll(() => cloud.jobs.get('job-1')?.gets ?? 0, { timeout: 20_000 }).toBeGreaterThan(0)
await page.reload()
await page.getByTestId('m-app').waitFor()
await screensLoaded(page)
await backToCreateTab(page)
// The photos of the booked training are not offered again: nothing here invites a second, paid tap.
await expect(tid(page, 'm-create-character-new-screen')).toBeVisible()
await expect(tid(page, 'm-create-char-photo')).toHaveCount(0)
await page.waitForTimeout(600)
await expect(tid(page, 'm-create-char-photo')).toHaveCount(0)
await back(page, 'm-create-character-new-screen')
await onShelf(page)
// The server is busy: neither stopped nor lost.
cloud.cancelStatus = 503
await tid(page, 'm-create-training-cancel').tap()
await expect(tid(page, 'm-toast-create-training-cancel-failed')).toContainText('Could not cancel')
await expect(tid(page, 'm-create-training')).toBeVisible()
await expect(tid(page, 'm-toast-create-training-cancel-failed')).toHaveCount(0, { timeout: 15_000 })
// A GPU took it.
cloud.cancelStatus = 409
await tid(page, 'm-create-training-cancel').tap()
await expect(tid(page, 'm-toast-create-training-cannot-stop')).toBeVisible()
await expect(tid(page, 'm-create-training')).toBeVisible()
await expect(tid(page, 'm-toast-create-training-cannot-stop')).toHaveCount(0, { timeout: 15_000 })
// And when it does get through, it is cancelled.
cloud.cancelStatus = null
await tid(page, 'm-create-training-cancel').tap()
await expect(tid(page, 'm-toast-create-training-cancelled')).toBeVisible()
await expect.poll(() => cloud.cancels).toEqual(['job-1'])
await expect(tid(page, 'm-create-training')).toHaveCount(0)
})
test('deleting a character fails: it says so and the character stays', async ({ page }) => {
const cloud = new Cloud()
cloud.loras = [{ id: 'l1', name: 'nova', trigger_word: 'nova', base_family: 'z-image', created_at: '2026-10-01T10:00:00Z' }]
cloud.loraDeleteFail = true
await openCreate(page, cloud)
await chooseTool(page, 'character')
await tid(page, 'm-create-characters-open').tap()
await expect(tid(page, 'm-create-character')).toContainText('nova')
await tid(page, 'm-create-character-more').tap()
await tid(page, 'm-create-character-delete').tap()
await tid(page, 'm-dialog-confirm').tap()
await expect(tid(page, 'm-toast-create-character-delete-failed')).toContainText('Could not delete')
await expect(tid(page, 'm-create-character')).toContainText('nova')
expect(cloud.deletedLoras).toEqual([])
// The second try goes through.
cloud.loraDeleteFail = false
await expect(tid(page, 'm-toast-create-character-delete-failed')).toHaveCount(0, { timeout: 15_000 })
await tid(page, 'm-create-character-more').tap()
await tid(page, 'm-create-character-delete').tap()
await tid(page, 'm-dialog-confirm').tap()
await expect(tid(page, 'm-create-characters-empty')).toBeVisible()
expect(cloud.deletedLoras).toEqual(['l1'])
})
test('improve my prompt does not work: the run goes on with the own prompt and says so', async ({ page }) => {
const cloud = new Cloud()
cloud.chatDown = true
await openCreate(page, cloud)
await typePrompt(page, 'a fox')
await tid(page, 'm-create-settings').tap()
await tid(page, 'm-create-improve').tap()
await tid(page, 'm-sheet-close').tap()
await run(page)
await expect(tid(page, 'm-toast-create-improve-failed')).toContainText('could not be improved', { timeout: 20_000 })
await expectResult(page, 'image')
expect(cloud.submits[0].prompt).toBe('a fox')
// The result keeps the note.
await expect(tid(page, 'm-toast-create-improve-failed')).toHaveCount(0, { timeout: 15_000 })
await tid(page, 'm-create-result-open').tap()
await tid(page, 'm-create-item-prompt').tap()
await expect(tid(page, 'm-create-item-improve-failed')).toContainText('used your own prompt')
await expectLayout(page, 'K7 prompt with the note')
})
test('prompt and inputs survive a restart of the app', async ({ page }) => {
const cloud = new Cloud()
await openCreate(page, cloud)
await chooseTool(page, 'edit')
await pickModel(page, 'qwen-image-edit')
await addSource(page, [photo('room.png')])
await expect(tid(page, 'm-create-source')).toBeVisible()
await typePrompt(page, 'make it night')
await expect.poll(() => draftOnDisk(page)).toEqual({ prompt: 'make it night', intent: 'edit', files: ['source'] })
// The phone ends the app in the background. It is opened again.
await page.reload()
await page.getByTestId('m-app').waitFor()
await screensLoaded(page)
await toCreate(page)
await expect(stage(page)).toHaveAttribute('data-m-tool', 'edit')
await expect(tid(page, 'm-create-prompt')).toHaveValue('make it night')
await expect(tid(page, 'm-create-source')).toBeVisible()
await expect(tid(page, 'm-create-source')).toContainText('640')
// And it is a real input: the run sends the photo.
await run(page)
await expectResult(page, 'image')
expect(cloud.uploads.map((u) => u.role)).toEqual(['source'])
expect(cloud.submits[0]).toMatchObject({ prompt: 'make it night', params: { op: 'edit' } })
// Emptying the inputs leaves nothing behind for the next start.
await tid(page, 'm-create-source-remove').tap()
await typePrompt(page, '')
await expect.poll(() => draftOnDisk(page).then((d) => d.files)).toEqual([])
})
test('the photos for a new character survive a restart of the app', async ({ page }) => {
const cloud = new Cloud()
await openCreate(page, cloud)
await chooseTool(page, 'character')
await tid(page, 'm-create-characters-open').tap()
await tid(page, 'm-create-character-new').tap()
await tid(page, 'm-create-char-name').fill('mia')
await pick(page, tid(page, 'm-create-char-add'), [photo('a.png', 1), photo('b.png', 2), photo('c.png', 3), photo('d.png', 4)])
await expect(tid(page, 'm-create-char-photo')).toHaveCount(4)
await expect.poll(() => draftOnDisk(page).then((d) => d.files)).toEqual(['train:0', 'train:1', 'train:2', 'train:3'])
// The app starts in a new chat; the tab Create comes back on the page it was on, with the photos.
await page.reload()
await page.getByTestId('m-app').waitFor()
await screensLoaded(page)
await backToCreateTab(page)
await expect(tid(page, 'm-create-character-new-screen')).toBeVisible()
await expect(tid(page, 'm-create-char-photo')).toHaveCount(4)
await expect(tid(page, 'm-create-char-name')).toHaveValue('mia')
await tid(page, 'm-create-train').tap()
await expect.poll(() => cloud.submits.length, { timeout: 20_000 }).toBe(1)
expect(cloud.uploads.filter((u) => u.role === 'train')).toHaveLength(4)
})
})
}
// ---------- low screens: a phone on its side, and very large text ----------
test.describe('create on a low screen', () => {
test('on its side: stage and composer side by side, a run works', async ({ page }) => {
await page.setViewportSize({ width: 844, height: 390 })
const cloud = new Cloud()
await openCreate(page, cloud)
await expect(tid(page, 'm-create-layout')).toHaveAttribute('data-state', 'wide')
const composer = await tid(page, 'm-create-composer').boundingBox()
const stageBox = await stage(page).boundingBox()
expect(composer && stageBox && composer.x >= stageBox.x + stageBox.width - 1).toBe(true)
await typePrompt(page, 'sideways')
await expectLayout(page, 'K1 wide')
await run(page)
await expectResult(page, 'image')
await expect(tid(page, 'm-create-generate')).toBeInViewport()
await expectLayout(page, 'K1 wide result')
// Turning the phone upright brings the fixed composer back.
await page.setViewportSize({ width: 390, height: 844 })
await expect(tid(page, 'm-create-layout')).toHaveCount(0)
await expect(tid(page, 'm-create-result')).toBeVisible()
})
test('very large text on the smallest phone: one column, nothing under the tab bar, a run works', async ({ page }) => {
await page.setViewportSize({ width: 320, height: 568 })
const cloud = new Cloud()
await openCreate(page, cloud, { fontScale: 200 })
await expect(tid(page, 'm-create-layout')).toHaveAttribute('data-state', 'low')
await expectLayout(page, 'K1 low')
await typePrompt(page, 'large text')
// Every control of the composer can be reached and tapped.
await tid(page, 'm-create-settings').tap()
await expect(tid(page, 'm-sheet-run-settings')).toBeVisible()
await expectLayout(page, 'K4 low')
await tid(page, 'm-sheet-close').tap()
await openRunRow(page, 'm-create-model')
await expectLayout(page, 'K3 low')
await tid(page, 'm-sheet-close').tap()
await run(page)
await expectResult(page, 'image')
await expect(tid(page, 'm-create-result')).toBeInViewport()
await expectLayout(page, 'K1 low result')
})
})
// ---------- screenshots of every page and sheet ----------
const SHOT_DIR = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../../mobile-docs/design/strang-shots/create')
const SHOT_VARIANTS = [
{ name: '390x844-dark', width: 390, height: 844, theme: 'dark', fs: 100 },
{ name: '390x844-light', width: 390, height: 844, theme: 'light', fs: 100 },
{ name: '320x568-light-200', width: 320, height: 568, theme: 'light', fs: 200 },
{ name: '844x390-dark', width: 844, height: 390, theme: 'dark', fs: 100 },
] as const
test.describe('create screenshots', () => {
test.skip(!process.env.LU_MOBILE_SHOTS, 'set LU_MOBILE_SHOTS=1 to write the screenshots')
test.use({ deviceScaleFactor: 1 })
for (const v of SHOT_VARIANTS) {
test(v.name, async ({ page, browser }) => {
test.setTimeout(240_000)
await page.setViewportSize({ width: v.width, height: v.height })
const problems: string[] = []
const shot = async (view: string, on: Page = page) => {
await screensLoaded(on)
await on.evaluate(async () => {
await document.fonts.ready
const finite = document.getAnimations().filter((a) => Number.isFinite(a.effect?.getComputedTiming().endTime ?? Infinity))
await Promise.all(finite.map((a) => a.finished.catch(() => undefined)))
})
const layout = await measureLayout(on)
if (layout.overflow.length || layout.small.length || layout.pageScrolls) problems.push(`${view}: ${JSON.stringify(layout)}`)
await on.screenshot({ path: path.join(SHOT_DIR, `${v.name}--${view}.png`) })
}
const options: SeedOptions = { theme: v.theme, fontScale: v.fs, consent: false, retentionSeen: false }
const cloud = new Cloud()
cloud.loras = [{ id: 'l1', name: 'nova', trigger_word: 'nova', base_family: 'z-image', created_at: '2026-10-01T10:00:00Z' }]
await openCreate(page, cloud, options)
// K1 empty, K2, K3, K4, K5.
await shot('k1-empty')
await openRunRow(page, 'm-create-tools-all')
await expect(tid(page, 'm-sheet-tools')).toBeVisible()
await shot('k2-tools')
await tid(page, 'm-sheet-close').tap()
await openRunRow(page, 'm-create-model')
await shot('k3-model')
await tid(page, 'm-create-model-price-open').first().tap()
await shot('k3-price')
await tid(page, 'm-sheet-close').tap()
await tid(page, 'm-create-settings').tap()
await shot('k4-settings')
await tid(page, 'm-create-history-open').tap()
await shot('k4-history-empty')
await tid(page, 'm-sheet-close').tap()
await tid(page, 'm-create-add-source').tap()
await shot('k5-source')
await tid(page, 'm-sheet-close').tap()
// Consent, running, result.
await typePrompt(page, 'a lighthouse at dusk, dramatic storm clouds, cinematic')
cloud.hold = true
await run(page)
await expect(tid(page, 'm-sheet-ai-consent')).toBeVisible()
await shot('dialog-consent')
await tid(page, 'm-consent-agree').tap()
await expect(tid(page, 'm-create-running')).toBeVisible()
await expect.poll(() => cloud.submits.length).toBe(1)
await shot('k1-running')
cloud.release()
await expectResult(page, 'image')
await shot('k1-result')
await tid(page, 'm-create-retention-ok').tap()
await tid(page, 'm-create-result-more').tap()
await shot('k8-result-sheet')
await tid(page, 'm-sheet-close').tap()
await tid(page, 'm-create-result-report').tap()
await shot('dialog-report')
await tid(page, 'm-dialog-cancel').tap()
// A clip and a tune, then gallery and viewer.
await chooseTool(page, 'video')
await typePrompt(page, 'waves on a beach')
await shot('k1-video-empty')
await run(page)
await expectResult(page, 'video')
await shot('k1-video-result')
await chooseTool(page, 'music')
await typePrompt(page, 'calm piano')
await shot('k1-music')
await run(page)
await expectResult(page, 'audio')
await shot('k1-music-result')
await tid(page, 'm-create-gallery').tap()
await expect(tid(page, 'm-create-gallery-item')).toHaveCount(3)
await shot('k6-gallery')
await tid(page, 'm-create-gallery-select').tap()
await tid(page, 'm-create-gallery-item').first().tap()
await shot('k6-gallery-select')
await tid(page, 'm-create-gallery-select-done').tap()
await page.locator('[data-testid="m-create-gallery-item"][data-m-id="job-1"]').tap()
await expect(tid(page, 'm-create-item-stage').locator('img')).toBeVisible()
await shot('k7-image')
await tid(page, 'm-create-item-prompt').tap()
// The button is still in its pressed size for a moment, which the layout check would read as too small.
await page.waitForTimeout(300)
await shot('k7-image-prompt')
await tid(page, 'm-create-item-close').tap()
await page.locator('[data-testid="m-create-gallery-item"][data-m-id="job-2"]').tap()
await expect(tid(page, 'm-create-item-video')).toBeVisible()
// A touch brings the system's time line up, otherwise the shot catches it half faded.
await tid(page, 'm-create-item-video').tap({ position: { x: 100, y: 100 } })
await page.waitForTimeout(600)
await shot('k7-video')
await tid(page, 'm-create-item-enhance').tap()
await shot('k7-enhance-sheet')
await tid(page, 'm-sheet-close').tap()
await tid(page, 'm-create-item-close').tap()
await back(page, 'm-create-gallery-screen')
// Edit with a source, the mask editor.
await chooseTool(page, 'edit')
await addSource(page, [photo('room.png', 0, 1200, 900)])
await pickModel(page, 'flux-dev')
await typePrompt(page, 'a red sofa')
await shot('k1-edit-source')
await tid(page, 'm-create-paint-mask').tap()
await expect(tid(page, 'm-create-mask-screen')).toHaveAttribute('data-state', 'ready')
await shot('k9-mask-empty')
await paint(page, [[0.3, 0.45], [0.45, 0.5], [0.6, 0.45], [0.7, 0.55]])
await paint(page, [[0.35, 0.6], [0.55, 0.62]])
await shot('k9-mask-painted')
await tid(page, 'm-create-mask-done').tap()
await shot('k1-edit-masked')
// An error with its next step.
cloud.submitReplies.push({ status: 429, body: { error: 'credits exhausted', code: 'credits_exhausted' } })
await run(page)
await expect(tid(page, 'm-sheet-credits')).toBeVisible()
await tid(page, 'm-sheet-close').tap()
await expect(tid(page, 'm-create-error')).toBeVisible()
await shot('k1-error-credits')
await tid(page, 'm-create-error-dismiss').tap()
cloud.outcome = { status: 'failed', error: 'The GPU ran out of memory.' }
await run(page)
await expect(tid(page, 'm-create-error')).toBeVisible()
await shot('k1-error-failed')
cloud.outcome = { status: 'succeeded' }
await tid(page, 'm-create-error-dismiss').tap()
// Batch.
await chooseTool(page, 'removebg')
await tid(page, 'm-create-source-remove').tap()
await addSource(page, [photo('a.png', 1), photo('b.png', 2), photo('c.png', 3)])
await expect(tid(page, 'm-create-batch-row')).toBeVisible()
await shot('k1-batch-row')
await tid(page, 'm-create-generate').tap()
await expect(tid(page, 'm-create-batch-screen')).toBeVisible()
await shot('k14-batch')
await tid(page, 'm-create-batch-start').tap()
await expect(tid(page, 'm-create-batch-result')).toHaveCount(3, { timeout: 30_000 })
await shot('k14-batch-done')
await back(page, 'm-create-batch-screen')
// Characters and a new one.
await chooseTool(page, 'character')
await shot('k1-character')
await tid(page, 'm-create-characters-open').tap()
await expect(tid(page, 'm-create-character')).toHaveCount(1)
await shot('k10-characters')
await tid(page, 'm-create-character-more').tap()
await shot('k10-character-sheet')
await tid(page, 'm-sheet-close').tap()
await tid(page, 'm-create-character-new').tap()
await tid(page, 'm-create-char-name').fill('mia')
await pick(page, tid(page, 'm-create-char-add'), [photo('a.png', 1), photo('b.png', 2), photo('c.png', 3), photo('d.png', 4), photo('e.png', 5)])
await expect(tid(page, 'm-create-char-photo')).toHaveCount(5)
await shot('k11-new-character')
cloud.hold = true
await tid(page, 'm-create-train').tap()
await expect(tid(page, 'm-create-train-running')).toBeVisible()
await expect.poll(() => cloud.submits.filter((s) => s.params.op === 'lora-train').length).toBe(1)
await shot('k11-training')
await back(page, 'm-create-character-new-screen')
await expect(tid(page, 'm-create-training')).toBeVisible()
await shot('k10-training')
cloud.release()
await expect(tid(page, 'm-create-character')).toHaveCount(2, { timeout: 20_000 })
await back(page, 'm-create-characters-screen')
// Talking with its voice card, presets.
await chooseTool(page, 'lipsync')
await shot('k1-talking')
await chooseTool(page, 'image')
await tid(page, 'm-create-styles-all').tap()
await shot('k12-styles')
await tid(page, 'm-create-style-new').tap()
await shot('k12-style-form')
// The gate and the showcase, on a phone that is not signed in.
const context = await browser.newContext({ viewport: { width: v.width, height: v.height }, userAgent: PHONE_UA, hasTouch: true, isMobile: true, deviceScaleFactor: 1 })
const guest = await context.newPage()
const out = new Cloud()
out.signedIn = false
await openCreate(guest, out, options)
await expect(tid(guest, 'm-create-gate')).toBeVisible()
await shot('k1-gate', guest)
await tid(guest, 'm-create-gate-showcase').tap()
await expect(tid(guest, 'm-create-showcase-screen')).toBeVisible()
await shot('k13-showcase', guest)
await context.close()
expect(problems).toEqual([])
})
}
})
// ---------- round 45: every tool fits on one screen, no examples ----------
//
// David on the phone (Galaxy S26 Ultra, 412x915 CSS px): the examples took the
// room and the page had to be scrolled to see what a tool wants. Create shows
// no examples any more, and on a current phone at normal text the page of
// every tool does not scroll: tool row, inputs, prompt, run settings, price
// and Create are all on the first screen. On a small phone the button to
// start stays on screen, whatever scrolls.
const FIT_TOOLS = ['image', 'edit', 'removebg', 'upscale', 'eraser', 'video', 'animate', 'character', 'lipsync', 'music', 'extend', 'motion'] as const
const R45_DIR = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../../mobile-docs/r45')
interface Fit {
shape: string
scrollHeight: number
clientHeight: number
/** Height of what the stage shows, from its first to its last part. */
content: number
examples: number
}
/** How the page Create sits in the window right now. */
async function createFit(page: Page): Promise<Fit> {
return page.evaluate(() => {
const screen = document.querySelector('[data-testid="m-create-screen"]')
const body = screen?.querySelector<HTMLElement>(':scope > .m-body')
const stageEl = screen?.querySelector<HTMLElement>('[data-testid="m-create-stage"]')
const kids = stageEl ? [...stageEl.children].filter((k) => (k as HTMLElement).offsetHeight > 0) : []
const first = kids[0]?.getBoundingClientRect()
const last = kids[kids.length - 1]?.getBoundingClientRect()
return {
shape: document.querySelector('[data-testid="m-create-layout"]')?.getAttribute('data-state') ?? 'tall',
scrollHeight: body?.scrollHeight ?? -1,
clientHeight: body?.clientHeight ?? -1,
content: first && last ? Math.round(last.bottom - first.top) : 0,
examples: document.querySelectorAll('[data-testid="m-create-example"], [data-el="K1.11"]').length,
}
})
}
/** Tools whose models price by a studio quote, which needs their inputs first. */
const STUDIO_PRICED_TOOLS: readonly string[] = ['extend', 'motion']
/** What has to be on the first screen of a tool to start it. */
function coreOf(tool: (typeof FIT_TOOLS)[number]): string[] {
// Prompt v2: tool and model are in the run settings; the settings button, Add source and Create with its price.
const ids = ['m-create-price', 'm-create-settings', 'm-create-add-source', 'm-create-generate']
if (!['removebg', 'upscale', 'eraser', 'lipsync'].includes(tool)) ids.push('m-create-prompt')
if (['edit', 'removebg', 'upscale', 'eraser', 'animate', 'motion'].includes(tool)) ids.push('m-create-source-add')
return ids
}
test.describe('create fits on one screen (round 45)', () => {
test('412x915, normal text: no examples, no tool scrolls, everything to start is on screen', async ({ page }) => {
test.setTimeout(240_000)
await page.setViewportSize({ width: 412, height: 915 })
const cloud = new Cloud()
await openCreate(page, cloud)
const problems: string[] = []
for (const tool of FIT_TOOLS) {
if (tool !== 'image') await chooseTool(page, tool)
await expect(stage(page)).toHaveAttribute('data-m-tool', tool)
// Extend and Motion run on studio models since the catalogue of 24.10.2026: until a clip is in, the price is
// the estimate with its ring ("pending") and the live quote has nothing to ask for. Their layout is measured as it is.
if (!STUDIO_PRICED_TOOLS.includes(tool)) await expect(tid(page, 'm-create-price')).not.toHaveAttribute('data-state', 'pending')
const f = await createFit(page)
if (f.examples > 0) problems.push(`${tool}: ${f.examples} examples in the page`)
if (f.shape !== 'tall') problems.push(`${tool}: layout ${f.shape}, not the fixed composer`)
if (f.scrollHeight > f.clientHeight) problems.push(`${tool}: the page scrolls ${f.scrollHeight - f.clientHeight} px`)
for (const id of coreOf(tool)) {
const el = tid(page, id).first()
if ((await el.count()) === 0) problems.push(`${tool}: ${id} missing`)
// A price that is not known yet is an empty line: there is nothing to see.
else if (id === 'm-create-price' && !(await el.textContent())?.trim()) continue
else if (!(await el.evaluate((n) => {
const r = n.getBoundingClientRect()
const nav = document.querySelector('[data-testid="m-nav"]')?.getBoundingClientRect()
return r.height > 0 && r.top >= 0 && r.bottom <= (nav ? nav.top : window.innerHeight) + 0.5
}))) problems.push(`${tool}: ${id} not on screen`)
}
// Round 33 adds a row "Character" to Image and Video: it needs a row of room.
if ((tool === 'image' || tool === 'video') && f.clientHeight - f.content < 80) problems.push(`${tool}: ${f.clientHeight - f.content} px left, a character row needs 80`)
}
expect(problems).toEqual([])
})
test('360x640, normal text: no examples, Create stays on screen in every tool', async ({ page }) => {
test.setTimeout(240_000)
await page.setViewportSize({ width: 360, height: 640 })
const cloud = new Cloud()
await openCreate(page, cloud)
const problems: string[] = []
for (const tool of FIT_TOOLS) {
if (tool !== 'image') await chooseTool(page, tool)
await expect(stage(page)).toHaveAttribute('data-m-tool', tool)
const f = await createFit(page)
if (f.examples > 0) problems.push(`${tool}: ${f.examples} examples in the page`)
if (!(await tid(page, 'm-create-generate').evaluate((n) => {
const r = n.getBoundingClientRect()
const nav = document.querySelector('[data-testid="m-nav"]')?.getBoundingClientRect()
return r.height > 0 && r.top >= 0 && r.bottom <= (nav ? nav.top : window.innerHeight) + 0.5
}))) problems.push(`${tool}: Create not on screen`)
}
expect(problems).toEqual([])
})
for (const v of [
{ w: 360, h: 640 },
{ w: 320, h: 568 },
]) {
test(`${v.w}x${v.h}, largest text: the page scrolls, Create stays fixed below it in every tool`, async ({ page }) => {
test.setTimeout(240_000)
await page.setViewportSize({ width: v.w, height: v.h })
const cloud = new Cloud()
await openCreate(page, cloud, { fontScale: 200 })
await expect(tid(page, 'm-create-layout')).toHaveAttribute('data-state', 'low')
const problems: string[] = []
for (const tool of FIT_TOOLS) {
if (tool !== 'image') await chooseTool(page, tool)
await expect(stage(page)).toHaveAttribute('data-m-tool', tool)
for (const where of ['top', 'end'] as const) {
await page.evaluate((to) => {
const body = document.querySelector<HTMLElement>('[data-testid="m-create-screen"] > .m-body')
body?.scrollTo({ top: to === 'top' ? 0 : body.scrollHeight })
}, where)
if (!(await tid(page, 'm-create-generate').evaluate((n) => {
const r = n.getBoundingClientRect()
const nav = document.querySelector('[data-testid="m-nav"]')?.getBoundingClientRect()
return r.height > 0 && r.top >= 0 && r.bottom <= (nav ? nav.top : window.innerHeight) + 0.5
}))) problems.push(`${tool}: Create not on screen at the ${where} of the page`)
}
}
expect(problems).toEqual([])
await expectLayout(page, 'K1 low, last tool')
})
}
// The numbers and pictures of round 45 (mobile-docs/r45). Opt in, it writes into the repo.
test('measure and photograph every tool', async ({ browser }) => {
test.skip(!process.env.LU_R45_MEASURE, 'set LU_R45_MEASURE=vorher or nachher to write the numbers and pictures')
test.setTimeout(600_000)
const label = process.env.LU_R45_MEASURE ?? 'nachher'
const rows: Record<string, unknown>[] = []
const views = [
{ w: 412, h: 915, fs: 100 },
{ w: 412, h: 915, fs: 200 },
{ w: 360, h: 640, fs: 100 },
{ w: 360, h: 640, fs: 200 },
{ w: 320, h: 568, fs: 100 },
{ w: 320, h: 568, fs: 200 },
]
const photographed = ['image', 'video', 'edit', 'music', 'lipsync', 'character']
for (const v of views) {
const context = await browser.newContext({ viewport: { width: v.w, height: v.h }, userAgent: PHONE_UA, hasTouch: true, isMobile: true, deviceScaleFactor: 1 })
const page = await context.newPage()
const cloud = new Cloud()
await openCreate(page, cloud, { fontScale: v.fs })
for (const tool of FIT_TOOLS) {
if (tool !== 'image') await chooseTool(page, tool)
await expect(stage(page)).toHaveAttribute('data-m-tool', tool)
await page.waitForTimeout(250)
const f = await createFit(page)
const startVisible = await tid(page, 'm-create-generate').evaluate((n) => {
const r = n.getBoundingClientRect()
const nav = document.querySelector('[data-testid="m-nav"]')?.getBoundingClientRect()
return r.height > 0 && r.top >= 0 && r.bottom <= (nav ? nav.top : window.innerHeight) + 0.5
})
rows.push({ view: `${v.w}x${v.h}`, fs: v.fs, tool, ...f, overflow: Math.max(0, f.scrollHeight - f.clientHeight), startVisible })
if (v.fs === 100 && v.w !== 320 && photographed.includes(tool)) {
await page.screenshot({ path: path.join(R45_DIR, 'bilder', `${label}-${v.w}x${v.h}-${tool}.png`) })
}
if (v.fs === 200 && v.w === 360 && tool === 'image') await page.screenshot({ path: path.join(R45_DIR, 'bilder', `${label}-${v.w}x${v.h}-schrift200-${tool}.png`) })
}
await context.close()
}
const fs = await import('node:fs')
fs.writeFileSync(path.join(R45_DIR, `messung-${label}.json`), `${JSON.stringify(rows, null, 1)}\n`)
})
})
// Customer mail of 30.10. (package M1, 3.0.9): "the keyboard keeps closing" on Create, Android. Android shrinks the
// window by the keyboard (adjustResize, MainActivity pads by the IME inset), which the viewport below does too. Below
// 30 text units of height Create went to one scrolling column, the prompt field was built anew in it, lost the focus,
// and Android took the keyboard away. Screenshots for the report: LU_M1_SHOTS=<folder>.
test.describe('the keyboard stays open on Create (M1)', () => {
for (const v of [
{ name: '360x740', w: 360, h: 740, kb: 300, fs: 100 },
{ name: '412x840 text 115', w: 412, h: 840, kb: 330, fs: 115 },
]) {
for (const tool of ['image', 'video'] as const) {
test(`${v.name}, ${tool}: the prompt keeps its place and the focus while the window shrinks`, async ({ page }) => {
await page.setViewportSize({ width: v.w, height: v.h })
const cloud = new Cloud()
await openCreate(page, cloud, { fontScale: v.fs })
if (tool !== 'image') await chooseTool(page, tool)
const prompt = tid(page, 'm-create-prompt')
await prompt.tap()
await page.keyboard.type('a cat')
await prompt.evaluate((n) => ((n as HTMLElement & { m1?: boolean }).m1 = true))
const shots = process.env.LU_M1_SHOTS
const slug = `${v.name.replace(/\s+/g, '-')}-${tool}`
if (shots) await page.screenshot({ path: path.join(shots, `${slug}-1-tastatur-zu.png`) })
await page.setViewportSize({ width: v.w, height: v.h - v.kb })
// Android sends more than one resize while the keyboard slides in; give React every one of them.
await page.waitForTimeout(400)
const after = await page.evaluate(() => {
const el = document.activeElement as (HTMLElement & { m1?: boolean }) | null
return { focused: el?.dataset.testid ?? null, same: el?.m1 === true, layout: document.querySelector('[data-testid="m-create-layout"]')?.getAttribute('data-state') ?? 'tall' }
})
expect(after).toEqual({ focused: 'm-create-prompt', same: true, layout: 'tall' })
await page.keyboard.type(' on a roof')
await expect(prompt).toHaveValue('a cat on a roof')
if (shots) await page.screenshot({ path: path.join(shots, `${slug}-2-tastatur-offen.png`) })
// The keyboard goes with the focus: the page measures again.
await prompt.evaluate((n) => (n as HTMLElement).blur())
await page.setViewportSize({ width: v.w, height: v.h })
await expect(prompt).toHaveValue('a cat on a roof')
await expect(tid(page, 'm-create-layout')).toHaveCount(0)
})
}
}
})
// Discord, mod report of 05.11. (3.0.10): "It has a prompt already loaded and I've tried to change it. Selected just
// cancels my keyboard." Image, Image to Video and the rest. The same loop as M1, reached from a prompt that is
// already there: the field is tapped again, the window shrinks by the keyboard, the field was built anew and the
// old prompt could not be changed. Red on v3.0.8 (focus on BODY, old prompt kept), green since the M1 fix.
test.describe('a prompt that is already there can be changed (3.0.10)', () => {
for (const tool of ['image', 'video', 'animate'] as const) {
test(`360x740, ${tool}: select the old prompt and type a new one while the keyboard is open`, async ({ page }) => {
await page.setViewportSize({ width: 360, height: 740 })
const cloud = new Cloud()
await openCreate(page, cloud)
if (tool !== 'image') await chooseTool(page, tool)
const prompt = tid(page, 'm-create-prompt')
await prompt.fill('a cat on a roof at night, rain, neon lights')
await prompt.evaluate((n) => (n as HTMLElement).blur())
await prompt.tap()
await prompt.evaluate((n) => ((n as HTMLElement & { kept?: boolean }).kept = true))
await page.setViewportSize({ width: 360, height: 440 })
await page.waitForTimeout(400)
await page.keyboard.press('ControlOrMeta+a')
await page.keyboard.type('a dog in the snow')
const after = await page.evaluate(() => {
const el = document.activeElement as (HTMLElement & { kept?: boolean }) | null
return { focused: el?.dataset.testid ?? el?.tagName ?? null, same: el?.kept === true }
})
expect(after).toEqual({ focused: 'm-create-prompt', same: true })
await expect(prompt).toHaveValue('a dog in the snow')
})
}
})
// ---------- 3D (3.1.0, cloud only) ----------
/**
* The cloud 3D models are not in the shipped registry yet. The app gets the
* three stand ins of the unit tests in place of the two registry files, and
* the catalog lists them. Nothing else of the app changes.
*/
async function serveThreeDRegistry(page: Page): Promise<void> {
const here = path.dirname(fileURLToPath(import.meta.url))
const read = (name: string) => JSON.parse(readFileSync(path.join(here, '../../src/lib/render', name), 'utf8')) as Record<string, unknown>
const models = { ...read('studio-models.json'), ...THREE_D_STUDIO }
const schemas = { ...read('provider-schemas.json'), ...THREE_D_SCHEMAS }
const asModule = (body: unknown) => ({ status: 200, headers: { 'content-type': 'text/javascript', 'cache-control': 'no-store' }, body: `export default ${JSON.stringify(body)}\n` })
await page.route(/\/src\/lib\/render\/studio-models\.json(\?.*)?$/, (route) => route.fulfill(asModule(models)))
await page.route(/\/src\/lib\/render\/provider-schemas\.json(\?.*)?$/, (route) => route.fulfill(asModule(schemas)))
}
const SHOTS_3D = process.env.LU_3D_SHOTS ?? ''
test.describe('3D on the phone', () => {
test('the tool is only there when the catalog lists a 3D model', async ({ page }) => {
const cloud = new Cloud()
await openCreate(page, cloud)
await openRunRow(page, 'm-create-tools-all')
await expect(tid(page, 'm-sheet-tools')).toBeVisible()
await expect(tid(page, 'm-create-tools-3d')).toHaveCount(0)
})
test('from words: the prompt field, the model of the way, no detail step and no photo', async ({ page }) => {
await serveThreeDRegistry(page)
const cloud = new Cloud()
cloud.models = [...CATALOG_MODELS, ...threeDCatalogEntries()]
await openCreate(page, cloud)
await chooseTool(page, '3d')
await expect(tid(page, 'm-create-3d-way')).toBeVisible()
// The way a fresh phone starts on: a photo, so no prompt field.
await expect(tid(page, 'm-create-prompt')).toHaveCount(0)
await tid(page, 'm-create-3d-way-text').tap()
await expect(tid(page, 'm-create-settings')).toContainText('Hunyuan3D')
await expect(tid(page, 'm-create-3d-detail-card')).toHaveCount(0)
await expect(tid(page, 'm-create-source-empty')).toHaveCount(0)
await expect(tid(page, 'm-create-blocked')).toHaveAttribute('data-m-reason', 'no-prompt')
await typePrompt(page, 'a clay teapot with a bamboo handle')
await expect(tid(page, 'm-create-generate')).toBeEnabled()
})
test('from words: the run sends the prompt and no picture', async ({ page }) => {
await serveThreeDRegistry(page)
const cloud = new Cloud()
cloud.models = [...CATALOG_MODELS, ...threeDCatalogEntries()]
await openCreate(page, cloud)
await chooseTool(page, '3d')
await tid(page, 'm-create-3d-way-text').tap()
await typePrompt(page, 'a clay teapot with a bamboo handle')
await run(page)
await expect(tid(page, 'm-create-result')).toHaveAttribute('data-m-kind', '3d', { timeout: 20_000 })
const submit = cloud.submits[cloud.submits.length - 1]
expect(submit).toMatchObject({ model: MESH_TEXT, kind: '3d', prompt: 'a clay teapot with a bamboo handle' })
expect(cloud.uploads).toHaveLength(0)
})
test('from a video: still frames, picked like on the desktop, and only the frames are uploaded', async ({ page }) => {
await serveThreeDRegistry(page)
const cloud = new Cloud()
cloud.models = [...CATALOG_MODELS, ...threeDCatalogEntries()]
await openCreate(page, cloud)
await chooseTool(page, '3d')
await tid(page, 'm-create-3d-way-video').tap()
await expect(tid(page, 'm-create-blocked')).toHaveAttribute('data-m-reason', 'no-3d-video')
await expect(tid(page, 'm-create-prompt')).toHaveCount(0)
await pick(page, tid(page, 'm-create-3d-video-add'), [clip('teapot.webm')])
await expect(tid(page, 'm-create-3d-video')).toHaveAttribute('data-state', 'ready', { timeout: 20_000 })
await expect(tid(page, 'm-create-3d-frame')).toHaveCount(8)
await expect(tid(page, 'm-create-3d-video')).toHaveAttribute('data-m-picked', '0,2,4,5')
await expect(tid(page, 'm-create-3d-detail')).toBeVisible()
if (SHOTS_3D) await page.screenshot({ path: path.join(SHOTS_3D, '3d-video.png') })
// Swap a moment: the oldest goes, the order of the video stays.
await tid(page, 'm-create-3d-frame').nth(7).tap()
await expect(tid(page, 'm-create-3d-video')).toHaveAttribute('data-m-picked', '2,4,5,7')
await tid(page, 'm-create-3d-detail-fine').tap()
await run(page)
await expect(tid(page, 'm-create-result')).toHaveAttribute('data-m-kind', '3d', { timeout: 20_000 })
const submit = cloud.submits[cloud.submits.length - 1]
expect(submit.model).toBe(MESH_VIEWS)
expect(submit.params.image_paths as string[]).toHaveLength(4)
expect((submit.params.studio_options as Record<string, unknown>).texture_quality).toBe('extreme')
expect(cloud.uploads).toHaveLength(4)
// No upload is the video (WebM starts with 1A 45 DF A3).
expect(cloud.uploads.some((u) => u.head.join(',') === '26,69,223,163')).toBe(false)
})
test('from a photo: further sides, the 3D view of the result, shared as a GLB, a tile in the gallery', async ({ page }) => {
const errors = watchErrors(page)
await serveThreeDRegistry(page)
const cloud = new Cloud()
cloud.models = [...CATALOG_MODELS, ...threeDCatalogEntries()]
await openCreate(page, cloud)
await chooseTool(page, '3d')
await tid(page, 'm-create-3d-way-image').tap()
await tid(page, 'm-create-add-source').tap()
await expect(tid(page, 'm-create-source-video')).toBeVisible()
await pick(page, tid(page, 'm-create-source-library'), [photo('front.png', 10)])
await expect(tid(page, 'm-sheet-source')).toHaveCount(0)
await expect(tid(page, 'm-create-source')).toBeVisible()
await openRunRow(page, 'm-create-model')
await page.locator(`[data-m-id="${MESH_VIEWS}"]`).first().tap()
await expect(tid(page, 'm-create-3d-sides')).toHaveAttribute('data-state', '0')
await pick(page, tid(page, 'm-create-3d-side-add'), [photo('left.png', 40)])
await expect(tid(page, 'm-create-3d-sides')).toHaveAttribute('data-state', '1')
if (SHOTS_3D) await page.screenshot({ path: path.join(SHOTS_3D, '3d-image.png') })
await run(page)
await expect(tid(page, 'm-create-result')).toHaveAttribute('data-m-kind', '3d', { timeout: 20_000 })
const submit = cloud.submits[cloud.submits.length - 1]
expect(submit.model).toBe(MESH_VIEWS)
expect(submit.params.image_paths as string[]).toHaveLength(2)
// The result turns in the 3D view right on the stage.
const viewer = tid(page, 'm-create-result-3d').getByTestId('model-viewer')
await expect(viewer).toHaveAttribute('data-phase', /ready|no-webgl/, { timeout: 20_000 })
if ((await viewer.getAttribute('data-phase')) === 'ready') await expect(tid(page, 'm-create-result-3d').getByTestId('model-viewer-facts')).toContainText('triangles')
if (SHOTS_3D) await page.screenshot({ path: path.join(SHOTS_3D, '3d-result.png') })
// Shared as the GLB it was made as.
await tid(page, 'm-create-result-share').tap()
await expect.poll(() => page.evaluate(() => (window as unknown as { __shared: { name: string; type: string }[] }).__shared)).toEqual([
expect.objectContaining({ name: expect.stringMatching(/\.glb$/), type: 'model/gltf-binary' }),
])
await tid(page, 'm-create-result-fullscreen').tap()
await expect(tid(page, 'm-create-item-3d')).toBeVisible()
await expect(tid(page, 'm-create-item-3d').getByTestId('model-viewer')).toHaveAttribute('data-phase', /ready|no-webgl/, { timeout: 20_000 })
if (SHOTS_3D) await page.screenshot({ path: path.join(SHOTS_3D, '3d-item.png') })
await tid(page, 'm-create-item-close').tap()
await tid(page, 'm-create-gallery').tap()
const tile = page.locator('[data-testid="m-create-gallery-tile"][data-m-kind="3d"]')
await expect(tile).toHaveCount(1)
await expect(tile.getByTestId('thumb-3d')).toBeVisible()
await expect(tid(page, 'm-create-gallery-filter-3d')).toBeVisible()
if (SHOTS_3D) await page.screenshot({ path: path.join(SHOTS_3D, '3d-gallery.png') })
expect(errors()).toEqual([])
})
})