Skip to content

Add integration test covering multiple package managers#911

Merged
slimreaper35 merged 3 commits intohermetoproject:mainfrom
slimreaper35:integration-tests
May 16, 2025
Merged

Add integration test covering multiple package managers#911
slimreaper35 merged 3 commits intohermetoproject:mainfrom
slimreaper35:integration-tests

Conversation

@slimreaper35
Copy link
Copy Markdown
Member

@slimreaper35 slimreaper35 commented Apr 24, 2025

Closes #857

Maintainers will complete the following section

  • Commit messages are descriptive enough
  • Code coverage from testing does not decrease and new code is covered
  • Docs updated (if applicable)
  • Docs links in the code are still valid (if docs were updated)

Note: If the contribution is external (not from an organization member), the CI
pipeline will not run automatically. After verifying that the CI is safe to run:

Copy link
Copy Markdown
Contributor

@a-ovchinnikov a-ovchinnikov left a comment

Choose a reason for hiding this comment

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

LGTM with two small questions

Comment thread tests/integration/test_multiple.py Outdated
Comment thread tests/integration/utils.py Outdated
@slimreaper35 slimreaper35 force-pushed the integration-tests branch 2 times, most recently from 19a9815 to 7aac0ee Compare April 29, 2025 10:45
@slimreaper35 slimreaper35 requested a review from eskultety April 29, 2025 11:18
@slimreaper35 slimreaper35 force-pushed the integration-tests branch 2 times, most recently from d786286 to a2ac795 Compare April 29, 2025 16:29
Comment thread tests/integration/utils.py
Comment thread tests/integration/utils.py Outdated
Copy link
Copy Markdown
Member

@eskultety eskultety left a comment

Choose a reason for hiding this comment

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

The test data and test case are fine but I can't say I'm a fan of how the utils code was bent to consider multiple in the test skipping logic.

Comment thread tests/integration/test_data/multiple_gomod_and_npm/container/Containerfile Outdated
Comment thread tests/integration/utils.py Outdated

def affects_pm_tests(change: Path) -> bool:
return tested_object_name(change) in SUPPORTED_PMS
return tested_object_name(change) in SUPPORTED_PMS or change.stem.endswith("multiple")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm afraid this and putting multiple to the EXTRA set is logically wrong and very confusing when looked at. If we merge this, while the underlying problem is only tangential to this PR, we'll forget about it and probably never address the real issue.
I think our main problem that f2e1314#r2069407087 touched in context of this PR is that we're trying to produce a set of tests to skip rather than a set of tests to run and then inverting the logic in pytest_collection_modifyitems, i.e. gather the set of tests to run and add the skip marker on the rest. It all boils down to
just_some_package_managers_were_affected_by which should IMO be refactored/dissected because the current design revolving around finding the affected set of package managers clearly doesn't suffice our needs. The code may end up being longer in the end, but arguably it could be more readable and less confusing when looked at. See below for a rough pseudocode snippet. If we adopt something similar, we don't need to fiddle with 'multiple' in this fairly opaque manner, IOW what's proposed in this PR pretty much just bends the code to comply with an existing design instead of amending/reworking the design itself if it lacks in any aspect.

#conftest.py
def pytest_collection_modifyitems(..., items: list):
  ...
  run_set = utils.determine_integration_tests_to_run(items)
  for item in items:
    # this is just a minor modification of the existing logic
    if utils.tested_object_name(item.path) in run_set:
      continue
    item.add_marker(skip_mark)

#utils.py
....
GLOBAL_TEST_IMPACT = (Path('Dockerfile'), Path('requirements.txt'), etc.)
LOCAL_TEST_IMPACT = namedtuple(Path('hermeto'), Path('tests/integration'))
PATHS_TO_CODE = frozenset(GLOBAL_TEST_IMPACT + LOCALT_TEST_IMPACT)
....
def determine_integration_tests_to_run(fullset: list):
  ret = set()
  changes = select_testable_changes()

  if must_test_all() or <changes in GLOBAL_TEST_IMPACT>:
    return fullset

  if len(changes) == 0:
    return ret

  if <changes in LOCAL_TEST_IMPACT.tests>:
    test_changes = [test for test in changes if test.name.startswith('test_')]
    if not test_changes:
      # global test impact change detected, e.g. utils.py or conftest.py
      return fullset
   
   # add specific test names directly to the set, this is a deliberate redundancy with what happens next
   ret.update(test_changes)

  # continue adding affected packages managers
  if <changes in LOCAL_TEST_IMPACT.hermeto>:
    ret.update(affected_package_managers(changes)

  return ret

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

we're trying to produce a set of tests to skip rather than a set of tests to run and then inverting the logic in pytest_collection_modifyitems

Heartily agree that this is not The Way

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Dropped this part in favor of #950

@slimreaper35
Copy link
Copy Markdown
Member Author

The test data and test case are fine but I can't say I'm a fan of how the utils code was bent to consider multiple in the test skipping logic.

Me neither, I would leave the adjustments in the utils code to you and @a-ovchinnikov as he has the best context around it. He also mentioned privately, that he would consider dropping the logic completely.

@a-ovchinnikov
Copy link
Copy Markdown
Contributor

a-ovchinnikov commented May 7, 2025

...mentioned ... he would consider dropping the logic completely

In this PR as well (see my comment above). Rewriting the rules to be less arcane than they appear now would also work. I am not entirely sure this is in the scope of the change though, maybe a follow-up issue would be a better place for that? Edit: formatting

@eskultety
Copy link
Copy Markdown
Member

eskultety commented May 7, 2025

...mentioned ... he would consider dropping the logic completely

In this PR as well (see my comment above). Rewriting the rules to be less arcane than they appear now would also work. I am not entirely sure this is in the scope of the change though, maybe a follow-up issue would be a better place for that? Edit: formatting

I mean, we'd be deliberately merging a misbehaving code, yeah, in tests, but that shouldn't be a justification factor really if the logic is off. I don't mind tracking and tackling the problem in a different PR, but then this PR would have to wait and rebase to merge clean changes, i.e. just the test. It's not like this work is urgent or anything, effort has been invested, work has been done, we can just wait for some related polishing to happen first.

@eskultety
Copy link
Copy Markdown
Member

Alternatively, we can incorporate the suggestion from #911 (comment) to eliminate the problem at hand and then we can tackle the refactoring or reverting the test filtering logic completely.

@slimreaper35 slimreaper35 force-pushed the integration-tests branch 2 times, most recently from c8f38fc to f35fa5d Compare May 9, 2025 13:18
Comment thread tests/integration/utils.py
@slimreaper35 slimreaper35 force-pushed the integration-tests branch 2 times, most recently from 4853a8e to 64bbdb8 Compare May 12, 2025 16:00
The flags have been deprecated in earlier versions of Hermeto and have
no effect [1].

---
[1]: https://github.com/hermetoproject/hermeto/blob/main/docs/gomod.md#deprecated-flags

Signed-off-by: Michal Šoltis <msoltis@redhat.com>
Signed-off-by: Michal Šoltis <msoltis@redhat.com>
Test branch:
https://github.com/hermetoproject/integration-tests/tree/multiple/gomod-and-npm

Verify Hermeto can handle projects with multiple package types in a
single request. The new test case includes Go modules, NPM packages, and
RPM dependencies to validate cross-language dependency resolution.

Include container build verification that blocks network access during
execution to confirm hermetic behavior.

Closes hermetoproject#857

Signed-off-by: Michal Šoltis <msoltis@redhat.com>
@slimreaper35 slimreaper35 added this pull request to the merge queue May 16, 2025
Merged via the queue into hermetoproject:main with commit 245fa4b May 16, 2025
16 checks passed
@slimreaper35 slimreaper35 deleted the integration-tests branch May 16, 2025 19:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Integration tests covering multiple package managers at once are missing

4 participants