-
Notifications
You must be signed in to change notification settings - Fork 0
Give home-directory resolution an injectable env seam (#486) #499
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
b5d6a52
Rebuild the home-resolution env seam on top of main
bf1bffb
Thread the injected env reader through home resolution
f32a238
Add the comma after the introductory when clause
04a9947
Render a configured home through the registered filter
0009dab
Drop the cfg gates from the home-directory ladders
1e5519f
Borrow the workspace root instead of cloning it in the filter test
aa78d0f
Report which source supplied the expanduser home
e8920f2
Document both home-resolution telemetry events
a5c24f6
Gate the home ladders and count their outcomes
leynos File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| # Seeds for failure cases proptest has generated in the past. It is | ||
| # automatically read and these particular cases re-run before any | ||
| # novel cases are generated. | ||
| # | ||
| # It is recommended to check this file in to source control so that | ||
| # everyone who runs the test benefits from these saved cases. | ||
| # Recorded while mutation-testing the property (the HOMEDRIVE emptiness | ||
| # check was disabled to prove the test detects it), not from a defect in | ||
| # the ladder itself. | ||
| cc be405399e1c660af7820653ee114f838dcaba6702e5fe1b47efc3a0a4953002c # shrinks to home = None, userprofile = None, homedrive = Some(""), homepath = Some("a"), homeshare = None |
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| //! Tests for the bounded home-resolution counter. | ||
| //! | ||
| //! Split from `home_tests`, which covers the ladders and the tracing events; | ||
| //! these cases pin the metric alone. A local `DebuggingRecorder` captures the | ||
| //! samples without touching the global recorder, so they stay as isolated as | ||
| //! the ladder cases. Both labels are drawn from closed sets in `path_utils`, | ||
| //! so the assertions below pin the series a dashboard would group by. | ||
|
|
||
| use super::path_utils::{EXPANDUSER_HOME_TOTAL, expanduser}; | ||
| use crate::stdlib::config_types::HomeDirectory; | ||
| use metrics_util::MetricKind; | ||
| use metrics_util::debugging::{DebugValue, DebuggingRecorder}; | ||
| use rstest::rstest; | ||
|
|
||
| /// Resolve one path under a local recorder and return the counter samples | ||
| /// as `(outcome, source, value)` triples. | ||
| fn samples_for( | ||
| home: &HomeDirectory, | ||
| read_env: impl Fn(&str) -> Option<String>, | ||
| ) -> Vec<(String, String, u64)> { | ||
| let recorder = DebuggingRecorder::new(); | ||
| let snapshotter = recorder.snapshotter(); | ||
| metrics::with_local_recorder(&recorder, || { | ||
| drop(expanduser("~/x", home, read_env)); | ||
| }); | ||
| snapshotter | ||
| .snapshot() | ||
| .into_vec() | ||
| .into_iter() | ||
| .filter_map(|(key, _unit, _description, value)| { | ||
| if key.kind() != MetricKind::Counter || key.key().name() != EXPANDUSER_HOME_TOTAL { | ||
| return None; | ||
| } | ||
| let label = |name: &str| { | ||
| key.key() | ||
| .labels() | ||
| .find(|label| label.key() == name) | ||
| .map(|label| label.value().to_owned()) | ||
| }; | ||
| let DebugValue::Counter(count) = value else { | ||
| return None; | ||
| }; | ||
| Some((label("outcome")?, label("source")?, count)) | ||
| }) | ||
| .collect() | ||
| } | ||
|
|
||
| /// A resolution that finds a home records `found` against the rung that | ||
| /// supplied it — one sample, whichever branch resolved it. | ||
| #[rstest] | ||
| #[case::explicit(HomeDirectory::Explicit("/home/a".to_owned()), "explicit")] | ||
| #[case::ambient(HomeDirectory::Ambient, "home")] | ||
| fn a_resolved_home_is_counted_against_its_source( | ||
| #[case] home: HomeDirectory, | ||
| #[case] expected_source: &str, | ||
| ) { | ||
| let read_env = |key: &str| (key == "HOME").then(|| "/home/a".to_owned()); | ||
| let samples = samples_for(&home, read_env); | ||
| assert_eq!( | ||
| samples, | ||
| vec![("found".to_owned(), expected_source.to_owned(), 1)], | ||
| "one sample labelled by outcome and source", | ||
| ); | ||
| } | ||
|
|
||
| /// A resolution that finds nothing records the failure outcome against the | ||
| /// `missing` source, and still counts exactly once despite the second debug | ||
| /// event the failure path emits. | ||
| #[rstest] | ||
| #[case::missing(HomeDirectory::Missing)] | ||
| #[case::ambient_with_an_empty_reader(HomeDirectory::Ambient)] | ||
| fn an_unresolvable_home_is_counted_once(#[case] home: HomeDirectory) { | ||
| let samples = samples_for(&home, |_| None); | ||
| assert_eq!( | ||
| samples, | ||
| vec![("home_unavailable".to_owned(), "missing".to_owned(), 1)], | ||
| "the failure path adds an event, not a second sample", | ||
| ); | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.