Skip to content

Add test coverage for document permissions and Research AI editor access#3198

Draft
cursor[bot] wants to merge 2 commits intomainfrom
cursor/missing-test-coverage-b912
Draft

Add test coverage for document permissions and Research AI editor access#3198
cursor[bot] wants to merge 2 commits intomainfrom
cursor/missing-test-coverage-b912

Conversation

@cursor
Copy link
Copy Markdown

@cursor cursor Bot commented Mar 17, 2026

Risky behavior now covered

  1. HasDocumentEditingPermission note_id is None guard (PR Implement user verification requirement for creating and updating posts #3188 bug fix): When a post has no linked note, a non-author/non-moderator editing attempt would previously crash with AttributeError on post.note.organization. The fix returns False instead. Now has 11 unit tests covering each permission path.

  2. Research AI editor access (PR [ExpertFinder] - Update permissions #3173): All Research AI views changed from IsModerator to UserIsEditor | IsModerator. Existing tests only verified moderator access—there were zero tests confirming editors could actually use the endpoints. Now has 12 new tests across permissions, expert-finder, email, and template views.

Test files added/updated

  • NEW src/researchhub_document/tests/test_permissions.py — 11 tests for HasDocumentEditingPermission
  • UPDATED src/research_ai/tests/test_permissions.py — 5 new tests for UserIsEditor | IsModerator OR-composition
  • UPDATED src/research_ai/tests/test_expert_finder_views.py — 2 editor access tests
  • UPDATED src/research_ai/tests/test_email_views.py — 4 editor access tests
  • UPDATED src/research_ai/tests/test_template_views.py — 5 editor access tests

Why these tests materially reduce regression risk

  • The permission bug fix is a single if guard that could easily be reverted or broken during refactoring. Without direct unit tests, the regression would only surface as a 500 error for real users.
  • The editor access change affects 10+ API endpoints across Research AI. Without editor-specific tests, a future refactor could silently lock out editors while all existing tests still pass (they only check moderator access).
Open in Web View Automation 

cursoragent and others added 2 commits March 17, 2026 10:12
Cover the bug fix where posts without a linked note would crash with
AttributeError when a non-author/non-moderator tried to update. Tests
verify each permission path: author, moderator, org member, non-member,
and the critical note_id=None guard clause.

Co-authored-by: Kobe Attias <kobeattias@gmail.com>
Verify hub editors (non-moderators) can access Research AI views after
the IsModerator -> UserIsEditor | IsModerator permission change. Covers:
- Permission composition unit tests (OR semantics)
- Expert search create/list for editors
- Email generate/list/retrieve/draft for editors
- Template CRUD for editors

Co-authored-by: Kobe Attias <kobeattias@gmail.com>
@sonarqubecloud
Copy link
Copy Markdown

@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 17, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 78.52%. Comparing base (c9e47b0) to head (26e0680).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3198      +/-   ##
==========================================
+ Coverage   78.51%   78.52%   +0.01%     
==========================================
  Files         612      612              
  Lines       34280    34280              
==========================================
+ Hits        26916    26920       +4     
+ Misses       7364     7360       -4     

☔ 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.

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.

1 participant