接通审核中结果核对、受理记账与后续调度

This commit is contained in:
Longtail committed 2026-10-31 17:20:36 +08:00
1 parent d157c179c8
commit f0be4f5596
18 files changed
+510 -57

No files matched your search

+79 -2
View File
@@ -22,7 +22,7 @@ class QueueTests(unittest.TestCase):
self.md.write_text('# 测试新闻\n\n正文内容。\n\n来源:测试来源,如有侵权,请联系删除。\n')
self.store = Store(self.root / 'queue.sqlite3')
self.store.configure(dict(fid=125, minimum=1, maximum=1, interval=0, history_checked=True))
self.owner = dict(owner='tab-a', account=dict(uid='123', name='测试账号'), extension={'idle': True})
self.owner = dict(owner='tab-a', account=dict(uid='123', name='测试账号'), extension={'idle': True}, url='https://www.dww11.com/')
def tearDown(self):
self.tmp.cleanup()
@@ -42,7 +42,7 @@ class QueueTests(unittest.TestCase):
def accept(self, job):
return self.store.accept(dict(owner='tab-a', id=job['id'], post_url='https://www.dww11.com/thread/12345.html',
author_uid='123', fid=125, title=job['title'], state='accepted_pending_moderation', evidence={'test': 'fixture only'}))
thread_id='123', first_post_pid='456', author_uid='123', fid=125, title=job['title'], state='accepted_pending_moderation', evidence={'thread_id': '123', 'test': 'fixture only'}))
def test_stable_identity_and_original_preserved(self):
before = self.md.read_bytes()
@@ -201,6 +201,83 @@ class QueueTests(unittest.TestCase):
self.store.skip(dict(owner='tab-a', id=job['id'], epoch=self.store.run['epoch']))
self.assertEqual(self.store.run['active'], job['id'])
def test_real_tid_and_return_home_gate(self):
job = self.begin(); self.submit(job); self.accept(job)
saved = self.store.state()['jobs'][0]
self.assertEqual(saved['thread_id'], '123')
self.assertEqual(saved['first_post_pid'], '456')
self.assertEqual(self.store.next({**self.owner, 'url': saved['post_url']})['action'], 'home')
self.assertEqual(self.store.next(self.owner)['action'], 'idle')
def test_integrity_issue_records_acceptance_but_stops(self):
job = self.begin(); self.submit(job)
self.store.accept(dict(owner='tab-a', id=job['id'], post_url='https://www.dww11.com/thread/12311.html',
thread_id='123', author_uid='123', fid=125, title=job['title'], state='accepted_pending_moderation',
evidence={'thread_id':'123','integrity_issues':['正文图片位置改变']}))
self.assertFalse(self.store.run['running'])
self.assertEqual(self.store.run['batch']['count'], 1)
self.assertIn('已受理', self.store.enqueue(self.article))
def test_historical_reconciliation_does_not_count_or_resume(self):
job = self.begin(); self.submit(job); self.store.control('stop')
data=dict(id=job['id'], article_key=job['article_key'], confirmed=True,
post_url='https://www.dww11.com/thread/12311.html',thread_id='123',author_uid='123',fid=125,
title=job['title'],state='accepted_pending_moderation',evidence={'thread_id':'123'})
self.store.reconcile(data); self.store.reconcile(data)
self.assertFalse(self.store.run['running'])
self.assertEqual(self.store.run['batch']['count'], 0)
self.assertIn('已受理', self.store.enqueue(self.article))
def test_transaction_rolls_back_in_memory_run(self):
import sqlite3
self.begin()
before = json.loads(json.dumps(self.store.run))
with self.assertRaises(sqlite3.IntegrityError):
with self.store.db() as db:
self.store.run['batch']['count'] = 999
db.execute("INSERT INTO posts VALUES(NULL,NULL)")
self.assertEqual(self.store.run, before)
def test_accept_after_stop_only_records_no_resumption(self):
job = self.begin(); self.submit(job); self.store.control('stop'); self.accept(job)
self.assertFalse(self.store.run['running'])
self.assertEqual(self.store.run['batch']['count'], 1)
self.assertEqual(self.store.next(self.owner)['action'], 'idle')
def test_switch_same_uid_and_idle_stops_without_reclick(self):
import time
job = self.begin(); self.submit(job); self.accept(job)
other = self.root / 'other'; shutil.copytree(self.article, other)
(other / 'a.md').write_text(self.md.read_text().replace('正文内容', '其他内容'))
self.store.enqueue(other)
self.assertEqual(self.store.next(self.owner)['action'], 'switch')
self.store.switch_begin({'owner':'tab-a'})
self.store.run['switch']['clicked_at'] = time.time() - 11
self.assertEqual(self.store.next(self.owner)['action'], 'idle')
self.assertFalse(self.store.run['running'])
self.assertEqual(self.store.run['switch']['state'], 'clicked')
def test_rejected_submission_requires_manual_resolution(self):
job = self.begin(); self.submit(job)
self.transition(job, 'rejected', error='标题超限')
self.assertFalse(self.store.run['running'])
self.assertEqual(self.store.run['batch']['count'], 0)
self.store.resolve(dict(id=job['id'],confirmed_not_accepted=True,retry=True))
saved = self.store.state()['jobs'][0]
self.assertNotIn('submitted_at', saved)
self.assertEqual(saved['state'], 'queued')
def test_legacy_identity_is_preserved_without_guessing_tid(self):
job = self.begin(); self.submit(job); self.accept(job)
with self.store.db() as db:
saved = self.store._job(db,job['id']); saved.pop('thread_id')
self.store._save(db,saved)
restarted = Store(self.root/'queue.sqlite3')
saved = restarted.state()['jobs'][0]
self.assertEqual(saved['legacy_url_id'],'123')
self.assertTrue(saved['identity_needs_reconciliation'])
self.assertFalse(restarted.run['running'])
def test_bad_result_does_not_increment(self):
job = self.begin();self.submit(job)
with self.assertRaises(ValueError):