Browser suite: feeds in every shape, a feed that starts failing, ipxd user (#463); coverage build's stylesheet named by its own hash (#464)

Atom, RSS with a bare ampersand and the iTunes and Media RSS fields, WordPress.com's posts,
and replies that are no feed are added through the API; a fixture feed turned 404, 403,
402, 500, a sentence, a web page linking its new address, garbled, a redirect loop and a
dropped connection says each, and after a day (error_since set back in the suite's SQLite)
in words, with the page's banner; ipxd user's commands and their refusals. API coverage
76.5% to 78.0%: failure.rs 12% to 91%, parse.rs 56% to 92%, cli.rs 44% to 86%.

#464: with IPX_COVERAGE=1 the page named app.css by the hash of it unminified while the
build wrote it minified. The worker's check from #449 reloaded the page for it, and its
throttle then swallowed the reload the #449 test waits for, which failed in every coverage
run. buildStyle now defaults to the page's choice.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-15 00:12:44 +00:00
parent eda77e87c7
commit b22016cbe5
3 changed files with 186 additions and 1 deletions

View File

@@ -613,6 +613,105 @@ test('a show inside an OPML can be kept, and only it', async ({ page }) => {
await expect(page.locator('#content [data-a="keep"]')).toHaveCount(0); await expect(page.locator('#content [data-a="keep"]')).toHaveCount(0);
}); });
test('feeds in every shape are read, and what is no feed is refused saying why (#463)', async ({ page }) => {
const F = 'http://127.0.0.1:8792';
const add = (url: string) => page.request.post('/api/feeds', { data: { url } });
for (const [file, said] of [
['said.txt', 'the site sent "Unable to establish a DB connection" instead of a feed'],
['long.txt', '…" instead of a feed'],
['empty.xml', 'the site sent an empty reply'],
['garbled.xml', 'not RSS ('],
] as const) {
const r = await add(`${F}/${file}`);
expect(r.status(), file).toBe(400);
expect(await r.text(), file).toContain(said);
}
const ids: Record<string, string> = {};
for (const file of ['atom.xml', 'amp.xml', 'wp.json']) {
const r = await add(`${F}/${file}`);
expect(r.status(), file).toBe(200);
ids[file] = (await r.json()).id;
}
const entries = async (file: string) => ((await (await page.request.get(
`/api/feeds/${encodeURIComponent(ids[file]!)}/entries?limit=50`)).json()) as ListPage).entries;
const byTitle = async (file: string) => Object.fromEntries((await entries(file)).map(e => [e.title, e]));
const feed = async (file: string) => (await (await page.request.get('/api/feeds')).json() as Feed[])
.find(f => f.id === ids[file])!;
// Atom: its title's entity decoded, the player's repeat of one file dropped, Markdown made HTML.
await expect.poll(async () => Object.keys(await byTitle('atom.xml')).sort(), { timeout: 20_000 })
.toEqual(['Markdown entry', 'Q&A in Atom']);
const atom = await byTitle('atom.xml');
expect(atom['Q&A in Atom']!.enclosures).toHaveLength(1);
expect(atom['Q&A in Atom']!.description).toContain('<b>notes</b>');
expect(atom['Markdown entry']!.description).toContain('<strong>bold</strong>');
expect((await feed('atom.xml')).title).toBe('Atom’s Show');
// A bare "&" read after all, with the iTunes and Media RSS fields.
await expect.poll(async () => Object.keys(await byTitle('amp.xml')).length, { timeout: 20_000 }).toBe(3);
const amp = await byTitle('amp.xml');
expect(amp['Tom & Jerry']!.duration).toBe(3723);
expect(amp['Tom & Jerry']!.image).toBe(`${F}/art2.jpg`);
expect(amp['Tom & Jerry']!.description).toMatch(/^<p><em>A subtitle not in the body<\/em><\/p>/);
expect(amp['Cut body']!.description).toBe('The whole description');
expect(amp['Cut body']!.image).toBe(`${F}/pic.png`);
expect(amp['Picture only']!.image).toBe(`${F}/amp-pic.png`);
expect((await feed('amp.xml')).feed_category).toBe('Games');
// WordPress.com's posts, as its API sends them, read as a feed.
await expect.poll(async () => Object.keys(await byTitle('wp.json')), { timeout: 20_000 })
.toEqual(['WordPress “post”']);
for (const id of Object.values(ids)) await page.request.delete(`/api/feeds/${encodeURIComponent(id)}`);
});
test('a feed that starts failing says why, and after a day in words with something to do (#463)', async ({ page }) => {
const F = 'http://127.0.0.1:8792';
const flip = (to: string) => page.request.get(`${F}/flip?to=${to}`);
await flip('ok');
const id = (await (await page.request.post('/api/feeds', { data: { url: `${F}/flip.xml` } })).json()).id as string;
const feed = async () => (await (await page.request.get('/api/feeds')).json() as Feed[]).find(f => f.id === id)!;
await expect.poll(async () => (await feed()).entries, { timeout: 20_000 }).toBe(1);
const db = path.join(setup.root, 'data', 'state.db');
try {
for (const [to, error, reason] of [
['404', /HTTP 404/, 'took this feed down'],
['403', /HTTP 403/, 'refuses'],
['402', /HTTP 402/, 'paid plan'],
['500', /HTTP 500/, null],
['text', /the site sent/, 'sent a message'],
['page', /got a web page, not a feed; it links .*moved\.xml/, 'The feed moved'],
['garbled', /not RSS/, null],
['loop', /redirect/i, null],
['drop', /./, null],
] as const) {
await flip(to);
await page.request.post('/api/fetch', { data: { feed: id, force: true } });
await expect.poll(async () => (await feed()).last_error ?? '', { timeout: 20_000 }).toMatch(error);
// A day in, which is when the page names a failure in words.
execFileSync('sqlite3', [db, `UPDATE feeds SET error_since = ${Math.floor(Date.now() / 1000) - 2 * 86_400} WHERE id = '${id}'`]);
const f = await feed();
if (reason) expect(f.failing?.reason, to).toContain(reason);
else expect(f.failing, to).toBeNull();
if (to === 'page') {
expect(f.failing?.new_url).toBe(`${F}/moved.xml`);
await page.reload();
await page.locator('#feedlist .feed', { hasText: 'Flip Show' }).click();
await expect(page.locator('#content .fail')).toContainText('The feed moved');
await expect(page.locator('#content [data-ffail="newurl"]')).toBeVisible();
}
}
// Back again: the error goes, and so does the banner.
await flip('ok');
await page.request.post('/api/fetch', { data: { feed: id, force: true } });
await expect.poll(async () => (await feed()).last_error, { timeout: 20_000 }).toBeNull();
} finally {
await flip('ok');
await page.request.delete(`/api/feeds/${encodeURIComponent(id)}`);
}
});
test('an item sent as HTML and Markdown switches between them', async ({ page }) => { test('an item sent as HTML and Markdown switches between them', async ({ page }) => {
const api = (p: string, init?: { method?: string, body?: string }) => page.evaluate(([p, init]) => fetch(p, { headers: { 'Content-Type': 'application/json' }, ...init }) const api = (p: string, init?: { method?: string, body?: string }) => page.evaluate(([p, init]) => fetch(p, { headers: { 'Content-Type': 'application/json' }, ...init })
.then((r) => r.json().catch(() => null)), [p, init] as const); .then((r) => r.json().catch(() => null)), [p, init] as const);
@@ -1028,6 +1127,37 @@ test('an export from one account imports into another', async ({ page, browser }
await ctx.close(); await ctx.close();
}); });
test('ipxd user adds, lists, renames and removes accounts, and says what is wrong (#463)', async () => {
// Its own database, as the import test has, so the suite's accounts are not touched.
const dir = path.join(setup.root, 'cli-users');
fs.rmSync(dir, { recursive: true, force: true });
fs.mkdirSync(path.join(dir, 'data'), { recursive: true });
fs.writeFileSync(path.join(dir, 'config.toml'),
`[general]\ndownload_dir = "${dir}/downloads"\nsocket = "${dir}/ipx.sock"\n`);
const env = { ...process.env, IPX_CONFIG: path.join(dir, 'config.toml'), IPX_DATA_DIR: path.join(dir, 'data') };
const ipx = (args: string[], input = '') => execFileSync(setup.IPX_BIN, ['user', ...args], { env, input, encoding: 'utf8' });
const fails = (args: string[], input = '') => { try { ipx(args, input); } catch (e) { return said(e); } throw new Error(`${args} succeeded`); };
expect(ipx(['list'])).toContain('no accounts yet');
expect(fails(['add', 'ada'])).toContain('no password on stdin');
expect(fails(['add', ' '])).toContain('a name is required');
expect(ipx(['add', 'Ada'], 'adapassword\n')).toBe('added ada (admin)\n');
expect(fails(['add', 'ada'], 'x')).toContain('ada already exists');
expect(ipx(['add', 'bo', '--no-password'])).toBe('added bo, signs in through the proxy\n');
const list = ipx(['list']);
expect(list).toMatch(/^ada\s+admin\s+password\s+added \d{4}-\d\d-\d\d\s+never signed in$/m);
expect(list).toMatch(/^bo\s+proxy only\s+added /m);
expect(ipx(['passwd', 'ada'], 'newpassword')).toContain('password changed for ada');
expect(fails(['passwd', 'nobody'], 'x')).toContain('no such account: nobody');
expect(fails(['rename', 'bo', 'b;o'])).toContain('not a usable name');
expect(fails(['rename', 'bo', 'ada'])).toContain('ada already exists');
expect(ipx(['rename', 'bo', 'bea'])).toBe('renamed bo to bea\n');
expect(ipx(['rm', 'bea'])).toBe('removed bea\n');
expect(fails(['rm', 'bea'])).toContain('no such account: bea');
expect(ipx(['list'])).not.toContain('bea');
});
test('ipxd import subscribes the admin, and ipxd export writes the feeds out', async () => { test('ipxd import subscribes the admin, and ipxd export writes the feeds out', async () => {
// Its own config and database. The CLI works in-process, and the suite's running daemon // Its own config and database. The CLI works in-process, and the suite's running daemon
// reads config.toml once at start, so it would not see what the CLI added anyway. // reads config.toml once at start, so it would not see what the CLI added anyway.

View File

@@ -6,6 +6,8 @@ import path from 'node:path';
const dir = import.meta.dirname; const dir = import.meta.dirname;
const port = Number(process.env.FIXTURE_PORT || 8792); const port = Number(process.env.FIXTURE_PORT || 8792);
let flip = 'ok';
http.createServer((req, res) => { http.createServer((req, res) => {
// Jev, for Signals (#254): sure of an item whose text has a question's keyword in it. Refuses // Jev, for Signals (#254): sure of an item whose text has a question's keyword in it. Refuses
// a request in the shape TypeSafe refuses, as it does (#257). // a request in the shape TypeSafe refuses, as it does (#257).
@@ -87,6 +89,59 @@ http.createServer((req, res) => {
next(); next();
return; return;
} }
// Feeds in the shapes the others are not (#463): Atom; RSS with a bare "&" and the iTunes and
// Media RSS fields; WordPress.com's posts as its API sends them; and replies that are no feed.
const at = `http://127.0.0.1:${port}`;
const shapes: Record<string, [string, string]> = {
'/atom.xml': ['application/atom+xml', `<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom"><title type="html">Atom&amp;#8217;s Show</title>
<subtitle>An Atom feed</subtitle><link rel="alternate" href="${at}/atom.html"/><logo>${at}/art.jpg</logo>
<id>urn:atom-show</id><updated>2026-01-01T00:00:00Z</updated>
<entry><id>urn:atom-1</id><title>Q&amp;A in Atom</title><updated>2026-01-02T00:00:00Z</updated>
<published>2026-01-02T00:00:00Z</published><link rel="alternate" href="${at}/atom-1.html"/>
<link rel="enclosure" href="${at}/atom-1.mp3" type="audio/mpeg" length="40000"/>
<link rel="enclosure" href="${at}/atom-1.mp3?_=1" type="audio/mpeg" length="40000"/>
<category term="tech"/><summary>Short summary</summary>
<content type="html">&lt;p&gt;Full &lt;b&gt;notes&lt;/b&gt;&lt;/p&gt;</content></entry>
<entry><id>urn:atom-2</id><title>Markdown entry</title><updated>2026-01-03T00:00:00Z</updated>
<summary>A [link](http://example.com) and **bold**</summary></entry></feed>`],
'/amp.xml': ['application/rss+xml', `<?xml version="1.0"?>
<rss version="2.0" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:media="http://search.yahoo.com/mrss/" xmlns:content="http://purl.org/rss/1.0/modules/content/">
<channel><title>Ampersand Radio</title><link>${at}/amp.html?a=1&b=2</link><description></description><ttl>90</ttl>
<itunes:summary>Summary from iTunes</itunes:summary><itunes:explicit>yes</itunes:explicit>
<itunes:category text="Leisure"><itunes:category text="Games"/></itunes:category>
<item><guid>amp-1</guid><title>Tom & Jerry</title><pubDate>2026-01-05T10:00:00Z</pubDate>
<itunes:duration>1:02:03</itunes:duration><media:thumbnail url="${at}/art2.jpg"/>
<description>A subtitle not in the body</description><content:encoded><![CDATA[<p>The body of the notes.</p>]]></content:encoded></item>
<item><guid>amp-2</guid><title>Cut body</title><description>The whole description</description>
<content:encoded><![CDATA[x">tail of a tag</p>]]></content:encoded><media:content url="${at}/pic.png" medium="image"/></item>
<item><title>Picture only</title><enclosure url="${at}/amp-pic.png" type="image/png" length="10"/></item>
</channel></rss>`],
'/wp.json': ['application/json', JSON.stringify([{
guid: { rendered: `${at}/?p=1` }, link: `${at}/wp-1`, title: { rendered: 'WordPress &#8220;post&#8221;' },
date_gmt: '2026-01-04T12:00:00', content: { rendered: '<p>Post body</p>' }, jetpack_featured_media_url: `${at}/art.jpg`,
}])],
'/said.txt': ['text/plain', 'Unable to establish a DB connection'],
'/long.txt': ['text/plain', 'This site is down for maintenance and will be back shortly, thank you for your patience while we work'],
'/empty.xml': ['application/xml', ''],
'/garbled.xml': ['application/xml', '<rss><channel><title>Broken'],
};
const shape = shapes[req.url ?? ''];
if (shape) { res.writeHead(200, { 'content-type': shape[0] }).end(shape[1]); return; }
// A feed that starts failing, in whichever way a test asks for with /flip?to= (#463).
if (req.url?.startsWith('/flip?to=')) { flip = req.url.slice('/flip?to='.length); res.writeHead(204).end(); return; }
if (req.url === '/flip.xml') {
if (/^\d{3}$/.test(flip)) { res.writeHead(Number(flip)).end('no'); return; }
if (flip === 'loop') { res.writeHead(302, { location: '/flip.xml' }).end(); return; }
if (flip === 'drop') { req.socket.destroy(); return; }
const body = flip === 'text' ? 'Unable to establish a DB connection'
: flip === 'nothing' ? ''
: flip === 'page' ? `<!doctype html><html><head><link rel="alternate" type="application/rss+xml" href="${at}/moved.xml"></head></html>`
: flip === 'garbled' ? '<rss><channel><title>Broken'
: `<?xml version="1.0"?><rss version="2.0"><channel><title>Flip Show</title><item><guid>flip-1</guid><title>Flip one</title></item></channel></rss>`;
res.writeHead(200, { 'content-type': 'application/xml' }).end(body);
return;
}
const name = decodeURIComponent((req.url ?? '/').split('?')[0]!.replace(/^\//, '')) || 'index'; const name = decodeURIComponent((req.url ?? '/').split('?')[0]!.replace(/^\//, '')) || 'index';
const file = path.join(dir, path.basename(name)); const file = path.join(dir, path.basename(name));
fs.readFile(file, (err, body) => { fs.readFile(file, (err, body) => {

View File

@@ -62,7 +62,7 @@ const ICONS_URL = `/icons/index.json?v=${hash(ICONS)}`;
/// The shared stylesheet, minified. @swc/html minifies CSS inside a page, so it goes through as /// The shared stylesheet, minified. @swc/html minifies CSS inside a page, so it goes through as
/// one; the doctype only keeps it from complaining that a fragment has none. /// one; the doctype only keeps it from complaining that a fragment has none.
export function buildStyle({ minify = true } = {}) { export function buildStyle({ minify = !coverageMap } = {}) {
const css = fs.readFileSync(path.join(here, STYLE), 'utf8'); const css = fs.readFileSync(path.join(here, STYLE), 'utf8');
if (!minify) return css; if (!minify) return css;
const r = html.minifySync(`<!doctype html><style>${css}</style>`, { minifyCss: true, removeComments: true }); const r = html.minifySync(`<!doctype html><style>${css}</style>`, { minifyCss: true, removeComments: true });