mirror of
https://github.com/coder/coder.git
synced 2026-10-16 14:48:56 +08:00
The chat `read_template` tool returned the parameter defaults recorded at template import. Defaults that depend on the workspace owner, such as a region chosen from the owner's groups, were therefore wrong for many users, and an agent that omitted the parameter in `create_workspace` built a workspace with a different value than the tool had shown. `read_template` now evaluates the active version's parameters for the chat owner with no inputs, through `dynamicparameters.Prepare` and the same `Render` call `wsbuilder` makes for a first build, via a `RenderTemplateParametersFn` hook wired from coderd like the other chat hooks. The result carries a `parameters_note` naming the source: owner-evaluated build values, import rows for templates on the classic parameter flow (which `wsbuilder` also builds from), a retry note while the version is still importing, or import rows with a warning when evaluation fails. A parameter whose evaluated default fails its own validation is reported as `error` instead of a usable `default`. Only an evaluated default is checked: without one, preview and the static renderer validate an empty value, so required parameters and unevaluated defaults are never reported as broken, and their remaining errors surface at build time. Fields preview cannot evaluate before the build are shown as evaluated rather than filled from the import row, because preview's output does not distinguish a default, option set, or validation bound that is unknown (it depends on `data.coder_provisioner`) from one that is null for this owner: an unevaluated default carries a `default_note` saying so, an option with an unknown value is omitted, with preview's invalid-options error surfaced as `error` when the parameter has an evaluated default, and bounds appear exactly as rendered. The one import-row fill is for parameters a `module_not_loaded` render dropped, keyed on the same diagnostic code `wsbuilder` uses. Import rows carry no module provenance, so that fill also restores root-level rows the render omitted for this owner; every restored row carries a `note` marking it an import-time estimate. The build-values note is scoped to a request that omits every parameter and matches no preset, since a default that depends on another parameter is re-evaluated against the values `create_workspace` passes, a preset can match without a `preset_id`, and a claimed prebuilt workspace can keep its own values. When evaluation falls back, the warning logs only diagnostic codes, because diagnostic text can quote owner attributes. Measured on dogfood, evaluation adds about 4 ms for a two-parameter template and about 70 ms for the 6-parameter, 19-module `coder` template per `read_template` call, matching the workspace create form's evaluate endpoint, with no file cache growth across repeated calls. > Xum acted for Mike on this pull request.
21 lines
896 B
Go
21 lines
896 B
Go
package coderd
|
|
|
|
// ChatStartWorkspace exposes chatStartWorkspace for external tests.
|
|
//
|
|
// chatStartWorkspace is intentionally unexported to keep symmetry with
|
|
// its sister chatCreateWorkspace. The alias lets external tests drive
|
|
// the RequireActiveVersion auto-update path end-to-end without
|
|
// stubbing the entire DB layer. The proper fix is to extract a pure
|
|
// request builder; tracked in CODAGT-292.
|
|
var ChatStartWorkspace = (*API).chatStartWorkspace
|
|
|
|
// ChatStopWorkspace exposes chatStopWorkspace for external tests.
|
|
var ChatStopWorkspace = (*API).chatStopWorkspace
|
|
|
|
// ChatRenderTemplateParameters exposes chatRenderTemplateParameters for
|
|
// external tests.
|
|
var ChatRenderTemplateParameters = (*API).chatRenderTemplateParameters
|
|
|
|
// NormalizeWorkspaceFileReference exposes normalizeWorkspaceFileReference for tests.
|
|
var NormalizeWorkspaceFileReference = normalizeWorkspaceFileReference
|