'use strict'; const test = require('node:test'); const assert = require('node:assert/strict'); const fs = require('node:fs/promises'); const os = require('node:os'); const path = require('node:path'); const { ScraperService } = require('../service'); test('an operator can pause one source while other lanes continue', async t => { const root = await fs.mkdtemp(path.join(os.tmpdir(), 'mc-source-pause-')); const service = await new ScraperService({ libraryRoot: path.join(root, 'library'), dataRoot: path.join(root, 'data') }).init(); t.after(async () => { await service.close(); await fs.rm(root, { recursive: true, force: true }); }); await assert.rejects(service.control('pause-source', 'unknown'), /Unknown source/); await service.control('pause-source', 'weebcentral'); assert.equal(service.state.sourcePaused.weebcentral, true); await service.control('resume'); assert.equal(service.state.paused, false); assert.equal(service.state.sourcePaused.weebcentral, true); service.state.queue.push({ source: 'weebcentral', status: 'error', failure: { kind: 'access' } }); await assert.rejects(service.control('resume-source', 'weebcentral'), /access block/); service.state.queue.pop(); await service.control('resume-source', 'weebcentral'); assert.equal(service.state.sourcePaused.weebcentral, undefined); }); test('confirmation can queue an inspected job without unpausing its source', async t => { const root = await fs.mkdtemp(path.join(os.tmpdir(), 'mc-source-confirm-')); const service = await new ScraperService({ libraryRoot: path.join(root, 'library'), dataRoot: path.join(root, 'data') }).init(); t.after(async () => { await service.close(); await fs.rm(root, { recursive: true, force: true }); }); const item = { id: 'inspected', source: 'weebcentral', title: 'Sample', sourceTitle: 'Sample', kind: 'inspection', status: 'ready' }; service.state.queue.push(item); await service.control('pause-source', 'weebcentral'); await service.control('confirm', item.id); assert.equal(item.kind, 'download'); assert.equal(item.status, 'queued'); assert.equal(service.state.sourcePaused.weebcentral, true); await assert.rejects(service.control('inspect', item.id), /source access block/); });