@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,820 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tests for admin API routes.
|
|
3
|
+
*
|
|
4
|
+
* Mocks: auth middleware, connection registry, internal DB, plugin registry,
|
|
5
|
+
* and transitive dependencies (explore, agent, semantic, conversations, etc.).
|
|
6
|
+
* Uses a real temp directory with fixture YAML files for semantic layer tests.
|
|
7
|
+
* Verifies admin role enforcement and endpoint response shapes.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import {
|
|
11
|
+
describe,
|
|
12
|
+
it,
|
|
13
|
+
expect,
|
|
14
|
+
beforeEach,
|
|
15
|
+
afterAll,
|
|
16
|
+
mock,
|
|
17
|
+
type Mock,
|
|
18
|
+
} from "bun:test";
|
|
19
|
+
import * as fs from "fs";
|
|
20
|
+
import * as path from "path";
|
|
21
|
+
|
|
22
|
+
// --- Create temp semantic fixtures before mocks ---
|
|
23
|
+
|
|
24
|
+
const tmpRoot = path.join(process.env.TMPDIR ?? "/tmp", `atlas-admin-test-${Date.now()}`);
|
|
25
|
+
|
|
26
|
+
function setupFixtures(): void {
|
|
27
|
+
fs.mkdirSync(path.join(tmpRoot, "entities"), { recursive: true });
|
|
28
|
+
fs.mkdirSync(path.join(tmpRoot, "metrics"), { recursive: true });
|
|
29
|
+
// Per-source subdirectory for multi-source testing
|
|
30
|
+
fs.mkdirSync(path.join(tmpRoot, "warehouse", "entities"), { recursive: true });
|
|
31
|
+
|
|
32
|
+
fs.writeFileSync(
|
|
33
|
+
path.join(tmpRoot, "entities", "companies.yml"),
|
|
34
|
+
`table: companies
|
|
35
|
+
description: All company records
|
|
36
|
+
dimensions:
|
|
37
|
+
id:
|
|
38
|
+
type: integer
|
|
39
|
+
description: Primary key
|
|
40
|
+
name:
|
|
41
|
+
type: text
|
|
42
|
+
description: Company name
|
|
43
|
+
industry:
|
|
44
|
+
type: text
|
|
45
|
+
description: Industry sector
|
|
46
|
+
joins:
|
|
47
|
+
to_accounts:
|
|
48
|
+
description: companies.id -> accounts.company_id
|
|
49
|
+
measures:
|
|
50
|
+
total_companies:
|
|
51
|
+
sql: "COUNT(DISTINCT id)"
|
|
52
|
+
`,
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
fs.writeFileSync(
|
|
56
|
+
path.join(tmpRoot, "warehouse", "entities", "orders.yml"),
|
|
57
|
+
`table: orders
|
|
58
|
+
description: Warehouse orders
|
|
59
|
+
connection: warehouse
|
|
60
|
+
dimensions:
|
|
61
|
+
id:
|
|
62
|
+
type: integer
|
|
63
|
+
total:
|
|
64
|
+
type: numeric
|
|
65
|
+
`,
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
fs.writeFileSync(
|
|
69
|
+
path.join(tmpRoot, "metrics", "total_companies.yml"),
|
|
70
|
+
`name: total_companies
|
|
71
|
+
table: companies
|
|
72
|
+
sql: "SELECT COUNT(*) FROM companies"
|
|
73
|
+
`,
|
|
74
|
+
);
|
|
75
|
+
|
|
76
|
+
fs.writeFileSync(
|
|
77
|
+
path.join(tmpRoot, "glossary.yml"),
|
|
78
|
+
`terms:
|
|
79
|
+
- term: ARR
|
|
80
|
+
definition: Annual Recurring Revenue
|
|
81
|
+
ambiguous: false
|
|
82
|
+
- term: churn
|
|
83
|
+
definition: Customer cancellation rate
|
|
84
|
+
ambiguous: true
|
|
85
|
+
`,
|
|
86
|
+
);
|
|
87
|
+
|
|
88
|
+
fs.writeFileSync(
|
|
89
|
+
path.join(tmpRoot, "catalog.yml"),
|
|
90
|
+
`name: Test Catalog
|
|
91
|
+
description: Test catalog for admin tests
|
|
92
|
+
`,
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
setupFixtures();
|
|
97
|
+
|
|
98
|
+
// Point admin routes to our temp directory
|
|
99
|
+
process.env.ATLAS_SEMANTIC_ROOT = tmpRoot;
|
|
100
|
+
|
|
101
|
+
// --- Mocks (before any import that touches the modules) ---
|
|
102
|
+
|
|
103
|
+
const mockAuthenticateRequest: Mock<(req: Request) => Promise<unknown>> = mock(
|
|
104
|
+
() =>
|
|
105
|
+
Promise.resolve({
|
|
106
|
+
authenticated: true,
|
|
107
|
+
mode: "simple-key",
|
|
108
|
+
user: { id: "admin-1", mode: "simple-key", label: "Admin", role: "admin" },
|
|
109
|
+
}),
|
|
110
|
+
);
|
|
111
|
+
|
|
112
|
+
const mockCheckRateLimit: Mock<(key: string) => { allowed: boolean; retryAfterMs?: number }> = mock(
|
|
113
|
+
() => ({ allowed: true }),
|
|
114
|
+
);
|
|
115
|
+
|
|
116
|
+
mock.module("@atlas/api/lib/auth/middleware", () => ({
|
|
117
|
+
authenticateRequest: mockAuthenticateRequest,
|
|
118
|
+
checkRateLimit: mockCheckRateLimit,
|
|
119
|
+
getClientIP: mock(() => null),
|
|
120
|
+
resetRateLimits: mock(() => {}),
|
|
121
|
+
_stopCleanup: mock(() => {}),
|
|
122
|
+
_setValidatorOverrides: mock(() => {}),
|
|
123
|
+
}));
|
|
124
|
+
|
|
125
|
+
mock.module("@atlas/api/lib/auth/detect", () => ({
|
|
126
|
+
detectAuthMode: () => "simple-key",
|
|
127
|
+
resetAuthModeCache: () => {},
|
|
128
|
+
}));
|
|
129
|
+
|
|
130
|
+
mock.module("@atlas/api/lib/startup", () => ({
|
|
131
|
+
validateEnvironment: mock(() => Promise.resolve([])),
|
|
132
|
+
getStartupWarnings: mock(() => []),
|
|
133
|
+
}));
|
|
134
|
+
|
|
135
|
+
const mockDBConnection = {
|
|
136
|
+
query: async () => ({ columns: ["?column?"], rows: [{ "?column?": 1 }] }),
|
|
137
|
+
close: async () => {},
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
const mockHealthCheck: Mock<(id: string) => Promise<unknown>> = mock(() =>
|
|
141
|
+
Promise.resolve({
|
|
142
|
+
status: "healthy",
|
|
143
|
+
latencyMs: 5,
|
|
144
|
+
checkedAt: new Date(),
|
|
145
|
+
}),
|
|
146
|
+
);
|
|
147
|
+
|
|
148
|
+
mock.module("@atlas/api/lib/db/connection", () => ({
|
|
149
|
+
getDB: () => mockDBConnection,
|
|
150
|
+
connections: {
|
|
151
|
+
get: () => mockDBConnection,
|
|
152
|
+
getDefault: () => mockDBConnection,
|
|
153
|
+
getDBType: () => "postgres" as const,
|
|
154
|
+
getTargetHost: () => "localhost",
|
|
155
|
+
getValidator: () => undefined,
|
|
156
|
+
list: () => ["default"],
|
|
157
|
+
describe: () => [
|
|
158
|
+
{ id: "default", dbType: "postgres", description: "Test DB" },
|
|
159
|
+
],
|
|
160
|
+
healthCheck: mockHealthCheck,
|
|
161
|
+
},
|
|
162
|
+
detectDBType: () => "postgres" as const,
|
|
163
|
+
extractTargetHost: () => "localhost",
|
|
164
|
+
rewriteClickHouseUrl: (url: string) => url,
|
|
165
|
+
parseSnowflakeURL: () => ({}),
|
|
166
|
+
ConnectionRegistry: class {},
|
|
167
|
+
}));
|
|
168
|
+
|
|
169
|
+
mock.module("@atlas/api/lib/semantic", () => ({
|
|
170
|
+
getWhitelistedTables: () => new Set(["companies"]),
|
|
171
|
+
getCrossSourceJoins: () => [],
|
|
172
|
+
_resetWhitelists: () => {},
|
|
173
|
+
registerPluginEntities: () => {},
|
|
174
|
+
_resetPluginEntities: () => {},
|
|
175
|
+
}));
|
|
176
|
+
|
|
177
|
+
let mockHasInternalDB = true;
|
|
178
|
+
const mockInternalQuery: Mock<(sql: string, params?: unknown[]) => Promise<unknown[]>> = mock(
|
|
179
|
+
() => Promise.resolve([]),
|
|
180
|
+
);
|
|
181
|
+
|
|
182
|
+
mock.module("@atlas/api/lib/db/internal", () => ({
|
|
183
|
+
hasInternalDB: () => mockHasInternalDB,
|
|
184
|
+
internalQuery: mockInternalQuery,
|
|
185
|
+
internalExecute: mock(() => {}),
|
|
186
|
+
getInternalDB: mock(() => ({})),
|
|
187
|
+
closeInternalDB: mock(async () => {}),
|
|
188
|
+
migrateInternalDB: mock(async () => {}),
|
|
189
|
+
_resetPool: mock(() => {}),
|
|
190
|
+
_resetCircuitBreaker: mock(() => {}),
|
|
191
|
+
}));
|
|
192
|
+
|
|
193
|
+
const mockPluginHealthCheck: Mock<() => Promise<unknown>> = mock(() =>
|
|
194
|
+
Promise.resolve({ healthy: true, message: "OK" }),
|
|
195
|
+
);
|
|
196
|
+
|
|
197
|
+
mock.module("@atlas/api/lib/plugins/registry", () => ({
|
|
198
|
+
plugins: {
|
|
199
|
+
describe: () => [
|
|
200
|
+
{ id: "test-plugin", type: "context", version: "1.0.0", name: "Test Plugin", status: "healthy" },
|
|
201
|
+
],
|
|
202
|
+
get: (id: string) => {
|
|
203
|
+
if (id === "test-plugin") {
|
|
204
|
+
return {
|
|
205
|
+
id: "test-plugin",
|
|
206
|
+
type: "context",
|
|
207
|
+
version: "1.0.0",
|
|
208
|
+
name: "Test Plugin",
|
|
209
|
+
healthCheck: mockPluginHealthCheck,
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
if (id === "no-health-plugin") {
|
|
213
|
+
return {
|
|
214
|
+
id: "no-health-plugin",
|
|
215
|
+
type: "action",
|
|
216
|
+
version: "0.1.0",
|
|
217
|
+
name: "No Health Plugin",
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
return undefined;
|
|
221
|
+
},
|
|
222
|
+
getStatus: (id: string) => {
|
|
223
|
+
if (id === "test-plugin") return "healthy";
|
|
224
|
+
if (id === "no-health-plugin") return "registered";
|
|
225
|
+
return undefined;
|
|
226
|
+
},
|
|
227
|
+
getAllHealthy: () => [],
|
|
228
|
+
getByType: () => [],
|
|
229
|
+
size: 1,
|
|
230
|
+
},
|
|
231
|
+
PluginRegistry: class {},
|
|
232
|
+
}));
|
|
233
|
+
|
|
234
|
+
mock.module("@atlas/api/lib/tools/explore", () => ({
|
|
235
|
+
getExploreBackendType: () => "just-bash",
|
|
236
|
+
getActiveSandboxPluginId: () => null,
|
|
237
|
+
explore: { type: "function" },
|
|
238
|
+
}));
|
|
239
|
+
|
|
240
|
+
mock.module("@atlas/api/lib/agent", () => ({
|
|
241
|
+
runAgent: mock(() =>
|
|
242
|
+
Promise.resolve({
|
|
243
|
+
toUIMessageStreamResponse: () => new Response("stream", { status: 200 }),
|
|
244
|
+
text: Promise.resolve("answer"),
|
|
245
|
+
}),
|
|
246
|
+
),
|
|
247
|
+
}));
|
|
248
|
+
|
|
249
|
+
mock.module("@atlas/api/lib/tools/actions", () => ({
|
|
250
|
+
createJiraTicket: {
|
|
251
|
+
name: "createJiraTicket",
|
|
252
|
+
description: "Mock",
|
|
253
|
+
tool: { type: "function" },
|
|
254
|
+
actionType: "jira:create",
|
|
255
|
+
reversible: true,
|
|
256
|
+
defaultApproval: "manual",
|
|
257
|
+
requiredCredentials: ["JIRA_BASE_URL"],
|
|
258
|
+
},
|
|
259
|
+
sendEmailReport: {
|
|
260
|
+
name: "sendEmailReport",
|
|
261
|
+
description: "Mock",
|
|
262
|
+
tool: { type: "function" },
|
|
263
|
+
actionType: "email:send",
|
|
264
|
+
reversible: false,
|
|
265
|
+
defaultApproval: "admin-only",
|
|
266
|
+
requiredCredentials: ["RESEND_API_KEY"],
|
|
267
|
+
},
|
|
268
|
+
}));
|
|
269
|
+
|
|
270
|
+
mock.module("@atlas/api/lib/conversations", () => ({
|
|
271
|
+
createConversation: mock(() => Promise.resolve(null)),
|
|
272
|
+
addMessage: mock(() => {}),
|
|
273
|
+
getConversation: mock(() => Promise.resolve(null)),
|
|
274
|
+
generateTitle: mock((q: string) => q.slice(0, 80)),
|
|
275
|
+
listConversations: mock(() => Promise.resolve({ conversations: [], total: 0 })),
|
|
276
|
+
deleteConversation: mock(() => Promise.resolve(false)),
|
|
277
|
+
starConversation: async () => false,
|
|
278
|
+
}));
|
|
279
|
+
|
|
280
|
+
// Import app after all mocks are registered
|
|
281
|
+
const { app } = await import("../index");
|
|
282
|
+
|
|
283
|
+
// --- Helpers ---
|
|
284
|
+
|
|
285
|
+
function adminRequest(urlPath: string, method = "GET", body?: unknown): Request {
|
|
286
|
+
const opts: RequestInit = {
|
|
287
|
+
method,
|
|
288
|
+
headers: { Authorization: "Bearer test-key" },
|
|
289
|
+
};
|
|
290
|
+
if (body) {
|
|
291
|
+
opts.headers = { ...opts.headers, "Content-Type": "application/json" };
|
|
292
|
+
opts.body = JSON.stringify(body);
|
|
293
|
+
}
|
|
294
|
+
return new Request(`http://localhost${urlPath}`, opts);
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
function setAdmin(): void {
|
|
298
|
+
mockAuthenticateRequest.mockResolvedValue({
|
|
299
|
+
authenticated: true,
|
|
300
|
+
mode: "simple-key",
|
|
301
|
+
user: { id: "admin-1", mode: "simple-key", label: "Admin", role: "admin" },
|
|
302
|
+
});
|
|
303
|
+
mockCheckRateLimit.mockReturnValue({ allowed: true });
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
// --- Cleanup ---
|
|
307
|
+
|
|
308
|
+
afterAll(() => {
|
|
309
|
+
fs.rmSync(tmpRoot, { recursive: true, force: true });
|
|
310
|
+
delete process.env.ATLAS_SEMANTIC_ROOT;
|
|
311
|
+
});
|
|
312
|
+
|
|
313
|
+
// --- Tests ---
|
|
314
|
+
|
|
315
|
+
describe("Admin routes — auth enforcement", () => {
|
|
316
|
+
beforeEach(() => {
|
|
317
|
+
mockAuthenticateRequest.mockReset();
|
|
318
|
+
mockCheckRateLimit.mockReset();
|
|
319
|
+
mockCheckRateLimit.mockReturnValue({ allowed: true });
|
|
320
|
+
});
|
|
321
|
+
|
|
322
|
+
it("returns 403 when user has analyst role", async () => {
|
|
323
|
+
mockAuthenticateRequest.mockResolvedValue({
|
|
324
|
+
authenticated: true,
|
|
325
|
+
mode: "simple-key",
|
|
326
|
+
user: { id: "user-1", mode: "simple-key", label: "Analyst", role: "analyst" },
|
|
327
|
+
});
|
|
328
|
+
|
|
329
|
+
const res = await app.fetch(adminRequest("/api/v1/admin/overview"));
|
|
330
|
+
expect(res.status).toBe(403);
|
|
331
|
+
const body = (await res.json()) as Record<string, unknown>;
|
|
332
|
+
expect(body.error).toBe("forbidden");
|
|
333
|
+
});
|
|
334
|
+
|
|
335
|
+
it("returns 403 when user has no role", async () => {
|
|
336
|
+
mockAuthenticateRequest.mockResolvedValue({
|
|
337
|
+
authenticated: true,
|
|
338
|
+
mode: "simple-key",
|
|
339
|
+
user: { id: "user-1", mode: "simple-key", label: "User" },
|
|
340
|
+
});
|
|
341
|
+
|
|
342
|
+
const res = await app.fetch(adminRequest("/api/v1/admin/overview"));
|
|
343
|
+
expect(res.status).toBe(403);
|
|
344
|
+
});
|
|
345
|
+
|
|
346
|
+
it("returns 401 when authentication fails", async () => {
|
|
347
|
+
mockAuthenticateRequest.mockResolvedValue({
|
|
348
|
+
authenticated: false,
|
|
349
|
+
mode: "simple-key",
|
|
350
|
+
status: 401,
|
|
351
|
+
error: "Invalid API key",
|
|
352
|
+
});
|
|
353
|
+
|
|
354
|
+
const res = await app.fetch(adminRequest("/api/v1/admin/overview"));
|
|
355
|
+
expect(res.status).toBe(401);
|
|
356
|
+
});
|
|
357
|
+
|
|
358
|
+
it("returns 403 when auth mode is none (no user object)", async () => {
|
|
359
|
+
mockAuthenticateRequest.mockResolvedValue({
|
|
360
|
+
authenticated: true,
|
|
361
|
+
mode: "none",
|
|
362
|
+
user: undefined,
|
|
363
|
+
});
|
|
364
|
+
|
|
365
|
+
const res = await app.fetch(adminRequest("/api/v1/admin/overview"));
|
|
366
|
+
expect(res.status).toBe(403);
|
|
367
|
+
});
|
|
368
|
+
|
|
369
|
+
it("returns 500 when authenticateRequest throws", async () => {
|
|
370
|
+
mockAuthenticateRequest.mockRejectedValue(new Error("DB crashed"));
|
|
371
|
+
|
|
372
|
+
const res = await app.fetch(adminRequest("/api/v1/admin/overview"));
|
|
373
|
+
expect(res.status).toBe(500);
|
|
374
|
+
const body = (await res.json()) as Record<string, unknown>;
|
|
375
|
+
expect(body.error).toBe("auth_error");
|
|
376
|
+
});
|
|
377
|
+
|
|
378
|
+
it("returns 429 when rate limited", async () => {
|
|
379
|
+
mockAuthenticateRequest.mockResolvedValue({
|
|
380
|
+
authenticated: true,
|
|
381
|
+
mode: "simple-key",
|
|
382
|
+
user: { id: "admin-1", mode: "simple-key", label: "Admin", role: "admin" },
|
|
383
|
+
});
|
|
384
|
+
mockCheckRateLimit.mockReturnValue({ allowed: false, retryAfterMs: 30000 });
|
|
385
|
+
|
|
386
|
+
const res = await app.fetch(adminRequest("/api/v1/admin/overview"));
|
|
387
|
+
expect(res.status).toBe(429);
|
|
388
|
+
expect(res.headers.get("Retry-After")).toBe("30");
|
|
389
|
+
const body = (await res.json()) as Record<string, unknown>;
|
|
390
|
+
expect(body.error).toBe("rate_limited");
|
|
391
|
+
});
|
|
392
|
+
|
|
393
|
+
it("enforces admin role on POST endpoints too", async () => {
|
|
394
|
+
mockAuthenticateRequest.mockResolvedValue({
|
|
395
|
+
authenticated: true,
|
|
396
|
+
mode: "simple-key",
|
|
397
|
+
user: { id: "user-1", mode: "simple-key", label: "Analyst", role: "analyst" },
|
|
398
|
+
});
|
|
399
|
+
|
|
400
|
+
const res = await app.fetch(adminRequest("/api/v1/admin/connections/default/test", "POST"));
|
|
401
|
+
expect(res.status).toBe(403);
|
|
402
|
+
});
|
|
403
|
+
});
|
|
404
|
+
|
|
405
|
+
describe("GET /api/v1/admin/overview", () => {
|
|
406
|
+
beforeEach(() => {
|
|
407
|
+
mockAuthenticateRequest.mockReset();
|
|
408
|
+
setAdmin();
|
|
409
|
+
});
|
|
410
|
+
|
|
411
|
+
it("returns overview data with correct shape", async () => {
|
|
412
|
+
const res = await app.fetch(adminRequest("/api/v1/admin/overview"));
|
|
413
|
+
expect(res.status).toBe(200);
|
|
414
|
+
|
|
415
|
+
const body = (await res.json()) as Record<string, unknown>;
|
|
416
|
+
expect(body.connections).toBe(1);
|
|
417
|
+
// 2 entities: companies (default) + orders (warehouse)
|
|
418
|
+
expect(body.entities).toBe(2);
|
|
419
|
+
expect(body.metrics).toBe(1);
|
|
420
|
+
expect(body.glossaryTerms).toBe(2);
|
|
421
|
+
expect(body.plugins).toBe(1);
|
|
422
|
+
expect(Array.isArray(body.pluginHealth)).toBe(true);
|
|
423
|
+
});
|
|
424
|
+
});
|
|
425
|
+
|
|
426
|
+
describe("GET /api/v1/admin/semantic/entities", () => {
|
|
427
|
+
beforeEach(() => {
|
|
428
|
+
mockAuthenticateRequest.mockReset();
|
|
429
|
+
setAdmin();
|
|
430
|
+
});
|
|
431
|
+
|
|
432
|
+
it("lists entities from default and per-source directories", async () => {
|
|
433
|
+
const res = await app.fetch(adminRequest("/api/v1/admin/semantic/entities"));
|
|
434
|
+
expect(res.status).toBe(200);
|
|
435
|
+
|
|
436
|
+
const body = (await res.json()) as { entities: Array<Record<string, unknown>> };
|
|
437
|
+
expect(body.entities.length).toBe(2);
|
|
438
|
+
|
|
439
|
+
const companies = body.entities.find((e) => e.table === "companies");
|
|
440
|
+
expect(companies).toBeDefined();
|
|
441
|
+
expect(companies!.columnCount).toBe(3);
|
|
442
|
+
expect(companies!.joinCount).toBe(1);
|
|
443
|
+
expect(companies!.measureCount).toBe(1);
|
|
444
|
+
expect(companies!.source).toBe("default");
|
|
445
|
+
|
|
446
|
+
const orders = body.entities.find((e) => e.table === "orders");
|
|
447
|
+
expect(orders).toBeDefined();
|
|
448
|
+
expect(orders!.source).toBe("warehouse");
|
|
449
|
+
expect(orders!.connection).toBe("warehouse");
|
|
450
|
+
});
|
|
451
|
+
});
|
|
452
|
+
|
|
453
|
+
describe("GET /api/v1/admin/semantic/entities/:name", () => {
|
|
454
|
+
beforeEach(() => {
|
|
455
|
+
mockAuthenticateRequest.mockReset();
|
|
456
|
+
setAdmin();
|
|
457
|
+
});
|
|
458
|
+
|
|
459
|
+
it("returns full entity detail", async () => {
|
|
460
|
+
const res = await app.fetch(adminRequest("/api/v1/admin/semantic/entities/companies"));
|
|
461
|
+
expect(res.status).toBe(200);
|
|
462
|
+
|
|
463
|
+
const body = (await res.json()) as { entity: Record<string, unknown> };
|
|
464
|
+
expect(body.entity.table).toBe("companies");
|
|
465
|
+
expect(body.entity.description).toBeDefined();
|
|
466
|
+
expect(body.entity.dimensions).toBeDefined();
|
|
467
|
+
});
|
|
468
|
+
|
|
469
|
+
it("returns 404 for non-existent entity", async () => {
|
|
470
|
+
const res = await app.fetch(adminRequest("/api/v1/admin/semantic/entities/nonexistent"));
|
|
471
|
+
expect(res.status).toBe(404);
|
|
472
|
+
});
|
|
473
|
+
|
|
474
|
+
it("returns 400 for path traversal attempts", async () => {
|
|
475
|
+
const traversalNames = [
|
|
476
|
+
"../../etc/passwd",
|
|
477
|
+
"..%2F..%2Fetc%2Fpasswd",
|
|
478
|
+
"../.env",
|
|
479
|
+
"foo/bar",
|
|
480
|
+
"foo\\bar",
|
|
481
|
+
];
|
|
482
|
+
for (const name of traversalNames) {
|
|
483
|
+
const res = await app.fetch(adminRequest(`/api/v1/admin/semantic/entities/${encodeURIComponent(name)}`));
|
|
484
|
+
expect(res.status).toBe(400);
|
|
485
|
+
}
|
|
486
|
+
});
|
|
487
|
+
|
|
488
|
+
it("finds entities in per-source subdirectories", async () => {
|
|
489
|
+
const res = await app.fetch(adminRequest("/api/v1/admin/semantic/entities/orders"));
|
|
490
|
+
expect(res.status).toBe(200);
|
|
491
|
+
|
|
492
|
+
const body = (await res.json()) as { entity: Record<string, unknown> };
|
|
493
|
+
expect(body.entity.table).toBe("orders");
|
|
494
|
+
});
|
|
495
|
+
});
|
|
496
|
+
|
|
497
|
+
describe("GET /api/v1/admin/semantic/metrics", () => {
|
|
498
|
+
beforeEach(() => {
|
|
499
|
+
mockAuthenticateRequest.mockReset();
|
|
500
|
+
setAdmin();
|
|
501
|
+
});
|
|
502
|
+
|
|
503
|
+
it("lists metrics", async () => {
|
|
504
|
+
const res = await app.fetch(adminRequest("/api/v1/admin/semantic/metrics"));
|
|
505
|
+
expect(res.status).toBe(200);
|
|
506
|
+
|
|
507
|
+
const body = (await res.json()) as { metrics: unknown[] };
|
|
508
|
+
expect(body.metrics.length).toBe(1);
|
|
509
|
+
});
|
|
510
|
+
});
|
|
511
|
+
|
|
512
|
+
describe("GET /api/v1/admin/semantic/glossary", () => {
|
|
513
|
+
beforeEach(() => {
|
|
514
|
+
mockAuthenticateRequest.mockReset();
|
|
515
|
+
setAdmin();
|
|
516
|
+
});
|
|
517
|
+
|
|
518
|
+
it("returns glossary data", async () => {
|
|
519
|
+
const res = await app.fetch(adminRequest("/api/v1/admin/semantic/glossary"));
|
|
520
|
+
expect(res.status).toBe(200);
|
|
521
|
+
|
|
522
|
+
const body = (await res.json()) as { glossary: unknown[] };
|
|
523
|
+
expect(body.glossary.length).toBeGreaterThan(0);
|
|
524
|
+
});
|
|
525
|
+
});
|
|
526
|
+
|
|
527
|
+
describe("GET /api/v1/admin/semantic/catalog", () => {
|
|
528
|
+
beforeEach(() => {
|
|
529
|
+
mockAuthenticateRequest.mockReset();
|
|
530
|
+
setAdmin();
|
|
531
|
+
});
|
|
532
|
+
|
|
533
|
+
it("returns catalog data", async () => {
|
|
534
|
+
const res = await app.fetch(adminRequest("/api/v1/admin/semantic/catalog"));
|
|
535
|
+
expect(res.status).toBe(200);
|
|
536
|
+
|
|
537
|
+
const body = (await res.json()) as { catalog: Record<string, unknown> };
|
|
538
|
+
expect(body.catalog).toBeDefined();
|
|
539
|
+
expect(body.catalog.name).toBe("Test Catalog");
|
|
540
|
+
});
|
|
541
|
+
|
|
542
|
+
it("returns null when catalog.yml does not exist", async () => {
|
|
543
|
+
// Temporarily rename the catalog file
|
|
544
|
+
const catalogPath = path.join(tmpRoot, "catalog.yml");
|
|
545
|
+
const tempPath = path.join(tmpRoot, "catalog.yml.bak");
|
|
546
|
+
fs.renameSync(catalogPath, tempPath);
|
|
547
|
+
|
|
548
|
+
try {
|
|
549
|
+
const res = await app.fetch(adminRequest("/api/v1/admin/semantic/catalog"));
|
|
550
|
+
expect(res.status).toBe(200);
|
|
551
|
+
const body = (await res.json()) as { catalog: unknown };
|
|
552
|
+
expect(body.catalog).toBeNull();
|
|
553
|
+
} finally {
|
|
554
|
+
fs.renameSync(tempPath, catalogPath);
|
|
555
|
+
}
|
|
556
|
+
});
|
|
557
|
+
});
|
|
558
|
+
|
|
559
|
+
describe("GET /api/v1/admin/semantic/stats", () => {
|
|
560
|
+
beforeEach(() => {
|
|
561
|
+
mockAuthenticateRequest.mockReset();
|
|
562
|
+
setAdmin();
|
|
563
|
+
});
|
|
564
|
+
|
|
565
|
+
it("returns aggregate stats including multi-source entities", async () => {
|
|
566
|
+
const res = await app.fetch(adminRequest("/api/v1/admin/semantic/stats"));
|
|
567
|
+
expect(res.status).toBe(200);
|
|
568
|
+
|
|
569
|
+
const body = (await res.json()) as Record<string, unknown>;
|
|
570
|
+
// 2 entities: companies (3 cols) + orders (2 cols) = 5 total columns
|
|
571
|
+
expect(body.totalEntities).toBe(2);
|
|
572
|
+
expect(body.totalColumns).toBe(5);
|
|
573
|
+
expect(body.totalJoins).toBe(1);
|
|
574
|
+
expect(body.totalMeasures).toBe(1);
|
|
575
|
+
expect(body.coverageGaps).toBeDefined();
|
|
576
|
+
});
|
|
577
|
+
});
|
|
578
|
+
|
|
579
|
+
describe("GET /api/v1/admin/connections", () => {
|
|
580
|
+
beforeEach(() => {
|
|
581
|
+
mockAuthenticateRequest.mockReset();
|
|
582
|
+
setAdmin();
|
|
583
|
+
});
|
|
584
|
+
|
|
585
|
+
it("lists connections", async () => {
|
|
586
|
+
const res = await app.fetch(adminRequest("/api/v1/admin/connections"));
|
|
587
|
+
expect(res.status).toBe(200);
|
|
588
|
+
|
|
589
|
+
const body = (await res.json()) as { connections: unknown[] };
|
|
590
|
+
expect(body.connections.length).toBe(1);
|
|
591
|
+
});
|
|
592
|
+
});
|
|
593
|
+
|
|
594
|
+
describe("POST /api/v1/admin/connections/:id/test", () => {
|
|
595
|
+
beforeEach(() => {
|
|
596
|
+
mockAuthenticateRequest.mockReset();
|
|
597
|
+
setAdmin();
|
|
598
|
+
mockHealthCheck.mockReset();
|
|
599
|
+
mockHealthCheck.mockResolvedValue({
|
|
600
|
+
status: "healthy",
|
|
601
|
+
latencyMs: 5,
|
|
602
|
+
checkedAt: new Date(),
|
|
603
|
+
});
|
|
604
|
+
});
|
|
605
|
+
|
|
606
|
+
it("returns health check result for existing connection", async () => {
|
|
607
|
+
const res = await app.fetch(adminRequest("/api/v1/admin/connections/default/test", "POST"));
|
|
608
|
+
expect(res.status).toBe(200);
|
|
609
|
+
|
|
610
|
+
const body = (await res.json()) as Record<string, unknown>;
|
|
611
|
+
expect(body.status).toBe("healthy");
|
|
612
|
+
});
|
|
613
|
+
|
|
614
|
+
it("returns 404 for non-existent connection", async () => {
|
|
615
|
+
const res = await app.fetch(adminRequest("/api/v1/admin/connections/nonexistent/test", "POST"));
|
|
616
|
+
expect(res.status).toBe(404);
|
|
617
|
+
});
|
|
618
|
+
|
|
619
|
+
it("returns 500 when health check throws", async () => {
|
|
620
|
+
mockHealthCheck.mockRejectedValue(new Error("Connection timed out"));
|
|
621
|
+
|
|
622
|
+
const res = await app.fetch(adminRequest("/api/v1/admin/connections/default/test", "POST"));
|
|
623
|
+
expect(res.status).toBe(500);
|
|
624
|
+
const body = (await res.json()) as Record<string, unknown>;
|
|
625
|
+
expect(body.error).toBe("internal_error");
|
|
626
|
+
});
|
|
627
|
+
});
|
|
628
|
+
|
|
629
|
+
describe("GET /api/v1/admin/audit", () => {
|
|
630
|
+
beforeEach(() => {
|
|
631
|
+
mockAuthenticateRequest.mockReset();
|
|
632
|
+
setAdmin();
|
|
633
|
+
mockHasInternalDB = true;
|
|
634
|
+
mockInternalQuery.mockReset();
|
|
635
|
+
});
|
|
636
|
+
|
|
637
|
+
it("returns 404 when no internal DB (after auth)", async () => {
|
|
638
|
+
mockHasInternalDB = false;
|
|
639
|
+
|
|
640
|
+
const res = await app.fetch(adminRequest("/api/v1/admin/audit"));
|
|
641
|
+
expect(res.status).toBe(404);
|
|
642
|
+
});
|
|
643
|
+
|
|
644
|
+
it("checks auth before hasInternalDB (returns 401 not 404 for unauth)", async () => {
|
|
645
|
+
mockHasInternalDB = false;
|
|
646
|
+
mockAuthenticateRequest.mockResolvedValue({
|
|
647
|
+
authenticated: false,
|
|
648
|
+
mode: "simple-key",
|
|
649
|
+
status: 401,
|
|
650
|
+
error: "Invalid API key",
|
|
651
|
+
});
|
|
652
|
+
|
|
653
|
+
const res = await app.fetch(adminRequest("/api/v1/admin/audit"));
|
|
654
|
+
expect(res.status).toBe(401);
|
|
655
|
+
});
|
|
656
|
+
|
|
657
|
+
it("returns paginated audit log", async () => {
|
|
658
|
+
let callCount = 0;
|
|
659
|
+
mockInternalQuery.mockImplementation(() => {
|
|
660
|
+
callCount++;
|
|
661
|
+
if (callCount === 1) return Promise.resolve([{ count: "5" }]);
|
|
662
|
+
return Promise.resolve([
|
|
663
|
+
{ id: "1", timestamp: "2026-01-01", user_id: "u1", success: true, sql: "SELECT 1" },
|
|
664
|
+
]);
|
|
665
|
+
});
|
|
666
|
+
|
|
667
|
+
const res = await app.fetch(adminRequest("/api/v1/admin/audit?limit=10&offset=0"));
|
|
668
|
+
expect(res.status).toBe(200);
|
|
669
|
+
|
|
670
|
+
const body = (await res.json()) as Record<string, unknown>;
|
|
671
|
+
expect(body.total).toBe(5);
|
|
672
|
+
expect(body.limit).toBe(10);
|
|
673
|
+
expect(body.offset).toBe(0);
|
|
674
|
+
expect(Array.isArray(body.rows)).toBe(true);
|
|
675
|
+
});
|
|
676
|
+
|
|
677
|
+
it("supports all filter query params including dates", async () => {
|
|
678
|
+
let capturedSql = "";
|
|
679
|
+
let capturedParams: unknown[] = [];
|
|
680
|
+
let callCount = 0;
|
|
681
|
+
mockInternalQuery.mockImplementation((sql: string, params?: unknown[]) => {
|
|
682
|
+
callCount++;
|
|
683
|
+
if (callCount === 1) {
|
|
684
|
+
capturedSql = sql;
|
|
685
|
+
capturedParams = params ?? [];
|
|
686
|
+
return Promise.resolve([{ count: "0" }]);
|
|
687
|
+
}
|
|
688
|
+
return Promise.resolve([]);
|
|
689
|
+
});
|
|
690
|
+
|
|
691
|
+
await app.fetch(adminRequest("/api/v1/admin/audit?user=test-user&success=true&from=2026-01-01&to=2026-03-01"));
|
|
692
|
+
|
|
693
|
+
expect(capturedSql).toContain("user_id = $1");
|
|
694
|
+
expect(capturedSql).toContain("success = $2");
|
|
695
|
+
expect(capturedSql).toContain("timestamp >= $3");
|
|
696
|
+
expect(capturedSql).toContain("timestamp <= $4");
|
|
697
|
+
expect(capturedParams).toContain("test-user");
|
|
698
|
+
expect(capturedParams).toContain(true);
|
|
699
|
+
expect(capturedParams).toContain("2026-01-01");
|
|
700
|
+
expect(capturedParams).toContain("2026-03-01");
|
|
701
|
+
});
|
|
702
|
+
|
|
703
|
+
it("returns 400 for invalid date format", async () => {
|
|
704
|
+
const res = await app.fetch(adminRequest("/api/v1/admin/audit?from=not-a-date"));
|
|
705
|
+
expect(res.status).toBe(400);
|
|
706
|
+
const body = (await res.json()) as Record<string, unknown>;
|
|
707
|
+
expect(body.error).toBe("invalid_request");
|
|
708
|
+
});
|
|
709
|
+
|
|
710
|
+
it("returns 500 when internalQuery throws", async () => {
|
|
711
|
+
mockInternalQuery.mockRejectedValue(new Error("DB connection lost"));
|
|
712
|
+
|
|
713
|
+
const res = await app.fetch(adminRequest("/api/v1/admin/audit"));
|
|
714
|
+
expect(res.status).toBe(500);
|
|
715
|
+
const body = (await res.json()) as Record<string, unknown>;
|
|
716
|
+
expect(body.error).toBe("internal_error");
|
|
717
|
+
});
|
|
718
|
+
});
|
|
719
|
+
|
|
720
|
+
describe("GET /api/v1/admin/audit/stats", () => {
|
|
721
|
+
beforeEach(() => {
|
|
722
|
+
mockAuthenticateRequest.mockReset();
|
|
723
|
+
setAdmin();
|
|
724
|
+
mockHasInternalDB = true;
|
|
725
|
+
mockInternalQuery.mockReset();
|
|
726
|
+
});
|
|
727
|
+
|
|
728
|
+
it("returns 404 when no internal DB", async () => {
|
|
729
|
+
mockHasInternalDB = false;
|
|
730
|
+
|
|
731
|
+
const res = await app.fetch(adminRequest("/api/v1/admin/audit/stats"));
|
|
732
|
+
expect(res.status).toBe(404);
|
|
733
|
+
});
|
|
734
|
+
|
|
735
|
+
it("returns audit stats", async () => {
|
|
736
|
+
let callCount = 0;
|
|
737
|
+
mockInternalQuery.mockImplementation(() => {
|
|
738
|
+
callCount++;
|
|
739
|
+
if (callCount === 1) return Promise.resolve([{ total: "100", errors: "5" }]);
|
|
740
|
+
return Promise.resolve([
|
|
741
|
+
{ day: "2026-03-01", count: "20" },
|
|
742
|
+
{ day: "2026-02-28", count: "15" },
|
|
743
|
+
]);
|
|
744
|
+
});
|
|
745
|
+
|
|
746
|
+
const res = await app.fetch(adminRequest("/api/v1/admin/audit/stats"));
|
|
747
|
+
expect(res.status).toBe(200);
|
|
748
|
+
|
|
749
|
+
const body = (await res.json()) as Record<string, unknown>;
|
|
750
|
+
expect(body.totalQueries).toBe(100);
|
|
751
|
+
expect(body.totalErrors).toBe(5);
|
|
752
|
+
expect(body.errorRate).toBe(0.05);
|
|
753
|
+
expect(Array.isArray(body.queriesPerDay)).toBe(true);
|
|
754
|
+
});
|
|
755
|
+
|
|
756
|
+
it("returns 500 when internalQuery throws", async () => {
|
|
757
|
+
mockInternalQuery.mockRejectedValue(new Error("DB timeout"));
|
|
758
|
+
|
|
759
|
+
const res = await app.fetch(adminRequest("/api/v1/admin/audit/stats"));
|
|
760
|
+
expect(res.status).toBe(500);
|
|
761
|
+
});
|
|
762
|
+
});
|
|
763
|
+
|
|
764
|
+
describe("GET /api/v1/admin/plugins", () => {
|
|
765
|
+
beforeEach(() => {
|
|
766
|
+
mockAuthenticateRequest.mockReset();
|
|
767
|
+
setAdmin();
|
|
768
|
+
});
|
|
769
|
+
|
|
770
|
+
it("lists plugins", async () => {
|
|
771
|
+
const res = await app.fetch(adminRequest("/api/v1/admin/plugins"));
|
|
772
|
+
expect(res.status).toBe(200);
|
|
773
|
+
|
|
774
|
+
const body = (await res.json()) as { plugins: unknown[] };
|
|
775
|
+
expect(body.plugins.length).toBe(1);
|
|
776
|
+
});
|
|
777
|
+
});
|
|
778
|
+
|
|
779
|
+
describe("POST /api/v1/admin/plugins/:id/health", () => {
|
|
780
|
+
beforeEach(() => {
|
|
781
|
+
mockAuthenticateRequest.mockReset();
|
|
782
|
+
setAdmin();
|
|
783
|
+
mockPluginHealthCheck.mockReset();
|
|
784
|
+
mockPluginHealthCheck.mockResolvedValue({ healthy: true, message: "OK" });
|
|
785
|
+
});
|
|
786
|
+
|
|
787
|
+
it("returns health check result for existing plugin", async () => {
|
|
788
|
+
const res = await app.fetch(adminRequest("/api/v1/admin/plugins/test-plugin/health", "POST"));
|
|
789
|
+
expect(res.status).toBe(200);
|
|
790
|
+
|
|
791
|
+
const body = (await res.json()) as Record<string, unknown>;
|
|
792
|
+
expect(body.healthy).toBe(true);
|
|
793
|
+
});
|
|
794
|
+
|
|
795
|
+
it("returns 404 for non-existent plugin", async () => {
|
|
796
|
+
const res = await app.fetch(adminRequest("/api/v1/admin/plugins/nonexistent/health", "POST"));
|
|
797
|
+
expect(res.status).toBe(404);
|
|
798
|
+
});
|
|
799
|
+
|
|
800
|
+
it("returns 500 when healthCheck throws", async () => {
|
|
801
|
+
mockPluginHealthCheck.mockRejectedValue(new Error("Plugin crashed"));
|
|
802
|
+
|
|
803
|
+
const res = await app.fetch(adminRequest("/api/v1/admin/plugins/test-plugin/health", "POST"));
|
|
804
|
+
expect(res.status).toBe(500);
|
|
805
|
+
const body = (await res.json()) as Record<string, unknown>;
|
|
806
|
+
expect(body.healthy).toBe(false);
|
|
807
|
+
// Should not leak raw error message
|
|
808
|
+
expect(body.message).toBe("Plugin health check failed unexpectedly.");
|
|
809
|
+
});
|
|
810
|
+
|
|
811
|
+
it("returns fallback for plugin without healthCheck method", async () => {
|
|
812
|
+
const res = await app.fetch(adminRequest("/api/v1/admin/plugins/no-health-plugin/health", "POST"));
|
|
813
|
+
expect(res.status).toBe(200);
|
|
814
|
+
|
|
815
|
+
const body = (await res.json()) as Record<string, unknown>;
|
|
816
|
+
expect(body.healthy).toBe(true);
|
|
817
|
+
expect(body.message).toBe("Plugin does not implement healthCheck.");
|
|
818
|
+
expect(body.status).toBe("registered");
|
|
819
|
+
});
|
|
820
|
+
});
|