@stackonward/cli 0.0.1 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +4588 -205
- package/dist/index.js.map +1 -1
- package/dist/resources/apple/.claude/docs/architecture-template.md +54 -0
- package/dist/resources/apple/.claude/docs/architecture.md +52 -0
- package/dist/resources/apple/.claude/docs/index.md +13 -0
- package/dist/resources/apple/.claude/docs/security-lifecycle.md +57 -0
- package/dist/resources/apple/.claude/docs/stack.md +93 -0
- package/dist/resources/apple/.claude/docs/verification.md +63 -0
- package/dist/resources/apple/AGENTS.md +397 -0
- package/dist/resources/apple/CLAUDE.md +397 -0
- package/dist/resources/apple/Gemfile +2 -0
- package/dist/resources/apple/Gemfile.lock +365 -0
- package/dist/resources/apple/_gitignore +14 -0
- package/dist/resources/apple/fastlane/Fastfile +123 -0
- package/dist/resources/components/nuxt/site-source/app/app.vue +42 -0
- package/dist/resources/components/nuxt/site-source/app/assets/css/site-shell.css +1035 -0
- package/dist/resources/components/nuxt/site-source/app/assets/icons/brand/.gitkeep +0 -0
- package/dist/resources/components/nuxt/site-source/app/assets/icons/common/.gitkeep +0 -0
- package/dist/resources/components/nuxt/site-source/app/components/site/ApplicationHeader.vue +35 -0
- package/dist/resources/components/nuxt/site-source/app/components/site/ApplicationShell.vue +56 -0
- package/dist/resources/components/nuxt/site-source/app/components/site/ApplicationSidebar.vue +40 -0
- package/dist/resources/components/nuxt/site-source/app/components/site/BackToTop.vue +42 -0
- package/dist/resources/components/nuxt/site-source/app/components/site/ContentArticlePage.vue +40 -0
- package/dist/resources/components/nuxt/site-source/app/components/site/ContentListPage.vue +30 -0
- package/dist/resources/components/nuxt/site-source/app/components/site/CookieConsent.vue +18 -0
- package/dist/resources/components/nuxt/site-source/app/components/site/MarketingFooter.vue +52 -0
- package/dist/resources/components/nuxt/site-source/app/components/site/MarketingHeader.vue +106 -0
- package/dist/resources/components/nuxt/site-source/app/components/site/MarketingShell.vue +35 -0
- package/dist/resources/components/nuxt/site-source/app/components/site/SiteBrand.vue +10 -0
- package/dist/resources/components/nuxt/site-source/app/components/site/StaticPage.vue +21 -0
- package/dist/resources/components/nuxt/site-source/app/components/site/ToastViewport.vue +25 -0
- package/dist/resources/components/nuxt/site-source/app/components/ui/BaseButton.vue +86 -0
- package/dist/resources/components/nuxt/site-source/app/components/ui/BaseGradientBorder.vue +59 -0
- package/dist/resources/components/nuxt/site-source/app/components/ui/BaseModal.vue +131 -0
- package/dist/resources/components/nuxt/site-source/app/components/ui/BasePopover.vue +150 -0
- package/dist/resources/components/nuxt/site-source/app/components/ui/BaseText.vue +138 -0
- package/dist/resources/components/nuxt/site-source/app/components/ui/CheckoutStatus.vue +112 -0
- package/dist/resources/components/nuxt/site-source/app/components/ui/CheckoutSummary.vue +172 -0
- package/dist/resources/components/nuxt/site-source/app/components/ui/GoogleSignInButton.vue +113 -0
- package/dist/resources/components/nuxt/site-source/app/components/ui/InfiniteScroll.vue +123 -0
- package/dist/resources/components/nuxt/site-source/app/components/ui/YoutubeEmbed.vue +126 -0
- package/dist/resources/components/nuxt/site-source/app/composables/useAnalytics.ts +24 -0
- package/dist/resources/components/nuxt/site-source/app/composables/useCheckout.ts +121 -0
- package/dist/resources/components/nuxt/site-source/app/composables/useConsent.ts +31 -0
- package/dist/resources/components/nuxt/site-source/app/composables/useGoogleIdentity.ts +163 -0
- package/dist/resources/components/nuxt/site-source/app/composables/useNavigation.ts +11 -0
- package/dist/resources/components/nuxt/site-source/app/composables/useSeo.ts +33 -0
- package/dist/resources/components/nuxt/site-source/app/composables/useSiteShell.ts +58 -0
- package/dist/resources/components/nuxt/site-source/app/composables/useToasts.ts +48 -0
- package/dist/resources/components/nuxt/site-source/app/layouts/app.vue +5 -0
- package/dist/resources/components/nuxt/site-source/app/layouts/default.vue +5 -0
- package/dist/resources/components/nuxt/site-source/app/plugins/analytics.client.ts +121 -0
- package/dist/resources/components/nuxt/site-source/app/plugins/google-identity.client.ts +24 -0
- package/dist/resources/components/nuxt/site-source/app/theme/accordion.ts +9 -0
- package/dist/resources/components/nuxt/site-source/app/theme/breadcrumb.ts +8 -0
- package/dist/resources/components/nuxt/site-source/app/theme/button.ts +92 -0
- package/dist/resources/components/nuxt/site-source/app/theme/carousel.ts +11 -0
- package/dist/resources/components/nuxt/site-source/app/theme/checkbox.ts +12 -0
- package/dist/resources/components/nuxt/site-source/app/theme/index.ts +30 -0
- package/dist/resources/components/nuxt/site-source/app/theme/input.ts +47 -0
- package/dist/resources/components/nuxt/site-source/app/theme/modal.ts +9 -0
- package/dist/resources/components/nuxt/site-source/app/theme/pagination.ts +6 -0
- package/dist/resources/components/nuxt/site-source/app/theme/select.ts +23 -0
- package/dist/resources/components/nuxt/site-source/app/theme/stepper.ts +10 -0
- package/dist/resources/components/nuxt/site-source/app/theme/toast.ts +8 -0
- package/dist/resources/components/nuxt/site-source/app/theme/tooltip.ts +6 -0
- package/dist/resources/components/nuxt/site-source/app/types/site-shell.ts +85 -0
- package/dist/resources/components/react/ui/Button.tsx +73 -0
- package/dist/resources/components/react/ui/Input.tsx +44 -0
- package/dist/resources/components/registry.json +355 -0
- package/dist/resources/components/vue/feedback/Toast.vue +120 -0
- package/dist/resources/components/vue/feedback/useToast.ts +70 -0
- package/dist/resources/components/vue/media/FileUpload.vue +229 -0
- package/dist/resources/components/vue/media/VideoPlayer.vue +157 -0
- package/dist/resources/components/vue/ui/AppImage.vue +147 -0
- package/dist/resources/components/vue/ui/BottomSheet.vue +217 -0
- package/dist/resources/components/vue/ui/Button.vue +154 -0
- package/dist/resources/components/vue/ui/Card.vue +111 -0
- package/dist/resources/components/vue/ui/Input.vue +113 -0
- package/dist/resources/components/vue/ui/Modal.vue +193 -0
- package/dist/resources/components/vue/ui/ScrollArea.vue +163 -0
- package/dist/resources/components/vue/ui/Tooltip.vue +115 -0
- package/dist/resources/registry.json +158 -0
- package/dist/resources/snippets/node/cache.ts +116 -0
- package/dist/resources/snippets/node/date.ts +126 -0
- package/dist/resources/snippets/node/logger.ts +104 -0
- package/dist/resources/snippets/node/validation.ts +132 -0
- package/dist/resources/snippets/react/useDebounce.ts +90 -0
- package/dist/resources/snippets/registry.json +65 -0
- package/dist/resources/snippets/vue/useAsync.ts +96 -0
- package/dist/resources/snippets/vue/usePagination.ts +102 -0
- package/dist/resources/templates/base/.claude/docs/architecture-template.md +459 -0
- package/dist/resources/templates/base/.claude/docs/architecture.md +137 -0
- package/dist/resources/templates/base/.claude/docs/index.md +42 -0
- package/dist/resources/templates/base/.claude/docs/security-lifecycle.md +129 -0
- package/dist/resources/templates/base/.claude/docs/verification.md +121 -0
- package/dist/resources/templates/base/AGENTS.md +415 -0
- package/dist/resources/templates/base/CLAUDE.md +415 -0
- package/dist/resources/templates/go-backend/.claude/docs/api-design.md +486 -0
- package/dist/resources/templates/go-backend/.claude/docs/architecture-template.md +449 -0
- package/dist/resources/templates/go-backend/.claude/docs/check-list.md +155 -0
- package/dist/resources/templates/go-backend/.claude/docs/database.md +369 -0
- package/dist/resources/templates/go-backend/.claude/docs/e2e-standards.md +161 -0
- package/dist/resources/templates/go-backend/.claude/docs/error-handling.md +558 -0
- package/dist/resources/templates/go-backend/.claude/docs/event-runtime-boundary.md +124 -0
- package/dist/resources/templates/go-backend/.claude/docs/identifier-contract.md +195 -0
- package/dist/resources/templates/go-backend/.claude/docs/index.md +22 -0
- package/dist/resources/templates/go-backend/.claude/docs/logging.md +314 -0
- package/dist/resources/templates/go-backend/.claude/docs/mediagen-provider-onboarding-sop.md +917 -0
- package/dist/resources/templates/go-backend/.claude/docs/mediagen-provider-quick-reference.md +195 -0
- package/dist/resources/templates/go-backend/.claude/docs/module-standards.md +309 -0
- package/dist/resources/templates/go-backend/.claude/docs/openapi-contract.md +141 -0
- package/dist/resources/templates/go-backend/.claude/docs/payment-gateway-onboarding.md +283 -0
- package/dist/resources/templates/go-backend/.claude/docs/platform-boundary.md +191 -0
- package/dist/resources/templates/go-backend/.claude/docs/quality-gates.md +112 -0
- package/dist/resources/templates/go-backend/.dockerignore +6 -0
- package/dist/resources/templates/go-backend/.env.example +13 -0
- package/dist/resources/templates/go-backend/.gitattributes +2 -0
- package/dist/resources/templates/go-backend/AGENTS.md +1139 -0
- package/dist/resources/templates/go-backend/CLAUDE.md +1139 -0
- package/dist/resources/templates/go-backend/Dockerfile +14 -0
- package/dist/resources/templates/go-backend/Makefile +71 -0
- package/dist/resources/templates/go-backend/README.md +66 -0
- package/dist/resources/templates/go-backend/_gitignore +10 -0
- package/dist/resources/templates/go-backend/api/openapi/README.md +29 -0
- package/dist/resources/templates/go-backend/api/openapi/dist/artifact-manifest.json +19 -0
- package/dist/resources/templates/go-backend/api/openapi/dist/conformance-matrix.json +276 -0
- package/dist/resources/templates/go-backend/api/openapi/document.go +30 -0
- package/dist/resources/templates/go-backend/api/openapi/package.json +28 -0
- package/dist/resources/templates/go-backend/api/openapi/pnpm-lock.yaml +3052 -0
- package/dist/resources/templates/go-backend/api/openapi/redocly-source.yaml +18 -0
- package/dist/resources/templates/go-backend/api/openapi/redocly.yaml +8 -0
- package/dist/resources/templates/go-backend/api/openapi/sdk-generators.json +16 -0
- package/dist/resources/templates/go-backend/api/openapi/service-registry.json +39 -0
- package/dist/resources/templates/go-backend/api/openapi/services/product-api/conformance/runtime.arazzo.yaml +65 -0
- package/dist/resources/templates/go-backend/api/openapi/services/product-api/dist/internal.openapi.json +327 -0
- package/dist/resources/templates/go-backend/api/openapi/services/product-api/dist/runtime-contract.json +56 -0
- package/dist/resources/templates/go-backend/api/openapi/services/product-api/openapi.yaml +222 -0
- package/dist/resources/templates/go-backend/api/openapi/services/worker/conformance/runtime.arazzo.yaml +65 -0
- package/dist/resources/templates/go-backend/api/openapi/services/worker/dist/internal.openapi.json +327 -0
- package/dist/resources/templates/go-backend/api/openapi/services/worker/dist/runtime-contract.json +56 -0
- package/dist/resources/templates/go-backend/api/openapi/services/worker/openapi.yaml +222 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/breaking.mjs +416 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/build.mjs +103 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/conformance_coverage.mjs +111 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/contract_compiler.mjs +62 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/contract_policy.mjs +208 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/delegated_contract.mjs +302 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/deterministic_archive.mjs +69 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/documentation_example_privacy.mjs +93 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/documentation_projection.mjs +498 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/documentation_quality.mjs +346 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/git_artifact_history.mjs +188 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/manifest.mjs +170 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/overlay.mjs +98 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/project.mjs +549 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/route_contract.mjs +156 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/runtime_conformance.mjs +193 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/scalar_asset_localization.mjs +164 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/sdk_generator.mjs +229 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/semantic_version.mjs +64 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/service_contract_inputs.mjs +16 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/test/breaking.test.mjs +365 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/test/build.test.mjs +42 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/test/conformance_coverage.test.mjs +88 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/test/contract_policy.test.mjs +257 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/test/delegated_contract.test.mjs +205 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/test/documentation_example_privacy.test.mjs +51 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/test/documentation_projection.test.mjs +368 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/test/documentation_quality.test.mjs +151 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/test/git_artifact_history.test.mjs +60 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/test/head_policy.test.mjs +8 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/test/overlay.test.mjs +44 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/test/projection.test.mjs +270 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/test/redocly_documentation_rules.test.mjs +146 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/test/release_manifest.test.mjs +76 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/test/route_contract.test.mjs +119 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/test/runtime_conformance.test.mjs +75 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/test/scalar_asset_localization.test.mjs +50 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/test/sdk_generator.test.mjs +31 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/test/semantic_version.test.mjs +60 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/test/service_contract_inputs.test.mjs +27 -0
- package/dist/resources/templates/go-backend/cmd/internal/runtime/resources.go +125 -0
- package/dist/resources/templates/go-backend/cmd/internal/runtime/runtime.go +102 -0
- package/dist/resources/templates/go-backend/cmd/internal/runtime/runtime_test.go +70 -0
- package/dist/resources/templates/go-backend/cmd/product-api/lifecycle_test.go +58 -0
- package/dist/resources/templates/go-backend/cmd/product-api/main.go +32 -0
- package/dist/resources/templates/go-backend/cmd/product-api/wire.go +13 -0
- package/dist/resources/templates/go-backend/cmd/product-api/wire_gen.go +94 -0
- package/dist/resources/templates/go-backend/cmd/worker/main.go +47 -0
- package/dist/resources/templates/go-backend/cmd/worker/wire.go +14 -0
- package/dist/resources/templates/go-backend/cmd/worker/wire_gen.go +111 -0
- package/dist/resources/templates/go-backend/configs/config.yaml +37 -0
- package/dist/resources/templates/go-backend/deployments/compose.yaml +71 -0
- package/dist/resources/templates/go-backend/docs/openapi-provenance.json +489 -0
- package/dist/resources/templates/go-backend/docs/runtime-provenance.json +175 -0
- package/dist/resources/templates/go-backend/docs/source-provenance.json +3568 -0
- package/dist/resources/templates/go-backend/docs/standards-provenance.json +1624 -0
- package/dist/resources/templates/go-backend/go.mod +256 -0
- package/dist/resources/templates/go-backend/go.sum +805 -0
- package/dist/resources/templates/go-backend/internal/common/canonicaljson/canonical.go +370 -0
- package/dist/resources/templates/go-backend/internal/common/canonicaljson/canonical_test.go +223 -0
- package/dist/resources/templates/go-backend/internal/common/checkoutbff/contracts.go +125 -0
- package/dist/resources/templates/go-backend/internal/common/checkoutbff/platform_client.go +212 -0
- package/dist/resources/templates/go-backend/internal/common/checkoutbff/platform_client_test.go +319 -0
- package/dist/resources/templates/go-backend/internal/common/contentaccess/contentaccess.go +50 -0
- package/dist/resources/templates/go-backend/internal/common/contracts/contact.go +85 -0
- package/dist/resources/templates/go-backend/internal/common/ctxutil/identity.go +20 -0
- package/dist/resources/templates/go-backend/internal/common/ctxutil/product.go +53 -0
- package/dist/resources/templates/go-backend/internal/common/enumdomain/payment.go +12 -0
- package/dist/resources/templates/go-backend/internal/common/enums/dto_admin.go +9 -0
- package/dist/resources/templates/go-backend/internal/common/enums/enum.go +1247 -0
- package/dist/resources/templates/go-backend/internal/common/enums/handler_admin.go +66 -0
- package/dist/resources/templates/go-backend/internal/common/enums/module.go +46 -0
- package/dist/resources/templates/go-backend/internal/common/enums/provider.go +10 -0
- package/dist/resources/templates/go-backend/internal/common/enums/register.go +11 -0
- package/dist/resources/templates/go-backend/internal/common/enums/register_audit.go +274 -0
- package/dist/resources/templates/go-backend/internal/common/enums/register_command_replay.go +12 -0
- package/dist/resources/templates/go-backend/internal/common/enums/register_config.go +27 -0
- package/dist/resources/templates/go-backend/internal/common/enums/register_locale.go +37 -0
- package/dist/resources/templates/go-backend/internal/common/enums/register_ops.go +14 -0
- package/dist/resources/templates/go-backend/internal/common/enums/register_outbox.go +15 -0
- package/dist/resources/templates/go-backend/internal/common/enums/register_rule_expression.go +63 -0
- package/dist/resources/templates/go-backend/internal/common/enums/registry.go +77 -0
- package/dist/resources/templates/go-backend/internal/common/httporigin/origin.go +62 -0
- package/dist/resources/templates/go-backend/internal/common/httporigin/origin_test.go +38 -0
- package/dist/resources/templates/go-backend/internal/common/iamcredential/plaintext.go +35 -0
- package/dist/resources/templates/go-backend/internal/common/iamcredential/plaintext_test.go +29 -0
- package/dist/resources/templates/go-backend/internal/common/iamscope/scope.go +212 -0
- package/dist/resources/templates/go-backend/internal/common/iamscope/scope_binding.go +26 -0
- package/dist/resources/templates/go-backend/internal/common/iamscope/scope_filter.go +173 -0
- package/dist/resources/templates/go-backend/internal/common/iamscope/scope_filter_test.go +279 -0
- package/dist/resources/templates/go-backend/internal/common/internalapi/authorization_details.go +10 -0
- package/dist/resources/templates/go-backend/internal/common/internalapi/route_permission_policies.go +660 -0
- package/dist/resources/templates/go-backend/internal/common/internalapi/route_permission_policies_test.go +331 -0
- package/dist/resources/templates/go-backend/internal/common/internalservice/audience_token_source.go +166 -0
- package/dist/resources/templates/go-backend/internal/common/internalservice/bootstrap_token_exchanger.go +183 -0
- package/dist/resources/templates/go-backend/internal/common/internalservice/bound_service_token_signer.go +52 -0
- package/dist/resources/templates/go-backend/internal/common/internalservice/delegated_access_token_exchanger.go +189 -0
- package/dist/resources/templates/go-backend/internal/common/internalservice/delegated_access_token_exchanger_test.go +159 -0
- package/dist/resources/templates/go-backend/internal/common/internalservice/product_scoped_service_token_signer.go +92 -0
- package/dist/resources/templates/go-backend/internal/common/internalservice/provider.go +25 -0
- package/dist/resources/templates/go-backend/internal/common/internalservice/request_signer.go +86 -0
- package/dist/resources/templates/go-backend/internal/common/internalservice/resolver.go +69 -0
- package/dist/resources/templates/go-backend/internal/common/internalservice/resolver_test.go +42 -0
- package/dist/resources/templates/go-backend/internal/common/internalservice/route_scope.go +95 -0
- package/dist/resources/templates/go-backend/internal/common/internalservice/route_scope_test.go +78 -0
- package/dist/resources/templates/go-backend/internal/common/internalservice/service_identity_test.go +387 -0
- package/dist/resources/templates/go-backend/internal/common/jsonschema/compiler.go +100 -0
- package/dist/resources/templates/go-backend/internal/common/jsonschema/compiler_test.go +41 -0
- package/dist/resources/templates/go-backend/internal/common/jwksapi/handler.go +83 -0
- package/dist/resources/templates/go-backend/internal/common/jwksapi/handler_test.go +104 -0
- package/dist/resources/templates/go-backend/internal/common/locale/locale.go +145 -0
- package/dist/resources/templates/go-backend/internal/common/locale/locale_test.go +75 -0
- package/dist/resources/templates/go-backend/internal/common/mediaref/mediaref.go +54 -0
- package/dist/resources/templates/go-backend/internal/common/mediaref/mediaref_test.go +77 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/apikey_auth.go +320 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/apikey_throttle.go +158 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/auth.go +40 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/auth_test.go +50 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/client_context.go +86 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/cors.go +68 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/event_context.go +18 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/gateway_identity.go +279 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/helpers.go +159 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/iam_delegated_route_permission.go +171 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/iam_delegated_token_auth.go +151 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/iam_delegated_token_auth_test.go +99 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/iam_service_identity.go +138 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/iam_service_token_auth.go +74 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/idempotent.go +273 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/idempotent_test.go +83 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/internal_route_permission.go +45 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/internal_route_permission_test.go +186 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/logging.go +191 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/metrics.go +45 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/middleware_test.go +1516 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/principal_context.go +160 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/principal_context_test.go +355 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/product_context.go +100 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/recovery.go +40 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/referral_attribution.go +178 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/requestid.go +48 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/resource_permission.go +790 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/resource_permission_test.go +440 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/service_credential_auth.go +67 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/tenant.go +148 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/throttle.go +310 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/trusted_client_ip.go +23 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/trusted_client_ip_test.go +60 -0
- package/dist/resources/templates/go-backend/internal/common/money/currency.go +25 -0
- package/dist/resources/templates/go-backend/internal/common/money/errors.go +23 -0
- package/dist/resources/templates/go-backend/internal/common/money/format.go +123 -0
- package/dist/resources/templates/go-backend/internal/common/money/format_test.go +204 -0
- package/dist/resources/templates/go-backend/internal/common/money/gateway.go +144 -0
- package/dist/resources/templates/go-backend/internal/common/money/gateway_test.go +165 -0
- package/dist/resources/templates/go-backend/internal/common/money/rounding.go +56 -0
- package/dist/resources/templates/go-backend/internal/common/money/rounding_test.go +51 -0
- package/dist/resources/templates/go-backend/internal/common/principal/context.go +56 -0
- package/dist/resources/templates/go-backend/internal/common/principal/principal.go +49 -0
- package/dist/resources/templates/go-backend/internal/common/productcode/code.go +24 -0
- package/dist/resources/templates/go-backend/internal/common/productcode/code_test.go +35 -0
- package/dist/resources/templates/go-backend/internal/common/providerconfig/schema.go +577 -0
- package/dist/resources/templates/go-backend/internal/common/providerconfig/schema_test.go +47 -0
- package/dist/resources/templates/go-backend/internal/common/requestprivacy/request.go +246 -0
- package/dist/resources/templates/go-backend/internal/common/requestprivacy/request_test.go +170 -0
- package/dist/resources/templates/go-backend/internal/common/response/pagination.go +60 -0
- package/dist/resources/templates/go-backend/internal/common/response/response.go +110 -0
- package/dist/resources/templates/go-backend/internal/common/response/response_test.go +463 -0
- package/dist/resources/templates/go-backend/internal/common/ruleexpression/ast.go +141 -0
- package/dist/resources/templates/go-backend/internal/common/ruleexpression/ast_test.go +81 -0
- package/dist/resources/templates/go-backend/internal/common/ruleexpression/canonical.go +184 -0
- package/dist/resources/templates/go-backend/internal/common/ruleexpression/canonical_test.go +319 -0
- package/dist/resources/templates/go-backend/internal/common/ruleexpression/decoder.go +555 -0
- package/dist/resources/templates/go-backend/internal/common/ruleexpression/decoder_test.go +260 -0
- package/dist/resources/templates/go-backend/internal/common/ruleexpression/errors.go +55 -0
- package/dist/resources/templates/go-backend/internal/common/ruleexpression/evaluator.go +96 -0
- package/dist/resources/templates/go-backend/internal/common/ruleexpression/evaluator_test.go +220 -0
- package/dist/resources/templates/go-backend/internal/common/ruleexpression/fuzz_test.go +116 -0
- package/dist/resources/templates/go-backend/internal/common/ruleexpression/limits.go +331 -0
- package/dist/resources/templates/go-backend/internal/common/ruleexpression/schema.go +412 -0
- package/dist/resources/templates/go-backend/internal/common/ruleexpression/schema_test.go +164 -0
- package/dist/resources/templates/go-backend/internal/common/runtimeinput/runtime_input.go +627 -0
- package/dist/resources/templates/go-backend/internal/common/runtimeinput/runtime_input_test.go +245 -0
- package/dist/resources/templates/go-backend/internal/common/semver/errors.go +6 -0
- package/dist/resources/templates/go-backend/internal/common/semver/semver.go +125 -0
- package/dist/resources/templates/go-backend/internal/common/semver/semver_test.go +205 -0
- package/dist/resources/templates/go-backend/internal/common/serviceidentity/audience.go +48 -0
- package/dist/resources/templates/go-backend/internal/common/serviceidentity/audience_test.go +35 -0
- package/dist/resources/templates/go-backend/internal/common/serviceidentity/resource_identifier.go +33 -0
- package/dist/resources/templates/go-backend/internal/common/serviceidentity/resource_identifier_test.go +32 -0
- package/dist/resources/templates/go-backend/internal/common/tradeno/generator.go +99 -0
- package/dist/resources/templates/go-backend/internal/common/tradeno/generator_test.go +396 -0
- package/dist/resources/templates/go-backend/internal/common/tradeno/prefix.go +247 -0
- package/dist/resources/templates/go-backend/internal/common/types/asset_url.go +11 -0
- package/dist/resources/templates/go-backend/internal/common/types/billing.go +89 -0
- package/dist/resources/templates/go-backend/internal/common/types/billing_test.go +77 -0
- package/dist/resources/templates/go-backend/internal/common/types/country.go +74 -0
- package/dist/resources/templates/go-backend/internal/common/types/country_test.go +28 -0
- package/dist/resources/templates/go-backend/internal/common/types/currency.go +60 -0
- package/dist/resources/templates/go-backend/internal/common/types/identifiers.go +41 -0
- package/dist/resources/templates/go-backend/internal/common/types/operator.go +28 -0
- package/dist/resources/templates/go-backend/internal/common/types/subscription_entitlement.go +24 -0
- package/dist/resources/templates/go-backend/internal/common/types/subscription_entitlement_test.go +35 -0
- package/dist/resources/templates/go-backend/internal/common/types/tier.go +72 -0
- package/dist/resources/templates/go-backend/internal/common/types/types.go +411 -0
- package/dist/resources/templates/go-backend/internal/common/types/types_test.go +295 -0
- package/dist/resources/templates/go-backend/internal/common/utils/constants.go +100 -0
- package/dist/resources/templates/go-backend/internal/common/utils/crypto.go +158 -0
- package/dist/resources/templates/go-backend/internal/common/utils/crypto_test.go +345 -0
- package/dist/resources/templates/go-backend/internal/common/utils/duration.go +25 -0
- package/dist/resources/templates/go-backend/internal/common/utils/helpers.go +18 -0
- package/dist/resources/templates/go-backend/internal/common/utils/json.go +62 -0
- package/dist/resources/templates/go-backend/internal/common/utils/json_test.go +76 -0
- package/dist/resources/templates/go-backend/internal/common/utils/pagination.go +51 -0
- package/dist/resources/templates/go-backend/internal/common/utils/pagination_test.go +45 -0
- package/dist/resources/templates/go-backend/internal/common/utils/pointer.go +107 -0
- package/dist/resources/templates/go-backend/internal/common/utils/pointer_test.go +15 -0
- package/dist/resources/templates/go-backend/internal/common/utils/slice.go +24 -0
- package/dist/resources/templates/go-backend/internal/common/utils/snowflake.go +110 -0
- package/dist/resources/templates/go-backend/internal/common/utils/snowflake_test.go +316 -0
- package/dist/resources/templates/go-backend/internal/common/utils/string.go +16 -0
- package/dist/resources/templates/go-backend/internal/common/utils/timefmt.go +42 -0
- package/dist/resources/templates/go-backend/internal/common/validator/validator.go +136 -0
- package/dist/resources/templates/go-backend/internal/common/validator/validator_test.go +240 -0
- package/dist/resources/templates/go-backend/internal/common/youtubeapi/client.go +224 -0
- package/dist/resources/templates/go-backend/internal/core/apicontract/document.go +269 -0
- package/dist/resources/templates/go-backend/internal/core/apicontract/document_test.go +104 -0
- package/dist/resources/templates/go-backend/internal/core/apicontract/route_validator.go +78 -0
- package/dist/resources/templates/go-backend/internal/core/apicontract/route_validator_test.go +108 -0
- package/dist/resources/templates/go-backend/internal/core/apidocs/assets/scalar-api-reference.js +2385 -0
- package/dist/resources/templates/go-backend/internal/core/apidocs/assets/scalar-api-reference.metadata.json +10 -0
- package/dist/resources/templates/go-backend/internal/core/apidocs/route.go +107 -0
- package/dist/resources/templates/go-backend/internal/core/apidocs/route_test.go +200 -0
- package/dist/resources/templates/go-backend/internal/core/apidocs/scalar.go +117 -0
- package/dist/resources/templates/go-backend/internal/core/apidocs/scalar_test.go +99 -0
- package/dist/resources/templates/go-backend/internal/core/audit/access_log_policy.go +91 -0
- package/dist/resources/templates/go-backend/internal/core/audit/access_log_policy_test.go +51 -0
- package/dist/resources/templates/go-backend/internal/core/audit/actor_resolver.go +36 -0
- package/dist/resources/templates/go-backend/internal/core/audit/constants.go +30 -0
- package/dist/resources/templates/go-backend/internal/core/audit/context.go +119 -0
- package/dist/resources/templates/go-backend/internal/core/audit/context_test.go +310 -0
- package/dist/resources/templates/go-backend/internal/core/audit/dto.go +468 -0
- package/dist/resources/templates/go-backend/internal/core/audit/dto_admin.go +172 -0
- package/dist/resources/templates/go-backend/internal/core/audit/enum.go +460 -0
- package/dist/resources/templates/go-backend/internal/core/audit/enum_test.go +314 -0
- package/dist/resources/templates/go-backend/internal/core/audit/errors.go +9 -0
- package/dist/resources/templates/go-backend/internal/core/audit/handler.go +568 -0
- package/dist/resources/templates/go-backend/internal/core/audit/listener.go +319 -0
- package/dist/resources/templates/go-backend/internal/core/audit/listener_test.go +98 -0
- package/dist/resources/templates/go-backend/internal/core/audit/middleware.go +669 -0
- package/dist/resources/templates/go-backend/internal/core/audit/middleware_test.go +268 -0
- package/dist/resources/templates/go-backend/internal/core/audit/model.go +306 -0
- package/dist/resources/templates/go-backend/internal/core/audit/partition_job.go +316 -0
- package/dist/resources/templates/go-backend/internal/core/audit/ports.go +9 -0
- package/dist/resources/templates/go-backend/internal/core/audit/provider.go +30 -0
- package/dist/resources/templates/go-backend/internal/core/audit/repository.go +1007 -0
- package/dist/resources/templates/go-backend/internal/core/audit/repository_test.go +934 -0
- package/dist/resources/templates/go-backend/internal/core/audit/router.go +85 -0
- package/dist/resources/templates/go-backend/internal/core/audit/service.go +770 -0
- package/dist/resources/templates/go-backend/internal/core/audit/service_test.go +331 -0
- package/dist/resources/templates/go-backend/internal/core/audit/vo_admin.go +475 -0
- package/dist/resources/templates/go-backend/internal/core/cache/config.go +30 -0
- package/dist/resources/templates/go-backend/internal/core/cache/key.go +41 -0
- package/dist/resources/templates/go-backend/internal/core/cache/key_test.go +62 -0
- package/dist/resources/templates/go-backend/internal/core/cache/l1.go +153 -0
- package/dist/resources/templates/go-backend/internal/core/cache/l1_test.go +212 -0
- package/dist/resources/templates/go-backend/internal/core/cache/manager.go +278 -0
- package/dist/resources/templates/go-backend/internal/core/cache/manager_provider.go +24 -0
- package/dist/resources/templates/go-backend/internal/core/cache/metrics.go +126 -0
- package/dist/resources/templates/go-backend/internal/core/cache/namespace.go +46 -0
- package/dist/resources/templates/go-backend/internal/core/cache/namespace_test.go +90 -0
- package/dist/resources/templates/go-backend/internal/core/cache/options.go +39 -0
- package/dist/resources/templates/go-backend/internal/core/cache/options_test.go +96 -0
- package/dist/resources/templates/go-backend/internal/core/cache/redis.go +311 -0
- package/dist/resources/templates/go-backend/internal/core/cache/redis_test.go +51 -0
- package/dist/resources/templates/go-backend/internal/core/cache/serializer.go +31 -0
- package/dist/resources/templates/go-backend/internal/core/cache/serializer_test.go +139 -0
- package/dist/resources/templates/go-backend/internal/core/cache/singleflight.go +53 -0
- package/dist/resources/templates/go-backend/internal/core/cache/singleflight_test.go +211 -0
- package/dist/resources/templates/go-backend/internal/core/cache/warming.go +86 -0
- package/dist/resources/templates/go-backend/internal/core/clock/clock.go +66 -0
- package/dist/resources/templates/go-backend/internal/core/clock/clock_test.go +26 -0
- package/dist/resources/templates/go-backend/internal/core/clock/runtime_clock.go +283 -0
- package/dist/resources/templates/go-backend/internal/core/clock/runtime_clock_test.go +98 -0
- package/dist/resources/templates/go-backend/internal/core/commandreplay/errors.go +6 -0
- package/dist/resources/templates/go-backend/internal/core/commandreplay/model.go +90 -0
- package/dist/resources/templates/go-backend/internal/core/commandreplay/model_test.go +79 -0
- package/dist/resources/templates/go-backend/internal/core/commandreplay/namespace.go +7 -0
- package/dist/resources/templates/go-backend/internal/core/commandreplay/persistence.go +269 -0
- package/dist/resources/templates/go-backend/internal/core/commandreplay/persistence_test.go +185 -0
- package/dist/resources/templates/go-backend/internal/core/commandreplay/provider.go +9 -0
- package/dist/resources/templates/go-backend/internal/core/commandreplay/repository.go +22 -0
- package/dist/resources/templates/go-backend/internal/core/commandreplay/service.go +853 -0
- package/dist/resources/templates/go-backend/internal/core/commandreplay/service_persistence_test.go +432 -0
- package/dist/resources/templates/go-backend/internal/core/commandreplay/service_test.go +891 -0
- package/dist/resources/templates/go-backend/internal/core/commandreplay/types.go +121 -0
- package/dist/resources/templates/go-backend/internal/core/config/config.go +2069 -0
- package/dist/resources/templates/go-backend/internal/core/config/config_test.go +1122 -0
- package/dist/resources/templates/go-backend/internal/core/config/contract/contract_test.go +388 -0
- package/dist/resources/templates/go-backend/internal/core/config/contract/docs.go +198 -0
- package/dist/resources/templates/go-backend/internal/core/config/contract/verify.go +424 -0
- package/dist/resources/templates/go-backend/internal/core/config/enum.go +46 -0
- package/dist/resources/templates/go-backend/internal/core/config/metadata.go +717 -0
- package/dist/resources/templates/go-backend/internal/core/config/metadata_test.go +228 -0
- package/dist/resources/templates/go-backend/internal/core/config/product_admin_config_test.go +210 -0
- package/dist/resources/templates/go-backend/internal/core/crypto/aes_gcm.go +111 -0
- package/dist/resources/templates/go-backend/internal/core/crypto/aes_gcm_test.go +364 -0
- package/dist/resources/templates/go-backend/internal/core/crypto/encryptor.go +12 -0
- package/dist/resources/templates/go-backend/internal/core/crypto/envelope_encryptor.go +134 -0
- package/dist/resources/templates/go-backend/internal/core/crypto/envelope_encryptor_test.go +118 -0
- package/dist/resources/templates/go-backend/internal/core/crypto/pem.go +112 -0
- package/dist/resources/templates/go-backend/internal/core/crypto/pem_test.go +44 -0
- package/dist/resources/templates/go-backend/internal/core/crypto/provider.go +130 -0
- package/dist/resources/templates/go-backend/internal/core/crypto/provider_test.go +92 -0
- package/dist/resources/templates/go-backend/internal/core/database/base_model.go +24 -0
- package/dist/resources/templates/go-backend/internal/core/database/clickhouse.go +121 -0
- package/dist/resources/templates/go-backend/internal/core/database/database.go +112 -0
- package/dist/resources/templates/go-backend/internal/core/database/database_logger_test.go +95 -0
- package/dist/resources/templates/go-backend/internal/core/database/errors.go +25 -0
- package/dist/resources/templates/go-backend/internal/core/database/metrics_plugin.go +105 -0
- package/dist/resources/templates/go-backend/internal/core/database/pool_collector.go +71 -0
- package/dist/resources/templates/go-backend/internal/core/database/read_replica.go +520 -0
- package/dist/resources/templates/go-backend/internal/core/database/transaction.go +170 -0
- package/dist/resources/templates/go-backend/internal/core/database/transaction_test.go +282 -0
- package/dist/resources/templates/go-backend/internal/core/distlock/lock.go +353 -0
- package/dist/resources/templates/go-backend/internal/core/distlock/lock_test.go +106 -0
- package/dist/resources/templates/go-backend/internal/core/errors/handler.go +189 -0
- package/dist/resources/templates/go-backend/internal/core/errors/handler_test.go +515 -0
- package/dist/resources/templates/go-backend/internal/core/eventbus/eventbus.go +667 -0
- package/dist/resources/templates/go-backend/internal/core/eventbus/eventbus_test.go +792 -0
- package/dist/resources/templates/go-backend/internal/core/eventstream/noop.go +22 -0
- package/dist/resources/templates/go-backend/internal/core/eventstream/provider.go +20 -0
- package/dist/resources/templates/go-backend/internal/core/eventstream/publisher.go +38 -0
- package/dist/resources/templates/go-backend/internal/core/eventstream/redis.go +109 -0
- package/dist/resources/templates/go-backend/internal/core/eventstream/routing.go +104 -0
- package/dist/resources/templates/go-backend/internal/core/eventstream/routing_test.go +71 -0
- package/dist/resources/templates/go-backend/internal/core/geoip/model.go +19 -0
- package/dist/resources/templates/go-backend/internal/core/geoip/service.go +88 -0
- package/dist/resources/templates/go-backend/internal/core/health/health.go +333 -0
- package/dist/resources/templates/go-backend/internal/core/health/health_test.go +27 -0
- package/dist/resources/templates/go-backend/internal/core/httpclient/client.go +772 -0
- package/dist/resources/templates/go-backend/internal/core/httpclient/client_test.go +287 -0
- package/dist/resources/templates/go-backend/internal/core/httpclient/download.go +578 -0
- package/dist/resources/templates/go-backend/internal/core/httpclient/download_test.go +374 -0
- package/dist/resources/templates/go-backend/internal/core/jwtkeyring/jwk.go +38 -0
- package/dist/resources/templates/go-backend/internal/core/jwtkeyring/keyring.go +144 -0
- package/dist/resources/templates/go-backend/internal/core/jwtkeyring/keyring_test.go +128 -0
- package/dist/resources/templates/go-backend/internal/core/jwtkeyring/registry.go +60 -0
- package/dist/resources/templates/go-backend/internal/core/logger/logger.go +53 -0
- package/dist/resources/templates/go-backend/internal/core/logger/logger_test.go +194 -0
- package/dist/resources/templates/go-backend/internal/core/observability/metrics.go +358 -0
- package/dist/resources/templates/go-backend/internal/core/observability/sentry.go +445 -0
- package/dist/resources/templates/go-backend/internal/core/observability/sentry_privacy_test.go +175 -0
- package/dist/resources/templates/go-backend/internal/core/observability/tracing.go +187 -0
- package/dist/resources/templates/go-backend/internal/core/outbox/model.go +314 -0
- package/dist/resources/templates/go-backend/internal/core/outbox/model_test.go +77 -0
- package/dist/resources/templates/go-backend/internal/core/outbox/persistence.go +51 -0
- package/dist/resources/templates/go-backend/internal/core/outbox/provider.go +23 -0
- package/dist/resources/templates/go-backend/internal/core/outbox/relay.go +1138 -0
- package/dist/resources/templates/go-backend/internal/core/outbox/relay_postgres_test.go +257 -0
- package/dist/resources/templates/go-backend/internal/core/outbox/relay_test.go +690 -0
- package/dist/resources/templates/go-backend/internal/core/outbox/rescheduler.go +164 -0
- package/dist/resources/templates/go-backend/internal/core/outbox/rescheduler_test.go +209 -0
- package/dist/resources/templates/go-backend/internal/core/outbox/writer.go +249 -0
- package/dist/resources/templates/go-backend/internal/core/outbox/writer_postgres_test.go +170 -0
- package/dist/resources/templates/go-backend/internal/core/outbox/writer_test.go +123 -0
- package/dist/resources/templates/go-backend/internal/core/provider.go +198 -0
- package/dist/resources/templates/go-backend/internal/core/queue/metrics_middleware.go +38 -0
- package/dist/resources/templates/go-backend/internal/core/queue/metrics_middleware_test.go +12 -0
- package/dist/resources/templates/go-backend/internal/core/queue/queue.go +288 -0
- package/dist/resources/templates/go-backend/internal/core/queue/queue_test.go +159 -0
- package/dist/resources/templates/go-backend/internal/core/resilience/bulkhead.go +514 -0
- package/dist/resources/templates/go-backend/internal/core/resilience/bulkhead_test.go +984 -0
- package/dist/resources/templates/go-backend/internal/core/resilience/circuitbreaker.go +358 -0
- package/dist/resources/templates/go-backend/internal/core/resilience/circuitbreaker_test.go +788 -0
- package/dist/resources/templates/go-backend/internal/core/resilience/retry.go +318 -0
- package/dist/resources/templates/go-backend/internal/core/resilience/retry_test.go +735 -0
- package/dist/resources/templates/go-backend/internal/core/schedule/recorder.go +305 -0
- package/dist/resources/templates/go-backend/internal/core/schedule/run_context.go +124 -0
- package/dist/resources/templates/go-backend/internal/core/schedule/run_context_test.go +85 -0
- package/dist/resources/templates/go-backend/internal/core/schedule/scheduler.go +1589 -0
- package/dist/resources/templates/go-backend/internal/core/schedule/scheduler_control_test.go +808 -0
- package/dist/resources/templates/go-backend/internal/core/storage/oss_provider.go +398 -0
- package/dist/resources/templates/go-backend/internal/core/storage/oss_provider_test.go +89 -0
- package/dist/resources/templates/go-backend/internal/core/storage/path.go +110 -0
- package/dist/resources/templates/go-backend/internal/core/storage/path_test.go +301 -0
- package/dist/resources/templates/go-backend/internal/core/storage/s3_provider.go +489 -0
- package/dist/resources/templates/go-backend/internal/core/storage/s3_provider_test.go +60 -0
- package/dist/resources/templates/go-backend/internal/core/storage/storage.go +268 -0
- package/dist/resources/templates/go-backend/internal/core/storage/validation.go +225 -0
- package/dist/resources/templates/go-backend/internal/core/storage/validation_test.go +495 -0
- package/dist/resources/templates/go-backend/internal/core/temporal/logger.go +38 -0
- package/dist/resources/templates/go-backend/internal/core/temporal/provider.go +126 -0
- package/dist/resources/templates/go-backend/internal/core/temporal/provider_test.go +67 -0
- package/dist/resources/templates/go-backend/internal/core/websocket/client.go +282 -0
- package/dist/resources/templates/go-backend/internal/core/websocket/client_test.go +81 -0
- package/dist/resources/templates/go-backend/internal/core/websocket/config.go +58 -0
- package/dist/resources/templates/go-backend/internal/core/websocket/handler.go +53 -0
- package/dist/resources/templates/go-backend/internal/core/websocket/hub.go +269 -0
- package/dist/resources/templates/go-backend/internal/core/websocket/message.go +273 -0
- package/dist/resources/templates/go-backend/internal/core/websocket/notifier.go +92 -0
- package/dist/resources/templates/go-backend/internal/core/websocket/provider.go +33 -0
- package/dist/resources/templates/go-backend/internal/integrations/onex/iam/action.go +77 -0
- package/dist/resources/templates/go-backend/internal/integrations/onex/iam/action_test.go +238 -0
- package/dist/resources/templates/go-backend/internal/integrations/onex/iam/condition.go +107 -0
- package/dist/resources/templates/go-backend/internal/integrations/onex/iam/decision.go +256 -0
- package/dist/resources/templates/go-backend/internal/integrations/onex/iam/enum.go +643 -0
- package/dist/resources/templates/go-backend/internal/integrations/onex/iam/errors.go +102 -0
- package/dist/resources/templates/go-backend/internal/integrations/onex/iam/principal_record.go +21 -0
- package/dist/resources/templates/go-backend/internal/integrations/onex/iam/product_context.go +486 -0
- package/dist/resources/templates/go-backend/internal/integrations/onex/iam/resource.go +215 -0
- package/dist/resources/templates/go-backend/internal/integrations/onex/iam/resource_test.go +242 -0
- package/dist/resources/templates/go-backend/internal/products/README.md +5 -0
- package/dist/resources/templates/go-backend/internal/sharedevents/README.md +5 -0
- package/dist/resources/templates/go-backend/migrations/000001_infrastructure.down.sql +13 -0
- package/dist/resources/templates/go-backend/migrations/000001_infrastructure.up.sql +886 -0
- package/dist/resources/templates/go-backend/pkg/apierror/error.go +327 -0
- package/dist/resources/templates/go-backend/pkg/apierror/error_code.go +65 -0
- package/dist/resources/templates/go-backend/pkg/apierror/error_test.go +41 -0
- package/dist/resources/templates/go-backend/pkg/apierror/error_type.go +14 -0
- package/dist/resources/templates/go-backend/pkg/apierror/http_response.go +216 -0
- package/dist/resources/templates/go-backend/pkg/apierror/http_response_test.go +216 -0
- package/dist/resources/templates/go-backend/scripts/check-openapi-clean-deletion.sh +54 -0
- package/dist/resources/templates/go-backend/scripts/test-migrations.sh +32 -0
- package/dist/resources/templates/go-backend/tests/infrastructure.sql +69 -0
- package/dist/resources/templates/mcp-server/.claude/docs/stack.md +338 -0
- package/dist/resources/templates/mcp-server/.editorconfig +13 -0
- package/dist/resources/templates/mcp-server/.env.example +8 -0
- package/dist/resources/templates/mcp-server/.github/ISSUE_TEMPLATE/bug_report.yml +104 -0
- package/dist/resources/templates/mcp-server/.github/ISSUE_TEMPLATE/feature_request.yml +54 -0
- package/dist/resources/templates/mcp-server/.github/PULL_REQUEST_TEMPLATE.md +36 -0
- package/dist/resources/templates/mcp-server/.github/workflows/ci.yml +78 -0
- package/dist/resources/templates/mcp-server/.husky/commit-msg +1 -0
- package/dist/resources/templates/mcp-server/.husky/pre-commit +1 -0
- package/dist/resources/templates/mcp-server/.lintstagedrc.json +4 -0
- package/dist/resources/templates/mcp-server/.nvmrc +1 -0
- package/dist/resources/templates/mcp-server/.prettierrc +8 -0
- package/dist/resources/templates/mcp-server/CONTRIBUTING.md +184 -0
- package/dist/resources/templates/mcp-server/Dockerfile +23 -0
- package/dist/resources/templates/mcp-server/LICENSE +21 -0
- package/dist/resources/templates/mcp-server/README.md +123 -0
- package/dist/resources/templates/mcp-server/_gitignore +26 -0
- package/dist/resources/templates/mcp-server/commitlint.config.js +24 -0
- package/dist/resources/templates/mcp-server/eslint.config.js +30 -0
- package/dist/resources/templates/mcp-server/package.json +72 -0
- package/dist/resources/templates/mcp-server/src/index.ts +27 -0
- package/dist/resources/templates/mcp-server/src/resources.ts +33 -0
- package/dist/resources/templates/mcp-server/src/services/.gitkeep +0 -0
- package/dist/resources/templates/mcp-server/src/tools.ts +43 -0
- package/dist/resources/templates/mcp-server/src/types/index.ts +19 -0
- package/dist/resources/templates/mcp-server/src/utils/index.ts +31 -0
- package/dist/resources/templates/mcp-server/tsconfig.json +22 -0
- package/dist/resources/templates/mcp-server/tsup.config.ts +14 -0
- package/dist/resources/templates/mcp-server/vitest.config.ts +15 -0
- package/dist/resources/templates/nuxt/.claude/docs/stack.md +666 -0
- package/dist/resources/templates/nuxt/.editorconfig +15 -0
- package/dist/resources/templates/nuxt/.env.example +22 -0
- package/dist/resources/templates/nuxt/.github/workflows/ci.yml +34 -0
- package/dist/resources/templates/nuxt/.husky/commit-msg +1 -0
- package/dist/resources/templates/nuxt/.husky/pre-commit +1 -0
- package/dist/resources/templates/nuxt/.nvmrc +1 -0
- package/dist/resources/templates/nuxt/.prettierignore +9 -0
- package/dist/resources/templates/nuxt/.prettierrc +1 -0
- package/dist/resources/templates/nuxt/README.md +23 -0
- package/dist/resources/templates/nuxt/_gitignore +7 -0
- package/dist/resources/templates/nuxt/app/app.config.ts +105 -0
- package/dist/resources/templates/nuxt/app/i18n/locales/en.json +5 -0
- package/dist/resources/templates/nuxt/app/pages/app/index.vue +224 -0
- package/dist/resources/templates/nuxt/app/pages/authors/[slug].vue +37 -0
- package/dist/resources/templates/nuxt/app/pages/blog/[slug].vue +55 -0
- package/dist/resources/templates/nuxt/app/pages/blog/category/[category].vue +38 -0
- package/dist/resources/templates/nuxt/app/pages/blog/index.vue +46 -0
- package/dist/resources/templates/nuxt/app/pages/index.vue +626 -0
- package/dist/resources/templates/nuxt/app/pages/legal/privacy.vue +21 -0
- package/dist/resources/templates/nuxt/app/pages/legal/terms.vue +21 -0
- package/dist/resources/templates/nuxt/app/pages/ui/index.vue +397 -0
- package/dist/resources/templates/nuxt/commitlint.config.mjs +1 -0
- package/dist/resources/templates/nuxt/eslint.config.mjs +4 -0
- package/dist/resources/templates/nuxt/lint-staged.config.mjs +8 -0
- package/dist/resources/templates/nuxt/nuxt.config.ts +71 -0
- package/dist/resources/templates/nuxt/package.json +67 -0
- package/dist/resources/templates/nuxt/public/apple-touch-icon.png +0 -0
- package/dist/resources/templates/nuxt/public/favicon.ico +0 -0
- package/dist/resources/templates/nuxt/public/favicon.svg +5 -0
- package/dist/resources/templates/nuxt/public/icon-16x16.png +0 -0
- package/dist/resources/templates/nuxt/public/icon-192x192.png +0 -0
- package/dist/resources/templates/nuxt/public/icon-32x32.png +0 -0
- package/dist/resources/templates/nuxt/public/icon-512x512.png +0 -0
- package/dist/resources/templates/nuxt/public/logo.svg +6 -0
- package/dist/resources/templates/nuxt/public/media/hero-product-gallery.png +0 -0
- package/dist/resources/templates/nuxt/server/api/content/sitemap-urls.get.ts +12 -0
- package/dist/resources/templates/nuxt/server/api/preview.get.ts +9 -0
- package/dist/resources/templates/nuxt/stylelint.config.mjs +3 -0
- package/dist/resources/templates/nuxt/test/e2e/rendering.test.ts +13 -0
- package/dist/resources/templates/nuxt/tsconfig.json +3 -0
- package/dist/resources/templates/nuxt/vitest.config.ts +8 -0
- package/package.json +16 -12
|
@@ -0,0 +1,735 @@
|
|
|
1
|
+
package resilience
|
|
2
|
+
|
|
3
|
+
import (
|
|
4
|
+
"context"
|
|
5
|
+
"errors"
|
|
6
|
+
"fmt"
|
|
7
|
+
"sync"
|
|
8
|
+
"sync/atomic"
|
|
9
|
+
"testing"
|
|
10
|
+
"time"
|
|
11
|
+
|
|
12
|
+
"github.com/stretchr/testify/assert"
|
|
13
|
+
"github.com/stretchr/testify/require"
|
|
14
|
+
"go.uber.org/zap"
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
// newTestLogger 构建静默 zap logger,避免测试输出噪音
|
|
18
|
+
func newTestLogger() *zap.Logger {
|
|
19
|
+
return zap.NewNop()
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// newFastConfig 构建零延迟重试配置,避免测试等待真实退避时长
|
|
23
|
+
func newFastConfig() RetryConfig {
|
|
24
|
+
return RetryConfig{
|
|
25
|
+
MaxAttempts: 3,
|
|
26
|
+
InitialDelay: time.Millisecond,
|
|
27
|
+
MaxDelay: 10 * time.Millisecond,
|
|
28
|
+
BackoffMultiplier: 2,
|
|
29
|
+
Jitter: false,
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// ═══════════════════════════════════════════════════════════════
|
|
34
|
+
// 1. NewRetryService — 构造验证
|
|
35
|
+
// ═══════════════════════════════════════════════════════════════
|
|
36
|
+
|
|
37
|
+
func TestRetryService_NewService_DefaultConfig(t *testing.T) {
|
|
38
|
+
svc := NewRetryService(newTestLogger())
|
|
39
|
+
require.NotNil(t, svc)
|
|
40
|
+
assert.Equal(t, DefaultRetryConfig.MaxAttempts, svc.globalConfig.MaxAttempts)
|
|
41
|
+
assert.Equal(t, DefaultRetryConfig.InitialDelay, svc.globalConfig.InitialDelay)
|
|
42
|
+
assert.Equal(t, DefaultRetryConfig.MaxDelay, svc.globalConfig.MaxDelay)
|
|
43
|
+
assert.Equal(t, DefaultRetryConfig.BackoffMultiplier, svc.globalConfig.BackoffMultiplier)
|
|
44
|
+
assert.True(t, svc.globalConfig.Jitter)
|
|
45
|
+
assert.NotNil(t, svc.retries)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
func TestRetryService_NewService_CustomConfig(t *testing.T) {
|
|
49
|
+
cfg := RetryConfig{
|
|
50
|
+
MaxAttempts: 5,
|
|
51
|
+
InitialDelay: 500 * time.Millisecond,
|
|
52
|
+
MaxDelay: 5 * time.Second,
|
|
53
|
+
BackoffMultiplier: 1.5,
|
|
54
|
+
Jitter: false,
|
|
55
|
+
}
|
|
56
|
+
svc := NewRetryService(newTestLogger(), cfg)
|
|
57
|
+
require.NotNil(t, svc)
|
|
58
|
+
assert.Equal(t, 5, svc.globalConfig.MaxAttempts)
|
|
59
|
+
assert.Equal(t, 500*time.Millisecond, svc.globalConfig.InitialDelay)
|
|
60
|
+
assert.InDelta(t, 1.5, svc.globalConfig.BackoffMultiplier, 0.001)
|
|
61
|
+
assert.False(t, svc.globalConfig.Jitter)
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// ═══════════════════════════════════════════════════════════════
|
|
65
|
+
// 2. 首次尝试成功 — 无重试
|
|
66
|
+
// ═══════════════════════════════════════════════════════════════
|
|
67
|
+
|
|
68
|
+
func TestRetryService_SuccessOnFirstAttempt(t *testing.T) {
|
|
69
|
+
svc := NewRetryService(newTestLogger(), newFastConfig())
|
|
70
|
+
|
|
71
|
+
callCount := 0
|
|
72
|
+
err := svc.Execute("op-success", func() error {
|
|
73
|
+
callCount++
|
|
74
|
+
return nil
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
require.NoError(t, err)
|
|
78
|
+
assert.Equal(t, 1, callCount, "首次成功应仅调用一次")
|
|
79
|
+
|
|
80
|
+
stats := svc.GetStats("op-success")
|
|
81
|
+
require.NotNil(t, stats)
|
|
82
|
+
assert.Equal(t, int64(1), stats.TotalExecutions)
|
|
83
|
+
assert.Equal(t, int64(0), stats.TotalRetries)
|
|
84
|
+
assert.Equal(t, int64(0), stats.RetriedSuccessCount)
|
|
85
|
+
assert.Equal(t, int64(0), stats.ExhaustedCount)
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// ═══════════════════════════════════════════════════════════════
|
|
89
|
+
// 3. 瞬时失败后成功 — 正确重试次数
|
|
90
|
+
// ═══════════════════════════════════════════════════════════════
|
|
91
|
+
|
|
92
|
+
func TestRetryService_TransientFailureThenSuccess(t *testing.T) {
|
|
93
|
+
svc := NewRetryService(newTestLogger(), newFastConfig())
|
|
94
|
+
|
|
95
|
+
callCount := 0
|
|
96
|
+
sentinelErr := errors.New("transient error")
|
|
97
|
+
|
|
98
|
+
// 前两次失败,第三次成功
|
|
99
|
+
err := svc.Execute("op-transient", func() error {
|
|
100
|
+
callCount++
|
|
101
|
+
if callCount < 3 {
|
|
102
|
+
return sentinelErr
|
|
103
|
+
}
|
|
104
|
+
return nil
|
|
105
|
+
})
|
|
106
|
+
|
|
107
|
+
require.NoError(t, err)
|
|
108
|
+
assert.Equal(t, 3, callCount, "应尝试三次")
|
|
109
|
+
|
|
110
|
+
stats := svc.GetStats("op-transient")
|
|
111
|
+
require.NotNil(t, stats)
|
|
112
|
+
assert.Equal(t, int64(1), stats.TotalExecutions)
|
|
113
|
+
assert.Equal(t, int64(2), stats.TotalRetries, "应记录两次重试")
|
|
114
|
+
assert.Equal(t, int64(1), stats.RetriedSuccessCount, "重试后成功计数应为 1")
|
|
115
|
+
assert.Equal(t, int64(0), stats.ExhaustedCount)
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// ═══════════════════════════════════════════════════════════════
|
|
119
|
+
// 4. 重试耗尽 — 返回 RetryExhaustedError 包装最后一个错误
|
|
120
|
+
// ═══════════════════════════════════════════════════════════════
|
|
121
|
+
|
|
122
|
+
func TestRetryService_AllRetriesExhausted(t *testing.T) {
|
|
123
|
+
svc := NewRetryService(newTestLogger(), newFastConfig())
|
|
124
|
+
|
|
125
|
+
callCount := 0
|
|
126
|
+
lastErr := errors.New("persistent failure")
|
|
127
|
+
|
|
128
|
+
err := svc.Execute("op-exhausted", func() error {
|
|
129
|
+
callCount++
|
|
130
|
+
return lastErr
|
|
131
|
+
})
|
|
132
|
+
|
|
133
|
+
require.Error(t, err)
|
|
134
|
+
assert.Equal(t, 3, callCount, "MaxAttempts=3 时应尝试三次")
|
|
135
|
+
|
|
136
|
+
var exhausted *RetryExhaustedError
|
|
137
|
+
require.True(t, errors.As(err, &exhausted), "错误类型应为 RetryExhaustedError")
|
|
138
|
+
assert.Equal(t, "op-exhausted", exhausted.Key)
|
|
139
|
+
assert.Equal(t, 3, exhausted.Attempts)
|
|
140
|
+
assert.Equal(t, lastErr, exhausted.LastError)
|
|
141
|
+
// Unwrap 应返回原始错误
|
|
142
|
+
assert.True(t, errors.Is(err, lastErr), "errors.Is 应能穿透 RetryExhaustedError")
|
|
143
|
+
|
|
144
|
+
stats := svc.GetStats("op-exhausted")
|
|
145
|
+
require.NotNil(t, stats)
|
|
146
|
+
assert.Equal(t, int64(1), stats.TotalExecutions)
|
|
147
|
+
assert.Equal(t, int64(1), stats.ExhaustedCount)
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
func TestRetryService_RetryExhaustedError_Message(t *testing.T) {
|
|
151
|
+
inner := errors.New("inner err")
|
|
152
|
+
e := &RetryExhaustedError{Key: "mykey", Attempts: 5, LastError: inner}
|
|
153
|
+
msg := e.Error()
|
|
154
|
+
assert.Contains(t, msg, "mykey")
|
|
155
|
+
assert.Contains(t, msg, "5")
|
|
156
|
+
assert.Contains(t, msg, "inner err")
|
|
157
|
+
assert.Equal(t, inner, e.Unwrap())
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// ═══════════════════════════════════════════════════════════════
|
|
161
|
+
// 5. RetryableCheck — 仅当谓词返回 true 时重试
|
|
162
|
+
// ═══════════════════════════════════════════════════════════════
|
|
163
|
+
|
|
164
|
+
func TestRetryService_RetryableCheck_OnlyRetriesWhenTrue(t *testing.T) {
|
|
165
|
+
svc := NewRetryService(newTestLogger(), newFastConfig())
|
|
166
|
+
|
|
167
|
+
retryableErr := errors.New("retryable")
|
|
168
|
+
nonRetryableErr := errors.New("not retryable")
|
|
169
|
+
|
|
170
|
+
callCount := 0
|
|
171
|
+
// 第一次返回 nonRetryableErr,check 返回 false,应立即停止
|
|
172
|
+
err := svc.Execute("op-check", func() error {
|
|
173
|
+
callCount++
|
|
174
|
+
return nonRetryableErr
|
|
175
|
+
}, RetryOptions{
|
|
176
|
+
RetryableCheck: func(e error) bool {
|
|
177
|
+
return errors.Is(e, retryableErr)
|
|
178
|
+
},
|
|
179
|
+
})
|
|
180
|
+
|
|
181
|
+
require.Error(t, err)
|
|
182
|
+
assert.Equal(t, 1, callCount, "不可重试错误应立即终止")
|
|
183
|
+
assert.Equal(t, nonRetryableErr, err, "应直接返回原始错误,而非 RetryExhaustedError")
|
|
184
|
+
|
|
185
|
+
var exhausted *RetryExhaustedError
|
|
186
|
+
assert.False(t, errors.As(err, &exhausted), "不应包装为 RetryExhaustedError")
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
func TestRetryService_RetryableCheck_RetriesWhenTrue(t *testing.T) {
|
|
190
|
+
svc := NewRetryService(newTestLogger(), newFastConfig())
|
|
191
|
+
|
|
192
|
+
retryableErr := errors.New("retryable")
|
|
193
|
+
callCount := 0
|
|
194
|
+
|
|
195
|
+
err := svc.Execute("op-check-retryable", func() error {
|
|
196
|
+
callCount++
|
|
197
|
+
return retryableErr
|
|
198
|
+
}, RetryOptions{
|
|
199
|
+
RetryableCheck: func(e error) bool {
|
|
200
|
+
return errors.Is(e, retryableErr)
|
|
201
|
+
},
|
|
202
|
+
})
|
|
203
|
+
|
|
204
|
+
require.Error(t, err)
|
|
205
|
+
assert.Equal(t, 3, callCount, "可重试错误应耗尽全部 MaxAttempts")
|
|
206
|
+
|
|
207
|
+
var exhausted *RetryExhaustedError
|
|
208
|
+
assert.True(t, errors.As(err, &exhausted))
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
// ═══════════════════════════════════════════════════════════════
|
|
212
|
+
// 6. 不可重试错误 — 立即失败,无重试
|
|
213
|
+
// ═══════════════════════════════════════════════════════════════
|
|
214
|
+
|
|
215
|
+
func TestRetryService_NonRetryableError_StopsImmediately(t *testing.T) {
|
|
216
|
+
cfg := newFastConfig()
|
|
217
|
+
// 在配置层设置 RetryableCheck,只有特定错误可重试
|
|
218
|
+
retryable := errors.New("ok to retry")
|
|
219
|
+
cfg.RetryableCheck = func(e error) bool {
|
|
220
|
+
return errors.Is(e, retryable)
|
|
221
|
+
}
|
|
222
|
+
svc := NewRetryService(newTestLogger(), cfg)
|
|
223
|
+
svc.ConfigureRetry("op-non-retryable", cfg)
|
|
224
|
+
|
|
225
|
+
callCount := 0
|
|
226
|
+
fatal := errors.New("fatal error")
|
|
227
|
+
|
|
228
|
+
err := svc.Execute("op-non-retryable", func() error {
|
|
229
|
+
callCount++
|
|
230
|
+
return fatal
|
|
231
|
+
})
|
|
232
|
+
|
|
233
|
+
require.Error(t, err)
|
|
234
|
+
assert.Equal(t, 1, callCount, "不可重试错误只应执行一次")
|
|
235
|
+
assert.Equal(t, fatal, err)
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
// ═══════════════════════════════════════════════════════════════
|
|
239
|
+
// 7. 指数退避 — 延迟随尝试次数增长
|
|
240
|
+
// ═══════════════════════════════════════════════════════════════
|
|
241
|
+
|
|
242
|
+
func TestRetryService_ExponentialBackoff_DelayIncreases(t *testing.T) {
|
|
243
|
+
cfg := RetryConfig{
|
|
244
|
+
MaxAttempts: 4,
|
|
245
|
+
InitialDelay: 20 * time.Millisecond,
|
|
246
|
+
MaxDelay: 1 * time.Second,
|
|
247
|
+
BackoffMultiplier: 2,
|
|
248
|
+
Jitter: false, // 禁用 jitter 以精确验证
|
|
249
|
+
}
|
|
250
|
+
svc := NewRetryService(newTestLogger(), cfg)
|
|
251
|
+
|
|
252
|
+
var delays []time.Duration
|
|
253
|
+
var mu sync.Mutex
|
|
254
|
+
var lastStart time.Time
|
|
255
|
+
|
|
256
|
+
callCount := 0
|
|
257
|
+
_ = svc.Execute("op-backoff", func() error {
|
|
258
|
+
callCount++
|
|
259
|
+
now := time.Now()
|
|
260
|
+
if callCount > 1 {
|
|
261
|
+
mu.Lock()
|
|
262
|
+
delays = append(delays, now.Sub(lastStart))
|
|
263
|
+
mu.Unlock()
|
|
264
|
+
}
|
|
265
|
+
lastStart = now
|
|
266
|
+
return errors.New("fail")
|
|
267
|
+
})
|
|
268
|
+
|
|
269
|
+
require.Equal(t, 4, callCount)
|
|
270
|
+
require.Len(t, delays, 3, "MaxAttempts=4 应有 3 次间隔")
|
|
271
|
+
|
|
272
|
+
// 验证每个间隔递增(允许 20ms 系统调度误差)
|
|
273
|
+
// attempt1→2: ~20ms, attempt2→3: ~40ms, attempt3→4: ~80ms
|
|
274
|
+
for i := 1; i < len(delays); i++ {
|
|
275
|
+
assert.Greater(t, delays[i], delays[i-1],
|
|
276
|
+
"第 %d 次间隔 (%v) 应大于第 %d 次间隔 (%v)", i+1, delays[i], i, delays[i-1])
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
// ═══════════════════════════════════════════════════════════════
|
|
281
|
+
// 8. 抖动 — 延迟有随机性(在 ±25% 范围内)
|
|
282
|
+
// ═══════════════════════════════════════════════════════════════
|
|
283
|
+
|
|
284
|
+
func TestRetryService_Jitter_DelayWithinBounds(t *testing.T) {
|
|
285
|
+
// 直接测试 calculateDelay 方法,避免 time.Sleep 引起测试缓慢
|
|
286
|
+
svc := NewRetryService(newTestLogger())
|
|
287
|
+
|
|
288
|
+
cfg := RetryConfig{
|
|
289
|
+
InitialDelay: 100 * time.Millisecond,
|
|
290
|
+
MaxDelay: 10 * time.Second,
|
|
291
|
+
BackoffMultiplier: 2,
|
|
292
|
+
Jitter: true,
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
// attempt=1 时 base delay = InitialDelay * multiplier^0 = 100ms
|
|
296
|
+
// ±25% 范围:[75ms, 125ms]
|
|
297
|
+
const baseDelay = 100 * time.Millisecond
|
|
298
|
+
const tolerance = 0.25
|
|
299
|
+
lower := time.Duration(float64(baseDelay) * (1 - tolerance))
|
|
300
|
+
upper := time.Duration(float64(baseDelay) * (1 + tolerance))
|
|
301
|
+
|
|
302
|
+
// 多次采样确认始终在边界内
|
|
303
|
+
seen := make(map[time.Duration]bool)
|
|
304
|
+
for i := 0; i < 100; i++ {
|
|
305
|
+
d := svc.calculateDelay(1, cfg)
|
|
306
|
+
assert.GreaterOrEqual(t, d, lower, "抖动下界违反")
|
|
307
|
+
assert.LessOrEqual(t, d, upper, "抖动上界违反")
|
|
308
|
+
seen[d] = true
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
// 100 次采样应产生多于 1 种延迟值(验证存在随机性)
|
|
312
|
+
assert.Greater(t, len(seen), 1, "抖动应产生不同的延迟值")
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
func TestRetryService_NoJitter_DelayIsDeterministic(t *testing.T) {
|
|
316
|
+
svc := NewRetryService(newTestLogger())
|
|
317
|
+
|
|
318
|
+
cfg := RetryConfig{
|
|
319
|
+
InitialDelay: 50 * time.Millisecond,
|
|
320
|
+
MaxDelay: 10 * time.Second,
|
|
321
|
+
BackoffMultiplier: 2,
|
|
322
|
+
Jitter: false,
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
// attempt=1 → 50ms, attempt=2 → 100ms, attempt=3 → 200ms
|
|
326
|
+
d1 := svc.calculateDelay(1, cfg)
|
|
327
|
+
d2 := svc.calculateDelay(2, cfg)
|
|
328
|
+
d3 := svc.calculateDelay(3, cfg)
|
|
329
|
+
|
|
330
|
+
assert.Equal(t, 50*time.Millisecond, d1)
|
|
331
|
+
assert.Equal(t, 100*time.Millisecond, d2)
|
|
332
|
+
assert.Equal(t, 200*time.Millisecond, d3)
|
|
333
|
+
|
|
334
|
+
// 同一 attempt 多次调用应相同
|
|
335
|
+
for i := 0; i < 10; i++ {
|
|
336
|
+
assert.Equal(t, d1, svc.calculateDelay(1, cfg))
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
func TestRetryService_MaxDelay_IsCapped(t *testing.T) {
|
|
341
|
+
svc := NewRetryService(newTestLogger())
|
|
342
|
+
|
|
343
|
+
cfg := RetryConfig{
|
|
344
|
+
InitialDelay: 100 * time.Millisecond,
|
|
345
|
+
MaxDelay: 150 * time.Millisecond,
|
|
346
|
+
BackoffMultiplier: 10, // 快速超过上限
|
|
347
|
+
Jitter: false,
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
// attempt=2 → 100ms * 10^1 = 1000ms,但 MaxDelay=150ms
|
|
351
|
+
d := svc.calculateDelay(2, cfg)
|
|
352
|
+
assert.LessOrEqual(t, d, 150*time.Millisecond, "延迟不应超过 MaxDelay")
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
// ═══════════════════════════════════════════════════════════════
|
|
356
|
+
// 9. MaxAttempts 配置 — 每次执行可覆盖
|
|
357
|
+
// ═══════════════════════════════════════════════════════════════
|
|
358
|
+
|
|
359
|
+
func TestRetryService_MaxRetries_Respected(t *testing.T) {
|
|
360
|
+
svc := NewRetryService(newTestLogger(), newFastConfig()) // 全局 MaxAttempts=3
|
|
361
|
+
|
|
362
|
+
// 通过 RetryOptions 覆盖为 5 次
|
|
363
|
+
maxAttempts := 5
|
|
364
|
+
callCount := 0
|
|
365
|
+
err := svc.Execute("op-max", func() error {
|
|
366
|
+
callCount++
|
|
367
|
+
return errors.New("fail")
|
|
368
|
+
}, RetryOptions{MaxAttempts: &maxAttempts})
|
|
369
|
+
|
|
370
|
+
require.Error(t, err)
|
|
371
|
+
assert.Equal(t, 5, callCount, "MaxAttempts 覆盖为 5 后应尝试 5 次")
|
|
372
|
+
|
|
373
|
+
var exhausted *RetryExhaustedError
|
|
374
|
+
require.True(t, errors.As(err, &exhausted))
|
|
375
|
+
assert.Equal(t, 5, exhausted.Attempts)
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
func TestRetryService_MaxRetries_One_NoRetry(t *testing.T) {
|
|
379
|
+
svc := NewRetryService(newTestLogger(), newFastConfig())
|
|
380
|
+
|
|
381
|
+
maxAttempts := 1
|
|
382
|
+
callCount := 0
|
|
383
|
+
err := svc.Execute("op-one", func() error {
|
|
384
|
+
callCount++
|
|
385
|
+
return errors.New("fail")
|
|
386
|
+
}, RetryOptions{MaxAttempts: &maxAttempts})
|
|
387
|
+
|
|
388
|
+
require.Error(t, err)
|
|
389
|
+
assert.Equal(t, 1, callCount, "MaxAttempts=1 时只执行一次")
|
|
390
|
+
|
|
391
|
+
var exhausted *RetryExhaustedError
|
|
392
|
+
require.True(t, errors.As(err, &exhausted))
|
|
393
|
+
assert.Equal(t, 1, exhausted.Attempts)
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
// ═══════════════════════════════════════════════════════════════
|
|
397
|
+
// 10. 不同 key 独立统计
|
|
398
|
+
// ═══════════════════════════════════════════════════════════════
|
|
399
|
+
|
|
400
|
+
func TestRetryService_DifferentKeys_IndependentStats(t *testing.T) {
|
|
401
|
+
svc := NewRetryService(newTestLogger(), newFastConfig())
|
|
402
|
+
|
|
403
|
+
// key-a:首次成功
|
|
404
|
+
_ = svc.Execute("key-a", func() error { return nil })
|
|
405
|
+
|
|
406
|
+
// key-b:全部失败(耗尽)
|
|
407
|
+
_ = svc.Execute("key-b", func() error { return errors.New("fail") })
|
|
408
|
+
|
|
409
|
+
statsA := svc.GetStats("key-a")
|
|
410
|
+
statsB := svc.GetStats("key-b")
|
|
411
|
+
|
|
412
|
+
require.NotNil(t, statsA)
|
|
413
|
+
require.NotNil(t, statsB)
|
|
414
|
+
|
|
415
|
+
assert.Equal(t, int64(1), statsA.TotalExecutions)
|
|
416
|
+
assert.Equal(t, int64(0), statsA.TotalRetries)
|
|
417
|
+
assert.Equal(t, int64(0), statsA.ExhaustedCount)
|
|
418
|
+
|
|
419
|
+
assert.Equal(t, int64(1), statsB.TotalExecutions)
|
|
420
|
+
assert.Equal(t, int64(2), statsB.TotalRetries)
|
|
421
|
+
assert.Equal(t, int64(1), statsB.ExhaustedCount)
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
func TestRetryService_ConfigureRetry_PerKeyConfig(t *testing.T) {
|
|
425
|
+
svc := NewRetryService(newTestLogger(), newFastConfig()) // 全局 MaxAttempts=3
|
|
426
|
+
|
|
427
|
+
// key-custom 单独配置为 2 次
|
|
428
|
+
svc.ConfigureRetry("key-custom", RetryConfig{
|
|
429
|
+
MaxAttempts: 2,
|
|
430
|
+
InitialDelay: time.Millisecond,
|
|
431
|
+
MaxDelay: 10 * time.Millisecond,
|
|
432
|
+
BackoffMultiplier: 2,
|
|
433
|
+
Jitter: false,
|
|
434
|
+
})
|
|
435
|
+
|
|
436
|
+
callCount := 0
|
|
437
|
+
err := svc.Execute("key-custom", func() error {
|
|
438
|
+
callCount++
|
|
439
|
+
return errors.New("fail")
|
|
440
|
+
})
|
|
441
|
+
|
|
442
|
+
require.Error(t, err)
|
|
443
|
+
assert.Equal(t, 2, callCount, "per-key MaxAttempts=2 应只尝试 2 次")
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
// ═══════════════════════════════════════════════════════════════
|
|
447
|
+
// 11. GetStats / GetAllStats / ResetStats
|
|
448
|
+
// ═══════════════════════════════════════════════════════════════
|
|
449
|
+
|
|
450
|
+
func TestRetryService_GetStats_UnknownKey_ReturnsNil(t *testing.T) {
|
|
451
|
+
svc := NewRetryService(newTestLogger(), newFastConfig())
|
|
452
|
+
stats := svc.GetStats("nonexistent")
|
|
453
|
+
assert.Nil(t, stats, "未知 key 应返回 nil")
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
func TestRetryService_GetAllStats_ReturnsAllKeys(t *testing.T) {
|
|
457
|
+
svc := NewRetryService(newTestLogger(), newFastConfig())
|
|
458
|
+
|
|
459
|
+
_ = svc.Execute("k1", func() error { return nil })
|
|
460
|
+
_ = svc.Execute("k2", func() error { return errors.New("fail") })
|
|
461
|
+
_ = svc.Execute("k3", func() error { return nil })
|
|
462
|
+
|
|
463
|
+
all := svc.GetAllStats()
|
|
464
|
+
assert.Len(t, all, 3, "应包含所有三个 key 的统计")
|
|
465
|
+
|
|
466
|
+
_, ok1 := all["k1"]
|
|
467
|
+
_, ok2 := all["k2"]
|
|
468
|
+
_, ok3 := all["k3"]
|
|
469
|
+
assert.True(t, ok1)
|
|
470
|
+
assert.True(t, ok2)
|
|
471
|
+
assert.True(t, ok3)
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
func TestRetryService_ResetStats_ClearsCounters(t *testing.T) {
|
|
475
|
+
svc := NewRetryService(newTestLogger(), newFastConfig())
|
|
476
|
+
|
|
477
|
+
// 制造一些统计数据
|
|
478
|
+
_ = svc.Execute("op-reset", func() error { return errors.New("fail") })
|
|
479
|
+
|
|
480
|
+
before := svc.GetStats("op-reset")
|
|
481
|
+
require.NotNil(t, before)
|
|
482
|
+
assert.Equal(t, int64(1), before.TotalExecutions)
|
|
483
|
+
assert.Greater(t, before.TotalRetries, int64(0))
|
|
484
|
+
|
|
485
|
+
// 重置
|
|
486
|
+
svc.ResetStats("op-reset")
|
|
487
|
+
|
|
488
|
+
after := svc.GetStats("op-reset")
|
|
489
|
+
require.NotNil(t, after)
|
|
490
|
+
assert.Equal(t, int64(0), after.TotalExecutions)
|
|
491
|
+
assert.Equal(t, int64(0), after.TotalRetries)
|
|
492
|
+
assert.Equal(t, int64(0), after.RetriedSuccessCount)
|
|
493
|
+
assert.Equal(t, int64(0), after.ExhaustedCount)
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
func TestRetryService_ResetStats_UnknownKey_NoOp(t *testing.T) {
|
|
497
|
+
svc := NewRetryService(newTestLogger(), newFastConfig())
|
|
498
|
+
// 对不存在的 key 调用 ResetStats 不应 panic
|
|
499
|
+
assert.NotPanics(t, func() {
|
|
500
|
+
svc.ResetStats("ghost-key")
|
|
501
|
+
})
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
func TestRetryService_Stats_MultipleExecutions_Accumulate(t *testing.T) {
|
|
505
|
+
svc := NewRetryService(newTestLogger(), newFastConfig())
|
|
506
|
+
|
|
507
|
+
// 执行 3 次:2 次成功,1 次耗尽
|
|
508
|
+
_ = svc.Execute("acc", func() error { return nil })
|
|
509
|
+
_ = svc.Execute("acc", func() error { return nil })
|
|
510
|
+
_ = svc.Execute("acc", func() error { return errors.New("fail") })
|
|
511
|
+
|
|
512
|
+
stats := svc.GetStats("acc")
|
|
513
|
+
require.NotNil(t, stats)
|
|
514
|
+
assert.Equal(t, int64(3), stats.TotalExecutions)
|
|
515
|
+
assert.Equal(t, int64(1), stats.ExhaustedCount)
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
// ═══════════════════════════════════════════════════════════════
|
|
519
|
+
// 12. Context 取消 — 停止重试
|
|
520
|
+
// ═══════════════════════════════════════════════════════════════
|
|
521
|
+
|
|
522
|
+
func TestRetryService_ContextCancellation_StopsRetrying(t *testing.T) {
|
|
523
|
+
cfg := RetryConfig{
|
|
524
|
+
MaxAttempts: 10,
|
|
525
|
+
InitialDelay: 5 * time.Millisecond,
|
|
526
|
+
MaxDelay: 50 * time.Millisecond,
|
|
527
|
+
BackoffMultiplier: 1, // 固定延迟便于控制
|
|
528
|
+
Jitter: false,
|
|
529
|
+
}
|
|
530
|
+
svc := NewRetryService(newTestLogger(), cfg)
|
|
531
|
+
|
|
532
|
+
ctx, cancel := context.WithCancel(context.Background())
|
|
533
|
+
callCount := 0
|
|
534
|
+
|
|
535
|
+
go func() {
|
|
536
|
+
// 第一次执行后立即取消
|
|
537
|
+
time.Sleep(2 * time.Millisecond)
|
|
538
|
+
cancel()
|
|
539
|
+
}()
|
|
540
|
+
|
|
541
|
+
err := svc.ExecuteWithContext(ctx, "op-ctx", func(context.Context) error {
|
|
542
|
+
callCount++
|
|
543
|
+
return errors.New("transient")
|
|
544
|
+
})
|
|
545
|
+
|
|
546
|
+
require.Error(t, err)
|
|
547
|
+
assert.ErrorIs(t, err, context.Canceled)
|
|
548
|
+
// context 取消后不应继续消耗重试预算
|
|
549
|
+
assert.Less(t, callCount, 10, "context 取消后不应耗尽全部 10 次重试")
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
func TestRetryService_ContextAlreadyCancelled_StopsImmediately(t *testing.T) {
|
|
553
|
+
cfg := RetryConfig{
|
|
554
|
+
MaxAttempts: 5,
|
|
555
|
+
InitialDelay: time.Millisecond,
|
|
556
|
+
MaxDelay: 10 * time.Millisecond,
|
|
557
|
+
BackoffMultiplier: 2,
|
|
558
|
+
Jitter: false,
|
|
559
|
+
}
|
|
560
|
+
svc := NewRetryService(newTestLogger(), cfg)
|
|
561
|
+
|
|
562
|
+
ctx, cancel := context.WithCancel(context.Background())
|
|
563
|
+
cancel() // 预先取消
|
|
564
|
+
|
|
565
|
+
callCount := 0
|
|
566
|
+
err := svc.ExecuteWithContext(ctx, "op-ctx-pre", func(context.Context) error {
|
|
567
|
+
callCount++
|
|
568
|
+
return errors.New("fail")
|
|
569
|
+
})
|
|
570
|
+
|
|
571
|
+
require.Error(t, err)
|
|
572
|
+
assert.ErrorIs(t, err, context.Canceled)
|
|
573
|
+
assert.Equal(t, 0, callCount, "context 已取消时不应执行被保护操作")
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
// ═══════════════════════════════════════════════════════════════
|
|
577
|
+
// 13. 并发使用 — 多 goroutine 同时重试
|
|
578
|
+
// ═══════════════════════════════════════════════════════════════
|
|
579
|
+
|
|
580
|
+
func TestRetryService_Concurrent_MultipleGoroutines(t *testing.T) {
|
|
581
|
+
svc := NewRetryService(newTestLogger(), newFastConfig())
|
|
582
|
+
|
|
583
|
+
const goroutines = 20
|
|
584
|
+
var wg sync.WaitGroup
|
|
585
|
+
var successCount atomic.Int64
|
|
586
|
+
var errCount atomic.Int64
|
|
587
|
+
|
|
588
|
+
for i := 0; i < goroutines; i++ {
|
|
589
|
+
wg.Add(1)
|
|
590
|
+
go func(id int) {
|
|
591
|
+
defer wg.Done()
|
|
592
|
+
key := fmt.Sprintf("goroutine-%d", id)
|
|
593
|
+
attempts := 0
|
|
594
|
+
err := svc.Execute(key, func() error {
|
|
595
|
+
attempts++
|
|
596
|
+
if attempts < 2 {
|
|
597
|
+
return errors.New("first fail")
|
|
598
|
+
}
|
|
599
|
+
return nil
|
|
600
|
+
})
|
|
601
|
+
if err == nil {
|
|
602
|
+
successCount.Add(1)
|
|
603
|
+
} else {
|
|
604
|
+
errCount.Add(1)
|
|
605
|
+
}
|
|
606
|
+
}(i)
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
wg.Wait()
|
|
610
|
+
|
|
611
|
+
// 全部 goroutine 都应在第二次尝试时成功
|
|
612
|
+
assert.Equal(t, int64(goroutines), successCount.Load())
|
|
613
|
+
assert.Equal(t, int64(0), errCount.Load())
|
|
614
|
+
|
|
615
|
+
// 每个 key 应有独立统计
|
|
616
|
+
all := svc.GetAllStats()
|
|
617
|
+
assert.Len(t, all, goroutines)
|
|
618
|
+
|
|
619
|
+
for i := 0; i < goroutines; i++ {
|
|
620
|
+
key := fmt.Sprintf("goroutine-%d", i)
|
|
621
|
+
st, ok := all[key]
|
|
622
|
+
assert.True(t, ok, "key %s 应存在", key)
|
|
623
|
+
assert.Equal(t, int64(1), st.TotalExecutions)
|
|
624
|
+
assert.Equal(t, int64(1), st.TotalRetries)
|
|
625
|
+
assert.Equal(t, int64(1), st.RetriedSuccessCount)
|
|
626
|
+
}
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
func TestRetryService_Concurrent_SameKey(t *testing.T) {
|
|
630
|
+
svc := NewRetryService(newTestLogger(), newFastConfig())
|
|
631
|
+
|
|
632
|
+
const goroutines = 50
|
|
633
|
+
var wg sync.WaitGroup
|
|
634
|
+
var totalSuccess atomic.Int64
|
|
635
|
+
|
|
636
|
+
for i := 0; i < goroutines; i++ {
|
|
637
|
+
wg.Add(1)
|
|
638
|
+
go func() {
|
|
639
|
+
defer wg.Done()
|
|
640
|
+
err := svc.Execute("shared-key", func() error { return nil })
|
|
641
|
+
if err == nil {
|
|
642
|
+
totalSuccess.Add(1)
|
|
643
|
+
}
|
|
644
|
+
}()
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
wg.Wait()
|
|
648
|
+
|
|
649
|
+
assert.Equal(t, int64(goroutines), totalSuccess.Load())
|
|
650
|
+
|
|
651
|
+
stats := svc.GetStats("shared-key")
|
|
652
|
+
require.NotNil(t, stats)
|
|
653
|
+
assert.Equal(t, int64(goroutines), stats.TotalExecutions)
|
|
654
|
+
// 首次即成功,不产生重试
|
|
655
|
+
assert.Equal(t, int64(0), stats.TotalRetries)
|
|
656
|
+
}
|
|
657
|
+
|
|
658
|
+
// ═══════════════════════════════════════════════════════════════
|
|
659
|
+
// SetGlobalConfig — 对后续新 key 生效
|
|
660
|
+
// ═══════════════════════════════════════════════════════════════
|
|
661
|
+
|
|
662
|
+
func TestRetryService_SetGlobalConfig_AffectsNewKeys(t *testing.T) {
|
|
663
|
+
svc := NewRetryService(newTestLogger(), newFastConfig()) // MaxAttempts=3
|
|
664
|
+
|
|
665
|
+
// 修改全局配置为 MaxAttempts=2
|
|
666
|
+
svc.SetGlobalConfig(RetryConfig{
|
|
667
|
+
MaxAttempts: 2,
|
|
668
|
+
InitialDelay: time.Millisecond,
|
|
669
|
+
MaxDelay: 5 * time.Millisecond,
|
|
670
|
+
BackoffMultiplier: 2,
|
|
671
|
+
Jitter: false,
|
|
672
|
+
})
|
|
673
|
+
|
|
674
|
+
callCount := 0
|
|
675
|
+
err := svc.Execute("new-key-after-global-change", func() error {
|
|
676
|
+
callCount++
|
|
677
|
+
return errors.New("fail")
|
|
678
|
+
})
|
|
679
|
+
|
|
680
|
+
require.Error(t, err)
|
|
681
|
+
assert.Equal(t, 2, callCount, "全局配置更新后新 key 应使用新的 MaxAttempts=2")
|
|
682
|
+
}
|
|
683
|
+
|
|
684
|
+
// ═══════════════════════════════════════════════════════════════
|
|
685
|
+
// RetryableCheck 与 RetryOptions 组合 — opt 覆盖 config 层
|
|
686
|
+
// ═══════════════════════════════════════════════════════════════
|
|
687
|
+
|
|
688
|
+
func TestRetryService_RetryOptions_OverridesConfig(t *testing.T) {
|
|
689
|
+
// 全局 RetryableCheck 允许所有错误
|
|
690
|
+
cfg := newFastConfig()
|
|
691
|
+
cfg.RetryableCheck = func(e error) bool { return true }
|
|
692
|
+
svc := NewRetryService(newTestLogger(), cfg)
|
|
693
|
+
|
|
694
|
+
specificErr := errors.New("specific")
|
|
695
|
+
callCount := 0
|
|
696
|
+
|
|
697
|
+
// 通过 RetryOptions 覆盖,只有 specificErr 才重试
|
|
698
|
+
err := svc.Execute("op-override", func() error {
|
|
699
|
+
callCount++
|
|
700
|
+
return errors.New("other error")
|
|
701
|
+
}, RetryOptions{
|
|
702
|
+
RetryableCheck: func(e error) bool {
|
|
703
|
+
return errors.Is(e, specificErr)
|
|
704
|
+
},
|
|
705
|
+
})
|
|
706
|
+
|
|
707
|
+
require.Error(t, err)
|
|
708
|
+
// "other error" 不匹配 specificErr → 立即停止
|
|
709
|
+
assert.Equal(t, 1, callCount, "opt.RetryableCheck 应覆盖 config 层")
|
|
710
|
+
}
|
|
711
|
+
|
|
712
|
+
// ═══════════════════════════════════════════════════════════════
|
|
713
|
+
// RetriedSuccessCount 精确验证
|
|
714
|
+
// ═══════════════════════════════════════════════════════════════
|
|
715
|
+
|
|
716
|
+
func TestRetryService_RetriedSuccessCount_OnlyCountsRetried(t *testing.T) {
|
|
717
|
+
svc := NewRetryService(newTestLogger(), newFastConfig())
|
|
718
|
+
|
|
719
|
+
// 第一次执行:首次成功(不计入 RetriedSuccessCount)
|
|
720
|
+
_ = svc.Execute("rc", func() error { return nil })
|
|
721
|
+
// 第二次执行:第二次才成功
|
|
722
|
+
count := 0
|
|
723
|
+
_ = svc.Execute("rc", func() error {
|
|
724
|
+
count++
|
|
725
|
+
if count < 2 {
|
|
726
|
+
return errors.New("x")
|
|
727
|
+
}
|
|
728
|
+
return nil
|
|
729
|
+
})
|
|
730
|
+
|
|
731
|
+
stats := svc.GetStats("rc")
|
|
732
|
+
require.NotNil(t, stats)
|
|
733
|
+
assert.Equal(t, int64(2), stats.TotalExecutions)
|
|
734
|
+
assert.Equal(t, int64(1), stats.RetriedSuccessCount, "只有重试后成功的执行才计入")
|
|
735
|
+
}
|