Groom code (remove dead code, increase coverage) #1061
Merged
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.
This series of commits significantly refactors the evidence collection logic in the push model agent and substantially increases the test coverage for the struct_filler and state_machine modules.
The primary motivation is to improve code quality by removing dead code paths and ensuring the core state transition logic is robust and well-tested.
Key Changes:
struct_filler.rs Refactoring (Commit 1/3):
Removed Dead Code: The unused FillerFromFile and FillerFromCode structs, along with their associated helper functions, have been completely removed. This significantly simplifies the module's public API and internal logic.
Simplified Logic: The get_filler_request function has been streamlined. It now has a single decision point: it returns a FillerFromHardware if a TPM ContextInfo is provided, otherwise it falls back to the TestingFiller. This makes the code's intent clearer and easier to maintain.
Increased Coverage for struct_filler.rs (Commit 2/3):
Following the refactoring, a comprehensive suite of unit tests has been added to cover the remaining logic in struct_filler.rs. The new tests verify:
Correct dispatcher behavior in get_filler_request for both Some(Context) and None cases.
The default behavior of the TestingFiller.
Error handling paths in FillerFromHardware, such as when parsing a malformed verifier response or when underlying hardware/TPM access fails.
Increased Coverage for state_machine.rs (Commit 3/3):
A new suite of integration-style tests has been added for the StateMachine.
These tests use a mock registration module (injected via conditional compilation) and a mock AttestationClient to test the state machine's flow control in isolation from network and hardware dependencies.
The tests now cover the "happy path" of the run() method from Unregistered to Complete, as well as failure transitions if the negotiation or attestation phases fail.