Skip to content

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

Merged
SasSwart merged 7 commits into
mainfrom
16930
Apr 16, 2025
Merged

fix: set preset parameters in the API rather than the frontend#17403
SasSwart merged 7 commits into
mainfrom
16930

Conversation

@SasSwart
Copy link
Copy Markdown
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.

Comment thread coderd/workspaces_test.go Outdated
Comment thread coderd/workspaces_test.go Outdated
Comment thread coderd/workspaces_test.go Outdated
Comment thread coderd/wsbuilder/wsbuilder_test.go Outdated

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
Copy Markdown
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?

Comment thread coderd/workspaces_test.go Outdated
Comment thread coderd/workspaces_test.go Outdated
Comment thread coderd/workspaces_test.go Outdated
Comment thread coderd/workspaces_test.go Outdated
Comment thread coderd/workspaces_test.go Outdated
Comment thread coderd/workspaces_test.go
name: "Single Preset - No Preset Parameters But With Template Parameters",
presets: []*proto.Preset{emptyPreset},
templateVersionParameters: templateVersionParameters,
selectedPresetIndex: ptr.Ref(0),
Copy link
Copy Markdown
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,

Comment thread coderd/workspaces_test.go Outdated
presets: []*proto.Preset{},
templateVersionParameters: []*proto.RichParameter{},
selectedPresetIndex: -1,
templateVersionParameters: templateVersionParameters,
Copy link
Copy Markdown
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
Copy Markdown
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 👍

Comment thread coderd/workspaces_test.go

// Test Utility variables
templateVersionParameters := []*proto.RichParameter{
{Name: "param1", Type: "string", Required: false},
Copy link
Copy Markdown
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
Copy Markdown
Contributor

Please update the referenced PR in the description

@SasSwart SasSwart merged commit 64172d3 into main Apr 16, 2025
@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