@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,248 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unit tests for the scheduler engine.
|
|
3
|
+
*/
|
|
4
|
+
import { describe, it, expect, beforeEach, afterEach, mock } from "bun:test";
|
|
5
|
+
|
|
6
|
+
// Mock dependencies before importing
|
|
7
|
+
const mockGetTasksDueForExecution = mock((): Promise<unknown[]> => Promise.resolve([]));
|
|
8
|
+
const mockLockTaskForExecution = mock((): Promise<boolean> => Promise.resolve(true));
|
|
9
|
+
const mockCreateTaskRun = mock((): Promise<string | null> => Promise.resolve("run-123"));
|
|
10
|
+
const mockCompleteTaskRun = mock((): void => {});
|
|
11
|
+
const mockGetScheduledTask = mock((): Promise<unknown> =>
|
|
12
|
+
Promise.resolve({ ok: true, data: { id: "task-123", question: "Q?", cronExpression: "0 9 * * 1" } }),
|
|
13
|
+
);
|
|
14
|
+
const mockComputeNextRun = mock((): Date | null => new Date("2025-01-01T09:00:00Z"));
|
|
15
|
+
|
|
16
|
+
mock.module("@atlas/api/lib/scheduled-tasks", () => ({
|
|
17
|
+
getTasksDueForExecution: mockGetTasksDueForExecution,
|
|
18
|
+
lockTaskForExecution: mockLockTaskForExecution,
|
|
19
|
+
createTaskRun: mockCreateTaskRun,
|
|
20
|
+
completeTaskRun: mockCompleteTaskRun,
|
|
21
|
+
getScheduledTask: mockGetScheduledTask,
|
|
22
|
+
computeNextRun: mockComputeNextRun,
|
|
23
|
+
}));
|
|
24
|
+
|
|
25
|
+
mock.module("@atlas/api/lib/db/internal", () => ({
|
|
26
|
+
internalExecute: mock(() => {}),
|
|
27
|
+
}));
|
|
28
|
+
|
|
29
|
+
const mockExecuteResult = {
|
|
30
|
+
tokensUsed: 1500,
|
|
31
|
+
deliveryAttempted: 1,
|
|
32
|
+
deliverySucceeded: 1,
|
|
33
|
+
deliveryFailed: 0,
|
|
34
|
+
};
|
|
35
|
+
const mockExecuteScheduledTask = mock(() => Promise.resolve(mockExecuteResult));
|
|
36
|
+
|
|
37
|
+
mock.module("../executor", () => ({
|
|
38
|
+
executeScheduledTask: mockExecuteScheduledTask,
|
|
39
|
+
}));
|
|
40
|
+
|
|
41
|
+
mock.module("@atlas/api/lib/config", () => ({
|
|
42
|
+
getConfig: () => ({
|
|
43
|
+
scheduler: {
|
|
44
|
+
maxConcurrentTasks: 5,
|
|
45
|
+
taskTimeout: 60_000,
|
|
46
|
+
tickIntervalSeconds: 1,
|
|
47
|
+
},
|
|
48
|
+
}),
|
|
49
|
+
}));
|
|
50
|
+
|
|
51
|
+
const { getScheduler, triggerTask, runTick, _resetScheduler } = await import("../engine");
|
|
52
|
+
|
|
53
|
+
describe("scheduler engine", () => {
|
|
54
|
+
beforeEach(() => {
|
|
55
|
+
_resetScheduler();
|
|
56
|
+
mockGetTasksDueForExecution.mockReset();
|
|
57
|
+
mockGetTasksDueForExecution.mockResolvedValue([]);
|
|
58
|
+
mockLockTaskForExecution.mockReset();
|
|
59
|
+
mockLockTaskForExecution.mockResolvedValue(true);
|
|
60
|
+
mockCreateTaskRun.mockReset();
|
|
61
|
+
mockCreateTaskRun.mockResolvedValue("run-123");
|
|
62
|
+
mockCompleteTaskRun.mockReset();
|
|
63
|
+
mockExecuteScheduledTask.mockReset();
|
|
64
|
+
mockExecuteScheduledTask.mockResolvedValue(mockExecuteResult);
|
|
65
|
+
mockGetScheduledTask.mockReset();
|
|
66
|
+
mockGetScheduledTask.mockResolvedValue({ ok: true, data: { id: "task-123", question: "Q?", cronExpression: "0 9 * * 1" } });
|
|
67
|
+
mockComputeNextRun.mockReset();
|
|
68
|
+
mockComputeNextRun.mockReturnValue(new Date("2025-01-01T09:00:00Z"));
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
afterEach(() => {
|
|
72
|
+
_resetScheduler();
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
describe("getScheduler()", () => {
|
|
76
|
+
it("returns a singleton", () => {
|
|
77
|
+
const s1 = getScheduler();
|
|
78
|
+
const s2 = getScheduler();
|
|
79
|
+
expect(s1).toBe(s2);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it("starts and stops", () => {
|
|
83
|
+
const scheduler = getScheduler();
|
|
84
|
+
expect(scheduler.isRunning()).toBe(false);
|
|
85
|
+
scheduler.start();
|
|
86
|
+
expect(scheduler.isRunning()).toBe(true);
|
|
87
|
+
scheduler.stop();
|
|
88
|
+
expect(scheduler.isRunning()).toBe(false);
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it("start is idempotent", () => {
|
|
92
|
+
const scheduler = getScheduler();
|
|
93
|
+
scheduler.start();
|
|
94
|
+
scheduler.start(); // Should not throw
|
|
95
|
+
expect(scheduler.isRunning()).toBe(true);
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it("stop is idempotent", () => {
|
|
99
|
+
const scheduler = getScheduler();
|
|
100
|
+
scheduler.stop(); // Not running — should not throw
|
|
101
|
+
expect(scheduler.isRunning()).toBe(false);
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
describe("triggerTask()", () => {
|
|
106
|
+
it("executes a task immediately and records token usage", async () => {
|
|
107
|
+
await triggerTask("task-123");
|
|
108
|
+
expect(mockLockTaskForExecution).toHaveBeenCalledWith("task-123");
|
|
109
|
+
expect(mockCreateTaskRun).toHaveBeenCalledWith("task-123");
|
|
110
|
+
expect(mockExecuteScheduledTask).toHaveBeenCalledWith("task-123", "run-123", 60_000);
|
|
111
|
+
expect(mockCompleteTaskRun).toHaveBeenCalledWith("run-123", "success", { tokensUsed: 1500 });
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
it("throws when lock fails", async () => {
|
|
115
|
+
mockLockTaskForExecution.mockResolvedValueOnce(false);
|
|
116
|
+
await expect(triggerTask("task-123")).rejects.toThrow("Failed to lock task");
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
it("throws when createTaskRun fails", async () => {
|
|
120
|
+
mockCreateTaskRun.mockResolvedValueOnce(null);
|
|
121
|
+
await expect(triggerTask("task-123")).rejects.toThrow("Failed to create run record");
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
it("marks run as failed on execution error", async () => {
|
|
125
|
+
mockExecuteScheduledTask.mockRejectedValueOnce(new Error("boom"));
|
|
126
|
+
await expect(triggerTask("task-123")).rejects.toThrow("boom");
|
|
127
|
+
expect(mockCompleteTaskRun).toHaveBeenCalledWith("run-123", "failed", { error: "boom" });
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
describe("runTick()", () => {
|
|
132
|
+
it("returns zero counts when no tasks are due", async () => {
|
|
133
|
+
mockGetTasksDueForExecution.mockResolvedValueOnce([]);
|
|
134
|
+
const result = await runTick();
|
|
135
|
+
expect(result).toEqual({
|
|
136
|
+
tasksFound: 0,
|
|
137
|
+
tasksDispatched: 0,
|
|
138
|
+
tasksCompleted: 0,
|
|
139
|
+
tasksFailed: 0,
|
|
140
|
+
});
|
|
141
|
+
expect(result.error).toBeUndefined();
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
it("awaits completion and returns correct counts", async () => {
|
|
145
|
+
mockGetTasksDueForExecution.mockResolvedValueOnce([
|
|
146
|
+
{ id: "t1" },
|
|
147
|
+
{ id: "t2" },
|
|
148
|
+
]);
|
|
149
|
+
const result = await runTick();
|
|
150
|
+
expect(result).toEqual({
|
|
151
|
+
tasksFound: 2,
|
|
152
|
+
tasksDispatched: 2,
|
|
153
|
+
tasksCompleted: 2,
|
|
154
|
+
tasksFailed: 0,
|
|
155
|
+
});
|
|
156
|
+
expect(mockExecuteScheduledTask).toHaveBeenCalledTimes(2);
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
it("counts execution failures in tasksFailed", async () => {
|
|
160
|
+
mockGetTasksDueForExecution.mockResolvedValueOnce([{ id: "t1" }]);
|
|
161
|
+
mockExecuteScheduledTask.mockRejectedValueOnce(new Error("boom"));
|
|
162
|
+
const result = await runTick();
|
|
163
|
+
expect(result).toEqual({
|
|
164
|
+
tasksFound: 1,
|
|
165
|
+
tasksDispatched: 1,
|
|
166
|
+
tasksCompleted: 0,
|
|
167
|
+
tasksFailed: 1,
|
|
168
|
+
});
|
|
169
|
+
expect(mockCompleteTaskRun).toHaveBeenCalledWith("run-123", "failed", { error: "boom" });
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
it("skips tasks that fail to lock (not counted as failure)", async () => {
|
|
173
|
+
mockGetTasksDueForExecution.mockResolvedValueOnce([{ id: "t1" }, { id: "t2" }]);
|
|
174
|
+
mockLockTaskForExecution
|
|
175
|
+
.mockResolvedValueOnce(false) // t1 — lock fails
|
|
176
|
+
.mockResolvedValueOnce(true); // t2 — lock succeeds
|
|
177
|
+
const result = await runTick();
|
|
178
|
+
expect(result).toEqual({
|
|
179
|
+
tasksFound: 2,
|
|
180
|
+
tasksDispatched: 1,
|
|
181
|
+
tasksCompleted: 1,
|
|
182
|
+
tasksFailed: 0,
|
|
183
|
+
});
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
it("respects maxConcurrentTasks limit", async () => {
|
|
187
|
+
// Config mock returns maxConcurrentTasks: 5, but we send 7 tasks
|
|
188
|
+
mockGetTasksDueForExecution.mockResolvedValueOnce([
|
|
189
|
+
{ id: "t1" }, { id: "t2" }, { id: "t3" },
|
|
190
|
+
{ id: "t4" }, { id: "t5" }, { id: "t6" }, { id: "t7" },
|
|
191
|
+
]);
|
|
192
|
+
const result = await runTick();
|
|
193
|
+
expect(result.tasksFound).toBe(7);
|
|
194
|
+
expect(result.tasksDispatched).toBe(5); // capped at maxConcurrentTasks
|
|
195
|
+
expect(mockExecuteScheduledTask).toHaveBeenCalledTimes(5);
|
|
196
|
+
expect(mockLockTaskForExecution).toHaveBeenCalledTimes(5);
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
it("surfaces error when getTasksDueForExecution throws", async () => {
|
|
200
|
+
mockGetTasksDueForExecution.mockRejectedValueOnce(new Error("db down"));
|
|
201
|
+
const result = await runTick();
|
|
202
|
+
expect(result.error).toBe("db down");
|
|
203
|
+
expect(result.tasksFound).toBe(0);
|
|
204
|
+
expect(result.tasksDispatched).toBe(0);
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
it("counts createTaskRun failure as tasksFailed without executing", async () => {
|
|
208
|
+
mockGetTasksDueForExecution.mockResolvedValueOnce([{ id: "t1" }]);
|
|
209
|
+
mockCreateTaskRun.mockResolvedValueOnce(null);
|
|
210
|
+
const result = await runTick();
|
|
211
|
+
expect(result).toEqual({
|
|
212
|
+
tasksFound: 1,
|
|
213
|
+
tasksDispatched: 1,
|
|
214
|
+
tasksCompleted: 0,
|
|
215
|
+
tasksFailed: 1,
|
|
216
|
+
});
|
|
217
|
+
expect(mockExecuteScheduledTask).not.toHaveBeenCalled();
|
|
218
|
+
expect(mockCompleteTaskRun).not.toHaveBeenCalled();
|
|
219
|
+
// Should attempt to reschedule
|
|
220
|
+
expect(mockGetScheduledTask).toHaveBeenCalledWith("t1");
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
it("skips tasks where lockTaskForExecution throws", async () => {
|
|
224
|
+
mockGetTasksDueForExecution.mockResolvedValueOnce([{ id: "t1" }, { id: "t2" }]);
|
|
225
|
+
mockLockTaskForExecution
|
|
226
|
+
.mockRejectedValueOnce(new Error("lock query timeout"))
|
|
227
|
+
.mockResolvedValueOnce(true);
|
|
228
|
+
const result = await runTick();
|
|
229
|
+
expect(result).toEqual({
|
|
230
|
+
tasksFound: 2,
|
|
231
|
+
tasksDispatched: 1,
|
|
232
|
+
tasksCompleted: 1,
|
|
233
|
+
tasksFailed: 0,
|
|
234
|
+
});
|
|
235
|
+
});
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
describe("_resetScheduler()", () => {
|
|
239
|
+
it("stops and clears the singleton", () => {
|
|
240
|
+
const s1 = getScheduler();
|
|
241
|
+
s1.start();
|
|
242
|
+
_resetScheduler();
|
|
243
|
+
const s2 = getScheduler();
|
|
244
|
+
expect(s2).not.toBe(s1);
|
|
245
|
+
expect(s2.isRunning()).toBe(false);
|
|
246
|
+
});
|
|
247
|
+
});
|
|
248
|
+
});
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unit tests for the email formatter.
|
|
3
|
+
*/
|
|
4
|
+
import { describe, it, expect } from "bun:test";
|
|
5
|
+
import { formatEmailReport } from "../format-email";
|
|
6
|
+
import type { ScheduledTask } from "@atlas/api/lib/scheduled-tasks";
|
|
7
|
+
import type { AgentQueryResult } from "@atlas/api/lib/agent-query";
|
|
8
|
+
|
|
9
|
+
function makeTask(overrides: Partial<ScheduledTask> = {}): ScheduledTask {
|
|
10
|
+
return {
|
|
11
|
+
id: "task-123",
|
|
12
|
+
ownerId: "u1",
|
|
13
|
+
name: "Daily Revenue",
|
|
14
|
+
question: "What was yesterday's revenue?",
|
|
15
|
+
cronExpression: "0 9 * * 1",
|
|
16
|
+
deliveryChannel: "email",
|
|
17
|
+
recipients: [],
|
|
18
|
+
connectionId: null,
|
|
19
|
+
approvalMode: "auto",
|
|
20
|
+
enabled: true,
|
|
21
|
+
lastRunAt: null,
|
|
22
|
+
nextRunAt: null,
|
|
23
|
+
createdAt: "2024-01-01T00:00:00Z",
|
|
24
|
+
updatedAt: "2024-01-01T00:00:00Z",
|
|
25
|
+
...overrides,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function makeResult(overrides: Partial<AgentQueryResult> = {}): AgentQueryResult {
|
|
30
|
+
return {
|
|
31
|
+
answer: "Revenue was $1M",
|
|
32
|
+
sql: ["SELECT SUM(revenue) FROM orders"],
|
|
33
|
+
data: [{ columns: ["total"], rows: [{ total: 1000000 }] }],
|
|
34
|
+
steps: 3,
|
|
35
|
+
usage: { totalTokens: 1500 },
|
|
36
|
+
...overrides,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
describe("formatEmailReport", () => {
|
|
41
|
+
it("produces subject and body", () => {
|
|
42
|
+
const { subject, body } = formatEmailReport(makeTask(), makeResult());
|
|
43
|
+
expect(subject).toBe("Atlas Report: Daily Revenue");
|
|
44
|
+
expect(body).toContain("Daily Revenue");
|
|
45
|
+
expect(body).toContain("Revenue was $1M");
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it("includes data table", () => {
|
|
49
|
+
const { body } = formatEmailReport(makeTask(), makeResult());
|
|
50
|
+
expect(body).toContain("<table");
|
|
51
|
+
expect(body).toContain("total");
|
|
52
|
+
expect(body).toContain("1000000");
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it("includes SQL", () => {
|
|
56
|
+
const { body } = formatEmailReport(makeTask(), makeResult());
|
|
57
|
+
expect(body).toContain("SELECT SUM(revenue)");
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it("includes metadata footer", () => {
|
|
61
|
+
const { body } = formatEmailReport(makeTask(), makeResult());
|
|
62
|
+
expect(body).toContain("3 steps");
|
|
63
|
+
expect(body).toContain("1,500 tokens");
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it("handles empty answer", () => {
|
|
67
|
+
const { body } = formatEmailReport(makeTask(), makeResult({ answer: "" }));
|
|
68
|
+
expect(body).toContain("No answer generated.");
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it("handles empty data", () => {
|
|
72
|
+
const { body } = formatEmailReport(makeTask(), makeResult({ data: [] }));
|
|
73
|
+
expect(body).not.toContain("<table");
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it("handles empty SQL", () => {
|
|
77
|
+
const { body } = formatEmailReport(makeTask(), makeResult({ sql: [] }));
|
|
78
|
+
expect(body).not.toContain("<pre");
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it("escapes HTML in task name", () => {
|
|
82
|
+
const task = makeTask({ name: "Test <script>alert(1)</script>" });
|
|
83
|
+
const { body } = formatEmailReport(task, makeResult());
|
|
84
|
+
expect(body).not.toContain("<script>");
|
|
85
|
+
expect(body).toContain("<script>");
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it("truncates large data tables", () => {
|
|
89
|
+
const rows = Array.from({ length: 100 }, (_, i) => ({ id: i, value: `row-${i}` }));
|
|
90
|
+
const { body } = formatEmailReport(
|
|
91
|
+
makeTask(),
|
|
92
|
+
makeResult({ data: [{ columns: ["id", "value"], rows }] }),
|
|
93
|
+
);
|
|
94
|
+
expect(body).toContain("Showing first 50");
|
|
95
|
+
});
|
|
96
|
+
});
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unit tests for the Slack formatter.
|
|
3
|
+
*/
|
|
4
|
+
import { describe, it, expect } from "bun:test";
|
|
5
|
+
import { formatSlackReport } from "../format-slack";
|
|
6
|
+
import type { ScheduledTask } from "@atlas/api/lib/scheduled-tasks";
|
|
7
|
+
import type { AgentQueryResult } from "@atlas/api/lib/agent-query";
|
|
8
|
+
|
|
9
|
+
function makeTask(overrides: Partial<ScheduledTask> = {}): ScheduledTask {
|
|
10
|
+
return {
|
|
11
|
+
id: "task-123",
|
|
12
|
+
ownerId: "u1",
|
|
13
|
+
name: "Daily Revenue",
|
|
14
|
+
question: "What was yesterday's revenue?",
|
|
15
|
+
cronExpression: "0 9 * * 1",
|
|
16
|
+
deliveryChannel: "slack",
|
|
17
|
+
recipients: [],
|
|
18
|
+
connectionId: null,
|
|
19
|
+
approvalMode: "auto",
|
|
20
|
+
enabled: true,
|
|
21
|
+
lastRunAt: null,
|
|
22
|
+
nextRunAt: null,
|
|
23
|
+
createdAt: "2024-01-01T00:00:00Z",
|
|
24
|
+
updatedAt: "2024-01-01T00:00:00Z",
|
|
25
|
+
...overrides,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function makeResult(overrides: Partial<AgentQueryResult> = {}): AgentQueryResult {
|
|
30
|
+
return {
|
|
31
|
+
answer: "Revenue was $1M",
|
|
32
|
+
sql: ["SELECT SUM(revenue) FROM orders"],
|
|
33
|
+
data: [{ columns: ["total"], rows: [{ total: 1000000 }] }],
|
|
34
|
+
steps: 3,
|
|
35
|
+
usage: { totalTokens: 1500 },
|
|
36
|
+
...overrides,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
describe("formatSlackReport", () => {
|
|
41
|
+
it("produces text and blocks", () => {
|
|
42
|
+
const { text, blocks } = formatSlackReport(makeTask(), makeResult());
|
|
43
|
+
expect(text).toContain("Daily Revenue");
|
|
44
|
+
expect(blocks.length).toBeGreaterThan(1);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it("includes header block with task name", () => {
|
|
48
|
+
const { blocks } = formatSlackReport(makeTask(), makeResult());
|
|
49
|
+
const header = blocks[0];
|
|
50
|
+
expect(header.type).toBe("section");
|
|
51
|
+
if ("text" in header) {
|
|
52
|
+
expect(header.text.text).toContain("*Daily Revenue*");
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it("includes answer from formatQueryResponse", () => {
|
|
57
|
+
const { blocks } = formatSlackReport(makeTask(), makeResult());
|
|
58
|
+
const answerBlock = blocks.find(
|
|
59
|
+
(b) => b.type === "section" && "text" in b && b.text.text.includes("Revenue was $1M"),
|
|
60
|
+
);
|
|
61
|
+
expect(answerBlock).toBeDefined();
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it("includes question in header", () => {
|
|
65
|
+
const { blocks } = formatSlackReport(makeTask(), makeResult());
|
|
66
|
+
if ("text" in blocks[0]) {
|
|
67
|
+
expect(blocks[0].text.text).toContain("yesterday's revenue");
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it("truncates long questions", () => {
|
|
72
|
+
const longQuestion = "a".repeat(300);
|
|
73
|
+
const { blocks } = formatSlackReport(makeTask({ question: longQuestion }), makeResult());
|
|
74
|
+
if ("text" in blocks[0]) {
|
|
75
|
+
expect(blocks[0].text.text.length).toBeLessThan(350);
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
});
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unit tests for the webhook formatter.
|
|
3
|
+
*/
|
|
4
|
+
import { describe, it, expect } from "bun:test";
|
|
5
|
+
import { formatWebhookPayload } from "../format-webhook";
|
|
6
|
+
import type { ScheduledTask } from "@atlas/api/lib/scheduled-tasks";
|
|
7
|
+
import type { AgentQueryResult } from "@atlas/api/lib/agent-query";
|
|
8
|
+
|
|
9
|
+
function makeTask(overrides: Partial<ScheduledTask> = {}): ScheduledTask {
|
|
10
|
+
return {
|
|
11
|
+
id: "task-123",
|
|
12
|
+
ownerId: "u1",
|
|
13
|
+
name: "Daily Revenue",
|
|
14
|
+
question: "What was yesterday's revenue?",
|
|
15
|
+
cronExpression: "0 9 * * 1",
|
|
16
|
+
deliveryChannel: "webhook",
|
|
17
|
+
recipients: [],
|
|
18
|
+
connectionId: null,
|
|
19
|
+
approvalMode: "auto",
|
|
20
|
+
enabled: true,
|
|
21
|
+
lastRunAt: null,
|
|
22
|
+
nextRunAt: null,
|
|
23
|
+
createdAt: "2024-01-01T00:00:00Z",
|
|
24
|
+
updatedAt: "2024-01-01T00:00:00Z",
|
|
25
|
+
...overrides,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function makeResult(overrides: Partial<AgentQueryResult> = {}): AgentQueryResult {
|
|
30
|
+
return {
|
|
31
|
+
answer: "Revenue was $1M",
|
|
32
|
+
sql: ["SELECT SUM(revenue) FROM orders"],
|
|
33
|
+
data: [{ columns: ["total"], rows: [{ total: 1000000 }] }],
|
|
34
|
+
steps: 3,
|
|
35
|
+
usage: { totalTokens: 1500 },
|
|
36
|
+
...overrides,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
describe("formatWebhookPayload", () => {
|
|
41
|
+
it("includes all required fields", () => {
|
|
42
|
+
const payload = formatWebhookPayload(makeTask(), makeResult());
|
|
43
|
+
expect(payload.taskId).toBe("task-123");
|
|
44
|
+
expect(payload.taskName).toBe("Daily Revenue");
|
|
45
|
+
expect(payload.question).toBe("What was yesterday's revenue?");
|
|
46
|
+
expect(payload.answer).toBe("Revenue was $1M");
|
|
47
|
+
expect(payload.sql).toEqual(["SELECT SUM(revenue) FROM orders"]);
|
|
48
|
+
expect(payload.data).toHaveLength(1);
|
|
49
|
+
expect(payload.steps).toBe(3);
|
|
50
|
+
expect(payload.usage.totalTokens).toBe(1500);
|
|
51
|
+
expect(payload.timestamp).toBeDefined();
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it("includes ISO timestamp", () => {
|
|
55
|
+
const payload = formatWebhookPayload(makeTask(), makeResult());
|
|
56
|
+
expect(() => new Date(payload.timestamp)).not.toThrow();
|
|
57
|
+
expect(payload.timestamp).toMatch(/^\d{4}-\d{2}-\d{2}T/);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it("handles empty answer", () => {
|
|
61
|
+
const payload = formatWebhookPayload(makeTask(), makeResult({ answer: "" }));
|
|
62
|
+
expect(payload.answer).toBe("");
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it("handles empty data", () => {
|
|
66
|
+
const payload = formatWebhookPayload(makeTask(), makeResult({ data: [] }));
|
|
67
|
+
expect(payload.data).toEqual([]);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it("preserves full data without truncation", () => {
|
|
71
|
+
const rows = Array.from({ length: 100 }, (_, i) => ({ id: i }));
|
|
72
|
+
const payload = formatWebhookPayload(
|
|
73
|
+
makeTask(),
|
|
74
|
+
makeResult({ data: [{ columns: ["id"], rows }] }),
|
|
75
|
+
);
|
|
76
|
+
expect(payload.data[0].rows.length).toBe(100);
|
|
77
|
+
});
|
|
78
|
+
});
|