Skip to content

fix: honor absolute path in --test-file flag#2689

Merged
eddycharly merged 2 commits into
kyverno:mainfrom
Ayush-Patel-56:fix/test-file-absolute-path
Apr 30, 2026
Merged

fix: honor absolute path in --test-file flag#2689
eddycharly merged 2 commits into
kyverno:mainfrom
Ayush-Patel-56:fix/test-file-absolute-path

Conversation

@Ayush-Patel-56

Copy link
Copy Markdown
Contributor

Explanation

--test-file silently ignored absolute paths - filepath.Join(testDir, absolutePath) produced a wrong path, causing chainsaw to fall through to step-file discovery instead of loading the specified file. This fix makes absolute paths work as expected.

Related issue

Fixes #2687 (case 3)

Proposed Changes

  • Added a resolve helper in tryLoadTestFiles that returns the filename as-is when it's absolute, skipping the filepath.Join with test-dir
  • Skip step-file fallback when an absolute path was given but not found
  • Added a test covering the absolute path case

Checklist

  • I have read the contributing guidelines.
  • I have read the PR documentation guide and followed the process including adding proof manifests to this PR.
  • This is a bug fix and I have added unit tests that prove my fix is effective.

Further Comments

Cases 1 and 2 from the issue (silent fallback when an explicit relative filename doesn't exist) involve the KUTTL-compat step-discovery behavior - left those for maintainer input before touching.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Fixes --test-file handling so absolute paths are honored during discovery/loading, preventing incorrect filepath.Join(testDir, absPath) behavior and avoiding unintended fallback to step-file discovery.

Changes:

  • Add path resolution in tryLoadTestFiles to use absolute --test-file values as-is.
  • Prevent step-file discovery fallback when an explicitly-provided absolute test file path is not found.
  • Add a unit test covering absolute --test-file behavior (found + missing).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
pkg/discovery/load.go Resolves absolute test-file paths correctly and disables step discovery fallback for missing absolute paths.
pkg/discovery/load_test.go Adds coverage for loading an absolute test file and ensuring missing absolute paths don’t fall through to step discovery.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@codecov

codecov Bot commented Apr 21, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 67.00%. Comparing base (6be08eb) to head (a318cf7).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2689      +/-   ##
==========================================
+ Coverage   66.97%   67.00%   +0.03%     
==========================================
  Files         149      149              
  Lines        5704     5710       +6     
==========================================
+ Hits         3820     3826       +6     
  Misses       1624     1624              
  Partials      260      260              

☔ 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.

@Ayush-Patel-56
Ayush-Patel-56 force-pushed the fix/test-file-absolute-path branch from 3256875 to 9a783f0 Compare April 29, 2026 13:44
@Ayush-Patel-56
Ayush-Patel-56 force-pushed the fix/test-file-absolute-path branch from 9a783f0 to 0d2086f Compare April 30, 2026 07:54
@eddycharly eddycharly added this to the v0.2.15 milestone Apr 30, 2026
@eddycharly
eddycharly enabled auto-merge (squash) April 30, 2026 11:14
@eddycharly
eddycharly merged commit ce303d5 into kyverno:main Apr 30, 2026
15 of 16 checks passed
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.

[Bug] chainsaw test issues with certain flags

4 participants