@stackonward/cli 0.0.1 → 1.0.1
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 +8 -5
|
@@ -0,0 +1,891 @@
|
|
|
1
|
+
package commandreplay
|
|
2
|
+
|
|
3
|
+
import (
|
|
4
|
+
"context"
|
|
5
|
+
"encoding/json"
|
|
6
|
+
"errors"
|
|
7
|
+
"net/http"
|
|
8
|
+
"strings"
|
|
9
|
+
"sync"
|
|
10
|
+
"testing"
|
|
11
|
+
"time"
|
|
12
|
+
|
|
13
|
+
"gorm.io/driver/sqlite"
|
|
14
|
+
"gorm.io/gorm"
|
|
15
|
+
|
|
16
|
+
"{{module}}/internal/common/canonicaljson"
|
|
17
|
+
"{{module}}/internal/core/database"
|
|
18
|
+
"{{module}}/pkg/apierror"
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
const commandReplayTestNamespace = "test.command.replay"
|
|
22
|
+
|
|
23
|
+
var commandReplayTestNow = time.Date(2026, 5, 28, 10, 0, 0, 0, time.UTC)
|
|
24
|
+
|
|
25
|
+
func TestCommandReplayExecuteSucceeds(t *testing.T) {
|
|
26
|
+
service, repo := newTestCommandReplayService(t)
|
|
27
|
+
principalType := "identity"
|
|
28
|
+
principalRef := "user_123"
|
|
29
|
+
fnCalled := 0
|
|
30
|
+
|
|
31
|
+
result, err := service.Execute(context.Background(), CommandReplayBeginRequest{
|
|
32
|
+
Namespace: " test.command.replay ",
|
|
33
|
+
CommandScope: " quote:123 ",
|
|
34
|
+
IdempotencyKey: " key-123 ",
|
|
35
|
+
RequestPayload: json.RawMessage(`{"currency":"USD","amount":100}`),
|
|
36
|
+
PrincipalType: &principalType,
|
|
37
|
+
PrincipalRef: &principalRef,
|
|
38
|
+
}, func(ctx context.Context, record *CommandReplayRecord) (*CommandReplayCommandResult, error) {
|
|
39
|
+
fnCalled++
|
|
40
|
+
if record.ID == 0 {
|
|
41
|
+
t.Fatalf("record.ID = 0, want persisted id")
|
|
42
|
+
}
|
|
43
|
+
return &CommandReplayCommandResult{
|
|
44
|
+
Status: CommandReplayStatusSucceeded,
|
|
45
|
+
ResponsePayload: json.RawMessage(`{"b":2,"a":1}`),
|
|
46
|
+
}, nil
|
|
47
|
+
})
|
|
48
|
+
if err != nil {
|
|
49
|
+
t.Fatalf("Execute() error = %v", err)
|
|
50
|
+
}
|
|
51
|
+
if fnCalled != 1 {
|
|
52
|
+
t.Fatalf("fnCalled = %d, want 1", fnCalled)
|
|
53
|
+
}
|
|
54
|
+
if result.Replayed {
|
|
55
|
+
t.Fatalf("Execute() Replayed = true, want false")
|
|
56
|
+
}
|
|
57
|
+
if result.Status != CommandReplayStatusSucceeded {
|
|
58
|
+
t.Fatalf("Execute() Status = %q, want succeeded", result.Status)
|
|
59
|
+
}
|
|
60
|
+
if string(result.ResponsePayload) != `{"a":1,"b":2}` {
|
|
61
|
+
t.Fatalf("Execute() ResponsePayload = %s, want canonical object", result.ResponsePayload)
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
stored := repo.mustFind(t, commandReplayTestNamespace, "quote:123", "key-123")
|
|
65
|
+
if stored.Status != CommandReplayStatusSucceeded {
|
|
66
|
+
t.Fatalf("stored Status = %q, want succeeded", stored.Status)
|
|
67
|
+
}
|
|
68
|
+
if string(stored.Metadata) != "{}" {
|
|
69
|
+
t.Fatalf("stored Metadata = %s, want {}", stored.Metadata)
|
|
70
|
+
}
|
|
71
|
+
if string(stored.ResponsePayload) != `{"a":1,"b":2}` {
|
|
72
|
+
t.Fatalf("stored ResponsePayload = %s, want canonical object", stored.ResponsePayload)
|
|
73
|
+
}
|
|
74
|
+
if !stored.ExpiresAt.Equal(commandReplayTestNow.Add(defaultCommandReplayTTL)) {
|
|
75
|
+
t.Fatalf("stored ExpiresAt = %s, want %s", stored.ExpiresAt, commandReplayTestNow.Add(defaultCommandReplayTTL))
|
|
76
|
+
}
|
|
77
|
+
if stored.CompletedAt == nil || !stored.CompletedAt.Equal(commandReplayTestNow) {
|
|
78
|
+
t.Fatalf("stored CompletedAt = %v, want %s", stored.CompletedAt, commandReplayTestNow)
|
|
79
|
+
}
|
|
80
|
+
if stored.PrincipalType == nil || *stored.PrincipalType != principalType {
|
|
81
|
+
t.Fatalf("stored PrincipalType = %v, want %q", stored.PrincipalType, principalType)
|
|
82
|
+
}
|
|
83
|
+
if stored.PrincipalRef == nil || *stored.PrincipalRef != principalRef {
|
|
84
|
+
t.Fatalf("stored PrincipalRef = %v, want %q", stored.PrincipalRef, principalRef)
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
func TestCommandReplayExecuteReplaysTerminalRecordWithoutInvokingFunc(t *testing.T) {
|
|
89
|
+
service, repo := newTestCommandReplayService(t)
|
|
90
|
+
errorCode := "payment_failed"
|
|
91
|
+
repo.seed(seedCommandReplayRecord(t, json.RawMessage(`{"amount":100}`), func(record *CommandReplayRecord) {
|
|
92
|
+
record.Status = CommandReplayStatusFailed
|
|
93
|
+
record.ResponsePayload = json.RawMessage(`{"error":{"code":"payment_failed","message":"Payment failed","type":"invalid_request_error"}}`)
|
|
94
|
+
record.ErrorCode = &errorCode
|
|
95
|
+
record.ErrorStatus = ptrInt(http.StatusConflict)
|
|
96
|
+
record.ExpiresAt = commandReplayTestNow.Add(time.Hour)
|
|
97
|
+
}))
|
|
98
|
+
|
|
99
|
+
result, err := service.Execute(context.Background(), beginRequest(json.RawMessage(`{"amount":100}`)), func(ctx context.Context, record *CommandReplayRecord) (*CommandReplayCommandResult, error) {
|
|
100
|
+
t.Fatalf("fn should not be invoked for terminal replay")
|
|
101
|
+
return nil, nil
|
|
102
|
+
})
|
|
103
|
+
assertAPIError(t, err, http.StatusConflict, errorCode)
|
|
104
|
+
if !result.Replayed {
|
|
105
|
+
t.Fatalf("Execute() Replayed = false, want true")
|
|
106
|
+
}
|
|
107
|
+
if result.Status != CommandReplayStatusFailed {
|
|
108
|
+
t.Fatalf("Execute() Status = %q, want failed", result.Status)
|
|
109
|
+
}
|
|
110
|
+
if string(result.ResponsePayload) != `{"error":{"code":"payment_failed","message":"Payment failed","type":"invalid_request_error"}}` {
|
|
111
|
+
t.Fatalf("Execute() ResponsePayload = %s", result.ResponsePayload)
|
|
112
|
+
}
|
|
113
|
+
if result.ErrorCode == nil || *result.ErrorCode != errorCode {
|
|
114
|
+
t.Fatalf("Execute() ErrorCode = %v, want %q", result.ErrorCode, errorCode)
|
|
115
|
+
}
|
|
116
|
+
if result.ErrorStatus == nil || *result.ErrorStatus != http.StatusConflict {
|
|
117
|
+
t.Fatalf("Execute() ErrorStatus = %v, want 409", result.ErrorStatus)
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
func TestCommandReplayExecuteRejectsInProgressScopeLockConflict(t *testing.T) {
|
|
122
|
+
service, repo := newTestCommandReplayService(t)
|
|
123
|
+
repo.lockAcquired = false
|
|
124
|
+
|
|
125
|
+
_, err := service.Execute(context.Background(), beginRequest(json.RawMessage(`{"amount":100}`)), func(ctx context.Context, record *CommandReplayRecord) (*CommandReplayCommandResult, error) {
|
|
126
|
+
t.Fatalf("fn should not be invoked when scope lock is unavailable")
|
|
127
|
+
return nil, nil
|
|
128
|
+
})
|
|
129
|
+
assertAPIError(t, err, http.StatusConflict, errCodeCommandReplayInProgress)
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
func TestCommandReplayExecuteRejectsHashConflict(t *testing.T) {
|
|
133
|
+
service, repo := newTestCommandReplayService(t)
|
|
134
|
+
repo.seed(seedCommandReplayRecord(t, json.RawMessage(`{"amount":100}`), func(record *CommandReplayRecord) {
|
|
135
|
+
record.Status = CommandReplayStatusSucceeded
|
|
136
|
+
record.ExpiresAt = commandReplayTestNow.Add(time.Hour)
|
|
137
|
+
}))
|
|
138
|
+
|
|
139
|
+
_, err := service.Execute(context.Background(), beginRequest(json.RawMessage(`{"amount":200}`)), successCommandReplayFunc(t))
|
|
140
|
+
assertAPIError(t, err, http.StatusConflict, errCodeCommandReplayConflict)
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
func TestCommandReplayExecuteRejectsExpiredRecord(t *testing.T) {
|
|
144
|
+
service, repo := newTestCommandReplayService(t)
|
|
145
|
+
repo.seed(seedCommandReplayRecord(t, json.RawMessage(`{"amount":100}`), func(record *CommandReplayRecord) {
|
|
146
|
+
record.Status = CommandReplayStatusSucceeded
|
|
147
|
+
record.ExpiresAt = commandReplayTestNow.Add(-time.Second)
|
|
148
|
+
}))
|
|
149
|
+
|
|
150
|
+
_, err := service.Execute(context.Background(), beginRequest(json.RawMessage(`{"amount":100}`)), successCommandReplayFunc(t))
|
|
151
|
+
assertAPIError(t, err, http.StatusConflict, errCodeCommandReplayExpired)
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
func TestCommandReplayExecuteBusinessFailureCommitsAndReturnsBusinessError(t *testing.T) {
|
|
155
|
+
service, repo := newTestCommandReplayService(t)
|
|
156
|
+
businessErr := apierror.Conflict("payment_declined", "Payment was declined")
|
|
157
|
+
|
|
158
|
+
result, err := service.Execute(context.Background(), beginRequest(json.RawMessage(`{"amount":100}`)), func(ctx context.Context, record *CommandReplayRecord) (*CommandReplayCommandResult, error) {
|
|
159
|
+
return &CommandReplayCommandResult{
|
|
160
|
+
Status: CommandReplayStatusFailed,
|
|
161
|
+
ErrorCode: " payment_declined ",
|
|
162
|
+
ReturnError: businessErr,
|
|
163
|
+
}, nil
|
|
164
|
+
})
|
|
165
|
+
if !errors.Is(err, businessErr) {
|
|
166
|
+
t.Fatalf("Execute() error = %v, want businessErr", err)
|
|
167
|
+
}
|
|
168
|
+
if result == nil || result.Status != CommandReplayStatusFailed {
|
|
169
|
+
t.Fatalf("Execute() result = %#v, want failed result", result)
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
stored := repo.mustFind(t, commandReplayTestNamespace, "quote:123", "key-123")
|
|
173
|
+
if stored.Status != CommandReplayStatusFailed {
|
|
174
|
+
t.Fatalf("stored Status = %q, want failed", stored.Status)
|
|
175
|
+
}
|
|
176
|
+
if stored.ErrorCode == nil || *stored.ErrorCode != "payment_declined" {
|
|
177
|
+
t.Fatalf("stored ErrorCode = %v, want payment_declined", stored.ErrorCode)
|
|
178
|
+
}
|
|
179
|
+
if stored.ErrorStatus == nil || *stored.ErrorStatus != http.StatusConflict {
|
|
180
|
+
t.Fatalf("stored ErrorStatus = %v, want 409", stored.ErrorStatus)
|
|
181
|
+
}
|
|
182
|
+
if string(stored.ResponsePayload) != `{"error":{"code":"payment_declined","message":"Payment was declined","type":"invalid_request_error"}}` {
|
|
183
|
+
t.Fatalf("stored ResponsePayload = %s, want canonical object", stored.ResponsePayload)
|
|
184
|
+
}
|
|
185
|
+
if stored.CompletedAt == nil || !stored.CompletedAt.Equal(commandReplayTestNow) {
|
|
186
|
+
t.Fatalf("stored CompletedAt = %v, want %s", stored.CompletedAt, commandReplayTestNow)
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
func TestCommandReplayExecuteInfrastructureErrorDoesNotMarkTerminal(t *testing.T) {
|
|
191
|
+
service, repo := newTestCommandReplayService(t)
|
|
192
|
+
infraErr := errors.New("database unavailable")
|
|
193
|
+
|
|
194
|
+
_, err := service.Execute(context.Background(), beginRequest(json.RawMessage(`{"amount":100}`)), func(ctx context.Context, record *CommandReplayRecord) (*CommandReplayCommandResult, error) {
|
|
195
|
+
return nil, infraErr
|
|
196
|
+
})
|
|
197
|
+
if !errors.Is(err, infraErr) {
|
|
198
|
+
t.Fatalf("Execute() error = %v, want infraErr", err)
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
stored := repo.mustFind(t, commandReplayTestNamespace, "quote:123", "key-123")
|
|
202
|
+
if stored.Status.IsTerminal() {
|
|
203
|
+
t.Fatalf("stored Status = %q, want non-terminal", stored.Status)
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
func TestCommandReplayExecuteRereadsDuplicateCreateAndClassifies(t *testing.T) {
|
|
208
|
+
service, repo := newTestCommandReplayService(t)
|
|
209
|
+
payload := json.RawMessage(`{"amount":100}`)
|
|
210
|
+
repo.createHook = func(record *CommandReplayRecord) error {
|
|
211
|
+
repo.seed(seedCommandReplayRecord(t, payload, func(existing *CommandReplayRecord) {
|
|
212
|
+
existing.ID = 99
|
|
213
|
+
existing.Status = CommandReplayStatusSucceeded
|
|
214
|
+
existing.ResponsePayload = json.RawMessage(`{"order_id":"ord_123"}`)
|
|
215
|
+
existing.ExpiresAt = commandReplayTestNow.Add(time.Hour)
|
|
216
|
+
}))
|
|
217
|
+
return ErrCommandReplayRecordExists
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
result, err := service.Execute(context.Background(), beginRequest(payload), successCommandReplayFunc(t))
|
|
221
|
+
if err != nil {
|
|
222
|
+
t.Fatalf("Execute() error = %v", err)
|
|
223
|
+
}
|
|
224
|
+
if !result.Replayed {
|
|
225
|
+
t.Fatalf("Execute() Replayed = false, want true")
|
|
226
|
+
}
|
|
227
|
+
if result.Record.ID != 99 {
|
|
228
|
+
t.Fatalf("Execute() Record.ID = %d, want 99", result.Record.ID)
|
|
229
|
+
}
|
|
230
|
+
if string(result.ResponsePayload) != `{"order_id":"ord_123"}` {
|
|
231
|
+
t.Fatalf("Execute() ResponsePayload = %s", result.ResponsePayload)
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
func TestCommandReplayExecuteRejectsInvalidMetadata(t *testing.T) {
|
|
236
|
+
service, _ := newTestCommandReplayService(t)
|
|
237
|
+
req := beginRequest(json.RawMessage(`{"amount":100}`))
|
|
238
|
+
req.Metadata = json.RawMessage(`[]`)
|
|
239
|
+
|
|
240
|
+
_, err := service.Execute(context.Background(), req, successCommandReplayFunc(t))
|
|
241
|
+
assertAPIError(t, err, http.StatusBadRequest, apierror.CodeValidationFailed)
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
func TestCommandReplayExecuteRejectsNonObjectPayload(t *testing.T) {
|
|
245
|
+
service, _ := newTestCommandReplayService(t)
|
|
246
|
+
req := beginRequest(json.RawMessage(`["not","object"]`))
|
|
247
|
+
|
|
248
|
+
_, err := service.Execute(context.Background(), req, successCommandReplayFunc(t))
|
|
249
|
+
assertAPIError(t, err, http.StatusBadRequest, apierror.CodeValidationFailed)
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
func TestCommandReplayExecuteRejectsInvalidNamespace(t *testing.T) {
|
|
253
|
+
service, _ := newTestCommandReplayService(t)
|
|
254
|
+
req := beginRequest(json.RawMessage(`{"amount":100}`))
|
|
255
|
+
req.Namespace = "Onex.product.product_beta.checkout"
|
|
256
|
+
|
|
257
|
+
_, err := service.Execute(context.Background(), req, successCommandReplayFunc(t))
|
|
258
|
+
assertAPIError(t, err, http.StatusBadRequest, apierror.CodeValidationFailed)
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
func TestCommandReplayExecuteRejectsIncompletePrincipal(t *testing.T) {
|
|
262
|
+
principalType := "identity"
|
|
263
|
+
principalRef := "ipr_123"
|
|
264
|
+
blank := " \t "
|
|
265
|
+
tests := []struct {
|
|
266
|
+
name string
|
|
267
|
+
principalType *string
|
|
268
|
+
principalRef *string
|
|
269
|
+
}{
|
|
270
|
+
{name: "missing principal ref", principalType: &principalType},
|
|
271
|
+
{name: "missing principal type", principalRef: &principalRef},
|
|
272
|
+
{name: "blank principal pair", principalType: &blank, principalRef: &blank},
|
|
273
|
+
{name: "blank principal ref", principalType: &principalType, principalRef: &blank},
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
for _, tt := range tests {
|
|
277
|
+
t.Run(tt.name, func(t *testing.T) {
|
|
278
|
+
service, _ := newTestCommandReplayService(t)
|
|
279
|
+
req := beginRequest(json.RawMessage(`{"amount":100}`))
|
|
280
|
+
req.PrincipalType = tt.principalType
|
|
281
|
+
req.PrincipalRef = tt.principalRef
|
|
282
|
+
|
|
283
|
+
_, err := service.Execute(context.Background(), req, successCommandReplayFunc(t))
|
|
284
|
+
assertAPIError(t, err, http.StatusBadRequest, apierror.CodeValidationFailed)
|
|
285
|
+
})
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
func TestCommandReplayExecuteRejectsOverlongFields(t *testing.T) {
|
|
290
|
+
tests := []struct {
|
|
291
|
+
name string
|
|
292
|
+
mutate func(*CommandReplayBeginRequest)
|
|
293
|
+
}{
|
|
294
|
+
{
|
|
295
|
+
name: "namespace",
|
|
296
|
+
mutate: func(req *CommandReplayBeginRequest) {
|
|
297
|
+
req.Namespace = "onex.platform." + strings.Repeat("a", maxNamespaceLength+1)
|
|
298
|
+
},
|
|
299
|
+
},
|
|
300
|
+
{
|
|
301
|
+
name: "command scope",
|
|
302
|
+
mutate: func(req *CommandReplayBeginRequest) {
|
|
303
|
+
req.CommandScope = strings.Repeat("a", maxCommandScopeLength+1)
|
|
304
|
+
},
|
|
305
|
+
},
|
|
306
|
+
{
|
|
307
|
+
name: "idempotency key",
|
|
308
|
+
mutate: func(req *CommandReplayBeginRequest) {
|
|
309
|
+
req.IdempotencyKey = strings.Repeat("a", maxIdempotencyKeyLength+1)
|
|
310
|
+
},
|
|
311
|
+
},
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
for _, tt := range tests {
|
|
315
|
+
t.Run(tt.name, func(t *testing.T) {
|
|
316
|
+
service, _ := newTestCommandReplayService(t)
|
|
317
|
+
req := beginRequest(json.RawMessage(`{"amount":100}`))
|
|
318
|
+
tt.mutate(&req)
|
|
319
|
+
|
|
320
|
+
_, err := service.Execute(context.Background(), req, successCommandReplayFunc(t))
|
|
321
|
+
assertAPIError(t, err, http.StatusBadRequest, apierror.CodeValidationFailed)
|
|
322
|
+
})
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
func TestCommandReplayExecuteRejectsOverlongErrorCode(t *testing.T) {
|
|
327
|
+
service, _ := newTestCommandReplayService(t)
|
|
328
|
+
errorCode := strings.Repeat("a", maxErrorCodeLength+1)
|
|
329
|
+
|
|
330
|
+
_, err := service.Execute(context.Background(), beginRequest(json.RawMessage(`{"amount":100}`)), func(ctx context.Context, record *CommandReplayRecord) (*CommandReplayCommandResult, error) {
|
|
331
|
+
return &CommandReplayCommandResult{
|
|
332
|
+
Status: CommandReplayStatusFailed,
|
|
333
|
+
ErrorCode: errorCode,
|
|
334
|
+
ReturnError: apierror.Conflict(errorCode, "Payment was declined"),
|
|
335
|
+
}, nil
|
|
336
|
+
})
|
|
337
|
+
assertAPIError(t, err, http.StatusBadRequest, apierror.CodeValidationFailed)
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
func TestCommandReplayCanonicalHashStableAcrossJSONKeyOrder(t *testing.T) {
|
|
341
|
+
first := mustCanonicalHash(t, json.RawMessage(`{"b":2.0,"a":{"d":4,"c":3}}`))
|
|
342
|
+
second := mustCanonicalHash(t, json.RawMessage(`{"a":{"c":3,"d":4},"b":2}`))
|
|
343
|
+
|
|
344
|
+
if first != second {
|
|
345
|
+
t.Fatalf("canonical hash mismatch: %s != %s", first, second)
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
func TestCommandReplayExecuteRejectsDuplicateJSONKeys(t *testing.T) {
|
|
350
|
+
service, _ := newTestCommandReplayService(t)
|
|
351
|
+
req := beginRequest(json.RawMessage(`{"amount":100,"amount":200}`))
|
|
352
|
+
|
|
353
|
+
_, err := service.Execute(context.Background(), req, successCommandReplayFunc(t))
|
|
354
|
+
assertAPIError(t, err, http.StatusBadRequest, apierror.CodeValidationFailed)
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
func TestCommandReplayExternalLifecycle(t *testing.T) {
|
|
358
|
+
service, repo := newTestCommandReplayService(t)
|
|
359
|
+
lease, err := service.BeginExternal(context.Background(), beginRequest(json.RawMessage(`{"amount":100}`)), 5*time.Minute, func(ctx context.Context, record *CommandReplayRecord) (CommandReplayExternalReservation, error) {
|
|
360
|
+
if record.ID == 0 {
|
|
361
|
+
t.Fatal("reservation record was not persisted")
|
|
362
|
+
}
|
|
363
|
+
return CommandReplayExternalReservation{
|
|
364
|
+
ReferenceType: "checkout.provider_operation",
|
|
365
|
+
ReferenceNo: "cpo_1",
|
|
366
|
+
PreparedResponsePayload: json.RawMessage(`{"operation_no":"cpo_1","state":"prepared"}`),
|
|
367
|
+
}, nil
|
|
368
|
+
})
|
|
369
|
+
if err != nil {
|
|
370
|
+
t.Fatalf("BeginExternal() error = %v", err)
|
|
371
|
+
}
|
|
372
|
+
if lease.ExecutionToken == "" || lease.AttemptCount != 1 || lease.Reservation.ReferenceNo != "cpo_1" {
|
|
373
|
+
t.Fatalf("lease = %#v", lease)
|
|
374
|
+
}
|
|
375
|
+
stored := repo.mustFind(t, commandReplayTestNamespace, "quote:123", "key-123")
|
|
376
|
+
if !stored.HasExternalReservation() || stored.ExecutionTokenHash == nil || stored.ExternalAttemptCount != 1 {
|
|
377
|
+
t.Fatalf("stored external record = %#v", stored)
|
|
378
|
+
}
|
|
379
|
+
if string(stored.ResponsePayload) != `{"operation_no":"cpo_1","state":"prepared"}` {
|
|
380
|
+
t.Fatalf("stored prepared response = %s", stored.ResponsePayload)
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
result, err := service.CompleteExternal(context.Background(), lease.RecordID, lease.ExecutionToken, func(ctx context.Context, record *CommandReplayRecord) (*CommandReplayCommandResult, error) {
|
|
384
|
+
if record.ExternalReferenceNo == nil || *record.ExternalReferenceNo != "cpo_1" {
|
|
385
|
+
t.Fatalf("completion record = %#v", record)
|
|
386
|
+
}
|
|
387
|
+
return &CommandReplayCommandResult{Status: CommandReplayStatusSucceeded, ResponsePayload: json.RawMessage(`{"operation_no":"cpo_1"}`)}, nil
|
|
388
|
+
})
|
|
389
|
+
if err != nil || result.Status != CommandReplayStatusSucceeded {
|
|
390
|
+
t.Fatalf("CompleteExternal() = %#v, %v", result, err)
|
|
391
|
+
}
|
|
392
|
+
stored = repo.mustFind(t, commandReplayTestNamespace, "quote:123", "key-123")
|
|
393
|
+
if stored.HasExternalReservation() || stored.ExecutionTokenHash != nil || stored.Status != CommandReplayStatusSucceeded {
|
|
394
|
+
t.Fatalf("completed stored record = %#v", stored)
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
func TestCommandReplayExternalRecoveryCarriesPreparedResponse(t *testing.T) {
|
|
399
|
+
service, _ := newTestCommandReplayService(t)
|
|
400
|
+
current := commandReplayTestNow
|
|
401
|
+
service.now = func() time.Time { return current }
|
|
402
|
+
lease, err := service.BeginExternal(
|
|
403
|
+
context.Background(),
|
|
404
|
+
beginRequest(json.RawMessage(`{"amount":100}`)),
|
|
405
|
+
time.Minute,
|
|
406
|
+
func(context.Context, *CommandReplayRecord) (CommandReplayExternalReservation, error) {
|
|
407
|
+
return CommandReplayExternalReservation{
|
|
408
|
+
ReferenceType: "checkout.provider_operation",
|
|
409
|
+
ReferenceNo: "cpo_1",
|
|
410
|
+
PreparedResponsePayload: json.RawMessage(`{"b":2,"a":1}`),
|
|
411
|
+
}, nil
|
|
412
|
+
},
|
|
413
|
+
)
|
|
414
|
+
if err != nil {
|
|
415
|
+
t.Fatalf("BeginExternal() error = %v", err)
|
|
416
|
+
}
|
|
417
|
+
if string(lease.Reservation.PreparedResponsePayload) != `{"a":1,"b":2}` {
|
|
418
|
+
t.Fatalf("prepared response = %s", lease.Reservation.PreparedResponsePayload)
|
|
419
|
+
}
|
|
420
|
+
nextRecoveryAt := current.Add(2 * time.Minute)
|
|
421
|
+
if err := service.DeferExternal(context.Background(), lease.RecordID, lease.ExecutionToken, "provider_timeout", nextRecoveryAt); err != nil {
|
|
422
|
+
t.Fatalf("DeferExternal() error = %v", err)
|
|
423
|
+
}
|
|
424
|
+
current = nextRecoveryAt
|
|
425
|
+
recoveryLease, err := service.BeginExternal(
|
|
426
|
+
context.Background(),
|
|
427
|
+
beginRequest(json.RawMessage(`{"amount":100}`)),
|
|
428
|
+
time.Minute,
|
|
429
|
+
func(context.Context, *CommandReplayRecord) (CommandReplayExternalReservation, error) {
|
|
430
|
+
t.Fatal("reservation callback ran during recovery")
|
|
431
|
+
return CommandReplayExternalReservation{}, nil
|
|
432
|
+
},
|
|
433
|
+
)
|
|
434
|
+
if err != nil {
|
|
435
|
+
t.Fatalf("BeginExternal(recovery) error = %v", err)
|
|
436
|
+
}
|
|
437
|
+
if string(recoveryLease.Reservation.PreparedResponsePayload) != `{"a":1,"b":2}` {
|
|
438
|
+
t.Fatalf("recovered prepared response = %s", recoveryLease.Reservation.PreparedResponsePayload)
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
func TestCommandReplayExternalDeferAndRecoveryClaim(t *testing.T) {
|
|
443
|
+
service, repo := newTestCommandReplayService(t)
|
|
444
|
+
current := commandReplayTestNow
|
|
445
|
+
service.now = func() time.Time { return current }
|
|
446
|
+
lease, err := service.BeginExternal(context.Background(), beginRequest(json.RawMessage(`{"amount":100}`)), time.Minute, func(ctx context.Context, record *CommandReplayRecord) (CommandReplayExternalReservation, error) {
|
|
447
|
+
return CommandReplayExternalReservation{ReferenceType: "checkout.provider_operation", ReferenceNo: "cpo_1"}, nil
|
|
448
|
+
})
|
|
449
|
+
if err != nil {
|
|
450
|
+
t.Fatal(err)
|
|
451
|
+
}
|
|
452
|
+
nextRecoveryAt := current.Add(2 * time.Minute)
|
|
453
|
+
if err := service.DeferExternal(context.Background(), lease.RecordID, lease.ExecutionToken, "provider_timeout", nextRecoveryAt); err != nil {
|
|
454
|
+
t.Fatalf("DeferExternal() error = %v", err)
|
|
455
|
+
}
|
|
456
|
+
stored := repo.mustFind(t, commandReplayTestNamespace, "quote:123", "key-123")
|
|
457
|
+
if stored.ExecutionTokenHash != nil || stored.ExternalLastErrorCode == nil || *stored.ExternalLastErrorCode != "provider_timeout" {
|
|
458
|
+
t.Fatalf("deferred record = %#v", stored)
|
|
459
|
+
}
|
|
460
|
+
current = nextRecoveryAt
|
|
461
|
+
recoveryLease, err := service.ClaimExternalRecovery(context.Background(), lease.RecordID, time.Minute)
|
|
462
|
+
if err != nil {
|
|
463
|
+
t.Fatalf("ClaimExternalRecovery() error = %v", err)
|
|
464
|
+
}
|
|
465
|
+
if recoveryLease.AttemptCount != 2 || recoveryLease.ExecutionToken == lease.ExecutionToken {
|
|
466
|
+
t.Fatalf("recovery lease = %#v", recoveryLease)
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
func TestCommandReplayListDueExternalRecoveriesRejectsUnboundedLimit(t *testing.T) {
|
|
471
|
+
service, _ := newTestCommandReplayService(t)
|
|
472
|
+
|
|
473
|
+
_, err := service.ListDueExternalRecoveries(
|
|
474
|
+
context.Background(),
|
|
475
|
+
"checkout.provider_operation",
|
|
476
|
+
commandReplayTestNow,
|
|
477
|
+
501,
|
|
478
|
+
)
|
|
479
|
+
assertAPIError(t, err, http.StatusBadRequest, apierror.CodeValidationFailed)
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
func TestCommandReplayExternalRejectsOverlongReferenceFields(t *testing.T) {
|
|
483
|
+
tests := []struct {
|
|
484
|
+
name string
|
|
485
|
+
reservation CommandReplayExternalReservation
|
|
486
|
+
}{
|
|
487
|
+
{
|
|
488
|
+
name: "reference type",
|
|
489
|
+
reservation: CommandReplayExternalReservation{
|
|
490
|
+
ReferenceType: strings.Repeat("a", maxExternalReferenceTypeLength+1),
|
|
491
|
+
ReferenceNo: "cpo_1",
|
|
492
|
+
},
|
|
493
|
+
},
|
|
494
|
+
{
|
|
495
|
+
name: "reference number",
|
|
496
|
+
reservation: CommandReplayExternalReservation{
|
|
497
|
+
ReferenceType: "checkout.provider_operation",
|
|
498
|
+
ReferenceNo: strings.Repeat("a", maxExternalReferenceNoLength+1),
|
|
499
|
+
},
|
|
500
|
+
},
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
for _, tt := range tests {
|
|
504
|
+
t.Run(tt.name, func(t *testing.T) {
|
|
505
|
+
service, _ := newTestCommandReplayService(t)
|
|
506
|
+
_, err := service.BeginExternal(
|
|
507
|
+
context.Background(),
|
|
508
|
+
beginRequest(json.RawMessage(`{"amount":100}`)),
|
|
509
|
+
time.Minute,
|
|
510
|
+
func(context.Context, *CommandReplayRecord) (CommandReplayExternalReservation, error) {
|
|
511
|
+
return tt.reservation, nil
|
|
512
|
+
},
|
|
513
|
+
)
|
|
514
|
+
assertAPIError(t, err, http.StatusBadRequest, apierror.CodeValidationFailed)
|
|
515
|
+
})
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
service, _ := newTestCommandReplayService(t)
|
|
519
|
+
_, err := service.ListDueExternalRecoveries(
|
|
520
|
+
context.Background(),
|
|
521
|
+
strings.Repeat("a", maxExternalReferenceTypeLength+1),
|
|
522
|
+
commandReplayTestNow,
|
|
523
|
+
1,
|
|
524
|
+
)
|
|
525
|
+
assertAPIError(t, err, http.StatusBadRequest, apierror.CodeValidationFailed)
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
func TestCommandReplayExternalRejectsStaleExecutionToken(t *testing.T) {
|
|
529
|
+
service, _ := newTestCommandReplayService(t)
|
|
530
|
+
lease, err := service.BeginExternal(context.Background(), beginRequest(json.RawMessage(`{"amount":100}`)), time.Minute, func(ctx context.Context, record *CommandReplayRecord) (CommandReplayExternalReservation, error) {
|
|
531
|
+
return CommandReplayExternalReservation{ReferenceType: "checkout.provider_operation", ReferenceNo: "cpo_1"}, nil
|
|
532
|
+
})
|
|
533
|
+
if err != nil {
|
|
534
|
+
t.Fatal(err)
|
|
535
|
+
}
|
|
536
|
+
called := false
|
|
537
|
+
_, err = service.CompleteExternal(context.Background(), lease.RecordID, strings.Repeat("A", 43), func(ctx context.Context, record *CommandReplayRecord) (*CommandReplayCommandResult, error) {
|
|
538
|
+
called = true
|
|
539
|
+
return nil, nil
|
|
540
|
+
})
|
|
541
|
+
assertAPIError(t, err, http.StatusConflict, errCodeCommandReplayInProgress)
|
|
542
|
+
if called {
|
|
543
|
+
t.Fatal("completion callback ran under stale token")
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
func TestCommandReplayExternalDeferWithRejectsStaleTokenBeforeBusinessMutation(t *testing.T) {
|
|
548
|
+
service, _ := newTestCommandReplayService(t)
|
|
549
|
+
lease, err := service.BeginExternal(context.Background(), beginRequest(json.RawMessage(`{"amount":100}`)), time.Minute, func(context.Context, *CommandReplayRecord) (CommandReplayExternalReservation, error) {
|
|
550
|
+
return CommandReplayExternalReservation{ReferenceType: "provider_price_mapping", ReferenceNo: "501"}, nil
|
|
551
|
+
})
|
|
552
|
+
if err != nil {
|
|
553
|
+
t.Fatalf("BeginExternal() error = %v", err)
|
|
554
|
+
}
|
|
555
|
+
called := false
|
|
556
|
+
err = service.DeferExternalWith(
|
|
557
|
+
context.Background(),
|
|
558
|
+
lease.RecordID,
|
|
559
|
+
strings.Repeat("A", 43),
|
|
560
|
+
"provider_timeout",
|
|
561
|
+
commandReplayTestNow.Add(time.Minute),
|
|
562
|
+
func(context.Context, *CommandReplayRecord) error {
|
|
563
|
+
called = true
|
|
564
|
+
return nil
|
|
565
|
+
},
|
|
566
|
+
)
|
|
567
|
+
assertAPIError(t, err, http.StatusConflict, errCodeCommandReplayInProgress)
|
|
568
|
+
if called {
|
|
569
|
+
t.Fatal("defer callback ran under stale token")
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
func newTestCommandReplayService(t *testing.T) (*CommandReplayService, *fakeCommandReplayRepository) {
|
|
574
|
+
t.Helper()
|
|
575
|
+
|
|
576
|
+
db, err := gorm.Open(sqlite.Open(":memory:"), &gorm.Config{})
|
|
577
|
+
if err != nil {
|
|
578
|
+
t.Fatalf("open sqlite: %v", err)
|
|
579
|
+
}
|
|
580
|
+
repo := newFakeCommandReplayRepository()
|
|
581
|
+
service := NewCommandReplayService(repo, database.NewTransactionManager(db))
|
|
582
|
+
service.now = func() time.Time { return commandReplayTestNow }
|
|
583
|
+
return service, repo
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
func beginRequest(payload json.RawMessage) CommandReplayBeginRequest {
|
|
587
|
+
return CommandReplayBeginRequest{
|
|
588
|
+
Namespace: commandReplayTestNamespace,
|
|
589
|
+
CommandScope: "quote:123",
|
|
590
|
+
IdempotencyKey: "key-123",
|
|
591
|
+
RequestPayload: payload,
|
|
592
|
+
Metadata: json.RawMessage(`{"source":"test"}`),
|
|
593
|
+
TTL: time.Hour,
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
func seedCommandReplayRecord(t *testing.T, payload json.RawMessage, mutate func(*CommandReplayRecord)) *CommandReplayRecord {
|
|
598
|
+
t.Helper()
|
|
599
|
+
|
|
600
|
+
record := &CommandReplayRecord{
|
|
601
|
+
Namespace: commandReplayTestNamespace,
|
|
602
|
+
CommandScope: "quote:123",
|
|
603
|
+
IdempotencyKey: "key-123",
|
|
604
|
+
RequestHash: mustCanonicalHash(t, payload),
|
|
605
|
+
Status: CommandReplayStatusStarted,
|
|
606
|
+
ResponsePayload: json.RawMessage(`{}`),
|
|
607
|
+
ExpiresAt: commandReplayTestNow.Add(time.Hour),
|
|
608
|
+
Metadata: json.RawMessage(`{}`),
|
|
609
|
+
}
|
|
610
|
+
if mutate != nil {
|
|
611
|
+
mutate(record)
|
|
612
|
+
}
|
|
613
|
+
return record
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
func successCommandReplayFunc(t *testing.T) CommandReplayExecuteFunc {
|
|
617
|
+
t.Helper()
|
|
618
|
+
|
|
619
|
+
return func(ctx context.Context, record *CommandReplayRecord) (*CommandReplayCommandResult, error) {
|
|
620
|
+
return &CommandReplayCommandResult{
|
|
621
|
+
Status: CommandReplayStatusSucceeded,
|
|
622
|
+
ResponsePayload: json.RawMessage(`{"ok":true}`),
|
|
623
|
+
}, nil
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
func mustCanonicalHash(t *testing.T, payload json.RawMessage) string {
|
|
628
|
+
t.Helper()
|
|
629
|
+
|
|
630
|
+
raw, err := canonicalRawJSONObject(payload, false)
|
|
631
|
+
if err != nil {
|
|
632
|
+
t.Fatalf("canonicalRawJSONObject() error = %v", err)
|
|
633
|
+
}
|
|
634
|
+
hash, err := canonicaljson.Hash(raw)
|
|
635
|
+
if err != nil {
|
|
636
|
+
t.Fatalf("canonicaljson.Hash() error = %v", err)
|
|
637
|
+
}
|
|
638
|
+
return hash
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
func assertAPIError(t *testing.T, err error, status int, code string) {
|
|
642
|
+
t.Helper()
|
|
643
|
+
|
|
644
|
+
var apiErr *apierror.APIError
|
|
645
|
+
if !errors.As(err, &apiErr) {
|
|
646
|
+
t.Fatalf("error = %v, want APIError", err)
|
|
647
|
+
}
|
|
648
|
+
if apiErr.Status != status {
|
|
649
|
+
t.Fatalf("APIError.Status = %d, want %d", apiErr.Status, status)
|
|
650
|
+
}
|
|
651
|
+
if apiErr.Detail.Code != code {
|
|
652
|
+
t.Fatalf("APIError.Code = %q, want %q", apiErr.Detail.Code, code)
|
|
653
|
+
}
|
|
654
|
+
}
|
|
655
|
+
|
|
656
|
+
type fakeCommandReplayRepository struct {
|
|
657
|
+
mu sync.Mutex
|
|
658
|
+
nextID int64
|
|
659
|
+
records map[string]*CommandReplayRecord
|
|
660
|
+
lockAcquired bool
|
|
661
|
+
createHook func(*CommandReplayRecord) error
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
func newFakeCommandReplayRepository() *fakeCommandReplayRepository {
|
|
665
|
+
return &fakeCommandReplayRepository{
|
|
666
|
+
nextID: 1,
|
|
667
|
+
records: make(map[string]*CommandReplayRecord),
|
|
668
|
+
lockAcquired: true,
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
|
|
672
|
+
func (r *fakeCommandReplayRepository) TryAcquireScopeLock(ctx context.Context, namespace, commandScope, idempotencyKey string) (bool, error) {
|
|
673
|
+
r.mu.Lock()
|
|
674
|
+
defer r.mu.Unlock()
|
|
675
|
+
|
|
676
|
+
return r.lockAcquired, nil
|
|
677
|
+
}
|
|
678
|
+
|
|
679
|
+
func (r *fakeCommandReplayRepository) FindByScope(ctx context.Context, namespace, commandScope, idempotencyKey string) (*CommandReplayRecord, error) {
|
|
680
|
+
r.mu.Lock()
|
|
681
|
+
defer r.mu.Unlock()
|
|
682
|
+
|
|
683
|
+
record := r.records[commandReplayRecordKey(namespace, commandScope, idempotencyKey)]
|
|
684
|
+
return cloneCommandReplayRecord(record), nil
|
|
685
|
+
}
|
|
686
|
+
|
|
687
|
+
func (r *fakeCommandReplayRepository) Create(ctx context.Context, record *CommandReplayRecord) error {
|
|
688
|
+
if r.createHook != nil {
|
|
689
|
+
return r.createHook(record)
|
|
690
|
+
}
|
|
691
|
+
|
|
692
|
+
r.mu.Lock()
|
|
693
|
+
defer r.mu.Unlock()
|
|
694
|
+
|
|
695
|
+
key := commandReplayRecordKey(record.Namespace, record.CommandScope, record.IdempotencyKey)
|
|
696
|
+
if _, exists := r.records[key]; exists {
|
|
697
|
+
return ErrCommandReplayRecordExists
|
|
698
|
+
}
|
|
699
|
+
stored := cloneCommandReplayRecord(record)
|
|
700
|
+
if stored.ID == 0 {
|
|
701
|
+
stored.ID = r.nextID
|
|
702
|
+
r.nextID++
|
|
703
|
+
}
|
|
704
|
+
record.ID = stored.ID
|
|
705
|
+
r.records[key] = stored
|
|
706
|
+
return nil
|
|
707
|
+
}
|
|
708
|
+
|
|
709
|
+
func (r *fakeCommandReplayRepository) MarkSucceeded(ctx context.Context, id int64, responsePayload json.RawMessage, completedAt time.Time) error {
|
|
710
|
+
r.mu.Lock()
|
|
711
|
+
defer r.mu.Unlock()
|
|
712
|
+
|
|
713
|
+
record := r.findByIDLocked(id)
|
|
714
|
+
if record == nil {
|
|
715
|
+
return errors.New("record not found")
|
|
716
|
+
}
|
|
717
|
+
record.Status = CommandReplayStatusSucceeded
|
|
718
|
+
record.ResponsePayload = append(json.RawMessage(nil), responsePayload...)
|
|
719
|
+
record.ErrorCode = nil
|
|
720
|
+
record.ErrorStatus = nil
|
|
721
|
+
record.CompletedAt = cloneTimePtr(&completedAt)
|
|
722
|
+
return nil
|
|
723
|
+
}
|
|
724
|
+
|
|
725
|
+
func (r *fakeCommandReplayRepository) MarkFailed(ctx context.Context, id int64, errorCode string, errorStatus int, responsePayload json.RawMessage, completedAt time.Time) error {
|
|
726
|
+
r.mu.Lock()
|
|
727
|
+
defer r.mu.Unlock()
|
|
728
|
+
|
|
729
|
+
record := r.findByIDLocked(id)
|
|
730
|
+
if record == nil {
|
|
731
|
+
return errors.New("record not found")
|
|
732
|
+
}
|
|
733
|
+
record.Status = CommandReplayStatusFailed
|
|
734
|
+
record.ErrorCode = &errorCode
|
|
735
|
+
record.ErrorStatus = &errorStatus
|
|
736
|
+
record.ResponsePayload = append(json.RawMessage(nil), responsePayload...)
|
|
737
|
+
record.CompletedAt = cloneTimePtr(&completedAt)
|
|
738
|
+
return nil
|
|
739
|
+
}
|
|
740
|
+
|
|
741
|
+
func (r *fakeCommandReplayRepository) FindByIDForUpdate(ctx context.Context, id int64) (*CommandReplayRecord, error) {
|
|
742
|
+
r.mu.Lock()
|
|
743
|
+
defer r.mu.Unlock()
|
|
744
|
+
return cloneCommandReplayRecord(r.findByIDLocked(id)), nil
|
|
745
|
+
}
|
|
746
|
+
|
|
747
|
+
func (r *fakeCommandReplayRepository) StartExternalExecution(ctx context.Context, id int64, referenceType, referenceNo, tokenHash string, preparedResponsePayload json.RawMessage, leaseExpiresAt time.Time) error {
|
|
748
|
+
r.mu.Lock()
|
|
749
|
+
defer r.mu.Unlock()
|
|
750
|
+
record := r.findByIDLocked(id)
|
|
751
|
+
if record == nil || record.Status != CommandReplayStatusStarted || record.ExternalReferenceNo != nil {
|
|
752
|
+
return errors.New("external execution cannot start")
|
|
753
|
+
}
|
|
754
|
+
record.ExternalReferenceType = cloneStringPtr(&referenceType)
|
|
755
|
+
record.ExternalReferenceNo = cloneStringPtr(&referenceNo)
|
|
756
|
+
record.ResponsePayload = append(json.RawMessage(nil), preparedResponsePayload...)
|
|
757
|
+
record.ExecutionTokenHash = cloneStringPtr(&tokenHash)
|
|
758
|
+
record.LeaseExpiresAt = cloneTimePtr(&leaseExpiresAt)
|
|
759
|
+
record.ExternalNextRecoveryAt = cloneTimePtr(&leaseExpiresAt)
|
|
760
|
+
record.ExternalAttemptCount = 1
|
|
761
|
+
record.ExternalLastErrorCode = nil
|
|
762
|
+
return nil
|
|
763
|
+
}
|
|
764
|
+
|
|
765
|
+
func (r *fakeCommandReplayRepository) ClaimExternalRecovery(ctx context.Context, id int64, expectedRecoveryAt time.Time, tokenHash string, leaseExpiresAt time.Time) error {
|
|
766
|
+
r.mu.Lock()
|
|
767
|
+
defer r.mu.Unlock()
|
|
768
|
+
record := r.findByIDLocked(id)
|
|
769
|
+
if record == nil || record.Status != CommandReplayStatusStarted || record.ExternalNextRecoveryAt == nil ||
|
|
770
|
+
!record.ExternalNextRecoveryAt.Equal(expectedRecoveryAt) {
|
|
771
|
+
return errors.New("external recovery cannot be claimed")
|
|
772
|
+
}
|
|
773
|
+
record.ExecutionTokenHash = cloneStringPtr(&tokenHash)
|
|
774
|
+
record.LeaseExpiresAt = cloneTimePtr(&leaseExpiresAt)
|
|
775
|
+
record.ExternalNextRecoveryAt = cloneTimePtr(&leaseExpiresAt)
|
|
776
|
+
record.ExternalAttemptCount++
|
|
777
|
+
record.ExternalLastErrorCode = nil
|
|
778
|
+
return nil
|
|
779
|
+
}
|
|
780
|
+
|
|
781
|
+
func (r *fakeCommandReplayRepository) DeferExternalExecution(ctx context.Context, id int64, tokenHash, errorCode string, nextRecoveryAt time.Time) error {
|
|
782
|
+
r.mu.Lock()
|
|
783
|
+
defer r.mu.Unlock()
|
|
784
|
+
record := r.findByIDLocked(id)
|
|
785
|
+
if record == nil || record.ExecutionTokenHash == nil || *record.ExecutionTokenHash != tokenHash {
|
|
786
|
+
return errors.New("external execution cannot be deferred")
|
|
787
|
+
}
|
|
788
|
+
record.ExecutionTokenHash = nil
|
|
789
|
+
record.LeaseExpiresAt = nil
|
|
790
|
+
record.ExternalNextRecoveryAt = cloneTimePtr(&nextRecoveryAt)
|
|
791
|
+
record.ExternalLastErrorCode = cloneStringPtr(&errorCode)
|
|
792
|
+
return nil
|
|
793
|
+
}
|
|
794
|
+
|
|
795
|
+
func (r *fakeCommandReplayRepository) ClearExternalExecution(ctx context.Context, id int64, tokenHash string) error {
|
|
796
|
+
r.mu.Lock()
|
|
797
|
+
defer r.mu.Unlock()
|
|
798
|
+
record := r.findByIDLocked(id)
|
|
799
|
+
if record == nil || record.ExecutionTokenHash == nil || *record.ExecutionTokenHash != tokenHash {
|
|
800
|
+
return errors.New("external execution cannot be cleared")
|
|
801
|
+
}
|
|
802
|
+
record.ExternalReferenceType = nil
|
|
803
|
+
record.ExternalReferenceNo = nil
|
|
804
|
+
record.ExecutionTokenHash = nil
|
|
805
|
+
record.LeaseExpiresAt = nil
|
|
806
|
+
record.ExternalNextRecoveryAt = nil
|
|
807
|
+
record.ExternalAttemptCount = 0
|
|
808
|
+
record.ExternalLastErrorCode = nil
|
|
809
|
+
return nil
|
|
810
|
+
}
|
|
811
|
+
|
|
812
|
+
func (r *fakeCommandReplayRepository) ListDueExternalRecoveries(ctx context.Context, referenceType string, at time.Time, limit int) ([]CommandReplayRecord, error) {
|
|
813
|
+
r.mu.Lock()
|
|
814
|
+
defer r.mu.Unlock()
|
|
815
|
+
records := make([]CommandReplayRecord, 0, limit)
|
|
816
|
+
for _, record := range r.records {
|
|
817
|
+
if record.ExternalReferenceType != nil && *record.ExternalReferenceType == referenceType && record.Status == CommandReplayStatusStarted &&
|
|
818
|
+
record.HasExternalReservation() && record.ExternalNextRecoveryAt != nil && !record.ExternalNextRecoveryAt.After(at) && !record.HasActiveExternalLease(at) {
|
|
819
|
+
records = append(records, *cloneCommandReplayRecord(record))
|
|
820
|
+
if len(records) == limit {
|
|
821
|
+
break
|
|
822
|
+
}
|
|
823
|
+
}
|
|
824
|
+
}
|
|
825
|
+
return records, nil
|
|
826
|
+
}
|
|
827
|
+
|
|
828
|
+
func (r *fakeCommandReplayRepository) seed(record *CommandReplayRecord) {
|
|
829
|
+
r.mu.Lock()
|
|
830
|
+
defer r.mu.Unlock()
|
|
831
|
+
|
|
832
|
+
stored := cloneCommandReplayRecord(record)
|
|
833
|
+
if stored.ID == 0 {
|
|
834
|
+
stored.ID = r.nextID
|
|
835
|
+
r.nextID++
|
|
836
|
+
}
|
|
837
|
+
record.ID = stored.ID
|
|
838
|
+
key := commandReplayRecordKey(stored.Namespace, stored.CommandScope, stored.IdempotencyKey)
|
|
839
|
+
r.records[key] = stored
|
|
840
|
+
}
|
|
841
|
+
|
|
842
|
+
func (r *fakeCommandReplayRepository) mustFind(t *testing.T, namespace, commandScope, idempotencyKey string) *CommandReplayRecord {
|
|
843
|
+
t.Helper()
|
|
844
|
+
|
|
845
|
+
r.mu.Lock()
|
|
846
|
+
defer r.mu.Unlock()
|
|
847
|
+
|
|
848
|
+
record := r.records[commandReplayRecordKey(namespace, commandScope, idempotencyKey)]
|
|
849
|
+
if record == nil {
|
|
850
|
+
t.Fatalf("record not found")
|
|
851
|
+
}
|
|
852
|
+
return cloneCommandReplayRecord(record)
|
|
853
|
+
}
|
|
854
|
+
|
|
855
|
+
func (r *fakeCommandReplayRepository) findByIDLocked(id int64) *CommandReplayRecord {
|
|
856
|
+
for _, record := range r.records {
|
|
857
|
+
if record.ID == id {
|
|
858
|
+
return record
|
|
859
|
+
}
|
|
860
|
+
}
|
|
861
|
+
return nil
|
|
862
|
+
}
|
|
863
|
+
|
|
864
|
+
func commandReplayRecordKey(namespace, commandScope, idempotencyKey string) string {
|
|
865
|
+
return namespace + "\x00" + commandScope + "\x00" + idempotencyKey
|
|
866
|
+
}
|
|
867
|
+
|
|
868
|
+
func cloneCommandReplayRecord(record *CommandReplayRecord) *CommandReplayRecord {
|
|
869
|
+
if record == nil {
|
|
870
|
+
return nil
|
|
871
|
+
}
|
|
872
|
+
cloned := *record
|
|
873
|
+
cloned.PrincipalType = cloneStringPtr(record.PrincipalType)
|
|
874
|
+
cloned.PrincipalRef = cloneStringPtr(record.PrincipalRef)
|
|
875
|
+
cloned.ErrorCode = cloneStringPtr(record.ErrorCode)
|
|
876
|
+
cloned.ErrorStatus = cloneIntPtr(record.ErrorStatus)
|
|
877
|
+
cloned.ResponsePayload = append(json.RawMessage(nil), record.ResponsePayload...)
|
|
878
|
+
cloned.Metadata = append(json.RawMessage(nil), record.Metadata...)
|
|
879
|
+
cloned.CompletedAt = cloneTimePtr(record.CompletedAt)
|
|
880
|
+
cloned.ExternalReferenceType = cloneStringPtr(record.ExternalReferenceType)
|
|
881
|
+
cloned.ExternalReferenceNo = cloneStringPtr(record.ExternalReferenceNo)
|
|
882
|
+
cloned.ExecutionTokenHash = cloneStringPtr(record.ExecutionTokenHash)
|
|
883
|
+
cloned.LeaseExpiresAt = cloneTimePtr(record.LeaseExpiresAt)
|
|
884
|
+
cloned.ExternalNextRecoveryAt = cloneTimePtr(record.ExternalNextRecoveryAt)
|
|
885
|
+
cloned.ExternalLastErrorCode = cloneStringPtr(record.ExternalLastErrorCode)
|
|
886
|
+
return &cloned
|
|
887
|
+
}
|
|
888
|
+
|
|
889
|
+
func ptrInt(value int) *int {
|
|
890
|
+
return &value
|
|
891
|
+
}
|