Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/website/e2e/fixtures/modelsAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const MODEL_PATH = '/models/bfl--flux-2-max--generate-images/'
/** The identity this fixture signs in as, and the workspace its token mints. */
export const MODELS_ACCOUNT_UID = 'e2e-models-user'
export const MODELS_WORKSPACE_ID = 'ws-personal'
const MODELS_WORKSPACE_TOKEN = 'mock-workspace-jwt'
export const MODELS_WORKSPACE_TOKEN = 'mock-workspace-jwt'

function jsonRoute(body: unknown, status = 200) {
return { status, contentType: 'application/json', body: JSON.stringify(body) }
Expand Down
124 changes: 124 additions & 0 deletions apps/website/e2e/fixtures/reshootProxy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
import { deflateSync } from 'node:zlib'

import type { Page, Request, Route } from '@playwright/test'
import { expect } from '@playwright/test'

/**
* comfy-api's app proxy for Re-shoot, answering as a warm deployment: the
* analyze job succeeds as soon as it is submitted and its output is a small
* but well-formed `.cvgeo`, so the page reads a real scene end to end.
*/

/** An 8x8 baseline JPEG, the frame image a `.cvgeo` carries per frame. */
const FRAME_JPEG = Buffer.from(
'/9j/4AAQSkZJRgABAgAAAQABAAD//gAPTGF2YzYzLjEuMTAxAP/bAEMACBQUFxQXGxsbGxsbIB4gISEhICAgICEhISQkJCoqKiQkJCEhJCQoKCoqLi8uKysqKy8vMjIyPDw5OUZGSFZWZ//EAEwAAQEAAAAAAAAAAAAAAAAAAAAGAQEBAAAAAAAAAAAAAAAAAAAFBhABAAAAAAAAAAAAAAAAAAAAABEBAAAAAAAAAAAAAAAAAAAAAP/AABEIAAgACAMBIgACEQADEQD/2gAMAwEAAhEDEQA/AJsBRAX/2Q==',
'base64'
)

/** 2.0 as an IEEE half float: the depth, in metres, of every pixel. */
const TWO_METRES_HALF = 0x4000

/**
* The file CrossViewGeometryExport writes (see reshoot-engine/cvgeo.ts): the
* magic, a little-endian header length, a JSON header, then the frame JPEGs
* and the zlib-deflated depth planes with each half's low bytes before its
* high bytes.
*/
function reshootGeometry({ frames = 2, width = 8, height = 8 } = {}): Buffer {
const count = frames * width * height
const planes = Buffer.alloc(2 * count)
planes.fill(TWO_METRES_HALF & 0xff, 0, count)
planes.fill(TWO_METRES_HALF >> 8, count)
const depth = deflateSync(planes)
const jpegs = Buffer.concat(Array.from({ length: frames }, () => FRAME_JPEG))
const header = Buffer.from(
JSON.stringify({
version: 1,
frames,
width,
height,
fps: 24,
source_width: 864,
source_height: 480,
fx_norm: null,
jpegs: Array.from({ length: frames }, (_, i) => ({
offset: i * FRAME_JPEG.length,
length: FRAME_JPEG.length
})),
depth: {
offset: jpegs.length,
length: depth.length,
dtype: 'float16',
shape: [frames, height, width],
encoding: 'shuffle2+zlib'
}
})
)
const length = Buffer.alloc(4)
length.writeUInt32LE(header.length)
return Buffer.concat([
Buffer.from('CVGEO1\0\0', 'latin1'),
length,
header,
jpegs,
depth
])
}

type Answer = Parameters<Route['fulfill']>[0]

const QUOTE = {
free_runs_allowance: { runs: 5, period: 'P7D', period_seconds: 604_800 },
free_runs_remaining: 3,
resets_at: null,
price_credits: 40,
next_run: 'free'
}

const ANALYZE_JOB = {
id: 'e2e-reshoot-analyze',
status: 'succeeded',
outputs: [{ id: 'geo', filename: 'crossview/geometry.cvgeo' }]
}

/**
* Answers the Re-shoot app proxy on any Router origin and proxy id. Every
* request must carry the workspace token the signed-in session minted.
* Returns the `METHOD path` of each call, in order, below the proxy id.
*/
export async function mockReshootProxy(page: Page, workspaceToken: string) {
const calls: string[] = []
const geometry = reshootGeometry()
const answers = new Map<string, (request: Request) => Answer>(
Object.entries({
'GET /quote': () => ({ json: QUOTE }),
'POST /assets': () => ({ json: { file_path: 'crossview-e2e.mp4' } }),
'POST /jobs': (request: Request) => {
expect(request.postData()).toContain('CrossViewGeometryExport')
return { json: ANALYZE_JOB }
},
[`GET /jobs/${ANALYZE_JOB.id}`]: () => ({ json: ANALYZE_JOB }),
[`GET /jobs/${ANALYZE_JOB.id}/outputs/geo/content`]: () => ({
contentType: 'application/octet-stream',
body: geometry
})
})
)
await page.route(/\/app-proxy\/[^/]+\//, async (route: Route) => {
const request = route.request()
const path = new URL(request.url()).pathname.replace(
/^.*\/app-proxy\/[^/]+/,
''
)
const call = `${request.method()} ${path}`
calls.push(call)
expect(request.headers()['authorization']).toBe(`Bearer ${workspaceToken}`)
const answer = answers.get(call)
return route.fulfill(
answer
? answer(request)
: { status: 404, json: { error_type: 'not_found' } }
)
})
return calls
}
126 changes: 81 additions & 45 deletions apps/website/e2e/workshop-apps.spec.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import type { BrowserContext } from '@playwright/test'
import type { BrowserContext, Page } from '@playwright/test'
import { expect } from '@playwright/test'

import { test } from './fixtures/blockExternalMedia'
import {
MODELS_WORKSPACE_TOKEN,
test as signedInTest
} from './fixtures/modelsAccount'
import { mockReshootProxy } from './fixtures/reshootProxy'

async function mockFlags(
context: BrowserContext,
flags: { apps: boolean; workflows: boolean }
flags: { apps: boolean; workflows: boolean; auth?: boolean }
) {
await context.route('**/t.comfy.org/**', (route) =>
/\/(flags|decide)\//.test(route.request().url())
Expand All @@ -15,7 +20,8 @@ async function mockFlags(
featureFlags: {
'workshop-enabled': true,
'workshop-apps-enabled': flags.apps,
'workshop-workflows-enabled': flags.workflows
'workshop-workflows-enabled': flags.workflows,
...(flags.auth ? { 'workshop-auth': true } : {})
},
featureFlagPayloads: {}
}
Expand All @@ -24,6 +30,40 @@ async function mockFlags(
)
}

/**
* Signs in with a workspace, opens Re-shoot on the example clip and waits
* for the app proxy (mocked) to read its scene, so the viewport is aimable.
*/
async function openReadReshootScene(
page: Page,
context: BrowserContext,
account: { email: string; password: string }
) {
await mockFlags(context, { apps: true, workflows: false, auth: true })
// Firebase waits for gapi's onload, which the empty stub never calls.
await context.route('https://apis.google.com/js/api.js*', (route) =>
route.abort('blockedbyclient')
)
const proxy = await mockReshootProxy(page, MODELS_WORKSPACE_TOKEN)
await page.goto('/login/')
await page.getByRole('button', { name: 'Use email instead' }).click()
await page.getByLabel('Email').fill(account.email)
await page.getByLabel('Password', { exact: true }).fill(account.password)
await page.getByRole('button', { name: 'Sign in', exact: true }).click()
await expect(page).toHaveURL('/')

await page.goto('/models/apps/reshoot/')
await page.getByText('Sci-fi pilot').first().click()
await expect(page.getByTestId('reshoot-drag-hint')).toBeVisible()
expect(proxy).toEqual(
expect.arrayContaining([
'POST /assets',
'POST /jobs',
'GET /jobs/e2e-reshoot-analyze/outputs/geo/content'
])
)
}

test('opens Cinematic Studio on the apps flag alone', async ({
page,
context
Expand Down Expand Up @@ -104,50 +144,46 @@ test('asks Safari for a first frame on the Re-shoot example video tile', async (
)
})

test('@mobile keeps the Re-shoot aim badges to one line on a phone', async ({
page,
context
}) => {
await mockFlags(context, { apps: true, workflows: false })
await page.goto('/models/apps/reshoot/')
await page.getByText('Sci-fi pilot').first().click()

const viewport = page.getByTestId('reshoot-viewport').first()
await expect(
viewport.getByText('Drag to orbit', { exact: true })
).toBeVisible()
await expect(viewport.getByText(/Scroll to move closer/)).toBeHidden()
signedInTest(
'@mobile keeps the Re-shoot aim badges to one line on a phone',
async ({ page, context, modelsAccount }) => {
await openReadReshootScene(page, context, modelsAccount)

for (const badge of [
viewport.getByTestId('reshoot-drag-hint'),
viewport.getByTestId('reshoot-angle-readout')
]) {
const box = await badge.boundingBox()
expect(box?.height).toBeLessThan(40)
const viewport = page.getByTestId('reshoot-viewport').first()
await expect(
viewport.getByText('Drag to orbit', { exact: true })
).toBeVisible()
await expect(viewport.getByText(/Scroll to move closer/)).toBeHidden()

for (const badge of [
viewport.getByTestId('reshoot-drag-hint'),
viewport.getByTestId('reshoot-angle-readout')
]) {
const box = await badge.boundingBox()
expect(box?.height).toBeLessThan(40)
}
}
})

test('@mobile pins the Re-shoot preview while the camera controls scroll under it', async ({
page,
context
}) => {
await mockFlags(context, { apps: true, workflows: false })
await page.goto('/models/apps/reshoot/')
await page.getByText('Sci-fi pilot').first().click()

const frame = page.getByTestId('reshoot-frame')
const distance = page.getByRole('slider', { name: /Distance/ })
await page.getByTestId('reshoot-action').scrollIntoViewIfNeeded()
const pinned = await frame.boundingBox()
expect(pinned?.y).toBeGreaterThanOrEqual(0)
expect(pinned?.y).toBeLessThan(120)

const before = Number(await distance.inputValue())
await page.getByRole('button', { name: 'Move the camera closer' }).tap()
await expect
.poll(async () => Number(await distance.inputValue()))
.toBeLessThan(before)
})
)

signedInTest(
'@mobile pins the Re-shoot preview while the camera controls scroll under it',
async ({ page, context, modelsAccount }) => {
await openReadReshootScene(page, context, modelsAccount)

const frame = page.getByTestId('reshoot-frame')
const distance = page.getByRole('slider', { name: /Distance/ })
await page.getByTestId('reshoot-action').scrollIntoViewIfNeeded()
const pinned = await frame.boundingBox()
expect(pinned?.y).toBeGreaterThanOrEqual(0)
expect(pinned?.y).toBeLessThan(120)

const before = Number(await distance.inputValue())
await page.getByRole('button', { name: 'Move the camera closer' }).tap()
await expect
.poll(async () => Number(await distance.inputValue()))
.toBeLessThan(before)
}
)

test('shows a preview frame for every Cinematic Studio shot option', async ({
page,
Expand Down
1 change: 1 addition & 0 deletions apps/website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"scripts": {
"dev": "astro dev",
"dev:no-toolbar": "cross-env NO_TOOLBAR=1 astro dev",
"dev:crossview-proxy": "tsx scripts/crossview-dev-proxy.ts",
"build": "astro build",
"format": "prettier --write \"src/**/*.astro\"",
"format:check": "prettier --check \"src/**/*.astro\"",
Expand Down
Loading
Loading