@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,237 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tests for Slack Block Kit formatter.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { describe, it, expect } from "bun:test";
|
|
6
|
+
import {
|
|
7
|
+
formatQueryResponse,
|
|
8
|
+
formatErrorResponse,
|
|
9
|
+
formatActionApproval,
|
|
10
|
+
formatActionResult,
|
|
11
|
+
type SlackQueryResult,
|
|
12
|
+
type SlackBlock,
|
|
13
|
+
} from "../format";
|
|
14
|
+
import type { PendingAction } from "@atlas/api/lib/agent-query";
|
|
15
|
+
|
|
16
|
+
/** Helper: extract text from a section block */
|
|
17
|
+
function blockText(block: SlackBlock): string {
|
|
18
|
+
if (block.type === "section") return block.text.text;
|
|
19
|
+
return "";
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** Helper: extract context element texts */
|
|
23
|
+
function contextTexts(block: SlackBlock): string[] {
|
|
24
|
+
if (block.type === "context") return block.elements.map((e) => e.text);
|
|
25
|
+
return [];
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function makeResult(overrides: Partial<SlackQueryResult> = {}): SlackQueryResult {
|
|
29
|
+
return {
|
|
30
|
+
answer: "There were 1,234 active users last month.",
|
|
31
|
+
sql: ["SELECT COUNT(*) FROM users WHERE active = true"],
|
|
32
|
+
data: [
|
|
33
|
+
{
|
|
34
|
+
columns: ["count"],
|
|
35
|
+
rows: [{ count: 1234 }],
|
|
36
|
+
},
|
|
37
|
+
],
|
|
38
|
+
steps: 3,
|
|
39
|
+
usage: { totalTokens: 5000 },
|
|
40
|
+
...overrides,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
describe("formatQueryResponse", () => {
|
|
45
|
+
it("formats a complete query response with answer, SQL, and data", () => {
|
|
46
|
+
const blocks = formatQueryResponse(makeResult());
|
|
47
|
+
|
|
48
|
+
expect(blocks.length).toBeGreaterThanOrEqual(3); // answer + SQL + data + context
|
|
49
|
+
expect(blocks[0].type).toBe("section");
|
|
50
|
+
expect(blockText(blocks[0])).toContain("1,234 active users");
|
|
51
|
+
|
|
52
|
+
// SQL block
|
|
53
|
+
expect(blockText(blocks[1])).toContain("```");
|
|
54
|
+
expect(blockText(blocks[1])).toContain("SELECT COUNT(*)");
|
|
55
|
+
|
|
56
|
+
// Context block (last)
|
|
57
|
+
const last = blocks[blocks.length - 1];
|
|
58
|
+
expect(last.type).toBe("context");
|
|
59
|
+
expect(contextTexts(last)[0]).toContain("3 steps");
|
|
60
|
+
expect(contextTexts(last)[0]).toContain("5,000 tokens");
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it("handles missing SQL gracefully", () => {
|
|
64
|
+
const blocks = formatQueryResponse(makeResult({ sql: [] }));
|
|
65
|
+
const sqlBlocks = blocks.filter(
|
|
66
|
+
(b) => blockText(b).includes("```") && blockText(b).includes("SQL"),
|
|
67
|
+
);
|
|
68
|
+
expect(sqlBlocks.length).toBe(0);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it("handles empty data gracefully", () => {
|
|
72
|
+
const blocks = formatQueryResponse(makeResult({ data: [] }));
|
|
73
|
+
expect(blocks.length).toBeGreaterThanOrEqual(2);
|
|
74
|
+
expect(blockText(blocks[0])).toContain("active users");
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it("handles missing answer with default text", () => {
|
|
78
|
+
const blocks = formatQueryResponse(makeResult({ answer: "" }));
|
|
79
|
+
expect(blockText(blocks[0])).toContain("No answer generated");
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it("truncates large data tables", () => {
|
|
83
|
+
const manyRows = Array.from({ length: 50 }, (_, i) => ({
|
|
84
|
+
id: i,
|
|
85
|
+
name: `User ${i}`,
|
|
86
|
+
email: `user${i}@example.com`,
|
|
87
|
+
}));
|
|
88
|
+
|
|
89
|
+
const blocks = formatQueryResponse(
|
|
90
|
+
makeResult({
|
|
91
|
+
data: [
|
|
92
|
+
{
|
|
93
|
+
columns: ["id", "name", "email"],
|
|
94
|
+
rows: manyRows as Record<string, unknown>[],
|
|
95
|
+
},
|
|
96
|
+
],
|
|
97
|
+
}),
|
|
98
|
+
);
|
|
99
|
+
|
|
100
|
+
const dataBlock = blocks.find(
|
|
101
|
+
(b) => blockText(b).includes("```") && !blockText(b).includes("SQL"),
|
|
102
|
+
);
|
|
103
|
+
expect(dataBlock).toBeDefined();
|
|
104
|
+
expect(blockText(dataBlock!)).toContain("Showing first");
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it("stays within 50 block limit", () => {
|
|
108
|
+
const manyDatasets = Array.from({ length: 60 }, () => ({
|
|
109
|
+
columns: ["col"],
|
|
110
|
+
rows: [{ col: "value" }],
|
|
111
|
+
}));
|
|
112
|
+
|
|
113
|
+
const blocks = formatQueryResponse(makeResult({ data: manyDatasets }));
|
|
114
|
+
expect(blocks.length).toBeLessThanOrEqual(50);
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
it("truncates long answer text to 3000 chars", () => {
|
|
118
|
+
const longAnswer = "A".repeat(4000);
|
|
119
|
+
const blocks = formatQueryResponse(makeResult({ answer: longAnswer }));
|
|
120
|
+
expect(blockText(blocks[0]).length).toBeLessThanOrEqual(3000);
|
|
121
|
+
expect(blockText(blocks[0])).toEndWith("...");
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
describe("formatErrorResponse", () => {
|
|
126
|
+
it("formats an error message", () => {
|
|
127
|
+
const blocks = formatErrorResponse("Something went wrong");
|
|
128
|
+
expect(blocks.length).toBe(1);
|
|
129
|
+
expect(blocks[0].type).toBe("section");
|
|
130
|
+
expect(blockText(blocks[0])).toContain("Something went wrong");
|
|
131
|
+
expect(blockText(blocks[0])).toContain(":warning:");
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
it("truncates long error messages", () => {
|
|
135
|
+
const longError = "E".repeat(500);
|
|
136
|
+
const blocks = formatErrorResponse(longError);
|
|
137
|
+
expect(blockText(blocks[0]).length).toBeLessThan(300);
|
|
138
|
+
});
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
/** Helper: build a PendingAction for tests */
|
|
142
|
+
function makeAction(overrides: Partial<PendingAction> = {}): PendingAction {
|
|
143
|
+
return {
|
|
144
|
+
id: "act_123",
|
|
145
|
+
type: "executeSQL",
|
|
146
|
+
target: "SELECT 1",
|
|
147
|
+
summary: "Run a test query",
|
|
148
|
+
...overrides,
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
describe("formatActionApproval", () => {
|
|
153
|
+
it("returns a section block and an actions block with two buttons", () => {
|
|
154
|
+
const blocks = formatActionApproval(makeAction());
|
|
155
|
+
expect(blocks.length).toBe(2);
|
|
156
|
+
expect(blocks[0].type).toBe("section");
|
|
157
|
+
expect(blocks[1].type).toBe("actions");
|
|
158
|
+
if (blocks[1].type === "actions") {
|
|
159
|
+
expect(blocks[1].elements.length).toBe(2);
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
it("approve button has correct action_id and value", () => {
|
|
164
|
+
const action = makeAction({ id: "act_abc" });
|
|
165
|
+
const blocks = formatActionApproval(action);
|
|
166
|
+
const actionsBlock = blocks[1];
|
|
167
|
+
if (actionsBlock.type === "actions") {
|
|
168
|
+
const approve = actionsBlock.elements[0];
|
|
169
|
+
expect(approve.action_id).toBe("atlas_action_approve");
|
|
170
|
+
expect(approve.value).toBe("act_abc");
|
|
171
|
+
expect(approve.style).toBe("primary");
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
it("deny button has correct action_id and value", () => {
|
|
176
|
+
const action = makeAction({ id: "act_xyz" });
|
|
177
|
+
const blocks = formatActionApproval(action);
|
|
178
|
+
const actionsBlock = blocks[1];
|
|
179
|
+
if (actionsBlock.type === "actions") {
|
|
180
|
+
const deny = actionsBlock.elements[1];
|
|
181
|
+
expect(deny.action_id).toBe("atlas_action_deny");
|
|
182
|
+
expect(deny.value).toBe("act_xyz");
|
|
183
|
+
expect(deny.style).toBe("danger");
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
it("falls back to action.type when summary is empty", () => {
|
|
188
|
+
const blocks = formatActionApproval(makeAction({ summary: "", type: "executeSQL" }));
|
|
189
|
+
expect(blockText(blocks[0])).toContain("executeSQL");
|
|
190
|
+
expect(blockText(blocks[0])).not.toContain("\n\n");
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
it("truncates very long summaries", () => {
|
|
194
|
+
const longSummary = "S".repeat(4000);
|
|
195
|
+
const blocks = formatActionApproval(makeAction({ summary: longSummary }));
|
|
196
|
+
expect(blockText(blocks[0]).length).toBeLessThanOrEqual(3000);
|
|
197
|
+
});
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
describe("formatActionResult", () => {
|
|
201
|
+
it("executed status produces check mark emoji", () => {
|
|
202
|
+
const blocks = formatActionResult(makeAction(), "executed");
|
|
203
|
+
expect(blockText(blocks[0])).toContain(":white_check_mark:");
|
|
204
|
+
expect(blockText(blocks[0])).toContain("executed");
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
it("denied status produces no_entry_sign emoji", () => {
|
|
208
|
+
const blocks = formatActionResult(makeAction(), "denied");
|
|
209
|
+
expect(blockText(blocks[0])).toContain(":no_entry_sign:");
|
|
210
|
+
expect(blockText(blocks[0])).toContain("denied");
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
it("failed status produces x emoji", () => {
|
|
214
|
+
const blocks = formatActionResult(makeAction(), "failed");
|
|
215
|
+
expect(blockText(blocks[0])).toContain(":x:");
|
|
216
|
+
expect(blockText(blocks[0])).toContain("failed");
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
it("appends error text when provided", () => {
|
|
220
|
+
const blocks = formatActionResult(makeAction(), "failed", "Connection timed out");
|
|
221
|
+
expect(blockText(blocks[0])).toContain("Connection timed out");
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
it("truncates very long error text", () => {
|
|
225
|
+
const longError = "E".repeat(500);
|
|
226
|
+
const blocks = formatActionResult(makeAction(), "failed", longError);
|
|
227
|
+
const text = blockText(blocks[0]);
|
|
228
|
+
// Error portion truncated to 200 chars (plus "..." = 203 max)
|
|
229
|
+
expect(text.length).toBeLessThan(500);
|
|
230
|
+
expect(text).toContain("...");
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
it("falls back to action.type when summary is empty", () => {
|
|
234
|
+
const blocks = formatActionResult(makeAction({ summary: "", type: "executeSQL" }), "executed");
|
|
235
|
+
expect(blockText(blocks[0])).toContain("executeSQL");
|
|
236
|
+
});
|
|
237
|
+
});
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tests for Slack installation storage (store.ts).
|
|
3
|
+
*
|
|
4
|
+
* Mocks the internal DB layer to test DB-backed and env-var fallback paths.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { describe, it, expect, beforeEach, afterEach, mock, type Mock } from "bun:test";
|
|
8
|
+
|
|
9
|
+
// --- Mocks ---
|
|
10
|
+
|
|
11
|
+
const mockHasInternalDB: Mock<() => boolean> = mock(() => true);
|
|
12
|
+
const mockInternalQuery: Mock<(sql: string, params?: unknown[]) => Promise<Record<string, unknown>[]>> = mock(() =>
|
|
13
|
+
Promise.resolve([]),
|
|
14
|
+
);
|
|
15
|
+
|
|
16
|
+
const mockPoolQuery: Mock<(sql: string, params?: unknown[]) => Promise<void>> = mock(() =>
|
|
17
|
+
Promise.resolve(),
|
|
18
|
+
);
|
|
19
|
+
const mockGetInternalDB: Mock<() => { query: typeof mockPoolQuery }> = mock(() => ({
|
|
20
|
+
query: mockPoolQuery,
|
|
21
|
+
}));
|
|
22
|
+
|
|
23
|
+
mock.module("@atlas/api/lib/db/internal", () => ({
|
|
24
|
+
hasInternalDB: mockHasInternalDB,
|
|
25
|
+
internalQuery: mockInternalQuery,
|
|
26
|
+
getInternalDB: mockGetInternalDB,
|
|
27
|
+
}));
|
|
28
|
+
|
|
29
|
+
mock.module("@atlas/api/lib/logger", () => ({
|
|
30
|
+
createLogger: () => ({
|
|
31
|
+
info: () => {},
|
|
32
|
+
warn: () => {},
|
|
33
|
+
error: () => {},
|
|
34
|
+
debug: () => {},
|
|
35
|
+
}),
|
|
36
|
+
}));
|
|
37
|
+
|
|
38
|
+
// Import after mocks are registered
|
|
39
|
+
const { getInstallation, saveInstallation, deleteInstallation, getBotToken } = await import("../store");
|
|
40
|
+
|
|
41
|
+
describe("store", () => {
|
|
42
|
+
const savedBotToken = process.env.SLACK_BOT_TOKEN;
|
|
43
|
+
|
|
44
|
+
beforeEach(() => {
|
|
45
|
+
mockHasInternalDB.mockClear();
|
|
46
|
+
mockInternalQuery.mockClear();
|
|
47
|
+
mockPoolQuery.mockClear();
|
|
48
|
+
mockGetInternalDB.mockClear();
|
|
49
|
+
delete process.env.SLACK_BOT_TOKEN;
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
afterEach(() => {
|
|
53
|
+
if (savedBotToken !== undefined) process.env.SLACK_BOT_TOKEN = savedBotToken;
|
|
54
|
+
else delete process.env.SLACK_BOT_TOKEN;
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
describe("getInstallation", () => {
|
|
58
|
+
it("returns installation from DB when hasInternalDB() is true and row exists", async () => {
|
|
59
|
+
mockHasInternalDB.mockReturnValue(true);
|
|
60
|
+
mockInternalQuery.mockResolvedValue([
|
|
61
|
+
{ team_id: "T123", bot_token: "xoxb-abc", installed_at: "2025-01-01T00:00:00Z" },
|
|
62
|
+
]);
|
|
63
|
+
|
|
64
|
+
const result = await getInstallation("T123");
|
|
65
|
+
expect(result).toEqual({
|
|
66
|
+
team_id: "T123",
|
|
67
|
+
bot_token: "xoxb-abc",
|
|
68
|
+
installed_at: "2025-01-01T00:00:00Z",
|
|
69
|
+
});
|
|
70
|
+
expect(mockInternalQuery).toHaveBeenCalledTimes(1);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it("returns null when DB has no matching row", async () => {
|
|
74
|
+
mockHasInternalDB.mockReturnValue(true);
|
|
75
|
+
mockInternalQuery.mockResolvedValue([]);
|
|
76
|
+
|
|
77
|
+
const result = await getInstallation("T999");
|
|
78
|
+
expect(result).toBeNull();
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it("throws when DB query fails (does NOT fall through to env var)", async () => {
|
|
82
|
+
mockHasInternalDB.mockReturnValue(true);
|
|
83
|
+
mockInternalQuery.mockRejectedValue(new Error("connection refused"));
|
|
84
|
+
process.env.SLACK_BOT_TOKEN = "xoxb-env-fallback";
|
|
85
|
+
|
|
86
|
+
await expect(getInstallation("T123")).rejects.toThrow("connection refused");
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it("returns env var token when hasInternalDB() is false and SLACK_BOT_TOKEN is set", async () => {
|
|
90
|
+
mockHasInternalDB.mockReturnValue(false);
|
|
91
|
+
process.env.SLACK_BOT_TOKEN = "xoxb-env-token";
|
|
92
|
+
|
|
93
|
+
const result = await getInstallation("T123");
|
|
94
|
+
expect(result).not.toBeNull();
|
|
95
|
+
expect(result!.bot_token).toBe("xoxb-env-token");
|
|
96
|
+
expect(result!.team_id).toBe("T123");
|
|
97
|
+
expect(mockInternalQuery).not.toHaveBeenCalled();
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it("returns null when hasInternalDB() is false and no env var", async () => {
|
|
101
|
+
mockHasInternalDB.mockReturnValue(false);
|
|
102
|
+
delete process.env.SLACK_BOT_TOKEN;
|
|
103
|
+
|
|
104
|
+
const result = await getInstallation("T123");
|
|
105
|
+
expect(result).toBeNull();
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
it("returns null for invalid DB record (non-string bot_token)", async () => {
|
|
109
|
+
mockHasInternalDB.mockReturnValue(true);
|
|
110
|
+
mockInternalQuery.mockResolvedValue([
|
|
111
|
+
{ team_id: "T123", bot_token: 12345, installed_at: "2025-01-01T00:00:00Z" },
|
|
112
|
+
]);
|
|
113
|
+
|
|
114
|
+
const result = await getInstallation("T123");
|
|
115
|
+
expect(result).toBeNull();
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
describe("saveInstallation", () => {
|
|
120
|
+
it("resolves when DB write succeeds", async () => {
|
|
121
|
+
mockHasInternalDB.mockReturnValue(true);
|
|
122
|
+
mockPoolQuery.mockResolvedValue(undefined as never);
|
|
123
|
+
|
|
124
|
+
await expect(saveInstallation("T123", "xoxb-new")).resolves.toBeUndefined();
|
|
125
|
+
expect(mockPoolQuery).toHaveBeenCalledTimes(1);
|
|
126
|
+
// Verify the SQL contains INSERT and the params
|
|
127
|
+
const [sql, params] = mockPoolQuery.mock.calls[0];
|
|
128
|
+
expect(sql).toContain("INSERT INTO slack_installations");
|
|
129
|
+
expect(params).toEqual(["T123", "xoxb-new"]);
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
it("throws when no internal DB", async () => {
|
|
133
|
+
mockHasInternalDB.mockReturnValue(false);
|
|
134
|
+
|
|
135
|
+
await expect(saveInstallation("T123", "xoxb-token")).rejects.toThrow(
|
|
136
|
+
"no internal database configured",
|
|
137
|
+
);
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
it("throws when DB write fails", async () => {
|
|
141
|
+
mockHasInternalDB.mockReturnValue(true);
|
|
142
|
+
mockPoolQuery.mockRejectedValue(new Error("disk full"));
|
|
143
|
+
|
|
144
|
+
await expect(saveInstallation("T123", "xoxb-token")).rejects.toThrow("disk full");
|
|
145
|
+
});
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
describe("deleteInstallation", () => {
|
|
149
|
+
it("resolves when DB delete succeeds", async () => {
|
|
150
|
+
mockHasInternalDB.mockReturnValue(true);
|
|
151
|
+
mockPoolQuery.mockResolvedValue(undefined as never);
|
|
152
|
+
|
|
153
|
+
await expect(deleteInstallation("T123")).resolves.toBeUndefined();
|
|
154
|
+
expect(mockPoolQuery).toHaveBeenCalledTimes(1);
|
|
155
|
+
const [sql, params] = mockPoolQuery.mock.calls[0];
|
|
156
|
+
expect(sql).toContain("DELETE FROM slack_installations");
|
|
157
|
+
expect(params).toEqual(["T123"]);
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
it("resolves (with warning) when no internal DB", async () => {
|
|
161
|
+
mockHasInternalDB.mockReturnValue(false);
|
|
162
|
+
|
|
163
|
+
// Should not throw — just logs a warning and returns
|
|
164
|
+
await expect(deleteInstallation("T123")).resolves.toBeUndefined();
|
|
165
|
+
expect(mockPoolQuery).not.toHaveBeenCalled();
|
|
166
|
+
});
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
describe("getBotToken", () => {
|
|
170
|
+
it("returns the token string from getInstallation", async () => {
|
|
171
|
+
mockHasInternalDB.mockReturnValue(true);
|
|
172
|
+
mockInternalQuery.mockResolvedValue([
|
|
173
|
+
{ team_id: "T123", bot_token: "xoxb-from-db", installed_at: "2025-01-01T00:00:00Z" },
|
|
174
|
+
]);
|
|
175
|
+
|
|
176
|
+
const token = await getBotToken("T123");
|
|
177
|
+
expect(token).toBe("xoxb-from-db");
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
it("returns null when no installation exists", async () => {
|
|
181
|
+
mockHasInternalDB.mockReturnValue(true);
|
|
182
|
+
mockInternalQuery.mockResolvedValue([]);
|
|
183
|
+
|
|
184
|
+
const token = await getBotToken("T999");
|
|
185
|
+
expect(token).toBeNull();
|
|
186
|
+
});
|
|
187
|
+
});
|
|
188
|
+
});
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tests for Slack thread → Atlas conversation ID mapping (threads.ts).
|
|
3
|
+
*
|
|
4
|
+
* Mocks the internal DB layer to test lookup and persistence paths.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { describe, it, expect, beforeEach, mock, type Mock } from "bun:test";
|
|
8
|
+
|
|
9
|
+
// --- Mocks ---
|
|
10
|
+
|
|
11
|
+
const mockHasInternalDB: Mock<() => boolean> = mock(() => true);
|
|
12
|
+
const mockInternalQuery: Mock<(sql: string, params?: unknown[]) => Promise<Record<string, unknown>[]>> = mock(() =>
|
|
13
|
+
Promise.resolve([]),
|
|
14
|
+
);
|
|
15
|
+
|
|
16
|
+
const mockPoolQuery: Mock<(sql: string, params?: unknown[]) => Promise<void>> = mock(() =>
|
|
17
|
+
Promise.resolve(),
|
|
18
|
+
);
|
|
19
|
+
const mockGetInternalDB: Mock<() => { query: typeof mockPoolQuery }> = mock(() => ({
|
|
20
|
+
query: mockPoolQuery,
|
|
21
|
+
}));
|
|
22
|
+
|
|
23
|
+
mock.module("@atlas/api/lib/db/internal", () => ({
|
|
24
|
+
hasInternalDB: mockHasInternalDB,
|
|
25
|
+
internalQuery: mockInternalQuery,
|
|
26
|
+
getInternalDB: mockGetInternalDB,
|
|
27
|
+
}));
|
|
28
|
+
|
|
29
|
+
mock.module("@atlas/api/lib/logger", () => ({
|
|
30
|
+
createLogger: () => ({
|
|
31
|
+
info: () => {},
|
|
32
|
+
warn: () => {},
|
|
33
|
+
error: () => {},
|
|
34
|
+
debug: () => {},
|
|
35
|
+
}),
|
|
36
|
+
}));
|
|
37
|
+
|
|
38
|
+
// Import after mocks are registered
|
|
39
|
+
const { getConversationId, setConversationId } = await import("../threads");
|
|
40
|
+
|
|
41
|
+
describe("threads", () => {
|
|
42
|
+
beforeEach(() => {
|
|
43
|
+
mockHasInternalDB.mockClear();
|
|
44
|
+
mockInternalQuery.mockClear();
|
|
45
|
+
mockPoolQuery.mockClear();
|
|
46
|
+
mockGetInternalDB.mockClear();
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
describe("getConversationId", () => {
|
|
50
|
+
it("returns null when hasInternalDB() is false", async () => {
|
|
51
|
+
mockHasInternalDB.mockReturnValue(false);
|
|
52
|
+
|
|
53
|
+
const result = await getConversationId("C123", "1234567890.000001");
|
|
54
|
+
expect(result).toBeNull();
|
|
55
|
+
expect(mockInternalQuery).not.toHaveBeenCalled();
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it("returns conversation ID when mapping exists", async () => {
|
|
59
|
+
mockHasInternalDB.mockReturnValue(true);
|
|
60
|
+
mockInternalQuery.mockResolvedValue([{ conversation_id: "conv-abc-123" }]);
|
|
61
|
+
|
|
62
|
+
const result = await getConversationId("C123", "1234567890.000001");
|
|
63
|
+
expect(result).toBe("conv-abc-123");
|
|
64
|
+
expect(mockInternalQuery).toHaveBeenCalledTimes(1);
|
|
65
|
+
const [sql, params] = mockInternalQuery.mock.calls[0];
|
|
66
|
+
expect(sql).toContain("SELECT conversation_id FROM slack_threads");
|
|
67
|
+
expect(params).toEqual(["C123", "1234567890.000001"]);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it("returns null when no mapping exists", async () => {
|
|
71
|
+
mockHasInternalDB.mockReturnValue(true);
|
|
72
|
+
mockInternalQuery.mockResolvedValue([]);
|
|
73
|
+
|
|
74
|
+
const result = await getConversationId("C123", "1234567890.000001");
|
|
75
|
+
expect(result).toBeNull();
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it("returns null on DB error (logs error)", async () => {
|
|
79
|
+
mockHasInternalDB.mockReturnValue(true);
|
|
80
|
+
mockInternalQuery.mockRejectedValue(new Error("table does not exist"));
|
|
81
|
+
|
|
82
|
+
// Should catch the error and return null, not throw
|
|
83
|
+
const result = await getConversationId("C123", "1234567890.000001");
|
|
84
|
+
expect(result).toBeNull();
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
describe("setConversationId", () => {
|
|
89
|
+
it("writes correct UPSERT to DB", async () => {
|
|
90
|
+
mockHasInternalDB.mockReturnValue(true);
|
|
91
|
+
mockPoolQuery.mockResolvedValue(undefined as never);
|
|
92
|
+
|
|
93
|
+
await setConversationId("C123", "1234567890.000001", "conv-xyz-789");
|
|
94
|
+
|
|
95
|
+
expect(mockGetInternalDB).toHaveBeenCalledTimes(1);
|
|
96
|
+
expect(mockPoolQuery).toHaveBeenCalledTimes(1);
|
|
97
|
+
const [sql, params] = mockPoolQuery.mock.calls[0];
|
|
98
|
+
expect(sql).toContain("INSERT INTO slack_threads");
|
|
99
|
+
expect(sql).toContain("ON CONFLICT");
|
|
100
|
+
expect(params).toEqual(["C123", "1234567890.000001", "conv-xyz-789"]);
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
it("is silent no-op when no internal DB", async () => {
|
|
104
|
+
mockHasInternalDB.mockReturnValue(false);
|
|
105
|
+
|
|
106
|
+
// Should return without error and without calling DB
|
|
107
|
+
await expect(setConversationId("C123", "1234567890.000001", "conv-abc")).resolves.toBeUndefined();
|
|
108
|
+
expect(mockGetInternalDB).not.toHaveBeenCalled();
|
|
109
|
+
expect(mockPoolQuery).not.toHaveBeenCalled();
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
});
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tests for Slack request signature verification.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { describe, it, expect } from "bun:test";
|
|
6
|
+
import crypto from "crypto";
|
|
7
|
+
import { verifySlackSignature } from "../verify";
|
|
8
|
+
|
|
9
|
+
const SIGNING_SECRET = "test_signing_secret_12345";
|
|
10
|
+
|
|
11
|
+
function makeSignature(secret: string, timestamp: string, body: string): string {
|
|
12
|
+
const sigBasestring = `v0:${timestamp}:${body}`;
|
|
13
|
+
return (
|
|
14
|
+
"v0=" + crypto.createHmac("sha256", secret).update(sigBasestring).digest("hex")
|
|
15
|
+
);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function currentTimestamp(): string {
|
|
19
|
+
return String(Math.floor(Date.now() / 1000));
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
describe("verifySlackSignature", () => {
|
|
23
|
+
it("accepts a valid signature", () => {
|
|
24
|
+
const timestamp = currentTimestamp();
|
|
25
|
+
const body = "token=xxx&team_id=T123&text=hello";
|
|
26
|
+
const signature = makeSignature(SIGNING_SECRET, timestamp, body);
|
|
27
|
+
|
|
28
|
+
const result = verifySlackSignature(SIGNING_SECRET, signature, timestamp, body);
|
|
29
|
+
expect(result.valid).toBe(true);
|
|
30
|
+
expect("error" in result).toBe(false);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it("rejects an invalid signature", () => {
|
|
34
|
+
const timestamp = currentTimestamp();
|
|
35
|
+
const body = "token=xxx&team_id=T123&text=hello";
|
|
36
|
+
const signature = "v0=deadbeef1234567890abcdef1234567890abcdef1234567890abcdef12345678";
|
|
37
|
+
|
|
38
|
+
const result = verifySlackSignature(SIGNING_SECRET, signature, timestamp, body);
|
|
39
|
+
expect(result.valid).toBe(false);
|
|
40
|
+
if (!result.valid) expect(result.error).toBe("Invalid signature");
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it("rejects missing signature header", () => {
|
|
44
|
+
const timestamp = currentTimestamp();
|
|
45
|
+
const body = "token=xxx";
|
|
46
|
+
|
|
47
|
+
const result = verifySlackSignature(SIGNING_SECRET, null, timestamp, body);
|
|
48
|
+
expect(result.valid).toBe(false);
|
|
49
|
+
if (!result.valid) expect(result.error).toBe("Missing signature or timestamp headers");
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it("rejects missing timestamp header", () => {
|
|
53
|
+
const body = "token=xxx";
|
|
54
|
+
const signature = "v0=something";
|
|
55
|
+
|
|
56
|
+
const result = verifySlackSignature(SIGNING_SECRET, signature, null, body);
|
|
57
|
+
expect(result.valid).toBe(false);
|
|
58
|
+
if (!result.valid) expect(result.error).toBe("Missing signature or timestamp headers");
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it("rejects expired timestamp (>5 minutes old)", () => {
|
|
62
|
+
const oldTimestamp = String(Math.floor(Date.now() / 1000) - 400); // 6+ minutes ago
|
|
63
|
+
const body = "token=xxx";
|
|
64
|
+
const signature = makeSignature(SIGNING_SECRET, oldTimestamp, body);
|
|
65
|
+
|
|
66
|
+
const result = verifySlackSignature(SIGNING_SECRET, signature, oldTimestamp, body);
|
|
67
|
+
expect(result.valid).toBe(false);
|
|
68
|
+
if (!result.valid) expect(result.error).toBe("Request timestamp too old");
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it("accepts timestamp within 5-minute window", () => {
|
|
72
|
+
const recentTimestamp = String(Math.floor(Date.now() / 1000) - 200); // ~3 minutes ago
|
|
73
|
+
const body = "token=xxx";
|
|
74
|
+
const signature = makeSignature(SIGNING_SECRET, recentTimestamp, body);
|
|
75
|
+
|
|
76
|
+
const result = verifySlackSignature(SIGNING_SECRET, signature, recentTimestamp, body);
|
|
77
|
+
expect(result.valid).toBe(true);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it("rejects invalid (non-numeric) timestamp", () => {
|
|
81
|
+
const body = "token=xxx";
|
|
82
|
+
const result = verifySlackSignature(SIGNING_SECRET, "v0=abc", "not-a-number", body);
|
|
83
|
+
expect(result.valid).toBe(false);
|
|
84
|
+
if (!result.valid) expect(result.error).toBe("Invalid timestamp");
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it("rejects signature with wrong secret", () => {
|
|
88
|
+
const timestamp = currentTimestamp();
|
|
89
|
+
const body = "token=xxx";
|
|
90
|
+
const signature = makeSignature("wrong_secret", timestamp, body);
|
|
91
|
+
|
|
92
|
+
const result = verifySlackSignature(SIGNING_SECRET, signature, timestamp, body);
|
|
93
|
+
expect(result.valid).toBe(false);
|
|
94
|
+
if (!result.valid) expect(result.error).toBe("Invalid signature");
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
it("rejects tampered body", () => {
|
|
98
|
+
const timestamp = currentTimestamp();
|
|
99
|
+
const body = "token=xxx&text=original";
|
|
100
|
+
const signature = makeSignature(SIGNING_SECRET, timestamp, body);
|
|
101
|
+
|
|
102
|
+
const result = verifySlackSignature(
|
|
103
|
+
SIGNING_SECRET,
|
|
104
|
+
signature,
|
|
105
|
+
timestamp,
|
|
106
|
+
"token=xxx&text=tampered",
|
|
107
|
+
);
|
|
108
|
+
expect(result.valid).toBe(false);
|
|
109
|
+
if (!result.valid) expect(result.error).toBe("Invalid signature");
|
|
110
|
+
});
|
|
111
|
+
});
|