Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

chore: refactor dynamic parameters into dedicated package#18420

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Emyrk merged 24 commits intomainfromstevenmasley/dynamic_param_pkg
Jun 20, 2025

Conversation

Emyrk
Copy link
Member

@EmyrkEmyrk commentedJun 17, 2025
edited
Loading

Refactor dynamic parameters into dedicated package

This PR extracts dynamic parameter rendering logic from coderd/parameters.go into a new coderd/dynamicparameters package. Partly for organization and maintainability, but primarily to be reused inwsbuilder to be leveraged as validation.

Key changes:

  • Created new dynamicparameters package to handle dynamic parameterpreview
  • Added support for both static and dynamic parameter rendering through unified interface
    • Older versions do not have the db state required for dynamic params. So it loads static params, and serves them through the same interface.
  • Added test utilities for testing dynamic parameters
    • Added more comprehensive tests for dynamic params.

The refactoring maintains backward compatibility while creating a cleaner separation of concerns for parameter handling logic. The next step is to use this logic in wsbuilder for validation purposes.

@EmyrkEmyrk changed the titleStevenmasley/dynamic param pkgchore: refactor dynamic parameters into dedicated packageJun 18, 2025
@EmyrkEmyrk marked this pull request as ready for reviewJune 18, 2025 18:42
@EmyrkEmyrkforce-pushed thestevenmasley/dynamic_param_pkg branch from37bfb5c to758cd26CompareJune 18, 2025 19:09
@EmyrkEmyrk requested a review fromSasSwartJune 18, 2025 19:20

// TestDynamicParameterTemplate uses a template with some dynamic elements, and
// tests the parameters, values, etc are all as expected.
funcTestDynamicParameterTemplate(t*testing.T) {
Copy link
MemberAuthor

Choose a reason for hiding this comment

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

This test is actually kinda dope. I like the resulting syntax

@@ -81,292 +68,49 @@ func (api *API) templateVersionDynamicParametersWebsocket(rw http.ResponseWriter
})(rw,r)
}

//nolint:revive // listen is a control flag
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is a control flag acceptable or desired here if the linter discourages it? Perhaps we should include that justification in the comment.

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

Added 👍

Copy link
Contributor

@SasSwartSasSwartJun 20, 2025
edited
Loading

Choose a reason for hiding this comment

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

I understood as much as you've described in the new comment. My question is why this needs to be a "control flag" in this way instead of being extracted from the context inside this endpoint. They're functionally equivalent as far as I can tell. I'm not saying one approach is better.

I'm asking because I'm sure the linting rule was added for a reason and//nolint can be a smell unless it's well justified.

Copy link
MemberAuthor

@EmyrkEmyrkJun 20, 2025
edited
Loading

Choose a reason for hiding this comment

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

As I read it, you are right. I could refactor this to remove the control flag now that thedynamicparameters package exists.

I'm going to keep it for now, and I'm going to make an issue to revisit this.
#18478

It is on the parameters board, so I can fix this up in my next maintenance cycle 👍

}

varprotoOptions []*sdkproto.RichParameterOption
_=json.Unmarshal(it.Options,&protoOptions)// Not going to make this fatal
Copy link
Contributor

Choose a reason for hiding this comment

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

If we're going to comment this, can we documentwhy we ignore this error, so that future contributors know when it may or may not be useful to reassess this? Is it simply because we're pretty sure this will be valid json since it comes from the DB? I'd like to avoid Chesterton's Fence.

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

Actually, I can throw this error on the parameter now as a diagnostic. I'm going to toss the error in there. 👍

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

Added it as a diagnostic on the param 👍

db612b3

@EmyrkEmyrk requested a review fromCopilotJune 20, 2025 11:45
Copy link
Contributor

@CopilotCopilotAI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors dynamic parameter rendering out ofcoderd/parameters.go into a newcoderd/dynamicparameters package, unifies static and dynamic parameter handling under a single interface, and adds test utilities and fixtures for exercising dynamic parameters.

  • Extract dynamic parameter logic intodynamicparameters package withLoader/Renderer
  • Update API handlers incoderd/parameters.go to use the new package
  • Add comprehensive tests and helpers for dynamic parameter rendering, plus a Terraform test fixture

Reviewed Changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 4 comments.

Show a summary per file
FileDescription
enterprise/coderd/testdata/parameters/dynamic/main.tfNew Terraform fixture demonstrating dynamic parameters
enterprise/coderd/parameters_test.goTests updated to useSynchronousStream helper
enterprise/coderd/dynamicparameters_test.goEnd-to-end tests for dynamic parameters via WebSocket/API
coderd/util/slice/slice.goNewConvert utility to map slices
coderd/parameters_test.goRefactored setup to use unifiedDynamicParameterTemplate
coderd/parameters.goSwitched todynamicparameters.Loader for rendering logic
coderd/dynamicparameters/static.goStatic renderer implementation for legacy parameter flow
coderd/dynamicparameters/render.goDynamic renderer andRenderer interface implementation
coderd/coderdtest/stream.goAddedSynchronousStream test helper
coderd/coderdtest/dynamicparameters.goHigh-level helper for template/dynamic parameter tests

@EmyrkEmyrk requested a review fromSasSwartJune 20, 2025 15:19
@EmyrkGraphite App
Copy link
MemberAuthor

Emyrk commentedJun 20, 2025
edited
Loading

This stack of pull requests is managed byGraphite. Learn more aboutstacking.

Copy link
Contributor

@SasSwartSasSwart left a comment

Choose a reason for hiding this comment

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

I'm new to the dynamic parameter space, but I'm pretty confident I understand how this all fits together.

Emyrk reacted with heart emoji
@EmyrkEmyrk merged commit9b5d499 intomainJun 20, 2025
35 checks passed
@EmyrkEmyrk deleted the stevenmasley/dynamic_param_pkg branchJune 20, 2025 18:00
@github-actionsgithub-actionsbot locked and limited conversation to collaboratorsJun 20, 2025
Sign up for freeto subscribe to this conversation on GitHub. Already have an account?Sign in.
Reviewers

@SasSwartSasSwartSasSwart approved these changes

Copilot code reviewCopilotCopilot left review comments

Assignees

@EmyrkEmyrk

Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

2 participants
@Emyrk@SasSwart

[8]ページ先頭

©2009-2025 Movatter.jp