Peach: Local-first video metadata scraper and media manager.
test: 跟上扫描与采集的取消确认与忙碌键语义
longmeidaod25c5c9abfd2
diff --git a/frontend/e2e/design-controls.test.ts b/frontend/e2e/design-controls.test.tsindex b927cf8da..6eb323dc6 100644--- a/frontend/e2e/design-controls.test.ts+++ b/frontend/e2e/design-controls.test.ts@@ -340,7 +340,7 @@ describe('设计决定:控件、状态与首页顶部', () => {}});- it('扫描卡的进度条走焦点环色,底槽是三级底,按下的那颗键转成忙态', { timeout: 60_000 }, async () => {+ it('扫描卡的进度条走焦点环色,底槽是三级底,任务在跑时同步键标为不可用但仍可聚焦', { timeout: 60_000 }, async () => {const opened = await openProcessing(browser, '/data-cleanup', RUNNING_JOB);try {const card = opened.page.locator('section[aria-label="扫描与采集"]');@@ -354,9 +354,10 @@ describe('设计决定:控件、状态与首页顶部', () => {await tokenColor(opened.page, '.peach-react', '--color-background-tertiary-default'));assert.equal(await fill(1),await tokenColor(opened.page, '.peach-react', '--color-border-focus-ring'));- // 忙态不改 `disabled`:控件仍可聚焦,重复触发由页面自己挡。+ // 已有任务在跑只标 `aria-disabled`、不改 `disabled`:控件仍可聚焦,点了由卡片说明为什么没开始。const scan = card.getByRole('button', { name: '同步新增文件', exact: true });- assert.equal(await scan.getAttribute('aria-busy'), 'true');+ assert.equal(await scan.getAttribute('aria-disabled'), 'true');+ assert.equal(await scan.getAttribute('aria-busy'), null);assert.equal(await scan.evaluate((element) => (element as HTMLButtonElement).disabled), false,'用原生 disabled 挡的话按钮连焦点都拿不到');const split = card.locator('[data-split-button]');diff --git a/frontend/e2e/library-processing-controls.test.ts b/frontend/e2e/library-processing-controls.test.tsindex 8c253bbf5..a036750bd 100644--- a/frontend/e2e/library-processing-controls.test.ts+++ b/frontend/e2e/library-processing-controls.test.ts@@ -255,9 +255,10 @@ describe('扫描与采集控制', () => {assert.equal(await resume.locator('svg').count(), 1);const occupied = card.getByRole('button', { name: '同步新增文件', exact: true });assert.equal(await occupied.getAttribute('aria-disabled'), 'true');- // 任务没结束时点同步不发请求,但要说清为什么没开始;Playwright 把 aria-disabled 当成不可点,人是能点的。+ // 任务没结束时点同步不发请求,但要说清为什么没开始。Playwright 把 aria-disabled 当成不可点,按键又常落在+ // 视口外或进度浮窗底下,直接在键上派发点击:它照样经过共享忙碌拦截的捕获阶段。const sent = writes.length;- await occupied.click({ force: true });+ await occupied.dispatchEvent('click');await page.locator('#toasts [data-sonner-toast]').filter({ hasText: '当前的扫描与采集任务还没结束' }).waitFor();assert.equal(writes.length, sent);// 和任务中心的取消同一枚图标,先确认;在确认框里点「取消」就不发请求。@@ -271,7 +272,7 @@ describe('扫描与采集控制', () => {state = { ...state, trigger: 'cli' };await page.reload();await resume.waitFor();- await occupied.click({ force: true });+ await occupied.dispatchEvent('click');await page.locator('#toasts [data-sonner-toast]').filter({ hasText: '当前的扫描与采集任务(由命令行或托盘发起)还没结束' }).waitFor();const lowSpeed = dock.getByRole('button', { name: '处理速度:低占用' });diff --git a/frontend/test/react/library-processing.test.tsx b/frontend/test/react/library-processing.test.tsxindex 20c30b6e6..454dd5226 100644--- a/frontend/test/react/library-processing.test.tsx+++ b/frontend/test/react/library-processing.test.tsx@@ -19,6 +19,12 @@ import type { LibraryProcessingProps } from '../../src/react/bundle';import { actionOrder, buttonNamed as textButtonNamed, click, mount, mountRoot, submit } from './render';+// 取消要过真的确认框:桩里的 `confirmModal` 不画对话框。+vi.mock('@peach/legacy/ui', async (original) => ({+ ...await original<typeof import('@peach/legacy/ui')>(),+ confirmModal: (await import('../../src/ui-kit/modal')).confirmModal,+}));+const buttonNamed = (name: string, root: ParentNode = document) =>[...root.querySelectorAll('button')].find(button => button.getAttribute('aria-label') === name)?? textButtonNamed(name, root);@@ -57,17 +63,22 @@ it('补全待处理影片只提交已登记范围,不触发文件发现',asyncexpect(calls.filter(call=>call.method==='POST').map(call=>call.body)).toEqual([{stage:'collect',scope:'new'}]);});-it('停止请求绑定原任务,正在停止时保留进度并禁止重发',async()=>{+it('取消先确认,请求绑定原任务,正在取消时保留进度并禁止重发',async()=>{let state:LibraryProcessingData={status:'running',job_id:'one',candidates:3};const {calls}=await open(state,(method)=>{if(method==='POST') state={...state,status:'stopping'};return state;});+ const posts=()=>calls.filter(call=>call.method==='POST').map(call=>call.body);const host=await mount(card({toast:vi.fn()}));- await click(buttonNamed('停止任务',host)!);- expect(calls.filter(call=>call.method==='POST').map(call=>call.body)).toEqual([{action:'cancel',job_id:'one'}]);- expect(host.textContent).toContain('正在停止');- expect(buttonNamed('正在停止',host)?.disabled).toBe(true);+ await click(buttonNamed('取消任务',host)!);+ await click(document.querySelector('[data-modal-cancel]'));+ expect(posts()).toEqual([]);+ await click(buttonNamed('取消任务',host)!);+ await click(document.querySelector('[data-modal-confirm]'));+ await vi.waitFor(()=>expect(posts()).toEqual([{action:'cancel',job_id:'one'}]));+ await vi.waitFor(()=>expect(host.textContent).toContain('正在取消'));+ expect(buttonNamed('正在取消',host)?.disabled).toBe(true);});type Reply = (method: string, body: unknown) => LibraryProcessingData;diff --git a/tests/test_metadata_library.py b/tests/test_metadata_library.pyindex 91e50b6ef..bf98b7d4e 100644--- a/tests/test_metadata_library.py+++ b/tests/test_metadata_library.py@@ -864,6 +864,7 @@ class LibraryNfoTests(unittest.TestCase):contract = Mock()contract.db_path = self.root / 'database/ledger.db'contract.library_processing_job.snapshot.return_value = {'status': 'running', 'job_id': 'one'}+ contract.task_runs.query.return_value = []with patch('peach.web_library_processing.process_library') as worker:self.assertEqual(q_library_processing(contract, {})['job_id'], 'one')worker.assert_not_called()diff --git a/tests/test_processing_control.py b/tests/test_processing_control.pyindex 578f98248..88070872b 100644--- a/tests/test_processing_control.py+++ b/tests/test_processing_control.py@@ -506,23 +506,22 @@ class ProcessingControlTests(unittest.TestCase):self.assertEqual(job_recovery.resume(db,{'library-processing':Mock()}),[])def test_status_names_how_a_command_line_run_was_started(self):- from peach.jobs import BackgroundJob- from peach.library_processing import _save, state_pathfrom peach.task_runs import TaskRunStorefrom peach.web_library_processing import q_library_processingroot = self.config.directory('database')root.mkdir(parents=True)db = fresh_ledger(root)runs = TaskRunStore(db)- contract = SimpleNamespace(db_path=db, library_processing_job=BackgroundJob('library-processing'),- task_runs=runs)- _save(state_path(self.config), {'job_id': 'cli', 'status': 'running', 'started_at': 1})+ # 命令行那一轮在另一个进程里写状态;这里用一份进行中的快照代替,状态里没有 `run_id`。+ job = Mock()+ job.snapshot.return_value = {'job_id': 'cli', 'status': 'running', 'started_at': 1}+ contract = SimpleNamespace(db_path=db, library_processing_job=job, task_runs=runs)with patch('peach.web_library_processing.settings_file.active', return_value=self.config):self.assertNotIn('trigger', q_library_processing(contract, {}))run = runs.start('library-processing', trigger='cli')self.assertEqual(q_library_processing(contract, {})['trigger'], 'cli')runs.finish(run.id, 'succeeded')- _save(state_path(self.config), {'job_id': 'cli', 'status': 'complete', 'started_at': 1})+ job.snapshot.return_value = {'job_id': 'cli', 'status': 'complete', 'started_at': 1}self.assertNotIn('trigger', q_library_processing(contract, {}))def test_web_pause_and_resume_preserve_running_job_and_initial_estimate(self):@@ -760,7 +759,8 @@ class ProcessingControlTests(unittest.TestCase):control = control_for(self.config)job = BackgroundJob('library-processing')job.state = dict(job_id='one', status='paused', speed_mode='low', eta_seconds_min=180, eta_seconds_max=360)- contract = SimpleNamespace(db_path=self.db, library_processing_job=job)+ from peach.task_runs import TaskRunStore+ contract = SimpleNamespace(db_path=self.db, library_processing_job=job, task_runs=TaskRunStore(self.db))with control.bind('one', publish=lambda **_: None, active=lambda: True, db_path=self.db, mode='low'), \patch('peach.web_library_processing.settings_file.active', return_value=self.config):control.request('pause', 'one')