@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,847 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Route-level tests for /api/slack endpoints.
|
|
3
|
+
*
|
|
4
|
+
* Mocks the agent, Slack API calls, and internal DB to isolate route logic.
|
|
5
|
+
* Tests signature verification, slash command ack, events API, and OAuth.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import {
|
|
9
|
+
describe,
|
|
10
|
+
it,
|
|
11
|
+
expect,
|
|
12
|
+
beforeEach,
|
|
13
|
+
afterEach,
|
|
14
|
+
mock,
|
|
15
|
+
type Mock,
|
|
16
|
+
} from "bun:test";
|
|
17
|
+
import crypto from "crypto";
|
|
18
|
+
|
|
19
|
+
// --- Mocks ---
|
|
20
|
+
|
|
21
|
+
const mockRunAgent: Mock<(opts: unknown) => Promise<{
|
|
22
|
+
text: Promise<string>;
|
|
23
|
+
steps: Promise<{ toolResults: unknown[] }[]>;
|
|
24
|
+
totalUsage: Promise<{ inputTokens: number; outputTokens: number }>;
|
|
25
|
+
}>> = mock(() =>
|
|
26
|
+
Promise.resolve({
|
|
27
|
+
text: Promise.resolve("42 active users"),
|
|
28
|
+
steps: Promise.resolve([]),
|
|
29
|
+
totalUsage: Promise.resolve({ inputTokens: 100, outputTokens: 50 }),
|
|
30
|
+
}),
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
mock.module("@atlas/api/lib/agent", () => ({
|
|
34
|
+
runAgent: mockRunAgent,
|
|
35
|
+
}));
|
|
36
|
+
|
|
37
|
+
const mockPostMessage: Mock<(token: string, params: unknown) => Promise<{ ok: boolean; ts?: string }>> = mock(() =>
|
|
38
|
+
Promise.resolve({ ok: true, ts: "1234567890.123456" }),
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
const mockUpdateMessage: Mock<(token: string, params: unknown) => Promise<{ ok: boolean }>> = mock(() =>
|
|
42
|
+
Promise.resolve({ ok: true }),
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
const mockSlackAPI: Mock<(method: string, token: string, body: unknown) => Promise<{ ok: boolean; team?: unknown; access_token?: string }>> = mock(() =>
|
|
46
|
+
Promise.resolve({ ok: true }),
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
const mockPostEphemeral: Mock<(token: string, params: unknown) => Promise<{ ok: boolean }>> = mock(() =>
|
|
50
|
+
Promise.resolve({ ok: true }),
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
mock.module("@atlas/api/lib/slack/api", () => ({
|
|
54
|
+
postMessage: mockPostMessage,
|
|
55
|
+
updateMessage: mockUpdateMessage,
|
|
56
|
+
postEphemeral: mockPostEphemeral,
|
|
57
|
+
slackAPI: mockSlackAPI,
|
|
58
|
+
}));
|
|
59
|
+
|
|
60
|
+
const mockApproveAction: Mock<(actionId: string, approverId: string) => Promise<Record<string, unknown> | null>> = mock(() =>
|
|
61
|
+
Promise.resolve({ id: "act-001", status: "executed", action_type: "notification", target: "#revenue", summary: "Send notification" }),
|
|
62
|
+
);
|
|
63
|
+
const mockDenyAction: Mock<(actionId: string, denierId: string, reason?: string) => Promise<Record<string, unknown> | null>> = mock(() =>
|
|
64
|
+
Promise.resolve({ id: "act-001", status: "denied", action_type: "notification", target: "#revenue", summary: "Send notification" }),
|
|
65
|
+
);
|
|
66
|
+
const mockGetAction: Mock<(actionId: string) => Promise<Record<string, unknown> | null>> = mock(() =>
|
|
67
|
+
Promise.resolve({ id: "act-001", status: "pending", action_type: "notification", target: "#revenue", summary: "Send notification" }),
|
|
68
|
+
);
|
|
69
|
+
|
|
70
|
+
mock.module("@atlas/api/lib/tools/actions/handler", () => ({
|
|
71
|
+
approveAction: mockApproveAction,
|
|
72
|
+
denyAction: mockDenyAction,
|
|
73
|
+
getAction: mockGetAction,
|
|
74
|
+
handleAction: mock(() => Promise.resolve({ status: "pending_approval", actionId: "act-001" })),
|
|
75
|
+
buildActionRequest: mock(() => ({ id: "act-001" })),
|
|
76
|
+
getActionConfig: mock(() => ({ approval: "manual" })),
|
|
77
|
+
registerActionExecutor: mock(() => {}),
|
|
78
|
+
getActionExecutor: mock(() => undefined),
|
|
79
|
+
listPendingActions: mock(() => Promise.resolve([])),
|
|
80
|
+
_resetActionStore: mock(() => {}),
|
|
81
|
+
}));
|
|
82
|
+
|
|
83
|
+
const mockGetBotToken: Mock<(teamId: string) => Promise<string | null>> = mock(() =>
|
|
84
|
+
Promise.resolve("xoxb-test-token"),
|
|
85
|
+
);
|
|
86
|
+
|
|
87
|
+
const mockSaveInstallation: Mock<(teamId: string, token: string) => Promise<void>> = mock(() => Promise.resolve());
|
|
88
|
+
|
|
89
|
+
mock.module("@atlas/api/lib/slack/store", () => ({
|
|
90
|
+
getBotToken: mockGetBotToken,
|
|
91
|
+
saveInstallation: mockSaveInstallation,
|
|
92
|
+
}));
|
|
93
|
+
|
|
94
|
+
const mockGetConversationId: Mock<(channelId: string, threadTs: string) => Promise<string | null>> = mock(() =>
|
|
95
|
+
Promise.resolve(null),
|
|
96
|
+
);
|
|
97
|
+
|
|
98
|
+
const mockSetConversationId: Mock<(channelId: string, threadTs: string, conversationId: string) => void> = mock(() => {});
|
|
99
|
+
|
|
100
|
+
mock.module("@atlas/api/lib/slack/threads", () => ({
|
|
101
|
+
getConversationId: mockGetConversationId,
|
|
102
|
+
setConversationId: mockSetConversationId,
|
|
103
|
+
}));
|
|
104
|
+
|
|
105
|
+
const mockCreateConversation: Mock<(opts: Record<string, unknown>) => Promise<{ id: string } | null>> = mock(() =>
|
|
106
|
+
Promise.resolve({ id: "conv-123" }),
|
|
107
|
+
);
|
|
108
|
+
|
|
109
|
+
const mockAddMessage: Mock<(opts: Record<string, unknown>) => void> = mock(() => {});
|
|
110
|
+
|
|
111
|
+
const mockGetConversation: Mock<(id: string, userId?: string | null) => Promise<Record<string, unknown> | null>> = mock(() =>
|
|
112
|
+
Promise.resolve(null),
|
|
113
|
+
);
|
|
114
|
+
|
|
115
|
+
const mockGenerateTitle: Mock<(question: string) => string> = mock((q: string) => q.slice(0, 80));
|
|
116
|
+
|
|
117
|
+
mock.module("@atlas/api/lib/conversations", () => ({
|
|
118
|
+
createConversation: mockCreateConversation,
|
|
119
|
+
addMessage: mockAddMessage,
|
|
120
|
+
getConversation: mockGetConversation,
|
|
121
|
+
generateTitle: mockGenerateTitle,
|
|
122
|
+
listConversations: mock(() => Promise.resolve({ conversations: [], total: 0 })),
|
|
123
|
+
deleteConversation: mock(() => Promise.resolve(false)),
|
|
124
|
+
starConversation: async () => false,
|
|
125
|
+
}));
|
|
126
|
+
|
|
127
|
+
const mockCheckRateLimit: Mock<(key: string) => { allowed: boolean; retryAfterMs?: number }> = mock(() =>
|
|
128
|
+
({ allowed: true }),
|
|
129
|
+
);
|
|
130
|
+
|
|
131
|
+
mock.module("@atlas/api/lib/auth/middleware", () => ({
|
|
132
|
+
checkRateLimit: mockCheckRateLimit,
|
|
133
|
+
authenticateRequest: mock(() => Promise.resolve({ mode: "none" as const, user: null })),
|
|
134
|
+
getClientIP: mock(() => "127.0.0.1"),
|
|
135
|
+
_stopCleanup: mock(() => {}),
|
|
136
|
+
}));
|
|
137
|
+
|
|
138
|
+
// --- Test setup ---
|
|
139
|
+
|
|
140
|
+
const SIGNING_SECRET = "test_secret_for_tests";
|
|
141
|
+
|
|
142
|
+
function makeSignature(body: string, timestamp?: string): {
|
|
143
|
+
signature: string;
|
|
144
|
+
timestamp: string;
|
|
145
|
+
} {
|
|
146
|
+
const ts = timestamp ?? String(Math.floor(Date.now() / 1000));
|
|
147
|
+
const sigBasestring = `v0:${ts}:${body}`;
|
|
148
|
+
const sig =
|
|
149
|
+
"v0=" +
|
|
150
|
+
crypto.createHmac("sha256", SIGNING_SECRET).update(sigBasestring).digest("hex");
|
|
151
|
+
return { signature: sig, timestamp: ts };
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// Dynamic import so env vars are set before module loads
|
|
155
|
+
async function getApp() {
|
|
156
|
+
const { app } = await import("../../api/index");
|
|
157
|
+
return app;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
describe("/api/slack", () => {
|
|
161
|
+
const savedSigningSecret = process.env.SLACK_SIGNING_SECRET;
|
|
162
|
+
const savedClientId = process.env.SLACK_CLIENT_ID;
|
|
163
|
+
const savedClientSecret = process.env.SLACK_CLIENT_SECRET;
|
|
164
|
+
|
|
165
|
+
beforeEach(() => {
|
|
166
|
+
process.env.SLACK_SIGNING_SECRET = SIGNING_SECRET;
|
|
167
|
+
mockRunAgent.mockClear();
|
|
168
|
+
mockPostMessage.mockClear();
|
|
169
|
+
mockUpdateMessage.mockClear();
|
|
170
|
+
mockPostEphemeral.mockClear();
|
|
171
|
+
mockSlackAPI.mockClear();
|
|
172
|
+
mockGetBotToken.mockClear();
|
|
173
|
+
mockSaveInstallation.mockClear();
|
|
174
|
+
mockGetConversationId.mockClear();
|
|
175
|
+
mockSetConversationId.mockClear();
|
|
176
|
+
mockCreateConversation.mockClear();
|
|
177
|
+
mockAddMessage.mockClear();
|
|
178
|
+
mockGetConversation.mockClear();
|
|
179
|
+
mockGenerateTitle.mockClear();
|
|
180
|
+
mockCheckRateLimit.mockClear();
|
|
181
|
+
mockApproveAction.mockClear();
|
|
182
|
+
mockDenyAction.mockClear();
|
|
183
|
+
mockGetAction.mockClear();
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
afterEach(() => {
|
|
187
|
+
// Restore only the vars we changed — never replace process.env entirely
|
|
188
|
+
if (savedSigningSecret !== undefined) process.env.SLACK_SIGNING_SECRET = savedSigningSecret;
|
|
189
|
+
else delete process.env.SLACK_SIGNING_SECRET;
|
|
190
|
+
if (savedClientId !== undefined) process.env.SLACK_CLIENT_ID = savedClientId;
|
|
191
|
+
else delete process.env.SLACK_CLIENT_ID;
|
|
192
|
+
if (savedClientSecret !== undefined) process.env.SLACK_CLIENT_SECRET = savedClientSecret;
|
|
193
|
+
else delete process.env.SLACK_CLIENT_SECRET;
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
describe("POST /api/slack/commands", () => {
|
|
197
|
+
it("acks a slash command with 200 and in_channel response", async () => {
|
|
198
|
+
const app = await getApp();
|
|
199
|
+
const body = "token=xxx&team_id=T123&channel_id=C456&user_id=U789&text=how+many+users";
|
|
200
|
+
const { signature, timestamp } = makeSignature(body);
|
|
201
|
+
|
|
202
|
+
const resp = await app.request("/api/slack/commands", {
|
|
203
|
+
method: "POST",
|
|
204
|
+
headers: {
|
|
205
|
+
"Content-Type": "application/x-www-form-urlencoded",
|
|
206
|
+
"x-slack-signature": signature,
|
|
207
|
+
"x-slack-request-timestamp": timestamp,
|
|
208
|
+
},
|
|
209
|
+
body,
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
expect(resp.status).toBe(200);
|
|
213
|
+
const json = (await resp.json()) as Record<string, unknown>;
|
|
214
|
+
expect(json.response_type).toBe("in_channel");
|
|
215
|
+
expect(json.text).toContain("Processing");
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
it("returns usage hint for empty text", async () => {
|
|
219
|
+
const app = await getApp();
|
|
220
|
+
const body = "token=xxx&team_id=T123&channel_id=C456&user_id=U789&text=";
|
|
221
|
+
const { signature, timestamp } = makeSignature(body);
|
|
222
|
+
|
|
223
|
+
const resp = await app.request("/api/slack/commands", {
|
|
224
|
+
method: "POST",
|
|
225
|
+
headers: {
|
|
226
|
+
"Content-Type": "application/x-www-form-urlencoded",
|
|
227
|
+
"x-slack-signature": signature,
|
|
228
|
+
"x-slack-request-timestamp": timestamp,
|
|
229
|
+
},
|
|
230
|
+
body,
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
expect(resp.status).toBe(200);
|
|
234
|
+
const json = (await resp.json()) as Record<string, unknown>;
|
|
235
|
+
expect(json.response_type).toBe("ephemeral");
|
|
236
|
+
expect(json.text).toContain("Usage");
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
it("rejects unsigned requests with 401", async () => {
|
|
240
|
+
const app = await getApp();
|
|
241
|
+
const body = "token=xxx&text=hello";
|
|
242
|
+
|
|
243
|
+
const resp = await app.request("/api/slack/commands", {
|
|
244
|
+
method: "POST",
|
|
245
|
+
headers: {
|
|
246
|
+
"Content-Type": "application/x-www-form-urlencoded",
|
|
247
|
+
"x-slack-signature": "v0=invalid",
|
|
248
|
+
"x-slack-request-timestamp": String(Math.floor(Date.now() / 1000)),
|
|
249
|
+
},
|
|
250
|
+
body,
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
expect(resp.status).toBe(401);
|
|
254
|
+
});
|
|
255
|
+
});
|
|
256
|
+
|
|
257
|
+
describe("POST /api/slack/events", () => {
|
|
258
|
+
it("responds to url_verification challenge", async () => {
|
|
259
|
+
const app = await getApp();
|
|
260
|
+
const payload = JSON.stringify({
|
|
261
|
+
type: "url_verification",
|
|
262
|
+
challenge: "test_challenge_string",
|
|
263
|
+
});
|
|
264
|
+
const { signature, timestamp } = makeSignature(payload);
|
|
265
|
+
|
|
266
|
+
const resp = await app.request("/api/slack/events", {
|
|
267
|
+
method: "POST",
|
|
268
|
+
headers: {
|
|
269
|
+
"Content-Type": "application/json",
|
|
270
|
+
"x-slack-signature": signature,
|
|
271
|
+
"x-slack-request-timestamp": timestamp,
|
|
272
|
+
},
|
|
273
|
+
body: payload,
|
|
274
|
+
});
|
|
275
|
+
|
|
276
|
+
expect(resp.status).toBe(200);
|
|
277
|
+
const json = (await resp.json()) as Record<string, unknown>;
|
|
278
|
+
expect(json.challenge).toBe("test_challenge_string");
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
it("ignores bot messages", async () => {
|
|
282
|
+
const app = await getApp();
|
|
283
|
+
const payload = JSON.stringify({
|
|
284
|
+
type: "event_callback",
|
|
285
|
+
team_id: "T123",
|
|
286
|
+
event: {
|
|
287
|
+
type: "message",
|
|
288
|
+
bot_id: "B123",
|
|
289
|
+
text: "I am a bot",
|
|
290
|
+
channel: "C456",
|
|
291
|
+
thread_ts: "1234567890.000001",
|
|
292
|
+
},
|
|
293
|
+
});
|
|
294
|
+
const { signature, timestamp } = makeSignature(payload);
|
|
295
|
+
|
|
296
|
+
const resp = await app.request("/api/slack/events", {
|
|
297
|
+
method: "POST",
|
|
298
|
+
headers: {
|
|
299
|
+
"Content-Type": "application/json",
|
|
300
|
+
"x-slack-signature": signature,
|
|
301
|
+
"x-slack-request-timestamp": timestamp,
|
|
302
|
+
},
|
|
303
|
+
body: payload,
|
|
304
|
+
});
|
|
305
|
+
|
|
306
|
+
expect(resp.status).toBe(200);
|
|
307
|
+
// Should not have triggered any agent call
|
|
308
|
+
expect(mockRunAgent).not.toHaveBeenCalled();
|
|
309
|
+
});
|
|
310
|
+
|
|
311
|
+
it("rejects invalid signatures for event callbacks", async () => {
|
|
312
|
+
const app = await getApp();
|
|
313
|
+
const payload = JSON.stringify({
|
|
314
|
+
type: "event_callback",
|
|
315
|
+
team_id: "T123",
|
|
316
|
+
event: {
|
|
317
|
+
type: "message",
|
|
318
|
+
text: "follow-up question",
|
|
319
|
+
channel: "C456",
|
|
320
|
+
thread_ts: "1234567890.000001",
|
|
321
|
+
},
|
|
322
|
+
});
|
|
323
|
+
|
|
324
|
+
const resp = await app.request("/api/slack/events", {
|
|
325
|
+
method: "POST",
|
|
326
|
+
headers: {
|
|
327
|
+
"Content-Type": "application/json",
|
|
328
|
+
"x-slack-signature": "v0=invalid",
|
|
329
|
+
"x-slack-request-timestamp": String(Math.floor(Date.now() / 1000)),
|
|
330
|
+
},
|
|
331
|
+
body: payload,
|
|
332
|
+
});
|
|
333
|
+
|
|
334
|
+
expect(resp.status).toBe(401);
|
|
335
|
+
});
|
|
336
|
+
|
|
337
|
+
it("rejects url_verification with invalid signature", async () => {
|
|
338
|
+
const app = await getApp();
|
|
339
|
+
const payload = JSON.stringify({
|
|
340
|
+
type: "url_verification",
|
|
341
|
+
challenge: "should_not_echo",
|
|
342
|
+
});
|
|
343
|
+
|
|
344
|
+
const resp = await app.request("/api/slack/events", {
|
|
345
|
+
method: "POST",
|
|
346
|
+
headers: {
|
|
347
|
+
"Content-Type": "application/json",
|
|
348
|
+
"x-slack-signature": "v0=bad_signature",
|
|
349
|
+
"x-slack-request-timestamp": String(Math.floor(Date.now() / 1000)),
|
|
350
|
+
},
|
|
351
|
+
body: payload,
|
|
352
|
+
});
|
|
353
|
+
|
|
354
|
+
expect(resp.status).toBe(401);
|
|
355
|
+
const json = (await resp.json()) as Record<string, unknown>;
|
|
356
|
+
expect(json.error).toBe("Invalid signature");
|
|
357
|
+
});
|
|
358
|
+
|
|
359
|
+
it("processes thread follow-up events and calls the agent", async () => {
|
|
360
|
+
const app = await getApp();
|
|
361
|
+
const payload = JSON.stringify({
|
|
362
|
+
type: "event_callback",
|
|
363
|
+
team_id: "T123",
|
|
364
|
+
event: {
|
|
365
|
+
type: "message",
|
|
366
|
+
text: "what about last quarter?",
|
|
367
|
+
channel: "C456",
|
|
368
|
+
thread_ts: "1234567890.000001",
|
|
369
|
+
},
|
|
370
|
+
});
|
|
371
|
+
const { signature, timestamp } = makeSignature(payload);
|
|
372
|
+
|
|
373
|
+
const resp = await app.request("/api/slack/events", {
|
|
374
|
+
method: "POST",
|
|
375
|
+
headers: {
|
|
376
|
+
"Content-Type": "application/json",
|
|
377
|
+
"x-slack-signature": signature,
|
|
378
|
+
"x-slack-request-timestamp": timestamp,
|
|
379
|
+
},
|
|
380
|
+
body: payload,
|
|
381
|
+
});
|
|
382
|
+
|
|
383
|
+
// Should ack immediately
|
|
384
|
+
expect(resp.status).toBe(200);
|
|
385
|
+
|
|
386
|
+
// Wait for async fire-and-forget processing
|
|
387
|
+
await new Promise((r) => setTimeout(r, 100));
|
|
388
|
+
|
|
389
|
+
expect(mockRunAgent).toHaveBeenCalled();
|
|
390
|
+
});
|
|
391
|
+
});
|
|
392
|
+
|
|
393
|
+
describe("async processing", () => {
|
|
394
|
+
it("posts thinking message, runs agent, and updates message for slash commands", async () => {
|
|
395
|
+
const app = await getApp();
|
|
396
|
+
const body =
|
|
397
|
+
"token=xxx&team_id=T123&channel_id=C456&user_id=U789&text=how+many+active+users";
|
|
398
|
+
const { signature, timestamp } = makeSignature(body);
|
|
399
|
+
|
|
400
|
+
const resp = await app.request("/api/slack/commands", {
|
|
401
|
+
method: "POST",
|
|
402
|
+
headers: {
|
|
403
|
+
"Content-Type": "application/x-www-form-urlencoded",
|
|
404
|
+
"x-slack-signature": signature,
|
|
405
|
+
"x-slack-request-timestamp": timestamp,
|
|
406
|
+
},
|
|
407
|
+
body,
|
|
408
|
+
});
|
|
409
|
+
|
|
410
|
+
expect(resp.status).toBe(200);
|
|
411
|
+
|
|
412
|
+
// Wait for async fire-and-forget processing
|
|
413
|
+
await new Promise((r) => setTimeout(r, 100));
|
|
414
|
+
|
|
415
|
+
// Thinking message was posted
|
|
416
|
+
expect(mockPostMessage).toHaveBeenCalled();
|
|
417
|
+
// Agent was called
|
|
418
|
+
expect(mockRunAgent).toHaveBeenCalled();
|
|
419
|
+
// Result was sent back by updating the thinking message
|
|
420
|
+
expect(mockUpdateMessage).toHaveBeenCalled();
|
|
421
|
+
});
|
|
422
|
+
});
|
|
423
|
+
|
|
424
|
+
describe("conversation persistence", () => {
|
|
425
|
+
it("creates conversation for slash commands", async () => {
|
|
426
|
+
const app = await getApp();
|
|
427
|
+
const body =
|
|
428
|
+
"token=xxx&team_id=T123&channel_id=C456&user_id=U789&text=how+many+active+users";
|
|
429
|
+
const { signature, timestamp } = makeSignature(body);
|
|
430
|
+
|
|
431
|
+
await app.request("/api/slack/commands", {
|
|
432
|
+
method: "POST",
|
|
433
|
+
headers: {
|
|
434
|
+
"Content-Type": "application/x-www-form-urlencoded",
|
|
435
|
+
"x-slack-signature": signature,
|
|
436
|
+
"x-slack-request-timestamp": timestamp,
|
|
437
|
+
},
|
|
438
|
+
body,
|
|
439
|
+
});
|
|
440
|
+
|
|
441
|
+
await new Promise((r) => setTimeout(r, 100));
|
|
442
|
+
|
|
443
|
+
expect(mockCreateConversation).toHaveBeenCalledWith(
|
|
444
|
+
expect.objectContaining({
|
|
445
|
+
surface: "slack",
|
|
446
|
+
title: expect.any(String),
|
|
447
|
+
}),
|
|
448
|
+
);
|
|
449
|
+
// Messages persisted
|
|
450
|
+
expect(mockAddMessage).toHaveBeenCalledTimes(2);
|
|
451
|
+
});
|
|
452
|
+
|
|
453
|
+
it("loads conversation history for thread follow-ups", async () => {
|
|
454
|
+
// Set up: conversation exists with prior messages
|
|
455
|
+
mockGetConversationId.mockResolvedValueOnce("conv-existing");
|
|
456
|
+
mockGetConversation.mockResolvedValueOnce({
|
|
457
|
+
id: "conv-existing",
|
|
458
|
+
messages: [
|
|
459
|
+
{ id: "m1", conversationId: "conv-existing", role: "user", content: "initial question", createdAt: "2024-01-01" },
|
|
460
|
+
{ id: "m2", conversationId: "conv-existing", role: "assistant", content: "initial answer", createdAt: "2024-01-01" },
|
|
461
|
+
],
|
|
462
|
+
});
|
|
463
|
+
|
|
464
|
+
const app = await getApp();
|
|
465
|
+
const payload = JSON.stringify({
|
|
466
|
+
type: "event_callback",
|
|
467
|
+
team_id: "T123",
|
|
468
|
+
event: {
|
|
469
|
+
type: "message",
|
|
470
|
+
text: "what about last quarter?",
|
|
471
|
+
channel: "C456",
|
|
472
|
+
thread_ts: "1234567890.000001",
|
|
473
|
+
},
|
|
474
|
+
});
|
|
475
|
+
const { signature, timestamp } = makeSignature(payload);
|
|
476
|
+
|
|
477
|
+
await app.request("/api/slack/events", {
|
|
478
|
+
method: "POST",
|
|
479
|
+
headers: {
|
|
480
|
+
"Content-Type": "application/json",
|
|
481
|
+
"x-slack-signature": signature,
|
|
482
|
+
"x-slack-request-timestamp": timestamp,
|
|
483
|
+
},
|
|
484
|
+
body: payload,
|
|
485
|
+
});
|
|
486
|
+
|
|
487
|
+
await new Promise((r) => setTimeout(r, 100));
|
|
488
|
+
|
|
489
|
+
// Should have loaded conversation
|
|
490
|
+
expect(mockGetConversation).toHaveBeenCalledWith("conv-existing");
|
|
491
|
+
// Agent was called (priorMessages passed internally)
|
|
492
|
+
expect(mockRunAgent).toHaveBeenCalled();
|
|
493
|
+
// New messages persisted
|
|
494
|
+
expect(mockAddMessage).toHaveBeenCalledTimes(2);
|
|
495
|
+
});
|
|
496
|
+
|
|
497
|
+
it("handles thread follow-ups without prior conversation gracefully", async () => {
|
|
498
|
+
// No conversation mapping exists
|
|
499
|
+
mockGetConversationId.mockResolvedValueOnce(null);
|
|
500
|
+
|
|
501
|
+
const app = await getApp();
|
|
502
|
+
const payload = JSON.stringify({
|
|
503
|
+
type: "event_callback",
|
|
504
|
+
team_id: "T123",
|
|
505
|
+
event: {
|
|
506
|
+
type: "message",
|
|
507
|
+
text: "what about last quarter?",
|
|
508
|
+
channel: "C456",
|
|
509
|
+
thread_ts: "1234567890.000001",
|
|
510
|
+
},
|
|
511
|
+
});
|
|
512
|
+
const { signature, timestamp } = makeSignature(payload);
|
|
513
|
+
|
|
514
|
+
await app.request("/api/slack/events", {
|
|
515
|
+
method: "POST",
|
|
516
|
+
headers: {
|
|
517
|
+
"Content-Type": "application/json",
|
|
518
|
+
"x-slack-signature": signature,
|
|
519
|
+
"x-slack-request-timestamp": timestamp,
|
|
520
|
+
},
|
|
521
|
+
body: payload,
|
|
522
|
+
});
|
|
523
|
+
|
|
524
|
+
await new Promise((r) => setTimeout(r, 100));
|
|
525
|
+
|
|
526
|
+
// Agent still called — just without prior context
|
|
527
|
+
expect(mockRunAgent).toHaveBeenCalled();
|
|
528
|
+
// No conversation to load
|
|
529
|
+
expect(mockGetConversation).not.toHaveBeenCalled();
|
|
530
|
+
// No messages persisted (no conversationId)
|
|
531
|
+
expect(mockAddMessage).not.toHaveBeenCalled();
|
|
532
|
+
});
|
|
533
|
+
});
|
|
534
|
+
|
|
535
|
+
describe("rate limiting", () => {
|
|
536
|
+
it("returns rate limit message for slash commands", async () => {
|
|
537
|
+
mockCheckRateLimit.mockReturnValueOnce({ allowed: false, retryAfterMs: 30000 });
|
|
538
|
+
|
|
539
|
+
const app = await getApp();
|
|
540
|
+
const body =
|
|
541
|
+
"token=xxx&team_id=T123&channel_id=C456&user_id=U789&text=how+many+users";
|
|
542
|
+
const { signature, timestamp } = makeSignature(body);
|
|
543
|
+
|
|
544
|
+
const resp = await app.request("/api/slack/commands", {
|
|
545
|
+
method: "POST",
|
|
546
|
+
headers: {
|
|
547
|
+
"Content-Type": "application/x-www-form-urlencoded",
|
|
548
|
+
"x-slack-signature": signature,
|
|
549
|
+
"x-slack-request-timestamp": timestamp,
|
|
550
|
+
},
|
|
551
|
+
body,
|
|
552
|
+
});
|
|
553
|
+
|
|
554
|
+
// Should still ack immediately
|
|
555
|
+
expect(resp.status).toBe(200);
|
|
556
|
+
|
|
557
|
+
// Wait for async processing
|
|
558
|
+
await new Promise((r) => setTimeout(r, 100));
|
|
559
|
+
|
|
560
|
+
// Rate limit message posted, agent NOT called
|
|
561
|
+
expect(mockPostMessage).toHaveBeenCalledWith(
|
|
562
|
+
"xoxb-test-token",
|
|
563
|
+
expect.objectContaining({ text: expect.stringContaining("Rate limit") }),
|
|
564
|
+
);
|
|
565
|
+
expect(mockRunAgent).not.toHaveBeenCalled();
|
|
566
|
+
});
|
|
567
|
+
|
|
568
|
+
it("returns rate limit message for thread follow-ups", async () => {
|
|
569
|
+
mockCheckRateLimit.mockReturnValueOnce({ allowed: false, retryAfterMs: 30000 });
|
|
570
|
+
|
|
571
|
+
const app = await getApp();
|
|
572
|
+
const payload = JSON.stringify({
|
|
573
|
+
type: "event_callback",
|
|
574
|
+
team_id: "T123",
|
|
575
|
+
event: {
|
|
576
|
+
type: "message",
|
|
577
|
+
text: "what about last quarter?",
|
|
578
|
+
channel: "C456",
|
|
579
|
+
thread_ts: "1234567890.000001",
|
|
580
|
+
},
|
|
581
|
+
});
|
|
582
|
+
const { signature, timestamp } = makeSignature(payload);
|
|
583
|
+
|
|
584
|
+
const resp = await app.request("/api/slack/events", {
|
|
585
|
+
method: "POST",
|
|
586
|
+
headers: {
|
|
587
|
+
"Content-Type": "application/json",
|
|
588
|
+
"x-slack-signature": signature,
|
|
589
|
+
"x-slack-request-timestamp": timestamp,
|
|
590
|
+
},
|
|
591
|
+
body: payload,
|
|
592
|
+
});
|
|
593
|
+
|
|
594
|
+
expect(resp.status).toBe(200);
|
|
595
|
+
|
|
596
|
+
// Wait for async processing
|
|
597
|
+
await new Promise((r) => setTimeout(r, 100));
|
|
598
|
+
|
|
599
|
+
// Rate limit message posted in thread, agent NOT called
|
|
600
|
+
expect(mockPostMessage).toHaveBeenCalledWith(
|
|
601
|
+
"xoxb-test-token",
|
|
602
|
+
expect.objectContaining({
|
|
603
|
+
text: expect.stringContaining("Rate limit"),
|
|
604
|
+
thread_ts: "1234567890.000001",
|
|
605
|
+
}),
|
|
606
|
+
);
|
|
607
|
+
expect(mockRunAgent).not.toHaveBeenCalled();
|
|
608
|
+
});
|
|
609
|
+
});
|
|
610
|
+
|
|
611
|
+
describe("POST /api/slack/interactions", () => {
|
|
612
|
+
function makeInteractionPayload(actionId: string, action_id: string) {
|
|
613
|
+
return JSON.stringify({
|
|
614
|
+
type: "block_actions",
|
|
615
|
+
team: { id: "T123" },
|
|
616
|
+
user: { id: "U789" },
|
|
617
|
+
actions: [{ action_id, value: actionId }],
|
|
618
|
+
response_url: "https://hooks.slack.com/actions/test",
|
|
619
|
+
});
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
it("approves an action when approve button is clicked", async () => {
|
|
623
|
+
const app = await getApp();
|
|
624
|
+
const payload = makeInteractionPayload("act-001", "atlas_action_approve");
|
|
625
|
+
const formBody = `payload=${encodeURIComponent(payload)}`;
|
|
626
|
+
const { signature, timestamp } = makeSignature(formBody);
|
|
627
|
+
|
|
628
|
+
const resp = await app.request("/api/slack/interactions", {
|
|
629
|
+
method: "POST",
|
|
630
|
+
headers: {
|
|
631
|
+
"Content-Type": "application/x-www-form-urlencoded",
|
|
632
|
+
"x-slack-signature": signature,
|
|
633
|
+
"x-slack-request-timestamp": timestamp,
|
|
634
|
+
},
|
|
635
|
+
body: formBody,
|
|
636
|
+
});
|
|
637
|
+
|
|
638
|
+
expect(resp.status).toBe(200);
|
|
639
|
+
const json = (await resp.json()) as Record<string, unknown>;
|
|
640
|
+
expect(json.ok).toBe(true);
|
|
641
|
+
|
|
642
|
+
// Wait for async processing
|
|
643
|
+
await new Promise((r) => setTimeout(r, 100));
|
|
644
|
+
|
|
645
|
+
expect(mockGetAction).toHaveBeenCalledWith("act-001");
|
|
646
|
+
expect(mockApproveAction).toHaveBeenCalledWith("act-001", "slack:U789");
|
|
647
|
+
});
|
|
648
|
+
|
|
649
|
+
it("denies an action when deny button is clicked", async () => {
|
|
650
|
+
const app = await getApp();
|
|
651
|
+
const payload = makeInteractionPayload("act-001", "atlas_action_deny");
|
|
652
|
+
const formBody = `payload=${encodeURIComponent(payload)}`;
|
|
653
|
+
const { signature, timestamp } = makeSignature(formBody);
|
|
654
|
+
|
|
655
|
+
const resp = await app.request("/api/slack/interactions", {
|
|
656
|
+
method: "POST",
|
|
657
|
+
headers: {
|
|
658
|
+
"Content-Type": "application/x-www-form-urlencoded",
|
|
659
|
+
"x-slack-signature": signature,
|
|
660
|
+
"x-slack-request-timestamp": timestamp,
|
|
661
|
+
},
|
|
662
|
+
body: formBody,
|
|
663
|
+
});
|
|
664
|
+
|
|
665
|
+
expect(resp.status).toBe(200);
|
|
666
|
+
|
|
667
|
+
await new Promise((r) => setTimeout(r, 100));
|
|
668
|
+
|
|
669
|
+
expect(mockGetAction).toHaveBeenCalledWith("act-001");
|
|
670
|
+
expect(mockDenyAction).toHaveBeenCalledWith("act-001", "slack:U789");
|
|
671
|
+
});
|
|
672
|
+
|
|
673
|
+
it("rejects unsigned interaction requests with 401", async () => {
|
|
674
|
+
const app = await getApp();
|
|
675
|
+
const payload = makeInteractionPayload("act-001", "atlas_action_approve");
|
|
676
|
+
const formBody = `payload=${encodeURIComponent(payload)}`;
|
|
677
|
+
|
|
678
|
+
const resp = await app.request("/api/slack/interactions", {
|
|
679
|
+
method: "POST",
|
|
680
|
+
headers: {
|
|
681
|
+
"Content-Type": "application/x-www-form-urlencoded",
|
|
682
|
+
"x-slack-signature": "v0=invalid",
|
|
683
|
+
"x-slack-request-timestamp": String(Math.floor(Date.now() / 1000)),
|
|
684
|
+
},
|
|
685
|
+
body: formBody,
|
|
686
|
+
});
|
|
687
|
+
|
|
688
|
+
expect(resp.status).toBe(401);
|
|
689
|
+
});
|
|
690
|
+
|
|
691
|
+
it("returns 400 when payload is missing", async () => {
|
|
692
|
+
const app = await getApp();
|
|
693
|
+
const formBody = "no_payload_here=true";
|
|
694
|
+
const { signature, timestamp } = makeSignature(formBody);
|
|
695
|
+
|
|
696
|
+
const resp = await app.request("/api/slack/interactions", {
|
|
697
|
+
method: "POST",
|
|
698
|
+
headers: {
|
|
699
|
+
"Content-Type": "application/x-www-form-urlencoded",
|
|
700
|
+
"x-slack-signature": signature,
|
|
701
|
+
"x-slack-request-timestamp": timestamp,
|
|
702
|
+
},
|
|
703
|
+
body: formBody,
|
|
704
|
+
});
|
|
705
|
+
|
|
706
|
+
expect(resp.status).toBe(400);
|
|
707
|
+
const json = (await resp.json()) as Record<string, unknown>;
|
|
708
|
+
expect(json.error).toBe("Missing payload");
|
|
709
|
+
});
|
|
710
|
+
});
|
|
711
|
+
|
|
712
|
+
describe("GET /api/slack/install", () => {
|
|
713
|
+
it("redirects to Slack OAuth URL when configured", async () => {
|
|
714
|
+
process.env.SLACK_CLIENT_ID = "test_client_id";
|
|
715
|
+
const app = await getApp();
|
|
716
|
+
|
|
717
|
+
const resp = await app.request("/api/slack/install", {
|
|
718
|
+
method: "GET",
|
|
719
|
+
redirect: "manual",
|
|
720
|
+
});
|
|
721
|
+
|
|
722
|
+
expect(resp.status).toBe(302);
|
|
723
|
+
const location = resp.headers.get("location");
|
|
724
|
+
expect(location).toContain("slack.com/oauth/v2/authorize");
|
|
725
|
+
expect(location).toContain("test_client_id");
|
|
726
|
+
});
|
|
727
|
+
|
|
728
|
+
it("returns 501 when OAuth is not configured", async () => {
|
|
729
|
+
delete process.env.SLACK_CLIENT_ID;
|
|
730
|
+
const app = await getApp();
|
|
731
|
+
|
|
732
|
+
const resp = await app.request("/api/slack/install", { method: "GET" });
|
|
733
|
+
expect(resp.status).toBe(501);
|
|
734
|
+
});
|
|
735
|
+
});
|
|
736
|
+
|
|
737
|
+
describe("GET /api/slack/callback", () => {
|
|
738
|
+
it("completes OAuth flow and saves installation", async () => {
|
|
739
|
+
process.env.SLACK_CLIENT_ID = "test_client_id";
|
|
740
|
+
process.env.SLACK_CLIENT_SECRET = "test_client_secret";
|
|
741
|
+
|
|
742
|
+
mockSlackAPI.mockResolvedValueOnce({
|
|
743
|
+
ok: true,
|
|
744
|
+
team: { id: "T999" },
|
|
745
|
+
access_token: "xoxb-new-token",
|
|
746
|
+
});
|
|
747
|
+
|
|
748
|
+
const app = await getApp();
|
|
749
|
+
|
|
750
|
+
// Get state from install redirect
|
|
751
|
+
const installResp = await app.request("/api/slack/install", {
|
|
752
|
+
method: "GET",
|
|
753
|
+
redirect: "manual",
|
|
754
|
+
});
|
|
755
|
+
const location = installResp.headers.get("location") ?? "";
|
|
756
|
+
const stateParam = new URL(location).searchParams.get("state");
|
|
757
|
+
|
|
758
|
+
const resp = await app.request(
|
|
759
|
+
`/api/slack/callback?code=test_code&state=${stateParam}`,
|
|
760
|
+
{ method: "GET" },
|
|
761
|
+
);
|
|
762
|
+
expect(resp.status).toBe(200);
|
|
763
|
+
const html = await resp.text();
|
|
764
|
+
expect(html).toContain("Atlas installed!");
|
|
765
|
+
expect(mockSaveInstallation).toHaveBeenCalledWith("T999", "xoxb-new-token");
|
|
766
|
+
});
|
|
767
|
+
|
|
768
|
+
it("returns error HTML when OAuth response is missing team data", async () => {
|
|
769
|
+
process.env.SLACK_CLIENT_ID = "test_client_id";
|
|
770
|
+
process.env.SLACK_CLIENT_SECRET = "test_client_secret";
|
|
771
|
+
|
|
772
|
+
// ok: true but no team or access_token
|
|
773
|
+
mockSlackAPI.mockResolvedValueOnce({ ok: true });
|
|
774
|
+
|
|
775
|
+
const app = await getApp();
|
|
776
|
+
|
|
777
|
+
// Get a valid state
|
|
778
|
+
const installResp = await app.request("/api/slack/install", {
|
|
779
|
+
method: "GET",
|
|
780
|
+
redirect: "manual",
|
|
781
|
+
});
|
|
782
|
+
const location = installResp.headers.get("location") ?? "";
|
|
783
|
+
const stateParam = new URL(location).searchParams.get("state");
|
|
784
|
+
|
|
785
|
+
const resp = await app.request(
|
|
786
|
+
`/api/slack/callback?code=test_code&state=${stateParam}`,
|
|
787
|
+
{ method: "GET" },
|
|
788
|
+
);
|
|
789
|
+
expect(resp.status).toBe(500);
|
|
790
|
+
const html = await resp.text();
|
|
791
|
+
expect(html).toContain("Installation Failed");
|
|
792
|
+
expect(mockSaveInstallation).not.toHaveBeenCalled();
|
|
793
|
+
});
|
|
794
|
+
|
|
795
|
+
it("returns 400 when state parameter is invalid or missing", async () => {
|
|
796
|
+
process.env.SLACK_CLIENT_ID = "test_client_id";
|
|
797
|
+
process.env.SLACK_CLIENT_SECRET = "test_client_secret";
|
|
798
|
+
const app = await getApp();
|
|
799
|
+
|
|
800
|
+
// No state at all
|
|
801
|
+
const resp1 = await app.request("/api/slack/callback?code=test_code", {
|
|
802
|
+
method: "GET",
|
|
803
|
+
});
|
|
804
|
+
expect(resp1.status).toBe(400);
|
|
805
|
+
const json1 = (await resp1.json()) as Record<string, unknown>;
|
|
806
|
+
expect(json1.error).toContain("state");
|
|
807
|
+
|
|
808
|
+
// Bogus state value
|
|
809
|
+
const resp2 = await app.request(
|
|
810
|
+
"/api/slack/callback?code=test_code&state=bogus-state-value",
|
|
811
|
+
{ method: "GET" },
|
|
812
|
+
);
|
|
813
|
+
expect(resp2.status).toBe(400);
|
|
814
|
+
});
|
|
815
|
+
|
|
816
|
+
it("returns 400 when code parameter is missing", async () => {
|
|
817
|
+
process.env.SLACK_CLIENT_ID = "test_client_id";
|
|
818
|
+
process.env.SLACK_CLIENT_SECRET = "test_client_secret";
|
|
819
|
+
const app = await getApp();
|
|
820
|
+
|
|
821
|
+
// Need a valid state but no code
|
|
822
|
+
const installResp = await app.request("/api/slack/install", {
|
|
823
|
+
method: "GET",
|
|
824
|
+
redirect: "manual",
|
|
825
|
+
});
|
|
826
|
+
const location = installResp.headers.get("location") ?? "";
|
|
827
|
+
const stateParam = new URL(location).searchParams.get("state");
|
|
828
|
+
|
|
829
|
+
const resp = await app.request(
|
|
830
|
+
`/api/slack/callback?state=${stateParam}`,
|
|
831
|
+
{ method: "GET" },
|
|
832
|
+
);
|
|
833
|
+
expect(resp.status).toBe(400);
|
|
834
|
+
});
|
|
835
|
+
|
|
836
|
+
it("returns 501 when OAuth is not configured", async () => {
|
|
837
|
+
delete process.env.SLACK_CLIENT_ID;
|
|
838
|
+
delete process.env.SLACK_CLIENT_SECRET;
|
|
839
|
+
const app = await getApp();
|
|
840
|
+
|
|
841
|
+
const resp = await app.request("/api/slack/callback?code=test", {
|
|
842
|
+
method: "GET",
|
|
843
|
+
});
|
|
844
|
+
expect(resp.status).toBe(501);
|
|
845
|
+
});
|
|
846
|
+
});
|
|
847
|
+
});
|