feat: indexers and download clients you add and configure (M502 #5518)
release / govulncheck (push) Successful in 34s
release / web (push) Successful in 1m13s
release / go (push) Successful in 2m12s
release / integration (push) Successful in 4m6s
release / Build signed APK (releases and dev) (push) Successful in 8m41s
release / android (push) Successful in 9m47s
release / Attach APK to the Release (tag releases only) (push) Skipped
release / Build + push container image (push) Successful in 59s
release / Verify release artifacts (tag releases only) (push) Skipped
release / govulncheck (push) Successful in 34s
release / web (push) Successful in 1m13s
release / go (push) Successful in 2m12s
release / integration (push) Successful in 4m6s
release / Build signed APK (releases and dev) (push) Successful in 8m41s
release / android (push) Successful in 9m47s
release / Attach APK to the Release (tag releases only) (push) Skipped
release / Build + push container image (push) Successful in 59s
release / Verify release artifacts (tag releases only) (push) Skipped
Admin → Integrations gains "Indexers and download clients": two lists of
connections the operator adds, Fabled Librarian's model. Nothing is seeded
or copied from Lidarr.
- Indexers: Prowlarr (its native /api/v1/search, which asks every indexer
at once; Prowlarr has no aggregate Torznab feed) and any Torznab feed.
- Download clients: qBittorrent (WebUI v2, with re-login on an expired
session) and FabledExchange, one entry with a switch per job:
downloads (/api/downloads), search (/api/search) and release details
(/api/torrents/{infohash}). All three start on; its key is optional.
- Each entry: enable, name, address, a write-only key or password, Test.
A download client's Test lists its torrents and checks the downloads
folder is visible and writable from Minstrel; an Exchange's Test
reports each job switched on.
- Download clients carry a path mapping (Minstrel's /downloads vs the
client's own name for it); search sources carry searches per hour.
Migration 0079 adds acquisition_services with its CHECKs. Ported from
Fabled Librarian: internal/indexer (Torznab, 429 Retry-After, magnet
redirects), internal/prowlarr, internal/exchange, internal/downloader,
and internal/acquire's one builder per kind, which Test already uses
so a passing Test vouches for the path a grab will take.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,168 @@
|
||||
import { afterEach, describe, expect, test, vi } from 'vitest';
|
||||
import { render, screen, fireEvent, waitFor, within } from '@testing-library/svelte';
|
||||
import type { AcquisitionService } from '#lib/api/admin.js';
|
||||
|
||||
vi.mock('#lib/api/admin.js', () => ({
|
||||
listAcquisitionServices: vi.fn(),
|
||||
addAcquisitionService: vi.fn(),
|
||||
updateAcquisitionService: vi.fn(),
|
||||
removeAcquisitionService: vi.fn(),
|
||||
testAcquisitionService: vi.fn(),
|
||||
setAcquisitionSecret: vi.fn(),
|
||||
clearAcquisitionSecret: vi.fn()
|
||||
}));
|
||||
|
||||
vi.mock('#lib/stores/toast.svelte.js', () => ({ pushToast: vi.fn() }));
|
||||
|
||||
import AcquisitionCard from './AcquisitionCard.svelte';
|
||||
import {
|
||||
addAcquisitionService,
|
||||
listAcquisitionServices,
|
||||
setAcquisitionSecret,
|
||||
testAcquisitionService,
|
||||
updateAcquisitionService
|
||||
} from '#lib/api/admin.js';
|
||||
|
||||
function service(over: Partial<AcquisitionService> = {}): AcquisitionService {
|
||||
return {
|
||||
code: 'prowlarr',
|
||||
kind: 'search',
|
||||
protocol: 'prowlarr',
|
||||
label: 'Prowlarr',
|
||||
enabled: false,
|
||||
base_url: '',
|
||||
has_api_key: false,
|
||||
has_password: false,
|
||||
username: '',
|
||||
category: '',
|
||||
timeout_ms: 60000,
|
||||
serves_search: true,
|
||||
serves_downloads: true,
|
||||
serves_enrichment: true,
|
||||
local_path: '/downloads',
|
||||
remote_path: '',
|
||||
searches_per_hour: 120,
|
||||
usable: false,
|
||||
...over
|
||||
};
|
||||
}
|
||||
|
||||
const exchange = (over: Partial<AcquisitionService> = {}) =>
|
||||
service({
|
||||
code: 'exchange',
|
||||
kind: 'download',
|
||||
protocol: 'exchange',
|
||||
label: 'FabledExchange',
|
||||
category: 'minstrel',
|
||||
searches_per_hour: 0,
|
||||
...over
|
||||
});
|
||||
|
||||
afterEach(() => vi.clearAllMocks());
|
||||
|
||||
async function renderCard(services: AcquisitionService[]) {
|
||||
vi.mocked(listAcquisitionServices).mockResolvedValue(services);
|
||||
render(AcquisitionCard);
|
||||
await screen.findByTestId('acquisition-health');
|
||||
}
|
||||
|
||||
describe('AcquisitionCard', () => {
|
||||
test('starts empty: nothing is seeded', async () => {
|
||||
await renderCard([]);
|
||||
expect(screen.getByText(/no indexer yet/i)).toBeInTheDocument();
|
||||
expect(screen.getByText(/no download client yet/i)).toBeInTheDocument();
|
||||
expect(screen.getByTestId('acquisition-health')).toHaveTextContent(/nothing can be downloaded/i);
|
||||
});
|
||||
|
||||
test('adding offers the types each list takes', async () => {
|
||||
await renderCard([]);
|
||||
await fireEvent.click(screen.getByRole('button', { name: 'Add indexer' }));
|
||||
const indexerChoices = within(screen.getByTestId('add-search'));
|
||||
expect(indexerChoices.getByRole('button', { name: /prowlarr/i })).toBeInTheDocument();
|
||||
expect(indexerChoices.getByRole('button', { name: /torznab feed/i })).toBeInTheDocument();
|
||||
expect(indexerChoices.queryByRole('button', { name: /qbittorrent/i })).toBeNull();
|
||||
|
||||
vi.mocked(addAcquisitionService).mockResolvedValue(service());
|
||||
await fireEvent.click(indexerChoices.getByRole('button', { name: /prowlarr/i }));
|
||||
expect(addAcquisitionService).toHaveBeenCalledWith('prowlarr');
|
||||
|
||||
await fireEvent.click(screen.getByRole('button', { name: 'Add download client' }));
|
||||
const clientChoices = within(screen.getByTestId('add-download'));
|
||||
expect(clientChoices.getByRole('button', { name: /qbittorrent/i })).toBeInTheDocument();
|
||||
expect(clientChoices.getByRole('button', { name: /fabledexchange/i })).toBeInTheDocument();
|
||||
});
|
||||
|
||||
test('an exchange sits under download clients with a switch per job; others have none', async () => {
|
||||
await renderCard([
|
||||
service({ code: 'qbittorrent', kind: 'download', protocol: 'qbittorrent', label: 'qBittorrent' }),
|
||||
exchange()
|
||||
]);
|
||||
const clients = within(screen.getByTestId('download-clients'));
|
||||
expect(clients.getAllByTestId('acquisition-service')).toHaveLength(2);
|
||||
// Only the exchange carries the job switches.
|
||||
expect(clients.getAllByTestId('exchange-jobs')).toHaveLength(1);
|
||||
expect(clients.getByRole('checkbox', { name: /downloads what is grabbed/i })).toBeChecked();
|
||||
expect(clients.getByRole('checkbox', { name: /searches its dht index/i })).toBeChecked();
|
||||
expect(clients.getByRole('checkbox', { name: /checks a release/i })).toBeChecked();
|
||||
// qBittorrent asks for a username and a password; the exchange for an optional key.
|
||||
expect(clients.getByText('Username')).toBeInTheDocument();
|
||||
expect(clients.getByText(/save password/i)).toBeInTheDocument();
|
||||
expect(clients.getByText(/save key/i)).toBeInTheDocument();
|
||||
});
|
||||
|
||||
test('an exchange searching is named under indexers too', async () => {
|
||||
await renderCard([exchange({ usable: true, enabled: true, base_url: 'http://ex' })]);
|
||||
expect(within(screen.getByTestId('indexers')).getByText(/also searched: fabledexchange/i)).toBeInTheDocument();
|
||||
expect(screen.getByTestId('acquisition-health')).toHaveTextContent(/searched for and downloaded/i);
|
||||
});
|
||||
|
||||
test('switching a job off and saving sends the switches', async () => {
|
||||
const ex = exchange({ base_url: 'http://ex' });
|
||||
await renderCard([ex]);
|
||||
await fireEvent.click(screen.getByRole('checkbox', { name: /checks a release/i }));
|
||||
vi.mocked(updateAcquisitionService).mockResolvedValue({ ...ex, serves_enrichment: false });
|
||||
await fireEvent.click(screen.getByRole('button', { name: /^save$/i }));
|
||||
await waitFor(() => expect(updateAcquisitionService).toHaveBeenCalled());
|
||||
const [code, sent] = vi.mocked(updateAcquisitionService).mock.calls[0];
|
||||
expect(code).toBe('exchange');
|
||||
expect(sent).toMatchObject({ serves_enrichment: false, serves_search: true, serves_downloads: true });
|
||||
});
|
||||
|
||||
test('a refused setting is shown beside the form in the server’s words', async () => {
|
||||
await renderCard([service({ base_url: 'http://p' })]);
|
||||
await fireEvent.input(screen.getByRole('textbox', { name: /^name$/i }), {
|
||||
target: { value: 'Mine' }
|
||||
});
|
||||
vi.mocked(updateAcquisitionService).mockRejectedValue({
|
||||
code: 'invalid_setting',
|
||||
message: 'Address: start with http:// or https://.',
|
||||
status: 400
|
||||
});
|
||||
await fireEvent.click(screen.getByRole('button', { name: /^save$/i }));
|
||||
expect(await screen.findByTestId('acquisition-problem')).toHaveTextContent(
|
||||
'Address: start with http:// or https://.'
|
||||
);
|
||||
});
|
||||
|
||||
test('Test shows what the server found, and needs an address', async () => {
|
||||
await renderCard([service({ code: 'a' }), service({ code: 'b', label: 'Second', base_url: 'http://p' })]);
|
||||
const [noAddress, addressed] = screen.getAllByRole('button', { name: 'Test' });
|
||||
expect(noAddress).toBeDisabled();
|
||||
vi.mocked(testAcquisitionService).mockResolvedValue({
|
||||
ok: false,
|
||||
detail: 'the API key was refused: HTTP 401. Check it on the service’s own settings page.'
|
||||
});
|
||||
await fireEvent.click(addressed);
|
||||
expect(testAcquisitionService).toHaveBeenCalledWith('b');
|
||||
expect(await screen.findByTestId('acquisition-test-result')).toHaveTextContent(/key was refused/i);
|
||||
});
|
||||
|
||||
test('a key is sent write-only and never shown back', async () => {
|
||||
await renderCard([service({ base_url: 'http://p', has_api_key: true })]);
|
||||
expect(screen.getByLabelText(/replace the api key/i)).toHaveValue('');
|
||||
await fireEvent.input(screen.getByLabelText(/replace the api key/i), { target: { value: 'k2' } });
|
||||
vi.mocked(setAcquisitionSecret).mockResolvedValue(undefined);
|
||||
await fireEvent.click(screen.getByRole('button', { name: /save key/i }));
|
||||
await waitFor(() => expect(setAcquisitionSecret).toHaveBeenCalledWith('prowlarr', 'api-key', 'k2'));
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user