Skip to content

feat(v0.1.25.26): bulk-action endpoints on tenants + webhooks - #109

Merged
amavashev merged 1 commit into
mainfrom
feat/admin-bulk-action-v0.1.25.26
Apr 17, 2026
Merged

amavashev merged 1 commit into
mainfrom
feat/admin-bulk-action-v0.1.25.26

Conversation

@amavashev

Copy link
Copy Markdown
Collaborator

Summary

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. Matching safety gates on both (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.

  • Tenants: actions SUSPEND, REACTIVATE, CLOSE with filter {status?, parent_tenant_id?, observe_mode?, search?(≤128)}.
  • Webhooks: actions PAUSE, RESUME, DELETE with filter {tenant_id?, status?, event_type?, search?(≤128)}.
  • Per-row apply reads live status at apply-time so concurrent mutations land in the correct succeeded / failed / skipped bucket; overall response is HTTP 200 with per-row outcomes. Classify-by-error-code maps GovernanceException onto the spec's row-level error codes; generic exceptions → INTERNAL_ERROR.

Design deviation from plan

The review plan required unifying BudgetController.fund idempotency 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 in IdempotencyStore.java javadoc and in AUDIT.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_MISMATCH and LIMIT_EXCEEDED required 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-protocol main — ContractSpecLoader fetches from main. Local verification uses a cache-seeded copy of the patched spec.

Test plan

  • Local mvn verify -Dtest='!*IntegrationTest' (cache-seeded v0.1.25.23 spec): 646 tests pass, 0 failures/errors.
  • JaCoCo LINE coverage rule met on cycles-admin-service-data and cycles-admin-service-api at ≥95%. New IdempotencyStore covered 25/25 lines.
  • OpenApiContractDiffTest + SpecCoverageReportTest allowlists emptied — bulk-action operations now fully covered by contract tests.
  • Per-endpoint controller tests cover: happy paths, empty filter 400, search > 128 chars 400, expected_count 409 COUNT_MISMATCH, > 500 matches 400 LIMIT_EXCEEDED, idempotency replay (no-writes), ALREADY_IN_TARGET_STATE skipped, INVALID_TRANSITION for CLOSED-tenant-SUSPEND and DISABLED-webhook-RESUME, ALREADY_DELETED skipped 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.
  • Repository-level matchForBulk unit 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.
  • Blocked on cycles-protocol PR Claude/server events implementation u e xga #51 merging before cloud CI can pass.

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.
@amavashev
amavashev merged commit 1378c03 into main Apr 17, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant