Raise Jest coverage above global thresholds.

Add real MCP HTTP/tool/entrypoint tests and extend torrent/qbt coverage
so statements, branches, functions, and lines all meet the configured floors.
This commit is contained in:
2026-08-07 19:37:22 +02:00
parent ac97862edb
commit b04e70e261
5 changed files with 549 additions and 7 deletions

View File

@@ -1,4 +1,4 @@
const { makeTorrent, extractWebseed } = require('../src/torrent');
const { makeTorrent, extractWebseed, extractInfoHash } = require('../src/torrent');
describe('makeTorrent + extractWebseed round-trip', () => {
it('extracts the webseed URL back from a generated torrent', () => {
@@ -23,6 +23,16 @@ describe('makeTorrent + extractWebseed round-trip', () => {
const buf = makeTorrent({ name: 'movie.mkv', size: 500, webseedUrl: 'http://x.com/s/z' });
expect(buf.toString()).toContain('movie.mkv');
});
it('encodes multi-piece torrents for large sizes', () => {
const buf = makeTorrent({
name: 'big.mkv',
size: 512 * 1024 * 3,
webseedUrl: 'http://x.com/s/big',
});
expect(Buffer.isBuffer(buf)).toBe(true);
expect(buf.length).toBeGreaterThan(60);
});
});
describe('extractWebseed', () => {
@@ -55,12 +65,42 @@ describe('extractWebseed', () => {
});
it('handles url-list as array', () => {
// Manually build a torrent-like bencode with url-list as list
const { makeTorrent: mt } = require('../src/torrent');
// We test via the actual makeTorrent which uses a string — round-trip test above covers it.
// Here just verify the array branch: if url-list is a Buffer (string) it still returns a string.
const url = 'http://cdn.example.com/stream/abcdef';
const buf = mt({ name: 't.mkv', size: 50, webseedUrl: url });
expect(typeof extractWebseed(buf)).toBe('string');
// d8:url-list l <len>:<url> e e
const buf = Buffer.from(`d8:url-listl${url.length}:${url}ee`);
expect(extractWebseed(buf)).toBe(url);
});
it('returns null for empty url-list array', () => {
const buf = Buffer.from('d8:url-listlee');
expect(extractWebseed(buf)).toBeNull();
});
});
describe('extractInfoHash', () => {
it('returns stable sha1 hex for a generated torrent', () => {
const buf = makeTorrent({ name: 't.mkv', size: 50, webseedUrl: 'http://x/s/a' });
const h = extractInfoHash(buf);
expect(h).toMatch(/^[0-9a-f]{40}$/);
expect(extractInfoHash(buf)).toBe(h);
});
it('returns null without info dict or on garbage', () => {
expect(extractInfoHash(Buffer.from('d3:fooi1ee'))).toBeNull();
expect(extractInfoHash(Buffer.from('not-bencode'))).toBeNull();
});
});
describe('bdecode edge cases via extractWebseed', () => {
it('decodes lists and rejects unclosed list', () => {
const url = 'http://a/b';
expect(extractWebseed(Buffer.from(`d8:url-listl${url.length}:${url}ee`))).toBe(url);
// unclosed list → catch → null
expect(extractWebseed(Buffer.from('d8:url-listl5:hello'))).toBeNull();
});
it('rejects bad string lengths and unclosed dicts', () => {
expect(extractWebseed(Buffer.from('d3:fo'))).toBeNull();
expect(extractWebseed(Buffer.from('d4:name5:hello'))).toBeNull();
});
});