Skip to content

test: cover staff audit backend - #124

Open
Jayaa05 wants to merge 2 commits into
fossasia:mainfrom
Jayaa05:test/issue-46-admin-audit
Open

Jayaa05 wants to merge 2 commits into
fossasia:mainfrom
Jayaa05:test/issue-46-admin-audit

Conversation

@Jayaa05

@Jayaa05 Jayaa05 commented Dec 3, 2026 •

Copy link
Copy Markdown

Summary

  • Add focused tests for StaffAuditBackend changed-field tracking and no-op updates.
  • Cover create/delete forwarding, missing snapshots, actor attribution, and audit-row construction.
  • Verify case-insensitive secret detection, nested redaction, and serialization of UUIDs, datetimes, and tuples.
  • Cover previous-value capture through remember().

This is a test-only contribution; no production code is changed.

Validation

  • pytest tests/test_admin_audit.py -v — 18 passed, with one existing Starlette/httpx deprecation warning.

Part of #46.

Summary by Sourcery

Tests:

  • Add focused tests for staff audit logging, including change filtering, actor and row construction, secret redaction, serialization, and previous-value capture.

Summary by CodeRabbit

  • Tests
    • Added coverage for staff audit logging, including change tracking, event forwarding, actor and record details, secret redaction, serialization, and snapshot handling.

@sourcery-ai

sourcery-ai Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

Tests

Add focused tests for staff audit change tracking, actor attribution, row serialization and redaction, and previous-value capture.

  • gateway/tests/test_admin_audit.py L1-215

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@coderabbitai

coderabbitai Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

Explain Change →

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 55 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: aa8b23e3-9fa3-457d-b53d-aaac9cff33f8
Commits

Reviewing files that changed from the base of the PR and between f3c2c8c and d04d234.

Files selected for processing: 1

  • gateway/tests/test_admin_audit.py

No actionable comments were generated in the recent review.

Walkthrough

The pull request adds tests for staff audit logging. They cover update diffing and forwarding, actor and row construction, secret redaction and serialization, and remember snapshot handling.

Changes: Admin audit test coverage

Layer / File(s) Summary
Audit behavior and data handling
gateway/tests/test_admin_audit.py
Adds test helpers and assertions for update handling, actor lookup, audit row construction, secret redaction, serialization, and remembered snapshots.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Other

Possibly related issues

Suggested reviewers: vedansh-5

Merge Risk: Minimal · previous review f3c2c

This change only adds tests for staff audit logging and does not alter production behavior. No merge-blocking risk was identified.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title "test: cover staff audit backend" matches the changeset, which adds gateway/tests/test_admin_audit.py with tests for StaffAuditBackend covering change tracking, create/delete forwarding, act…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title "test: cover staff audit backend" matches the changeset, which adds gateway/tests/test_admin_audit.py with tests for StaffAuditBackend covering change tracking, create/delete forwarding, actor attribution, audit-row construction, secret redaction, serialization, and remember() snapshot handling. It is a short, single-sentence title that names the primary change (tests for the staff audit backend) and uses the conventional test: prefix. It does not list every test case, which is acceptable.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 1ef7b62b-6b46-4554-8512-71c86358d083
Commits

Reviewing files that changed from the base of the PR and between 0278935 and f3c2c8c.

Files selected for processing: 1

  • gateway/tests/test_admin_audit.py

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hey - I've found 1 issue

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="gateway/tests/test_admin_audit.py" line_range="107" />
<code_context>
+
+
+def test_get_actor_reads_the_configured_session_key():
+    request = _request(admin_id="staff-123", admin_email="staff@example.com")
+
+    assert asyncio.run(_backend().get_actor(request)) == "staff-123"
</code_context>
<issue_to_address>
**Configured actor lookup goes unverified**

When `get_actor` is changed to use a fixed `admin_id` key or actor value instead of the configured key, `test_get_actor_reads_the_configured_session_key` still passes if `get_actor` reads the literal `"admin_id"` or returns `"staff-123"`, because `_backend()` uses that same key and the request supplies that value. Production config uses `admin_user`, so this regression can go unnoticed and audit actions lose staff attribution.

Configure the test backend with a distinct key and assert that its value is used even when the session contains a different `admin_id`.
</issue_to_address>

Sourcery assessment

Approval pending. 1 finding to address first.

Blocking findings: gateway/tests/test_admin_audit.py:107


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread gateway/tests/test_admin_audit.py Resolved

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Sourcery assessment

Approved.

Jayaa05 commented Dec 4, 2026

Copy link
Copy Markdown
Author

Hi maintainers,

The latest commit (d04d234) addresses the configured staff actor session-key finding, and the focused audit test suite passed locally (18 passed). The Actions run is currently marked action_required before any jobs start, so it appears to need maintainer approval to run.

Could someone with the required repository permissions approve the workflow run so CI can execute?

Thanks!

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