Preserve match candidate evidence when papers merge
Metadata integrity checks / metadata (push) Waiting to run

This commit is contained in:
2026-11-26 01:40:22 +08:00
parent b03a8bc5fc
commit 1e5237fe19
3 changed files with 104 additions and 2 deletions
+34
View File
@@ -97,6 +97,40 @@ class StoreTests(unittest.TestCase):
self.assertIsNotNone(self.store.conn.execute('SELECT 1 FROM papers WHERE id=?',(unrelated,)).fetchone())
self.assertEqual(self.store.conn.execute('SELECT count(*) FROM paper_merges').fetchone()[0],1)
def test_merge_preserves_colliding_candidate_observations(self):
first, _ = self.record('arxiv', '2601.00001', authors=['First Author'])
second, _ = self.record('pmlr', 'v1/second', authors=['Second Author'])
third, _ = self.record('acl', '2026.acl.1', authors=['Third Author'])
related, _ = self.record('arxiv', '2601.00002', authors=['Related Author'])
db = self.store.conn
method = 'exact_title_unconfirmed'
original = (None, '{"title":"Conference title"}', 'pending')
incoming = (0.98, '{"title":"Preprint title"}', 'pending')
for paper, observation in ((first, original), (second, incoming), (third, incoming)):
left, right = sorted((paper, related))
db.execute(
'INSERT INTO match_candidates VALUES(?,?,?,?,?,?) '
'ON CONFLICT(left_paper_id,right_paper_id,method) DO UPDATE SET '
'score=excluded.score,evidence_json=excluded.evidence_json,status=excluded.status',
(left, right, method, *observation),
)
self.store.merge(first, second, 'confirmed publication version')
self.store.merge(first, third, 'confirmed additional source')
rows = db.execute(
'SELECT left_paper_id,right_paper_id,score,evidence_json,status '
'FROM match_candidates WHERE method=?',
(method,),
).fetchall()
[(left, right, score, evidence, status)] = rows
self.assertEqual((left, right, score, status), (first, related, None, 'pending'))
self.assertEqual(
json.loads(evidence)['reattached_observations'],
[list(original), list(incoming)],
)
self.assertEqual(db.execute('PRAGMA foreign_key_check').fetchall(), [])
def test_manifest_count_mismatch_rolls_back_records(self):
path=Path(self.tmp.name)/'source.jsonl'
path.write_text(json.dumps({'source':'pmlr','external_id':'v1/paper','url':'https://example.org/paper','title':'Paper','abstract':'Abstract','authors':[],'venue':'ICML','year':2023,'track':'main','status':'accepted'})+'\n')