fix: handle User extension test when invoking user has no groups (#339)#359
Conversation
|
I raised the PR, please review it and if any issues or want me to change anything or in case of any errors just let me know , I'll see it |
tfoote
left a comment
There was a problem hiding this comment.
This looks like a potential solution. I haven't looked too deep at the technical solution yet as I think this should be extended structurally first.
I don't see a change in the code that correlates with the test changes. We should fix the issue for users not just the tests. And instead of just adding conditional logic in the tests we should mock the case to check that both paths through the code work, and not just the one present on the host system for the tests.
Thanks for the feedback ! I got it Is that what you want me to do, |
|
Hi @tfoote , thanks for the feedback and I've updated the PR 1-Production code fix (src/rocker/extensions.py) : In User.get_snippet(), the auto-discovery path (when user_preserve_groups=[]) now explicitly handles the case where the user has no supplementary groups. The one-liner was split for clarity and an informational message is printed when no groups are found, making the no-groups path visible rather than silently producing an empty string. 2-Mocked tests (test/test_extension.py): Replaced all host-dependent conditional assertions with unittest.mock.patch on rocker.extensions.grp.getgrall. The test now deterministically covers both code paths regardless of the host system's user configuration. This ensures the tests no longer depend on the host user's actual group memberships and both paths are always exercised. Plz let me know if you'd like any further changes! |
|
Hey @tfoote |
tfoote
left a comment
There was a problem hiding this comment.
Thanks for the iteration this looks better with the fix for the usage and then good coverage on the tests.
You're right that codecov@v4 had an issue submitting from forks using OIDC that was fixed so I bumped it up to v6 and the upload worked.
|
Thank you @tfoote for the guidance in solving the issue. |
Fixes #339
Description of Changes:
The
test_user_extensionunit test previously failed for host users who are not explicitly members of any supplementary groups. The test was unconditionally asserting the presence of theusermod -aGcommand in the generated snippet, whichrockercorrectly omits when there are no groups to add.This PR introduces a dynamic check using the
grpmodule to fetch the invoking user's actual group memberships. Conditional logic was added so that the test only expectsusermod -aGanduser-preserve-group-permissive Enabledin the snippet if the user actually belongs to secondary groups. If the user has no supplementary groups, it properly assertsFalse.Testing Performed:
Ran
pytest test/test_extension.pylocally to verify that the tests now pass cleanly in environments where the host user lacks secondary group memberships.