Skip to content

Add generic plugin test runner script#10963

Merged
ehelms merged 1 commit into
theforeman:developfrom
ehelms:add-plugin-test-script
Jul 20, 2026
Merged

Add generic plugin test runner script#10963
ehelms merged 1 commit into
theforeman:developfrom
ehelms:add-plugin-test-script

Conversation

@ehelms

@ehelms ehelms commented Apr 27, 2026

Copy link
Copy Markdown
Member

Plugins like Katello and foreman_puppet have their own wrapper scripts or Rakefile customizations to make it easier to run individual test files without manually switching to the Foreman directory and setting up cross-project load paths. This script generalizes that pattern for all plugins.

Supports running from the Foreman checkout, a plugin checkout, or anywhere on PATH with automatic Foreman/plugin discovery. Single-file runs use direct ruby invocation for faster feedback; full-suite runs delegate to the plugin's existing rake tasks.

I am submitting this as a replacement for ktest to be available for any plugin, and support different paths of usage. And instead of this living inside our development deployment tooling, to live as a script in the main repository and thus allow it's usage from more places.

In the use case of foremanctl, the development deployer would copy the script to the users local bin directory to make it broadly available within the environment.

@adamruzicka

Copy link
Copy Markdown
Contributor

Every now and then, I need to run an ad-hoc plugin rake task (usually foreman_theme_satellite:validate_docs), could this be extended to be able to run arbitrary rake tasks or would that be out of scope?

@ehelms

ehelms commented Apr 27, 2026

Copy link
Copy Markdown
Member Author

Every now and then, I need to run an ad-hoc plugin rake task (usually foreman_theme_satellite:validate_docs), could this be extended to be able to run arbitrary rake tasks or would that be out of scope?

I think that's fair. Do you think we can count on the pattern always including : to differentiate rake tasks from test files? Or do you think it will need an option like --rake ?

@adamruzicka

Copy link
Copy Markdown
Contributor

Or do you think it will need an option like --rake ?

I'd prefer this to also cover cases like string extraction where the plugin-name-prefix is not there (it is plugin:gettext[$plugin])

@ehelms
ehelms force-pushed the add-plugin-test-script branch from 7717fdf to 00ebd76 Compare April 27, 2026 14:23
Comment thread script/plugin-test Outdated
Comment thread script/plugin-test Outdated
Comment thread script/plugin-test Outdated
Comment thread script/plugin-test Outdated
Comment thread script/plugin-test Outdated
Comment thread script/foreman-plugin-test Outdated
@ehelms

ehelms commented Jun 2, 2026

Copy link
Copy Markdown
Member Author

@adamruzicka updated from your feedback

@adamruzicka adamruzicka left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

One last comment, otherwise lgtm

Comment thread script/foreman-plugin-test Outdated
adamruzicka
adamruzicka previously approved these changes Jun 4, 2026

@adamruzicka adamruzicka left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This looks good, please squash the commits

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

Adds a generic, repository-provided wrapper script to run Foreman plugin tests/rake tasks from various working directories by auto-discovering the Foreman checkout and (optionally) the plugin location.

Changes:

  • Introduces script/foreman-plugin-test bash script for running plugin test suites, single test files, or arbitrary rake tasks.
  • Implements Foreman/plugin discovery logic (Foreman checkout, plugin checkout, PATH usage, direct plugin paths).
  • Uses direct bundle exec ruby for single-file runs and delegates full-suite runs to bundle exec rake test:<plugin>.

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

Comment thread script/foreman-plugin-test Outdated
Comment thread script/foreman-plugin-test
Comment thread script/foreman-plugin-test Outdated
@ehelms
ehelms force-pushed the add-plugin-test-script branch from 8c31ed8 to 24151fa Compare July 14, 2026 01:39
@ehelms

ehelms commented Jul 14, 2026

Copy link
Copy Markdown
Member Author

Green again -- @jeremylenz you might want to look at this and tell me what you think

@jeremylenz jeremylenz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks! Looks like an awesome replacement for ktest.

Comment thread script/foreman-plugin-test Outdated
Comment thread script/foreman-plugin-test Outdated
Comment thread script/foreman-plugin-test Outdated
@jeremylenz

Copy link
Copy Markdown
Contributor

This will be awesome for LLMs because there will be one way to run Ruby tests across the entire ecosystem. Is there a companion foremanctl PR for adding the script to bin?

@ianballou ianballou left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I haven't tested it, but from a ktest functionality standpoint I'm happy with this PR. The biggest different is the sequential run of tests, which we can revisit in case speed is a concern.

@ehelms
ehelms force-pushed the add-plugin-test-script branch from 24151fa to 4aadd2d Compare July 16, 2026 14:59
@ehelms

ehelms commented Jul 16, 2026

Copy link
Copy Markdown
Member Author

@jeremylenz Updated based on your feedback

@jeremylenz jeremylenz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It doesn't seem to be working right for me.

  1. I seem to get all the output in one shot (after a long wait), rather than being able to follow along
  2. I don't see the error you added:
$ script/foreman-test test/unit/foreman/renderer/scope/macros/host_template_test.rb --name "foo"
WARNING:  SET CONSTRAINTS can only be used in transaction blocks
Emptying /home/vagrant/foreman/jenkins/reports/unit
-- execute("SET CONSTRAINTS ALL DEFERRED;")
   -> 0.0011s

# Running tests with run options --name foo --seed 50466:

Writing XML reports to /home/vagrant/foreman/jenkins/reports/unit


Finished tests in 0.004709s, 0.0000 tests/s, 0.0000 assertions/s.


0 tests, 0 assertions, 0 failures, 0 errors, 0 skips

Plugins like Katello and foreman_puppet have their own wrapper scripts
or Rakefile customizations to make it easier to run individual test
files without manually switching to the Foreman directory and setting
up cross-project load paths. This script generalizes that pattern for
all plugins.

Supports running from the Foreman checkout, a plugin checkout, or
anywhere on PATH with automatic Foreman/plugin discovery. Single-file
runs use direct ruby invocation for faster feedback; full-suite runs
delegate to the plugin's existing rake tasks.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@ehelms
ehelms force-pushed the add-plugin-test-script branch from 4aadd2d to 542b530 Compare July 17, 2026 19:52
@ehelms

ehelms commented Jul 17, 2026

Copy link
Copy Markdown
Member Author
  • I seem to get all the output in one shot (after a long wait), rather than being able to follow along

That is due to having implemented ". May be worth fixing in the script by detecting the "0 tests" case and returning a non-zero exit / warning." But I think that's not a great path and am switching it back to streaming output.

@jeremylenz jeremylenz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM 👍 streams test output again.

@ehelms
ehelms merged commit f1751b7 into theforeman:develop Jul 20, 2026
35 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.

5 participants