Skip to content

fix: host-runner compatibility for tests and scripts#19712

Merged
davdhacs merged 4 commits intomasterfrom
davdhacs/host-runner-test-fixes
Apr 2, 2026
Merged

fix: host-runner compatibility for tests and scripts#19712
davdhacs merged 4 commits intomasterfrom
davdhacs/host-runner-test-fixes

Conversation

@davdhacs
Copy link
Copy Markdown
Contributor

@davdhacs davdhacs commented Mar 31, 2026

Description

Fix tests and scripts to work on ubuntu-latest host runners (no container) in addition to CI container environments. All changes are backward-compatible — CI still passes in containers.

This is a prerequisite for removing containers from unit-test jobs (#19678).

Changes

File Issue Fix
rate_limited_logger.go Log path prefix /home/runner/work/ not recognized (container used /__w/) Add host runner prefix
download_zip_test.go os.Stat("/root/evil.txt") returns ErrPermission on non-root (container ran as root) Accept ErrNotExist or ErrPermission
detection_test.go Not a valid test if GHA runs without a container. Delete (path change based on isContainer, covered by local-roxctl bats tests)
lib.sh bash 5.2+ treats & in ${var//pat/repl} as matched pattern (container had bash 5.1) Escape with \& (works on all versions 4.4-5.3, verified via docker)
helpers.bash yq 4.52 adds --- separators in multi-doc output (container had yq 4.16) Add yq_multidoc helper that strips separators
*-netpol-generate-*.bats Line index assertions broken by yq separators Use yq_multidoc

Verification

These changes run in the existing CI container workflow (no workflow changes in this PR). If all tests pass, the fixes are proven backward-compatible.

Testing and quality

  • CI results inspected

Automated testing

  • modified existing tests

How I validated my change

CI runs:
A: in the existing rox-ci-image container, proving backward compatibility.
B: without a container, passing on #19678

Partially generated by AI.

Fix tests and scripts to work on ubuntu-latest host runners (no
container) in addition to CI container environments.

- rate_limited_logger.go: add /home/runner/work/ path prefix
  (container used /__w/)
- download_zip_test.go: accept ErrPermission for /root/ paths
  (non-root runner returns permission denied, not not-found)
- detection_test.go: delete circular test
- lib.sh: escape & in bash 5.2+ replacements (verified 4.4-5.3)
- helpers.bash: add yq_multidoc helper (yq 4.x adds --- separators)
- roxctl-netpol-generate-*.bats: use yq_multidoc

All changes are backward-compatible with container environments.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@openshift-ci
Copy link
Copy Markdown

openshift-ci bot commented Mar 31, 2026

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey - I've left some high level feedback:

  • The new yq_multidoc helper blindly strips any line equal to ---, which could hide legitimate content in future YAML outputs; consider making the filtering more targeted (e.g., only when multi-doc mode is expected or using yq flags/options to control separators instead of post-processing).
  • The hard-coded githubHostPrefix = "/home/runner/work/stackrox/stackrox/" in rate_limited_logger.go is tightly coupled to the current GitHub runner layout; it may be more robust to derive the prefix from GITHUB_WORKSPACE or to trim dynamically based on the repo path instead of specific absolute paths.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The new `yq_multidoc` helper blindly strips any line equal to `---`, which could hide legitimate content in future YAML outputs; consider making the filtering more targeted (e.g., only when multi-doc mode is expected or using yq flags/options to control separators instead of post-processing).
- The hard-coded `githubHostPrefix = "/home/runner/work/stackrox/stackrox/"` in `rate_limited_logger.go` is tightly coupled to the current GitHub runner layout; it may be more robust to derive the prefix from `GITHUB_WORKSPACE` or to trim dynamically based on the repo path instead of specific absolute paths.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 31, 2026

📝 Walkthrough

Walkthrough

The pull request removes a container detection test, updates test error handling, adds a path prefix to file path trimming logic, fixes XML-escaping in CI output generation, introduces a YAML processing helper function, and updates BATS tests to use the new helper for multi-document YAML validation.

Changes

Cohort / File(s) Summary
Test Removal and Cleanup
pkg/containers/detection_test.go
Removed TestContainerDetection test that conditionally validated container detection based on the GITHUB_ACTIONS environment variable.
Error Handling in Tests
roxctl/common/zipdownload/download_zip_test.go
Updated path traversal test to accept both fs.ErrNotExist and fs.ErrPermission errors as evidence of successful traversal prevention, accommodating runner permission restrictions.
Logging and Path Trimming
pkg/logging/rate_limited_logger.go
Extended getTrimmedFilePath to include /home/runner/work/stackrox/stackrox/ path prefix for improved file path normalization in log suppression key generation.
CI Output and Build Tools
scripts/ci/lib.sh
Fixed XML-escaping logic in _save_junit_record() to correctly handle ampersand, quote, apostrophe, and angle bracket escaping in JUnit testcase descriptions using bash parameter substitution syntax.
YAML Processing Utilities
tests/roxctl/bats-tests/helpers.bash
Added new yq_multidoc() bash helper function that executes yq commands and filters out standalone document separator lines (---).
BATS Network Policy Tests
tests/roxctl/bats-tests/local/roxctl-netpol-generate-development.bats, tests/roxctl/bats-tests/local/roxctl-netpol-generate-release.bats
Replaced all yq/yq e invocations with yq_multidoc in YAML assertions for multi-document validation, including kind extraction, label checking, and port specification queries. Removed duplicate commented-out assertions.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 75.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main objective: making tests and scripts compatible with host runners while maintaining backward compatibility.
Description check ✅ Passed The PR description is well-structured with clear explanations of all changes, their rationale, verification approach, and backward compatibility assurance.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch davdhacs/host-runner-test-fixes

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@rhacs-bot
Copy link
Copy Markdown
Contributor

rhacs-bot commented Mar 31, 2026

Images are ready for the commit at 58ea483.

To use with deploy scripts, first export MAIN_IMAGE_TAG=4.11.x-528-g58ea4834ab.

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 31, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 49.59%. Comparing base (2837c9b) to head (58ea483).
⚠️ Report is 20 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #19712      +/-   ##
==========================================
- Coverage   49.59%   49.59%   -0.01%     
==========================================
  Files        2756     2756              
  Lines      208036   208036              
==========================================
- Hits       103183   103180       -3     
- Misses      97192    97196       +4     
+ Partials     7661     7660       -1     
Flag Coverage Δ
go-unit-tests 49.59% <100.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

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

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@davdhacs davdhacs marked this pull request as ready for review April 1, 2026 13:18
@davdhacs davdhacs requested a review from a team as a code owner April 1, 2026 13:18
Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey - I've found 1 issue, and left some high level feedback:

  • In getTrimmedFilePath, instead of hardcoding the /home/runner/work/stackrox/stackrox/ host-runner prefix, consider deriving the workspace prefix from an environment variable (e.g. GITHUB_WORKSPACE) or making it configurable so the logic is robust to path changes and non-GHA environments.
  • The new yq_multidoc helper will cause grep -v '^---$' to exit non‑zero when the only output lines are ---, which will fail the caller even though yq succeeded; consider tolerating an empty filtered output (e.g. grep -v '^---$' <<< "$output" || true) or handling this case explicitly.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `getTrimmedFilePath`, instead of hardcoding the `/home/runner/work/stackrox/stackrox/` host-runner prefix, consider deriving the workspace prefix from an environment variable (e.g. `GITHUB_WORKSPACE`) or making it configurable so the logic is robust to path changes and non-GHA environments.
- The new `yq_multidoc` helper will cause `grep -v '^---$'` to exit non‑zero when the only output lines are `---`, which will fail the caller even though `yq` succeeded; consider tolerating an empty filtered output (e.g. `grep -v '^---$' <<< "$output" || true`) or handling this case explicitly.

## Individual Comments

### Comment 1
<location path="tests/roxctl/bats-tests/helpers.bash" line_range="14-17" />
<code_context>

+# yq_multidoc runs yq and strips --- document separators from output.
+# yq 4.x adds separators between multi-doc results which shift assert_line indices.
+yq_multidoc() {
+  local output
+  output=$(yq "$@") || return $?
+  grep -v '^---$' <<< "$output"
+}
+
</code_context>
<issue_to_address>
**issue:** yq_multidoc may fail when yq outputs only '---' lines or no lines at all because grep -v will return a non‑zero exit code

This helper has an edge case: if `yq` outputs only `---` separators (or nothing), `grep -v '^---$'` exits with status 1, making it look like `yq` failed and causing spurious test failures. To avoid this, consider using `sed '/^---$/d'` instead, or appending `|| true` to the `grep` call while preserving the original `yq` exit code (e.g., capture `$?` right after `yq` and return that).
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

grep -v returns exit code 1 when no lines match (e.g. yq output is
only --- separators), which would look like a yq failure. sed always
returns 0 regardless of whether lines were deleted.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@davdhacs
Copy link
Copy Markdown
Contributor Author

davdhacs commented Apr 1, 2026

@sourcery-ai review

Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey - I've left some high level feedback:

  • In getTrimmedFilePath, the list of hard-coded GitHub path prefixes is starting to grow; consider centralizing these host/container path mappings or deriving them from an environment variable to avoid further proliferation of magic strings tied to specific CI layouts.
  • The updated assertion in TestExtractZipToFolder_PreventPathTraversal using assert.True with a compound errors.Is condition is a bit opaque; consider extracting this into a small helper (e.g. assertPathNotWritten(t, err)) or using a clearer assertion pattern to make the intent and allowed error types more obvious.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `getTrimmedFilePath`, the list of hard-coded GitHub path prefixes is starting to grow; consider centralizing these host/container path mappings or deriving them from an environment variable to avoid further proliferation of magic strings tied to specific CI layouts.
- The updated assertion in `TestExtractZipToFolder_PreventPathTraversal` using `assert.True` with a compound `errors.Is` condition is a bit opaque; consider extracting this into a small helper (e.g. `assertPathNotWritten(t, err)`) or using a clearer assertion pattern to make the intent and allowed error types more obvious.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

davdhacs added a commit that referenced this pull request Apr 1, 2026
Run Go test jobs directly on ubuntu-latest instead of in the CI
container image. This saves ~55s container init overhead per job
and enables faster cache I/O (no overlay filesystem).

Changes per job:
- Remove container: block
- Add actions/setup-go with GOTOOLCHAIN=auto override
- Replace su postgres with docker run postgres
- Add pg_isready retry loop (docker postgres needs warmup time)
- go-bench: skip on PRs (if: github.event_name == 'push')

Depends on #19712 (host-runner test fixes).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
davdhacs added a commit that referenced this pull request Apr 1, 2026
Run remaining unit-tests jobs directly on ubuntu-latest:

- ui: remove container, add setup-node
- ui-component: remove container, use cypress-io/github-action
- local-roxctl-tests: remove container, add setup-go
- shell-unit-tests: remove container, add bats-core/bats-action
- openshift-ci-unit-tests: remove container

Depends on #19712 (host-runner test fixes).
Split from #19678.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@davdhacs davdhacs requested review from janisz and mtodor April 1, 2026 19:27
@davdhacs
Copy link
Copy Markdown
Contributor Author

davdhacs commented Apr 2, 2026

/test ?

@openshift-ci
Copy link
Copy Markdown

openshift-ci bot commented Apr 2, 2026

@davdhacs: The following commands are available to trigger required jobs:

/test gke-nongroovy-e2e-tests
/test gke-ui-e2e-tests

The following commands are available to trigger optional jobs:

/test aks-qa-e2e-tests
/test aro-qa-e2e-tests
/test eks-qa-e2e-tests
/test gke-external-pg-17-qa-e2e-tests
/test gke-latest-nongroovy-e2e-tests
/test gke-latest-operator-e2e-tests
/test gke-latest-qa-e2e-tests
/test gke-latest-ui-e2e-tests
/test gke-nongroovy-compatibility-tests
/test gke-oldest-nongroovy-e2e-tests
/test gke-oldest-operator-e2e-tests
/test gke-oldest-qa-e2e-tests
/test gke-oldest-ui-e2e-tests
/test gke-operator-e2e-tests
/test gke-qa-e2e-tests
/test gke-race-condition-qa-e2e-tests
/test gke-scale-tests
/test gke-scanner-v4-install-tests
/test gke-sensor-integration-tests
/test gke-upgrade-tests
/test gke-version-compatibility-tests
/test ibmcloudz-4-14-qa-e2e-tests
/test ibmcloudz-4-15-qa-e2e-tests
/test ibmcloudz-4-16-qa-e2e-tests
/test ibmcloudz-4-17-qa-e2e-tests
/test ocp-4-12-compliance-e2e-tests
/test ocp-4-12-nongroovy-e2e-tests
/test ocp-4-12-operator-e2e-tests
/test ocp-4-12-qa-e2e-tests
/test ocp-4-12-scanner-v4-install-tests
/test ocp-4-12-sensor-integration-tests
/test ocp-4-12-ui-e2e-tests
/test ocp-4-21-compliance-e2e-tests
/test ocp-4-21-crun-qa-e2e-tests
/test ocp-4-21-fips-qa-e2e-tests
/test ocp-4-21-nongroovy-e2e-tests
/test ocp-4-21-operator-e2e-tests
/test ocp-4-21-qa-e2e-tests
/test ocp-4-21-scanner-v4-install-tests
/test ocp-4-21-sensor-integration-tests
/test ocp-4-21-ui-e2e-tests
/test ocp-dev-preview-compliance-e2e-tests
/test ocp-dev-preview-fips-qa-e2e-tests
/test ocp-dev-preview-nongroovy-e2e-tests
/test ocp-dev-preview-operator-e2e-tests
/test ocp-dev-preview-qa-e2e-tests
/test ocp-dev-preview-scanner-v4-install-tests
/test ocp-dev-preview-sensor-integration-tests
/test ocp-dev-preview-ui-e2e-tests
/test ocp-next-candidate-compliance-e2e-tests
/test ocp-next-candidate-fips-qa-e2e-tests
/test ocp-next-candidate-nongroovy-e2e-tests
/test ocp-next-candidate-operator-e2e-tests
/test ocp-next-candidate-qa-e2e-tests
/test ocp-next-candidate-scanner-v4-install-tests
/test ocp-next-candidate-sensor-integration-tests
/test ocp-next-candidate-ui-e2e-tests
/test ocp-stable-scanner-v4-install-compliance-e2e-tests
/test ocp-stable-scanner-v4-install-nongroovy-e2e-tests
/test ocp-stable-scanner-v4-install-operator-e2e-tests
/test ocp-stable-scanner-v4-install-qa-e2e-tests
/test ocp-stable-scanner-v4-install-scanner-v4-install-tests
/test ocp-stable-scanner-v4-install-sensor-integration-tests
/test ocp-stable-scanner-v4-install-ui-e2e-tests
/test osd-aws-qa-e2e-tests
/test osd-gcp-qa-e2e-tests
/test powervs-4-16-qa-corebpf-e2e-tests
/test powervs-4-17-qa-corebpf-e2e-tests
/test powervs-4-18-qa-corebpf-e2e-tests
/test powervs-4-19-qa-corebpf-e2e-tests
/test powervs-4-20-qa-corebpf-e2e-tests
/test powervs-4-21-qa-corebpf-e2e-tests
/test rosa-fips-qa-e2e-tests
/test rosa-hcp-qa-e2e-tests
/test rosa-qa-e2e-tests

Use /test all to run the following jobs that were automatically triggered:

pull-ci-stackrox-stackrox-master-gke-nongroovy-e2e-tests
pull-ci-stackrox-stackrox-master-gke-operator-e2e-tests
pull-ci-stackrox-stackrox-master-gke-qa-e2e-tests
pull-ci-stackrox-stackrox-master-gke-scanner-v4-install-tests
pull-ci-stackrox-stackrox-master-gke-ui-e2e-tests
pull-ci-stackrox-stackrox-master-gke-upgrade-tests
pull-ci-stackrox-stackrox-master-ocp-4-12-nongroovy-e2e-tests
pull-ci-stackrox-stackrox-master-ocp-4-12-operator-e2e-tests
pull-ci-stackrox-stackrox-master-ocp-4-12-qa-e2e-tests
pull-ci-stackrox-stackrox-master-ocp-4-12-scanner-v4-install-tests
pull-ci-stackrox-stackrox-master-ocp-4-21-nongroovy-e2e-tests
pull-ci-stackrox-stackrox-master-ocp-4-21-operator-e2e-tests
pull-ci-stackrox-stackrox-master-ocp-4-21-qa-e2e-tests
pull-ci-stackrox-stackrox-master-ocp-4-21-scanner-v4-install-tests
Details

In response to this:

/test ?

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@davdhacs davdhacs merged commit 64ecebe into master Apr 2, 2026
129 of 130 checks passed
@davdhacs davdhacs deleted the davdhacs/host-runner-test-fixes branch April 2, 2026 16:13
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 2, 2026

🚀 Build Images Ready

Images are ready for commit 64ecebe. To use with deploy scripts:

export MAIN_IMAGE_TAG=4.11.x-544-g64ecebe08f

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants