Skip to content

Conversation

@therazix
Copy link
Contributor

@therazix therazix commented Dec 2, 2025

This PR extracts some shared behavior (repository fetching, installation of libraries, and application of policies) from individual discover plugins to their parent Discover plugin. The discover step now has control over these individual actions and can, for example, choose when exactly to perform repository fetching and other actions. It also makes some behavior consistent between the two discover plugins. The discover/shell plugin now gains the url-content-type key, which works the same way as in the discover/fmf plugin. Remote repository fetching is now unified for both plugins.

Resolves #4348

Pull Request Checklist

  • implement the feature
  • write the documentation
  • extend the test coverage
  • update the specification
  • adjust plugin docstring
  • modify the json schema
  • mention the version
  • include a release note

@therazix therazix added this to the 1.63 milestone Dec 2, 2025
@therazix therazix added this to planning Dec 2, 2025
@therazix therazix added step | discover Stuff related to the discover step plugin | fmf The fmf discover plugin plugin | shell The shell discover plugin labels Dec 2, 2025
@github-project-automation github-project-automation bot moved this to backlog in planning Dec 2, 2025
@therazix therazix added the area | maintenance Changes important for efficiency and the long-term health of the project label Dec 2, 2025
@therazix therazix moved this from backlog to implement in planning Dec 2, 2025
@therazix therazix added the ci | full test Pull request is ready for the full test execution label Dec 2, 2025
@therazix therazix force-pushed the fvagner-discover-refactor branch from 00fdab0 to 8a53658 Compare December 2, 2025 08:58
@therazix therazix moved this from implement to review in planning Dec 2, 2025
@therazix therazix force-pushed the fvagner-discover-refactor branch 3 times, most recently from ff65754 to c4afbf3 Compare December 2, 2025 12:05
@tcornell-bus tcornell-bus self-requested a review December 2, 2025 19:55
@therazix therazix force-pushed the fvagner-discover-refactor branch from c4afbf3 to c026f69 Compare December 3, 2025 08:46
@LecrisUT LecrisUT self-assigned this Dec 3, 2025
@psss psss modified the milestones: 1.63, 1.64 Dec 4, 2025
@therazix therazix moved this from review to implement in planning Dec 5, 2025
@therazix therazix force-pushed the fvagner-discover-refactor branch 3 times, most recently from 30d793b to 4f5a2d6 Compare December 10, 2025 01:47
@LecrisUT LecrisUT assigned psss and tcornell-bus and unassigned psss Dec 10, 2025
@happz happz self-requested a review December 10, 2025 08:53
@thrix
Copy link
Contributor

thrix commented Jan 8, 2026

/packit retest-failed

@psss psss modified the milestones: 1.64, 1.65 Jan 8, 2026
@therazix therazix force-pushed the fvagner-discover-refactor branch from 90f026b to 9a5fdaf Compare January 9, 2026 15:09
@thrix
Copy link
Contributor

thrix commented Jan 12, 2026

@therazix looks good, I just found one thing via Claude Code Opus 4.5 to review. Can you check on it please?

Bug: Incorrect keep-git-metadata validation when using remote URL in discover/shell

Summary

The refactoring introduced a regression where the keep-git-metadata validation incorrectly runs when cloning a remote URL. The validation checks the local repository structure (git_root vs fmf_root), which is irrelevant when cloning a remote repository.

Location

tmt/steps/discover/shell.py:331-341

Original Behavior (main branch)

The validation only ran when no URL was provided (local repository case):

def go(self, ...):
    if self.data.url:
        # Clone remote repo - NO validation about local git structure
        self.fetch_remote_repository(self.data.url, self.data.ref, testdir, keep_git_metadata)
    else:
        # Local repo only:
        if keep_git_metadata:
            if git_root != tree_root:
                raise DiscoverError("The 'keep-git-metadata' option can be "
                                    "used only when fmf root is the same as git root.")
            self.run(Command("rsync", ...))

New Behavior (this PR)

The validation now runs regardless of whether a URL is provided:

def go(self, ...):
    # Runs ALWAYS, even when URL is used
    if keep_git_metadata:
        if self.step.plan.fmf_root:
            git_root = tmt.utils.git.git_root(
                fmf_root=self.step.plan.fmf_root, logger=self._logger
            )
            if git_root and git_root != self.step.plan.fmf_root:
                raise DiscoverError(...)  # BUG: also triggers when URL is used!
    else:
        shutil.rmtree(self.test_dir / '.git', ignore_errors=True)

Reproduction Scenario

Local repo structure:
  /home/user/myrepo/           <- git root
  /home/user/myrepo/tests/     <- fmf root (different from git root)

Plan at /home/user/myrepo/tests/plan.fmf:
discover:
    how: shell
    url: https://github.com/teemtee/fmf
    keep-git-metadata: true
    tests:
    - name: test
      test: test -e .git

Expected: Clone remote repo successfully, keep its .git directory

Actual: Error: The 'keep-git-metadata' option can be used only when fmf root is the same as git root.

The error incorrectly refers to the local repo structure, which should be irrelevant when cloning a remote URL.

Why CI Passes

The existing test /url/keep runs git init at the data directory level, making git_root == fmf_root, so the spurious validation doesn't trigger.

Suggested Fix

Remove the duplicated/incorrect validation from go() since _fetch_local_repository() already handles the local repo case correctly:

def go(self, ...):
    keep_git_metadata = True if self.data.dist_git_source else self.data.keep_git_metadata

    if not keep_git_metadata:
        # Remove .git so that it's not copied to the SUT
        shutil.rmtree(self.test_dir / '.git', ignore_errors=True)
    # Remove the validation block - already handled in _fetch_local_repository()

Or, if the validation must remain in go() for some reason, guard it with a URL check:

if keep_git_metadata and not self.data.url:
    # Validation only applies to local repos
    if self.step.plan.fmf_root:
        git_root = tmt.utils.git.git_root(...)
        if git_root and git_root != self.step.plan.fmf_root:
            raise DiscoverError(...)
else:
    if not keep_git_metadata:
        shutil.rmtree(self.test_dir / '.git', ignore_errors=True)

@therazix therazix force-pushed the fvagner-discover-refactor branch 2 times, most recently from fa6a6dc to b83cd5a Compare January 12, 2026 10:55
@therazix
Copy link
Contributor Author

therazix commented Jan 12, 2026

@therazix looks good, I just found one thing via Claude Code Opus 4.5 to review. Can you check on it please?

Nice catch, thanks! I completely missed the duplicate validation. It should be fixed in 562eaa0.

@therazix therazix force-pushed the fvagner-discover-refactor branch from 5b03d27 to 6b5508b Compare January 13, 2026 10:16
@therazix therazix force-pushed the fvagner-discover-refactor branch from 6b5508b to 562eaa0 Compare January 13, 2026 10:17
@thrix
Copy link
Contributor

thrix commented Jan 13, 2026

@therazix looks good, I just found one thing via Claude Code Opus 4.5 to review. Can you check on it please?

Nice catch, thanks! I completely missed the duplicate validation. It should be fixed in 562eaa0.

Ty, can we also add tests?

  1. Add test plan in tests/discover/libraries/data/plan.fmf

  /shell:
      summary: "Library installation with shell discover plugin"
      discover:
          how: shell
          tests:
            - name: /certificate-shell
              test: ./certificate.sh
              require:
                - library(openssl/certgen)

  2. Add test phase in tests/discover/libraries/test.sh

  Add this phase before the cleanup:

  rlPhaseStartTest "Shell discover plugin installs libraries"
      rlRun -s "$tmt shell"
      rlAssertGrep "Fetch library 'openssl/certgen'" $rlRun_LOG
  rlPhaseEnd

@thrix thrix requested review from happz and thrix January 13, 2026 10:41
Copy link
Contributor

@thrix thrix left a comment

Choose a reason for hiding this comment

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

LGTM after adding tests.

@LecrisUT
Copy link
Contributor

Ty, can we also add tests?

  1. Add test plan in tests/discover/libraries/data/plan.fmf

  /shell:
      summary: "Library installation with shell discover plugin"
      discover:
          how: shell
          tests:
            - name: /certificate-shell
              test: ./certificate.sh
              require:
                - library(openssl/certgen)

Would prefer to keep it similar to file.sh that is already there. It seems that that would require changes on #4427 also because I had an assumption in there which I should be able to relax, but we would need more coverage in /tests/libarires

@LecrisUT
Copy link
Contributor

@therazix do you have a tracker for unifying the rest of these options? I don't see why keep_git_metadata should be only in shell or why the dist_git_* are only in fmf. There is still a lot of other discrepancy that we need to deal with, but just tracking these discrepancies would be helpful.

@thrix
Copy link
Contributor

thrix commented Jan 13, 2026

@therazix do you have a tracker for unifying the rest of these options? I don't see why keep_git_metadata should be only in shell or why the dist_git_* are only in fmf. There is still a lot of other discrepancy that we need to deal with, but just tracking these discrepancies would be helpful.

In that case I would keep it for the next release with an issue

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

Labels

area | maintenance Changes important for efficiency and the long-term health of the project ci | full test Pull request is ready for the full test execution plugin | fmf The fmf discover plugin plugin | shell The shell discover plugin step | discover Stuff related to the discover step

Projects

Status: review

Development

Successfully merging this pull request may close these issues.

Refactor discover plugins

7 participants