Skip to content

refactor(enterprise/coderd): extract AI model price body decoding and validation - #30716

Merged
SasSwart merged 3 commits into
mainfrom
sdlcgraph/aigov-612-1-price-validation
Oct 19, 2026
Merged

SasSwart merged 3 commits into
mainfrom
sdlcgraph/aigov-612-1-price-validation

Conversation

@SasSwart

@SasSwart SasSwart commented Oct 13, 2026 •

Copy link
Copy Markdown
Collaborator

Moves request body decoding and per-price validation out of the site-wide upsertAIModelPrices handler, so the organization price handler later in this stack can reuse them.

  • The handler still reads the body and writes the HTTP errors. writeAIModelPricesBodyReadError picks 413 or 400.
  • decodeAIModelPricesBody only decodes, and returns an error.
  • aiModelPriceKeys holds the JSON keys present in one price, so validation can tell an explicit null apart from a missing price.
  • validateAIModelPriceValues checks the four prices of one model price. It takes them as an aiModelTokenPrices struct, so callers set each price by name and cannot pass them in the wrong order.

No behavior change. The existing TestUpsertAIModelPrices, TestListAIModelPrices and TestValidateAIModelPrices cover the site-wide handler.

Used later: #30720 reuses the body read error, the price keys and the value validation for its single-price upsert.


This PR was generated by Coder Agents on behalf of @SasSwart.

@linear-code

linear-code Bot commented Oct 13, 2026

Copy link
Copy Markdown

AIGOV-612

@SasSwart SasSwart left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Self review

Comment thread enterprise/coderd/aimodelprices.go Resolved
Comment thread enterprise/coderd/aimodelprices.go Resolved
Comment thread enterprise/coderd/aimodelprices.go Resolved
@SasSwart
SasSwart requested a review from ssncferreira October 14, 2026 15:47
@SasSwart
SasSwart marked this pull request as ready for review October 14, 2026 15:47

@ssncferreira ssncferreira left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM 👍

Comment thread enterprise/coderd/aimodelprices.go Resolved
… decoding

The handler reads the body and writes errors. decodeAIModelPricesBody only
decodes and returns an error. aiModelPriceKeys names the keys present in a
price, which tell an explicit null apart from a missing price.
Group the four token prices passed to validateAIModelPriceValues into
aiModelTokenPrices, so callers set each price by name and cannot pass
them in the wrong order.
@SasSwart
SasSwart force-pushed the sdlcgraph/aigov-612-1-price-validation branch from f1faa97 to 7542472 Compare October 19, 2026 08:56
@SasSwart
SasSwart merged commit 41e5b2d into main Oct 19, 2026
29 checks passed
@SasSwart
SasSwart deleted the sdlcgraph/aigov-612-1-price-validation branch October 19, 2026 09:12
@github-actions github-actions Bot locked and limited conversation to collaborators Oct 19, 2026
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