Skip to content

pam/integration-tests: Avoid downloading chromium on each test run#1040

Merged
adombeck merged 2 commits intomainfrom
vhs-cache-browser
Sep 1, 2025
Merged

pam/integration-tests: Avoid downloading chromium on each test run#1040
adombeck merged 2 commits intomainfrom
vhs-cache-browser

Conversation

@adombeck
Copy link
Contributor

@adombeck adombeck commented Aug 25, 2025

The $HOME environment variable wasn't set in the environment which the vhs command runs in, resulting in chromium being downloaded to .cache/rod in the current working directory, which is a temporary directory. In effect, chromium was being downloaded each time a test using vhs was executed, which made the test take ~1m longer.

UDENG-7819

@adombeck adombeck marked this pull request as ready for review August 25, 2025 15:08
@adombeck adombeck requested a review from a team as a code owner August 25, 2025 15:08
@adombeck adombeck requested a review from 3v1n0 August 25, 2025 15:08

// vhs uses rod, which downloads chromium to $HOME/.cache/rod,
// so $HOME needs to be set to avoid that it downloads it every time.
cmd.Env = append(cmd.Env, fmt.Sprintf("HOME=%s", os.Getenv("HOME")))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@3v1n0 do you see any reason why we shouldn't just pass the whole os.Environ to the vhs command here?

Copy link
Contributor

Choose a reason for hiding this comment

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

I would prefer to control what VHS sees and ideally I'd prefer not to be potentially interfered by the developers HOME, and so to shared here. So wondering, can we just set the XDG_CACHE_HOME to make rod use it?

Copy link
Contributor

Choose a reason for hiding this comment

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

BTW likely this can be confined to the cases in which: we're in CI, and no chromium or google-chrome[-unstable] is in PATH, no?

Copy link
Contributor

Choose a reason for hiding this comment

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

Another option is to just set HOME for vhs itself, but then set it to some test path for the tests themselves

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The directory used by rod is: filepath.Join(os.Getenv("HOME"), ".cache", "rod", "browser")

https://github.com/go-rod/rod/blob/393ac0d60b53f3c4a9b2a6504d250cbada55b546/lib/launcher/browser.go#L73

So we could set $HOME to some temporary directory, but that could have unexpected side effects. IMO we should just keep the environment variables from the go test environment. Or is vhs more prone to interference by the developer's home directory than everything else we do in the tests (where we don't unset the environment)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, I see. In the SSH tests we already set HOME to a temporary directory in tapeData.Env: https://github.com/ubuntu/authd/blob/0609f97a414c0b9fe366f4342e91a89d6bcf347c/pam/integration-tests/ssh_test.go#L464-L464

That means that the commands executed by the tape won't see the HOME variable we're setting for vhs anyway, right? Should I add a commit which always sets td.Env["HOME"] = t.TempDir() in RunVhs?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, I've fixed it there in go-rod/rod#1213

I added a TODO comment to set XDG_CACHE_HOME instead of HOME once that PR was merged

Copy link
Contributor

Choose a reason for hiding this comment

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

That means that the commands executed by the tape won't see the HOME variable we're setting for vhs anyway, right?

Yeah, that is fine, my point was: maybe we can just do it for all the tests now (also CLI and Native) and drop it the specific case in ssh 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.

my point was: maybe we can just do it for all the tests now (also CLI and Native) and drop it the specific case in ssh tests?

that's what I meant with "Should I add a commit which always sets td.Env["HOME"] = t.TempDir() in RunVhs"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@codecov-commenter
Copy link

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.10%. Comparing base (b3a6cc9) to head (5ee79e3).
⚠️ Report is 13 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1040      +/-   ##
==========================================
- Coverage   88.11%   88.10%   -0.02%     
==========================================
  Files          85       85              
  Lines        6026     6026              
  Branches      111      111              
==========================================
- Hits         5310     5309       -1     
- Misses        660      661       +1     
  Partials       56       56              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@adombeck
Copy link
Contributor Author

@3v1n0 anything missing here?

The $HOME environment variable wasn't set in the environment which the
vhs command runs in, resulting in chromium being downloaded to
`.cache/rod` in the current working directory, which is a temporary
directory. In effect, chromium was being downloaded each time a test
using vhs was executed, which made the test take ~1m longer.
@adombeck adombeck merged commit 0da1cf8 into main Sep 1, 2025
9 of 13 checks passed
@adombeck adombeck deleted the vhs-cache-browser branch September 1, 2025 12:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants