Lint and format with Biome, and retire used share codes
Biome formats and lints the TypeScript, the Vue templates and the CSS: pnpm lint checks, pnpm format fixes. It keeps the existing style, single quotes and 120 columns, and leaves the vendored logo alone. Besides its recommended rules it looks for promises nobody awaits. Rules that only flagged deliberate code are off: non-null assertions that state what the code guarantees, CSS order where no two rules set the same property, and fieldset for role="group". The one-time formatting pass mostly splits long chains. Promises that are deliberately not awaited are marked with void, none of them can reject today. Buttons say type="button", the any for peer messages and the checkbox switch keep their reasons in ignore comments. The sender's code also counts as no longer valid once a transfer started: that closes the trackers, so another receiver would wait for nothing, yet the card still offered the code with Copy. The tracker transfer tests check it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
2167b528b2
commit
b6b6e7c29b
9 files changed
+371
-122
No files matched your search
+59
-20
@@ -4,15 +4,15 @@ import { createReadStream } from 'node:fs';
|
||||
import { open as openFile, readFile, writeFile } from 'node:fs/promises';
|
||||
import { networkInterfaces } from 'node:os';
|
||||
import {
|
||||
chromium,
|
||||
expect,
|
||||
firefox,
|
||||
test,
|
||||
type Browser,
|
||||
type BrowserContext,
|
||||
type BrowserType,
|
||||
chromium,
|
||||
expect,
|
||||
firefox,
|
||||
type Page,
|
||||
type WebSocket as PageSocket,
|
||||
test,
|
||||
type WebSocketRoute,
|
||||
} from '@playwright/test';
|
||||
import { build, createServer, preview, type ViteDevServer } from 'vite';
|
||||
@@ -130,7 +130,8 @@ test.afterAll(async () => {
|
||||
|
||||
// init runs in the page before the app. base is the app's URL, the dev server's by default.
|
||||
async function open(name: string, { init, base = url }: { init?: () => void; base?: string } = {}) {
|
||||
const browser = await (browsers[name] ??= BROWSERS[name]!.launch());
|
||||
browsers[name] ??= BROWSERS[name]!.launch();
|
||||
const browser = await browsers[name];
|
||||
const context = await browser.newContext({ permissions: PERMISSIONS[name] });
|
||||
contexts.push(context);
|
||||
const page = await context.newPage();
|
||||
@@ -192,8 +193,10 @@ function trackPeers() {
|
||||
// Everything the page opened for a transfer is closed again: its peer connections and tracker sockets.
|
||||
async function expectClosed(page: Page) {
|
||||
const peers = () =>
|
||||
page.evaluate(() =>
|
||||
(window as unknown as { peers: RTCPeerConnection[] }).peers.filter((pc) => pc.signalingState !== 'closed').length,
|
||||
page.evaluate(
|
||||
() =>
|
||||
(window as unknown as { peers: RTCPeerConnection[] }).peers.filter((pc) => pc.signalingState !== 'closed')
|
||||
.length,
|
||||
);
|
||||
await expect.poll(peers).toBe(0);
|
||||
await expect.poll(() => sockets.get(page)!.filter((ws) => !ws.isClosed()).length).toBe(0);
|
||||
@@ -289,7 +292,10 @@ async function withLogs(sender: Page, receiver: Page, fn: () => Promise<void>) {
|
||||
try {
|
||||
await fn();
|
||||
} finally {
|
||||
for (const [name, page] of [['sender', sender], ['receiver', receiver]] as const) {
|
||||
for (const [name, page] of [
|
||||
['sender', sender],
|
||||
['receiver', receiver],
|
||||
] as const) {
|
||||
await test.info().attach(`${name} log`, { body: (await log(page).catch(() => null)) ?? '' });
|
||||
}
|
||||
}
|
||||
@@ -353,6 +359,11 @@ async function transfer(
|
||||
expect(await hash(await download.path())).toBe(await hash(source));
|
||||
await expect(receiver.locator('#log')).toContainText('download complete');
|
||||
await expect(sender.locator('#log')).toContainText('delivered');
|
||||
if (mode === 'tracker') {
|
||||
// The transfer used the share up, another receiver would wait for nothing.
|
||||
await expect(sender.locator('label[for=send-code]')).toHaveText('Code, no longer valid:');
|
||||
await expect(sender.locator('#copy-send-code')).toBeDisabled();
|
||||
}
|
||||
await expect(sender.locator('#send-progress')).toHaveJSProperty('value', 100);
|
||||
await expect(receiver.locator('#receive-progress')).toHaveJSProperty('value', 100);
|
||||
// Removed hidden pages release the service worker for updates.
|
||||
@@ -383,7 +394,10 @@ for (const from of Object.keys(BROWSERS)) {
|
||||
// Through the public STUN servers and trackers. The signaling doesn't depend on the browser pair, one
|
||||
// pairing each way is enough.
|
||||
for (const mode of ['manual', 'tracker']) {
|
||||
for (const [from, to] of [['chromium', 'firefox'], ['firefox', 'chromium']] as const) {
|
||||
for (const [from, to] of [
|
||||
['chromium', 'firefox'],
|
||||
['firefox', 'chromium'],
|
||||
] as const) {
|
||||
test(`live ${mode}: ${from} sends to ${to}`, async () => {
|
||||
const [sender, receiver] = await Promise.all([open(from), open(to)]);
|
||||
await transfer(mode, sender, receiver, await payload(randomBytes(SIZE)), SIZE);
|
||||
@@ -409,7 +423,10 @@ for (const name of Object.keys(BROWSERS)) {
|
||||
test(`servers: ${name} skips invalid lines and keeps the lists over a reload`, async () => {
|
||||
const page = await open(name);
|
||||
const core = () =>
|
||||
page.evaluate((path) => import(path).then(({ settings }) => [settings.stunServers, settings.trackers]), '/src/core.ts');
|
||||
page.evaluate(
|
||||
(path) => import(path).then(({ settings }) => [settings.stunServers, settings.trackers]),
|
||||
'/src/core.ts',
|
||||
);
|
||||
await page.click('#servers summary');
|
||||
// Both would make the constructors throw.
|
||||
await page.fill('#stun-servers', 'stun:stun.example:99999');
|
||||
@@ -465,7 +482,9 @@ for (const name of Object.keys(BROWSERS)) {
|
||||
await updateWorker(receiver);
|
||||
// The update has to wait instead of replacing the worker that feeds the download.
|
||||
await expect
|
||||
.poll(() => receiver.evaluate(async () => !!(await navigator.serviceWorker.getRegistration('download/'))?.waiting))
|
||||
.poll(() =>
|
||||
receiver.evaluate(async () => !!(await navigator.serviceWorker.getRegistration('download/'))?.waiting),
|
||||
)
|
||||
.toBe(true);
|
||||
expect(await updated(receiver)).toBe(false);
|
||||
await release(receiver);
|
||||
@@ -633,7 +652,9 @@ for (const name of Object.keys(BROWSERS)) {
|
||||
await inject(sender, 10_000);
|
||||
const { download } = await started;
|
||||
await inject(sender, 10_001);
|
||||
await expect(receiver.locator('#receive-error')).toHaveText('download failed: the sender sent more than it offered');
|
||||
await expect(receiver.locator('#receive-error')).toHaveText(
|
||||
'download failed: the sender sent more than it offered',
|
||||
);
|
||||
await expect(receiver.locator('iframe')).toHaveCount(0);
|
||||
// Firefox leaves the download stalled instead of failing it, see TODO.md.
|
||||
if (name === 'chromium') expect(await download.failure()).not.toBeNull();
|
||||
@@ -730,7 +751,12 @@ for (const name of Object.keys(BROWSERS)) {
|
||||
await receiver.fill('#receive-code', (await sender.locator('#send-code').textContent())!);
|
||||
await receiver.click('#receive');
|
||||
await expect(receiver.locator('#receive-error')).toHaveText(rejected);
|
||||
await expect.poll(() => trackers.map(({ sockets, open }) => [sockets.length, open])).toEqual([[2, 0], [2, 0]]);
|
||||
await expect
|
||||
.poll(() => trackers.map(({ sockets, open }) => [sockets.length, open]))
|
||||
.toEqual([
|
||||
[2, 0],
|
||||
[2, 0],
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -739,7 +765,8 @@ for (const name of Object.keys(BROWSERS)) {
|
||||
test(`tracker: ${name} sender keeps nothing of repeated unusable offers`, async () => {
|
||||
const sender = await open(name, { init: countAbortListeners });
|
||||
const trackers = await mockTrackers(sender, ({ info_hash }) => ({ action: 'announce', interval: 120, info_hash }));
|
||||
const listeners = () => sender.evaluate(() => (window as unknown as { abortListeners: () => number }).abortListeners());
|
||||
const listeners = () =>
|
||||
sender.evaluate(() => (window as unknown as { abortListeners: () => number }).abortListeners());
|
||||
const unusable = async () => (await log(sender))!.match(/unusable offer/g)?.length ?? 0;
|
||||
|
||||
await withLogs(sender, sender, async () => {
|
||||
@@ -765,6 +792,7 @@ for (const name of Object.keys(BROWSERS)) {
|
||||
test(`tracker: ${name} both sides announce again until they give up after 6 minutes`, async () => {
|
||||
const pages = await Promise.all([open(name), open(name)]);
|
||||
const [sender, receiver] = pages as [Page, Page];
|
||||
// biome-ignore lint/suspicious/noExplicitAny: raw tracker messages, the test reads nested fields as it needs them
|
||||
const announced = pages.map(() => [] as Record<string, any>[]);
|
||||
// 0 would announce in a loop, the app waits 30 s at least.
|
||||
const trackers = await Promise.all(
|
||||
@@ -795,10 +823,16 @@ for (const name of Object.keys(BROWSERS)) {
|
||||
await expect.poll(() => again().map((msgs) => msgs.length)).toEqual([2, 2]);
|
||||
// The receiver's offers again, a busy sender may have dropped them.
|
||||
const offers = announced[1]!.filter((msg) => msg.event === 'started').map((msg) => msg.offers[0].offer_id);
|
||||
expect(again()[1]!.map((msg) => msg.offers[0].offer_id).sort()).toEqual(offers.sort());
|
||||
expect(
|
||||
again()[1]!
|
||||
.map((msg) => msg.offers[0].offer_id)
|
||||
.sort(),
|
||||
).toEqual(offers.sort());
|
||||
|
||||
await fastForward(330_000);
|
||||
await expect(sender.locator('#send-error')).toHaveText('nobody received the file within 6 minutes, share it again');
|
||||
await expect(sender.locator('#send-error')).toHaveText(
|
||||
'nobody received the file within 6 minutes, share it again',
|
||||
);
|
||||
await expect(sender.locator('label[for=send-code]')).toHaveText('Code, no longer valid:');
|
||||
await expect(sender.locator('#copy-send-code')).toBeDisabled();
|
||||
await expect(receiver.locator('#receive-error')).toHaveText(
|
||||
@@ -823,7 +857,9 @@ for (const name of Object.keys(BROWSERS)) {
|
||||
),
|
||||
);
|
||||
const deadlines = () =>
|
||||
Promise.all(pages.map((page) => page.evaluate(() => (window as unknown as { deadlines: () => number }).deadlines())));
|
||||
Promise.all(
|
||||
pages.map((page) => page.evaluate(() => (window as unknown as { deadlines: () => number }).deadlines())),
|
||||
);
|
||||
|
||||
await withLogs(sender, receiver, async () => {
|
||||
await sender.setInputFiles('input[type=file]', await payload(randomBytes(1000)));
|
||||
@@ -886,9 +922,12 @@ for (const name of Object.keys(BROWSERS)) {
|
||||
// The sender notices the receiver left, Chromium only once the connection counts as failed.
|
||||
await expect(sender.locator('#log')).toContainText('waiting for the next receiver', { timeout: 30_000 });
|
||||
|
||||
await expect(receiver.locator('#check-local')).toHaveText(new RegExp(`^(?!${first}$)([0-9A-F]{2} ){7}[0-9A-F]{2}$`), {
|
||||
timeout: 45_000,
|
||||
});
|
||||
await expect(receiver.locator('#check-local')).toHaveText(
|
||||
new RegExp(`^(?!${first}$)([0-9A-F]{2} ){7}[0-9A-F]{2}$`),
|
||||
{
|
||||
timeout: 45_000,
|
||||
},
|
||||
);
|
||||
await expect(sender.locator('#check-remote')).toHaveText((await receiver.locator('#check-local').textContent())!);
|
||||
const started = downloadStarts(receiver);
|
||||
await sender.click('#confirm');
|
||||
|
||||
Reference in new issue
Block a user