feat!: patchTemplateMeta to use optional fields#24984
Conversation
Docs preview📖 View docs preview for |
| // Either a successful no-op or a 304 Not Modified is | ||
| // acceptable: the request itself is allowed (it does not | ||
| // require enterprise entitlement), and AGPL silently | ||
| // ignores enterprise-only schedule fields, so the | ||
| // effective template state is unchanged. | ||
| if err != nil { | ||
| require.ErrorContains(t, err, "not modified") | ||
| } |
There was a problem hiding this comment.
304's are considered errors by the cli. I'm not trying to change that behavior here
| @@ -0,0 +1,162 @@ | |||
| package coderd | |||
There was a problem hiding this comment.
This file has the meat of the change.
Extracted the settings to it's own function for easier unit test
37fc1d8 to
63db44b
Compare
|
/coder-agents-review |
There was a problem hiding this comment.
First-pass review (Netero only). This is a mechanical scan; the full review panel has not yet reviewed this PR and will review after these findings are addressed.
The conversion to pointer fields is clean and the test matrix is thorough. One test-correctness issue (P2) and several stale-comment leftovers from the 304 removal.
1 P2, 4 P3, 1 Nit.
"The handler now always writes to the DB and returns 200 OK; remove the 304 references." Netero, surveying the battlefield
🤖 This review was automatically generated with Coder Agents.
UpdateTemplateMeta is the body for PATCH /api/v2/templates/{template}.
Convert all settable fields to pointers so omitted fields preserve the
existing template value instead of overwriting with the Go zero value.
Closes #13112
…lper Splits the resolution phase of patchTemplateMeta into a pure helper that takes (template, scheduleOpts, req) and returns a templateMetaUpdate struct plus parsing-only validation errors. The handler now calls this helper once and references resolved.foo throughout, which makes the mapping from request -> persisted state explicit and testable without spinning up a coderd instance. Adds an internal table-driven test (one case per pointer field) that verifies an empty PATCH preserves every value and that each single-field PATCH changes only that field, plus targeted cases for the one-shot intent flags (DisableEveryoneGroupAccess, UpdateWorkspaceLastUsedAt, UpdateWorkspaceDormantAt) and parsing-error paths. No behavior change.
…fault CORS The CORS subtests call UpdateTemplateMeta with CORSBehavior set to the same value the freshly-created template already has. Now that the API treats unchanged fields as a true no-op, that returns 304 Not Modified which the SDK surfaces as an error. Tolerate 'not modified' and fetch the template to keep the assertion on the response value meaningful.
1f1aa5d to
c0a4ab1
Compare
The previous docstring suggested the resolver performed all user-facing validation. It does not. The resolver only validates shape (parsing weekday strings and CORS enums). Range and content checks (e.g. activityBumpMillis >= 0, failureTTLMillis >= 1 minute) live in the caller.
| err := inv.WithContext(ctx).Run() | ||
|
|
||
| require.ErrorContains(t, err, "not modified") | ||
| require.NoError(t, err) |
There was a problem hiding this comment.
Someone might be impacted by this behavior change, but I think this is a net improvement to the CLI ergonomics (folks don't need to ignore the no-change error).
There was a problem hiding this comment.
Should we mark this as a breaking change? Any clients expecting a 304 will be in for a surprise.
There was a problem hiding this comment.
Yeah it should be called out.
There was a problem hiding this comment.
I'll mark it a breaking change.
A 304 being an error was very annoying to handle. And it was not a sentinel error, so we always did a string comparison
Closes #13112
Breaking Change: Removed status code
StatusNotModifiedwhen no diffs occur in a patch. Now the patch is always applied and a template is always returned.What this does
codersdk.UpdateTemplateMetato a pointer.Most of this diff is unit testing every single field
This pull request was generated by a Coder agent on behalf of @Emyrk.