Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Windows version check in doctor #110013

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

Conversation

eliasyishak
Copy link
Contributor

@eliasyishak eliasyishak commented Aug 22, 2022

Pre-launch Checklist

  • I read the [Contributor Guide] and followed the process outlined there for submitting PRs.
  • I read the [Tree Hygiene] wiki page, which explains my responsibilities.
  • I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement].
  • I signed the [CLA].
  • I listed at least one issue that this PR fixes in the description above.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is [test-exempt].
  • All existing and new tests are passing.

Addresses #102607 stating that a warning should be emitted during a flutter doctor run to warn users on Windows versions less than 10

@flutter-dashboard flutter-dashboard bot added the tool Affects the "flutter" command-line tool. See also t: labels. label Aug 22, 2022
@eliasyishak
Copy link
Contributor Author

eliasyishak commented Aug 22, 2022

Example return from a systeminfo call in a Windows environment.

Host Name:                 XXXXXXXXXXXX
OS Name:                   Microsoft Windows 10 Enterprise
OS Version:                10.0.19044 N/A Build 19044
OS Manufacturer:           Microsoft Corporation
OS Configuration:          Member Workstation
OS Build Type:             Multiprocessor Free
Registered Owner:          N/A
Registered Organization:   N/A
Product ID:                XXXXXXXXXXXX
Original Install Date:     8/4/2022, 2:51:28 PM
System Boot Time:          8/10/2022, 1:03:10 PM
System Manufacturer:       Google
System Model:              Google Compute Engine
System Type:               x64-based PC
Processor(s):              1 Processor(s) Installed.
                           [01]: AMD64 Family 23 Model 49 Stepping 0 AuthenticAMD ~2250 Mhz
BIOS Version:              Google Google, 6/29/2022
Windows Directory:         C:\\Windows
System Directory:          C:\\Windows\\system32
Boot Device:               \\Device\\HarddiskVolume2
System Locale:             en-us;English (United States)
Input Locale:              en-us;English (United States)
Time Zone:                 (UTC-08:00) Pacific Time (US & Canada)
Total Physical Memory:     32,764 MB
Available Physical Memory: 17,852 MB
Virtual Memory: Max Size:  33,788 MB
Virtual Memory: Available: 18,063 MB
Virtual Memory: In Use:    15,725 MB
Page File Location(s):     C:\\pagefile.sys
Domain:                    ad.corp.google.com
Logon Server:              \\CBF-DC-8
Hotfix(s):                 7 Hotfix(s) Installed.
                           [01]: KB5013624
                           [02]: KB5003791
                           [03]: KB5012170
                           [04]: KB5016616
                           [05]: KB5014032
                           [06]: KB5014671
                           [07]: KB5015895
Hyper-V Requirements:      A hypervisor has been detected. Features required for Hyper-V will not be displayed.

Each line will be parsed by the windows version validator by filtering for the line that is relevant. Actual results for systeminfo could result in different returns from what is shown in the above snippet.

@eliasyishak
Copy link
Contributor Author

cc @Jasguerrero

version = null;
}

ValidationType windowsVersionStatus = ValidationType.missing;
Copy link
Contributor

Choose a reason for hiding this comment

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

This can be final and set it to ValidationType.missing on the else

bool versionText = false;
bool versionSemver = false;
String? version;
for (int i = 0; i < systemInfoElements.length; i++) {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: you can iterate directly over the systemInfoElements (as well as the lineElements) and avoid using .elementAt

for (final String curLine in systemInfoElements) {...}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

nice, i meant to actually refactor this to use that notation

@eliasyishak eliasyishak self-assigned this Aug 22, 2022
@jonahwilliams jonahwilliams self-requested a review August 23, 2022 17:07
@eliasyishak eliasyishak reopened this Aug 23, 2022
@@ -50,7 +50,7 @@ class WindowsVersionValidator extends DoctorValidator {
// semantic versioned strings
// (ie. 10.5.4123)
final RegExp regex =
RegExp(r'\n(OS Version:\s*)([0-9]+\.[0-9]+\.[0-9]+)(.*)\n');
RegExp(r'\n?(OS Version:\s*)([0-9]+\.[0-9]+\.[0-9]+)(.*)\n?');
Copy link
Contributor

Choose a reason for hiding this comment

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

Does adding the question mark not make this also match 'BIOS Version: ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't believe so, the question mark should be only looking for 0 or 1 newline characters before OS. Unless I had the wrong assumption there?

I added the question mark incase there was no new line character before the OS Version line on print out

Copy link
Contributor

Choose a reason for hiding this comment

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

So in "BIOS Version:" won't there be 0 newline characters before "OS"?

Copy link
Contributor

Choose a reason for hiding this comment

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

whether i'm right or wrong, this should be test cases in the unit tests :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see what you mean now, I'm going to try a refactor with multiLine enabled so that I can specify the start of the line as a reference point

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll build some test cases with multiline enabled when i get back. thanks for the review! 😁

@zanderso zanderso marked this pull request as ready for review August 28, 2022 15:15
@zanderso
Copy link
Member

Oops. I fatfingered the ready for review button on mobile, but there's no way in the mobile UI to change back to draft...

@jonahwilliams jonahwilliams marked this pull request as draft August 28, 2022 15:26
@jonahwilliams
Copy link
Member

Switch to desktop view 😁

@eliasyishak eliasyishak closed this Sep 6, 2022
@eliasyishak eliasyishak reopened this Sep 6, 2022
@eliasyishak eliasyishak marked this pull request as ready for review September 7, 2022 17:29
Comment on lines 28 to 31
static Iterable<RegExpMatch> validateString(String pattern, String str,
{bool multiLine = true}) {
final RegExp regex = RegExp(
pattern,
Copy link
Member

Choose a reason for hiding this comment

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

I don't really think this helper method is carrying its weight. First, I would move the regex string to a top level and document there what it is intended to match. Then you can replace it with regex.allMaches(contents)

Copy link
Member

Choose a reason for hiding this comment

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

Oh, I think from reading @christopherfujino's comment, the idea was to embed the version matching pattern in this method to make it easy to test.

From reading the test cases, I think it would work OK without this as a public method. But if you're not going to specifically test it you should drop this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, Chris mentioned that it would be helpful to make this regex helper a method that we can unit test independently, so that we can feed it test strings as we start to encounter newer versions of the stdout from systeminfo.

Copy link
Member

Choose a reason for hiding this comment

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

You're basically not testing this method, though, because this method itself is trivial. I would just test the regex itself

Copy link
Contributor

Choose a reason for hiding this comment

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

I was thinking that this helper method would also include lines 58-61 and return a boolean. Also the rather than passing the pattern (which is actually what you want to test), that the function would receive resultStdout.

Then your test can look (something) like:

test('validateVersionString() correctly validates the output of `systeminfo`', () {
  bool result = validateVersionString('123');
  expect(result, isFalse);
  result = validateVersionString('OS Version:   8.0.0');
  // Too old
  expect(result, isFalse);
  result = validateVersionString('OS Version:     11.1.2');
  expect(result, isTrue);
});

Copy link
Member

Choose a reason for hiding this comment

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

I think this approach is fine too, its the middle ground that isn't very useful

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I do agree with @jonahwilliams that the static method was very trivial but @christopherfujino what your test looks like is essentially what the entire validator was built to check.

I shied away from creating a regex method that returned a boolean because I didn't want to assume that there would only be one match within the stdout. The conditionals beginning on line 60 were added to ensure that the matches only returned 1 result AND that the major version was valid.

Copy link
Contributor

Choose a reason for hiding this comment

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

ok, makes sense, i'm fine with you removing this function

Copy link
Member

@jonahwilliams jonahwilliams left a comment

Choose a reason for hiding this comment

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

LGTM

@eliasyishak eliasyishak added the autosubmit Merge PR when tree becomes green via auto submit App label Sep 8, 2022
@auto-submit auto-submit bot merged commit 66c306b into flutter:master Sep 8, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Sep 8, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/plugins that referenced this pull request Sep 8, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Sep 8, 2022
@eliasyishak eliasyishak deleted the windows-version-check-in-doctor branch September 8, 2022 16:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
autosubmit Merge PR when tree becomes green via auto submit App tool Affects the "flutter" command-line tool. See also t: labels.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants