@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,387 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tests for the Atlas internal database module (src/lib/db/internal.ts).
|
|
3
|
+
*
|
|
4
|
+
* Uses _resetPool(mockPool) to inject a mock pool instance, avoiding
|
|
5
|
+
* the need to mock the pg module (which is require()'d lazily).
|
|
6
|
+
*/
|
|
7
|
+
import { describe, it, expect, beforeEach, afterEach } from "bun:test";
|
|
8
|
+
import {
|
|
9
|
+
hasInternalDB,
|
|
10
|
+
getInternalDB,
|
|
11
|
+
closeInternalDB,
|
|
12
|
+
internalQuery,
|
|
13
|
+
internalExecute,
|
|
14
|
+
migrateInternalDB,
|
|
15
|
+
_resetPool,
|
|
16
|
+
_resetCircuitBreaker,
|
|
17
|
+
} from "../internal";
|
|
18
|
+
|
|
19
|
+
/** Creates a mock pool that tracks query/end calls. */
|
|
20
|
+
function createMockPool() {
|
|
21
|
+
const calls = {
|
|
22
|
+
queries: [] as { sql: string; params?: unknown[] }[],
|
|
23
|
+
endCount: 0,
|
|
24
|
+
onEvents: [] as { event: "error"; listener: (err: Error) => void }[],
|
|
25
|
+
};
|
|
26
|
+
let queryResult: { rows: Record<string, unknown>[] } = { rows: [] };
|
|
27
|
+
let queryError: Error | null = null;
|
|
28
|
+
|
|
29
|
+
const pool = {
|
|
30
|
+
async query(sql: string, params?: unknown[]) {
|
|
31
|
+
calls.queries.push({ sql, params });
|
|
32
|
+
if (queryError) throw queryError;
|
|
33
|
+
return queryResult;
|
|
34
|
+
},
|
|
35
|
+
async end() {
|
|
36
|
+
calls.endCount++;
|
|
37
|
+
},
|
|
38
|
+
on(event: "error", listener: (err: Error) => void) {
|
|
39
|
+
calls.onEvents.push({ event, listener });
|
|
40
|
+
},
|
|
41
|
+
// Test helpers
|
|
42
|
+
_setResult(result: { rows: Record<string, unknown>[] }) {
|
|
43
|
+
queryResult = result;
|
|
44
|
+
},
|
|
45
|
+
_setError(err: Error | null) {
|
|
46
|
+
queryError = err;
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
return { pool, calls };
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
describe("internal DB module", () => {
|
|
54
|
+
const origDatabaseUrl = process.env.DATABASE_URL;
|
|
55
|
+
|
|
56
|
+
beforeEach(() => {
|
|
57
|
+
delete process.env.DATABASE_URL;
|
|
58
|
+
_resetPool();
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
afterEach(() => {
|
|
62
|
+
if (origDatabaseUrl !== undefined) {
|
|
63
|
+
process.env.DATABASE_URL = origDatabaseUrl;
|
|
64
|
+
} else {
|
|
65
|
+
delete process.env.DATABASE_URL;
|
|
66
|
+
}
|
|
67
|
+
_resetPool();
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
describe("hasInternalDB()", () => {
|
|
71
|
+
it("returns false when DATABASE_URL is not set", () => {
|
|
72
|
+
delete process.env.DATABASE_URL;
|
|
73
|
+
expect(hasInternalDB()).toBe(false);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it("returns true when DATABASE_URL is set", () => {
|
|
77
|
+
process.env.DATABASE_URL = "postgresql://user:pass@localhost:5432/atlas";
|
|
78
|
+
expect(hasInternalDB()).toBe(true);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it("returns false for empty string DATABASE_URL", () => {
|
|
82
|
+
process.env.DATABASE_URL = "";
|
|
83
|
+
expect(hasInternalDB()).toBe(false);
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
describe("getInternalDB()", () => {
|
|
88
|
+
it("throws when DATABASE_URL is not set", () => {
|
|
89
|
+
expect(() => getInternalDB()).toThrow("DATABASE_URL is not set");
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it("returns injected mock pool", () => {
|
|
93
|
+
process.env.DATABASE_URL = "postgresql://user:pass@localhost:5432/atlas";
|
|
94
|
+
const { pool } = createMockPool();
|
|
95
|
+
_resetPool(pool);
|
|
96
|
+
expect(getInternalDB()).toBe(pool);
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it("returns the same pool instance on repeated calls (singleton)", () => {
|
|
100
|
+
process.env.DATABASE_URL = "postgresql://user:pass@localhost:5432/atlas";
|
|
101
|
+
const { pool } = createMockPool();
|
|
102
|
+
_resetPool(pool);
|
|
103
|
+
const pool1 = getInternalDB();
|
|
104
|
+
const pool2 = getInternalDB();
|
|
105
|
+
expect(pool1).toBe(pool2);
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
describe("internalQuery()", () => {
|
|
110
|
+
it("executes parameterized query and returns typed rows", async () => {
|
|
111
|
+
process.env.DATABASE_URL = "postgresql://user:pass@localhost:5432/atlas";
|
|
112
|
+
const { pool, calls } = createMockPool();
|
|
113
|
+
pool._setResult({ rows: [{ id: "abc", count: 42 }] });
|
|
114
|
+
_resetPool(pool);
|
|
115
|
+
|
|
116
|
+
const rows = await internalQuery("SELECT * FROM audit_log WHERE user_id = $1", ["user-1"]);
|
|
117
|
+
expect(rows).toEqual([{ id: "abc", count: 42 }]);
|
|
118
|
+
expect(calls.queries[0]).toEqual({
|
|
119
|
+
sql: "SELECT * FROM audit_log WHERE user_id = $1",
|
|
120
|
+
params: ["user-1"],
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
it("works without params", async () => {
|
|
125
|
+
process.env.DATABASE_URL = "postgresql://user:pass@localhost:5432/atlas";
|
|
126
|
+
const { pool } = createMockPool();
|
|
127
|
+
pool._setResult({ rows: [{ n: 1 }] });
|
|
128
|
+
_resetPool(pool);
|
|
129
|
+
|
|
130
|
+
const rows = await internalQuery("SELECT 1 AS n");
|
|
131
|
+
expect(rows).toEqual([{ n: 1 }]);
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
it("propagates query errors", async () => {
|
|
135
|
+
process.env.DATABASE_URL = "postgresql://user:pass@localhost:5432/atlas";
|
|
136
|
+
const { pool } = createMockPool();
|
|
137
|
+
pool._setError(new Error("relation does not exist"));
|
|
138
|
+
_resetPool(pool);
|
|
139
|
+
|
|
140
|
+
await expect(internalQuery("SELECT * FROM missing")).rejects.toThrow(
|
|
141
|
+
"relation does not exist",
|
|
142
|
+
);
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
describe("internalExecute()", () => {
|
|
147
|
+
it("executes fire-and-forget query", async () => {
|
|
148
|
+
process.env.DATABASE_URL = "postgresql://user:pass@localhost:5432/atlas";
|
|
149
|
+
const { pool, calls } = createMockPool();
|
|
150
|
+
_resetPool(pool);
|
|
151
|
+
|
|
152
|
+
internalExecute("INSERT INTO audit_log (auth_mode) VALUES ($1)", ["none"]);
|
|
153
|
+
await new Promise((r) => setTimeout(r, 10));
|
|
154
|
+
expect(calls.queries.length).toBe(1);
|
|
155
|
+
expect(calls.queries[0].sql).toBe("INSERT INTO audit_log (auth_mode) VALUES ($1)");
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
it("does not throw on query error (logs instead)", async () => {
|
|
159
|
+
process.env.DATABASE_URL = "postgresql://user:pass@localhost:5432/atlas";
|
|
160
|
+
const { pool } = createMockPool();
|
|
161
|
+
pool._setError(new Error("connection lost"));
|
|
162
|
+
_resetPool(pool);
|
|
163
|
+
|
|
164
|
+
// Should not throw
|
|
165
|
+
internalExecute("INSERT INTO audit_log (auth_mode) VALUES ($1)", ["none"]);
|
|
166
|
+
await new Promise((r) => setTimeout(r, 10));
|
|
167
|
+
// Error was swallowed — no exception propagated
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
it("handles non-Error thrown values without crashing", async () => {
|
|
171
|
+
process.env.DATABASE_URL = "postgresql://user:pass@localhost:5432/atlas";
|
|
172
|
+
const { pool: mockPool } = createMockPool();
|
|
173
|
+
// Override query to throw a string instead of an Error
|
|
174
|
+
const pool = {
|
|
175
|
+
...mockPool,
|
|
176
|
+
async query() {
|
|
177
|
+
throw "string error";
|
|
178
|
+
},
|
|
179
|
+
};
|
|
180
|
+
_resetPool(pool);
|
|
181
|
+
|
|
182
|
+
// Should not throw
|
|
183
|
+
internalExecute("INSERT INTO audit_log (auth_mode) VALUES ($1)", ["none"]);
|
|
184
|
+
await new Promise((r) => setTimeout(r, 10));
|
|
185
|
+
// String error was handled gracefully — no exception propagated
|
|
186
|
+
});
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
describe("migrateInternalDB()", () => {
|
|
190
|
+
it("executes CREATE TABLE and CREATE INDEX statements for all tables", async () => {
|
|
191
|
+
process.env.DATABASE_URL = "postgresql://user:pass@localhost:5432/atlas";
|
|
192
|
+
const { pool, calls } = createMockPool();
|
|
193
|
+
_resetPool(pool);
|
|
194
|
+
|
|
195
|
+
await migrateInternalDB();
|
|
196
|
+
expect(calls.queries.length).toBe(26);
|
|
197
|
+
expect(calls.queries[0].sql).toContain("CREATE TABLE IF NOT EXISTS audit_log");
|
|
198
|
+
expect(calls.queries[1].sql).toContain("idx_audit_log_timestamp");
|
|
199
|
+
expect(calls.queries[2].sql).toContain("idx_audit_log_user_id");
|
|
200
|
+
expect(calls.queries[3].sql).toContain("CREATE TABLE IF NOT EXISTS conversations");
|
|
201
|
+
expect(calls.queries[4].sql).toContain("idx_conversations_user");
|
|
202
|
+
expect(calls.queries[5].sql).toContain("CREATE TABLE IF NOT EXISTS messages");
|
|
203
|
+
expect(calls.queries[6].sql).toContain("idx_messages_conversation");
|
|
204
|
+
expect(calls.queries[7].sql).toContain("CREATE TABLE IF NOT EXISTS slack_installations");
|
|
205
|
+
expect(calls.queries[8].sql).toContain("CREATE TABLE IF NOT EXISTS slack_threads");
|
|
206
|
+
expect(calls.queries[9].sql).toContain("idx_slack_threads_conversation");
|
|
207
|
+
expect(calls.queries[10].sql).toContain("CREATE TABLE IF NOT EXISTS action_log");
|
|
208
|
+
expect(calls.queries[11].sql).toContain("idx_action_log_requested_by");
|
|
209
|
+
expect(calls.queries[12].sql).toContain("idx_action_log_status");
|
|
210
|
+
expect(calls.queries[13].sql).toContain("idx_action_log_action_type");
|
|
211
|
+
expect(calls.queries[14].sql).toContain("idx_action_log_conversation");
|
|
212
|
+
expect(calls.queries[15].sql).toContain("ADD COLUMN IF NOT EXISTS source_id");
|
|
213
|
+
expect(calls.queries[16].sql).toContain("idx_audit_log_source_id");
|
|
214
|
+
expect(calls.queries[17].sql).toContain("starred BOOLEAN");
|
|
215
|
+
expect(calls.queries[18].sql).toContain("idx_conversations_starred");
|
|
216
|
+
expect(calls.queries[19].sql).toContain("CREATE TABLE IF NOT EXISTS scheduled_tasks");
|
|
217
|
+
expect(calls.queries[20].sql).toContain("idx_scheduled_tasks_owner");
|
|
218
|
+
expect(calls.queries[21].sql).toContain("idx_scheduled_tasks_enabled");
|
|
219
|
+
expect(calls.queries[22].sql).toContain("idx_scheduled_tasks_next_run");
|
|
220
|
+
expect(calls.queries[23].sql).toContain("CREATE TABLE IF NOT EXISTS scheduled_task_runs");
|
|
221
|
+
expect(calls.queries[24].sql).toContain("idx_scheduled_task_runs_task");
|
|
222
|
+
expect(calls.queries[25].sql).toContain("idx_scheduled_task_runs_status");
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
it("propagates migration errors", async () => {
|
|
226
|
+
process.env.DATABASE_URL = "postgresql://user:pass@localhost:5432/atlas";
|
|
227
|
+
const { pool } = createMockPool();
|
|
228
|
+
pool._setError(new Error("permission denied"));
|
|
229
|
+
_resetPool(pool);
|
|
230
|
+
|
|
231
|
+
await expect(migrateInternalDB()).rejects.toThrow("permission denied");
|
|
232
|
+
});
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
describe("closeInternalDB()", () => {
|
|
236
|
+
it("calls pool.end()", async () => {
|
|
237
|
+
process.env.DATABASE_URL = "postgresql://user:pass@localhost:5432/atlas";
|
|
238
|
+
const { pool, calls } = createMockPool();
|
|
239
|
+
_resetPool(pool);
|
|
240
|
+
await closeInternalDB();
|
|
241
|
+
expect(calls.endCount).toBe(1);
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
it("is a no-op when no pool exists", async () => {
|
|
245
|
+
await closeInternalDB(); // should not throw
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
it("nullifies the singleton (getInternalDB returns a new pool after close)", async () => {
|
|
249
|
+
process.env.DATABASE_URL = "postgresql://user:pass@localhost:5432/atlas";
|
|
250
|
+
const { pool: pool1 } = createMockPool();
|
|
251
|
+
_resetPool(pool1);
|
|
252
|
+
expect(getInternalDB()).toBe(pool1);
|
|
253
|
+
|
|
254
|
+
await closeInternalDB();
|
|
255
|
+
|
|
256
|
+
// After close, injecting a new pool and calling getInternalDB should return the new one
|
|
257
|
+
const { pool: pool2 } = createMockPool();
|
|
258
|
+
_resetPool(pool2);
|
|
259
|
+
expect(getInternalDB()).toBe(pool2);
|
|
260
|
+
expect(pool2).not.toBe(pool1);
|
|
261
|
+
});
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
describe("circuit breaker", () => {
|
|
265
|
+
beforeEach(() => {
|
|
266
|
+
_resetCircuitBreaker();
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
it("opens after 5 consecutive failures", async () => {
|
|
270
|
+
process.env.DATABASE_URL = "postgresql://user:pass@localhost:5432/atlas";
|
|
271
|
+
const { pool, calls } = createMockPool();
|
|
272
|
+
pool._setError(new Error("connection refused"));
|
|
273
|
+
_resetPool(pool);
|
|
274
|
+
|
|
275
|
+
// Fire 5 failing queries to trip the circuit breaker
|
|
276
|
+
for (let i = 0; i < 5; i++) {
|
|
277
|
+
internalExecute("INSERT INTO audit_log (auth_mode) VALUES ($1)", ["none"]);
|
|
278
|
+
}
|
|
279
|
+
await new Promise((r) => setTimeout(r, 50));
|
|
280
|
+
expect(calls.queries.length).toBe(5);
|
|
281
|
+
|
|
282
|
+
// 6th call should be silently skipped (circuit open)
|
|
283
|
+
internalExecute("INSERT INTO audit_log (auth_mode) VALUES ($1)", ["none"]);
|
|
284
|
+
await new Promise((r) => setTimeout(r, 10));
|
|
285
|
+
expect(calls.queries.length).toBe(5); // no new query issued
|
|
286
|
+
});
|
|
287
|
+
|
|
288
|
+
it("silently skips requests when circuit is open and increments dropped count", async () => {
|
|
289
|
+
process.env.DATABASE_URL = "postgresql://user:pass@localhost:5432/atlas";
|
|
290
|
+
const { pool, calls } = createMockPool();
|
|
291
|
+
pool._setError(new Error("connection refused"));
|
|
292
|
+
_resetPool(pool);
|
|
293
|
+
|
|
294
|
+
// Trip the circuit breaker
|
|
295
|
+
for (let i = 0; i < 5; i++) {
|
|
296
|
+
internalExecute("INSERT INTO audit_log (auth_mode) VALUES ($1)", ["none"]);
|
|
297
|
+
}
|
|
298
|
+
await new Promise((r) => setTimeout(r, 50));
|
|
299
|
+
|
|
300
|
+
// Fire several more — all should be dropped
|
|
301
|
+
for (let i = 0; i < 3; i++) {
|
|
302
|
+
internalExecute("INSERT INTO audit_log (auth_mode) VALUES ($1)", ["none"]);
|
|
303
|
+
}
|
|
304
|
+
await new Promise((r) => setTimeout(r, 10));
|
|
305
|
+
// Still only 5 queries were actually sent to the pool
|
|
306
|
+
expect(calls.queries.length).toBe(5);
|
|
307
|
+
});
|
|
308
|
+
|
|
309
|
+
it("recovers after timeout", async () => {
|
|
310
|
+
process.env.DATABASE_URL = "postgresql://user:pass@localhost:5432/atlas";
|
|
311
|
+
const { pool, calls } = createMockPool();
|
|
312
|
+
pool._setError(new Error("connection refused"));
|
|
313
|
+
_resetPool(pool);
|
|
314
|
+
|
|
315
|
+
// Trip the circuit breaker
|
|
316
|
+
for (let i = 0; i < 5; i++) {
|
|
317
|
+
internalExecute("INSERT INTO audit_log (auth_mode) VALUES ($1)", ["none"]);
|
|
318
|
+
}
|
|
319
|
+
await new Promise((r) => setTimeout(r, 50));
|
|
320
|
+
expect(calls.queries.length).toBe(5);
|
|
321
|
+
|
|
322
|
+
// Verify circuit is open
|
|
323
|
+
internalExecute("INSERT INTO audit_log (auth_mode) VALUES ($1)", ["none"]);
|
|
324
|
+
await new Promise((r) => setTimeout(r, 10));
|
|
325
|
+
expect(calls.queries.length).toBe(5);
|
|
326
|
+
|
|
327
|
+
// Advance timer to trigger recovery (setTimeout 60s)
|
|
328
|
+
// Use Bun's mock timer approach: we can't easily mock setTimeout here,
|
|
329
|
+
// so we manually reset the circuit breaker to simulate recovery
|
|
330
|
+
_resetCircuitBreaker();
|
|
331
|
+
|
|
332
|
+
// Now the pool should accept queries again
|
|
333
|
+
pool._setError(null);
|
|
334
|
+
internalExecute("INSERT INTO audit_log (auth_mode) VALUES ($1)", ["none"]);
|
|
335
|
+
await new Promise((r) => setTimeout(r, 10));
|
|
336
|
+
expect(calls.queries.length).toBe(6);
|
|
337
|
+
});
|
|
338
|
+
|
|
339
|
+
it("_resetCircuitBreaker() clears all circuit state", async () => {
|
|
340
|
+
process.env.DATABASE_URL = "postgresql://user:pass@localhost:5432/atlas";
|
|
341
|
+
const { pool, calls } = createMockPool();
|
|
342
|
+
pool._setError(new Error("connection refused"));
|
|
343
|
+
_resetPool(pool);
|
|
344
|
+
|
|
345
|
+
// Trip the circuit breaker
|
|
346
|
+
for (let i = 0; i < 5; i++) {
|
|
347
|
+
internalExecute("INSERT INTO audit_log (auth_mode) VALUES ($1)", ["none"]);
|
|
348
|
+
}
|
|
349
|
+
await new Promise((r) => setTimeout(r, 50));
|
|
350
|
+
|
|
351
|
+
// Circuit is open — queries are dropped
|
|
352
|
+
internalExecute("INSERT INTO audit_log (auth_mode) VALUES ($1)", ["none"]);
|
|
353
|
+
await new Promise((r) => setTimeout(r, 10));
|
|
354
|
+
expect(calls.queries.length).toBe(5);
|
|
355
|
+
|
|
356
|
+
// Reset circuit breaker
|
|
357
|
+
_resetCircuitBreaker();
|
|
358
|
+
|
|
359
|
+
// Queries should flow through again
|
|
360
|
+
pool._setError(null);
|
|
361
|
+
internalExecute("INSERT INTO audit_log (auth_mode) VALUES ($1)", ["none"]);
|
|
362
|
+
await new Promise((r) => setTimeout(r, 10));
|
|
363
|
+
expect(calls.queries.length).toBe(6);
|
|
364
|
+
});
|
|
365
|
+
|
|
366
|
+
it("_resetPool() also resets circuit breaker state", async () => {
|
|
367
|
+
process.env.DATABASE_URL = "postgresql://user:pass@localhost:5432/atlas";
|
|
368
|
+
const { pool } = createMockPool();
|
|
369
|
+
pool._setError(new Error("connection refused"));
|
|
370
|
+
_resetPool(pool);
|
|
371
|
+
|
|
372
|
+
// Trip the circuit breaker
|
|
373
|
+
for (let i = 0; i < 5; i++) {
|
|
374
|
+
internalExecute("INSERT INTO audit_log (auth_mode) VALUES ($1)", ["none"]);
|
|
375
|
+
}
|
|
376
|
+
await new Promise((r) => setTimeout(r, 50));
|
|
377
|
+
|
|
378
|
+
// Reset pool with a fresh mock — circuit breaker should also be reset
|
|
379
|
+
const { pool: freshPool, calls: freshCalls } = createMockPool();
|
|
380
|
+
_resetPool(freshPool);
|
|
381
|
+
|
|
382
|
+
internalExecute("INSERT INTO audit_log (auth_mode) VALUES ($1)", ["none"]);
|
|
383
|
+
await new Promise((r) => setTimeout(r, 10));
|
|
384
|
+
expect(freshCalls.queries.length).toBe(1); // query went through
|
|
385
|
+
});
|
|
386
|
+
});
|
|
387
|
+
});
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tests for ConnectionRegistry health check features.
|
|
3
|
+
*/
|
|
4
|
+
import { describe, it, expect, beforeEach, afterEach, mock } from "bun:test";
|
|
5
|
+
import { resolve } from "path";
|
|
6
|
+
|
|
7
|
+
// Mock pg
|
|
8
|
+
mock.module("pg", () => ({
|
|
9
|
+
Pool: class MockPool {
|
|
10
|
+
async query() { return { rows: [], fields: [] }; }
|
|
11
|
+
async connect() {
|
|
12
|
+
return { async query() { return { rows: [], fields: [] }; }, release() {} };
|
|
13
|
+
}
|
|
14
|
+
async end() {}
|
|
15
|
+
},
|
|
16
|
+
}));
|
|
17
|
+
|
|
18
|
+
mock.module("mysql2/promise", () => ({
|
|
19
|
+
createPool: () => ({
|
|
20
|
+
async getConnection() {
|
|
21
|
+
return { async execute() { return [[], []]; }, release() {} };
|
|
22
|
+
},
|
|
23
|
+
async end() {},
|
|
24
|
+
}),
|
|
25
|
+
}));
|
|
26
|
+
|
|
27
|
+
mock.module("@duckdb/node-api", () => ({
|
|
28
|
+
DuckDBInstance: {
|
|
29
|
+
async create() {
|
|
30
|
+
return {
|
|
31
|
+
async connect() {
|
|
32
|
+
return {
|
|
33
|
+
async runAndReadAll() {
|
|
34
|
+
return { columnNames: () => [], getRowObjects: () => [] };
|
|
35
|
+
},
|
|
36
|
+
async run() {},
|
|
37
|
+
async close() {},
|
|
38
|
+
};
|
|
39
|
+
},
|
|
40
|
+
async close() {},
|
|
41
|
+
};
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
}));
|
|
45
|
+
|
|
46
|
+
// Cache-busting import
|
|
47
|
+
const connModPath = resolve(__dirname, "../connection.ts");
|
|
48
|
+
const connMod = await import(`${connModPath}?t=${Date.now()}`);
|
|
49
|
+
const ConnectionRegistry = connMod.ConnectionRegistry as typeof import("../connection").ConnectionRegistry;
|
|
50
|
+
const extractTargetHost = connMod.extractTargetHost as typeof import("../connection").extractTargetHost;
|
|
51
|
+
type DBConnection = import("../connection").DBConnection;
|
|
52
|
+
|
|
53
|
+
describe("ConnectionRegistry health checks", () => {
|
|
54
|
+
let registry: InstanceType<typeof ConnectionRegistry>;
|
|
55
|
+
|
|
56
|
+
beforeEach(() => {
|
|
57
|
+
registry = new ConnectionRegistry();
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
afterEach(() => {
|
|
61
|
+
registry._reset();
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
function mockConn(opts?: { failQuery?: boolean }): DBConnection {
|
|
65
|
+
return {
|
|
66
|
+
async query() {
|
|
67
|
+
if (opts?.failQuery) throw new Error("connection refused");
|
|
68
|
+
return { columns: ["?column?"], rows: [{ "?column?": 1 }] };
|
|
69
|
+
},
|
|
70
|
+
async close() {},
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
it("healthy on successful health check", async () => {
|
|
75
|
+
await registry.registerDirect("test", mockConn(), "postgres");
|
|
76
|
+
const result = await registry.healthCheck("test");
|
|
77
|
+
expect(result.status).toBe("healthy");
|
|
78
|
+
expect(result.latencyMs).toBeGreaterThanOrEqual(0);
|
|
79
|
+
expect(result.checkedAt).toBeInstanceOf(Date);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it("degraded after 1 failure", async () => {
|
|
83
|
+
await registry.registerDirect("test", mockConn({ failQuery: true }), "postgres");
|
|
84
|
+
const result = await registry.healthCheck("test");
|
|
85
|
+
expect(result.status).toBe("degraded");
|
|
86
|
+
expect(result.message).toContain("connection refused");
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it("unhealthy after 3 failures spanning > 5 minutes", async () => {
|
|
90
|
+
const conn = mockConn({ failQuery: true });
|
|
91
|
+
await registry.registerDirect("test", conn, "postgres");
|
|
92
|
+
|
|
93
|
+
// Simulate 3 failures over 5+ minutes
|
|
94
|
+
await registry.healthCheck("test"); // failure 1
|
|
95
|
+
|
|
96
|
+
// Manipulate the entry's firstFailureAt to simulate time passing
|
|
97
|
+
// Access private field via any cast
|
|
98
|
+
const entries = (registry as unknown as { entries: Map<string, { firstFailureAt: number | null; consecutiveFailures: number }> }).entries;
|
|
99
|
+
const entry = entries.get("test")!;
|
|
100
|
+
entry.firstFailureAt = Date.now() - (5 * 60 * 1000 + 1000); // 5min + 1s ago
|
|
101
|
+
entry.consecutiveFailures = 2; // already had 2 failures
|
|
102
|
+
|
|
103
|
+
const result = await registry.healthCheck("test"); // failure 3
|
|
104
|
+
expect(result.status).toBe("unhealthy");
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it("recovers from unhealthy to healthy on success", async () => {
|
|
108
|
+
let shouldFail = true;
|
|
109
|
+
const conn: DBConnection = {
|
|
110
|
+
async query() {
|
|
111
|
+
if (shouldFail) throw new Error("down");
|
|
112
|
+
return { columns: ["?column?"], rows: [{ "?column?": 1 }] };
|
|
113
|
+
},
|
|
114
|
+
async close() {},
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
await registry.registerDirect("test", conn, "postgres");
|
|
118
|
+
|
|
119
|
+
// Make it unhealthy
|
|
120
|
+
const entries = (registry as unknown as { entries: Map<string, { firstFailureAt: number | null; consecutiveFailures: number }> }).entries;
|
|
121
|
+
await registry.healthCheck("test");
|
|
122
|
+
const entry = entries.get("test")!;
|
|
123
|
+
entry.firstFailureAt = Date.now() - (5 * 60 * 1000 + 1000);
|
|
124
|
+
entry.consecutiveFailures = 2;
|
|
125
|
+
const unhealthy = await registry.healthCheck("test");
|
|
126
|
+
expect(unhealthy.status).toBe("unhealthy");
|
|
127
|
+
|
|
128
|
+
// Now recover
|
|
129
|
+
shouldFail = false;
|
|
130
|
+
const recovered = await registry.healthCheck("test");
|
|
131
|
+
expect(recovered.status).toBe("healthy");
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
it("describe() includes health status", async () => {
|
|
135
|
+
await registry.registerDirect("test", mockConn(), "postgres", "Test DB");
|
|
136
|
+
await registry.healthCheck("test");
|
|
137
|
+
|
|
138
|
+
const meta = registry.describe();
|
|
139
|
+
expect(meta).toHaveLength(1);
|
|
140
|
+
expect(meta[0].health).toBeDefined();
|
|
141
|
+
expect(meta[0].health!.status).toBe("healthy");
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
it("describe() omits health when no check has been run", async () => {
|
|
145
|
+
await registry.registerDirect("test", mockConn(), "postgres");
|
|
146
|
+
const meta = registry.describe();
|
|
147
|
+
expect(meta[0].health).toBeUndefined();
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
it("_reset() stops health checks", () => {
|
|
151
|
+
registry.startHealthChecks(60000);
|
|
152
|
+
registry._reset();
|
|
153
|
+
// Should not throw — interval is already cleared
|
|
154
|
+
registry.stopHealthChecks();
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
it("startHealthChecks is idempotent", () => {
|
|
158
|
+
registry.startHealthChecks(60000);
|
|
159
|
+
registry.startHealthChecks(60000); // should not create a second interval
|
|
160
|
+
registry.stopHealthChecks();
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
it("getTargetHost returns host for registered connection", () => {
|
|
164
|
+
registry.register("pg", {
|
|
165
|
+
url: "postgresql://user:pass@db-host.example.com:5432/mydb",
|
|
166
|
+
});
|
|
167
|
+
expect(registry.getTargetHost("pg")).toBe("db-host.example.com");
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
it("getTargetHost returns (unknown) for unregistered connection", () => {
|
|
171
|
+
expect(registry.getTargetHost("nonexistent")).toBe("(unknown)");
|
|
172
|
+
});
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
describe("extractTargetHost", () => {
|
|
176
|
+
it("extracts hostname from postgresql URL", () => {
|
|
177
|
+
expect(extractTargetHost("postgresql://user:pass@db.example.com:5432/mydb")).toBe("db.example.com");
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
it("extracts hostname from mysql URL", () => {
|
|
181
|
+
expect(extractTargetHost("mysql://user:pass@mysql.host:3306/db")).toBe("mysql.host");
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
it("extracts hostname from clickhouse URL", () => {
|
|
185
|
+
expect(extractTargetHost("clickhouse://user:pass@ch.host:8123/default")).toBe("ch.host");
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
it("extracts hostname from snowflake URL", () => {
|
|
189
|
+
expect(extractTargetHost("snowflake://user:pass@account123/db/schema")).toBe("account123");
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
it("extracts hostname from duckdb URL", () => {
|
|
193
|
+
// duckdb://:memory: doesn't have a parseable hostname
|
|
194
|
+
expect(extractTargetHost("duckdb://:memory:")).toBe("(unknown)");
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
it("returns (unknown) for unparseable URL", () => {
|
|
198
|
+
expect(extractTargetHost("not-a-url")).toBe("(unknown)");
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
it("never exposes credentials", () => {
|
|
202
|
+
const host = extractTargetHost("postgresql://admin:s3cret@db.example.com:5432/production");
|
|
203
|
+
expect(host).toBe("db.example.com");
|
|
204
|
+
expect(host).not.toContain("admin");
|
|
205
|
+
expect(host).not.toContain("s3cret");
|
|
206
|
+
});
|
|
207
|
+
});
|