Skip to content

fix: set preset parameters in the API rather than the frontend #17403

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

Merged
merged 7 commits into from
Apr 16, 2025
Merged

Conversation

SasSwart
Copy link
Contributor

@SasSwart SasSwart commented Apr 15, 2025

Follow-up from a previous Pull Request required some additional testing of Presets from the API perspective.

In the process of adding the new tests, I updated the API to enforce preset parameter values based on the selected preset instead of trusting whichever frontend makes the request. This avoids errors scenarios in prebuilds where a prebuild might expect a certain preset but find a different set of actual parameter values.

@@ -960,6 +961,12 @@ func withInactiveVersion(params []database.TemplateVersionParameter) func(mTx *d
}
}

func withTemplateVersionPreset(presetID uuid.UUID) func(mTx *dbmock.MockStore) {
return func(mTx *dbmock.MockStore) {
mTx.EXPECT().GetPresetParametersByPresetID(gomock.Any(), presetID).Return(nil, nil)
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't understand the value of returning nil, nil here; this won't execute your new codepath in findNewBuildParameterValue. Can you help me understand pls?

name: "Single Preset - No Preset Parameters But With Template Parameters",
presets: []*proto.Preset{emptyPreset},
templateVersionParameters: templateVersionParameters,
selectedPresetIndex: ptr.Ref(0),
Copy link
Contributor

Choose a reason for hiding this comment

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

What about instead just doing something like this?

Suggested change
selectedPresetIndex: ptr.Ref(0),
selectedPreset: &emptyPreset,

presets: []*proto.Preset{},
templateVersionParameters: []*proto.RichParameter{},
selectedPresetIndex: -1,
templateVersionParameters: templateVersionParameters,
Copy link
Contributor

Choose a reason for hiding this comment

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

Implementation doesn't seem to match the name

Copy link
Contributor

@dannykopping dannykopping left a comment

Choose a reason for hiding this comment

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

Tests read much better now, thanks 👍


// Test Utility variables
templateVersionParameters := []*proto.RichParameter{
{Name: "param1", Type: "string", Required: false},
Copy link
Contributor

Choose a reason for hiding this comment

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

Only testing with unrequired params might introduce interesting blindspots, no?

@SasSwart SasSwart marked this pull request as ready for review April 16, 2025 12:33
@dannykopping
Copy link
Contributor

Please update the referenced PR in the description

@SasSwart SasSwart merged commit 64172d3 into main Apr 16, 2025
36 checks passed
@SasSwart SasSwart deleted the 16930 branch April 16, 2025 13:54
@github-actions github-actions bot locked and limited conversation to collaborators Apr 16, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants