@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,550 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unit tests for the scheduled tasks CRUD module.
|
|
3
|
+
*
|
|
4
|
+
* Uses _resetPool(mockPool) injection pattern from conversations.test.ts.
|
|
5
|
+
*/
|
|
6
|
+
import { describe, it, expect, beforeEach, afterEach } from "bun:test";
|
|
7
|
+
import { _resetPool, type InternalPool } from "../db/internal";
|
|
8
|
+
import {
|
|
9
|
+
createScheduledTask,
|
|
10
|
+
getScheduledTask,
|
|
11
|
+
listScheduledTasks,
|
|
12
|
+
updateScheduledTask,
|
|
13
|
+
deleteScheduledTask,
|
|
14
|
+
createTaskRun,
|
|
15
|
+
completeTaskRun,
|
|
16
|
+
listTaskRuns,
|
|
17
|
+
getTasksDueForExecution,
|
|
18
|
+
lockTaskForExecution,
|
|
19
|
+
validateCronExpression,
|
|
20
|
+
computeNextRun,
|
|
21
|
+
} from "../scheduled-tasks";
|
|
22
|
+
|
|
23
|
+
// ---------------------------------------------------------------------------
|
|
24
|
+
// Mock pool
|
|
25
|
+
// ---------------------------------------------------------------------------
|
|
26
|
+
|
|
27
|
+
let queryCalls: Array<{ sql: string; params?: unknown[] }> = [];
|
|
28
|
+
let queryResults: Array<{ rows: Record<string, unknown>[] }> = [];
|
|
29
|
+
let queryResultIndex = 0;
|
|
30
|
+
let queryThrow: Error | null = null;
|
|
31
|
+
|
|
32
|
+
const mockPool: InternalPool = {
|
|
33
|
+
query: async (sql: string, params?: unknown[]) => {
|
|
34
|
+
if (queryThrow) throw queryThrow;
|
|
35
|
+
queryCalls.push({ sql, params });
|
|
36
|
+
const result = queryResults[queryResultIndex] ?? { rows: [] };
|
|
37
|
+
queryResultIndex++;
|
|
38
|
+
return result;
|
|
39
|
+
},
|
|
40
|
+
end: async () => {},
|
|
41
|
+
on: () => {},
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
function enableInternalDB() {
|
|
45
|
+
process.env.DATABASE_URL = "postgresql://test:test@localhost:5432/test";
|
|
46
|
+
_resetPool(mockPool);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function setResults(...results: Array<{ rows: Record<string, unknown>[] }>) {
|
|
50
|
+
queryResults = results;
|
|
51
|
+
queryResultIndex = 0;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function makeTaskRow(overrides: Partial<Record<string, unknown>> = {}): Record<string, unknown> {
|
|
55
|
+
return {
|
|
56
|
+
id: "task-123",
|
|
57
|
+
owner_id: "u1",
|
|
58
|
+
name: "Daily Report",
|
|
59
|
+
question: "What was yesterday's revenue?",
|
|
60
|
+
cron_expression: "0 9 * * 1",
|
|
61
|
+
delivery_channel: "email",
|
|
62
|
+
recipients: JSON.stringify([{ type: "email", address: "test@test.com" }]),
|
|
63
|
+
connection_id: null,
|
|
64
|
+
approval_mode: "auto",
|
|
65
|
+
enabled: true,
|
|
66
|
+
last_run_at: null,
|
|
67
|
+
next_run_at: "2024-01-08T09:00:00Z",
|
|
68
|
+
created_at: "2024-01-01T00:00:00Z",
|
|
69
|
+
updated_at: "2024-01-01T00:00:00Z",
|
|
70
|
+
...overrides,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function makeRunRow(overrides: Partial<Record<string, unknown>> = {}): Record<string, unknown> {
|
|
75
|
+
return {
|
|
76
|
+
id: "run-123",
|
|
77
|
+
task_id: "task-123",
|
|
78
|
+
started_at: "2024-01-08T09:00:00Z",
|
|
79
|
+
completed_at: "2024-01-08T09:00:30Z",
|
|
80
|
+
status: "success",
|
|
81
|
+
conversation_id: null,
|
|
82
|
+
action_id: null,
|
|
83
|
+
error: null,
|
|
84
|
+
tokens_used: 1500,
|
|
85
|
+
created_at: "2024-01-08T09:00:00Z",
|
|
86
|
+
...overrides,
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// ---------------------------------------------------------------------------
|
|
91
|
+
// Setup / teardown
|
|
92
|
+
// ---------------------------------------------------------------------------
|
|
93
|
+
|
|
94
|
+
describe("scheduled-tasks module", () => {
|
|
95
|
+
const origDbUrl = process.env.DATABASE_URL;
|
|
96
|
+
|
|
97
|
+
beforeEach(() => {
|
|
98
|
+
queryCalls = [];
|
|
99
|
+
queryResults = [];
|
|
100
|
+
queryResultIndex = 0;
|
|
101
|
+
queryThrow = null;
|
|
102
|
+
delete process.env.DATABASE_URL;
|
|
103
|
+
_resetPool(null);
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
afterEach(() => {
|
|
107
|
+
if (origDbUrl) process.env.DATABASE_URL = origDbUrl;
|
|
108
|
+
else delete process.env.DATABASE_URL;
|
|
109
|
+
_resetPool(null);
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
// -------------------------------------------------------------------------
|
|
113
|
+
// validateCronExpression
|
|
114
|
+
// -------------------------------------------------------------------------
|
|
115
|
+
|
|
116
|
+
describe("validateCronExpression()", () => {
|
|
117
|
+
it("returns valid for standard cron", () => {
|
|
118
|
+
expect(validateCronExpression("0 9 * * 1")).toEqual({ valid: true });
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
it("returns valid for every minute", () => {
|
|
122
|
+
expect(validateCronExpression("* * * * *")).toEqual({ valid: true });
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
it("returns invalid for garbage", () => {
|
|
126
|
+
const result = validateCronExpression("not a cron");
|
|
127
|
+
expect(result.valid).toBe(false);
|
|
128
|
+
expect(result.error).toBeDefined();
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
it("returns invalid for empty string", () => {
|
|
132
|
+
const result = validateCronExpression("");
|
|
133
|
+
expect(result.valid).toBe(false);
|
|
134
|
+
});
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
// -------------------------------------------------------------------------
|
|
138
|
+
// computeNextRun
|
|
139
|
+
// -------------------------------------------------------------------------
|
|
140
|
+
|
|
141
|
+
describe("computeNextRun()", () => {
|
|
142
|
+
it("returns a Date for valid cron", () => {
|
|
143
|
+
const next = computeNextRun("0 9 * * 1");
|
|
144
|
+
expect(next).toBeInstanceOf(Date);
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
it("returns null for invalid cron", () => {
|
|
148
|
+
expect(computeNextRun("invalid")).toBeNull();
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
it("respects the 'after' parameter", () => {
|
|
152
|
+
const after = new Date("2024-01-01T00:00:00Z");
|
|
153
|
+
const next = computeNextRun("0 9 * * 1", after);
|
|
154
|
+
expect(next).toBeInstanceOf(Date);
|
|
155
|
+
expect(next!.getTime()).toBeGreaterThan(after.getTime());
|
|
156
|
+
});
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
// -------------------------------------------------------------------------
|
|
160
|
+
// createScheduledTask
|
|
161
|
+
// -------------------------------------------------------------------------
|
|
162
|
+
|
|
163
|
+
describe("createScheduledTask()", () => {
|
|
164
|
+
it("returns { ok: true, data } on success", async () => {
|
|
165
|
+
enableInternalDB();
|
|
166
|
+
setResults({ rows: [makeTaskRow()] });
|
|
167
|
+
|
|
168
|
+
const result = await createScheduledTask({
|
|
169
|
+
ownerId: "u1",
|
|
170
|
+
name: "Daily Report",
|
|
171
|
+
question: "Revenue?",
|
|
172
|
+
cronExpression: "0 9 * * 1",
|
|
173
|
+
deliveryChannel: "email",
|
|
174
|
+
recipients: [{ type: "email", address: "test@test.com" }],
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
expect(result.ok).toBe(true);
|
|
178
|
+
if (result.ok) {
|
|
179
|
+
expect(result.data.id).toBe("task-123");
|
|
180
|
+
expect(result.data.name).toBe("Daily Report");
|
|
181
|
+
expect(result.data.deliveryChannel).toBe("email");
|
|
182
|
+
expect(result.data.recipients).toHaveLength(1);
|
|
183
|
+
}
|
|
184
|
+
expect(queryCalls[0].sql).toContain("INSERT INTO scheduled_tasks");
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
it("returns { ok: false, reason: 'no_db' } when no DB", async () => {
|
|
188
|
+
const result = await createScheduledTask({
|
|
189
|
+
ownerId: "u1",
|
|
190
|
+
name: "Test",
|
|
191
|
+
question: "Q?",
|
|
192
|
+
cronExpression: "0 9 * * 1",
|
|
193
|
+
});
|
|
194
|
+
expect(result).toEqual({ ok: false, reason: "no_db" });
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
it("returns { ok: false, reason: 'error' } for invalid cron", async () => {
|
|
198
|
+
enableInternalDB();
|
|
199
|
+
const result = await createScheduledTask({
|
|
200
|
+
ownerId: "u1",
|
|
201
|
+
name: "Test",
|
|
202
|
+
question: "Q?",
|
|
203
|
+
cronExpression: "not valid",
|
|
204
|
+
});
|
|
205
|
+
expect(result).toEqual({ ok: false, reason: "error" });
|
|
206
|
+
expect(queryCalls.length).toBe(0); // No DB call made
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
it("returns { ok: false, reason: 'error' } on DB error", async () => {
|
|
210
|
+
enableInternalDB();
|
|
211
|
+
queryThrow = new Error("connection refused");
|
|
212
|
+
const result = await createScheduledTask({
|
|
213
|
+
ownerId: "u1",
|
|
214
|
+
name: "Test",
|
|
215
|
+
question: "Q?",
|
|
216
|
+
cronExpression: "0 9 * * 1",
|
|
217
|
+
});
|
|
218
|
+
expect(result).toEqual({ ok: false, reason: "error" });
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
it("defaults delivery_channel to webhook", async () => {
|
|
222
|
+
enableInternalDB();
|
|
223
|
+
setResults({ rows: [makeTaskRow({ delivery_channel: "webhook" })] });
|
|
224
|
+
|
|
225
|
+
await createScheduledTask({
|
|
226
|
+
ownerId: "u1",
|
|
227
|
+
name: "Test",
|
|
228
|
+
question: "Q?",
|
|
229
|
+
cronExpression: "0 9 * * 1",
|
|
230
|
+
});
|
|
231
|
+
expect(queryCalls[0].params![4]).toBe("webhook");
|
|
232
|
+
});
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
// -------------------------------------------------------------------------
|
|
236
|
+
// getScheduledTask
|
|
237
|
+
// -------------------------------------------------------------------------
|
|
238
|
+
|
|
239
|
+
describe("getScheduledTask()", () => {
|
|
240
|
+
it("returns { ok: true, data } when found", async () => {
|
|
241
|
+
enableInternalDB();
|
|
242
|
+
setResults({ rows: [makeTaskRow()] });
|
|
243
|
+
|
|
244
|
+
const result = await getScheduledTask("task-123", "u1");
|
|
245
|
+
expect(result.ok).toBe(true);
|
|
246
|
+
if (result.ok) {
|
|
247
|
+
expect(result.data.id).toBe("task-123");
|
|
248
|
+
expect(result.data.ownerId).toBe("u1");
|
|
249
|
+
}
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
it("returns { ok: false, reason: 'not_found' } when not found", async () => {
|
|
253
|
+
enableInternalDB();
|
|
254
|
+
setResults({ rows: [] });
|
|
255
|
+
expect(await getScheduledTask("missing")).toEqual({ ok: false, reason: "not_found" });
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
it("scopes by ownerId when provided", async () => {
|
|
259
|
+
enableInternalDB();
|
|
260
|
+
setResults({ rows: [] });
|
|
261
|
+
await getScheduledTask("task-123", "u1");
|
|
262
|
+
expect(queryCalls[0].sql).toContain("owner_id");
|
|
263
|
+
expect(queryCalls[0].params).toEqual(["task-123", "u1"]);
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
it("does not scope by ownerId when not provided", async () => {
|
|
267
|
+
enableInternalDB();
|
|
268
|
+
setResults({ rows: [] });
|
|
269
|
+
await getScheduledTask("task-123");
|
|
270
|
+
expect(queryCalls[0].sql).not.toContain("owner_id");
|
|
271
|
+
expect(queryCalls[0].params).toEqual(["task-123"]);
|
|
272
|
+
});
|
|
273
|
+
|
|
274
|
+
it("returns { ok: false, reason: 'no_db' } when no DB", async () => {
|
|
275
|
+
expect(await getScheduledTask("task-123")).toEqual({ ok: false, reason: "no_db" });
|
|
276
|
+
});
|
|
277
|
+
|
|
278
|
+
it("returns { ok: false, reason: 'error' } on DB error", async () => {
|
|
279
|
+
enableInternalDB();
|
|
280
|
+
queryThrow = new Error("fail");
|
|
281
|
+
expect(await getScheduledTask("task-123")).toEqual({ ok: false, reason: "error" });
|
|
282
|
+
});
|
|
283
|
+
});
|
|
284
|
+
|
|
285
|
+
// -------------------------------------------------------------------------
|
|
286
|
+
// listScheduledTasks
|
|
287
|
+
// -------------------------------------------------------------------------
|
|
288
|
+
|
|
289
|
+
describe("listScheduledTasks()", () => {
|
|
290
|
+
it("returns tasks and total", async () => {
|
|
291
|
+
enableInternalDB();
|
|
292
|
+
setResults(
|
|
293
|
+
{ rows: [{ total: 1 }] },
|
|
294
|
+
{ rows: [makeTaskRow()] },
|
|
295
|
+
);
|
|
296
|
+
|
|
297
|
+
const result = await listScheduledTasks({ ownerId: "u1" });
|
|
298
|
+
expect(result.total).toBe(1);
|
|
299
|
+
expect(result.tasks).toHaveLength(1);
|
|
300
|
+
});
|
|
301
|
+
|
|
302
|
+
it("returns empty when no DB", async () => {
|
|
303
|
+
expect(await listScheduledTasks()).toEqual({ tasks: [], total: 0 });
|
|
304
|
+
});
|
|
305
|
+
|
|
306
|
+
it("respects limit and offset", async () => {
|
|
307
|
+
enableInternalDB();
|
|
308
|
+
setResults({ rows: [{ total: 50 }] }, { rows: [] });
|
|
309
|
+
await listScheduledTasks({ limit: 5, offset: 10 });
|
|
310
|
+
expect(queryCalls[1].params).toEqual([5, 10]);
|
|
311
|
+
});
|
|
312
|
+
|
|
313
|
+
it("filters by enabled", async () => {
|
|
314
|
+
enableInternalDB();
|
|
315
|
+
setResults({ rows: [{ total: 3 }] }, { rows: [] });
|
|
316
|
+
await listScheduledTasks({ enabled: true });
|
|
317
|
+
expect(queryCalls[0].sql).toContain("enabled");
|
|
318
|
+
expect(queryCalls[0].params).toEqual([true]);
|
|
319
|
+
});
|
|
320
|
+
|
|
321
|
+
it("returns empty on DB error", async () => {
|
|
322
|
+
enableInternalDB();
|
|
323
|
+
queryThrow = new Error("fail");
|
|
324
|
+
expect(await listScheduledTasks()).toEqual({ tasks: [], total: 0 });
|
|
325
|
+
});
|
|
326
|
+
});
|
|
327
|
+
|
|
328
|
+
// -------------------------------------------------------------------------
|
|
329
|
+
// updateScheduledTask
|
|
330
|
+
// -------------------------------------------------------------------------
|
|
331
|
+
|
|
332
|
+
describe("updateScheduledTask()", () => {
|
|
333
|
+
it("returns { ok: true } on success", async () => {
|
|
334
|
+
enableInternalDB();
|
|
335
|
+
setResults({ rows: [{ id: "task-123" }] });
|
|
336
|
+
|
|
337
|
+
const result = await updateScheduledTask("task-123", "u1", { name: "Updated" });
|
|
338
|
+
expect(result).toEqual({ ok: true });
|
|
339
|
+
expect(queryCalls[0].sql).toContain("UPDATE scheduled_tasks");
|
|
340
|
+
expect(queryCalls[0].sql).toContain("name =");
|
|
341
|
+
});
|
|
342
|
+
|
|
343
|
+
it("returns { ok: true } when no updates", async () => {
|
|
344
|
+
enableInternalDB();
|
|
345
|
+
const result = await updateScheduledTask("task-123", "u1", {});
|
|
346
|
+
expect(result).toEqual({ ok: true });
|
|
347
|
+
expect(queryCalls.length).toBe(0);
|
|
348
|
+
});
|
|
349
|
+
|
|
350
|
+
it("returns { ok: false, reason: 'not_found' } when not found", async () => {
|
|
351
|
+
enableInternalDB();
|
|
352
|
+
setResults({ rows: [] });
|
|
353
|
+
expect(await updateScheduledTask("missing", "u1", { name: "X" })).toEqual({ ok: false, reason: "not_found" });
|
|
354
|
+
});
|
|
355
|
+
|
|
356
|
+
it("returns { ok: false, reason: 'no_db' } when no DB", async () => {
|
|
357
|
+
expect(await updateScheduledTask("t", "u1", { name: "X" })).toEqual({ ok: false, reason: "no_db" });
|
|
358
|
+
});
|
|
359
|
+
|
|
360
|
+
it("recomputes next_run_at when cron changes", async () => {
|
|
361
|
+
enableInternalDB();
|
|
362
|
+
setResults({ rows: [{ id: "task-123" }] });
|
|
363
|
+
|
|
364
|
+
await updateScheduledTask("task-123", "u1", { cronExpression: "0 10 * * *" });
|
|
365
|
+
expect(queryCalls[0].sql).toContain("cron_expression");
|
|
366
|
+
expect(queryCalls[0].sql).toContain("next_run_at");
|
|
367
|
+
});
|
|
368
|
+
|
|
369
|
+
it("returns error for invalid cron", async () => {
|
|
370
|
+
enableInternalDB();
|
|
371
|
+
const result = await updateScheduledTask("t", "u1", { cronExpression: "bad" });
|
|
372
|
+
expect(result).toEqual({ ok: false, reason: "error" });
|
|
373
|
+
});
|
|
374
|
+
|
|
375
|
+
it("returns { ok: false, reason: 'error' } on DB error", async () => {
|
|
376
|
+
enableInternalDB();
|
|
377
|
+
queryThrow = new Error("fail");
|
|
378
|
+
expect(await updateScheduledTask("t", "u1", { name: "X" })).toEqual({ ok: false, reason: "error" });
|
|
379
|
+
});
|
|
380
|
+
});
|
|
381
|
+
|
|
382
|
+
// -------------------------------------------------------------------------
|
|
383
|
+
// deleteScheduledTask
|
|
384
|
+
// -------------------------------------------------------------------------
|
|
385
|
+
|
|
386
|
+
describe("deleteScheduledTask()", () => {
|
|
387
|
+
it("soft deletes by setting enabled=false", async () => {
|
|
388
|
+
enableInternalDB();
|
|
389
|
+
setResults({ rows: [{ id: "task-123" }] });
|
|
390
|
+
|
|
391
|
+
const result = await deleteScheduledTask("task-123", "u1");
|
|
392
|
+
expect(result).toEqual({ ok: true });
|
|
393
|
+
expect(queryCalls[0].sql).toContain("SET enabled = false");
|
|
394
|
+
expect(queryCalls[0].sql).toContain("owner_id");
|
|
395
|
+
});
|
|
396
|
+
|
|
397
|
+
it("returns { ok: false, reason: 'not_found' } when not found", async () => {
|
|
398
|
+
enableInternalDB();
|
|
399
|
+
setResults({ rows: [] });
|
|
400
|
+
expect(await deleteScheduledTask("missing", "u1")).toEqual({ ok: false, reason: "not_found" });
|
|
401
|
+
});
|
|
402
|
+
|
|
403
|
+
it("returns { ok: false, reason: 'no_db' } when no DB", async () => {
|
|
404
|
+
expect(await deleteScheduledTask("t")).toEqual({ ok: false, reason: "no_db" });
|
|
405
|
+
});
|
|
406
|
+
|
|
407
|
+
it("does not scope by ownerId when not provided", async () => {
|
|
408
|
+
enableInternalDB();
|
|
409
|
+
setResults({ rows: [{ id: "task-123" }] });
|
|
410
|
+
await deleteScheduledTask("task-123");
|
|
411
|
+
expect(queryCalls[0].sql).not.toContain("owner_id");
|
|
412
|
+
});
|
|
413
|
+
});
|
|
414
|
+
|
|
415
|
+
// -------------------------------------------------------------------------
|
|
416
|
+
// createTaskRun / completeTaskRun / listTaskRuns
|
|
417
|
+
// -------------------------------------------------------------------------
|
|
418
|
+
|
|
419
|
+
describe("createTaskRun()", () => {
|
|
420
|
+
it("returns run ID on success", async () => {
|
|
421
|
+
enableInternalDB();
|
|
422
|
+
setResults({ rows: [{ id: "run-456" }] });
|
|
423
|
+
expect(await createTaskRun("task-123")).toBe("run-456");
|
|
424
|
+
});
|
|
425
|
+
|
|
426
|
+
it("returns null when no DB", async () => {
|
|
427
|
+
expect(await createTaskRun("task-123")).toBeNull();
|
|
428
|
+
});
|
|
429
|
+
|
|
430
|
+
it("returns null on DB error", async () => {
|
|
431
|
+
enableInternalDB();
|
|
432
|
+
queryThrow = new Error("fail");
|
|
433
|
+
expect(await createTaskRun("task-123")).toBeNull();
|
|
434
|
+
});
|
|
435
|
+
});
|
|
436
|
+
|
|
437
|
+
describe("completeTaskRun()", () => {
|
|
438
|
+
it("fires update query", () => {
|
|
439
|
+
enableInternalDB();
|
|
440
|
+
completeTaskRun("run-123", "success", { tokensUsed: 1500 });
|
|
441
|
+
expect(queryCalls.length).toBe(1);
|
|
442
|
+
expect(queryCalls[0].sql).toContain("UPDATE scheduled_task_runs");
|
|
443
|
+
});
|
|
444
|
+
|
|
445
|
+
it("is a no-op when no DB", () => {
|
|
446
|
+
completeTaskRun("run-123", "success");
|
|
447
|
+
expect(queryCalls.length).toBe(0);
|
|
448
|
+
});
|
|
449
|
+
});
|
|
450
|
+
|
|
451
|
+
describe("listTaskRuns()", () => {
|
|
452
|
+
it("returns runs", async () => {
|
|
453
|
+
enableInternalDB();
|
|
454
|
+
setResults({ rows: [makeRunRow()] });
|
|
455
|
+
|
|
456
|
+
const runs = await listTaskRuns("task-123");
|
|
457
|
+
expect(runs).toHaveLength(1);
|
|
458
|
+
expect(runs[0].id).toBe("run-123");
|
|
459
|
+
expect(runs[0].status).toBe("success");
|
|
460
|
+
expect(runs[0].tokensUsed).toBe(1500);
|
|
461
|
+
});
|
|
462
|
+
|
|
463
|
+
it("returns empty when no DB", async () => {
|
|
464
|
+
expect(await listTaskRuns("task-123")).toEqual([]);
|
|
465
|
+
});
|
|
466
|
+
|
|
467
|
+
it("returns empty on DB error", async () => {
|
|
468
|
+
enableInternalDB();
|
|
469
|
+
queryThrow = new Error("fail");
|
|
470
|
+
expect(await listTaskRuns("task-123")).toEqual([]);
|
|
471
|
+
});
|
|
472
|
+
});
|
|
473
|
+
|
|
474
|
+
// -------------------------------------------------------------------------
|
|
475
|
+
// getTasksDueForExecution
|
|
476
|
+
// -------------------------------------------------------------------------
|
|
477
|
+
|
|
478
|
+
describe("getTasksDueForExecution()", () => {
|
|
479
|
+
it("returns due tasks", async () => {
|
|
480
|
+
enableInternalDB();
|
|
481
|
+
setResults({ rows: [makeTaskRow()] });
|
|
482
|
+
const tasks = await getTasksDueForExecution();
|
|
483
|
+
expect(tasks).toHaveLength(1);
|
|
484
|
+
expect(queryCalls[0].sql).toContain("enabled = true");
|
|
485
|
+
expect(queryCalls[0].sql).toContain("next_run_at <= now()");
|
|
486
|
+
});
|
|
487
|
+
|
|
488
|
+
it("returns empty when no DB", async () => {
|
|
489
|
+
expect(await getTasksDueForExecution()).toEqual([]);
|
|
490
|
+
});
|
|
491
|
+
|
|
492
|
+
it("returns empty on DB error", async () => {
|
|
493
|
+
enableInternalDB();
|
|
494
|
+
queryThrow = new Error("fail");
|
|
495
|
+
expect(await getTasksDueForExecution()).toEqual([]);
|
|
496
|
+
});
|
|
497
|
+
});
|
|
498
|
+
|
|
499
|
+
// -------------------------------------------------------------------------
|
|
500
|
+
// lockTaskForExecution
|
|
501
|
+
// -------------------------------------------------------------------------
|
|
502
|
+
|
|
503
|
+
describe("lockTaskForExecution()", () => {
|
|
504
|
+
it("returns true when lock acquired", async () => {
|
|
505
|
+
enableInternalDB();
|
|
506
|
+
// First call: SELECT task (getScheduledTask to read cron expression)
|
|
507
|
+
// Second call: UPDATE with atomic lock (next_run_at IS NOT NULL)
|
|
508
|
+
setResults(
|
|
509
|
+
{ rows: [makeTaskRow()] },
|
|
510
|
+
{ rows: [{ id: "task-123" }] },
|
|
511
|
+
);
|
|
512
|
+
|
|
513
|
+
const result = await lockTaskForExecution("task-123");
|
|
514
|
+
expect(result).toBe(true);
|
|
515
|
+
// First query is the SELECT to read cron
|
|
516
|
+
expect(queryCalls[0].sql).toContain("SELECT");
|
|
517
|
+
// Second query is the atomic UPDATE
|
|
518
|
+
expect(queryCalls[1].sql).toContain("UPDATE scheduled_tasks");
|
|
519
|
+
expect(queryCalls[1].sql).toContain("last_run_at = now()");
|
|
520
|
+
expect(queryCalls[1].sql).toContain("next_run_at IS NOT NULL");
|
|
521
|
+
});
|
|
522
|
+
|
|
523
|
+
it("returns false when task not found", async () => {
|
|
524
|
+
enableInternalDB();
|
|
525
|
+
// getScheduledTask returns empty
|
|
526
|
+
setResults({ rows: [] });
|
|
527
|
+
expect(await lockTaskForExecution("missing")).toBe(false);
|
|
528
|
+
});
|
|
529
|
+
|
|
530
|
+
it("returns false when UPDATE matches no rows (already locked)", async () => {
|
|
531
|
+
enableInternalDB();
|
|
532
|
+
// getScheduledTask succeeds, but UPDATE returns empty (already locked)
|
|
533
|
+
setResults(
|
|
534
|
+
{ rows: [makeTaskRow()] },
|
|
535
|
+
{ rows: [] },
|
|
536
|
+
);
|
|
537
|
+
expect(await lockTaskForExecution("task-123")).toBe(false);
|
|
538
|
+
});
|
|
539
|
+
|
|
540
|
+
it("returns false when no DB", async () => {
|
|
541
|
+
expect(await lockTaskForExecution("task-123")).toBe(false);
|
|
542
|
+
});
|
|
543
|
+
|
|
544
|
+
it("returns false on DB error", async () => {
|
|
545
|
+
enableInternalDB();
|
|
546
|
+
queryThrow = new Error("fail");
|
|
547
|
+
expect(await lockTaskForExecution("task-123")).toBe(false);
|
|
548
|
+
});
|
|
549
|
+
});
|
|
550
|
+
});
|