Repository navigation
feat: add coderd_ai_user_budget_override resource - #454
ssncferreira wants to merge 1 commit into
Conversation
4a53442 to
e557846
Compare
e557846 to
ed6f583
Compare
ed6f583 to
439b34c
Compare
439b34c to
2751b02
Compare
2751b02 to
65dbcd2
Compare
| resource "coderd_user" "alice" { | ||
| username = "alice" | ||
| email = "alice@example.com" | ||
| } |
There was a problem hiding this comment.
Could we update integration/agents-model-test to cover this resource and coderd_ai_group_budget, like #445 and #448 did for the other AI resources? Something like:
- create a user, add it to the existing
agents-usersgroup, and give the group acoderd_ai_group_budgetand the user acoderd_ai_user_budget_override, all in the same apply - assert that
UserAISpendStatusfor that user returns the override's limit withlimit_sourceset touser_override
The acceptance tests for both resources create the users and groups through the SDK, so nothing applies this example shape end to end or checks that Coder enforces the override over the group budget.
Generated by an agent on behalf of the user
| // aiUserBudgetOverrideDiag converts an error from the user AI budget override | ||
| // API into a diagnostic. The upsert call returns 404 only when the group does | ||
| // not exist, or when the deployment has no user AI budget override API. | ||
| func aiUserBudgetOverrideDiag(action string, userID uuid.UUID, err error) diag.Diagnostics { | ||
| var diags diag.Diagnostics | ||
| if isHTTPNotFound(err) { | ||
| diags.AddError("Group Not Found or Unsupported Coder Version", fmt.Sprintf( | ||
| "Unable to %s AI budget override for user %s: the deployment returned 404 for /api/v2/users/%s/ai/budget/override. "+ | ||
| "Either the group does not exist, or the deployment is older than Coder version %s, which this resource requires. "+ | ||
| "Original error: %s", | ||
| action, userID, userID, aiUserBudgetOverrideMinVersion, err)) |
There was a problem hiding this comment.
A 404 here doesn't only mean a missing group or an old Coder. Coder also returns 404 when the user_id doesn't exist, or when the token can't update the user or the group: UpsertUserAIBudgetOverride checks update on both, and the handler maps the denial to 404 through httpapi.Is404Error.
An Organization Admin or Organization User Admin token hits this. Those roles can read users site-wide but can't update them, so the plan-time conflict check passes, then the apply fails with "Group Not Found or Unsupported Coder Version" while the group exists and Coder is new enough. #453 documents those roles as enough for coderd_ai_group_budget, so the same token can apply the group budget and then hit this.
Could the comment and the message cover the missing user and missing permission cases too, similar to the 404 message in agentsSystemPromptDiag?
Generated by an agent on behalf of the user
Description
Adds the
coderd_ai_user_budget_overrideresource, which manages an AI spend limit for a single user and the group their spend is attributed to (/api/v2/users/{user}/ai/budget/override). Stacked on #453.Changes
coderd_ai_user_budget_overridewithuser_id,group_id, andspend_limit, registered under the "AI Governance" docs subcategory.spend_limitvalidators and conventions fromcoderd_ai_group_budget, and link the two resources in the docs.coderd_user.Closes AIGOV-682
Note
Generated by Coder Agents on behalf of @ssncferreira.