@vesviet/agent-skills 5.7.3 → 5.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/INDEX.md +21 -18
- package/README.md +11 -10
- package/VERSION +1 -1
- package/adapters/antigravity/ANTIGRAVITY.md +89 -4
- package/adapters/antigravity/INDEX_TIER1.json +1294 -0
- package/adapters/antigravity/a2a-config.template.yaml +22 -8
- package/adapters/antigravity/role-skill-index.json +48 -19
- package/adapters/claude/CLAUDE_ADAPTER.md +1 -1
- package/adapters/claude/settings.template.json +7 -3
- package/adapters/cursor/hooks.template.json +3 -1
- package/core/contracts/README.md +4 -1
- package/core/contracts/schemas/INDEX.md +7 -1
- package/core/contracts/schemas/a2a-artifact.json +9 -2
- package/core/contracts/schemas/a2a-jsonrpc-envelope.json +7 -2
- package/core/contracts/schemas/a2a-task-progress.json +15 -4
- package/core/contracts/schemas/a2a-task.json +11 -3
- package/core/contracts/schemas/agent-card.json +48 -1
- package/core/contracts/schemas/agent-skills-discovery.json +91 -0
- package/core/contracts/schemas/compliance-report.json +255 -0
- package/core/contracts/schemas/mcp-server-card.json +193 -0
- package/core/contracts/schemas/seo-content-brief.json +1 -1
- package/core/contracts/schemas/seo-weekly-board.json +1 -1
- package/core/contracts/schemas/series-article.json +1 -1
- package/core/policies/action-boundaries.yaml +334 -2
- package/core/policies/mcp-tool-map.yaml +61 -4
- package/core/roles/3d-graphics-engineer.md +5 -1
- package/core/roles/README.md +1 -1
- package/core/roles/agent-coordinator.md +21 -3
- package/core/roles/agent-discovery-engineer.md +27 -8
- package/core/roles/ai-systems-engineer.md +3 -1
- package/core/roles/aws-engineer.md +6 -8
- package/core/roles/backend-developer.md +5 -5
- package/core/roles/business-analyst.md +4 -2
- package/core/roles/cloudflare-engineer.md +4 -2
- package/core/roles/content-manager.md +3 -1
- package/core/roles/content-writer.md +3 -1
- package/core/roles/data-analyst.md +3 -1
- package/core/roles/data-engineer.md +3 -1
- package/core/roles/devops-engineer.md +9 -9
- package/core/roles/ecommerce-engineer.md +7 -7
- package/core/roles/frontend-developer.md +10 -8
- package/core/roles/game-developer.md +5 -3
- package/core/roles/mmo-engineer.md +8 -9
- package/core/roles/mobile-engineer.md +5 -3
- package/core/roles/product-manager.md +8 -9
- package/core/roles/project-manager.md +10 -13
- package/core/roles/prompt-engineer.md +6 -4
- package/core/roles/qa-engineer.md +9 -9
- package/core/roles/references/vietnam-accounting-specialist-review-checklist.md +6 -6
- package/core/roles/researcher.md +12 -14
- package/core/roles/reverse-engineer.md +5 -2
- package/core/roles/reviewer.md +7 -5
- package/core/roles/role-standard.md +23 -1
- package/core/roles/sdet.md +7 -5
- package/core/roles/security-engineer.md +9 -7
- package/core/roles/seo-analyst.md +9 -7
- package/core/roles/solution-architect.md +8 -9
- package/core/roles/sre.md +8 -6
- package/core/roles/system-engineer.md +20 -20
- package/core/roles/task-planner.md +8 -10
- package/core/roles/teacher.md +8 -6
- package/core/roles/technical-architect.md +10 -8
- package/core/roles/technical-lead.md +9 -7
- package/core/roles/technical-writer.md +8 -6
- package/core/roles/ui-ux-designer.md +8 -7
- package/core/roles/vietnam-accounting-specialist.md +26 -24
- package/core/roles/vietnam-legal-counsel.md +6 -4
- package/core/rules/code.md +11 -6
- package/core/skills/README.md +3 -2
- package/core/skills/agent/agent-a2a-protocol/SKILL.md +25 -93
- package/core/skills/agent/agent-memory-compaction/SKILL.md +27 -0
- package/core/skills/agent/architect-mcp-server/SKILL.md +35 -27
- package/core/skills/agent/configure-agent-commerce/SKILL.md +2 -0
- package/core/skills/agent/configure-agent-commerce/examples/ucp-commerce-manifest-and-endpoints.json +55 -0
- package/core/skills/agent/configure-agent-commerce/references/acp-ucp-agent-commerce-manifest-specs.md +66 -0
- package/core/skills/agent/configure-agent-skills/SKILL.md +60 -68
- package/core/skills/agent/manage-agent-identity/SKILL.md +2 -0
- package/core/skills/agent/manage-agent-identity/examples/agent-identity-spire-workload.yaml +72 -0
- package/core/skills/agent/manage-agent-identity/references/nhi-lifecycle-and-token-rotation.md +45 -0
- package/core/skills/ai/openrouter-task/SKILL.md +5 -5
- package/core/skills/ai-agent/agent-evaluation/resources/eval-benchmarks/eval-cases.json +529 -0
- package/core/skills/ai-agent/agent-evaluation/resources/eval-benchmarks/eval-manifest.yaml +61 -0
- package/core/skills/ai-agent/agent-evaluation/scripts/run-eval-benchmark.py +856 -0
- package/core/skills/ai-agent/agent-evaluation/tests/test_golden_benchmarks.py +248 -0
- package/core/skills/ai-agent/context-optimization/SKILL.md +61 -60
- package/core/skills/ai-agent/context-optimization/examples/context-pruner-and-reorderer.py +85 -0
- package/core/skills/ai-agent/context-optimization/references/token-budgeting-and-attention-allocation.md +47 -0
- package/core/skills/ai-agent/memory-hygiene/SKILL.md +13 -0
- package/core/skills/ai-agent/memory-hygiene/examples/memory-audit-and-compaction-routine.py +90 -0
- package/core/skills/ai-agent/memory-hygiene/references/agent-memory-vault-spec.md +137 -0
- package/core/skills/ai-agent/memory-hygiene/references/owasp-asi06-and-memory-poisoning-defense.md +38 -0
- package/core/skills/backend/add-api-endpoint/examples/express-zod-rfc9457-endpoint.md +329 -0
- package/core/skills/backend/add-api-endpoint/examples/kratos-go-clean-architecture-endpoint.md +405 -0
- package/core/skills/backend/add-api-endpoint/references/idempotency-and-rate-limiting.md +116 -0
- package/core/skills/backend/add-event-handler/SKILL.md +1 -1
- package/core/skills/backend/scaffold-new-service/SKILL.md +2 -1
- package/core/skills/backend/scaffold-new-service/references/deep-modules-and-seams.md +43 -0
- package/core/skills/business/elicit-requirements/SKILL.md +1 -0
- package/core/skills/commerce/handle-checkout-flow/SKILL.md +3 -1
- package/core/skills/commerce/handle-checkout-flow/examples/production-checkout-orchestrator.ts +185 -0
- package/core/skills/commerce/handle-checkout-flow/references/pci-dss-v4-and-agentic-checkout-specs.md +72 -0
- package/core/skills/commerce/integrate-payment-gateway/SKILL.md +3 -1
- package/core/skills/commerce/integrate-payment-gateway/examples/resilient-webhook-and-mpp-handler.ts +164 -0
- package/core/skills/commerce/integrate-payment-gateway/references/mpp-x402-and-webhook-security-specs.md +47 -0
- package/core/skills/commerce/manage-order-fulfillment/SKILL.md +3 -1
- package/core/skills/commerce/manage-order-fulfillment/examples/temporal-fulfillment-saga.ts +104 -0
- package/core/skills/commerce/manage-order-fulfillment/references/event-sourced-fulfillment-and-carrier-webhooks.md +58 -0
- package/core/skills/commerce/manage-product-catalog/SKILL.md +3 -1
- package/core/skills/commerce/manage-product-catalog/examples/hybrid-search-and-governance-pipeline.ts +120 -0
- package/core/skills/commerce/manage-product-catalog/references/semantic-vector-catalog-and-graphrag.md +54 -0
- package/core/skills/content/write-article/SKILL.md +1 -1
- package/core/skills/document/pdf/SKILL.md +1 -0
- package/core/skills/document/pdf/references/pdf-acroforms-and-pdfplumber-specs.md +54 -0
- package/core/skills/document/pdf/scripts/check_fillable_fields.py +144 -0
- package/core/skills/document/pdf/scripts/fill_fillable_fields.py +145 -0
- package/core/skills/documentation/configure-llms-txt/SKILL.md +2 -0
- package/core/skills/documentation/configure-llms-txt/examples/canonical-llms-txt-and-full-txt.md +45 -0
- package/core/skills/documentation/configure-llms-txt/references/llms-txt-and-llms-full-txt-standard.md +37 -0
- package/core/skills/documentation/write-documentation/SKILL.md +3 -1
- package/core/skills/documentation/write-documentation/examples/microservice-production-readme-and-api-docs.md +70 -0
- package/core/skills/documentation/write-documentation/references/diataxis-framework-and-doc-standards.md +62 -0
- package/core/skills/foundation/ai-risk-assessment/SKILL.md +3 -5
- package/core/skills/foundation/ai-risk-assessment/examples/genai-system-risk-register.md +67 -0
- package/core/skills/foundation/ai-risk-assessment/references/nist-ai-rmf-and-eu-ai-act-taxonomy.md +49 -0
- package/core/skills/foundation/conduct-research/SKILL.md +1 -1
- package/core/skills/foundation/discernment-nudge/SKILL.md +1 -0
- package/core/skills/foundation/plan-technical-delivery/SKILL.md +2 -1
- package/core/skills/foundation/release-notes/SKILL.md +2 -3
- package/core/skills/foundation/release-notes/examples/enterprise-platform-release-notes.md +42 -0
- package/core/skills/foundation/release-notes/references/keep-a-changelog-and-semver-governance.md +43 -0
- package/core/skills/foundation/systematic-debugging/SKILL.md +5 -0
- package/core/skills/foundation/write-tests/examples/anti-tautological-tdd-walkthrough.md +204 -0
- package/core/skills/foundation/write-tests/examples/testcontainers-kratos-integration-test.md +186 -0
- package/core/skills/foundation/write-tests/references/contract-and-chaos-testing.md +187 -0
- package/core/skills/frontend/INDEX.json +16 -0
- package/core/skills/frontend/add-page-route/SKILL.md +3 -1
- package/core/skills/frontend/add-page-route/examples/streaming-rsc-page-with-view-transition.tsx +133 -0
- package/core/skills/frontend/add-page-route/references/rsc-routing-and-view-transitions.md +72 -0
- package/core/skills/frontend/add-ui-component/SKILL.md +3 -1
- package/core/skills/frontend/add-ui-component/examples/compound-dialog-and-form-actions.tsx +193 -0
- package/core/skills/frontend/add-ui-component/references/react19-component-standards-and-anti-slop.md +55 -0
- package/core/skills/frontend/component-composition/SKILL.md +2 -1
- package/core/skills/frontend/component-composition/examples/headless-combobox-compound-component.tsx +207 -0
- package/core/skills/frontend/frontend-testing/SKILL.md +3 -1
- package/core/skills/frontend/frontend-testing/examples/playwright-e2e-with-msw-and-axe.spec.ts +87 -0
- package/core/skills/frontend/frontend-testing/references/playwright-msw-and-a11y-testing-standards.md +78 -0
- package/core/skills/frontend/implement-ai-disclosure/SKILL.md +118 -0
- package/core/skills/frontend/implement-webmcp/SKILL.md +3 -1
- package/core/skills/frontend/implement-webmcp/examples/webmcp-provider-and-hitl-modal.tsx +163 -0
- package/core/skills/frontend/implement-webmcp/references/webmcp-architecture-and-hitl-security.md +48 -0
- package/core/skills/frontend/integrate-api-client/SKILL.md +3 -1
- package/core/skills/frontend/integrate-api-client/examples/orval-query-and-streaming-mutation.ts +102 -0
- package/core/skills/frontend/integrate-api-client/references/orval-tanstack-query-and-streaming-specs.md +57 -0
- package/core/skills/frontend/setup-design-system/SKILL.md +3 -1
- package/core/skills/frontend/setup-design-system/examples/tailwind-v4-theme-and-dtcg-tokens.css +87 -0
- package/core/skills/frontend/setup-design-system/references/tailwind-v4-oklch-and-dtcg-tokens.md +61 -0
- package/core/skills/frontend/setup-visual-regression/SKILL.md +3 -1
- package/core/skills/frontend/setup-visual-regression/examples/visual-regression-playwright.config.ts +83 -0
- package/core/skills/frontend/setup-visual-regression/references/visual-regression-docker-and-masking-specs.md +46 -0
- package/core/skills/gamedev/abstract-input-actions/SKILL.md +2 -0
- package/core/skills/gamedev/abstract-input-actions/examples/input-action-manager.ts +85 -0
- package/core/skills/gamedev/abstract-input-actions/references/action-mapping-and-analog-deadzones.md +54 -0
- package/core/skills/gamedev/architect-ecs-systems/SKILL.md +2 -0
- package/core/skills/gamedev/architect-ecs-systems/examples/bevy-flecs-combat-system.rs +73 -0
- package/core/skills/gamedev/architect-ecs-systems/references/data-oriented-design-and-archetype-ecs.md +39 -0
- package/core/skills/gamedev/author-game-ai/SKILL.md +2 -0
- package/core/skills/gamedev/author-game-ai/examples/modular-behavior-tree-ai.ts +98 -0
- package/core/skills/gamedev/author-game-ai/references/behavior-trees-and-utility-ai-curves.md +47 -0
- package/core/skills/gamedev/configure-physics-collision/SKILL.md +2 -0
- package/core/skills/gamedev/configure-physics-collision/examples/kinematic-physics-substepping.cpp +100 -0
- package/core/skills/gamedev/configure-physics-collision/references/continuous-collision-detection-and-substepping.md +50 -0
- package/core/skills/gamedev/develop-gameplay-systems/SKILL.md +2 -0
- package/core/skills/gamedev/develop-gameplay-systems/examples/kinematic-character-controller.gd +86 -0
- package/core/skills/gamedev/develop-gameplay-systems/references/deterministic-gameplay-state-machines.md +42 -0
- package/core/skills/gamedev/implement-save-persistence/SKILL.md +2 -0
- package/core/skills/gamedev/implement-save-persistence/examples/versioned-save-manager.ts +127 -0
- package/core/skills/gamedev/implement-save-persistence/references/versioned-save-schemas-and-checksums.md +44 -0
- package/core/skills/gamedev/render-webgl-threejs/SKILL.md +2 -0
- package/core/skills/gamedev/render-webgl-threejs/examples/production-threejs-webgpu-scene.ts +116 -0
- package/core/skills/gamedev/render-webgl-threejs/references/webgpu-threejs-pbr-pipeline.md +56 -0
- package/core/skills/mmo/analyze-campaign-roi/SKILL.md +2 -0
- package/core/skills/mmo/analyze-campaign-roi/examples/campaign-roi-and-roas-dashboard.py +80 -0
- package/core/skills/mmo/analyze-campaign-roi/references/multi-touch-attribution-and-cpa-analytics.md +33 -0
- package/core/skills/mmo/create-automation-script/SKILL.md +2 -0
- package/core/skills/mmo/create-automation-script/examples/stealth-browser-automation-flow.ts +65 -0
- package/core/skills/mmo/create-automation-script/references/stealth-cdp-and-behavioral-mimicry.md +37 -0
- package/core/skills/mmo/deploy-mmo-infrastructure/SKILL.md +2 -0
- package/core/skills/mmo/deploy-mmo-infrastructure/examples/proxy-health-probe-and-rotation-daemon.py +75 -0
- package/core/skills/mmo/deploy-mmo-infrastructure/references/proxy-pool-rotation-and-anti-detect-specs.md +45 -0
- package/core/skills/mmo/deploy-proxyware-fleet/SKILL.md +2 -0
- package/core/skills/mmo/deploy-proxyware-fleet/examples/docker-compose-depin-light-node-fleet.yaml +52 -0
- package/core/skills/mmo/deploy-proxyware-fleet/references/depin-bandwidth-monetization-node-specs.md +43 -0
- package/core/skills/mmo/generate-mmo-content/SKILL.md +2 -0
- package/core/skills/mmo/generate-mmo-content/examples/pseo-programmatic-page-generator.ts +76 -0
- package/core/skills/mmo/generate-mmo-content/references/pseo-landing-pages-and-social-video-hooks.md +39 -0
- package/core/skills/mmo/manage-mmo-assets/SKILL.md +2 -0
- package/core/skills/mmo/manage-mmo-assets/examples/mmo-asset-vault-manager.py +63 -0
- package/core/skills/mmo/manage-mmo-assets/references/mmo-asset-rbac-and-vault-isolation.md +38 -0
- package/core/skills/mmo/setup-tracking-system/SKILL.md +2 -0
- package/core/skills/mmo/setup-tracking-system/examples/meta-capi-s2s-event-dispatcher.ts +79 -0
- package/core/skills/mmo/setup-tracking-system/references/server-to-server-postback-and-capi-specs.md +45 -0
- package/core/skills/platform/add-telemetry-instrumentation/SKILL.md +2 -0
- package/core/skills/platform/add-telemetry-instrumentation/examples/kratos-otel-middleware-instrumentation.go +87 -0
- package/core/skills/platform/add-telemetry-instrumentation/references/opentelemetry-semantic-conventions-2026.md +37 -0
- package/core/skills/platform/aws-infrastructure/SKILL.md +2 -0
- package/core/skills/platform/aws-infrastructure/examples/opentofu-eks-pod-identity-vpc.tf +101 -0
- package/core/skills/platform/aws-infrastructure/references/opentofu-aws-zero-trust-and-irsa.md +40 -0
- package/core/skills/platform/setup-deployment/SKILL.md +4 -0
- package/core/skills/platform/setup-deployment/examples/kustomize-production-service-manifests.yaml +123 -0
- package/core/skills/platform/setup-deployment/references/interactive-hitl-wizard.md +55 -0
- package/core/skills/platform/setup-deployment/references/k8s-gitops-and-kustomize-invariants.md +40 -0
- package/core/skills/platform/supply-chain-security/SKILL.md +2 -0
- package/core/skills/platform/supply-chain-security/examples/github-actions-sbom-cosign.yaml +57 -0
- package/core/skills/platform/supply-chain-security/references/slsa-provenance-and-sbom-sigstore.md +60 -0
- package/core/skills/product/build-story-map/SKILL.md +2 -0
- package/core/skills/repo-ops/review-code/SKILL.md +2 -2
- package/core/skills/repo-ops/review-code/examples/adversarial-two-axis-pr-review.md +167 -0
- package/core/skills/repo-ops/review-code/examples/ai-vibe-slop-remediation.md +220 -0
- package/core/skills/repo-ops/review-code/references/supply-chain-and-migration-safety.md +103 -0
- package/core/skills/repo-ops/review-service/SKILL.md +1 -1
- package/core/skills/security-data/database-maintenance/SKILL.md +1 -1
- package/core/skills/security-data/manage-secrets/SKILL.md +2 -0
- package/core/skills/security-data/manage-secrets/examples/external-secrets-vault-crds.yaml +53 -0
- package/core/skills/security-data/manage-secrets/references/zero-trust-secret-rotation-and-eso.md +30 -0
- package/core/skills/security-data/manage-vietnam-accounting/SKILL.md +7 -7
- package/core/skills/security-data/prompt-injection-defense/SKILL.md +2 -0
- package/core/skills/security-data/prompt-injection-defense/examples/bounded-tool-execution-wrapper.py +78 -0
- package/core/skills/security-data/prompt-injection-defense/references/prompt-injection-taxonomy-and-delimiters.md +37 -0
- package/core/skills/security-data/reverse-engineer-binary/SKILL.md +2 -0
- package/core/skills/security-data/reverse-engineer-binary/examples/binary-triage-and-vulnerability-dossier.md +58 -0
- package/core/skills/security-data/reverse-engineer-binary/references/ghidra-radare2-and-rea-evidence-ledgers.md +43 -0
- package/core/skills/security-data/security-audit/SKILL.md +3 -1
- package/core/skills/security-data/security-audit/examples/enterprise-service-security-audit-report.md +54 -0
- package/core/skills/security-data/security-audit/references/owasp-asi-and-cvss4-threat-modeling.md +39 -0
- package/core/skills/security-data/skill-preflight-ast-check/SKILL.md +2 -0
- package/core/skills/security-data/skill-preflight-ast-check/references/ast-lethal-trifecta-and-static-vetting.md +38 -0
- package/core/skills/security-data/skill-preflight-ast-check/scripts/scan-skill-ast.py +127 -0
- package/overlays/README.md +1 -1
- package/overlays/security-research/README.md +1 -1
- package/package.json +2 -2
- package/overlays/security-research/skills/reverse-engineer-binary/SKILL.md +0 -129
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
# Worked Example: Testcontainers + Go Kratos Integration Test
|
|
2
|
+
|
|
3
|
+
This worked example demonstrates an ephemeral integration test for Go Kratos microservices using `testcontainers-go` to spin up PostgreSQL 18, Wire dependency injection, uncommitted transactional rollbacks (`InTx`) for cross-test state isolation, and goroutine leak detection (`goleak`).
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## 1. Test Suite Architecture
|
|
8
|
+
|
|
9
|
+
```
|
|
10
|
+
┌────────────────────────────────────────────────────────┐
|
|
11
|
+
│ go test -v -race │
|
|
12
|
+
│ │
|
|
13
|
+
│ ┌──────────────────┐ ┌────────────────────┐ │
|
|
14
|
+
│ │ TestMain Setup ├─────────►│ PostgreSQL 18 │ │
|
|
15
|
+
│ │ (testcontainers) │ │ Ephemeral Container│ │
|
|
16
|
+
│ └────────┬─────────┘ └─────────▲──────────┘ │
|
|
17
|
+
│ │ │ │
|
|
18
|
+
│ ┌────────▼─────────┐ │ │
|
|
19
|
+
│ │ Wire DI Init │ │ │
|
|
20
|
+
│ │ (TestProviderSet)│ │ │
|
|
21
|
+
│ └────────┬─────────┘ │ │
|
|
22
|
+
│ │ │ │
|
|
23
|
+
│ ┌────────▼──────────────────────────────┴──────────┐ │
|
|
24
|
+
│ │ Subtest 1: InTx Rollback ──► Zero State Contam. │ │
|
|
25
|
+
│ │ Subtest 2: InTx Rollback ──► Zero State Contam. │ │
|
|
26
|
+
│ │ goleak.VerifyNone(t) ──► Zero Leaks │ │
|
|
27
|
+
│ └──────────────────────────────────────────────────┘ │
|
|
28
|
+
└────────────────────────────────────────────────────────┘
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
---
|
|
32
|
+
|
|
33
|
+
## 2. Complete Integration Test (`test/payment_integration_test.go`)
|
|
34
|
+
|
|
35
|
+
```go
|
|
36
|
+
package test
|
|
37
|
+
|
|
38
|
+
import (
|
|
39
|
+
"context"
|
|
40
|
+
"fmt"
|
|
41
|
+
"testing"
|
|
42
|
+
"time"
|
|
43
|
+
|
|
44
|
+
"payment/internal/biz"
|
|
45
|
+
"payment/internal/data"
|
|
46
|
+
|
|
47
|
+
"github.com/go-kratos/kratos/v2/log"
|
|
48
|
+
"github.com/stretchr/testify/assert"
|
|
49
|
+
"github.com/stretchr/testify/require"
|
|
50
|
+
"github.com/testcontainers/testcontainers-go"
|
|
51
|
+
"github.com/testcontainers/testcontainers-go/modules/postgres"
|
|
52
|
+
"github.com/testcontainers/testcontainers-go/wait"
|
|
53
|
+
"go.uber.org/goleak"
|
|
54
|
+
gormpg "gorm.io/driver/postgres"
|
|
55
|
+
"gorm.io/gorm"
|
|
56
|
+
)
|
|
57
|
+
|
|
58
|
+
var (
|
|
59
|
+
testDB *gorm.DB
|
|
60
|
+
pgC *postgres.PostgresContainer
|
|
61
|
+
)
|
|
62
|
+
|
|
63
|
+
func TestMain(m *testing.M) {
|
|
64
|
+
ctx := context.Background()
|
|
65
|
+
|
|
66
|
+
// 1. Start ephemeral PostgreSQL 18 container
|
|
67
|
+
var err error
|
|
68
|
+
pgC, err = postgres.Run(ctx,
|
|
69
|
+
"postgres:18-alpine",
|
|
70
|
+
postgres.WithDatabase("testdb"),
|
|
71
|
+
postgres.WithUsername("testuser"),
|
|
72
|
+
postgres.WithPassword("testpass"),
|
|
73
|
+
testcontainers.WithWaitStrategy(
|
|
74
|
+
wait.ForLog("database system is ready to accept connections").
|
|
75
|
+
WithOccurrence(2).
|
|
76
|
+
WithStartupTimeout(30*time.Second),
|
|
77
|
+
),
|
|
78
|
+
)
|
|
79
|
+
if err != nil {
|
|
80
|
+
panic(fmt.Sprintf("Failed to start Postgres container: %v", err))
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// 2. Obtain connection string and initialize GORM
|
|
84
|
+
connStr, err := pgC.ConnectionString(ctx, "sslmode=disable")
|
|
85
|
+
if err != nil {
|
|
86
|
+
panic(err)
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
testDB, err = gorm.Open(gormpg.Open(connStr), &gorm.Config{})
|
|
90
|
+
if err != nil {
|
|
91
|
+
panic(err)
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// Run auto-migration for test schema
|
|
95
|
+
if err := testDB.AutoMigrate(&data.PaymentPO{}); err != nil {
|
|
96
|
+
panic(err)
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// 3. Execute test suite with goleak verification
|
|
100
|
+
code := m.Run()
|
|
101
|
+
|
|
102
|
+
// 4. Terminate container
|
|
103
|
+
_ = pgC.Terminate(ctx)
|
|
104
|
+
|
|
105
|
+
goleak.VerifyTestMain(m)
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
func TestPaymentUsecase_Integration(t *testing.T) {
|
|
109
|
+
defer goleak.VerifyNone(t)
|
|
110
|
+
|
|
111
|
+
// Dependency injection wiring
|
|
112
|
+
logger := log.DefaultLogger
|
|
113
|
+
d, cleanup, err := data.NewData(testDB, logger)
|
|
114
|
+
require.NoError(t, err)
|
|
115
|
+
defer cleanup()
|
|
116
|
+
|
|
117
|
+
repo := data.NewPaymentRepo(d, logger)
|
|
118
|
+
tx := data.NewTransaction(d)
|
|
119
|
+
uc := biz.NewPaymentUsecase(repo, tx, logger)
|
|
120
|
+
|
|
121
|
+
t.Run("Subtest 1 - Insert payment within isolated transaction rollback", func(t *testing.T) {
|
|
122
|
+
ctx := context.Background()
|
|
123
|
+
|
|
124
|
+
// Execute operation inside a manual transaction that rolls back at end of subtest
|
|
125
|
+
err := testDB.Transaction(func(txDB *gorm.DB) error {
|
|
126
|
+
subData, _, _ := data.NewData(txDB, logger)
|
|
127
|
+
subRepo := data.NewPaymentRepo(subData, logger)
|
|
128
|
+
subUsecase := biz.NewPaymentUsecase(subRepo, data.NewTransaction(subData), logger)
|
|
129
|
+
|
|
130
|
+
payment := &biz.Payment{
|
|
131
|
+
ID: "txn-test-001",
|
|
132
|
+
IdempotencyKey: "idemp-key-alpha",
|
|
133
|
+
AmountCents: 10000,
|
|
134
|
+
Currency: "USD",
|
|
135
|
+
RecipientID: "rec-001",
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
saved, err := subUsecase.ProcessPayment(ctx, payment)
|
|
139
|
+
assert.NoError(t, err)
|
|
140
|
+
assert.Equal(t, "SETTLED", saved.Status)
|
|
141
|
+
|
|
142
|
+
// Verify record exists in active transaction view
|
|
143
|
+
found, err := subRepo.GetByIdempotencyKey(ctx, "idemp-key-alpha")
|
|
144
|
+
assert.NoError(t, err)
|
|
145
|
+
assert.NotNil(t, found)
|
|
146
|
+
assert.Equal(t, "txn-test-001", found.ID)
|
|
147
|
+
|
|
148
|
+
// Return error deliberately to force rollback
|
|
149
|
+
return fmt.Errorf("force-rollback-for-isolation")
|
|
150
|
+
})
|
|
151
|
+
|
|
152
|
+
assert.Error(t, err)
|
|
153
|
+
})
|
|
154
|
+
|
|
155
|
+
t.Run("Subtest 2 - Verify zero state contamination from Subtest 1", func(t *testing.T) {
|
|
156
|
+
ctx := context.Background()
|
|
157
|
+
|
|
158
|
+
// Verify that "idemp-key-alpha" from Subtest 1 does NOT exist in the database
|
|
159
|
+
found, err := repo.GetByIdempotencyKey(ctx, "idemp-key-alpha")
|
|
160
|
+
assert.NoError(t, err)
|
|
161
|
+
assert.Nil(t, found, "Expected database to be clean; rolled back transaction leaked data!")
|
|
162
|
+
|
|
163
|
+
// Insert fresh record cleanly
|
|
164
|
+
payment := &biz.Payment{
|
|
165
|
+
ID: "txn-test-002",
|
|
166
|
+
IdempotencyKey: "idemp-key-alpha", // Reuse same key safely
|
|
167
|
+
AmountCents: 25000,
|
|
168
|
+
Currency: "EUR",
|
|
169
|
+
RecipientID: "rec-002",
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
saved, err := uc.ProcessPayment(ctx, payment)
|
|
173
|
+
assert.NoError(t, err)
|
|
174
|
+
assert.Equal(t, "SETTLED", saved.Status)
|
|
175
|
+
assert.Equal(t, int64(25000), saved.AmountCents)
|
|
176
|
+
})
|
|
177
|
+
}
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
---
|
|
181
|
+
|
|
182
|
+
## 3. Key Verification Guarantees
|
|
183
|
+
|
|
184
|
+
1. **Zero Database Drift**: Each subtest operates in an uncommitted rollback wrapper, eliminating the need to drop tables, run truncate scripts, or restart Docker containers between test cases.
|
|
185
|
+
2. **Ephemeral Port Mapping**: `testcontainers-go` binds PostgreSQL to a random available host port, preventing port collision (`5432 already in use`) in parallel CI runs.
|
|
186
|
+
3. **Goroutine Leak Proof**: `goleak.VerifyNone(t)` guarantees no unclosed database connection pools or background monitoring threads remain active after test completion.
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
# Contract Testing, Chaos Injection & Concurrency Verification — Reference
|
|
2
|
+
|
|
3
|
+
This reference documents 2027 testing standards for resilient distributed systems: Consumer-Driven Contract Testing (PactV3), in-test network chaos injection (Toxiproxy), Circuit Breaker state verification, and strict goroutine leak detection (`goleak`).
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## 1. Consumer-Driven Contract Testing (PactV3)
|
|
8
|
+
|
|
9
|
+
Consumer-Driven Contract Testing eliminates breaking API changes between microservices without requiring brittle end-to-end multi-service test environments.
|
|
10
|
+
|
|
11
|
+
### 1.1 Core Principles
|
|
12
|
+
1. **Consumer-Driven**: The client (consumer) defines expectations for endpoints, query params, headers, and payload structures.
|
|
13
|
+
2. **Flexible Structural Matching**: Contracts assert data types and shape using PactV3 matchers (`like`, `eachLike`, `regex`) rather than hardcoded mock values.
|
|
14
|
+
3. **Provider State Isolation**: Providers set up isolated test fixtures based on a declared `providerState` before verifying interactions.
|
|
15
|
+
|
|
16
|
+
### 1.2 TypeScript PactV3 Consumer Contract Specification
|
|
17
|
+
|
|
18
|
+
```typescript
|
|
19
|
+
import { PactV3, MatchersV3 } from "@pact-foundation/pact";
|
|
20
|
+
import { PaymentClient } from "../clients/payment";
|
|
21
|
+
|
|
22
|
+
const { like, eachLike, regex } = MatchersV3;
|
|
23
|
+
|
|
24
|
+
const provider = new PactV3({
|
|
25
|
+
consumer: "order-service",
|
|
26
|
+
provider: "payment-service",
|
|
27
|
+
dir: "./pacts"
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
test("fetches payment transaction details by transaction ID", async () => {
|
|
31
|
+
await provider
|
|
32
|
+
.given("payment txn_12345 exists and is settled")
|
|
33
|
+
.uponReceiving("a request for payment txn_12345")
|
|
34
|
+
.withRequest({
|
|
35
|
+
method: "GET",
|
|
36
|
+
path: "/v1/payments/txn_12345",
|
|
37
|
+
headers: { Accept: "application/json" }
|
|
38
|
+
})
|
|
39
|
+
.willRespondWith({
|
|
40
|
+
status: 200,
|
|
41
|
+
headers: { "Content-Type": "application/json" },
|
|
42
|
+
body: {
|
|
43
|
+
paymentId: like("txn_12345"),
|
|
44
|
+
status: regex("SETTLED|AUTHORIZED", "SETTLED"),
|
|
45
|
+
amountCents: like(10000),
|
|
46
|
+
currency: regex("^[A-Z]{3}$", "USD"),
|
|
47
|
+
lineItems: eachLike({
|
|
48
|
+
itemId: like("item_abc"),
|
|
49
|
+
quantity: like(1)
|
|
50
|
+
})
|
|
51
|
+
}
|
|
52
|
+
})
|
|
53
|
+
.executeTest(async (mockServer) => {
|
|
54
|
+
const client = new PaymentClient(mockServer.url);
|
|
55
|
+
const res = await client.getPayment("txn_12345");
|
|
56
|
+
expect(res.paymentId).toBe("txn_12345");
|
|
57
|
+
expect(res.status).toBe("SETTLED");
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
---
|
|
63
|
+
|
|
64
|
+
## 2. In-Test Chaos Injection via Toxiproxy
|
|
65
|
+
|
|
66
|
+
Unit tests with in-memory mocks fail to verify real-world transport failure handling. Toxiproxy simulates production network faults deterministically in local integration tests.
|
|
67
|
+
|
|
68
|
+
### 2.1 Toxic Types & Failure Modes
|
|
69
|
+
- **`latency`**: Adds simulated latency and jitter (e.g., 2000ms ± 500ms) to trigger timeouts and race conditions.
|
|
70
|
+
- **`reset_peer`**: Simulates TCP RST packets or abrupt network disconnects mid-stream.
|
|
71
|
+
- **`bandwidth`**: Limits downstream or upstream throughput (e.g., 10 KB/s) to simulate mobile packet loss or network degradation.
|
|
72
|
+
- **`slicer`**: Slices TCP packets into small chunks with delays to test socket streaming parsers.
|
|
73
|
+
|
|
74
|
+
### 2.2 Go In-Test Toxiproxy Walkthrough
|
|
75
|
+
|
|
76
|
+
```go
|
|
77
|
+
package chaos_test
|
|
78
|
+
|
|
79
|
+
import (
|
|
80
|
+
"context"
|
|
81
|
+
"testing"
|
|
82
|
+
"time"
|
|
83
|
+
|
|
84
|
+
toxiproxy "github.com/Shopify/toxiproxy/v2/client"
|
|
85
|
+
"github.com/stretchr/testify/assert"
|
|
86
|
+
)
|
|
87
|
+
|
|
88
|
+
func TestClientCircuitBreakerUnderNetworkChaos(t *testing.T) {
|
|
89
|
+
toxiClient := toxiproxy.NewClient("localhost:8474")
|
|
90
|
+
|
|
91
|
+
// Create proxy between payment client and downstream mock server
|
|
92
|
+
proxy, err := toxiClient.CreateProxy("payment_proxy", "localhost:28080", "localhost:18080")
|
|
93
|
+
assert.NoError(t, err)
|
|
94
|
+
defer proxy.Delete()
|
|
95
|
+
|
|
96
|
+
// 1. Inject high latency toxic (simulate 3000ms delay)
|
|
97
|
+
toxic, err := proxy.AddToxic("slow_network", "latency", "downstream", 1.0, toxiproxy.Attributes{
|
|
98
|
+
"latency": 3000,
|
|
99
|
+
"jitter": 200,
|
|
100
|
+
})
|
|
101
|
+
assert.NoError(t, err)
|
|
102
|
+
|
|
103
|
+
client := NewResilientClient("http://localhost:28080", 500*time.Millisecond)
|
|
104
|
+
|
|
105
|
+
// 2. Client timeout triggers
|
|
106
|
+
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
|
|
107
|
+
defer cancel()
|
|
108
|
+
|
|
109
|
+
_, err = client.ExecuteRequest(ctx)
|
|
110
|
+
assert.ErrorIs(t, err, context.DeadlineExceeded)
|
|
111
|
+
|
|
112
|
+
// 3. Remove toxic and verify automatic recovery
|
|
113
|
+
assert.NoError(t, proxy.RemoveToxic(toxic.Name))
|
|
114
|
+
resp, err := client.ExecuteRequest(context.Background())
|
|
115
|
+
assert.NoError(t, err)
|
|
116
|
+
assert.Equal(t, 200, resp.StatusCode)
|
|
117
|
+
}
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
---
|
|
121
|
+
|
|
122
|
+
## 3. Circuit Breaker State Transition Testing
|
|
123
|
+
|
|
124
|
+
A circuit breaker prevents cascading microservice failures by failing fast when a dependency degrades.
|
|
125
|
+
|
|
126
|
+
### 3.1 State Machine Specification
|
|
127
|
+
```
|
|
128
|
+
┌──────────────────────────────────────┐
|
|
129
|
+
│ │ Success count >= threshold
|
|
130
|
+
▼ │
|
|
131
|
+
┌───────────┐ Failure threshold reached ┌───────────┐
|
|
132
|
+
│ CLOSED ├───────────────────────────────►│ OPEN │
|
|
133
|
+
│ (Normal) │ │(Fast-Fail)│
|
|
134
|
+
└─────▲─────┘ └─────┬─────┘
|
|
135
|
+
│ │
|
|
136
|
+
│ Success Timeout expires│
|
|
137
|
+
│ │
|
|
138
|
+
│ ┌───────────┐ │
|
|
139
|
+
└──────────────┤ HALF-OPEN │◄────────────────┘
|
|
140
|
+
│ (Probing) │
|
|
141
|
+
└─────┬─────┘
|
|
142
|
+
│ Failure
|
|
143
|
+
▼
|
|
144
|
+
(Back to OPEN)
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
### 3.2 Verification Protocol
|
|
148
|
+
1. **Transition to OPEN**: Fire $N$ consecutive simulated failure requests (e.g. 5 failures within 10 seconds). Assert that subsequent requests fail immediately without invoking the network (`ErrCircuitOpen`).
|
|
149
|
+
2. **Transition to HALF-OPEN**: Advance virtual or real clock past the sleep window (e.g. 5 seconds). Assert the breaker permits a single probe request.
|
|
150
|
+
3. **Transition to CLOSED**: Assert that successful probe resets failure counters and restores normal traffic.
|
|
151
|
+
|
|
152
|
+
---
|
|
153
|
+
|
|
154
|
+
## 4. Concurrency & Goroutine Leak Assertions
|
|
155
|
+
|
|
156
|
+
Data races and goroutine leaks in asynchronous services cause memory starvation and mysterious production deadlocks.
|
|
157
|
+
|
|
158
|
+
### 4.1 Race Detection
|
|
159
|
+
Run all test suites with the race detector enabled:
|
|
160
|
+
```bash
|
|
161
|
+
go test -v -race -count=1 ./...
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
### 4.2 Leak Detection with `uber-go/goleak`
|
|
165
|
+
Enforce that no background goroutines linger after test teardown:
|
|
166
|
+
|
|
167
|
+
```go
|
|
168
|
+
package integration_test
|
|
169
|
+
|
|
170
|
+
import (
|
|
171
|
+
"testing"
|
|
172
|
+
"go.uber.org/goleak"
|
|
173
|
+
)
|
|
174
|
+
|
|
175
|
+
func TestMain(m *testing.M) {
|
|
176
|
+
// Verify zero leaked goroutines across all package tests
|
|
177
|
+
goleak.VerifyTestMain(m)
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
func TestWorkerPoolShutdown(t *testing.T) {
|
|
181
|
+
defer goleak.VerifyNone(t)
|
|
182
|
+
|
|
183
|
+
pool := NewWorkerPool(4)
|
|
184
|
+
pool.Submit(func() { /* task */ })
|
|
185
|
+
pool.Shutdown() // Must cancel all internal worker loops
|
|
186
|
+
}
|
|
187
|
+
```
|
|
@@ -126,6 +126,22 @@
|
|
|
126
126
|
],
|
|
127
127
|
"version": "1.0.0"
|
|
128
128
|
},
|
|
129
|
+
{
|
|
130
|
+
"name": "implement-ai-disclosure",
|
|
131
|
+
"description": "Implement EU AI Act Article 50 transparency components — <AIDisclosureBanner>, data-ai-generated attributes, C2PA metadata embedding for AI media, and DOMPurify sanitization for AI-generated content. Use when deploying user-facing AI features, chatbots, generative content, or any system requiring AI disclosure per EU AI Act (effective 2 August 2026, C2PA deadline 2 December 2026).",
|
|
132
|
+
"allowed-tools": [
|
|
133
|
+
"read_file",
|
|
134
|
+
"write_file",
|
|
135
|
+
"edit_file",
|
|
136
|
+
"create_file",
|
|
137
|
+
"search_code",
|
|
138
|
+
"run_tests",
|
|
139
|
+
"run_linter",
|
|
140
|
+
"run_build",
|
|
141
|
+
"execute_command"
|
|
142
|
+
],
|
|
143
|
+
"version": "1.0.0"
|
|
144
|
+
},
|
|
129
145
|
{
|
|
130
146
|
"name": "implement-view-transitions",
|
|
131
147
|
"description": "Implement fluid, native-feeling page and state transitions using CSS View Transitions API, React 19 ViewTransition, Next.js App Router transitions, and shared element morphing without degrading Core Web Vitals. Use when adding route animations, shared element transitions, or layout morphs.",
|
|
@@ -150,5 +150,7 @@ Skip emission for solo refactor work where no downstream handoff is expected.
|
|
|
150
150
|
- **accessibility-review**: Check route-level a11y (focus management, navigation announcements)
|
|
151
151
|
- **navigate-service**: Understand existing frontend structure before wiring routes
|
|
152
152
|
- **commit-code**: Prepare the route change for delivery
|
|
153
|
+
- Companion reference: `references/rsc-routing-and-view-transitions.md`
|
|
154
|
+
- Companion example: `examples/streaming-rsc-page-with-view-transition.tsx`
|
|
153
155
|
|
|
154
|
-
Last updated: 2026-
|
|
156
|
+
Last updated: 2026-11-08
|
package/core/skills/frontend/add-page-route/examples/streaming-rsc-page-with-view-transition.tsx
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Streaming RSC Page with View Transitions (Next.js 15 / React 19)
|
|
3
|
+
*
|
|
4
|
+
* Implements:
|
|
5
|
+
* - Server Component data hoisting with React Suspense streaming
|
|
6
|
+
* - Zod search parameter validation with resilient .catch() fallbacks
|
|
7
|
+
* - Leaf Client Component with CSS View Transition trigger
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import React, { Suspense, startTransition } from 'react';
|
|
11
|
+
import { z } from 'zod';
|
|
12
|
+
|
|
13
|
+
// 1. Zod URL Search Parameter Schema
|
|
14
|
+
export const searchParamsSchema = z.object({
|
|
15
|
+
tab: z.enum(['overview', 'analytics', 'audit']).catch('overview'),
|
|
16
|
+
page: z.coerce.number().int().min(1).catch(1),
|
|
17
|
+
q: z.string().trim().max(100).catch(''),
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
export type ValidatedSearchParams = z.infer<typeof searchParamsSchema>;
|
|
21
|
+
|
|
22
|
+
// Mock data fetcher running server-side
|
|
23
|
+
async function fetchMetricData(tab: string, page: number) {
|
|
24
|
+
// Simulate database latency
|
|
25
|
+
await new Promise((resolve) => setTimeout(resolve, 80));
|
|
26
|
+
return [
|
|
27
|
+
{ id: '1', title: `Metric A (${tab})`, value: page * 1420 },
|
|
28
|
+
{ id: '2', title: `Metric B (${tab})`, value: page * 890 },
|
|
29
|
+
];
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// 2. Client Leaf Component: View Transition Tab Navigation
|
|
33
|
+
export function ViewTransitionNavLeaf({ currentTab }: { currentTab: string }) {
|
|
34
|
+
const tabs = ['overview', 'analytics', 'audit'];
|
|
35
|
+
|
|
36
|
+
const handleTabChange = (nextTab: string) => {
|
|
37
|
+
if (!document.startViewTransition) {
|
|
38
|
+
window.location.search = `?tab=${nextTab}`;
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
document.startViewTransition(() => {
|
|
43
|
+
startTransition(() => {
|
|
44
|
+
const url = new URL(window.location.href);
|
|
45
|
+
url.searchParams.set('tab', nextTab);
|
|
46
|
+
window.history.pushState({}, '', url.toString());
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
return (
|
|
52
|
+
<nav className="flex space-x-2 border-b border-border pb-2" aria-label="Route Tabs">
|
|
53
|
+
{tabs.map((tab) => {
|
|
54
|
+
const isActive = tab === currentTab;
|
|
55
|
+
return (
|
|
56
|
+
<button
|
|
57
|
+
key={tab}
|
|
58
|
+
type="button"
|
|
59
|
+
onClick={() => handleTabChange(tab)}
|
|
60
|
+
style={{ viewTransitionName: isActive ? 'active-tab-indicator' : undefined }}
|
|
61
|
+
className={`px-4 py-2 text-sm font-medium rounded-md transition-transform active:scale-[0.98] ${
|
|
62
|
+
isActive
|
|
63
|
+
? 'bg-primary text-primary-foreground shadow-sm'
|
|
64
|
+
: 'text-muted-foreground hover:bg-muted hover:text-foreground'
|
|
65
|
+
}`}
|
|
66
|
+
>
|
|
67
|
+
{tab.charAt(0).toUpperCase() + tab.slice(1)}
|
|
68
|
+
</button>
|
|
69
|
+
);
|
|
70
|
+
})}
|
|
71
|
+
</nav>
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// 3. Streaming Server Data Component
|
|
76
|
+
async function MetricDataList({ tab, page }: { tab: string; page: number }) {
|
|
77
|
+
const metrics = await fetchMetricData(tab, page);
|
|
78
|
+
|
|
79
|
+
return (
|
|
80
|
+
<ul className="mt-4 grid gap-4 sm:grid-cols-2" role="list">
|
|
81
|
+
{metrics.map((m) => (
|
|
82
|
+
<li
|
|
83
|
+
key={m.id}
|
|
84
|
+
className="p-4 rounded-xl border border-border bg-card shadow-sm hover:border-primary/50 transition-colors"
|
|
85
|
+
>
|
|
86
|
+
<h3 className="text-sm font-medium text-muted-foreground">{m.title}</h3>
|
|
87
|
+
<p className="mt-2 text-2xl font-bold tracking-tight text-foreground">
|
|
88
|
+
{m.value.toLocaleString()}
|
|
89
|
+
</p>
|
|
90
|
+
</li>
|
|
91
|
+
))}
|
|
92
|
+
</ul>
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// 4. Root React Server Component Page
|
|
97
|
+
export default async function AnalyticsRoutePage({
|
|
98
|
+
searchParams,
|
|
99
|
+
}: {
|
|
100
|
+
searchParams: Promise<Record<string, string | string[] | undefined>>;
|
|
101
|
+
}) {
|
|
102
|
+
const rawParams = await searchParams;
|
|
103
|
+
const validated = searchParamsSchema.parse({
|
|
104
|
+
tab: typeof rawParams.tab === 'string' ? rawParams.tab : undefined,
|
|
105
|
+
page: typeof rawParams.page === 'string' ? rawParams.page : undefined,
|
|
106
|
+
q: typeof rawParams.q === 'string' ? rawParams.q : undefined,
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
return (
|
|
110
|
+
<main className="container mx-auto px-4 py-8 min-h-[100dvh]">
|
|
111
|
+
<header className="mb-6">
|
|
112
|
+
<h1 className="text-3xl font-extrabold tracking-tight">System Performance Metrics</h1>
|
|
113
|
+
<p className="text-muted-foreground text-sm mt-1">
|
|
114
|
+
Real-time telemetry with React 19 RSC streaming and off-thread View Transitions.
|
|
115
|
+
</p>
|
|
116
|
+
</header>
|
|
117
|
+
|
|
118
|
+
{/* Interactive Client Leaf */}
|
|
119
|
+
<ViewTransitionNavLeaf currentTab={validated.tab} />
|
|
120
|
+
|
|
121
|
+
{/* Streaming Asynchronous Server Component */}
|
|
122
|
+
<Suspense
|
|
123
|
+
fallback={
|
|
124
|
+
<div className="mt-6 flex items-center justify-center p-8 text-muted-foreground">
|
|
125
|
+
<span className="animate-pulse">Streaming metric data...</span>
|
|
126
|
+
</div>
|
|
127
|
+
}
|
|
128
|
+
>
|
|
129
|
+
<MetricDataList tab={validated.tab} page={validated.page} />
|
|
130
|
+
</Suspense>
|
|
131
|
+
</main>
|
|
132
|
+
);
|
|
133
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
# React 19 RSC Routing & View Transitions Architecture (2026)
|
|
2
|
+
|
|
3
|
+
## 1. React Server Component (RSC) Leaf Architecture
|
|
4
|
+
|
|
5
|
+
### 1.1 Data Hoisting & Boundary Isolation
|
|
6
|
+
In React 19 and Next.js 15+ App Router, routes enforce strict separation between data fetching and interactive presentation:
|
|
7
|
+
- **Server Component Root**: All data fetching, auth verification, and database reads occur in async Server Components at the route root.
|
|
8
|
+
- **Client Leaf Boundary**: The `"use client"` directive must be pushed down to terminal UI leaves (buttons, interactive filter inputs, modals).
|
|
9
|
+
- **Waterfall Elimination**: Avoid fetching primary page data inside client-side `useEffect` hooks, which causes layout shift waterfalls and Cumulative Layout Shift (CLS) regressions.
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
## 2. Type-Safe Route Validation (TanStack Router & Next.js)
|
|
14
|
+
|
|
15
|
+
### 2.1 Untrusted Query Parameters
|
|
16
|
+
URL search parameters are user-controlled inputs subject to tampering:
|
|
17
|
+
- Every query parameter must be validated with Zod schemas.
|
|
18
|
+
- Use `.catch()` fallbacks to supply safe defaults instead of failing hard on malformed inputs:
|
|
19
|
+
```typescript
|
|
20
|
+
import { z } from 'zod';
|
|
21
|
+
|
|
22
|
+
export const searchSchema = z.object({
|
|
23
|
+
page: z.coerce.number().int().positive().catch(1),
|
|
24
|
+
filter: z.enum(['all', 'active', 'archived']).catch('all'),
|
|
25
|
+
query: z.string().trim().max(100).catch(''),
|
|
26
|
+
});
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
---
|
|
30
|
+
|
|
31
|
+
## 3. CSS View Transitions & React 19 `ViewTransition`
|
|
32
|
+
|
|
33
|
+
### 3.1 Off-Thread Composited Motion
|
|
34
|
+
Route animations must never trigger layout recalculation during transitions:
|
|
35
|
+
- Restrict animated CSS properties to `transform` and `opacity`.
|
|
36
|
+
- Target Interaction to Next Paint (INP) budget of `< 200ms` with DOM mutation callbacks `< 50ms`.
|
|
37
|
+
- Wrap route mutations in `React.startTransition()`:
|
|
38
|
+
```tsx
|
|
39
|
+
import { startTransition } from 'react';
|
|
40
|
+
|
|
41
|
+
function onNavigate(nextUrl: string) {
|
|
42
|
+
if (!document.startViewTransition) {
|
|
43
|
+
router.push(nextUrl);
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
document.startViewTransition(() => {
|
|
47
|
+
startTransition(() => {
|
|
48
|
+
router.push(nextUrl);
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
```
|
|
53
|
+
- **Accessibility Invariant**:
|
|
54
|
+
```css
|
|
55
|
+
@media (prefers-reduced-motion: reduce) {
|
|
56
|
+
::view-transition-group(*),
|
|
57
|
+
::view-transition-old(*),
|
|
58
|
+
::view-transition-new(*) {
|
|
59
|
+
animation: none !important;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
---
|
|
65
|
+
|
|
66
|
+
## 4. AI Route Audit Checklist
|
|
67
|
+
|
|
68
|
+
Before accepting AI-generated route code, verify:
|
|
69
|
+
- [ ] Auth guard completeness: Route wraps access control or verifies session before server reads.
|
|
70
|
+
- [ ] Loader hoisting: Data loading occurs at server root, not in client hooks.
|
|
71
|
+
- [ ] Cache revalidation: Mutating actions call `revalidatePath` or `router.invalidate()`.
|
|
72
|
+
- [ ] Safe parameters: Query/path parameters validated against Zod schemas with fallbacks.
|
|
@@ -158,5 +158,7 @@ Skip emission for solo exploratory UI work with no planned handoff.
|
|
|
158
158
|
- **design-ux-flow**: Upstream ux-flow-spec and ui-component-spec from UI/UX Designer
|
|
159
159
|
- **commit-code**: Prepare the component change for delivery
|
|
160
160
|
- **develop-mobile-app**: Build high-performance React Native / Expo UI components with FlashList virtualization and Reanimated motion
|
|
161
|
+
- Companion reference: `references/react19-component-standards-and-anti-slop.md`
|
|
162
|
+
- Companion example: `examples/compound-dialog-and-form-actions.tsx`
|
|
161
163
|
|
|
162
|
-
Last updated: 2026-
|
|
164
|
+
Last updated: 2026-11-08
|