serviceability: prune User test literals in multicastgroup/tenant/user commands - #4328
Open
ayushsingh82 wants to merge 1 commit into
Open
ayushsingh82 wants to merge 1 commit into
ayushsingh82 wants to merge 1 commit into
Conversation
…r commands Second slice of malbeclabs#4084: tenant/delete.rs, multicastgroup/{subscribe, subscribe_feed,unsubscribe_feed}.rs, and user/{delete,requestban,update}.rs each built a full ~20-field User literal per test even though the command under test only reads a handful of those fields (owner, device_pk, client_ip, tenant_pk, publishers/subscribers, user_type — whichever ones the specific command actually branches on or forwards into the instruction it builds). Pruned each literal down to just the fields that are read by the command or asserted on by the test, letting User::default() (malbeclabs#4080) fill the rest. accesspass/get.rs was already at this shape from the malbeclabs#4244 work. sdk/rs is now fully done; crates/doublezero-daemon-cli is left for a follow-up — connect.rs alone has ~70 more User literals, too large for one PR.
Contributor
Author
|
@nikw9944 could you take a look when you have a chance? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
PR #4080 added a manual
impl Default for Userand switched test literals acrosssmartcontract/cli,smartcontract/sdk/rs, andcrates/doublezero-daemon-clito end with..Default::default()— but as merged, the struct-update tail only absorbedfeed_pks; every literal still named the other ~20 fields explicitly. #4084 asks to lean into the pattern: prune each literal down to only the fields a test actually asserts on or that drive the command's behavior.#4235 did the first slice (
smartcontract/cli/src/user/*). This is the second slice:smartcontract/sdk/rs.Changes
Pruned
Userliterals in:commands/tenant/delete.rscommands/multicastgroup/{subscribe,subscribe_feed,unsubscribe_feed}.rscommands/user/{delete,requestban,update}.rsFor each literal I traced which fields the command under test actually reads (or which the test's own mock setup independently depends on) before dropping the rest — e.g.
DeleteUserCommandreadsowner/device_pk/tenant_pk/publishers/subscribersbut neveruser_type/cyoa_type/dz_ip/tunnel_net/etc., so only the former survive per-test.commands/accesspass/get.rswas already at this shape (from the earlier #4244 work), so it's untouched here.crates/doublezero-daemon-cliis not included —connect.rsalone has ~70 moreUserliterals, well past this repo's ~500-line PR guidance, so that's left for a follow-up PR.Testing Verification
cargo test -p doublezero_sdk --lib: 212/212 passing (no literal's pruning changed a test's outcome).cargo clippy -p doublezero_sdk --all-targets -- -Dclippy::all -Dwarnings: clean.cargo +nightly fmt -p doublezero_sdk -- --check: clean.NetworkV4,UserCYOA,UserStatus,UserType,Ipv4Addr) file-by-file as literals no longer referenced them.