import { test, expect } from '@playwright/test'; import { createHash, createPublicKey, verify } from 'node:crypto'; test('Mac download matches the website release manifest', async ({ request }) => { const manifestResponse = await request.get('/mac-release.json'); expect(manifestResponse.ok()).toBeTruthy(); const manifest = await manifestResponse.json(); expect(manifest.version).toMatch(/^\d+(\.\d+){1,2}$/); expect(manifest.build).toBeGreaterThan(0); expect(manifest.file).toBe(`Jotley-${manifest.version}-${manifest.build}.dmg`); const response = await request.get(`https://jotley.ai/${manifest.file}`); expect(response.ok()).toBeTruthy(); const bytes = await response.body(); expect(bytes.length).toBe(manifest.bytes); expect(createHash('sha256').update(bytes).digest('hex')).toBe(manifest.sha256); }); test('the website and Sparkle serve the same signed Mac release', async ({ request }) => { const manifestResponse = await request.get('/mac-release.json'); expect(manifestResponse.ok()).toBeTruthy(); const manifest = await manifestResponse.json(); const feedResponse = await request.get('/appcast.xml'); expect(feedResponse.ok()).toBeTruthy(); const feed = await feedResponse.text(); const firstItem = feed.match(/[\s\S]*?<\/item>/)?.[0] ?? ''; const url = firstItem.match(/]*\burl="(https:\/\/jotley\.ai\/Jotley-[\w.-]+\.dmg)"/)?.[1]; const length = firstItem.match(/]*\blength="(\d+)"/)?.[1]; const signature = firstItem.match(/sparkle:edSignature="([^"]+)"/)?.[1]; expect(firstItem).toContain(`${manifest.build}`); expect(firstItem).toContain(`${manifest.version}`); const feedBuilds = Array.from(feed.matchAll(/(\d+)<\/sparkle:version>/g), match => Number(match[1])); expect(Math.max(...feedBuilds)).toBe(manifest.build); expect(url).toBe(`https://jotley.ai/${manifest.file}`); expect(Number(length)).toBe(manifest.bytes); expect(signature).toBeTruthy(); expect(firstItem).toContain('27.0'); const response = await request.get(url!); expect(response.ok()).toBeTruthy(); const bytes = await response.body(); expect(bytes.length).toBe(Number(length)); expect(createHash('sha256').update(bytes).digest('hex')).toBe(manifest.sha256); const key = createPublicKey({ key: Buffer.concat([ Buffer.from('302a300506032b6570032100', 'hex'), Buffer.from('oVkqL3P3OGrwFhzgcWJQcF2dQ2Dn2rBvlB3bNOXGZSc=', 'base64'), ]), type: 'spki', format: 'der', }); expect(verify(null, bytes, key, Buffer.from(signature!, 'base64'))).toBeTruthy(); }); test('the installation page shows free feedback and downloads only after a click', async ({ page, request }) => { const manifest = await (await request.get('/mac-release.json')).json(); await page.goto('/'); const links = page.getByRole('link', { name: 'Download for Mac', exact: true }); expect(await links.count()).toBe(3); await expect(page.locator('.mac-availability, .mac-download-status')).toHaveCount(0); await expect(page.locator('.platform-downloads').filter({ hasText: /coming soon/i })).toHaveCount(0); // Two TestFlight pills plus the phone-width header link. await expect(page.locator('a[href="https://testflight.apple.com/join/1y7UFzjK"]')).toHaveCount(3); await expect(page.getByRole('link', { name: 'Join the TestFlight beta', exact: true }).first()).toHaveAttribute('href', 'https://testflight.apple.com/join/1y7UFzjK'); await expect(page.locator('a[href*="apps.apple.com"]')).toHaveCount(0); for (const link of await links.all()) await expect(link).toHaveAttribute('href', '/download'); const downloads: string[] = []; page.on('download', download => downloads.push(download.suggestedFilename())); await page.goto('/download'); await expect(page.getByRole('heading', { name: 'Free software. Supported by people.' })).toBeVisible(); const feedback = page.locator('.dl-support').getByRole('link', { name: 'Send feedback' }); await expect(feedback).toHaveAttribute('href', 'https://projectatom.ai/apps?app=jotley#feedback'); await expect(page.locator('.dl-support')).not.toContainText(/tip|coffee|paid/i); const downloadButton = page.getByRole('link', { name: 'Download Jotley for Mac', exact: true }); await expect(downloadButton).toHaveAttribute('href', `/${manifest.file}`); const feedbackBounds = await feedback.boundingBox(); const downloadBounds = await downloadButton.boundingBox(); expect(feedbackBounds!.y + feedbackBounds!.height).toBeLessThan(downloadBounds!.y); await expect(page.getByRole('heading', { name: 'Download the Installer' })).toBeVisible(); await expect(page.getByRole('heading', { name: 'Open DMG, Drag to Applications & Launch' })).toBeVisible(); await expect(page.getByRole('heading', { name: 'Confirm Opening & Grant Permissions' })).toBeVisible(); for (const alt of ['Jotley DMG file in Downloads folder', 'Jotley installer window, showing the app icon, Applications shortcut, and instructions to drag Jotley into Applications', 'Confirm opening Jotley', 'Jotley microphone access prompt']) { const image = page.getByRole('img', { name: alt, exact: true }); await image.scrollIntoViewIfNeeded(); await expect.poll(() => image.evaluate(el => (el as HTMLImageElement).naturalWidth)).toBeGreaterThan(0); } const installer = page.locator('.dl-shot--installer'); await expect(installer.getByRole('img')).toHaveAttribute('src', '/install-jotley.png'); await expect(installer.locator('.dl-mark')).toHaveCount(0); expect(downloads).toEqual([]); const retry = page.waitForEvent('download'); await downloadButton.click(); expect((await retry).suggestedFilename()).toBe(manifest.file); expect(downloads).toEqual([manifest.file]); }); test('the singular installation page is canonical', async ({ request, baseURL }) => { const page = await request.get('/download', { maxRedirects: 0 }); expect(page.status()).toBe(200); expect(page.headers().location).toBeUndefined(); expect(await page.text()).toContain('https://jotley.ai/download'); const legacyPage = await request.get('/downloads', { maxRedirects: 0 }); const local = ['localhost', '127.0.0.1'].includes(new URL(baseURL!).hostname); if (local) { expect(legacyPage.status()).toBe(404); } else { expect(legacyPage.status()).toBe(308); expect(legacyPage.headers().location).toBe('/download'); } });