Skip to content

refactor: promote shared sample_* test fixtures to pub(crate) in each resource group's mod.rs#117

Merged
23prime merged 3 commits intomainfrom
feature/107-share-sample-fixtures
Mar 22, 2026
Merged

refactor: promote shared sample_* test fixtures to pub(crate) in each resource group's mod.rs#117
23prime merged 3 commits intomainfrom
feature/107-share-sample-fixtures

Conversation

@23prime
Copy link
Owner

@23prime 23prime commented Mar 22, 2026

Checklist

  • Target branch is main
  • Status checks are passing
  • Documentation updated if user-visible behavior changed (website/docs/, website/i18n/ja/, README.md)

Summary

  • Add #[cfg(test)] pub(crate) fn sample_*() functions to each resource group's mod.rs
  • Remove duplicate sample_* functions from sibling subcommand files
  • Update imports in test modules to use use crate::cmd::<group>::sample_*

Reason for change

Each test module under src/cmd/ defined its own sample_* factory functions that were identical across siblings. These duplicates made changes (e.g. adding a field to a struct) require updates in many places.

Changes

Groups affected:

  • team: sample_member, sample_team (5 files deduped)
  • wiki: sample_wiki (4 files), wiki/attachment: sample_attachment (3 files)
  • user: sample_user (5 files)
  • watch: sample_watching (5 files)
  • space: sample_notification (2 files)
  • project: sample_project (5 files), sample_project_user (2 files, renamed from sample_user)
  • issue/attachment: sample_attachment (2 files)

Closes #107

Copilot AI review requested due to automatic review settings March 22, 2026 07:58
@coderabbitai
Copy link

coderabbitai bot commented Mar 22, 2026

Warning

Rate limit exceeded

@23prime has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 20 minutes and 32 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 37739307-bac6-4743-9cb8-e6db42707b9e

📥 Commits

Reviewing files that changed from the base of the PR and between 58f64ad and d9bb21c.

📒 Files selected for processing (5)
  • src/cmd/wiki/create.rs
  • src/cmd/wiki/delete.rs
  • src/cmd/wiki/mod.rs
  • src/cmd/wiki/show.rs
  • src/cmd/wiki/update.rs
📝 Walkthrough

Walkthrough

Consolidated duplicated test fixture factories by adding shared #[cfg(test)] pub(crate) fn sample_*() helpers (in resource module roots) and updating many subcommand test modules to import and use those shared helpers instead of local copies. No production code or public API signatures were changed.

Changes

Cohort / File(s) Summary
Issue Attachment Helpers
src/cmd/issue/attachment/mod.rs, src/cmd/issue/attachment/delete.rs, src/cmd/issue/attachment/list.rs
Added #[cfg(test)] pub(crate) fn sample_attachment() to mod.rs; removed local sample_attachment() helpers and related test-only imports in sibling tests.
Project Helpers
src/cmd/project/mod.rs, src/cmd/project/{create.rs,delete.rs,list.rs,show.rs,update.rs,admin.rs}
Added sample_project() and sample_project_user() in mod.rs; updated all project subcommand tests to import these shared fixtures and removed local helpers and BTreeMap imports.
Space Notification Helpers
src/cmd/space/mod.rs, src/cmd/space/notification.rs, src/cmd/space/update_notification.rs
Added sample_notification() in mod.rs; tests now import shared helper; adjusted one test expectation to match new fixture data.
Team Helpers
src/cmd/team/mod.rs, src/cmd/team/{add.rs,delete.rs,list.rs,show.rs,update.rs}
Added sample_member() and sample_team() in mod.rs; removed local team/member test helpers and BTreeMap usage across subcommand tests.
User Helpers
src/cmd/user/mod.rs, src/cmd/user/{add.rs,delete.rs,list.rs,show.rs,update.rs}
Added sample_user() in mod.rs; subcommand tests now import it and local sample_user() + BTreeMap imports were removed; one test assertion adjusted to match shared fixture formatting.
Watch Helpers
src/cmd/watch/mod.rs, src/cmd/watch/{add.rs,delete.rs,list.rs,show.rs,update.rs}
Added sample_watching() (deserializes hard-coded JSON) in mod.rs; removed inline JSON/deserialize helpers from tests and import shared fixture instead.
Wiki Attachment Helpers
src/cmd/wiki/attachment/mod.rs, src/cmd/wiki/attachment/{add.rs,delete.rs,list.rs}
Added sample_attachment() in mod.rs (uses shared wiki user helper); sibling tests now import it and local helpers were deleted.
Wiki Page Helpers
src/cmd/wiki/list.rs, src/cmd/wiki/{create.rs,delete.rs,show.rs,update.rs}
Introduced sample_wiki() in list.rs test helpers; removed local sample_wiki() implementations from multiple wiki tests and updated imports to use shared helper.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~30 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 35.16% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main refactoring: promoting shared sample_* test fixtures to pub(crate) in each resource group's mod.rs file.
Description check ✅ Passed The description is well-structured with clear sections explaining the reason for changes, affected groups, and deduplication details.
Linked Issues check ✅ Passed The PR directly addresses issue #107 by promoting duplicated sample_* test helpers to pub(crate) in each resource group's mod.rs, following the precedent of existing patterns.
Out of Scope Changes check ✅ Passed All changes are scoped to test-only refactoring: adding shared sample_* helpers to mod.rs files and removing duplicates from sibling test modules, with no modifications to production code.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch feature/107-share-sample-fixtures

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 and usage tips.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Refactors src/cmd/* test modules to deduplicate repeated sample_* fixture factories by promoting them to shared pub(crate) helpers within each resource group (typically in the group mod.rs, and for wiki in list::tests_helper), then updating tests to import the shared fixtures.

Changes:

  • Added shared #[cfg(test)] pub(crate) fn sample_*() fixtures in resource-group modules (e.g., team, user, watch, space, project, issue/attachment, wiki/attachment).
  • Removed duplicated per-file sample_* fixtures from sibling subcommand test modules.
  • Updated test imports/usages to reference the shared fixtures.

Reviewed changes

Copilot reviewed 41 out of 41 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/cmd/wiki/update.rs Switch tests to use shared sample_wiki fixture.
src/cmd/wiki/show.rs Switch tests to use shared sample_wiki fixture.
src/cmd/wiki/list.rs Extend tests_helper with a shared sample_wiki() for other wiki tests.
src/cmd/wiki/delete.rs Switch tests to use shared sample_wiki fixture.
src/cmd/wiki/create.rs Switch tests to use shared sample_wiki fixture.
src/cmd/wiki/attachment/mod.rs Introduce shared sample_attachment() fixture for wiki-attachment tests.
src/cmd/wiki/attachment/list.rs Use shared sample_attachment() fixture; remove local duplicate.
src/cmd/wiki/attachment/delete.rs Use shared sample_attachment() fixture; remove local duplicate.
src/cmd/wiki/attachment/add.rs Use shared sample_attachment() fixture; remove local duplicate.
src/cmd/watch/update.rs Use shared sample_watching() fixture; remove local duplicate.
src/cmd/watch/show.rs Use shared sample_watching() fixture; remove local duplicate.
src/cmd/watch/mod.rs Introduce shared sample_watching() fixture for watch tests.
src/cmd/watch/list.rs Use shared sample_watching() fixture; remove local duplicate helpers.
src/cmd/watch/delete.rs Use shared sample_watching() fixture; remove local duplicate.
src/cmd/watch/add.rs Use shared sample_watching() fixture; remove local duplicate.
src/cmd/user/update.rs Use shared sample_user() fixture; remove local duplicate.
src/cmd/user/show.rs Use shared sample_user() fixture; remove local duplicate and adjust assertions.
src/cmd/user/mod.rs Introduce shared sample_user() fixture for user tests.
src/cmd/user/list.rs Use shared sample_user() fixture; remove local duplicate.
src/cmd/user/delete.rs Use shared sample_user() fixture; remove local duplicate.
src/cmd/user/add.rs Use shared sample_user() fixture; remove local duplicate.
src/cmd/team/update.rs Use shared sample_team() fixture; remove local duplicate fixtures.
src/cmd/team/show.rs Use shared sample_team() fixture; remove local duplicate fixtures.
src/cmd/team/mod.rs Introduce shared sample_member() / sample_team() fixtures for team tests.
src/cmd/team/list.rs Use shared sample_team() fixture; remove local duplicate fixtures.
src/cmd/team/delete.rs Use shared sample_team() fixture; remove local duplicate fixtures.
src/cmd/team/add.rs Use shared sample_team() fixture; remove local duplicate fixtures.
src/cmd/space/update_notification.rs Use shared sample_notification() fixture; remove local duplicate and update assertions.
src/cmd/space/notification.rs Use shared sample_notification() fixture; remove local duplicate.
src/cmd/space/mod.rs Introduce shared sample_notification() fixture for space tests.
src/cmd/project/user.rs Use shared sample_project_user() fixture (renamed from local sample_user).
src/cmd/project/update.rs Use shared sample_project() fixture; remove local duplicate.
src/cmd/project/show.rs Use shared sample_project() fixture; remove local duplicate.
src/cmd/project/mod.rs Introduce shared sample_project() / sample_project_user() fixtures for project tests.
src/cmd/project/list.rs Use shared sample_project() fixture; remove local duplicate.
src/cmd/project/delete.rs Use shared sample_project() fixture; remove local duplicate.
src/cmd/project/create.rs Use shared sample_project() fixture; remove local duplicate.
src/cmd/project/admin.rs Use shared sample_project_user() fixture (renamed from local sample_user).
src/cmd/issue/attachment/mod.rs Introduce shared sample_attachment() fixture for issue-attachment tests.
src/cmd/issue/attachment/list.rs Use shared sample_attachment() fixture; remove local duplicate user/attachment fixtures.
src/cmd/issue/attachment/delete.rs Use shared sample_attachment() fixture; remove local duplicate.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (3)
src/cmd/wiki/list.rs (1)

82-99: Minor: Remove redundant import.

The use std::collections::BTreeMap; on line 83 is unnecessary since BTreeMap is already imported at line 66 in the enclosing tests_helper module scope.

🧹 Suggested cleanup
     pub fn sample_wiki() -> Wiki {
-        use std::collections::BTreeMap;
         Wiki {
             id: 1,
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/cmd/wiki/list.rs` around lines 82 - 99, The function sample_wiki in
src/cmd/wiki/list.rs contains a redundant local import `use
std::collections::BTreeMap;`; remove that line so the function relies on the
BTreeMap imported at the tests_helper module scope, leaving the rest of the
sample_wiki implementation unchanged.
src/cmd/wiki/delete.rs (1)

45-87: Consider: wiki fixtures location differs from other groups.

The wiki module places shared fixtures in list::tests_helper (requiring imports like crate::cmd::wiki::list::tests_helper::sample_wiki), whereas other resource groups (space, watch, team, project, issue/attachment) place them directly in mod.rs (e.g., crate::cmd::team::sample_team).

This is fine for now but could be unified in a follow-up for consistency across all resource groups.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/cmd/wiki/delete.rs` around lines 45 - 87, Tests in delete.rs import
sample_wiki from crate::cmd::wiki::list::tests_helper, which differs from other
resource groups that expose fixtures at crate::cmd::...::sample_*; to make this
consistent either re-export sample_wiki from the wiki module root or move the
fixture into the wiki module's mod.rs so tests can import
crate::cmd::wiki::sample_wiki; update delete.rs to import sample_wiki from
crate::cmd::wiki::sample_wiki (and/or add a pub use in list::tests_helper) and
ensure the sample_wiki symbol remains available to the tests.
src/cmd/user/show.rs (1)

97-97: Test assertion is now ambiguous.

The assertion text.contains("1") passes for both id (1) and role_type (1) in the shared fixture. The previous assertion likely checked for a more unique value. Consider a more specific assertion to verify the ID field distinctly.

💡 Suggested improvement
-        assert!(text.contains("1"));
+        assert!(text.contains("ID:           1"));

Alternatively, you could check for the bold formatting applied to the ID, or use a regex to match the specific line.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/cmd/user/show.rs` at line 97, The test assertion text.contains("1") is
ambiguous (matches both id and role_type); update the assertion in the test in
show.rs to target the ID field explicitly — e.g. assert that the output contains
the exact ID label and value (like "ID: 1" or the bold-formatted ID string), or
use a regex that matches the ID line only (for example a multiline regex
matching "^ID:\\s*1\\b"). Locate the failing assertion (text.contains("1")) and
replace it with a more specific containment or regex check so it only verifies
the record ID, not other fields such as role_type.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/cmd/wiki/show.rs`:
- Around line 52-53: The test in show.rs currently imports sample_wiki from the
sibling list::tests_helper which couples tests to list internals; change the
import to the wiki group-level helper exported by the wiki mod (use the
module-level tests_helper export) so show.rs imports sample_wiki from
crate::cmd::wiki::tests_helper (referenced symbol: sample_wiki) instead of
crate::cmd::wiki::list::tests_helper; update the use line in show.rs accordingly
to reference the module-level helper exported by mod.rs.

---

Nitpick comments:
In `@src/cmd/user/show.rs`:
- Line 97: The test assertion text.contains("1") is ambiguous (matches both id
and role_type); update the assertion in the test in show.rs to target the ID
field explicitly — e.g. assert that the output contains the exact ID label and
value (like "ID: 1" or the bold-formatted ID string), or use a regex that
matches the ID line only (for example a multiline regex matching
"^ID:\\s*1\\b"). Locate the failing assertion (text.contains("1")) and replace
it with a more specific containment or regex check so it only verifies the
record ID, not other fields such as role_type.

In `@src/cmd/wiki/delete.rs`:
- Around line 45-87: Tests in delete.rs import sample_wiki from
crate::cmd::wiki::list::tests_helper, which differs from other resource groups
that expose fixtures at crate::cmd::...::sample_*; to make this consistent
either re-export sample_wiki from the wiki module root or move the fixture into
the wiki module's mod.rs so tests can import crate::cmd::wiki::sample_wiki;
update delete.rs to import sample_wiki from crate::cmd::wiki::sample_wiki
(and/or add a pub use in list::tests_helper) and ensure the sample_wiki symbol
remains available to the tests.

In `@src/cmd/wiki/list.rs`:
- Around line 82-99: The function sample_wiki in src/cmd/wiki/list.rs contains a
redundant local import `use std::collections::BTreeMap;`; remove that line so
the function relies on the BTreeMap imported at the tests_helper module scope,
leaving the rest of the sample_wiki implementation unchanged.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: f7facf8e-1220-46b2-949d-906b6e3ed556

📥 Commits

Reviewing files that changed from the base of the PR and between dc8aede and 76797f7.

📒 Files selected for processing (41)
  • src/cmd/issue/attachment/delete.rs
  • src/cmd/issue/attachment/list.rs
  • src/cmd/issue/attachment/mod.rs
  • src/cmd/project/admin.rs
  • src/cmd/project/create.rs
  • src/cmd/project/delete.rs
  • src/cmd/project/list.rs
  • src/cmd/project/mod.rs
  • src/cmd/project/show.rs
  • src/cmd/project/update.rs
  • src/cmd/project/user.rs
  • src/cmd/space/mod.rs
  • src/cmd/space/notification.rs
  • src/cmd/space/update_notification.rs
  • src/cmd/team/add.rs
  • src/cmd/team/delete.rs
  • src/cmd/team/list.rs
  • src/cmd/team/mod.rs
  • src/cmd/team/show.rs
  • src/cmd/team/update.rs
  • src/cmd/user/add.rs
  • src/cmd/user/delete.rs
  • src/cmd/user/list.rs
  • src/cmd/user/mod.rs
  • src/cmd/user/show.rs
  • src/cmd/user/update.rs
  • src/cmd/watch/add.rs
  • src/cmd/watch/delete.rs
  • src/cmd/watch/list.rs
  • src/cmd/watch/mod.rs
  • src/cmd/watch/show.rs
  • src/cmd/watch/update.rs
  • src/cmd/wiki/attachment/add.rs
  • src/cmd/wiki/attachment/delete.rs
  • src/cmd/wiki/attachment/list.rs
  • src/cmd/wiki/attachment/mod.rs
  • src/cmd/wiki/create.rs
  • src/cmd/wiki/delete.rs
  • src/cmd/wiki/list.rs
  • src/cmd/wiki/show.rs
  • src/cmd/wiki/update.rs

23prime added 2 commits March 22, 2026 17:05
…ser ID field

Addresses review comment: assert!(text.contains("1")) is too weak
…ralization

Addresses review comment: import sample_wiki from list::tests_helper couples tests to list internals
@23prime 23prime merged commit 93afa4d into main Mar 22, 2026
7 checks passed
@23prime 23prime deleted the feature/107-share-sample-fixtures branch March 22, 2026 08:09
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.

refactor: share sample_* test fixture factories within each resource group

2 participants