feat(app): artifact videos play in the viewer, as the web

This commit is contained in:
2026-10-23 14:41:30 +01:00
parent d1555e721f
commit 6fd14e76ca
9 changed files with 345 additions and 17 deletions
+32 -5
View File
@@ -93,6 +93,23 @@ const probePng = () => {
const png = probePng();
const probeCsv = Buffer.from('id,name\n1,alpha\n2,beta\n');
// A real one-second H.264 clip, so the in-app player is exercised against a
// playable file (ffmpeg is required for this probe).
async function probeMp4() {
const dir = await mkdtemp(join(tmpdir(), 'gallery-mp4-'));
const file = join(dir, 'clip.mp4');
const ffmpeg = spawn('ffmpeg', [
'-loglevel', 'error', '-f', 'lavfi', '-i', 'testsrc=size=320x180:rate=10',
'-t', '1', '-pix_fmt', 'yuv420p', '-c:v', 'libx264', '-movflags', '+faststart', file,
]);
const [code] = await once(ffmpeg, 'exit');
if (code !== 0) throw new Error('ffmpeg could not create the probe video');
const bytes = await readFile(file);
await rm(dir, { recursive: true, force: true });
return bytes;
}
const mp4 = await probeMp4();
const server = createServer(async (req, res) => {
const pathname = decodeURIComponent(new URL(req.url, 'http://localhost').pathname);
if (pathname.startsWith('/fixture/')) {
@@ -114,6 +131,11 @@ const server = createServer(async (req, res) => {
res.end(png);
return;
}
if (pathname.endsWith('.mp4')) {
res.writeHead(200, { 'content-type': 'video/mp4', 'content-length': mp4.length });
res.end(mp4);
return;
}
res.writeHead(200, { 'content-type': 'text/plain; charset=utf-8' });
res.end(`recorded artifact ${pathname}\n`);
return;
@@ -566,18 +588,23 @@ try {
if (!videoBody.includes('4 of 4 · video/mp4')) {
throw new Error(`Viewer did not page to the video: ${JSON.stringify(videoBody)}`);
}
if (!videoBody.includes('This file type cannot be previewed here.')) {
throw new Error(`Video was not marked unpresentable: ${JSON.stringify(videoBody)}`);
// The video plays in-app: its player loads the real clip and offers Play.
for (let i = 0; i < 20 && !(await hasLabel('Play video')); i++) await delay(250);
if (!(await hasLabel('Play video'))) {
throw new Error(`Video did not load in the player: ${JSON.stringify(await bodyText())}`);
}
if ((await bodyText()).includes('The video could not be played.')) {
throw new Error('The playable probe clip was reported as unplayable');
}
if (!(await hasLabel('Open')) || !(await hasLabel('Copy link'))) {
throw new Error(`Unsupported page lost its actions: ${JSON.stringify(await labels())}`);
throw new Error(`Video page lost its actions: ${JSON.stringify(await labels())}`);
}
await capture('a1w-viewer-video');
await clickExact('Next artifact');
if (!(await bodyText()).includes('4 of 4 · video/mp4')) {
throw new Error('Next past the last artifact changed the page');
}
evidence.checks.push({ check: 'unsupported types are explicit with Open/Copy and paging clamps', value: true });
await capture('a1w-viewer-unsupported');
evidence.checks.push({ check: 'a video plays in-app with Open/Copy and paging clamps', value: true });
await clickExact('Previous artifact');
await clickExact('Previous artifact');