Add JSON output method for doctor#22448
Conversation
MikeMcQuaid
left a comment
There was a problem hiding this comment.
Great idea but I think this needs a lot of work before we can merge. We need to actually provide structured output from all diagnostics rather than relying on regexes.
There was a problem hiding this comment.
Pull request overview
This PR adds JSON output support to brew doctor, making diagnostic results easier for scripts and tools to consume.
Changes:
- Adds a
--jsonswitch tobrew doctor. - Builds and prints a JSON object containing a support tier and findings.
- Adds the generated Sorbet RBI predicate and a basic command spec.
Reviewed changes
Copilot reviewed 2 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
Library/Homebrew/cmd/doctor.rb |
Adds JSON output generation for doctor diagnostics. |
Library/Homebrew/sorbet/rbi/dsl/homebrew/cmd/doctor.rbi |
Adds the json? argument predicate. |
Library/Homebrew/test/cmd/doctor_spec.rb |
Adds a basic spec for brew doctor --json. |
Files not reviewed (1)
- Library/Homebrew/sorbet/rbi/dsl/homebrew/cmd/doctor.rbi: Language not supported
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Fair enough, I'd suggest a structure like this:
That we can then turn into a string or json object in the output. |
|
@SMillerDev yeh something like that sounds good. Also may want to have things like: affected formulae/casks, relevant URL(s). |
|
Adjusted to include that |
|
@SMillerDev looks good except we need to return the structured data from diagnostics rather than using regex on their string output. |
|
Yeah, fully planning to do that. Just wanted to work out a structure here before I get on reshaping all audit check output 😅 |
81d5b7e to
3bbaf15
Compare
|
JSON output: {
"tier": 1,
"findings": [
{
"title": "Deprecated or disabled formulae",
"issue": "Some installed formulae are deprecated or disabled.",
"tier": 1,
"affects": [
"php@7.2",
"mysql@8.0"
],
"links": [],
"remediation": {
"commands": [],
"text": "You should find replacements for the following formulae:\nmysql@8.0\n php@7.2\n"
}
}
]
} |
3bbaf15 to
bb17f35
Compare
MikeMcQuaid
left a comment
There was a problem hiding this comment.
Thanks, this is looking good! Will take another look when 🟢 and comments addressed. Happy to discuss more before addressing.
e94087a to
2324ef7
Compare
a816ce5 to
800b5e2
Compare
aa5857b to
ed7767d
Compare
309e62a to
4c60d4e
Compare
|
I think this is ready for review again, now with a split out Findings class. |
MikeMcQuaid
left a comment
There was a problem hiding this comment.
Thanks! Looking better. I think I'd have more confidence to give a ✅ and have us merge this if we can split into two PRs:
-
mostly this PR: make
--jsonoptionhidden:, make it mostly a no-op, add Finding class, port maybe one method in each file to use a Finding (or just a single one or even zero), add all theto_stest changes that should be a no-op etc. -
make all the
*/diagnostic.rbchanges so we can review those more closely line-by-line, unhide--json, will actually change behaviour for users.
c7ec868 to
a11c1e0
Compare
a11c1e0 to
823007f
Compare
377b846 to
39b875e
Compare
|
Okay, split it into two pull requests and made 2 methods a finding in this PR. |
MikeMcQuaid
left a comment
There was a problem hiding this comment.
Thanks, couple of last tiny things.
|
|
||
| sig { returns(T.nilable(String)) } | ||
| def self.issues_url | ||
| OS::ISSUES_URL if defined?(OS::ISSUES_URL) |
There was a problem hiding this comment.
Again: why is this better than just a defined?(OS::ISSUES_URL) check? We're literally doing that in method just above.
There was a problem hiding this comment.
I misunderstood the question then. I don't think it's better, I just need the url. Not just the check.
There was a problem hiding this comment.
Cool, just inline OS::ISSUES_URL if defined?(OS::ISSUES_URL) instead of adding this IMO
| next if out.blank? | ||
| finding = checks.public_send(method) | ||
| method_findings = T.let(Array(finding).compact, T::Array[T.any(Diagnostic::Finding, String)]) | ||
|
|
|
|
||
| sig { params(formula: ::Formula).returns(T.nilable(String)) } | ||
| def check_flat_namespace(formula) | ||
| # See https://developer.apple.com/forums/thread/689991?answerId=687895022#687895022 |
There was a problem hiding this comment.
So that's where that went. That's meant to be a separate pull request, ignore it
| def mismatch_warning_message(mismatch) | ||
| <<~EOS | ||
| You have pkgconf installed that was built on macOS #{mismatch[0]}, | ||
| You have pkgconf installed that was built on macOS #{mismatch[0]}, |
Co-authored-by: Mike McQuaid <mike@mikemcquaid.com>
Add an option to output the
brew doctorresults in easily parseable JSON output.brew lgtm(style, typechecking and tests) with your changes locally?