Skip to content

Fix spurious new-assessment log entries for renamed articles#1126

Merged
audiodude merged 7 commits intoopenzim:mainfrom
arnchlmcodes:fixes-issue72
Apr 14, 2026
Merged

Fix spurious new-assessment log entries for renamed articles#1126
audiodude merged 7 commits intoopenzim:mainfrom
arnchlmcodes:fixes-issue72

Conversation

@arnchlmcodes
Copy link
Copy Markdown
Contributor

Heyy @audiodude During update_project_assessments_by_kind, any article whose ref is absent from old_ratings gets treated as new. The problem is that a renamed article will always look new at this stage because the old name is what's stored in old_ratings, not the new one. Previously, store_new_ratings would immediately call add_log_for_rating for these, writing a spurious log entry with old_rating_value defaulting to NotA-Class.

The fix defers those log entries into a list instead of writing them immediately. Only articles that already existed in old_ratings but had a rating change get logged right away, since an existing ref changing its rating cannot be a rename.

process_unseen_articles runs after both quality and importance passes complete. For each old ref that wasn't seen, it calls get_move_data() to check if the article was renamed. If a move is detected, the destination ref is added to a moved_articles set. Back in update_project_assessments, the deferred logs are then written only for refs not present in moved_articles, ensuring that renamed articles don't get a spurious new-assessment log entry while genuinely new articles are logged correctly.

fixes issue #72

let me know if the fix is correct, I'll start working on the test cases next.

Copy link
Copy Markdown
Member

@audiodude audiodude left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great! Please add the tests now.

@arnchlmcodes
Copy link
Copy Markdown
Contributor Author

hey @audiodude , sorry for taking time with the tests, the coverage was tricky and kind of confusing hence the delay,
I've added 3 test classes

StoreNewRatingsTest checks the branch logic in store_new_ratings directly new refs defer their log, existing changed refs log immediately, unchanged refs do nothing. Also asserts the rating is persisted even when the log is deferred since that wasn't obvious from reading the code.

ProcessUnseenArticlesMovedTest covers the new return value from process_unseen_articles (it used to return None). Had to add a dummy article to seen just to get past the early-return guard. Also explicitly assert that get_move_data and update_page_moved were called, otherwise the test passes vacuously if the mock path is never hit.

DeferredLogMovedArticleTest is the end-to-end regression check for the original bug, renamed article shouldn't produce a spurious new-assessment log. Covers three scenarios: pure rename, purely new articles, and a mix of both.

Copy link
Copy Markdown
Member

@audiodude audiodude left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work, these tests look good!

@audiodude audiodude enabled auto-merge April 14, 2026 04:03
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 14, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.80%. Comparing base (8f4f67d) to head (3b10a98).
⚠️ Report is 4 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1126      +/-   ##
==========================================
+ Coverage   92.78%   92.80%   +0.02%     
==========================================
  Files          74       74              
  Lines        4311     4325      +14     
==========================================
+ Hits         4000     4014      +14     
  Misses        311      311              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@audiodude audiodude added this pull request to the merge queue Apr 14, 2026
Merged via the queue into openzim:main with commit f6e40ea Apr 14, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants