Repository navigation
feat(v0.1.25.26): bulk-action endpoints on tenants + webhooks - #109
Merged
Merged
Conversation
Closes v0.1.25.21 spec gap (second bullet): two new AdminKeyAuth-only endpoints — POST /v1/admin/tenants/bulk-action and POST /v1/admin/webhooks/bulk-action — with matching safety gates (empty-filter 400, expected_count 409 COUNT_MISMATCH, 500-row cap 400 LIMIT_EXCEEDED, 15-minute idempotency replay). Ships with a new Redis-backed IdempotencyStore under cycles-admin-service-data for bulk-action envelope caching. The existing BudgetController.fund idempotency is deliberately NOT migrated onto this store — fund-path idempotency is atomic inside its Redis Lua script with the balance mutation; externalising would break that atomicity. Rationale documented inline in IdempotencyStore.java javadoc and in AUDIT.md. Paired with cycles-protocol PR #51 (spec v0.1.25.23) which widens the ErrorCode enum to include COUNT_MISMATCH and LIMIT_EXCEEDED required by v0.1.25.21 prose but missing from the enum. Cloud CI on this branch will be red until PR #51 merges to cycles-protocol main; local verify passes with a cache-seeded v0.1.25.23 spec (646/646 tests, JaCoCo ≥95% on both data and api modules). - Model: BulkActionRowOutcome (shared), TenantBulkAction/Filter/Request/Response, WebhookBulkAction/Filter/Request/Response. - Data: TenantRepository.matchForBulk, WebhookRepository.matchForBulk (cap+1 sentinel for LIMIT_EXCEEDED detection without full hydration). - Api: bulkAction controllers + per-row applyTenantAction/applyWebhookAction with try/catch classifying GovernanceException via classifyFailureCode and generic exceptions as INTERNAL_ERROR. Reads live status at apply-time so concurrent mutations land in the correct per-row outcome bucket. - AuthInterceptor: admin-only routing for both bulk-action paths. - Contract tests: KNOWN_MISSING allowlists emptied; bulk-action now fully covered by OpenApiContractDiffTest and SpecCoverageReportTest. - AUDIT.md: spec header → info.version 0.1.25.23; full release section describing endpoints, safety gates, apply semantics, IdempotencyStore rationale, and verification. - pom.xml: revision 0.1.25.25 → 0.1.25.26.
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
Closes v0.1.25.21 spec gap (second bullet): two new AdminKeyAuth-only endpoints —
POST /v1/admin/tenants/bulk-actionandPOST /v1/admin/webhooks/bulk-action. Matching safety gates on both (empty-filter 400,expected_count409COUNT_MISMATCH, 500-row cap 400LIMIT_EXCEEDED, 15-minute idempotency replay). Ships with a new Redis-backedIdempotencyStoreundercycles-admin-service-data.SUSPEND,REACTIVATE,CLOSEwith filter{status?, parent_tenant_id?, observe_mode?, search?(≤128)}.PAUSE,RESUME,DELETEwith filter{tenant_id?, status?, event_type?, search?(≤128)}.succeeded/failed/skippedbucket; overall response is HTTP 200 with per-row outcomes. Classify-by-error-code mapsGovernanceExceptiononto the spec's row-level error codes; generic exceptions →INTERNAL_ERROR.Design deviation from plan
The review plan required unifying
BudgetController.fundidempotency onto the new shared store. On inspection, the fund-path idempotency lives inside a Redis Lua script atomic with the balance mutation — externalising would break atomicity (concurrent retry could slip between lookup and apply, double-applying the balance). Kept fund-path untouched; rationale documented inline inIdempotencyStore.javajavadoc and inAUDIT.md.Spec lineage — paired PR (blocks cloud CI)
Important
This PR is paired with cycles-protocol PR #51 (spec v0.1.25.23 — enum widening to add
COUNT_MISMATCHandLIMIT_EXCEEDEDrequired by v0.1.25.21 prose but missing from the enum). Cloud CI on this branch will remain red until PR #51 merges to cycles-protocolmain—ContractSpecLoaderfetches frommain. Local verification uses a cache-seeded copy of the patched spec.Test plan
mvn verify -Dtest='!*IntegrationTest'(cache-seeded v0.1.25.23 spec): 646 tests pass, 0 failures/errors.cycles-admin-service-dataandcycles-admin-service-apiat ≥95%. NewIdempotencyStorecovered 25/25 lines.OpenApiContractDiffTest+SpecCoverageReportTestallowlists emptied — bulk-action operations now fully covered by contract tests.expected_count409COUNT_MISMATCH, > 500 matches 400LIMIT_EXCEEDED, idempotency replay (no-writes),ALREADY_IN_TARGET_STATEskipped,INVALID_TRANSITIONfor CLOSED-tenant-SUSPEND and DISABLED-webhook-RESUME,ALREADY_DELETEDskipped for missing rows and concurrent-delete between match and apply, missing idempotency_key 400, no admin key 401, classify-by-error-code (PERMISSION_DENIED/INVALID_TRANSITION/NOT_FOUND), generic-exception →INTERNAL_ERROR.matchForBulkunit tests cover: no-filter scan, per-field filters, search matching on both fields, missing-row and corrupt-JSON skipping, blank-tenantId fallback to global set, cap+1 sentinel stopping iteration without hydrating the extra row.