Repository navigation
feat(v0.1.25.29): budget bulk-action endpoint (spec v0.1.25.26) - #112
Merged
Merged
Conversation
Implements POST /v1/admin/budgets/bulk-action, resolving cycles-server-admin issue #99 ("Bulk Budget Reset at Tenant or Parent-Scope Level"). Operators rolling over a billing period can now issue one filtered bulk request instead of iterating listBudgets + per-row fundBudget. Shape mirrors the tenant/webhook bulk-action pattern already shipped in v0.1.25.26: - BudgetBulkFilter reuses the listBudgets matcher (zero-drift via BudgetListFilters.fromBulkFilter) and requires tenant_id for cross-tenant safety. - action reuses FundingOperation (CREDIT/DEBIT/RESET/REPAY_DEBT/RESET_SPENT). - Envelope returns 200 with succeeded/failed/skipped; per-row id is the ledger_id per spec BudgetBulkActionResponse.succeeded.description. - Safety gates: 500-row hard cap -> LIMIT_EXCEEDED (400); expected_count -> COUNT_MISMATCH (409); 15-min idempotency replay via IdempotencyStore. - Per-row derived idempotency key (bulkKey:scope:unit) feeds Lua fund short-circuit so replays and retry-the-failed-set never double-apply. - Row-level known codes: BUDGET_EXCEEDED, INVALID_TRANSITION, NOT_FOUND, PERMISSION_DENIED, INTERNAL_ERROR; skipped carries reason=ALREADY_IN_TARGET_STATE for REPAY_DEBT on zero debt. - AuthInterceptor plugged: bulk-action path now explicitly requires AdminKeyAuth (tenant keys rejected 401). - AuditLogEntry emitted once per bulk-op with per-bucket counts. Verification: 698/698 tests green, JaCoCo >=95% per module, OpenApiContractDiffTest + SpecCoverageReportTest clean against spec v0.1.25.26 on cycles-protocol/main.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements
POST /v1/admin/budgets/bulk-actionto match cycles-protocol admin spec v0.1.25.26, resolving issue #99 (Bulk Budget Reset at Tenant or Parent-Scope Level). Operators rolling over a billing period can now issue one filtered bulk request instead of iteratinglistBudgets+ per-rowfundBudget.Shape mirrors the tenant/webhook bulk-action pattern already shipped in v0.1.25.26.
Endpoint
/v1/admin/budgets/bulk-actionFundingOperation(CREDIT / DEBIT / RESET / REPAY_DEBT / RESET_SPENT) to every budget matching a filter, bounded to 500 rows.Safety & semantics
LIMIT_EXCEEDEDCOUNT_MISMATCHIdempotencyStore(returns cached envelope verbatim)bulkKey:scope:unit) → Lua fund short-circuit prevents double-apply on retry-the-failed-setBUDGET_EXCEEDED,INVALID_TRANSITION,NOT_FOUND,PERMISSION_DENIED,INTERNAL_ERRORREPAY_DEBTon debt==0 →reason=ALREADY_IN_TARGET_STATEfilter.tenant_idis required; missing → 400BudgetListFilters.fromBulkFilter(...)ensureslistBudgetspreview andbulk-actionalways agree on what matchesledger_id(per specBudgetBulkActionResponse.succeeded.description)Files changed
BudgetBulkFilter,BudgetBulkActionRequest,BudgetBulkActionResponsematchForBulk(tenantId, filters, cap)+fromBulkFilterstatic factory onBudgetListFiltersbulkActionBudgetshandler — validate → idempotency lookup → match → limit check → count gate → per-row apply → store → audit/v1/admin/budgets/bulk-actionadmin-key branch0.1.25.28→0.1.25.29inpom.xml,docker-compose.prod.yml,docker-compose.full-stack.prod.ymlTest coverage
BudgetControllerBulkActionTest— 27 tests (happy paths × 5 actions, classification branches, validation 400s, idempotency replay, audit metadata, auth)BudgetRepositoryBulkMatchTest— 14 tests (each filter dimension, cap+1 sentinel, tenant isolation, stale-index cleanup, parse-failure tolerance)OpenApiContractDiffTest+SpecCoverageReportTestclean against spec v0.1.25.26 on cycles-protocol/mainCloses #99.
Test plan
mvn-proxy -B verify --file cycles-admin-service/pom.xml -Dtest='!*IntegrationTest' -Dsurefire.failIfNoSpecifiedTests=false— 698/698 greenBudgetControllerBulkActionTest— 27/27 greenBudgetRepositoryBulkMatchTest— 14/14 greenOpenApiContractDiffTest+SpecCoverageReportTest— 46/46 spec operations coveredlistBudgets,bulk-actionwithexpected_count, 409 on count drift, 400 on missing amount