Bug 220925 - [webkit-patch] Allow user to opt out of browser for viewing the diff
Summary: [webkit-patch] Allow user to opt out of browser for viewing the diff
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Tools / Tests (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nobody
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2021-01-25 07:35 PST by Angelos Oikonomopoulos
Modified: 2022-03-01 01:51 PST (History)
10 users (show)

See Also:


Attachments
Patch (1.35 KB, patch)
2021-01-25 07:39 PST, Angelos Oikonomopoulos
no flags Details | Formatted Diff | Diff
Patch (1.63 KB, patch)
2021-01-26 05:01 PST, Angelos Oikonomopoulos
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Angelos Oikonomopoulos 2021-01-25 07:35:58 PST
[webkit-patch] Allow user to opt out of browser for viewing the diff
Comment 1 Angelos Oikonomopoulos 2021-01-25 07:39:03 PST
Created attachment 418293 [details]
Patch
Comment 2 Jonathan Bedard 2021-01-25 08:51:23 PST
Comment on attachment 418293 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=418293&action=review

> Tools/Scripts/webkitpy/common/system/user.py:175
> +            return False

Not against this in principle...is the rationale that the user does not want to see the diff (even though they have a browser) or that the user does not have a browser installed? If it's the latter, what does this function actually do?
Comment 3 Angelos Oikonomopoulos 2021-01-25 11:42:47 PST
(In reply to Jonathan Bedard from comment #2)
> Comment on attachment 418293 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=418293&action=review
> 
> > Tools/Scripts/webkitpy/common/system/user.py:175
> > +            return False
> 
> Not against this in principle...is the rationale that the user does not want
> to see the diff (even though they have a browser) or that the user does not
> have a browser installed? If it's the latter, what does this function
> actually do?

The motivating use case is that the user does want to see the diff, except not in a browser. This may be the case when they're connected over ssh to a remote box that has a text-mode browser installed for other reasons, but the diff is not really viewable in the text-mode browser.
Comment 4 Sam Weinig 2021-01-25 12:54:13 PST
Comment on attachment 418293 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=418293&action=review

> Tools/Scripts/webkitpy/common/system/user.py:174
> +        if os.environ.get("WEBKIT_PATCH_NO_BROWSER"):

This seems reasonably, but I think we would want this to have also be configurable via an argument and documented in the help text, as an environment variable is not very discoverable.
Comment 5 Alexey Proskuryakov 2021-01-25 13:56:20 PST
> The motivating use case is that the user does want to see the diff, except
> not in a browser. This may be the case when they're connected over ssh to a
> remote box that has a text-mode browser installed for other reasons, but the
> diff is not really viewable in the text-mode browser.

Is there a way to detect this automatically? There probably is one on macOS at least, although I'm do not know how exactly. The design of this function is that webbrowser.get() raises an exception when it's not available, so this is probably where the check for WEBKIT_PATCH_NO_BROWSER needs to go, if there is no automatic solution.

What is the failure behavior that you are currently observing?
Comment 6 Angelos Oikonomopoulos 2021-01-25 14:17:16 PST
(In reply to Alexey Proskuryakov from comment #5)
> > The motivating use case is that the user does want to see the diff, except
> > not in a browser. This may be the case when they're connected over ssh to a
> > remote box that has a text-mode browser installed for other reasons, but the
> > diff is not really viewable in the text-mode browser.
> 
> Is there a way to detect this automatically?

I'm not sure what 'this' refers to here.

> There probably is one on macOS
> at least, although I'm do not know how exactly. The design of this function
> is that webbrowser.get() raises an exception when it's not available, so
> this is probably where the check for WEBKIT_PATCH_NO_BROWSER needs to go, if
> there is no automatic solution.

Not sure if I understand correctly; the reason I placed the check at the top of the function was to do what the name of the variable does, i.e. not use a browser regardless of if one is available or not. I should add that this also helps in the case where the user doesn't want to hunt for the new diff tab in their open browser windows but would rather see the diff "synchronously", i.e. in the terminal they're working in, in a pager.

> What is the failure behavior that you are currently observing?

The failure is that if any text-mode browser is installed on the machine that I've ssh'd in to, then running webkit-patch will show me the diff in that browser, however the diff is not readable in a text-mode browser.
Comment 7 Angelos Oikonomopoulos 2021-01-25 14:20:24 PST
(In reply to Sam Weinig from comment #4)
> Comment on attachment 418293 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=418293&action=review
> 
> > Tools/Scripts/webkitpy/common/system/user.py:174
> > +        if os.environ.get("WEBKIT_PATCH_NO_BROWSER"):
> 
> This seems reasonably, but I think we would want this to have also be
> configurable via an argument and documented in the help text, as an
> environment variable is not very discoverable.

The discoverability is a good point. TBH adding an option for this felt a little heavy-weight and mentioning the environment variable in the help text seems even less subtle. Yet I imagine in most cases the user would want to set the environment variable rather than pass in a flag for every invocation. So if we want to make this discoverable, sounds like this is the way to go.
Comment 8 Alexey Proskuryakov 2021-01-25 19:50:36 PST
> I'm not sure what 'this' refers to here.

Running in a session where the browser cannot display diffs. I imagine that it's pretty limited set of configurations that you'd need to detect.

I guess another consideration is that the function that you are patching is more generic than just diff viewing. Wouldn't this also prevent viewing test results, and do we want that?
Comment 9 Alexey Proskuryakov 2021-01-25 19:51:11 PST
To be clear, I don't feel very strongly about this.
Comment 10 Angelos Oikonomopoulos 2021-01-26 03:05:56 PST
(In reply to Alexey Proskuryakov from comment #8)
> > I'm not sure what 'this' refers to here.
> 
> Running in a session where the browser cannot display diffs. I imagine that
> it's pretty limited set of configurations that you'd need to detect.

I have no idea; also, I wonder if with some text-mode browsers the diff might be something a person can understand, but still hard to make out, in which case we'd need to make a judgement call.

> I guess another consideration is that the function that you are patching is
> more generic than just diff viewing. Wouldn't this also prevent viewing test
> results, and do we want that?

AFAICS, this patch will only affect diff viewing. can_open_url is used in exactly two places. The first when deciding how to show the diff, the other is in open_url. open_url is used in various places, but it only uses the result of can_open_url to print a warning and then proceeds to unconditionally try and open the url in a browser:

    def open_url(self, url):
        if not self.can_open_url():
            _log.warn("Failed to open %s" % url)
        webbrowser.open(url)

So I think this should be pretty safe ATM. Though perhaps I should rename the variable to WEBKIT_PATCH_PREFER_PAGER and only check it in ConfirmDiff._show_pretty_diff.
Comment 11 Angelos Oikonomopoulos 2021-01-26 05:01:49 PST
Created attachment 418397 [details]
Patch
Comment 12 Angelos Oikonomopoulos 2021-01-26 05:02:24 PST
(In reply to Angelos Oikonomopoulos from comment #10)
[...]
> So I think this should be pretty safe ATM. Though perhaps I should rename
> the variable to WEBKIT_PATCH_PREFER_PAGER and only check it in
> ConfirmDiff._show_pretty_diff.

Submitted a new patch with this change.
Comment 13 Angelos Oikonomopoulos 2021-01-26 08:06:04 PST
(In reply to Angelos Oikonomopoulos from comment #7)
> (In reply to Sam Weinig from comment #4)
> > Comment on attachment 418293 [details]
> > Patch
> > 
> > View in context:
> > https://bugs.webkit.org/attachment.cgi?id=418293&action=review
> > 
> > > Tools/Scripts/webkitpy/common/system/user.py:174
> > > +        if os.environ.get("WEBKIT_PATCH_NO_BROWSER"):
> > 
> > This seems reasonably, but I think we would want this to have also be
> > configurable via an argument and documented in the help text, as an
> > environment variable is not very discoverable.
> 
> The discoverability is a good point. TBH adding an option for this felt a
> little heavy-weight and mentioning the environment variable in the help text
> seems even less subtle. Yet I imagine in most cases the user would want to
> set the environment variable rather than pass in a flag for every
> invocation. So if we want to make this discoverable, sounds like this is the
> way to go.

Not sure how to best handle this. AFAIU adding this flag and propagating it to ConfirmDiff seems like a pretty invasive change for something this trivial. I guuess Ican look into that, but is it worth the trade off in added complexity?
Comment 14 Radar WebKit Bug Importer 2021-02-01 07:36:16 PST
<rdar://problem/73828826>
Comment 15 Angelos Oikonomopoulos 2021-02-23 02:58:20 PST
Ping.
Comment 16 Jonathan Bedard 2022-02-28 09:28:59 PST
Comment on attachment 418397 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=418397&action=review

> Tools/Scripts/webkitpy/tool/steps/confirmdiff.py:54
> +        if os.environ.get('WEBKIT_PATCH_PREFER_PAGER') or not self._tool.user.can_open_url():

r+ing this for now, but this will be more relevant in git-webkit, where we'll probably do this with a git config option.
Comment 17 EWS 2022-02-28 11:20:11 PST
Committed r290608 (247881@main): <https://commits.webkit.org/247881@main>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 418397 [details].
Comment 18 Angelos Oikonomopoulos 2022-03-01 01:51:13 PST
(In reply to Jonathan Bedard from comment #16)
> Comment on attachment 418397 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=418397&action=review
> 
> > Tools/Scripts/webkitpy/tool/steps/confirmdiff.py:54
> > +        if os.environ.get('WEBKIT_PATCH_PREFER_PAGER') or not self._tool.user.can_open_url():
> 
> r+ing this for now, but this will be more relevant in git-webkit, where
> we'll probably do this with a git config option.

I'll submit a patch as soon as I can start using git-webkit then ;-)