Skip to content

refactor: add default unimplemented!() to BacklogApi trait to eliminate test boilerplate#63

Merged
23prime merged 3 commits intomainfrom
feature/backlog-api-default-impls
Mar 15, 2026
Merged

refactor: add default unimplemented!() to BacklogApi trait to eliminate test boilerplate#63
23prime merged 3 commits intomainfrom
feature/backlog-api-default-impls

Conversation

@23prime
Copy link
Owner

@23prime 23prime commented Mar 15, 2026

Checklist

  • Target branch is main
  • Status checks are passing

Summary

  • Add default unimplemented!() bodies to all BacklogApi trait methods
  • Remove 2,150 unimplemented!() stub implementations from test MockApi structs across 44 files

Reason for change

Each MockApi in tests had to implement all ~43 trait methods even when only 1–2 were relevant to the test. This made test files very long, hurt readability, and wasted context when AI reads the codebase.

Changes

  • src/api/mod.rs: trait methods now have default { unimplemented!() } bodies (with _-prefixed unused params)
  • src/cmd/**/*.rs: removed all stub-only methods from test MockApi/MockApiCapture impls; only methods with meaningful logic remain

Notes

  • impl BacklogApi for BacklogClient is unchanged — it still overrides every method with real HTTP calls
  • Net change: -10,503 lines / -2,150 stubs

Copilot AI review requested due to automatic review settings March 15, 2026 04:30
@coderabbitai
Copy link

coderabbitai bot commented Mar 15, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 1278ce62-4a41-4a36-bb52-b0288f04db73

📥 Commits

Reviewing files that changed from the base of the PR and between 25fc7e2 and fbb6366.

📒 Files selected for processing (1)
  • .claude/skills/developing/references/patterns.md

📝 Walkthrough

Walkthrough

BacklogApi trait in src/api/mod.rs now provides default method bodies (mostly unimplemented!()), many method signatures accept underscored params, and the inherent BacklogClient impl forwards calls to same-named methods. Test modules across many command files trim their MockApi impls to only the methods each test exercises.

Changes

Cohort / File(s) Summary
API trait defaults & client forwarding
src/api/mod.rs
Added default implementations (typically unimplemented!()) for many BacklogApi methods; parameters renamed with leading underscores. BacklogClient's inherent impl forwards to self.<method>(), preserving call sites but creating potential recursion if trait methods are not overridden.
Command test mocks trimmed
src/cmd/... (many files, e.g. src/cmd/auth.rs, src/cmd/issue/*, src/cmd/project/*, src/cmd/space/*, src/cmd/user/*, src/cmd/wiki/*, src/cmd/notification/*, src/cmd/team/*)
Removed large blocks of MockApi method stubs in test modules; each test now implements only the BacklogApi method(s) it uses and narrowed test imports to required types.
Docs / example updates
.claude/skills/developing/references/patterns.md
Updated examples and guidance to match new trait signatures (query-param slices) and note that BacklogApi now supplies default unimplemented!() bodies; MockApi examples updated accordingly.

Sequence Diagram(s)

sequenceDiagram
    participant Cmd as Caller (command)
    participant Client as BacklogClient
    participant Trait as BacklogApi trait (default)
    participant Impl as Concrete impl (e.g., MockApi / HTTP client)

    Cmd->>Client: call Client.get_space()
    Note right of Client: inherent impl forwards
    Client->>Trait: calls self.get_space()
    alt Concrete impl overrides
      Trait->>Impl: dispatch to Impl.get_space()
      Impl-->>Trait: Result<Space>
      Trait-->>Client: return result
      Client-->>Cmd: return result
    else No override (uses trait default)
      Trait-->>Trait: default body executes (unimplemented!() or other)
      Trait-->>Client: panic / unimplemented
      Client-->>Cmd: panic / error
    end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

Poem

🐰 I trimmed my mock to one bright hop,
Hopped through traits that now say "unimplemented" on top.
The client calls itself in a curious loop,
I nibble recursion and juggle a troop.
Tiny mocks, big carrots — hop on, let's stop!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed Title clearly and specifically describes the main change: adding default unimplemented!() to BacklogApi trait and eliminating test boilerplate through the removal of stub implementations.
Description check ✅ Passed Description is well-structured, provides clear context (problem: repetitive test boilerplate), explains the solution (default implementations in trait), lists specific changes across files, and includes a note about unchanged behavior for BacklogClient.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feature/backlog-api-default-impls
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch feature/backlog-api-default-impls
📝 Coding Plan
  • Generate coding plan for human review comments

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

This PR refactors the BacklogApi trait to provide default unimplemented!() method bodies, allowing test mocks to implement only the API calls they actually exercise, and removes large amounts of stub-only boilerplate from command tests.

Changes:

  • Added default unimplemented!() bodies to all BacklogApi trait methods.
  • Removed stub-only unimplemented!() method implementations from many test MockApi impls, along with now-unneeded imports.
  • Kept BacklogClient’s BacklogApi implementation overriding all methods with real behavior.

Reviewed changes

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

Show a summary per file
File Description
src/api/mod.rs Adds default unimplemented!() bodies to BacklogApi methods to reduce test mock boilerplate.
src/cmd/auth.rs Simplifies test MockApi impl by removing unused trait-method stubs.
src/cmd/wiki/update.rs Removes stub-only mock methods and trims test imports.
src/cmd/wiki/show.rs Removes stub-only mock methods and trims test imports.
src/cmd/wiki/list.rs Removes stub-only mock methods and trims test imports.
src/cmd/wiki/history.rs Removes stub-only mock methods and trims test imports.
src/cmd/wiki/delete.rs Removes stub-only mock methods and trims test imports.
src/cmd/wiki/create.rs Removes stub-only mock methods and trims test imports.
src/cmd/wiki/attachment/list.rs Removes stub-only mock methods and trims test imports.
src/cmd/user/show.rs Removes stub-only mock methods from tests.
src/cmd/user/list.rs Removes stub-only mock methods from tests.
src/cmd/team/show.rs Removes stub-only mock methods from tests.
src/cmd/space/update_notification.rs Removes stub-only mock methods from tests.
src/cmd/space/show.rs Removes stub-only mock methods from tests.
src/cmd/space/notification.rs Removes stub-only mock methods from tests.
src/cmd/space/licence.rs Removes stub-only mock methods from tests.
src/cmd/space/disk_usage.rs Removes stub-only mock methods from tests.
src/cmd/project/version.rs Removes stub-only mock methods from tests.
src/cmd/project/user.rs Removes stub-only mock methods from tests.
src/cmd/project/status.rs Removes stub-only mock methods from tests.
src/cmd/project/show.rs Removes stub-only mock methods from tests.
src/cmd/project/list.rs Removes stub-only mock methods from tests.
src/cmd/project/issue_type.rs Removes stub-only mock methods from tests.
src/cmd/project/disk_usage.rs Removes stub-only mock methods from tests.
src/cmd/project/category.rs Removes stub-only mock methods from tests.
src/cmd/notification/reset_unread.rs Removes stub-only mock methods/imports, leaving only the tested API call.
src/cmd/notification/read.rs Removes stub-only mock methods/imports, leaving only the tested API call.
src/cmd/notification/count.rs Removes stub-only mock methods/imports, leaving only the tested API call.
src/cmd/issue/update.rs Removes stub-only mock methods and trims test imports.
src/cmd/issue/show.rs Removes stub-only mock methods and trims test imports.
src/cmd/issue/list.rs Removes stub-only mock methods and trims test imports.
src/cmd/issue/delete.rs Removes stub-only mock methods and trims test imports.
src/cmd/issue/create.rs Removes stub-only mock methods and trims test imports.
src/cmd/issue/count.rs Removes stub-only mock methods and trims test imports.
src/cmd/issue/comment/update.rs Removes stub-only mock methods and trims test imports.
src/cmd/issue/comment/list.rs Removes stub-only mock methods and trims test imports.
src/cmd/issue/comment/delete.rs Removes stub-only mock methods and trims test imports.
src/cmd/issue/comment/add.rs Removes stub-only mock methods and trims test imports.
src/cmd/issue/attachment/list.rs Removes stub-only mock methods and trims test imports.

You can also share your feedback on Copilot code review. Take the survey.

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: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In @.claude/skills/developing/references/patterns.md:
- Around line 45-51: The examples are inconsistent with the new parameterized
signature for get_my_resource; update all declarations and call sites to accept
and forward params. Specifically, change the trait/default stub for
get_my_resource to fn get_my_resource(&self, params: &[(String, String)]) ->
Result<MyResource>, update BacklogClient::get_my_resource implementation to
accept params and forward them (self.get_my_resource(params)), and update any
example calls (e.g., api.get_my_resource() ) to pass a params value (e.g.,
api.get_my_resource(&params) or similar) so BacklogApi, BacklogClient and
example usage are consistent.

In `@src/api/mod.rs`:
- Around line 52-199: The default implementations in BacklogApi (e.g.,
get_space, get_myself, get_users, get_user, get_space_activities,
get_space_disk_usage, get_space_notification, get_projects, get_project,
get_project_activities, get_project_disk_usage, get_project_users,
get_project_statuses, get_project_issue_types, get_project_categories,
get_project_versions, get_issues, count_issues, get_issue, create_issue,
update_issue, delete_issue, get_issue_comments, add_issue_comment,
update_issue_comment, delete_issue_comment, get_issue_attachments, get_wikis,
get_wiki, create_wiki, update_wiki, delete_wiki, get_wiki_history,
get_wiki_attachments, get_teams, get_team, get_user_activities,
get_recently_viewed_issues, get_notifications, count_notifications,
read_notification, reset_unread_notifications, get_space_licence,
put_space_notification) currently call unimplemented!() which panics; replace
each panic with an anyhow-compatible error return (e.g., return
Err(anyhow::anyhow!("BacklogApi::<method_name> not implemented")) or use
anyhow::bail!) so the functions return a Result::Err instead of crashing; update
imports to include anyhow if missing and ensure the error message identifies the
specific method (use the method name symbol) for easier debugging.
🪄 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: d6dd45dc-f4ff-494b-a157-ef9965b54791

📥 Commits

Reviewing files that changed from the base of the PR and between bc5b753 and 25fc7e2.

📒 Files selected for processing (2)
  • .claude/skills/developing/references/patterns.md
  • src/api/mod.rs

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