Skip to content

refactor(client): Introduce ClientBuilder pattern to fix constructor telescoping#902

Open
addisonbeck wants to merge 6 commits intomainfrom
pm-34617
Open

refactor(client): Introduce ClientBuilder pattern to fix constructor telescoping#902
addisonbeck wants to merge 6 commits intomainfrom
pm-34617

Conversation

@addisonbeck
Copy link
Copy Markdown
Contributor

🎟️ Tracking

https://bitwarden.atlassian.net/browse/PM-34617

📔 Objective

We've got multiple in flight SDK features where part of the design is to create new constructors for clients with different options for provided args.

This PR sets up a builder pattern to replace these. I've left the old constructors and have not marked them deprecated, but all new work will follow this new pattern.

Introduces ClientBuilder in crates/bitwarden-core/src/client/builder.rs
with new(), with_settings(), with_token_handler(), and build() methods.
The build() body is the exact logic from Client::new_internal, moved here
as the first step of the builder pattern refactor (PM-34617).

Includes Default impl and 4 unit tests. Helper functions
new_http_client_builder() and build_default_headers() moved from
client.rs into this file. Module not yet wired into mod.rs — that
happens in Commit 3.
Client::new() and Client::new_with_token_handler() are now thin wrappers
delegating to ClientBuilder::build(). Adds Client::builder() factory method.
Removes Client::new_internal() entirely. Wires pub mod builder into
client/mod.rs so ClientBuilder is resolvable.

Part of PM-34617 builder pattern refactor.
Adds pub use builder::ClientBuilder in client/mod.rs and includes
ClientBuilder in the pub use client::{...} re-export in lib.rs.
ClientBuilder is now importable as bitwarden_core::ClientBuilder.

All 4 builder unit tests now compile and pass. Part of PM-34617.
Introduces PasswordManagerClientBuilder in crates/bitwarden-pm/src/builder.rs
with new(), with_settings(), build(), and Default impl. Delegates to
ClientBuilder::new().with_token_handler(PasswordManagerTokenHandler::default()).

Includes 2 unit tests. Module not yet wired into lib.rs — that
happens in the next commit. Part of PM-34617.
@addisonbeck addisonbeck added the ai-review Request a Claude code review label Apr 3, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 3, 2026

Logo
Checkmarx One – Scan Summary & Details69c6d6e3-bed2-4ef6-8ac8-88c34b033631


New Issues (1) Checkmarx found the following issues in this Pull Request
# Severity Issue Source File / Package Checkmarx Insight
1 LOW Parameter_Tampering /crates/bitwarden-uniffi/kotlin/app/src/main/java/com/bitwarden/myapplication/MainActivity.kt: 410
detailsMethod decryptVault at line 410 of /crates/bitwarden-uniffi/kotlin/app/src/main/java/com/bitwarden/myapplication/MainActivity.kt gets user input ...
Attack Vector

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 3, 2026

🔍 SDK Breaking Change Detection Results

SDK Version: pm-34617 (8f91a91)
Completed: 2026-04-04 01:18:26 UTC
Total Time: 275s

Client Status Details
typescript ✅ No breaking changes detected TypeScript compilation passed with new SDK version - View Details

Breaking change detection completed. View SDK workflow

addisonbeck added a commit that referenced this pull request Apr 3, 2026
The project enforces #![warn(missing_docs)] escalated to errors
via RUSTFLAGS=-D warnings. All new public items introduced by the
ClientBuilder refactor (PR #902) were missing doc comments,
causing 10 CI job failures across all platforms (build + clippy).

Adds /// doc comments to:
- ClientBuilder struct and its new(), with_settings(),
  with_token_handler(), and build() methods
- pub mod builder declaration in client/mod.rs
- Client::builder() factory method
- PasswordManagerClientBuilder struct and its new(),
  with_settings(), and build() methods
- PasswordManagerClient::builder() factory method

Refs: PM-34617
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 3, 2026

Bitwarden Claude Code Review

Overall Assessment: APPROVE

This PR introduces a ClientBuilder in bitwarden-core and a PasswordManagerClientBuilder in bitwarden-pm to replace constructor telescoping. The refactor is a clean mechanical extraction of Client::new_internal into ClientBuilder::build() with no behavioral changes. All #[cfg] feature guards, TLS configuration, HTTPS enforcement, and header construction are preserved identically. Existing public APIs (Client::new, Client::new_with_token_handler, PasswordManagerClient::new) remain backward compatible, delegating to the new builders internally. Tests cover default construction, settings, token handler, and method chaining order independence.

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 3, 2026

Codecov Report

❌ Patch coverage is 79.76879% with 35 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.46%. Comparing base (7cc2cbc) to head (8f91a91).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
crates/bitwarden-core/src/client/builder.rs 82.67% 22 Missing ⚠️
crates/bitwarden-pm/src/lib.rs 0.00% 8 Missing ⚠️
crates/bitwarden-pm/src/builder.rs 88.88% 3 Missing ⚠️
crates/bitwarden-core/src/client/client.rs 81.81% 2 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main     #902   +/-   ##
=======================================
  Coverage   82.45%   82.46%           
=======================================
  Files         356      358    +2     
  Lines       42817    42893   +76     
=======================================
+ Hits        35306    35370   +64     
- Misses       7511     7523   +12     

☔ 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.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@addisonbeck
Copy link
Copy Markdown
Contributor Author

The breaking change reported here is unrelated, typechecking on clients is failing on main.

The project enforces #![warn(missing_docs)] escalated to errors
via RUSTFLAGS=-D warnings. All new public items introduced by the
ClientBuilder refactor (PR #902) were missing doc comments,
causing 10 CI job failures across all platforms (build + clippy).

Adds /// doc comments to:
- ClientBuilder struct and its new(), with_settings(),
  with_token_handler(), and build() methods
- pub mod builder declaration in client/mod.rs
- Client::builder() factory method
- PasswordManagerClientBuilder struct and its new(),
  with_settings(), and build() methods
- PasswordManagerClient::builder() factory method

Refs: PM-34617
@addisonbeck addisonbeck marked this pull request as ready for review April 3, 2026 19:52
@addisonbeck addisonbeck requested a review from a team as a code owner April 3, 2026 19:52
@addisonbeck addisonbeck requested a review from dani-garcia April 3, 2026 19:52
dani-garcia
dani-garcia previously approved these changes Apr 3, 2026
Copy link
Copy Markdown
Member

@dani-garcia dani-garcia left a comment

Choose a reason for hiding this comment

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

LGTM just one tiny nit

Co-authored-by: Daniel García <dani-garcia@users.noreply.github.com>
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud bot commented Apr 4, 2026

@addisonbeck addisonbeck requested a review from dani-garcia April 5, 2026 22:55
@addisonbeck addisonbeck enabled auto-merge (squash) April 5, 2026 23:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai-review Request a Claude code review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants