Skip to content

test(user_shares): add store + route tests with conftest integration#1945

Open
hognek wants to merge 2 commits into
jaylfc:devfrom
hognek:feat/test-user-shares
Open

test(user_shares): add store + route tests with conftest integration#1945
hognek wants to merge 2 commits into
jaylfc:devfrom
hognek:feat/test-user-shares

Conversation

@hognek

@hognek hognek commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Summary

Tests for the user-to-user resource sharing feature (taOS #1893 C3), targeting the implementation in PRs #1897 (UserSharesStore) and #1908 (share routes + consent wiring).

Depends on: #1897, #1908

Files

  • tests/test_user_shares_store.py (new, +207 lines) — 13 store tests mirroring test_agent_grants_store.py patterns
  • tests/test_user_shares_routes.py (new, +233 lines) — 9 route tests mirroring test_routes_agent_auth_requests.py patterns
  • tests/conftest.py (+9 lines) — init user_shares store in client fixture with graceful fallback

Store tests (13)

add_share: returns_inserted_row, with_optional_fields, idempotent_replace, uninitialised_raises
list_shares: returns_all, empty_for_unknown, scoped_by_owner, received
revoke_share: removes_it, nonexistent_does_not_crash
user_can_access: true_for_active, false_for_expired, false_for_none

Route tests (9)

create_share (200), unknown_username (404), duplicate_idempotent (200), to_self_rejected (400)
list_outgoing (200), list_incoming (200)
revoke (200), nonexistent (404), non_owner_unauthorized (403)

Test results

Store: 13/13 pass
Route: 9/9 pass
Full suite: known aiosqlite daemon-thread hang on teardown (pre-existing issue)

@coderabbitai

coderabbitai Bot commented Jul 17, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@hognek, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 50 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 3870f3e7-e96e-4fc1-a027-a86679f60da1

📥 Commits

Reviewing files that changed from the base of the PR and between 5506223 and 3dd4211.

📒 Files selected for processing (3)
  • tests/conftest.py
  • tests/test_user_shares_routes.py
  • tests/test_user_shares_store.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

Comment @coderabbitai help to get the list of available commands.

@hognek
hognek marked this pull request as ready for review July 17, 2026 20:40
@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@gitar-bot

gitar-bot Bot commented Jul 17, 2026

Copy link
Copy Markdown

Gitar is working

Gitar

r = await shares_client.post(
"/api/shares",
json={
"resource_type": "project",

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

SUGGESTION: Direction filtering is not actually verified.

Both test_list_incoming_shares and test_list_outgoing_shares filter results only by resource_type (if s["resource_type"] == "project"), never by the direction the route is supposed to honour. A regression where the route ignores direction and returns all shares would still pass these tests, defeating their purpose. Add an assertion that the opposite direction contains none of the created resource ids (e.g. assert the incoming list is empty when only outgoing shares were created, or check a distinguishing field).


Reply with @kilocode-bot fix it to have Kilo Code address this issue.

resp = await shares_client.post(
"/api/shares",
json={
"resource_type": "project",

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

SUGGESTION: Redundant bob user creation duplicates the shares_client logic.

shares_client already guarantees the bob user exists (lines 60-65). This fixture re-checks find_user("bob") and re-invites/completes again. While idempotent-ish, if complete_invite raises on an already-completed invite, bob_client would fail. The duplicate invite/complete block can be removed since shares_client runs first as a dependency.


Reply with @kilocode-bot fix it to have Kilo Code address this issue.

"write",
tier="always",
expires_at="2030-01-01T00:00:00+00:00",
)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

WARNING: These tests assert implementation defaults (tier == "once", status == "pending") and call accept_share/list_shares_received that live in the not-yet-merged store PRs (#1897/#1908).

This PR's description states it Depends on #1897 and #1908. If those PRs change the default tier/status values or rename/remove accept_share, these tests will fail to even import/collect once this PR is merged ahead of them (or vice-versa). Confirm the merge order guarantees the store API matches these assumptions, or mark this PR as blocked until #1897/#1908 land to avoid a red CI state.


Reply with @kilocode-bot fix it to have Kilo Code address this issue.


r2 = await shares_client.post("/api/shares", json=body)
assert r2.status_code == 200

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

SUGGESTION: Hardcoded "admin" username for the self-share rejection check.

test_create_share_to_self_rejected posts to_username="admin" expecting a 400, relying on the authenticated user being named exactly admin. If the conftest client fixture's admin user is ever renamed, this test would flip to a 404 (unknown username) and still pass the == 400? No — it would then fail with 404, so it is somewhat self-checking, but the intent is fragile. Prefer deriving the current username from the authenticated session (e.g. app.state.auth.find_user(...) or the fixture's known admin id) instead of hardcoding "admin".


Reply with @kilocode-bot fix it to have Kilo Code address this issue.

@kilo-code-bot

kilo-code-bot Bot commented Jul 17, 2026

Copy link
Copy Markdown

Code Review Summary

Status: No Issues Found | Recommendation: Merge

All four previous findings have been re-verified against current HEAD (3dd4211a) and are resolved:

  • tests/test_user_shares_store.py now uses pytest.importorskip plus a _require_method merge-order guard for list_shares_received/accept_share (resolves the WARNING on the prior line 57).
  • tests/test_user_shares_routes.py bob_client no longer duplicates bob user creation (resolves the SUGGESTION on the prior line 94).
  • test_create_share_to_self_rejected derives the username dynamically from the session (my_username) instead of hardcoding "admin" (resolves the SUGGESTION on the prior line 135).
  • test_list_outgoing_shares now creates an incoming share and asserts it is excluded from the outgoing list, verifying direction filtering (resolves the SUGGESTION on the prior line 172).

No new issues were found in the changed lines.

Files Reviewed (3 files)
  • tests/test_user_shares_routes.py - 0 new issues (4 prior suggestions resolved)
  • tests/test_user_shares_store.py - 0 new issues (prior warning resolved)
  • tests/conftest.py - no changes in incremental diff
Previous Review Summaries (2 snapshots, latest commit b8d7a5e)

Current summary above is authoritative. Previous snapshots are kept for context only.

Previous review (commit b8d7a5e)

Status: No Issues Found | Recommendation: Merge

All four previous findings (the WARNING on tests/test_user_shares_store.py:57 and the three SUGGESTIONS on tests/test_user_shares_routes.py) have been resolved in the incremental changes since 63712f3a:

  • shares_client now uses try/except ImportErrorpytest.skip instead of a hard from import.
  • bob_client removed the redundant bob-create block (correctly relying on shares_client, which still guarantees the bob user at lines 47-51).
  • test_create_share_to_self_rejected derives the username from the session (my_username) instead of hardcoding "admin".
  • test_list_outgoing_shares now creates an incoming share and asserts it is excluded from the outgoing list, verifying direction filtering.
  • test_user_shares_store.py switched to pytest.importorskip plus a _require_method merge-order guard for list_shares_received/accept_share.

No new issues were found in the changed lines.

Files Reviewed (3 files)
  • tests/test_user_shares_routes.py - 0 issues (4 prior suggestions resolved)
  • tests/test_user_shares_store.py - 0 issues (prior warning resolved)
  • tests/conftest.py - no changes in incremental diff

Previous review (commit 63712f3)

Status: 4 Issues Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 1
SUGGESTION 3
Issue Details (click to expand)

WARNING

File Line Issue
tests/test_user_shares_store.py 47 Tests assert store defaults (tier=='once', status=='pending') and call accept_share/list_shares_received from not-yet-merged PRs #1897/#1908; merge-order coupling risks red CI

SUGGESTION

File Line Issue
tests/test_user_shares_routes.py 170 direction filtering not verified (results filtered only by resource_type)
tests/test_user_shares_routes.py 96 bob_client redundantly re-creates bob already guaranteed by shares_client
tests/test_user_shares_routes.py 137 Hardcoded "admin" username for self-share rejection check
Files Reviewed (3 files)
  • tests/conftest.py - 0 issues
  • tests/test_user_shares_routes.py - 3 issues
  • tests/test_user_shares_store.py - 1 issue

Fix these issues in Kilo Cloud


Reviewed by hy3:free · Input: 41.2K · Output: 2K · Cached: 153.2K

hognek added a commit to hognek/tinyagentos that referenced this pull request Jul 17, 2026
…1945)

- Use pytest.importorskip for UserSharesStore to decouple merge order (jaylfc#1897)
- Add _require_method() guards for accept_share/list_shares_received (jaylfc#1897)
- Verify direction filtering excludes incoming shares from outgoing list
- Remove redundant bob user creation in bob_client fixture
- Replace hardcoded 'admin' username with dynamic session lookup

Resolves: 1W + 3S from Kilo review on jaylfc#1945
@hognek

hognek commented Jul 17, 2026

Copy link
Copy Markdown
Contributor Author

Kilo bot findings (1W + 3S) fixed in b8d7a5e:

  • WARNING (merge-order coupling): Added pytest.importorskip for UserSharesStore + _require_method() guards for accept_share/list_shares_received — tests now skip gracefully when feat(user_shares): add UserSharesStore with NULL-safe write lock #1897 isn't merged yet
  • S1 (direction filtering): test_list_outgoing_shares now creates an incoming share (bob→admin) and verifies it's excluded from the outgoing list
  • S2 (redundant bob_client): Removed duplicate bob user creation in bob_client fixture (already guaranteed by shares_client)
  • S3 (hardcoded username): test_create_share_to_self_rejected now resolves the current username via auth.get_user(session_token) instead of hardcoding 'admin'

Test results: 13/13 store tests skip cleanly when the store module isn't available. Route tests skip at fixture level. Existing aiosqlite daemon-thread hang on teardown is pre-existing.

@jaylfc

jaylfc commented Jul 19, 2026

Copy link
Copy Markdown
Owner

Heads up: the real CI workflow (test 3.12/3.13 + lint + spa-build) did not trigger on this one, only CLA + the automerge skip registered. A tests-only change can miss the workflow path filters. An empty commit or a rebase onto latest dev should kick the full run, then I can verify and merge. #1946 I have just approved the pending fork CI run.

hognek added 2 commits July 19, 2026 16:03
Store tests (13): add_share row/optionals/idempotent/uninit, list_shares
all/scoped/received/empty, revoke/exists/nonexistent, user_can_access
active/expired/none. Follows test_agent_grants_store.py patterns.

Route tests (9): create/unknown-404/idempotent/self-400, list out/in,
revoke/not-found-404/non-owner-403. Uses conftest client fixture.

Conftest: init user_shares store in client fixture (lifespan-owned,
bypassed in tests) with graceful fallback for pre-merge state.
…1945)

- Use pytest.importorskip for UserSharesStore to decouple merge order (jaylfc#1897)
- Add _require_method() guards for accept_share/list_shares_received (jaylfc#1897)
- Verify direction filtering excludes incoming shares from outgoing list
- Remove redundant bob user creation in bob_client fixture
- Replace hardcoded 'admin' username with dynamic session lookup

Resolves: 1W + 3S from Kilo review on jaylfc#1945
@hognek
hognek force-pushed the feat/test-user-shares branch from b8d7a5e to 3dd4211 Compare July 19, 2026 14:03
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