Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test_landings: increase git landing coverage (bug 1934485) #190

Merged
merged 18 commits into from
Jan 17, 2025

Conversation

shtrom
Copy link
Member

@shtrom shtrom commented Jan 6, 2025

  • upgrade landings tests to work with both Hg and Git repos
  • fix a few simple bugs in the Git implementation

@shtrom shtrom force-pushed the bug1934485/landing-test-coverage branch from aea01be to 8411436 Compare January 10, 2025 03:57
@shtrom shtrom force-pushed the bug1934485/landing-test-coverage branch from 8411436 to 15c0d4e Compare January 10, 2025 04:03
@shtrom shtrom force-pushed the bug1934485/landing-test-coverage branch from 15c0d4e to 18e9068 Compare January 10, 2025 04:07
@shtrom shtrom requested review from cgsheeh and zzzeid January 10, 2025 04:10
@shtrom shtrom force-pushed the bug1934485/landing-test-coverage branch from 18e9068 to 2588f72 Compare January 10, 2025 04:46
Comment on lines 832 to 835
def _scm_get_previous_hash(scm: AbstractSCM) -> str:
if scm.scm_type() == SCM_TYPE_HG:
return HgSCM.run_hg(scm, ["log", "-r", "tip^", "-T", "{node}"]).decode("utf-8")
return GitSCM._git_run("rev-parse", "HEAD^", cwd=scm.path)
Copy link
Member

Choose a reason for hiding this comment

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

We should have an AbstractSCM.get_previous_hash instead of this function which checks for the specific implementation.

Copy link
Collaborator

Choose a reason for hiding this comment

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

If these are only used in tests, I would hesitate to put them directly in the main implementation, but maybe they can be added in a mixin or a test class that extends AbstractSCM. Again, depends if they are only used in tests.

Copy link
Member Author

Choose a reason for hiding this comment

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

I had the same thought as @zzzeid here. Same for the other one that gets the whole commit message.

Both are only used in tests at the moment.

Copy link
Member

Choose a reason for hiding this comment

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

I don't think it's an issue that it's a function only used in tests, worst case we could add a comment pointing that out in the docstring. This way it seems like we are going against the purpose of the AbstractSCM. I'm not too fussed about it either way though, happy to go with whatever you decide.

Comment on lines 909 to 912
def _scm_get_last_commit_message(scm: AbstractSCM) -> str:
if scm.scm_type() == SCM_TYPE_HG:
return HgSCM.run_hg(scm, ["log", "-r", "tip", "-T", "{desc}"]).decode("utf-8")
return GitSCM._git_run("log", "--pretty=%B", "HEAD^..", cwd=scm.path)
Copy link
Member

Choose a reason for hiding this comment

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

Same as above, these methods should go on the AbstractSCM and the implementations.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Same comment here as in _scm_get_previous_hash -- i.e., maybe those should be added to a mixin or test class.

zzzeid
zzzeid previously requested changes Jan 10, 2025
Comment on lines 832 to 835
def _scm_get_previous_hash(scm: AbstractSCM) -> str:
if scm.scm_type() == SCM_TYPE_HG:
return HgSCM.run_hg(scm, ["log", "-r", "tip^", "-T", "{node}"]).decode("utf-8")
return GitSCM._git_run("rev-parse", "HEAD^", cwd=scm.path)
Copy link
Collaborator

Choose a reason for hiding this comment

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

If these are only used in tests, I would hesitate to put them directly in the main implementation, but maybe they can be added in a mixin or a test class that extends AbstractSCM. Again, depends if they are only used in tests.

Comment on lines +253 to +254
if "nothing to commit, working tree clean" in exc.out:
return []
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is there a more rigorous way of doing this check? Is there a specific error code we could be checking when raising SCMException? Looking at your implementation of _git_run, looks like we are raising this exception specifically based on a return code, and perhaps we shouldn't be raising this as an exception at all from the get go.

Copy link
Member Author

Choose a reason for hiding this comment

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

The initial implementation had a conditional to allow throwing an exception or not, but I realised at the time that we always were throwing an exception, so I removed the parameter.

We could re-add it, but I can't find documentation about git commit's error codes (at the moment it return 1 for this case), so we'd still have to inspect the error message to determine the cause of the error (FWIW, this is also how we do it for Mercurial) https://github.com/mozilla-conduit/lando/blob/main/src/lando/main/scm/hg.py#L372-L377

@shtrom shtrom requested a review from zzzeid January 13, 2025 00:49
@shtrom shtrom dismissed stale reviews from zzzeid and cgsheeh January 13, 2025 00:49

Updated mc_repo factory, fixed nits.

@shtrom shtrom requested a review from cgsheeh January 13, 2025 00:50
@shtrom
Copy link
Member Author

shtrom commented Jan 13, 2025

Hum. The tests in GitHub fail https://github.com/mozilla-conduit/lando/pull/190/checks#step:6:390. They were fine on last week, and still pass locally. Something's odd with GHActions, I think.

@shtrom
Copy link
Member Author

shtrom commented Jan 15, 2025

@zzzeid @cgsheeh test pass with the fix to test_hg. This should be good for one last look.

Comment on lines 832 to 835
def _scm_get_previous_hash(scm: AbstractSCM) -> str:
if scm.scm_type() == SCM_TYPE_HG:
return HgSCM.run_hg(scm, ["log", "-r", "tip^", "-T", "{node}"]).decode("utf-8")
return GitSCM._git_run("rev-parse", "HEAD^", cwd=scm.path)
Copy link
Member

Choose a reason for hiding this comment

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

I don't think it's an issue that it's a function only used in tests, worst case we could add a comment pointing that out in the docstring. This way it seems like we are going against the purpose of the AbstractSCM. I'm not too fussed about it either way though, happy to go with whatever you decide.

zzzeid
zzzeid previously requested changes Jan 16, 2025
Copy link
Collaborator

@zzzeid zzzeid left a comment

Choose a reason for hiding this comment

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

nit: in first line of commit message: test -> test_landings.

@shtrom shtrom changed the title test: increase git landing coverage (bug 1934485) test_landings: increase git landing coverage (bug 1934485) Jan 17, 2025
@shtrom shtrom merged commit d780a9e into main Jan 17, 2025
1 check passed
@shtrom shtrom deleted the bug1934485/landing-test-coverage branch January 17, 2025 01:26
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.

3 participants