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

Fix merge integration test #3552

Merged
merged 8 commits into from
Oct 28, 2024
Merged

Fix merge integration test #3552

merged 8 commits into from
Oct 28, 2024

Conversation

MDrakos
Copy link
Member

@MDrakos MDrakos commented Oct 21, 2024

BugDX-3115 Nightly failure: TestPullIntegrationTestSuite/TestMergeBuildScript

@github-actions github-actions bot changed the base branch from master to version/0-47-0-RC1 October 21, 2024 21:42
@MDrakos MDrakos marked this pull request as ready for review October 21, 2024 21:46
if err := script.UnmarshalBuildExpression(resp.Commit.Expression); err != nil {
return nil, errs.Wrap(err, "failed to parse build expression")
}
script.SetAtTime(time.Time(resp.Commit.AtTime))
Copy link
Member Author

Choose a reason for hiding this comment

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

This update is to follow the same structure as here: https://github.com/ActiveState/cli/blob/master/pkg/platform/model/buildplanner/build.go#L113

It appears we want to the buildscript at_time to be the commit at_time even if the buildscript has it's own time set.

@MDrakos MDrakos requested a review from Naatan October 21, 2024 22:31
Copy link
Member

@Naatan Naatan left a comment

Choose a reason for hiding this comment

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

I think we should fix this issue closer to the root. The issue here is that UnmarshalBuildExpression is apparently overriding the AtTime. We should fix that.

We might still be setting at time in the raw representation, we should move that out of raw and just set it on the buildscript struct itself. Raw effectively represents the build expression, which does not contain the at time at all.

@mitchell-as
Copy link
Contributor

There was a time before we had "$at_time" in build expressions. In those days, it was a timestamp. When we find a timestamp, we should be using it, not overriding it with a later atTime. I don't agree with the latest change, but maybe I'm missing something.

@MDrakos
Copy link
Member Author

MDrakos commented Oct 22, 2024

As per our discussion at stand the at_time value being a timestamp in the buildexpression is a legacy use case that will be only be on old commits.

This change ensures that the at_time in the build script will always be the commit at_time and we disregard the at_time we find in the solve node.

@MDrakos MDrakos requested a review from Naatan October 22, 2024 18:02
Copy link
Member

@Naatan Naatan left a comment

Choose a reason for hiding this comment

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

Reading the code now, I realize that this should just be an update to our testing code. The reason the test was failing is we were essentially testing how we want things to work with new buildscripts, but it was failing cause it was dealing with an old builscript. The solution with old buildscripts was appropriate: Take the at_time value, and record it on the buildscript level. Next time the user commits either it is bumped or at the very least it will be recorded on the commit level.

So sorry for going back on what we discussed during stand; but I think the fix here ought to be no code changes to anything but the integration test. And the integration test fix in theory would just be to bump the time stamp on the commit that it starts from for the comparison (ie. so it uses a build expression without the at time value hardcoded on it).

@MDrakos
Copy link
Member Author

MDrakos commented Oct 24, 2024

From our discussion the following points are how we want to handle the at_time value along with how this solution should address them.

  • We respect the hardcoded at_time value
    • This is done via storing the at_time found in the solve node separately from the preferred time value.
    • We return the commit at_time if that was set externally, otherwise we default to the solve at time.
    • When we unmarshall the build expression the solve at_time could either be a time stamp or a reference.
  • BUT; any future commits we make transfer it to the commit level and use a variable instead
    • This is already handled by our current implementation
    • The buildscript library updates the at_time in the solve node to be a reference if it finds a timestamp there.
    • When we make a commit we supply the at_time as part of the input parameters which sets the commit's at_time
  • If at_time is already used as a variable then we don't do anything special other than respect the commit at time and not touch the build expression value
    • This is done by updating the SetAtTime() and AtTime() methods to work with the preferred (commit) atTime and not the one found in the solve node if set.
    • SetAtTime() is currently being called when we unmarshall the buildexpression from a commit response which sets the atTime value to the commit at time.
  • I as a developer shouldn't need to think about this when using the buildscript library externally
    • Since SetAtTime() is working with a separate value than the solve node external callers of the library can be assured that calling SetAtTime() with a time value will be preserved and returned when calling AtTime()

@MDrakos MDrakos requested a review from Naatan October 24, 2024 18:34
Copy link
Member

@Naatan Naatan left a comment

Choose a reason for hiding this comment

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

I don't think this is meeting the criteria:

  • We respect the hardcoded at_time value

Because we are always returning atTime when it is set. Which will always be the case. I think you are not seeing this in your tests because you are likely still setting atTime before unmarshalling.

Essentially the following test should pass (pseudo code):

func TestLegacyAtTime(t *testing.T) {
  bs := newBuildScript()
  err := bs.UnmarshalBuildExpression(bexp)
  require.NoError(t, err)
  err := bs.SetAtTime(bogusValue)
  require.ErrorAs(err, ErrAtTimeAlreadySet)
  require.Equal(t, bs.AtTime(), buildExpressionAtTime)
}

So that would be asserting that the build expression atTime is preserved and overrides the commit atTime.

The error check on SetAtTime is just an in-the-moment solution to the problem of "I as a developer do not need special knowledge". Because when working with legacy atTime values it straight up isn't appropriate to override the at time with that of the commit. I think erroring out in this case is ok, because then at least the failure will be obvious to the developer and they can then handle it better (eg. ignore that type of error and move on).

@MDrakos
Copy link
Member Author

MDrakos commented Oct 25, 2024

@Naatan You're right I misinterpreted that point. I didn't realize we want to retain the solve node's atTime. Going through the code there appears to be some cases where we want to override the atTime like when we pass the --ts flag or when merging. I've added the ability to specify overriding the time value but we may want to go with a different pattern.

@MDrakos MDrakos requested a review from Naatan October 25, 2024 18:34
@@ -114,6 +114,7 @@ func (i *Install) Run(params Params) (rerr error) {
var oldCommit *bpModel.Commit
var reqs requirements
var ts time.Time
var override bool
Copy link
Member

Choose a reason for hiding this comment

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

I think for the install action we always want to override.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah okay, so anytime we make a change we want to update the timestamp? I was under the impression that we want to preserve the timestamp in the solve node and I was only bumping it when the user explicitly passed the --ts flag.

Copy link
Member

Choose a reason for hiding this comment

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

We only want to preserve it when we retrieve the commit. Once we're acting on the buildscript (ie. making changes) the existing timestamp should always be overwritten.

internal/runners/platforms/add.go Outdated Show resolved Hide resolved
internal/runners/upgrade/upgrade.go Outdated Show resolved Hide resolved
pkg/buildscript/buildscript.go Show resolved Hide resolved
@MDrakos MDrakos requested a review from Naatan October 28, 2024 20:28
@MDrakos MDrakos merged commit 7aa9e61 into version/0-47-0-RC1 Oct 28, 2024
7 of 8 checks passed
@MDrakos MDrakos deleted the DX-3115 branch October 28, 2024 21:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants