@useatlas/create 0.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/README.md +231 -0
- package/index.ts +829 -0
- package/package.json +38 -0
- package/templates/docker/.env.example +67 -0
- package/templates/docker/Dockerfile +52 -0
- package/templates/docker/bin/__tests__/benchmark.test.ts +598 -0
- package/templates/docker/bin/__tests__/duckdb-ingest.test.ts +171 -0
- package/templates/docker/bin/__tests__/eval.test.ts +434 -0
- package/templates/docker/bin/__tests__/matview-partition.test.ts +615 -0
- package/templates/docker/bin/__tests__/multi-source.test.ts +113 -0
- package/templates/docker/bin/__tests__/plugin-cli.test.ts +322 -0
- package/templates/docker/bin/__tests__/profiler-heuristics.test.ts +608 -0
- package/templates/docker/bin/__tests__/query.test.ts +240 -0
- package/templates/docker/bin/__tests__/schema-drift.test.ts +542 -0
- package/templates/docker/bin/__tests__/view-yaml-generation.test.ts +146 -0
- package/templates/docker/bin/atlas.ts +5044 -0
- package/templates/docker/bin/benchmark.ts +695 -0
- package/templates/docker/bin/enrich.ts +559 -0
- package/templates/docker/bin/eval.ts +770 -0
- package/templates/docker/bin/smoke.ts +438 -0
- package/templates/docker/data/.gitkeep +0 -0
- package/templates/docker/data/cybersec.sql +1961 -0
- package/templates/docker/data/demo-semantic/catalog.yml +40 -0
- package/templates/docker/data/demo-semantic/entities/accounts.yml +170 -0
- package/templates/docker/data/demo-semantic/entities/companies.yml +207 -0
- package/templates/docker/data/demo-semantic/entities/people.yml +145 -0
- package/templates/docker/data/demo-semantic/glossary.yml +22 -0
- package/templates/docker/data/demo-semantic/metrics/accounts.yml +38 -0
- package/templates/docker/data/demo-semantic/metrics/companies.yml +89 -0
- package/templates/docker/data/demo.sql +373 -0
- package/templates/docker/data/ecommerce.sql +1690 -0
- package/templates/docker/data/init-demo-db.sql +8 -0
- package/templates/docker/docker-compose.yml +34 -0
- package/templates/docker/docs/deploy.md +390 -0
- package/templates/docker/eslint.config.mjs +18 -0
- package/templates/docker/gitignore +5 -0
- package/templates/docker/next.config.ts +9 -0
- package/templates/docker/package.json +59 -0
- package/templates/docker/postcss.config.mjs +8 -0
- package/templates/docker/public/.gitkeep +0 -0
- package/templates/docker/public/favicon.svg +4 -0
- package/templates/docker/railway.json +13 -0
- package/templates/docker/render.yaml +34 -0
- package/templates/docker/semantic/catalog.yml +5 -0
- package/templates/docker/semantic/entities/.gitkeep +0 -0
- package/templates/docker/semantic/glossary.yml +6 -0
- package/templates/docker/semantic/metrics/.gitkeep +0 -0
- package/templates/docker/sidecar/Dockerfile +28 -0
- package/templates/docker/sidecar/railway.json +14 -0
- package/templates/docker/sidecar/server.ts +188 -0
- package/templates/docker/src/api/__tests__/actions.test.ts +683 -0
- package/templates/docker/src/api/__tests__/admin.test.ts +820 -0
- package/templates/docker/src/api/__tests__/auth.test.ts +165 -0
- package/templates/docker/src/api/__tests__/chat.test.ts +376 -0
- package/templates/docker/src/api/__tests__/conversations.test.ts +555 -0
- package/templates/docker/src/api/__tests__/cors.test.ts +135 -0
- package/templates/docker/src/api/__tests__/health-plugin.test.ts +169 -0
- package/templates/docker/src/api/__tests__/health.test.ts +261 -0
- package/templates/docker/src/api/__tests__/query.test.ts +891 -0
- package/templates/docker/src/api/__tests__/scheduled-tasks.test.ts +601 -0
- package/templates/docker/src/api/__tests__/slack.test.ts +847 -0
- package/templates/docker/src/api/index.ts +117 -0
- package/templates/docker/src/api/routes/actions.ts +274 -0
- package/templates/docker/src/api/routes/admin.ts +757 -0
- package/templates/docker/src/api/routes/auth.ts +48 -0
- package/templates/docker/src/api/routes/chat.ts +465 -0
- package/templates/docker/src/api/routes/conversations.ts +266 -0
- package/templates/docker/src/api/routes/health.ts +287 -0
- package/templates/docker/src/api/routes/openapi.ts +390 -0
- package/templates/docker/src/api/routes/query.ts +318 -0
- package/templates/docker/src/api/routes/scheduled-tasks.ts +467 -0
- package/templates/docker/src/api/routes/slack.ts +611 -0
- package/templates/docker/src/api/server.ts +226 -0
- package/templates/docker/src/app/api/[...route]/route.ts +33 -0
- package/templates/docker/src/app/error.tsx +24 -0
- package/templates/docker/src/app/globals.css +126 -0
- package/templates/docker/src/app/layout.tsx +19 -0
- package/templates/docker/src/app/page.tsx +14 -0
- package/templates/docker/src/global.d.ts +1 -0
- package/templates/docker/src/lib/__tests__/agent-cache.test.ts +437 -0
- package/templates/docker/src/lib/__tests__/agent-dialect.test.ts +114 -0
- package/templates/docker/src/lib/__tests__/agent-health-annotations.test.ts +164 -0
- package/templates/docker/src/lib/__tests__/agent-integration.test.ts +514 -0
- package/templates/docker/src/lib/__tests__/config-actions.test.ts +166 -0
- package/templates/docker/src/lib/__tests__/config.test.ts +1063 -0
- package/templates/docker/src/lib/__tests__/conversations.test.ts +589 -0
- package/templates/docker/src/lib/__tests__/errors.test.ts +256 -0
- package/templates/docker/src/lib/__tests__/logger.test.ts +200 -0
- package/templates/docker/src/lib/__tests__/providers.test.ts +99 -0
- package/templates/docker/src/lib/__tests__/rls.test.ts +435 -0
- package/templates/docker/src/lib/__tests__/scheduled-task-types.test.ts +124 -0
- package/templates/docker/src/lib/__tests__/scheduled-tasks.test.ts +550 -0
- package/templates/docker/src/lib/__tests__/semantic-index.test.ts +547 -0
- package/templates/docker/src/lib/__tests__/semantic-multisource.test.ts +544 -0
- package/templates/docker/src/lib/__tests__/semantic.test.ts +363 -0
- package/templates/docker/src/lib/__tests__/startup-actions.test.ts +452 -0
- package/templates/docker/src/lib/__tests__/startup.test.ts +465 -0
- package/templates/docker/src/lib/__tests__/tracing.test.ts +28 -0
- package/templates/docker/src/lib/action-types.ts +95 -0
- package/templates/docker/src/lib/agent-query.ts +178 -0
- package/templates/docker/src/lib/agent.ts +505 -0
- package/templates/docker/src/lib/api-url.ts +2 -0
- package/templates/docker/src/lib/auth/__tests__/audit.test.ts +418 -0
- package/templates/docker/src/lib/auth/__tests__/byot-integration.test.ts +222 -0
- package/templates/docker/src/lib/auth/__tests__/byot.test.ts +366 -0
- package/templates/docker/src/lib/auth/__tests__/detect.test.ts +190 -0
- package/templates/docker/src/lib/auth/__tests__/managed.test.ts +173 -0
- package/templates/docker/src/lib/auth/__tests__/middleware.test.ts +456 -0
- package/templates/docker/src/lib/auth/__tests__/migrate.test.ts +201 -0
- package/templates/docker/src/lib/auth/__tests__/permissions.test.ts +225 -0
- package/templates/docker/src/lib/auth/__tests__/server.test.ts +34 -0
- package/templates/docker/src/lib/auth/__tests__/simple-key.test.ts +176 -0
- package/templates/docker/src/lib/auth/__tests__/types.test.ts +44 -0
- package/templates/docker/src/lib/auth/audit.ts +89 -0
- package/templates/docker/src/lib/auth/byot.ts +158 -0
- package/templates/docker/src/lib/auth/client.ts +35 -0
- package/templates/docker/src/lib/auth/detect.ts +83 -0
- package/templates/docker/src/lib/auth/managed.ts +73 -0
- package/templates/docker/src/lib/auth/middleware.ts +208 -0
- package/templates/docker/src/lib/auth/migrate.ts +111 -0
- package/templates/docker/src/lib/auth/permissions.ts +156 -0
- package/templates/docker/src/lib/auth/server.ts +142 -0
- package/templates/docker/src/lib/auth/simple-key.ts +92 -0
- package/templates/docker/src/lib/auth/types.ts +49 -0
- package/templates/docker/src/lib/config.ts +704 -0
- package/templates/docker/src/lib/conversation-types.ts +29 -0
- package/templates/docker/src/lib/conversations.ts +270 -0
- package/templates/docker/src/lib/db/__tests__/connection.test.ts +69 -0
- package/templates/docker/src/lib/db/__tests__/duckdb.test.ts +141 -0
- package/templates/docker/src/lib/db/__tests__/internal.test.ts +387 -0
- package/templates/docker/src/lib/db/__tests__/registry-health.test.ts +207 -0
- package/templates/docker/src/lib/db/__tests__/registry-pool-limits.test.ts +156 -0
- package/templates/docker/src/lib/db/__tests__/registry.test.ts +595 -0
- package/templates/docker/src/lib/db/__tests__/salesforce.test.ts +339 -0
- package/templates/docker/src/lib/db/__tests__/snowflake.test.ts +217 -0
- package/templates/docker/src/lib/db/__tests__/source-rate-limit.test.ts +130 -0
- package/templates/docker/src/lib/db/connection.ts +753 -0
- package/templates/docker/src/lib/db/duckdb.ts +122 -0
- package/templates/docker/src/lib/db/internal.ts +273 -0
- package/templates/docker/src/lib/db/salesforce.ts +342 -0
- package/templates/docker/src/lib/db/source-rate-limit.ts +191 -0
- package/templates/docker/src/lib/errors.ts +154 -0
- package/templates/docker/src/lib/logger.ts +98 -0
- package/templates/docker/src/lib/plugins/__tests__/hooks-integration.test.ts +202 -0
- package/templates/docker/src/lib/plugins/__tests__/hooks.test.ts +529 -0
- package/templates/docker/src/lib/plugins/__tests__/migrate.test.ts +521 -0
- package/templates/docker/src/lib/plugins/__tests__/registry.test.ts +346 -0
- package/templates/docker/src/lib/plugins/__tests__/tools.test.ts +49 -0
- package/templates/docker/src/lib/plugins/__tests__/wiring.test.ts +585 -0
- package/templates/docker/src/lib/plugins/hooks.ts +162 -0
- package/templates/docker/src/lib/plugins/index.ts +9 -0
- package/templates/docker/src/lib/plugins/migrate.ts +309 -0
- package/templates/docker/src/lib/plugins/registry.ts +231 -0
- package/templates/docker/src/lib/plugins/tools.ts +39 -0
- package/templates/docker/src/lib/plugins/wiring.ts +291 -0
- package/templates/docker/src/lib/providers.ts +102 -0
- package/templates/docker/src/lib/rls.ts +321 -0
- package/templates/docker/src/lib/scheduled-task-types.ts +132 -0
- package/templates/docker/src/lib/scheduled-tasks.ts +475 -0
- package/templates/docker/src/lib/scheduler/__tests__/delivery.test.ts +192 -0
- package/templates/docker/src/lib/scheduler/__tests__/engine.test.ts +248 -0
- package/templates/docker/src/lib/scheduler/__tests__/format-email.test.ts +96 -0
- package/templates/docker/src/lib/scheduler/__tests__/format-slack.test.ts +78 -0
- package/templates/docker/src/lib/scheduler/__tests__/format-webhook.test.ts +78 -0
- package/templates/docker/src/lib/scheduler/delivery.ts +248 -0
- package/templates/docker/src/lib/scheduler/engine.ts +317 -0
- package/templates/docker/src/lib/scheduler/executor.ts +73 -0
- package/templates/docker/src/lib/scheduler/format-email.ts +109 -0
- package/templates/docker/src/lib/scheduler/format-slack.ts +35 -0
- package/templates/docker/src/lib/scheduler/format-webhook.ts +37 -0
- package/templates/docker/src/lib/scheduler/index.ts +7 -0
- package/templates/docker/src/lib/security.ts +11 -0
- package/templates/docker/src/lib/semantic-index.ts +503 -0
- package/templates/docker/src/lib/semantic.ts +387 -0
- package/templates/docker/src/lib/sidecar-types.ts +16 -0
- package/templates/docker/src/lib/slack/__tests__/api.test.ts +160 -0
- package/templates/docker/src/lib/slack/__tests__/format.test.ts +237 -0
- package/templates/docker/src/lib/slack/__tests__/store.test.ts +188 -0
- package/templates/docker/src/lib/slack/__tests__/threads.test.ts +112 -0
- package/templates/docker/src/lib/slack/__tests__/verify.test.ts +111 -0
- package/templates/docker/src/lib/slack/api.ts +102 -0
- package/templates/docker/src/lib/slack/format.ts +209 -0
- package/templates/docker/src/lib/slack/store.ts +107 -0
- package/templates/docker/src/lib/slack/threads.ts +64 -0
- package/templates/docker/src/lib/slack/verify.ts +71 -0
- package/templates/docker/src/lib/startup.ts +730 -0
- package/templates/docker/src/lib/tools/__tests__/action-permissions.test.ts +594 -0
- package/templates/docker/src/lib/tools/__tests__/custom-validation.test.ts +238 -0
- package/templates/docker/src/lib/tools/__tests__/explore-backend.test.ts +267 -0
- package/templates/docker/src/lib/tools/__tests__/explore-nsjail.test.ts +492 -0
- package/templates/docker/src/lib/tools/__tests__/explore-plugin.test.ts +374 -0
- package/templates/docker/src/lib/tools/__tests__/explore-sdk-compat.test.ts +82 -0
- package/templates/docker/src/lib/tools/__tests__/explore-sidecar.test.ts +208 -0
- package/templates/docker/src/lib/tools/__tests__/registry-actions.test.ts +144 -0
- package/templates/docker/src/lib/tools/__tests__/registry.test.ts +235 -0
- package/templates/docker/src/lib/tools/__tests__/salesforce-tool.test.ts +154 -0
- package/templates/docker/src/lib/tools/__tests__/soql-validation.test.ts +303 -0
- package/templates/docker/src/lib/tools/__tests__/sql-audit.test.ts +225 -0
- package/templates/docker/src/lib/tools/__tests__/sql-connection-whitelist.test.ts +98 -0
- package/templates/docker/src/lib/tools/__tests__/sql-duckdb.test.ts +233 -0
- package/templates/docker/src/lib/tools/__tests__/sql-ratelimit.test.ts +225 -0
- package/templates/docker/src/lib/tools/__tests__/sql.test.ts +1012 -0
- package/templates/docker/src/lib/tools/actions/__tests__/audit.test.ts +211 -0
- package/templates/docker/src/lib/tools/actions/__tests__/email.test.ts +378 -0
- package/templates/docker/src/lib/tools/actions/__tests__/handler.test.ts +681 -0
- package/templates/docker/src/lib/tools/actions/__tests__/jira.test.ts +427 -0
- package/templates/docker/src/lib/tools/actions/audit.ts +47 -0
- package/templates/docker/src/lib/tools/actions/email.ts +191 -0
- package/templates/docker/src/lib/tools/actions/handler.ts +591 -0
- package/templates/docker/src/lib/tools/actions/index.ts +23 -0
- package/templates/docker/src/lib/tools/actions/jira.ts +220 -0
- package/templates/docker/src/lib/tools/explore-nsjail.ts +343 -0
- package/templates/docker/src/lib/tools/explore-sandbox.ts +264 -0
- package/templates/docker/src/lib/tools/explore-sidecar.ts +163 -0
- package/templates/docker/src/lib/tools/explore.ts +379 -0
- package/templates/docker/src/lib/tools/registry.ts +221 -0
- package/templates/docker/src/lib/tools/salesforce.ts +138 -0
- package/templates/docker/src/lib/tools/soql-validation.ts +172 -0
- package/templates/docker/src/lib/tools/sql.ts +680 -0
- package/templates/docker/src/lib/tracing.ts +40 -0
- package/templates/docker/src/lib/utils.ts +6 -0
- package/templates/docker/src/test-setup.ts +38 -0
- package/templates/docker/src/types/vercel-sandbox.d.ts +54 -0
- package/templates/docker/src/ui/components/actions/action-approval-card.tsx +295 -0
- package/templates/docker/src/ui/components/actions/action-status-badge.tsx +50 -0
- package/templates/docker/src/ui/components/admin/admin-layout.tsx +26 -0
- package/templates/docker/src/ui/components/admin/admin-sidebar.tsx +96 -0
- package/templates/docker/src/ui/components/admin/empty-state.tsx +24 -0
- package/templates/docker/src/ui/components/admin/entity-detail.tsx +233 -0
- package/templates/docker/src/ui/components/admin/entity-list.tsx +96 -0
- package/templates/docker/src/ui/components/admin/error-banner.tsx +22 -0
- package/templates/docker/src/ui/components/admin/feature-disabled.tsx +44 -0
- package/templates/docker/src/ui/components/admin/health-badge.tsx +30 -0
- package/templates/docker/src/ui/components/admin/loading-state.tsx +14 -0
- package/templates/docker/src/ui/components/admin/stat-card.tsx +32 -0
- package/templates/docker/src/ui/components/atlas-chat.tsx +370 -0
- package/templates/docker/src/ui/components/chart/chart-detection.ts +261 -0
- package/templates/docker/src/ui/components/chart/result-chart.tsx +375 -0
- package/templates/docker/src/ui/components/chat/api-key-bar.tsx +66 -0
- package/templates/docker/src/ui/components/chat/copy-button.tsx +25 -0
- package/templates/docker/src/ui/components/chat/data-table.tsx +102 -0
- package/templates/docker/src/ui/components/chat/error-banner.tsx +32 -0
- package/templates/docker/src/ui/components/chat/explore-card.tsx +41 -0
- package/templates/docker/src/ui/components/chat/loading-card.tsx +10 -0
- package/templates/docker/src/ui/components/chat/managed-auth-card.tsx +116 -0
- package/templates/docker/src/ui/components/chat/markdown.tsx +72 -0
- package/templates/docker/src/ui/components/chat/sql-block.tsx +30 -0
- package/templates/docker/src/ui/components/chat/sql-result-card.tsx +144 -0
- package/templates/docker/src/ui/components/chat/starter-prompts.ts +6 -0
- package/templates/docker/src/ui/components/chat/tool-part.tsx +40 -0
- package/templates/docker/src/ui/components/chat/typing-indicator.tsx +19 -0
- package/templates/docker/src/ui/components/conversations/conversation-item.tsx +120 -0
- package/templates/docker/src/ui/components/conversations/conversation-list.tsx +66 -0
- package/templates/docker/src/ui/components/conversations/conversation-sidebar.tsx +78 -0
- package/templates/docker/src/ui/components/conversations/delete-confirmation.tsx +27 -0
- package/templates/docker/src/ui/context.tsx +78 -0
- package/templates/docker/src/ui/hooks/use-admin-fetch.ts +104 -0
- package/templates/docker/src/ui/hooks/use-conversations.ts +184 -0
- package/templates/docker/src/ui/hooks/use-dark-mode.ts +17 -0
- package/templates/docker/src/ui/lib/action-types.ts +63 -0
- package/templates/docker/src/ui/lib/helpers.ts +104 -0
- package/templates/docker/src/ui/lib/types.ts +145 -0
- package/templates/docker/tsconfig.json +41 -0
- package/templates/docker/vercel.json +3 -0
- package/templates/nextjs-standalone/.env.example +68 -0
- package/templates/nextjs-standalone/bin/__tests__/benchmark.test.ts +598 -0
- package/templates/nextjs-standalone/bin/__tests__/duckdb-ingest.test.ts +171 -0
- package/templates/nextjs-standalone/bin/__tests__/eval.test.ts +434 -0
- package/templates/nextjs-standalone/bin/__tests__/matview-partition.test.ts +615 -0
- package/templates/nextjs-standalone/bin/__tests__/multi-source.test.ts +113 -0
- package/templates/nextjs-standalone/bin/__tests__/plugin-cli.test.ts +322 -0
- package/templates/nextjs-standalone/bin/__tests__/profiler-heuristics.test.ts +608 -0
- package/templates/nextjs-standalone/bin/__tests__/query.test.ts +240 -0
- package/templates/nextjs-standalone/bin/__tests__/schema-drift.test.ts +542 -0
- package/templates/nextjs-standalone/bin/__tests__/view-yaml-generation.test.ts +146 -0
- package/templates/nextjs-standalone/bin/atlas.ts +5044 -0
- package/templates/nextjs-standalone/bin/benchmark.ts +695 -0
- package/templates/nextjs-standalone/bin/enrich.ts +559 -0
- package/templates/nextjs-standalone/bin/eval.ts +770 -0
- package/templates/nextjs-standalone/bin/smoke.ts +438 -0
- package/templates/nextjs-standalone/data/.gitkeep +0 -0
- package/templates/nextjs-standalone/data/cybersec.sql +1961 -0
- package/templates/nextjs-standalone/data/demo-semantic/catalog.yml +40 -0
- package/templates/nextjs-standalone/data/demo-semantic/entities/accounts.yml +170 -0
- package/templates/nextjs-standalone/data/demo-semantic/entities/companies.yml +207 -0
- package/templates/nextjs-standalone/data/demo-semantic/entities/people.yml +145 -0
- package/templates/nextjs-standalone/data/demo-semantic/glossary.yml +22 -0
- package/templates/nextjs-standalone/data/demo-semantic/metrics/accounts.yml +38 -0
- package/templates/nextjs-standalone/data/demo-semantic/metrics/companies.yml +89 -0
- package/templates/nextjs-standalone/data/demo.sql +373 -0
- package/templates/nextjs-standalone/data/ecommerce.sql +1690 -0
- package/templates/nextjs-standalone/data/init-demo-db.sql +8 -0
- package/templates/nextjs-standalone/docs/deploy.md +390 -0
- package/templates/nextjs-standalone/eslint.config.mjs +18 -0
- package/templates/nextjs-standalone/gitignore +5 -0
- package/templates/nextjs-standalone/next.config.ts +10 -0
- package/templates/nextjs-standalone/package.json +63 -0
- package/templates/nextjs-standalone/postcss.config.mjs +8 -0
- package/templates/nextjs-standalone/semantic/catalog.yml +5 -0
- package/templates/nextjs-standalone/semantic/entities/.gitkeep +0 -0
- package/templates/nextjs-standalone/semantic/glossary.yml +6 -0
- package/templates/nextjs-standalone/semantic/metrics/.gitkeep +0 -0
- package/templates/nextjs-standalone/src/api/__tests__/actions.test.ts +683 -0
- package/templates/nextjs-standalone/src/api/__tests__/admin.test.ts +820 -0
- package/templates/nextjs-standalone/src/api/__tests__/auth.test.ts +165 -0
- package/templates/nextjs-standalone/src/api/__tests__/chat.test.ts +376 -0
- package/templates/nextjs-standalone/src/api/__tests__/conversations.test.ts +555 -0
- package/templates/nextjs-standalone/src/api/__tests__/cors.test.ts +135 -0
- package/templates/nextjs-standalone/src/api/__tests__/health-plugin.test.ts +169 -0
- package/templates/nextjs-standalone/src/api/__tests__/health.test.ts +261 -0
- package/templates/nextjs-standalone/src/api/__tests__/query.test.ts +891 -0
- package/templates/nextjs-standalone/src/api/__tests__/scheduled-tasks.test.ts +601 -0
- package/templates/nextjs-standalone/src/api/__tests__/slack.test.ts +847 -0
- package/templates/nextjs-standalone/src/api/index.ts +117 -0
- package/templates/nextjs-standalone/src/api/routes/actions.ts +274 -0
- package/templates/nextjs-standalone/src/api/routes/admin.ts +757 -0
- package/templates/nextjs-standalone/src/api/routes/auth.ts +48 -0
- package/templates/nextjs-standalone/src/api/routes/chat.ts +465 -0
- package/templates/nextjs-standalone/src/api/routes/conversations.ts +266 -0
- package/templates/nextjs-standalone/src/api/routes/health.ts +287 -0
- package/templates/nextjs-standalone/src/api/routes/openapi.ts +390 -0
- package/templates/nextjs-standalone/src/api/routes/query.ts +318 -0
- package/templates/nextjs-standalone/src/api/routes/scheduled-tasks.ts +467 -0
- package/templates/nextjs-standalone/src/api/routes/slack.ts +611 -0
- package/templates/nextjs-standalone/src/api/server.ts +226 -0
- package/templates/nextjs-standalone/src/app/api/[...route]/route.ts +33 -0
- package/templates/nextjs-standalone/src/app/error.tsx +24 -0
- package/templates/nextjs-standalone/src/app/global-error.tsx +68 -0
- package/templates/nextjs-standalone/src/app/globals.css +126 -0
- package/templates/nextjs-standalone/src/app/layout.tsx +19 -0
- package/templates/nextjs-standalone/src/app/page.tsx +14 -0
- package/templates/nextjs-standalone/src/lib/__tests__/agent-cache.test.ts +437 -0
- package/templates/nextjs-standalone/src/lib/__tests__/agent-dialect.test.ts +114 -0
- package/templates/nextjs-standalone/src/lib/__tests__/agent-health-annotations.test.ts +164 -0
- package/templates/nextjs-standalone/src/lib/__tests__/agent-integration.test.ts +514 -0
- package/templates/nextjs-standalone/src/lib/__tests__/config-actions.test.ts +166 -0
- package/templates/nextjs-standalone/src/lib/__tests__/config.test.ts +1063 -0
- package/templates/nextjs-standalone/src/lib/__tests__/conversations.test.ts +589 -0
- package/templates/nextjs-standalone/src/lib/__tests__/errors.test.ts +256 -0
- package/templates/nextjs-standalone/src/lib/__tests__/logger.test.ts +200 -0
- package/templates/nextjs-standalone/src/lib/__tests__/providers.test.ts +99 -0
- package/templates/nextjs-standalone/src/lib/__tests__/rls.test.ts +435 -0
- package/templates/nextjs-standalone/src/lib/__tests__/scheduled-task-types.test.ts +124 -0
- package/templates/nextjs-standalone/src/lib/__tests__/scheduled-tasks.test.ts +550 -0
- package/templates/nextjs-standalone/src/lib/__tests__/semantic-index.test.ts +547 -0
- package/templates/nextjs-standalone/src/lib/__tests__/semantic-multisource.test.ts +544 -0
- package/templates/nextjs-standalone/src/lib/__tests__/semantic.test.ts +363 -0
- package/templates/nextjs-standalone/src/lib/__tests__/startup-actions.test.ts +452 -0
- package/templates/nextjs-standalone/src/lib/__tests__/startup.test.ts +465 -0
- package/templates/nextjs-standalone/src/lib/__tests__/tracing.test.ts +28 -0
- package/templates/nextjs-standalone/src/lib/action-types.ts +95 -0
- package/templates/nextjs-standalone/src/lib/agent-query.ts +178 -0
- package/templates/nextjs-standalone/src/lib/agent.ts +505 -0
- package/templates/nextjs-standalone/src/lib/api-url.ts +3 -0
- package/templates/nextjs-standalone/src/lib/auth/__tests__/audit.test.ts +418 -0
- package/templates/nextjs-standalone/src/lib/auth/__tests__/byot-integration.test.ts +222 -0
- package/templates/nextjs-standalone/src/lib/auth/__tests__/byot.test.ts +366 -0
- package/templates/nextjs-standalone/src/lib/auth/__tests__/detect.test.ts +190 -0
- package/templates/nextjs-standalone/src/lib/auth/__tests__/managed.test.ts +173 -0
- package/templates/nextjs-standalone/src/lib/auth/__tests__/middleware.test.ts +456 -0
- package/templates/nextjs-standalone/src/lib/auth/__tests__/migrate.test.ts +201 -0
- package/templates/nextjs-standalone/src/lib/auth/__tests__/permissions.test.ts +225 -0
- package/templates/nextjs-standalone/src/lib/auth/__tests__/server.test.ts +34 -0
- package/templates/nextjs-standalone/src/lib/auth/__tests__/simple-key.test.ts +176 -0
- package/templates/nextjs-standalone/src/lib/auth/__tests__/types.test.ts +44 -0
- package/templates/nextjs-standalone/src/lib/auth/audit.ts +89 -0
- package/templates/nextjs-standalone/src/lib/auth/byot.ts +158 -0
- package/templates/nextjs-standalone/src/lib/auth/client.ts +23 -0
- package/templates/nextjs-standalone/src/lib/auth/detect.ts +83 -0
- package/templates/nextjs-standalone/src/lib/auth/managed.ts +73 -0
- package/templates/nextjs-standalone/src/lib/auth/middleware.ts +208 -0
- package/templates/nextjs-standalone/src/lib/auth/migrate.ts +111 -0
- package/templates/nextjs-standalone/src/lib/auth/permissions.ts +156 -0
- package/templates/nextjs-standalone/src/lib/auth/server.ts +142 -0
- package/templates/nextjs-standalone/src/lib/auth/simple-key.ts +92 -0
- package/templates/nextjs-standalone/src/lib/auth/types.ts +49 -0
- package/templates/nextjs-standalone/src/lib/config.ts +704 -0
- package/templates/nextjs-standalone/src/lib/conversation-types.ts +29 -0
- package/templates/nextjs-standalone/src/lib/conversations.ts +270 -0
- package/templates/nextjs-standalone/src/lib/db/__tests__/connection.test.ts +69 -0
- package/templates/nextjs-standalone/src/lib/db/__tests__/duckdb.test.ts +141 -0
- package/templates/nextjs-standalone/src/lib/db/__tests__/internal.test.ts +387 -0
- package/templates/nextjs-standalone/src/lib/db/__tests__/registry-health.test.ts +207 -0
- package/templates/nextjs-standalone/src/lib/db/__tests__/registry-pool-limits.test.ts +156 -0
- package/templates/nextjs-standalone/src/lib/db/__tests__/registry.test.ts +595 -0
- package/templates/nextjs-standalone/src/lib/db/__tests__/salesforce.test.ts +339 -0
- package/templates/nextjs-standalone/src/lib/db/__tests__/snowflake.test.ts +217 -0
- package/templates/nextjs-standalone/src/lib/db/__tests__/source-rate-limit.test.ts +130 -0
- package/templates/nextjs-standalone/src/lib/db/connection.ts +753 -0
- package/templates/nextjs-standalone/src/lib/db/duckdb.ts +122 -0
- package/templates/nextjs-standalone/src/lib/db/internal.ts +273 -0
- package/templates/nextjs-standalone/src/lib/db/salesforce.ts +342 -0
- package/templates/nextjs-standalone/src/lib/db/source-rate-limit.ts +191 -0
- package/templates/nextjs-standalone/src/lib/errors.ts +154 -0
- package/templates/nextjs-standalone/src/lib/logger.ts +98 -0
- package/templates/nextjs-standalone/src/lib/plugins/__tests__/hooks-integration.test.ts +202 -0
- package/templates/nextjs-standalone/src/lib/plugins/__tests__/hooks.test.ts +529 -0
- package/templates/nextjs-standalone/src/lib/plugins/__tests__/migrate.test.ts +521 -0
- package/templates/nextjs-standalone/src/lib/plugins/__tests__/registry.test.ts +346 -0
- package/templates/nextjs-standalone/src/lib/plugins/__tests__/tools.test.ts +49 -0
- package/templates/nextjs-standalone/src/lib/plugins/__tests__/wiring.test.ts +585 -0
- package/templates/nextjs-standalone/src/lib/plugins/hooks.ts +162 -0
- package/templates/nextjs-standalone/src/lib/plugins/index.ts +9 -0
- package/templates/nextjs-standalone/src/lib/plugins/migrate.ts +309 -0
- package/templates/nextjs-standalone/src/lib/plugins/registry.ts +231 -0
- package/templates/nextjs-standalone/src/lib/plugins/tools.ts +39 -0
- package/templates/nextjs-standalone/src/lib/plugins/wiring.ts +291 -0
- package/templates/nextjs-standalone/src/lib/providers.ts +102 -0
- package/templates/nextjs-standalone/src/lib/rls.ts +321 -0
- package/templates/nextjs-standalone/src/lib/scheduled-task-types.ts +132 -0
- package/templates/nextjs-standalone/src/lib/scheduled-tasks.ts +475 -0
- package/templates/nextjs-standalone/src/lib/scheduler/__tests__/delivery.test.ts +192 -0
- package/templates/nextjs-standalone/src/lib/scheduler/__tests__/engine.test.ts +248 -0
- package/templates/nextjs-standalone/src/lib/scheduler/__tests__/format-email.test.ts +96 -0
- package/templates/nextjs-standalone/src/lib/scheduler/__tests__/format-slack.test.ts +78 -0
- package/templates/nextjs-standalone/src/lib/scheduler/__tests__/format-webhook.test.ts +78 -0
- package/templates/nextjs-standalone/src/lib/scheduler/delivery.ts +248 -0
- package/templates/nextjs-standalone/src/lib/scheduler/engine.ts +317 -0
- package/templates/nextjs-standalone/src/lib/scheduler/executor.ts +73 -0
- package/templates/nextjs-standalone/src/lib/scheduler/format-email.ts +109 -0
- package/templates/nextjs-standalone/src/lib/scheduler/format-slack.ts +35 -0
- package/templates/nextjs-standalone/src/lib/scheduler/format-webhook.ts +37 -0
- package/templates/nextjs-standalone/src/lib/scheduler/index.ts +7 -0
- package/templates/nextjs-standalone/src/lib/security.ts +11 -0
- package/templates/nextjs-standalone/src/lib/semantic-index.ts +503 -0
- package/templates/nextjs-standalone/src/lib/semantic.ts +387 -0
- package/templates/nextjs-standalone/src/lib/sidecar-types.ts +16 -0
- package/templates/nextjs-standalone/src/lib/slack/__tests__/api.test.ts +160 -0
- package/templates/nextjs-standalone/src/lib/slack/__tests__/format.test.ts +237 -0
- package/templates/nextjs-standalone/src/lib/slack/__tests__/store.test.ts +188 -0
- package/templates/nextjs-standalone/src/lib/slack/__tests__/threads.test.ts +112 -0
- package/templates/nextjs-standalone/src/lib/slack/__tests__/verify.test.ts +111 -0
- package/templates/nextjs-standalone/src/lib/slack/api.ts +102 -0
- package/templates/nextjs-standalone/src/lib/slack/format.ts +209 -0
- package/templates/nextjs-standalone/src/lib/slack/store.ts +107 -0
- package/templates/nextjs-standalone/src/lib/slack/threads.ts +64 -0
- package/templates/nextjs-standalone/src/lib/slack/verify.ts +71 -0
- package/templates/nextjs-standalone/src/lib/startup.ts +730 -0
- package/templates/nextjs-standalone/src/lib/tools/__tests__/action-permissions.test.ts +594 -0
- package/templates/nextjs-standalone/src/lib/tools/__tests__/custom-validation.test.ts +238 -0
- package/templates/nextjs-standalone/src/lib/tools/__tests__/explore-backend.test.ts +267 -0
- package/templates/nextjs-standalone/src/lib/tools/__tests__/explore-nsjail.test.ts +492 -0
- package/templates/nextjs-standalone/src/lib/tools/__tests__/explore-plugin.test.ts +374 -0
- package/templates/nextjs-standalone/src/lib/tools/__tests__/explore-sdk-compat.test.ts +82 -0
- package/templates/nextjs-standalone/src/lib/tools/__tests__/explore-sidecar.test.ts +208 -0
- package/templates/nextjs-standalone/src/lib/tools/__tests__/registry-actions.test.ts +144 -0
- package/templates/nextjs-standalone/src/lib/tools/__tests__/registry.test.ts +235 -0
- package/templates/nextjs-standalone/src/lib/tools/__tests__/salesforce-tool.test.ts +154 -0
- package/templates/nextjs-standalone/src/lib/tools/__tests__/soql-validation.test.ts +303 -0
- package/templates/nextjs-standalone/src/lib/tools/__tests__/sql-audit.test.ts +225 -0
- package/templates/nextjs-standalone/src/lib/tools/__tests__/sql-connection-whitelist.test.ts +98 -0
- package/templates/nextjs-standalone/src/lib/tools/__tests__/sql-duckdb.test.ts +233 -0
- package/templates/nextjs-standalone/src/lib/tools/__tests__/sql-ratelimit.test.ts +225 -0
- package/templates/nextjs-standalone/src/lib/tools/__tests__/sql.test.ts +1012 -0
- package/templates/nextjs-standalone/src/lib/tools/actions/__tests__/audit.test.ts +211 -0
- package/templates/nextjs-standalone/src/lib/tools/actions/__tests__/email.test.ts +378 -0
- package/templates/nextjs-standalone/src/lib/tools/actions/__tests__/handler.test.ts +681 -0
- package/templates/nextjs-standalone/src/lib/tools/actions/__tests__/jira.test.ts +427 -0
- package/templates/nextjs-standalone/src/lib/tools/actions/audit.ts +47 -0
- package/templates/nextjs-standalone/src/lib/tools/actions/email.ts +191 -0
- package/templates/nextjs-standalone/src/lib/tools/actions/handler.ts +591 -0
- package/templates/nextjs-standalone/src/lib/tools/actions/index.ts +23 -0
- package/templates/nextjs-standalone/src/lib/tools/actions/jira.ts +220 -0
- package/templates/nextjs-standalone/src/lib/tools/explore-nsjail.ts +343 -0
- package/templates/nextjs-standalone/src/lib/tools/explore-sandbox.ts +264 -0
- package/templates/nextjs-standalone/src/lib/tools/explore-sidecar.ts +163 -0
- package/templates/nextjs-standalone/src/lib/tools/explore.ts +379 -0
- package/templates/nextjs-standalone/src/lib/tools/registry.ts +221 -0
- package/templates/nextjs-standalone/src/lib/tools/salesforce.ts +138 -0
- package/templates/nextjs-standalone/src/lib/tools/soql-validation.ts +172 -0
- package/templates/nextjs-standalone/src/lib/tools/sql.ts +680 -0
- package/templates/nextjs-standalone/src/lib/tracing.ts +40 -0
- package/templates/nextjs-standalone/src/lib/utils.ts +6 -0
- package/templates/nextjs-standalone/src/test-setup.ts +38 -0
- package/templates/nextjs-standalone/src/ui/components/actions/action-approval-card.tsx +295 -0
- package/templates/nextjs-standalone/src/ui/components/actions/action-status-badge.tsx +50 -0
- package/templates/nextjs-standalone/src/ui/components/admin/admin-layout.tsx +26 -0
- package/templates/nextjs-standalone/src/ui/components/admin/admin-sidebar.tsx +96 -0
- package/templates/nextjs-standalone/src/ui/components/admin/empty-state.tsx +24 -0
- package/templates/nextjs-standalone/src/ui/components/admin/entity-detail.tsx +233 -0
- package/templates/nextjs-standalone/src/ui/components/admin/entity-list.tsx +96 -0
- package/templates/nextjs-standalone/src/ui/components/admin/error-banner.tsx +22 -0
- package/templates/nextjs-standalone/src/ui/components/admin/feature-disabled.tsx +44 -0
- package/templates/nextjs-standalone/src/ui/components/admin/health-badge.tsx +30 -0
- package/templates/nextjs-standalone/src/ui/components/admin/loading-state.tsx +14 -0
- package/templates/nextjs-standalone/src/ui/components/admin/stat-card.tsx +32 -0
- package/templates/nextjs-standalone/src/ui/components/atlas-chat.tsx +370 -0
- package/templates/nextjs-standalone/src/ui/components/chart/chart-detection.ts +261 -0
- package/templates/nextjs-standalone/src/ui/components/chart/result-chart.tsx +375 -0
- package/templates/nextjs-standalone/src/ui/components/chat/api-key-bar.tsx +66 -0
- package/templates/nextjs-standalone/src/ui/components/chat/copy-button.tsx +25 -0
- package/templates/nextjs-standalone/src/ui/components/chat/data-table.tsx +102 -0
- package/templates/nextjs-standalone/src/ui/components/chat/error-banner.tsx +32 -0
- package/templates/nextjs-standalone/src/ui/components/chat/explore-card.tsx +41 -0
- package/templates/nextjs-standalone/src/ui/components/chat/loading-card.tsx +10 -0
- package/templates/nextjs-standalone/src/ui/components/chat/managed-auth-card.tsx +116 -0
- package/templates/nextjs-standalone/src/ui/components/chat/markdown.tsx +72 -0
- package/templates/nextjs-standalone/src/ui/components/chat/sql-block.tsx +30 -0
- package/templates/nextjs-standalone/src/ui/components/chat/sql-result-card.tsx +144 -0
- package/templates/nextjs-standalone/src/ui/components/chat/starter-prompts.ts +6 -0
- package/templates/nextjs-standalone/src/ui/components/chat/tool-part.tsx +40 -0
- package/templates/nextjs-standalone/src/ui/components/chat/typing-indicator.tsx +19 -0
- package/templates/nextjs-standalone/src/ui/components/conversations/conversation-item.tsx +120 -0
- package/templates/nextjs-standalone/src/ui/components/conversations/conversation-list.tsx +66 -0
- package/templates/nextjs-standalone/src/ui/components/conversations/conversation-sidebar.tsx +78 -0
- package/templates/nextjs-standalone/src/ui/components/conversations/delete-confirmation.tsx +27 -0
- package/templates/nextjs-standalone/src/ui/context.tsx +78 -0
- package/templates/nextjs-standalone/src/ui/hooks/use-admin-fetch.ts +104 -0
- package/templates/nextjs-standalone/src/ui/hooks/use-conversations.ts +184 -0
- package/templates/nextjs-standalone/src/ui/hooks/use-dark-mode.ts +17 -0
- package/templates/nextjs-standalone/src/ui/lib/action-types.ts +63 -0
- package/templates/nextjs-standalone/src/ui/lib/helpers.ts +104 -0
- package/templates/nextjs-standalone/src/ui/lib/types.ts +145 -0
- package/templates/nextjs-standalone/tsconfig.json +32 -0
- package/templates/nextjs-standalone/vercel.json +4 -0
|
@@ -0,0 +1,339 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tests for the Salesforce DataSource adapter and registry.
|
|
3
|
+
*/
|
|
4
|
+
import { describe, it, expect, beforeEach, mock } from "bun:test";
|
|
5
|
+
|
|
6
|
+
// Mock jsforce before importing the module under test
|
|
7
|
+
const mockLogin = mock(() => Promise.resolve());
|
|
8
|
+
const mockLogout = mock(() => Promise.resolve());
|
|
9
|
+
const mockQuery = mock(() =>
|
|
10
|
+
Promise.resolve({
|
|
11
|
+
records: [
|
|
12
|
+
{ attributes: { type: "Account" }, Id: "001", Name: "Acme" },
|
|
13
|
+
{ attributes: { type: "Account" }, Id: "002", Name: "Widget Co" },
|
|
14
|
+
],
|
|
15
|
+
}),
|
|
16
|
+
);
|
|
17
|
+
const mockDescribe = mock(() =>
|
|
18
|
+
Promise.resolve({
|
|
19
|
+
name: "Account",
|
|
20
|
+
label: "Account",
|
|
21
|
+
fields: [
|
|
22
|
+
{
|
|
23
|
+
name: "Id",
|
|
24
|
+
type: "id",
|
|
25
|
+
label: "Account ID",
|
|
26
|
+
picklistValues: [],
|
|
27
|
+
referenceTo: [],
|
|
28
|
+
nillable: false,
|
|
29
|
+
length: 18,
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
name: "Name",
|
|
33
|
+
type: "string",
|
|
34
|
+
label: "Account Name",
|
|
35
|
+
picklistValues: [],
|
|
36
|
+
referenceTo: [],
|
|
37
|
+
nillable: false,
|
|
38
|
+
length: 255,
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
name: "Industry",
|
|
42
|
+
type: "picklist",
|
|
43
|
+
label: "Industry",
|
|
44
|
+
picklistValues: [
|
|
45
|
+
{ value: "Technology", label: "Technology", active: true },
|
|
46
|
+
{ value: "Finance", label: "Finance", active: true },
|
|
47
|
+
],
|
|
48
|
+
referenceTo: [],
|
|
49
|
+
nillable: true,
|
|
50
|
+
length: 255,
|
|
51
|
+
},
|
|
52
|
+
],
|
|
53
|
+
}),
|
|
54
|
+
);
|
|
55
|
+
const mockDescribeGlobal = mock(() =>
|
|
56
|
+
Promise.resolve({
|
|
57
|
+
sobjects: [
|
|
58
|
+
{ name: "Account", label: "Account", queryable: true },
|
|
59
|
+
{ name: "Contact", label: "Contact", queryable: true },
|
|
60
|
+
{ name: "ApexLog", label: "Apex Log", queryable: false },
|
|
61
|
+
],
|
|
62
|
+
}),
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
mock.module("jsforce", () => ({
|
|
66
|
+
Connection: class MockConnection {
|
|
67
|
+
login = mockLogin;
|
|
68
|
+
logout = mockLogout;
|
|
69
|
+
query = mockQuery;
|
|
70
|
+
describe = mockDescribe;
|
|
71
|
+
describeGlobal = mockDescribeGlobal;
|
|
72
|
+
},
|
|
73
|
+
}));
|
|
74
|
+
|
|
75
|
+
const {
|
|
76
|
+
parseSalesforceURL,
|
|
77
|
+
createSalesforceDataSource,
|
|
78
|
+
registerSalesforceSource,
|
|
79
|
+
getSalesforceSource,
|
|
80
|
+
listSalesforceSources,
|
|
81
|
+
describeSalesforceSources,
|
|
82
|
+
_resetSalesforceSources,
|
|
83
|
+
} = await import("@atlas/api/lib/db/salesforce");
|
|
84
|
+
|
|
85
|
+
describe("parseSalesforceURL", () => {
|
|
86
|
+
it("parses a full URL", () => {
|
|
87
|
+
const config = parseSalesforceURL(
|
|
88
|
+
"salesforce://user%40example.com:pass123@login.salesforce.com?token=SECTOKEN",
|
|
89
|
+
);
|
|
90
|
+
expect(config.loginUrl).toBe("https://login.salesforce.com");
|
|
91
|
+
expect(config.username).toBe("user@example.com");
|
|
92
|
+
expect(config.password).toBe("pass123");
|
|
93
|
+
expect(config.securityToken).toBe("SECTOKEN");
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it("parses minimal URL with defaults", () => {
|
|
97
|
+
const config = parseSalesforceURL("salesforce://admin:secret@localhost");
|
|
98
|
+
expect(config.loginUrl).toBe("https://localhost");
|
|
99
|
+
expect(config.username).toBe("admin");
|
|
100
|
+
expect(config.password).toBe("secret");
|
|
101
|
+
expect(config.securityToken).toBeUndefined();
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
it("parses sandbox URL (test.salesforce.com)", () => {
|
|
105
|
+
const config = parseSalesforceURL(
|
|
106
|
+
"salesforce://user:pass@test.salesforce.com",
|
|
107
|
+
);
|
|
108
|
+
expect(config.loginUrl).toBe("https://test.salesforce.com");
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
it("parses OAuth params", () => {
|
|
112
|
+
const config = parseSalesforceURL(
|
|
113
|
+
"salesforce://user:pass@login.salesforce.com?clientId=CID&clientSecret=CSEC",
|
|
114
|
+
);
|
|
115
|
+
expect(config.clientId).toBe("CID");
|
|
116
|
+
expect(config.clientSecret).toBe("CSEC");
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
it("throws for non-salesforce scheme", () => {
|
|
120
|
+
expect(() => parseSalesforceURL("postgresql://user:pass@localhost")).toThrow(
|
|
121
|
+
"expected salesforce://",
|
|
122
|
+
);
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
it("throws for missing username", () => {
|
|
126
|
+
expect(() =>
|
|
127
|
+
parseSalesforceURL("salesforce://:pass@login.salesforce.com"),
|
|
128
|
+
).toThrow("missing username");
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
it("throws for missing password", () => {
|
|
132
|
+
expect(() =>
|
|
133
|
+
parseSalesforceURL("salesforce://user@login.salesforce.com"),
|
|
134
|
+
).toThrow("missing password");
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
describe("createSalesforceDataSource", () => {
|
|
139
|
+
beforeEach(() => {
|
|
140
|
+
mockLogin.mockClear();
|
|
141
|
+
mockLogout.mockClear();
|
|
142
|
+
mockQuery.mockClear();
|
|
143
|
+
mockDescribe.mockClear();
|
|
144
|
+
mockDescribeGlobal.mockClear();
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
it("query returns columns and rows without attributes key", async () => {
|
|
148
|
+
const source = createSalesforceDataSource({
|
|
149
|
+
loginUrl: "https://login.salesforce.com",
|
|
150
|
+
username: "user",
|
|
151
|
+
password: "pass",
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
const result = await source.query("SELECT Id, Name FROM Account");
|
|
155
|
+
expect(result.columns).toEqual(["Id", "Name"]);
|
|
156
|
+
expect(result.rows).toEqual([
|
|
157
|
+
{ Id: "001", Name: "Acme" },
|
|
158
|
+
{ Id: "002", Name: "Widget Co" },
|
|
159
|
+
]);
|
|
160
|
+
expect(mockLogin).toHaveBeenCalledTimes(1);
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
it("query returns empty result for no records", async () => {
|
|
164
|
+
mockQuery.mockImplementationOnce(() =>
|
|
165
|
+
Promise.resolve({ records: [] }),
|
|
166
|
+
);
|
|
167
|
+
const source = createSalesforceDataSource({
|
|
168
|
+
loginUrl: "https://login.salesforce.com",
|
|
169
|
+
username: "user",
|
|
170
|
+
password: "pass",
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
const result = await source.query("SELECT Id FROM Account WHERE Id = 'none'");
|
|
174
|
+
expect(result.columns).toEqual([]);
|
|
175
|
+
expect(result.rows).toEqual([]);
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
it("describe returns mapped fields", async () => {
|
|
179
|
+
const source = createSalesforceDataSource({
|
|
180
|
+
loginUrl: "https://login.salesforce.com",
|
|
181
|
+
username: "user",
|
|
182
|
+
password: "pass",
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
const desc = await source.describe("Account");
|
|
186
|
+
expect(desc.name).toBe("Account");
|
|
187
|
+
expect(desc.fields).toHaveLength(3);
|
|
188
|
+
expect(desc.fields[0].name).toBe("Id");
|
|
189
|
+
expect(desc.fields[2].picklistValues).toHaveLength(2);
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
it("listObjects filters to queryable only", async () => {
|
|
193
|
+
const source = createSalesforceDataSource({
|
|
194
|
+
loginUrl: "https://login.salesforce.com",
|
|
195
|
+
username: "user",
|
|
196
|
+
password: "pass",
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
const objects = await source.listObjects();
|
|
200
|
+
expect(objects).toHaveLength(2);
|
|
201
|
+
expect(objects.map((o) => o.name)).toEqual(["Account", "Contact"]);
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
it("close calls logout", async () => {
|
|
205
|
+
const source = createSalesforceDataSource({
|
|
206
|
+
loginUrl: "https://login.salesforce.com",
|
|
207
|
+
username: "user",
|
|
208
|
+
password: "pass",
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
// Force login first
|
|
212
|
+
await source.listObjects();
|
|
213
|
+
await source.close();
|
|
214
|
+
expect(mockLogout).toHaveBeenCalledTimes(1);
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
it("appends security token to password on login", async () => {
|
|
218
|
+
const source = createSalesforceDataSource({
|
|
219
|
+
loginUrl: "https://login.salesforce.com",
|
|
220
|
+
username: "user",
|
|
221
|
+
password: "pass",
|
|
222
|
+
securityToken: "TOKEN123",
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
await source.listObjects();
|
|
226
|
+
expect(mockLogin).toHaveBeenCalledWith("user", "passTOKEN123");
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
it("serializes concurrent login attempts (no duplicate logins)", async () => {
|
|
230
|
+
// Make login take some time so concurrent calls overlap
|
|
231
|
+
mockLogin.mockImplementation(
|
|
232
|
+
() => new Promise((resolve) => setTimeout(resolve, 50)),
|
|
233
|
+
);
|
|
234
|
+
|
|
235
|
+
const source = createSalesforceDataSource({
|
|
236
|
+
loginUrl: "https://login.salesforce.com",
|
|
237
|
+
username: "user",
|
|
238
|
+
password: "pass",
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
// Fire three concurrent queries — all need login
|
|
242
|
+
await Promise.all([
|
|
243
|
+
source.query("SELECT Id FROM Account"),
|
|
244
|
+
source.listObjects(),
|
|
245
|
+
source.describe("Account"),
|
|
246
|
+
]);
|
|
247
|
+
|
|
248
|
+
// Login should have been called exactly once despite three concurrent callers
|
|
249
|
+
expect(mockLogin).toHaveBeenCalledTimes(1);
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
it("close without prior login is a no-op", async () => {
|
|
253
|
+
const source = createSalesforceDataSource({
|
|
254
|
+
loginUrl: "https://login.salesforce.com",
|
|
255
|
+
username: "user",
|
|
256
|
+
password: "pass",
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
// Close without ever calling login — should not throw or call logout
|
|
260
|
+
await source.close();
|
|
261
|
+
expect(mockLogout).not.toHaveBeenCalled();
|
|
262
|
+
expect(mockLogin).not.toHaveBeenCalled();
|
|
263
|
+
});
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
describe("Salesforce source registry", () => {
|
|
267
|
+
beforeEach(() => {
|
|
268
|
+
_resetSalesforceSources();
|
|
269
|
+
mockLogin.mockClear();
|
|
270
|
+
mockLogout.mockClear();
|
|
271
|
+
});
|
|
272
|
+
|
|
273
|
+
it("register and get a source", () => {
|
|
274
|
+
registerSalesforceSource("sf1", {
|
|
275
|
+
loginUrl: "https://login.salesforce.com",
|
|
276
|
+
username: "user",
|
|
277
|
+
password: "pass",
|
|
278
|
+
});
|
|
279
|
+
|
|
280
|
+
const source = getSalesforceSource("sf1");
|
|
281
|
+
expect(source).toBeDefined();
|
|
282
|
+
expect(source.query).toBeDefined();
|
|
283
|
+
});
|
|
284
|
+
|
|
285
|
+
it("throws for unregistered source", () => {
|
|
286
|
+
expect(() => getSalesforceSource("nonexistent")).toThrow(
|
|
287
|
+
'not registered',
|
|
288
|
+
);
|
|
289
|
+
});
|
|
290
|
+
|
|
291
|
+
it("lists registered sources", () => {
|
|
292
|
+
registerSalesforceSource("sf1", {
|
|
293
|
+
loginUrl: "https://login.salesforce.com",
|
|
294
|
+
username: "user",
|
|
295
|
+
password: "pass",
|
|
296
|
+
});
|
|
297
|
+
registerSalesforceSource("sf2", {
|
|
298
|
+
loginUrl: "https://test.salesforce.com",
|
|
299
|
+
username: "admin",
|
|
300
|
+
password: "secret",
|
|
301
|
+
});
|
|
302
|
+
|
|
303
|
+
expect(listSalesforceSources()).toEqual(["sf1", "sf2"]);
|
|
304
|
+
});
|
|
305
|
+
|
|
306
|
+
it("reset clears all sources", () => {
|
|
307
|
+
registerSalesforceSource("sf1", {
|
|
308
|
+
loginUrl: "https://login.salesforce.com",
|
|
309
|
+
username: "user",
|
|
310
|
+
password: "pass",
|
|
311
|
+
});
|
|
312
|
+
|
|
313
|
+
_resetSalesforceSources();
|
|
314
|
+
expect(listSalesforceSources()).toEqual([]);
|
|
315
|
+
});
|
|
316
|
+
|
|
317
|
+
it("describeSalesforceSources returns metadata for registered sources", () => {
|
|
318
|
+
registerSalesforceSource("sf1", {
|
|
319
|
+
loginUrl: "https://login.salesforce.com",
|
|
320
|
+
username: "user",
|
|
321
|
+
password: "pass",
|
|
322
|
+
});
|
|
323
|
+
registerSalesforceSource("sf2", {
|
|
324
|
+
loginUrl: "https://test.salesforce.com",
|
|
325
|
+
username: "admin",
|
|
326
|
+
password: "secret",
|
|
327
|
+
});
|
|
328
|
+
|
|
329
|
+
const meta = describeSalesforceSources();
|
|
330
|
+
expect(meta).toEqual([
|
|
331
|
+
{ id: "sf1", dbType: "salesforce" },
|
|
332
|
+
{ id: "sf2", dbType: "salesforce" },
|
|
333
|
+
]);
|
|
334
|
+
});
|
|
335
|
+
|
|
336
|
+
it("describeSalesforceSources returns empty array when no sources registered", () => {
|
|
337
|
+
expect(describeSalesforceSources()).toEqual([]);
|
|
338
|
+
});
|
|
339
|
+
});
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tests for Snowflake URL parsing, detectDBType integration, and connection behavior.
|
|
3
|
+
*/
|
|
4
|
+
import { describe, it, expect, mock, beforeEach } from "bun:test";
|
|
5
|
+
import { resolve } from "path";
|
|
6
|
+
|
|
7
|
+
// Track all SQL statements executed via the mock connection.
|
|
8
|
+
// Reset in each describe block's beforeEach to prevent cross-test pollution.
|
|
9
|
+
let executedStatements: string[] = [];
|
|
10
|
+
|
|
11
|
+
// Flag to make the QUERY_TAG ALTER SESSION fail in specific tests
|
|
12
|
+
let queryTagShouldFail = false;
|
|
13
|
+
|
|
14
|
+
// Mock logger to capture structured log output
|
|
15
|
+
const mockWarn = mock(() => {});
|
|
16
|
+
mock.module("@atlas/api/lib/logger", () => ({
|
|
17
|
+
createLogger: () => ({
|
|
18
|
+
info: mock(() => {}),
|
|
19
|
+
warn: mockWarn,
|
|
20
|
+
error: mock(() => {}),
|
|
21
|
+
debug: mock(() => {}),
|
|
22
|
+
child: () => ({ info: mock(() => {}), warn: mockWarn, error: mock(() => {}), debug: mock(() => {}) }),
|
|
23
|
+
}),
|
|
24
|
+
}));
|
|
25
|
+
|
|
26
|
+
// Mock database drivers before importing connection module
|
|
27
|
+
mock.module("pg", () => ({
|
|
28
|
+
Pool: class MockPool {
|
|
29
|
+
async query() { return { rows: [], fields: [] }; }
|
|
30
|
+
async connect() { return { async query() { return { rows: [], fields: [] }; }, release() {} }; }
|
|
31
|
+
async end() {}
|
|
32
|
+
},
|
|
33
|
+
}));
|
|
34
|
+
|
|
35
|
+
mock.module("mysql2/promise", () => ({
|
|
36
|
+
createPool: () => ({
|
|
37
|
+
async getConnection() { return { async execute() { return [[], []]; }, release() {} }; },
|
|
38
|
+
async end() {},
|
|
39
|
+
}),
|
|
40
|
+
}));
|
|
41
|
+
|
|
42
|
+
mock.module("snowflake-sdk", () => ({
|
|
43
|
+
configure: () => {},
|
|
44
|
+
createPool: () => ({
|
|
45
|
+
use: async (fn: (conn: unknown) => Promise<unknown>) => {
|
|
46
|
+
const mockConn = {
|
|
47
|
+
execute: (opts: { sqlText: string; complete: (err: Error | null, stmt: unknown, rows: unknown[]) => void }) => {
|
|
48
|
+
executedStatements.push(opts.sqlText);
|
|
49
|
+
if (queryTagShouldFail && opts.sqlText.includes("QUERY_TAG")) {
|
|
50
|
+
opts.complete(new Error("Insufficient privileges to set QUERY_TAG"), null, []);
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
opts.complete(null, { getColumns: () => [] }, []);
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
return fn(mockConn);
|
|
57
|
+
},
|
|
58
|
+
drain: async () => {},
|
|
59
|
+
clear: async () => {},
|
|
60
|
+
}),
|
|
61
|
+
}));
|
|
62
|
+
|
|
63
|
+
// Cache-busting import to get a fresh module instance, avoiding interference
|
|
64
|
+
// from global mock.module("@atlas/api/lib/db/connection") in other test files
|
|
65
|
+
// (e.g. sql.test.ts) that don't export parseSnowflakeURL.
|
|
66
|
+
const connModPath = resolve(__dirname, "../connection.ts");
|
|
67
|
+
const connMod = await import(`${connModPath}?t=${Date.now()}`);
|
|
68
|
+
const parseSnowflakeURL = connMod.parseSnowflakeURL as typeof import("../connection").parseSnowflakeURL;
|
|
69
|
+
const detectDBType = connMod.detectDBType as typeof import("../connection").detectDBType;
|
|
70
|
+
|
|
71
|
+
describe("parseSnowflakeURL", () => {
|
|
72
|
+
it("parses full Snowflake URL with all components", () => {
|
|
73
|
+
const opts = parseSnowflakeURL(
|
|
74
|
+
"snowflake://myuser:mypass@xy12345.us-east-1/mydb/myschema?warehouse=COMPUTE_WH&role=ANALYST"
|
|
75
|
+
);
|
|
76
|
+
expect(opts.account).toBe("xy12345.us-east-1");
|
|
77
|
+
expect(opts.username).toBe("myuser");
|
|
78
|
+
expect(opts.password).toBe("mypass");
|
|
79
|
+
expect(opts.database).toBe("mydb");
|
|
80
|
+
expect(opts.schema).toBe("myschema");
|
|
81
|
+
expect(opts.warehouse).toBe("COMPUTE_WH");
|
|
82
|
+
expect(opts.role).toBe("ANALYST");
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it("parses URL with database only (no schema)", () => {
|
|
86
|
+
const opts = parseSnowflakeURL("snowflake://user:pass@account123/mydb");
|
|
87
|
+
expect(opts.account).toBe("account123");
|
|
88
|
+
expect(opts.username).toBe("user");
|
|
89
|
+
expect(opts.password).toBe("pass");
|
|
90
|
+
expect(opts.database).toBe("mydb");
|
|
91
|
+
expect(opts.schema).toBeUndefined();
|
|
92
|
+
expect(opts.warehouse).toBeUndefined();
|
|
93
|
+
expect(opts.role).toBeUndefined();
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it("parses minimal URL (account only)", () => {
|
|
97
|
+
const opts = parseSnowflakeURL("snowflake://user:pass@account123");
|
|
98
|
+
expect(opts.account).toBe("account123");
|
|
99
|
+
expect(opts.username).toBe("user");
|
|
100
|
+
expect(opts.password).toBe("pass");
|
|
101
|
+
expect(opts.database).toBeUndefined();
|
|
102
|
+
expect(opts.schema).toBeUndefined();
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
it("decodes URL-encoded credentials", () => {
|
|
106
|
+
const opts = parseSnowflakeURL("snowflake://my%40user:p%40ss%23word@account123/db");
|
|
107
|
+
expect(opts.username).toBe("my@user");
|
|
108
|
+
expect(opts.password).toBe("p@ss#word");
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
it("handles warehouse query parameter only", () => {
|
|
112
|
+
const opts = parseSnowflakeURL("snowflake://user:pass@account123/db/schema?warehouse=WH");
|
|
113
|
+
expect(opts.warehouse).toBe("WH");
|
|
114
|
+
expect(opts.role).toBeUndefined();
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
it("throws for non-snowflake protocol", () => {
|
|
118
|
+
expect(() => parseSnowflakeURL("postgresql://user:pass@localhost:5432/db")).toThrow(
|
|
119
|
+
"Invalid Snowflake URL"
|
|
120
|
+
);
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
it("accepts empty password (key-pair auth scenario)", () => {
|
|
124
|
+
const opts = parseSnowflakeURL("snowflake://user:@account123/db");
|
|
125
|
+
expect(opts.username).toBe("user");
|
|
126
|
+
expect(opts.password).toBe("");
|
|
127
|
+
expect(opts.database).toBe("db");
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
it("throws for missing username", () => {
|
|
131
|
+
expect(() => parseSnowflakeURL("snowflake://:pass@account123/db")).toThrow(
|
|
132
|
+
"missing username"
|
|
133
|
+
);
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
it("throws for missing account (unparseable URL)", () => {
|
|
137
|
+
// snowflake://user:pass@/db is not a valid URL — the URL constructor throws
|
|
138
|
+
expect(() => parseSnowflakeURL("snowflake://user:pass@/db")).toThrow();
|
|
139
|
+
});
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
describe("detectDBType — Snowflake", () => {
|
|
143
|
+
it("returns 'snowflake' for snowflake:// URLs", () => {
|
|
144
|
+
expect(detectDBType("snowflake://user:pass@account123/db")).toBe("snowflake");
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
it("still returns 'postgres' for postgresql:// URLs", () => {
|
|
148
|
+
expect(detectDBType("postgresql://user:pass@localhost:5432/db")).toBe("postgres");
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
it("still returns 'mysql' for mysql:// URLs", () => {
|
|
152
|
+
expect(detectDBType("mysql://user:pass@localhost:3306/db")).toBe("mysql");
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
it("throws for unsupported URL schemes", () => {
|
|
156
|
+
expect(() => detectDBType("sqlite:///test.db")).toThrow("Unsupported database URL");
|
|
157
|
+
});
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
describe("createSnowflakeDB — defense-in-depth", () => {
|
|
161
|
+
const ConnectionRegistry = connMod.ConnectionRegistry as typeof import("../connection").ConnectionRegistry;
|
|
162
|
+
|
|
163
|
+
beforeEach(() => {
|
|
164
|
+
executedStatements = [];
|
|
165
|
+
queryTagShouldFail = false;
|
|
166
|
+
mockWarn.mockClear();
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
it("logs a startup warning recommending a SELECT-only role", () => {
|
|
170
|
+
const registry = new ConnectionRegistry();
|
|
171
|
+
registry.register("sf-test", { url: "snowflake://user:pass@account123/db" });
|
|
172
|
+
expect(mockWarn).toHaveBeenCalledWith(
|
|
173
|
+
expect.stringContaining("no session-level read-only mode"),
|
|
174
|
+
);
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
it("sets QUERY_TAG before each query", async () => {
|
|
178
|
+
const registry = new ConnectionRegistry();
|
|
179
|
+
registry.register("sf-tag", { url: "snowflake://user:pass@account123/db" });
|
|
180
|
+
const db = registry.get("sf-tag");
|
|
181
|
+
await db.query("SELECT 1");
|
|
182
|
+
|
|
183
|
+
expect(executedStatements).toContain("ALTER SESSION SET QUERY_TAG = 'atlas:readonly'");
|
|
184
|
+
// QUERY_TAG should come after timeout and before the actual query
|
|
185
|
+
const tagIdx = executedStatements.indexOf("ALTER SESSION SET QUERY_TAG = 'atlas:readonly'");
|
|
186
|
+
const queryIdx = executedStatements.indexOf("SELECT 1");
|
|
187
|
+
expect(tagIdx).toBeLessThan(queryIdx);
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
it("sets statement timeout before QUERY_TAG", async () => {
|
|
191
|
+
const registry = new ConnectionRegistry();
|
|
192
|
+
registry.register("sf-order", { url: "snowflake://user:pass@account123/db" });
|
|
193
|
+
const db = registry.get("sf-order");
|
|
194
|
+
await db.query("SELECT 1", 15000);
|
|
195
|
+
|
|
196
|
+
const timeoutIdx = executedStatements.findIndex((s) => s.includes("STATEMENT_TIMEOUT_IN_SECONDS"));
|
|
197
|
+
const tagIdx = executedStatements.indexOf("ALTER SESSION SET QUERY_TAG = 'atlas:readonly'");
|
|
198
|
+
expect(timeoutIdx).toBeLessThan(tagIdx);
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
it("proceeds with the query when QUERY_TAG fails (best-effort)", async () => {
|
|
202
|
+
queryTagShouldFail = true;
|
|
203
|
+
const registry = new ConnectionRegistry();
|
|
204
|
+
registry.register("sf-tag-fail", { url: "snowflake://user:pass@account123/db" });
|
|
205
|
+
const db = registry.get("sf-tag-fail");
|
|
206
|
+
const result = await db.query("SELECT 42");
|
|
207
|
+
|
|
208
|
+
// The actual query should still execute despite QUERY_TAG failure
|
|
209
|
+
expect(executedStatements).toContain("SELECT 42");
|
|
210
|
+
expect(result).toEqual({ columns: [], rows: [] });
|
|
211
|
+
|
|
212
|
+
// A warning should be logged
|
|
213
|
+
expect(mockWarn).toHaveBeenCalledWith(
|
|
214
|
+
expect.stringContaining("Failed to set QUERY_TAG"),
|
|
215
|
+
);
|
|
216
|
+
});
|
|
217
|
+
});
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tests for per-source rate limiting.
|
|
3
|
+
*/
|
|
4
|
+
import { describe, it, expect, afterEach } from "bun:test";
|
|
5
|
+
import {
|
|
6
|
+
checkSourceRateLimit,
|
|
7
|
+
registerSourceRateLimit,
|
|
8
|
+
clearSourceRateLimit,
|
|
9
|
+
incrementSourceConcurrency,
|
|
10
|
+
decrementSourceConcurrency,
|
|
11
|
+
_resetSourceRateLimits,
|
|
12
|
+
_stopSourceRateLimitCleanup,
|
|
13
|
+
} from "../source-rate-limit";
|
|
14
|
+
|
|
15
|
+
afterEach(() => {
|
|
16
|
+
_resetSourceRateLimits();
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
// Stop cleanup timer so it doesn't keep test runner alive
|
|
20
|
+
afterEach(() => {
|
|
21
|
+
_stopSourceRateLimitCleanup();
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
describe("per-source rate limiting", () => {
|
|
25
|
+
describe("QPM enforcement", () => {
|
|
26
|
+
it("allows queries under the limit", () => {
|
|
27
|
+
registerSourceRateLimit("test", { queriesPerMinute: 5, concurrency: 10 });
|
|
28
|
+
for (let i = 0; i < 5; i++) {
|
|
29
|
+
expect(checkSourceRateLimit("test").allowed).toBe(true);
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it("blocks queries over the QPM limit", () => {
|
|
34
|
+
registerSourceRateLimit("test", { queriesPerMinute: 3, concurrency: 10 });
|
|
35
|
+
expect(checkSourceRateLimit("test").allowed).toBe(true);
|
|
36
|
+
expect(checkSourceRateLimit("test").allowed).toBe(true);
|
|
37
|
+
expect(checkSourceRateLimit("test").allowed).toBe(true);
|
|
38
|
+
const result = checkSourceRateLimit("test");
|
|
39
|
+
expect(result.allowed).toBe(false);
|
|
40
|
+
expect(result.reason).toContain("QPM limit reached");
|
|
41
|
+
expect(result.retryAfterMs).toBeGreaterThan(0);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it("uses default limit (60 QPM) when no custom limit is set", () => {
|
|
45
|
+
for (let i = 0; i < 60; i++) {
|
|
46
|
+
expect(checkSourceRateLimit("unregistered").allowed).toBe(true);
|
|
47
|
+
}
|
|
48
|
+
expect(checkSourceRateLimit("unregistered").allowed).toBe(false);
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
describe("concurrency enforcement", () => {
|
|
53
|
+
it("allows queries under the concurrency limit", () => {
|
|
54
|
+
registerSourceRateLimit("test", { queriesPerMinute: 100, concurrency: 2 });
|
|
55
|
+
incrementSourceConcurrency("test");
|
|
56
|
+
expect(checkSourceRateLimit("test").allowed).toBe(true);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it("blocks queries at the concurrency limit", () => {
|
|
60
|
+
registerSourceRateLimit("test", { queriesPerMinute: 100, concurrency: 2 });
|
|
61
|
+
incrementSourceConcurrency("test");
|
|
62
|
+
incrementSourceConcurrency("test");
|
|
63
|
+
const result = checkSourceRateLimit("test");
|
|
64
|
+
expect(result.allowed).toBe(false);
|
|
65
|
+
expect(result.reason).toContain("concurrency limit reached");
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it("allows queries after decrementing concurrency", () => {
|
|
69
|
+
registerSourceRateLimit("test", { queriesPerMinute: 100, concurrency: 1 });
|
|
70
|
+
incrementSourceConcurrency("test");
|
|
71
|
+
expect(checkSourceRateLimit("test").allowed).toBe(false);
|
|
72
|
+
decrementSourceConcurrency("test");
|
|
73
|
+
expect(checkSourceRateLimit("test").allowed).toBe(true);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it("concurrency does not go below zero", () => {
|
|
77
|
+
decrementSourceConcurrency("test");
|
|
78
|
+
decrementSourceConcurrency("test");
|
|
79
|
+
// Should not throw, count stays at 0
|
|
80
|
+
expect(checkSourceRateLimit("test").allowed).toBe(true);
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
describe("per-source isolation", () => {
|
|
85
|
+
it("limits are independent per source", () => {
|
|
86
|
+
registerSourceRateLimit("a", { queriesPerMinute: 2, concurrency: 10 });
|
|
87
|
+
registerSourceRateLimit("b", { queriesPerMinute: 2, concurrency: 10 });
|
|
88
|
+
|
|
89
|
+
expect(checkSourceRateLimit("a").allowed).toBe(true);
|
|
90
|
+
expect(checkSourceRateLimit("a").allowed).toBe(true);
|
|
91
|
+
expect(checkSourceRateLimit("a").allowed).toBe(false); // a is at limit
|
|
92
|
+
|
|
93
|
+
expect(checkSourceRateLimit("b").allowed).toBe(true); // b is independent
|
|
94
|
+
expect(checkSourceRateLimit("b").allowed).toBe(true);
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
describe("registerSourceRateLimit + clearSourceRateLimit", () => {
|
|
99
|
+
it("custom limits override defaults", () => {
|
|
100
|
+
registerSourceRateLimit("test", { queriesPerMinute: 2, concurrency: 1 });
|
|
101
|
+
expect(checkSourceRateLimit("test").allowed).toBe(true);
|
|
102
|
+
expect(checkSourceRateLimit("test").allowed).toBe(true);
|
|
103
|
+
expect(checkSourceRateLimit("test").allowed).toBe(false);
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it("clearSourceRateLimit reverts to defaults", () => {
|
|
107
|
+
registerSourceRateLimit("test", { queriesPerMinute: 1, concurrency: 10 });
|
|
108
|
+
expect(checkSourceRateLimit("test").allowed).toBe(true);
|
|
109
|
+
expect(checkSourceRateLimit("test").allowed).toBe(false);
|
|
110
|
+
|
|
111
|
+
_resetSourceRateLimits();
|
|
112
|
+
clearSourceRateLimit("test");
|
|
113
|
+
// Should use default (60 QPM) — should allow
|
|
114
|
+
expect(checkSourceRateLimit("test").allowed).toBe(true);
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
describe("_resetSourceRateLimits", () => {
|
|
119
|
+
it("clears all state", () => {
|
|
120
|
+
registerSourceRateLimit("test", { queriesPerMinute: 1, concurrency: 1 });
|
|
121
|
+
incrementSourceConcurrency("test");
|
|
122
|
+
checkSourceRateLimit("test");
|
|
123
|
+
|
|
124
|
+
_resetSourceRateLimits();
|
|
125
|
+
|
|
126
|
+
// After reset, limits/concurrency/windows are cleared
|
|
127
|
+
expect(checkSourceRateLimit("test").allowed).toBe(true);
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
});
|