qgis / QGIS

QGIS is a free, open source, cross platform (lin/win/mac) geographical information system (GIS)
https://qgis.org
GNU General Public License v2.0
10.36k stars 2.98k forks source link

Unit tests create html report, but Ubuntu browsers can't open the report from ~/.tmp #58631

Open velle opened 1 week ago

velle commented 1 week ago

What is the bug or the crash?

Lets consider the test test_core_compositionconverter. Im not sure if it always creates an html report and opens in a local browser, or if that only happens when there is a failed test.

The test report is saved to this path:

 file:///home/velle/.tmp/qgis_test_report/index.html

But on Ubuntu, at least 22.04, both Firefox and Chromium are installed via snap. Even if using apt, it is still installed via snap. And snap apps are in some way is restricted in accessing local files. So Chromium and Firefox both respond with ERR_ACCESS_DENIED.

The file system permissions seem ok, by the way.

$ ll /home/velle/.tmp/qgis_test_report/index.html
-rw-rw-r-- 1 velle velle 7579 Sep 10 05:01 /home/velle/.tmp/qgis_test_report/index.html

Workaround 1

It's possible to launch Chrome (even when installed via snap), but just running it's binary, and there is no sandbox. Just start it from terminal with:

/snap/chromium/current/usr/lib/chromium-browser/chrome

Now copy and paste the URL from the sandboxed instance to the non-sandboxed instance.

Source: https://askubuntu.com/a/1286825

Workaround 2

The only way to install Chromium on Ubuntu via apt (ie not via snap) with the default repositories, is if one completely uninstalls snap. I have not tried that. And I think it has unacceptable consequences for most people.

Source: https://askubuntu.com/a/1286825, https://askubuntu.com/q/1179273

Workaround 3

Install some browser in some other way than apt/snap, e.g. from a .deb package. That browser will have to be set up as the default browser, I haven't tried that yet.

Suggested solution

It seems that all hidden (starting with a dot, e.g. .github) folders and files in $HOME are off bounds for snap applications. So if the files are simply saved to $HOME/qgis_test_tmp or similar, then there is no problem.

Other solutions?

What have everybody else done?

Steps to reproduce the issue

.

Versions

master

Supported QGIS version

New profile

Additional context

No response

velle commented 1 week ago

I just tried it out, and replaced temp() with home(), in qgsrenderchecker.cpp line 60.

# return QDir( QDir::temp().filePath( QStringLiteral( "qgis_test_report" ) ) ); 
return QDir( QDir::home().filePath( QStringLiteral( "qgis_test_report" ) ) ); 

Now results are saved in ~/qgis_test_report, and they open in Chromium without issue. But I can't tell if this will cause other issues, so I wont create a PR until someone approves of this idea/change.

nyalldawson commented 1 week ago

@velle why not make it an environment variable, so you opt it to storing the reports in a custom dir?

velle commented 1 week ago

@nyalldawson Certainly could be :)

So how would you do it then. Should the default still be temp(), and it does not change unless the user sets that env. var. himself? Or should that env. var. automatically be set to something on Ubuntu. E.g. CMake, gnumake or ctest or something could check which OS, and then set the env.var.?

nyalldawson commented 1 week ago

I think default should always be temp. It's managed by the operating system and is the "correct" place for things like this.

Someone would need to manually set the env variable to change the behaviour. We'd add notes in the developer's guide on when they should do this.

velle commented 1 week ago

I think default should always be temp. It's managed by the operating system and is the "correct" place for things like this.

Got it :) I will make a PR, today or tomorrow.

velle commented 1 week ago

I wrote the code, and now I'm working on the documentation part.

Is there a complete list of all environment variables? Is so, then I would like to add it to the list. I found this list but it's only for QGIS Server, https://docs.qgis.org/3.34/en/docs/server_manual/config.html#environment-variables.

And then I plan to add a paragraph to this article https://www.qgis.org/resources/testing/. In brief describing what is saved to this report, where it's normally saved and how to change the destination with the env.var. Does that sound ok?