Skip to content
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

Fix -OlderThan/-NewerThan parameters for Test-Path when using PathType and date range #20942

Merged

Conversation

ArmaanMcleod
Copy link
Contributor

@ArmaanMcleod ArmaanMcleod commented Dec 18, 2023

PR Summary

Fixes #19855
Fixes #19462

Fix -OlderThan/-NewerThan dynamic parameters for Test-Path when using PathType and date range.

PR Context

Made the following changes to improve experience using date parameters:

  • Removed this.PathType == TestPathType.Any check from GetDynamicParameters method so -OlderThan/-NewerThan can be used with any path type.
  • Updated file system provider logic which checks -OlderThan/-NewerThan last write time in ItemExists method to do a logical AND so it checks path existence within a time range instead of NewerThan overwriting OlderThan if they are both used. This change is probably considered a bucket 3 breaking change since its highly unlikely anyone relied in previous broken behaviour.
  • Updated Test-Path to run ItemExists on directories as well so they can be checked with -OlderThan/-NewerThan parameters, since before it only checked IsItemContainer, which didn't run the dynamic parameter date checks.
  • Updated tests to check -OlderThan/-NewerThan parameters since there was no code coverage for this functonality before this PR. Included multiple combinations of path types against files & directories.

PR Checklist

This PR has 70 quantified lines of changes. In general, a change size of upto 200 lines is ideal for the best PR experience!


Quantification details

Label      : Small
Size       : +61 -9
Percentile : 28%

Total files changed: 3

Change summary by file extension:
.cs : +6 -9
.ps1 : +55 -0

Change counts above are quantified counts, based on the PullRequestQuantifier customizations.

Why proper sizing of changes matters

Optimal pull request sizes drive a better predictable PR flow as they strike a
balance between between PR complexity and PR review overhead. PRs within the
optimal size (typical small, or medium sized PRs) mean:

  • Fast and predictable releases to production:
    • Optimal size changes are more likely to be reviewed faster with fewer
      iterations.
    • Similarity in low PR complexity drives similar review times.
  • Review quality is likely higher as complexity is lower:
    • Bugs are more likely to be detected.
    • Code inconsistencies are more likely to be detected.
  • Knowledge sharing is improved within the participants:
    • Small portions can be assimilated better.
  • Better engineering practices are exercised:
    • Solving big problems by dividing them in well contained, smaller problems.
    • Exercising separation of concerns within the code changes.

What can I do to optimize my changes

  • Use the PullRequestQuantifier to quantify your PR accurately
    • Create a context profile for your repo using the context generator
    • Exclude files that are not necessary to be reviewed or do not increase the review complexity. Example: Autogenerated code, docs, project IDE setting files, binaries, etc. Check out the Excluded section from your prquantifier.yaml context profile.
    • Understand your typical change complexity, drive towards the desired complexity by adjusting the label mapping in your prquantifier.yaml context profile.
    • Only use the labels that matter to you, see context specification to customize your prquantifier.yaml context profile.
  • Change your engineering behaviors
    • For PRs that fall outside of the desired spectrum, review the details and check if:
      • Your PR could be split in smaller, self-contained PRs instead
      • Your PR only solves one particular issue. (For example, don't refactor and code new features in the same PR).

How to interpret the change counts in git diff output

  • One line was added: +1 -0
  • One line was deleted: +0 -1
  • One line was modified: +1 -1 (git diff doesn't know about modified, it will
    interpret that line like one addition plus one deletion)
  • Change percentiles: Change characteristics (addition, deletion, modification)
    of this PR in relation to all other PRs within the repository.


Was this comment helpful? 👍  :ok_hand:  :thumbsdown: (Email)
Customize PullRequestQuantifier for this repository.

@iSazonov iSazonov added WG-Cmdlets-Utility cmdlets in the Microsoft.PowerShell.Utility module CL-BreakingChange Indicates that a PR should be marked as a breaking change in the Change Log CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log WG-NeedsReview Needs a review by the labeled Working Group Review - Committee The PR/Issue needs a review from the PowerShell Committee labels Dec 18, 2023
@iSazonov
Copy link
Collaborator

The GitHub search results shows that users don't use this both parameters simultaneously. So the change is in grace area and only formally breaking change.
As for directory behavior change, now we return true only if container exist. But docs say for the cmdlet "Determines whether all elements of a path exist." So old behavior was a bug and the PR fix it.

@iSazonov iSazonov added the PowerShell-Docs needed The PR was reviewed and a PowerShell Docs update is needed label Dec 18, 2023
@iSazonov
Copy link
Collaborator

@ArmaanMcleod Please open doc issue - I think we need to add more informative examples for these parameters.

@ArmaanMcleod
Copy link
Contributor Author

@iSazonov Thanks for confirming current usage using both parameters together and container bug 🙂.

I have also opened up docs issue to document parameter usage.

@SteveL-MSFT
Copy link
Member

@PowerShell/wg-powershell-cmdlets reviewed this, we agree that the change to -OlderThan and -NewerThan to apply to a date range rather than having -OlderThan dropped when both are used (seems like a bug) enables a useful case whereas the previous behavior is unlikely to be relied upon.

@SteveL-MSFT SteveL-MSFT added WG-Reviewed A Working Group has reviewed this and made a recommendation and removed Review - Committee The PR/Issue needs a review from the PowerShell Committee WG-NeedsReview Needs a review by the labeled Working Group labels Dec 20, 2023
@iSazonov iSazonov merged commit 103c945 into PowerShell:master Dec 20, 2023
38 checks passed
Copy link
Contributor

microsoft-github-policy-service bot commented Dec 20, 2023

📣 Hey @ArmaanMcleod, how did we do? We would love to hear your feedback with the link below! 🗣️

🔗 https://aka.ms/PSRepoFeedback

@ArmaanMcleod ArmaanMcleod deleted the test-path-type-fix-dynamic-param branch December 20, 2023 22:19
VindSkyggen pushed a commit to VindSkyggen/PowerShell that referenced this pull request Dec 26, 2023
dkattan pushed a commit to dkattan/PowerShell that referenced this pull request Feb 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CL-BreakingChange Indicates that a PR should be marked as a breaking change in the Change Log CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log PowerShell-Docs needed The PR was reviewed and a PowerShell Docs update is needed Small WG-Cmdlets-Utility cmdlets in the Microsoft.PowerShell.Utility module WG-Reviewed A Working Group has reviewed this and made a recommendation
Projects
None yet
3 participants