@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,601 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unit tests for the scheduled tasks REST routes.
|
|
3
|
+
*
|
|
4
|
+
* Uses mock.module() pattern from actions.test.ts.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import {
|
|
8
|
+
describe,
|
|
9
|
+
it,
|
|
10
|
+
expect,
|
|
11
|
+
beforeEach,
|
|
12
|
+
afterEach,
|
|
13
|
+
mock,
|
|
14
|
+
type Mock,
|
|
15
|
+
} from "bun:test";
|
|
16
|
+
import type { AuthResult } from "@atlas/api/lib/auth/types";
|
|
17
|
+
|
|
18
|
+
// --- Auth mocks ---
|
|
19
|
+
|
|
20
|
+
const mockAuthenticateRequest: Mock<
|
|
21
|
+
(req: Request) => Promise<AuthResult>
|
|
22
|
+
> = mock(() =>
|
|
23
|
+
Promise.resolve({
|
|
24
|
+
authenticated: true as const,
|
|
25
|
+
mode: "simple-key" as const,
|
|
26
|
+
user: { id: "u1", label: "test@test.com", mode: "simple-key" as const },
|
|
27
|
+
}),
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
const mockCheckRateLimit: Mock<
|
|
31
|
+
(key: string) => { allowed: boolean; retryAfterMs?: number }
|
|
32
|
+
> = mock(() => ({ allowed: true }));
|
|
33
|
+
|
|
34
|
+
const mockGetClientIP: Mock<(req: Request) => string | null> = mock(
|
|
35
|
+
() => null,
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
mock.module("@atlas/api/lib/auth/middleware", () => ({
|
|
39
|
+
authenticateRequest: mockAuthenticateRequest,
|
|
40
|
+
checkRateLimit: mockCheckRateLimit,
|
|
41
|
+
getClientIP: mockGetClientIP,
|
|
42
|
+
}));
|
|
43
|
+
|
|
44
|
+
// --- CRUD mocks ---
|
|
45
|
+
|
|
46
|
+
const mockCreateScheduledTask = mock((): Promise<unknown> =>
|
|
47
|
+
Promise.resolve({ ok: true, data: { id: "task-123", name: "Test" } }),
|
|
48
|
+
);
|
|
49
|
+
const mockGetScheduledTask = mock((): Promise<unknown> =>
|
|
50
|
+
Promise.resolve({ ok: true, data: { id: "task-123", name: "Test" } }),
|
|
51
|
+
);
|
|
52
|
+
const mockListScheduledTasks = mock((): Promise<unknown> =>
|
|
53
|
+
Promise.resolve({ tasks: [], total: 0 }),
|
|
54
|
+
);
|
|
55
|
+
const mockUpdateScheduledTask = mock((): Promise<unknown> =>
|
|
56
|
+
Promise.resolve({ ok: true }),
|
|
57
|
+
);
|
|
58
|
+
const mockDeleteScheduledTask = mock((): Promise<unknown> =>
|
|
59
|
+
Promise.resolve({ ok: true }),
|
|
60
|
+
);
|
|
61
|
+
const mockListTaskRuns = mock((): Promise<unknown> => Promise.resolve([]));
|
|
62
|
+
const mockValidateCronExpression = mock((): unknown => ({ valid: true }));
|
|
63
|
+
|
|
64
|
+
mock.module("@atlas/api/lib/scheduled-tasks", () => ({
|
|
65
|
+
createScheduledTask: mockCreateScheduledTask,
|
|
66
|
+
getScheduledTask: mockGetScheduledTask,
|
|
67
|
+
listScheduledTasks: mockListScheduledTasks,
|
|
68
|
+
updateScheduledTask: mockUpdateScheduledTask,
|
|
69
|
+
deleteScheduledTask: mockDeleteScheduledTask,
|
|
70
|
+
listTaskRuns: mockListTaskRuns,
|
|
71
|
+
validateCronExpression: mockValidateCronExpression,
|
|
72
|
+
}));
|
|
73
|
+
|
|
74
|
+
// --- Other mocks (required by Hono app index.ts) ---
|
|
75
|
+
|
|
76
|
+
mock.module("@atlas/api/lib/agent", () => ({
|
|
77
|
+
runAgent: mock(() =>
|
|
78
|
+
Promise.resolve({
|
|
79
|
+
toUIMessageStreamResponse: () => new Response("stream", { status: 200 }),
|
|
80
|
+
text: Promise.resolve("answer"),
|
|
81
|
+
steps: Promise.resolve([]),
|
|
82
|
+
totalUsage: Promise.resolve({ inputTokens: 0, outputTokens: 0 }),
|
|
83
|
+
}),
|
|
84
|
+
),
|
|
85
|
+
}));
|
|
86
|
+
|
|
87
|
+
mock.module("@atlas/api/lib/conversations", () => ({
|
|
88
|
+
listConversations: mock(() => Promise.resolve({ conversations: [], total: 0 })),
|
|
89
|
+
getConversation: mock(() => Promise.resolve(null)),
|
|
90
|
+
deleteConversation: mock(() => Promise.resolve(false)),
|
|
91
|
+
createConversation: mock(() => Promise.resolve(null)),
|
|
92
|
+
addMessage: mock(() => {}),
|
|
93
|
+
generateTitle: mock(() => "Test title"),
|
|
94
|
+
starConversation: async () => false,
|
|
95
|
+
}));
|
|
96
|
+
|
|
97
|
+
mock.module("@atlas/api/lib/semantic", () => ({
|
|
98
|
+
getWhitelistedTables: () => new Set(),
|
|
99
|
+
_resetWhitelists: () => {},
|
|
100
|
+
}));
|
|
101
|
+
|
|
102
|
+
mock.module("@atlas/api/lib/tools/explore", () => ({
|
|
103
|
+
getExploreBackendType: () => "just-bash",
|
|
104
|
+
getActiveSandboxPluginId: () => null,
|
|
105
|
+
}));
|
|
106
|
+
|
|
107
|
+
mock.module("@atlas/api/lib/auth/detect", () => ({
|
|
108
|
+
detectAuthMode: () => "none",
|
|
109
|
+
resetAuthModeCache: () => {},
|
|
110
|
+
}));
|
|
111
|
+
|
|
112
|
+
mock.module("@atlas/api/lib/startup", () => ({
|
|
113
|
+
validateEnvironment: mock(() => Promise.resolve([])),
|
|
114
|
+
getStartupWarnings: () => [],
|
|
115
|
+
}));
|
|
116
|
+
|
|
117
|
+
const mockRunTick = mock((): Promise<{ tasksFound: number; tasksDispatched: number; tasksCompleted: number; tasksFailed: number; error?: string }> =>
|
|
118
|
+
Promise.resolve({ tasksFound: 0, tasksDispatched: 0, tasksCompleted: 0, tasksFailed: 0 }),
|
|
119
|
+
);
|
|
120
|
+
|
|
121
|
+
mock.module("@atlas/api/lib/scheduler/engine", () => ({
|
|
122
|
+
triggerTask: mock(() => Promise.resolve()),
|
|
123
|
+
runTick: mockRunTick,
|
|
124
|
+
getScheduler: () => ({ start: () => {}, stop: () => {}, isRunning: () => false }),
|
|
125
|
+
_resetScheduler: () => {},
|
|
126
|
+
}));
|
|
127
|
+
|
|
128
|
+
const mockGetConfig = mock(() => ({ scheduler: { backend: "bun" } }));
|
|
129
|
+
mock.module("@atlas/api/lib/config", () => ({
|
|
130
|
+
getConfig: mockGetConfig,
|
|
131
|
+
loadConfig: mock(() => Promise.resolve({})),
|
|
132
|
+
configFromEnv: mock(() => ({})),
|
|
133
|
+
initializeConfig: mock(() => Promise.resolve({})),
|
|
134
|
+
_resetConfig: () => {},
|
|
135
|
+
}));
|
|
136
|
+
|
|
137
|
+
// Enable routes before importing the app
|
|
138
|
+
process.env.ATLAS_SCHEDULER_ENABLED = "true";
|
|
139
|
+
|
|
140
|
+
// Import after mocks
|
|
141
|
+
const { app } = await import("../index");
|
|
142
|
+
|
|
143
|
+
const VALID_ID = "a1b2c3d4-e5f6-7890-abcd-ef1234567890";
|
|
144
|
+
|
|
145
|
+
describe("scheduled-tasks routes", () => {
|
|
146
|
+
const origDatabaseUrl = process.env.DATABASE_URL;
|
|
147
|
+
|
|
148
|
+
beforeEach(() => {
|
|
149
|
+
process.env.DATABASE_URL = "postgresql://test:test@localhost:5432/test";
|
|
150
|
+
mockAuthenticateRequest.mockReset();
|
|
151
|
+
mockAuthenticateRequest.mockResolvedValue({
|
|
152
|
+
authenticated: true as const,
|
|
153
|
+
mode: "simple-key" as const,
|
|
154
|
+
user: { id: "u1", label: "test@test.com", mode: "simple-key" as const },
|
|
155
|
+
});
|
|
156
|
+
mockCheckRateLimit.mockReset();
|
|
157
|
+
mockCheckRateLimit.mockReturnValue({ allowed: true });
|
|
158
|
+
mockGetClientIP.mockReset();
|
|
159
|
+
mockGetClientIP.mockReturnValue(null);
|
|
160
|
+
mockCreateScheduledTask.mockReset();
|
|
161
|
+
mockCreateScheduledTask.mockResolvedValue({ ok: true, data: { id: "task-123", name: "Test" } });
|
|
162
|
+
mockGetScheduledTask.mockReset();
|
|
163
|
+
mockGetScheduledTask.mockResolvedValue({ ok: true, data: { id: VALID_ID, name: "Test" } });
|
|
164
|
+
mockListScheduledTasks.mockReset();
|
|
165
|
+
mockListScheduledTasks.mockResolvedValue({ tasks: [], total: 0 });
|
|
166
|
+
mockUpdateScheduledTask.mockReset();
|
|
167
|
+
mockUpdateScheduledTask.mockResolvedValue({ ok: true });
|
|
168
|
+
mockDeleteScheduledTask.mockReset();
|
|
169
|
+
mockDeleteScheduledTask.mockResolvedValue({ ok: true });
|
|
170
|
+
mockListTaskRuns.mockReset();
|
|
171
|
+
mockListTaskRuns.mockResolvedValue([]);
|
|
172
|
+
mockValidateCronExpression.mockReset();
|
|
173
|
+
mockValidateCronExpression.mockReturnValue({ valid: true });
|
|
174
|
+
mockRunTick.mockReset();
|
|
175
|
+
mockRunTick.mockResolvedValue({ tasksFound: 0, tasksDispatched: 0, tasksCompleted: 0, tasksFailed: 0 });
|
|
176
|
+
mockGetConfig.mockReset();
|
|
177
|
+
mockGetConfig.mockReturnValue({ scheduler: { backend: "bun" } });
|
|
178
|
+
delete process.env.CRON_SECRET;
|
|
179
|
+
delete process.env.ATLAS_SCHEDULER_SECRET;
|
|
180
|
+
delete process.env.NODE_ENV;
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
afterEach(() => {
|
|
184
|
+
if (origDatabaseUrl !== undefined) process.env.DATABASE_URL = origDatabaseUrl;
|
|
185
|
+
else delete process.env.DATABASE_URL;
|
|
186
|
+
delete process.env.CRON_SECRET;
|
|
187
|
+
delete process.env.ATLAS_SCHEDULER_SECRET;
|
|
188
|
+
delete process.env.NODE_ENV;
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
// -------------------------------------------------------------------------
|
|
192
|
+
// GET /api/v1/scheduled-tasks
|
|
193
|
+
// -------------------------------------------------------------------------
|
|
194
|
+
|
|
195
|
+
describe("GET /api/v1/scheduled-tasks", () => {
|
|
196
|
+
it("returns 200 with task list", async () => {
|
|
197
|
+
const response = await app.fetch(
|
|
198
|
+
new Request("http://localhost/api/v1/scheduled-tasks"),
|
|
199
|
+
);
|
|
200
|
+
expect(response.status).toBe(200);
|
|
201
|
+
const body = (await response.json()) as { tasks: unknown[]; total: number };
|
|
202
|
+
expect(body.tasks).toEqual([]);
|
|
203
|
+
expect(body.total).toBe(0);
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
it("returns 404 when no internal DB", async () => {
|
|
207
|
+
delete process.env.DATABASE_URL;
|
|
208
|
+
const response = await app.fetch(
|
|
209
|
+
new Request("http://localhost/api/v1/scheduled-tasks"),
|
|
210
|
+
);
|
|
211
|
+
expect(response.status).toBe(404);
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
it("returns 401 when unauthenticated", async () => {
|
|
215
|
+
mockAuthenticateRequest.mockResolvedValueOnce({
|
|
216
|
+
authenticated: false as const,
|
|
217
|
+
mode: "simple-key" as const,
|
|
218
|
+
status: 401 as const,
|
|
219
|
+
error: "API key required",
|
|
220
|
+
});
|
|
221
|
+
const response = await app.fetch(
|
|
222
|
+
new Request("http://localhost/api/v1/scheduled-tasks"),
|
|
223
|
+
);
|
|
224
|
+
expect(response.status).toBe(401);
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
it("returns 429 when rate limited", async () => {
|
|
228
|
+
mockCheckRateLimit.mockReturnValueOnce({
|
|
229
|
+
allowed: false,
|
|
230
|
+
retryAfterMs: 30000,
|
|
231
|
+
});
|
|
232
|
+
const response = await app.fetch(
|
|
233
|
+
new Request("http://localhost/api/v1/scheduled-tasks"),
|
|
234
|
+
);
|
|
235
|
+
expect(response.status).toBe(429);
|
|
236
|
+
});
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
// -------------------------------------------------------------------------
|
|
240
|
+
// POST /api/v1/scheduled-tasks
|
|
241
|
+
// -------------------------------------------------------------------------
|
|
242
|
+
|
|
243
|
+
describe("POST /api/v1/scheduled-tasks", () => {
|
|
244
|
+
it("returns 201 on valid create", async () => {
|
|
245
|
+
const response = await app.fetch(
|
|
246
|
+
new Request("http://localhost/api/v1/scheduled-tasks", {
|
|
247
|
+
method: "POST",
|
|
248
|
+
headers: { "Content-Type": "application/json" },
|
|
249
|
+
body: JSON.stringify({
|
|
250
|
+
name: "Daily Revenue",
|
|
251
|
+
question: "What was yesterday's revenue?",
|
|
252
|
+
cronExpression: "0 9 * * 1",
|
|
253
|
+
deliveryChannel: "email",
|
|
254
|
+
recipients: [{ type: "email", address: "test@test.com" }],
|
|
255
|
+
}),
|
|
256
|
+
}),
|
|
257
|
+
);
|
|
258
|
+
expect(response.status).toBe(201);
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
it("returns 400 for missing name", async () => {
|
|
262
|
+
const response = await app.fetch(
|
|
263
|
+
new Request("http://localhost/api/v1/scheduled-tasks", {
|
|
264
|
+
method: "POST",
|
|
265
|
+
headers: { "Content-Type": "application/json" },
|
|
266
|
+
body: JSON.stringify({
|
|
267
|
+
question: "What?",
|
|
268
|
+
cronExpression: "0 9 * * 1",
|
|
269
|
+
}),
|
|
270
|
+
}),
|
|
271
|
+
);
|
|
272
|
+
expect(response.status).toBe(400);
|
|
273
|
+
});
|
|
274
|
+
|
|
275
|
+
it("returns 400 for invalid JSON", async () => {
|
|
276
|
+
const response = await app.fetch(
|
|
277
|
+
new Request("http://localhost/api/v1/scheduled-tasks", {
|
|
278
|
+
method: "POST",
|
|
279
|
+
headers: { "Content-Type": "application/json" },
|
|
280
|
+
body: "not json{",
|
|
281
|
+
}),
|
|
282
|
+
);
|
|
283
|
+
expect(response.status).toBe(400);
|
|
284
|
+
});
|
|
285
|
+
|
|
286
|
+
it("returns 400 for invalid cron expression", async () => {
|
|
287
|
+
mockValidateCronExpression.mockReturnValueOnce({ valid: false, error: "Bad cron" });
|
|
288
|
+
const response = await app.fetch(
|
|
289
|
+
new Request("http://localhost/api/v1/scheduled-tasks", {
|
|
290
|
+
method: "POST",
|
|
291
|
+
headers: { "Content-Type": "application/json" },
|
|
292
|
+
body: JSON.stringify({
|
|
293
|
+
name: "Test",
|
|
294
|
+
question: "Q?",
|
|
295
|
+
cronExpression: "bad",
|
|
296
|
+
}),
|
|
297
|
+
}),
|
|
298
|
+
);
|
|
299
|
+
expect(response.status).toBe(400);
|
|
300
|
+
const body = (await response.json()) as Record<string, unknown>;
|
|
301
|
+
expect(body.message).toContain("Invalid cron expression");
|
|
302
|
+
});
|
|
303
|
+
|
|
304
|
+
it("returns 404 when no internal DB", async () => {
|
|
305
|
+
delete process.env.DATABASE_URL;
|
|
306
|
+
const response = await app.fetch(
|
|
307
|
+
new Request("http://localhost/api/v1/scheduled-tasks", {
|
|
308
|
+
method: "POST",
|
|
309
|
+
headers: { "Content-Type": "application/json" },
|
|
310
|
+
body: JSON.stringify({
|
|
311
|
+
name: "Test",
|
|
312
|
+
question: "Q?",
|
|
313
|
+
cronExpression: "0 9 * * 1",
|
|
314
|
+
}),
|
|
315
|
+
}),
|
|
316
|
+
);
|
|
317
|
+
expect(response.status).toBe(404);
|
|
318
|
+
});
|
|
319
|
+
});
|
|
320
|
+
|
|
321
|
+
// -------------------------------------------------------------------------
|
|
322
|
+
// GET /api/v1/scheduled-tasks/:id
|
|
323
|
+
// -------------------------------------------------------------------------
|
|
324
|
+
|
|
325
|
+
describe("GET /api/v1/scheduled-tasks/:id", () => {
|
|
326
|
+
it("returns 200 with task and recent runs", async () => {
|
|
327
|
+
const response = await app.fetch(
|
|
328
|
+
new Request(`http://localhost/api/v1/scheduled-tasks/${VALID_ID}`),
|
|
329
|
+
);
|
|
330
|
+
expect(response.status).toBe(200);
|
|
331
|
+
const body = (await response.json()) as Record<string, unknown>;
|
|
332
|
+
expect(body.id).toBe(VALID_ID);
|
|
333
|
+
expect(body.recentRuns).toBeDefined();
|
|
334
|
+
});
|
|
335
|
+
|
|
336
|
+
it("returns 400 for invalid UUID", async () => {
|
|
337
|
+
const response = await app.fetch(
|
|
338
|
+
new Request("http://localhost/api/v1/scheduled-tasks/not-a-uuid"),
|
|
339
|
+
);
|
|
340
|
+
expect(response.status).toBe(400);
|
|
341
|
+
});
|
|
342
|
+
|
|
343
|
+
it("returns 404 when not found", async () => {
|
|
344
|
+
mockGetScheduledTask.mockResolvedValueOnce({ ok: false, reason: "not_found" });
|
|
345
|
+
const response = await app.fetch(
|
|
346
|
+
new Request(`http://localhost/api/v1/scheduled-tasks/${VALID_ID}`),
|
|
347
|
+
);
|
|
348
|
+
expect(response.status).toBe(404);
|
|
349
|
+
});
|
|
350
|
+
});
|
|
351
|
+
|
|
352
|
+
// -------------------------------------------------------------------------
|
|
353
|
+
// PUT /api/v1/scheduled-tasks/:id
|
|
354
|
+
// -------------------------------------------------------------------------
|
|
355
|
+
|
|
356
|
+
describe("PUT /api/v1/scheduled-tasks/:id", () => {
|
|
357
|
+
it("returns 200 on valid update", async () => {
|
|
358
|
+
const response = await app.fetch(
|
|
359
|
+
new Request(`http://localhost/api/v1/scheduled-tasks/${VALID_ID}`, {
|
|
360
|
+
method: "PUT",
|
|
361
|
+
headers: { "Content-Type": "application/json" },
|
|
362
|
+
body: JSON.stringify({ name: "Updated Name" }),
|
|
363
|
+
}),
|
|
364
|
+
);
|
|
365
|
+
expect(response.status).toBe(200);
|
|
366
|
+
});
|
|
367
|
+
|
|
368
|
+
it("returns 400 for invalid UUID", async () => {
|
|
369
|
+
const response = await app.fetch(
|
|
370
|
+
new Request("http://localhost/api/v1/scheduled-tasks/bad-id", {
|
|
371
|
+
method: "PUT",
|
|
372
|
+
headers: { "Content-Type": "application/json" },
|
|
373
|
+
body: JSON.stringify({ name: "X" }),
|
|
374
|
+
}),
|
|
375
|
+
);
|
|
376
|
+
expect(response.status).toBe(400);
|
|
377
|
+
});
|
|
378
|
+
|
|
379
|
+
it("returns 400 for invalid JSON", async () => {
|
|
380
|
+
const response = await app.fetch(
|
|
381
|
+
new Request(`http://localhost/api/v1/scheduled-tasks/${VALID_ID}`, {
|
|
382
|
+
method: "PUT",
|
|
383
|
+
headers: { "Content-Type": "application/json" },
|
|
384
|
+
body: "not json{",
|
|
385
|
+
}),
|
|
386
|
+
);
|
|
387
|
+
expect(response.status).toBe(400);
|
|
388
|
+
});
|
|
389
|
+
|
|
390
|
+
it("returns 404 when not found", async () => {
|
|
391
|
+
mockUpdateScheduledTask.mockResolvedValueOnce({ ok: false, reason: "not_found" });
|
|
392
|
+
const response = await app.fetch(
|
|
393
|
+
new Request(`http://localhost/api/v1/scheduled-tasks/${VALID_ID}`, {
|
|
394
|
+
method: "PUT",
|
|
395
|
+
headers: { "Content-Type": "application/json" },
|
|
396
|
+
body: JSON.stringify({ name: "Updated" }),
|
|
397
|
+
}),
|
|
398
|
+
);
|
|
399
|
+
expect(response.status).toBe(404);
|
|
400
|
+
});
|
|
401
|
+
});
|
|
402
|
+
|
|
403
|
+
// -------------------------------------------------------------------------
|
|
404
|
+
// DELETE /api/v1/scheduled-tasks/:id
|
|
405
|
+
// -------------------------------------------------------------------------
|
|
406
|
+
|
|
407
|
+
describe("DELETE /api/v1/scheduled-tasks/:id", () => {
|
|
408
|
+
it("returns 204 on success", async () => {
|
|
409
|
+
const response = await app.fetch(
|
|
410
|
+
new Request(`http://localhost/api/v1/scheduled-tasks/${VALID_ID}`, {
|
|
411
|
+
method: "DELETE",
|
|
412
|
+
}),
|
|
413
|
+
);
|
|
414
|
+
expect(response.status).toBe(204);
|
|
415
|
+
});
|
|
416
|
+
|
|
417
|
+
it("returns 400 for invalid UUID", async () => {
|
|
418
|
+
const response = await app.fetch(
|
|
419
|
+
new Request("http://localhost/api/v1/scheduled-tasks/bad-id", {
|
|
420
|
+
method: "DELETE",
|
|
421
|
+
}),
|
|
422
|
+
);
|
|
423
|
+
expect(response.status).toBe(400);
|
|
424
|
+
});
|
|
425
|
+
|
|
426
|
+
it("returns 404 when not found", async () => {
|
|
427
|
+
mockDeleteScheduledTask.mockResolvedValueOnce({ ok: false, reason: "not_found" });
|
|
428
|
+
const response = await app.fetch(
|
|
429
|
+
new Request(`http://localhost/api/v1/scheduled-tasks/${VALID_ID}`, {
|
|
430
|
+
method: "DELETE",
|
|
431
|
+
}),
|
|
432
|
+
);
|
|
433
|
+
expect(response.status).toBe(404);
|
|
434
|
+
});
|
|
435
|
+
});
|
|
436
|
+
|
|
437
|
+
// -------------------------------------------------------------------------
|
|
438
|
+
// POST /api/v1/scheduled-tasks/:id/run
|
|
439
|
+
// -------------------------------------------------------------------------
|
|
440
|
+
|
|
441
|
+
describe("POST /api/v1/scheduled-tasks/:id/run", () => {
|
|
442
|
+
it("returns 200 on successful trigger", async () => {
|
|
443
|
+
const response = await app.fetch(
|
|
444
|
+
new Request(`http://localhost/api/v1/scheduled-tasks/${VALID_ID}/run`, {
|
|
445
|
+
method: "POST",
|
|
446
|
+
}),
|
|
447
|
+
);
|
|
448
|
+
expect(response.status).toBe(200);
|
|
449
|
+
const body = (await response.json()) as Record<string, unknown>;
|
|
450
|
+
expect(body.taskId).toBe(VALID_ID);
|
|
451
|
+
});
|
|
452
|
+
|
|
453
|
+
it("returns 400 for invalid UUID", async () => {
|
|
454
|
+
const response = await app.fetch(
|
|
455
|
+
new Request("http://localhost/api/v1/scheduled-tasks/bad-id/run", {
|
|
456
|
+
method: "POST",
|
|
457
|
+
}),
|
|
458
|
+
);
|
|
459
|
+
expect(response.status).toBe(400);
|
|
460
|
+
});
|
|
461
|
+
|
|
462
|
+
it("returns 404 when task not found", async () => {
|
|
463
|
+
mockGetScheduledTask.mockResolvedValueOnce({ ok: false, reason: "not_found" });
|
|
464
|
+
const response = await app.fetch(
|
|
465
|
+
new Request(`http://localhost/api/v1/scheduled-tasks/${VALID_ID}/run`, {
|
|
466
|
+
method: "POST",
|
|
467
|
+
}),
|
|
468
|
+
);
|
|
469
|
+
expect(response.status).toBe(404);
|
|
470
|
+
});
|
|
471
|
+
});
|
|
472
|
+
|
|
473
|
+
// -------------------------------------------------------------------------
|
|
474
|
+
// GET /api/v1/scheduled-tasks/:id/runs
|
|
475
|
+
// -------------------------------------------------------------------------
|
|
476
|
+
|
|
477
|
+
describe("GET /api/v1/scheduled-tasks/:id/runs", () => {
|
|
478
|
+
it("returns 200 with runs", async () => {
|
|
479
|
+
const response = await app.fetch(
|
|
480
|
+
new Request(`http://localhost/api/v1/scheduled-tasks/${VALID_ID}/runs`),
|
|
481
|
+
);
|
|
482
|
+
expect(response.status).toBe(200);
|
|
483
|
+
const body = (await response.json()) as { runs: unknown[] };
|
|
484
|
+
expect(body.runs).toEqual([]);
|
|
485
|
+
});
|
|
486
|
+
|
|
487
|
+
it("returns 400 for invalid UUID", async () => {
|
|
488
|
+
const response = await app.fetch(
|
|
489
|
+
new Request("http://localhost/api/v1/scheduled-tasks/bad-id/runs"),
|
|
490
|
+
);
|
|
491
|
+
expect(response.status).toBe(400);
|
|
492
|
+
});
|
|
493
|
+
|
|
494
|
+
it("returns 404 when task not found", async () => {
|
|
495
|
+
mockGetScheduledTask.mockResolvedValueOnce({ ok: false, reason: "not_found" });
|
|
496
|
+
const response = await app.fetch(
|
|
497
|
+
new Request(`http://localhost/api/v1/scheduled-tasks/${VALID_ID}/runs`),
|
|
498
|
+
);
|
|
499
|
+
expect(response.status).toBe(404);
|
|
500
|
+
});
|
|
501
|
+
});
|
|
502
|
+
|
|
503
|
+
// -------------------------------------------------------------------------
|
|
504
|
+
// POST /api/v1/scheduled-tasks/tick
|
|
505
|
+
// -------------------------------------------------------------------------
|
|
506
|
+
|
|
507
|
+
describe("POST /api/v1/scheduled-tasks/tick", () => {
|
|
508
|
+
it("returns 404 when no internal DB", async () => {
|
|
509
|
+
delete process.env.DATABASE_URL;
|
|
510
|
+
const response = await app.fetch(
|
|
511
|
+
new Request("http://localhost/api/v1/scheduled-tasks/tick", { method: "POST" }),
|
|
512
|
+
);
|
|
513
|
+
expect(response.status).toBe(404);
|
|
514
|
+
});
|
|
515
|
+
|
|
516
|
+
it("returns 200 with tick result when no secret is set (non-production)", async () => {
|
|
517
|
+
mockRunTick.mockResolvedValueOnce({ tasksFound: 2, tasksDispatched: 2, tasksCompleted: 2, tasksFailed: 0 });
|
|
518
|
+
const response = await app.fetch(
|
|
519
|
+
new Request("http://localhost/api/v1/scheduled-tasks/tick", { method: "POST" }),
|
|
520
|
+
);
|
|
521
|
+
expect(response.status).toBe(200);
|
|
522
|
+
const body = (await response.json()) as Record<string, unknown>;
|
|
523
|
+
expect(body.tasksFound).toBe(2);
|
|
524
|
+
});
|
|
525
|
+
|
|
526
|
+
it("returns 200 when CRON_SECRET matches", async () => {
|
|
527
|
+
process.env.CRON_SECRET = "test-secret";
|
|
528
|
+
mockRunTick.mockResolvedValueOnce({ tasksFound: 0, tasksDispatched: 0, tasksCompleted: 0, tasksFailed: 0 });
|
|
529
|
+
const response = await app.fetch(
|
|
530
|
+
new Request("http://localhost/api/v1/scheduled-tasks/tick", {
|
|
531
|
+
method: "POST",
|
|
532
|
+
headers: { Authorization: "Bearer test-secret" },
|
|
533
|
+
}),
|
|
534
|
+
);
|
|
535
|
+
expect(response.status).toBe(200);
|
|
536
|
+
});
|
|
537
|
+
|
|
538
|
+
it("returns 200 when ATLAS_SCHEDULER_SECRET matches", async () => {
|
|
539
|
+
process.env.ATLAS_SCHEDULER_SECRET = "my-secret";
|
|
540
|
+
mockRunTick.mockResolvedValueOnce({ tasksFound: 0, tasksDispatched: 0, tasksCompleted: 0, tasksFailed: 0 });
|
|
541
|
+
const response = await app.fetch(
|
|
542
|
+
new Request("http://localhost/api/v1/scheduled-tasks/tick", {
|
|
543
|
+
method: "POST",
|
|
544
|
+
headers: { Authorization: "Bearer my-secret" },
|
|
545
|
+
}),
|
|
546
|
+
);
|
|
547
|
+
expect(response.status).toBe(200);
|
|
548
|
+
});
|
|
549
|
+
|
|
550
|
+
it("returns 401 when CRON_SECRET is set but Authorization is wrong", async () => {
|
|
551
|
+
process.env.CRON_SECRET = "test-secret";
|
|
552
|
+
const response = await app.fetch(
|
|
553
|
+
new Request("http://localhost/api/v1/scheduled-tasks/tick", {
|
|
554
|
+
method: "POST",
|
|
555
|
+
headers: { Authorization: "Bearer wrong" },
|
|
556
|
+
}),
|
|
557
|
+
);
|
|
558
|
+
expect(response.status).toBe(401);
|
|
559
|
+
});
|
|
560
|
+
|
|
561
|
+
it("returns 401 when CRON_SECRET is set but Authorization is missing", async () => {
|
|
562
|
+
process.env.CRON_SECRET = "test-secret";
|
|
563
|
+
const response = await app.fetch(
|
|
564
|
+
new Request("http://localhost/api/v1/scheduled-tasks/tick", { method: "POST" }),
|
|
565
|
+
);
|
|
566
|
+
expect(response.status).toBe(401);
|
|
567
|
+
});
|
|
568
|
+
|
|
569
|
+
it("returns 500 when backend is vercel and no secret is configured", async () => {
|
|
570
|
+
mockGetConfig.mockReturnValue({ scheduler: { backend: "vercel" } });
|
|
571
|
+
const response = await app.fetch(
|
|
572
|
+
new Request("http://localhost/api/v1/scheduled-tasks/tick", { method: "POST" }),
|
|
573
|
+
);
|
|
574
|
+
expect(response.status).toBe(500);
|
|
575
|
+
const body = (await response.json()) as Record<string, unknown>;
|
|
576
|
+
expect(body.error).toBe("misconfigured");
|
|
577
|
+
});
|
|
578
|
+
|
|
579
|
+
it("returns 500 in production when no secret is configured", async () => {
|
|
580
|
+
process.env.NODE_ENV = "production";
|
|
581
|
+
const response = await app.fetch(
|
|
582
|
+
new Request("http://localhost/api/v1/scheduled-tasks/tick", { method: "POST" }),
|
|
583
|
+
);
|
|
584
|
+
expect(response.status).toBe(500);
|
|
585
|
+
const body = (await response.json()) as Record<string, unknown>;
|
|
586
|
+
expect(body.error).toBe("misconfigured");
|
|
587
|
+
});
|
|
588
|
+
|
|
589
|
+
it("returns 500 when runTick returns an error", async () => {
|
|
590
|
+
mockRunTick.mockResolvedValueOnce({
|
|
591
|
+
tasksFound: 0, tasksDispatched: 0, tasksCompleted: 0, tasksFailed: 0, error: "db down",
|
|
592
|
+
});
|
|
593
|
+
const response = await app.fetch(
|
|
594
|
+
new Request("http://localhost/api/v1/scheduled-tasks/tick", { method: "POST" }),
|
|
595
|
+
);
|
|
596
|
+
expect(response.status).toBe(500);
|
|
597
|
+
const body = (await response.json()) as Record<string, unknown>;
|
|
598
|
+
expect(body.error).toBe("db down");
|
|
599
|
+
});
|
|
600
|
+
});
|
|
601
|
+
});
|