@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,683 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unit tests for the actions REST routes.
|
|
3
|
+
*
|
|
4
|
+
* Uses mock.module() pattern from conversations.test.ts.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import {
|
|
8
|
+
describe,
|
|
9
|
+
it,
|
|
10
|
+
expect,
|
|
11
|
+
beforeEach,
|
|
12
|
+
afterEach,
|
|
13
|
+
mock,
|
|
14
|
+
type Mock,
|
|
15
|
+
} from "bun:test";
|
|
16
|
+
import type { AuthResult } from "@atlas/api/lib/auth/types";
|
|
17
|
+
import type { ActionLogEntry, ActionApprovalMode } from "@atlas/api/lib/action-types";
|
|
18
|
+
|
|
19
|
+
// --- Mocks ---
|
|
20
|
+
|
|
21
|
+
const mockAuthenticateRequest: Mock<
|
|
22
|
+
(req: Request) => Promise<AuthResult>
|
|
23
|
+
> = mock(() =>
|
|
24
|
+
Promise.resolve({
|
|
25
|
+
authenticated: true as const,
|
|
26
|
+
mode: "simple-key" as const,
|
|
27
|
+
user: { id: "u1", label: "test@test.com", mode: "simple-key" as const },
|
|
28
|
+
}),
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
const mockCheckRateLimit: Mock<
|
|
32
|
+
(key: string) => { allowed: boolean; retryAfterMs?: number }
|
|
33
|
+
> = mock(() => ({ allowed: true }));
|
|
34
|
+
|
|
35
|
+
const mockGetClientIP: Mock<(req: Request) => string | null> = mock(
|
|
36
|
+
() => null,
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
mock.module("@atlas/api/lib/auth/middleware", () => ({
|
|
40
|
+
authenticateRequest: mockAuthenticateRequest,
|
|
41
|
+
checkRateLimit: mockCheckRateLimit,
|
|
42
|
+
getClientIP: mockGetClientIP,
|
|
43
|
+
}));
|
|
44
|
+
|
|
45
|
+
// --- Action handler mocks ---
|
|
46
|
+
|
|
47
|
+
const mockListPendingActions = mock((): Promise<ActionLogEntry[]> =>
|
|
48
|
+
Promise.resolve([]),
|
|
49
|
+
);
|
|
50
|
+
const mockGetAction = mock((): Promise<ActionLogEntry | null> =>
|
|
51
|
+
Promise.resolve(null),
|
|
52
|
+
);
|
|
53
|
+
const mockApproveAction = mock((): Promise<ActionLogEntry | null> =>
|
|
54
|
+
Promise.resolve(null),
|
|
55
|
+
);
|
|
56
|
+
const mockDenyAction = mock((): Promise<ActionLogEntry | null> =>
|
|
57
|
+
Promise.resolve(null),
|
|
58
|
+
);
|
|
59
|
+
const mockGetActionExecutor = mock((): undefined => undefined);
|
|
60
|
+
const mockGetActionConfig = mock(
|
|
61
|
+
(): { approval: ActionApprovalMode; timeout?: number; maxPerConversation?: number } => ({
|
|
62
|
+
approval: "manual",
|
|
63
|
+
}),
|
|
64
|
+
);
|
|
65
|
+
|
|
66
|
+
mock.module("@atlas/api/lib/tools/actions/handler", () => ({
|
|
67
|
+
listPendingActions: mockListPendingActions,
|
|
68
|
+
getAction: mockGetAction,
|
|
69
|
+
approveAction: mockApproveAction,
|
|
70
|
+
denyAction: mockDenyAction,
|
|
71
|
+
getActionExecutor: mockGetActionExecutor,
|
|
72
|
+
getActionConfig: mockGetActionConfig,
|
|
73
|
+
}));
|
|
74
|
+
|
|
75
|
+
// Mock other modules required by the Hono app (same as conversations.test.ts)
|
|
76
|
+
|
|
77
|
+
mock.module("@atlas/api/lib/agent", () => ({
|
|
78
|
+
runAgent: mock(() =>
|
|
79
|
+
Promise.resolve({
|
|
80
|
+
toUIMessageStreamResponse: () => new Response("stream", { status: 200 }),
|
|
81
|
+
text: Promise.resolve("answer"),
|
|
82
|
+
steps: Promise.resolve([]),
|
|
83
|
+
totalUsage: Promise.resolve({ inputTokens: 0, outputTokens: 0 }),
|
|
84
|
+
}),
|
|
85
|
+
),
|
|
86
|
+
}));
|
|
87
|
+
|
|
88
|
+
mock.module("@atlas/api/lib/conversations", () => ({
|
|
89
|
+
listConversations: mock(() => Promise.resolve({ conversations: [], total: 0 })),
|
|
90
|
+
getConversation: mock(() => Promise.resolve(null)),
|
|
91
|
+
deleteConversation: mock(() => Promise.resolve(false)),
|
|
92
|
+
createConversation: mock(() => Promise.resolve(null)),
|
|
93
|
+
addMessage: mock(() => {}),
|
|
94
|
+
generateTitle: mock(() => "Test title"),
|
|
95
|
+
starConversation: async () => false,
|
|
96
|
+
}));
|
|
97
|
+
|
|
98
|
+
mock.module("@atlas/api/lib/semantic", () => ({
|
|
99
|
+
getWhitelistedTables: () => new Set(),
|
|
100
|
+
_resetWhitelists: () => {},
|
|
101
|
+
}));
|
|
102
|
+
|
|
103
|
+
mock.module("@atlas/api/lib/tools/explore", () => ({
|
|
104
|
+
getExploreBackendType: () => "just-bash",
|
|
105
|
+
getActiveSandboxPluginId: () => null,
|
|
106
|
+
}));
|
|
107
|
+
|
|
108
|
+
mock.module("@atlas/api/lib/auth/detect", () => ({
|
|
109
|
+
detectAuthMode: () => "none",
|
|
110
|
+
resetAuthModeCache: () => {},
|
|
111
|
+
}));
|
|
112
|
+
|
|
113
|
+
mock.module("@atlas/api/lib/startup", () => ({
|
|
114
|
+
validateEnvironment: mock(() => Promise.resolve([])),
|
|
115
|
+
getStartupWarnings: () => [],
|
|
116
|
+
}));
|
|
117
|
+
|
|
118
|
+
// Enable actions route before importing the app — the route mounts conditionally
|
|
119
|
+
process.env.ATLAS_ACTIONS_ENABLED = "true";
|
|
120
|
+
|
|
121
|
+
// Import after mocks
|
|
122
|
+
const { app } = await import("../index");
|
|
123
|
+
|
|
124
|
+
// Valid UUID for tests — routes validate UUID format on :id params
|
|
125
|
+
const VALID_ID = "a1b2c3d4-e5f6-7890-abcd-ef1234567890";
|
|
126
|
+
|
|
127
|
+
function makeAction(overrides: Partial<ActionLogEntry> = {}): ActionLogEntry {
|
|
128
|
+
return {
|
|
129
|
+
id: VALID_ID,
|
|
130
|
+
requested_at: "2024-06-01T00:00:00Z",
|
|
131
|
+
resolved_at: null,
|
|
132
|
+
executed_at: null,
|
|
133
|
+
requested_by: "u1",
|
|
134
|
+
approved_by: null,
|
|
135
|
+
auth_mode: "simple-key",
|
|
136
|
+
action_type: "send_email",
|
|
137
|
+
target: "user@example.com",
|
|
138
|
+
summary: "Send email to user",
|
|
139
|
+
payload: { to: "user@example.com", body: "Hello" },
|
|
140
|
+
status: "pending",
|
|
141
|
+
result: null,
|
|
142
|
+
error: null,
|
|
143
|
+
rollback_info: null,
|
|
144
|
+
conversation_id: null,
|
|
145
|
+
request_id: null,
|
|
146
|
+
...overrides,
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
describe("actions routes", () => {
|
|
151
|
+
const origDatabaseUrl = process.env.DATABASE_URL;
|
|
152
|
+
|
|
153
|
+
beforeEach(() => {
|
|
154
|
+
// Enable hasInternalDB() by setting DATABASE_URL
|
|
155
|
+
process.env.DATABASE_URL = "postgresql://test:test@localhost:5432/test";
|
|
156
|
+
mockAuthenticateRequest.mockReset();
|
|
157
|
+
mockAuthenticateRequest.mockResolvedValue({
|
|
158
|
+
authenticated: true as const,
|
|
159
|
+
mode: "simple-key" as const,
|
|
160
|
+
user: { id: "u1", label: "test@test.com", mode: "simple-key" as const },
|
|
161
|
+
});
|
|
162
|
+
mockCheckRateLimit.mockReset();
|
|
163
|
+
mockCheckRateLimit.mockReturnValue({ allowed: true });
|
|
164
|
+
mockGetClientIP.mockReset();
|
|
165
|
+
mockGetClientIP.mockReturnValue(null);
|
|
166
|
+
mockListPendingActions.mockReset();
|
|
167
|
+
mockListPendingActions.mockResolvedValue([]);
|
|
168
|
+
mockGetAction.mockReset();
|
|
169
|
+
mockGetAction.mockResolvedValue(null);
|
|
170
|
+
mockApproveAction.mockReset();
|
|
171
|
+
mockApproveAction.mockResolvedValue(null);
|
|
172
|
+
mockDenyAction.mockReset();
|
|
173
|
+
mockDenyAction.mockResolvedValue(null);
|
|
174
|
+
mockGetActionExecutor.mockReset();
|
|
175
|
+
mockGetActionExecutor.mockReturnValue(undefined);
|
|
176
|
+
mockGetActionConfig.mockReset();
|
|
177
|
+
mockGetActionConfig.mockReturnValue({ approval: "manual" });
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
afterEach(() => {
|
|
181
|
+
if (origDatabaseUrl !== undefined) process.env.DATABASE_URL = origDatabaseUrl;
|
|
182
|
+
else delete process.env.DATABASE_URL;
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
// -------------------------------------------------------------------------
|
|
186
|
+
// GET /api/v1/actions
|
|
187
|
+
// -------------------------------------------------------------------------
|
|
188
|
+
|
|
189
|
+
describe("GET /api/v1/actions", () => {
|
|
190
|
+
it("returns 200 with actions list", async () => {
|
|
191
|
+
const action = makeAction();
|
|
192
|
+
mockListPendingActions.mockResolvedValueOnce([action]);
|
|
193
|
+
|
|
194
|
+
const response = await app.fetch(
|
|
195
|
+
new Request("http://localhost/api/v1/actions"),
|
|
196
|
+
);
|
|
197
|
+
expect(response.status).toBe(200);
|
|
198
|
+
|
|
199
|
+
const body = (await response.json()) as { actions: unknown[] };
|
|
200
|
+
expect(body.actions.length).toBe(1);
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
it("returns 200 with empty list when no actions", async () => {
|
|
204
|
+
mockListPendingActions.mockResolvedValueOnce([]);
|
|
205
|
+
|
|
206
|
+
const response = await app.fetch(
|
|
207
|
+
new Request("http://localhost/api/v1/actions"),
|
|
208
|
+
);
|
|
209
|
+
expect(response.status).toBe(200);
|
|
210
|
+
|
|
211
|
+
const body = (await response.json()) as { actions: unknown[] };
|
|
212
|
+
expect(body.actions.length).toBe(0);
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
it("returns 404 when no internal DB", async () => {
|
|
216
|
+
delete process.env.DATABASE_URL;
|
|
217
|
+
|
|
218
|
+
const response = await app.fetch(
|
|
219
|
+
new Request("http://localhost/api/v1/actions"),
|
|
220
|
+
);
|
|
221
|
+
expect(response.status).toBe(404);
|
|
222
|
+
|
|
223
|
+
const body = (await response.json()) as Record<string, unknown>;
|
|
224
|
+
expect(body.error).toBe("not_available");
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
it("returns 401 when unauthenticated", async () => {
|
|
228
|
+
mockAuthenticateRequest.mockResolvedValueOnce({
|
|
229
|
+
authenticated: false as const,
|
|
230
|
+
mode: "simple-key" as const,
|
|
231
|
+
status: 401 as const,
|
|
232
|
+
error: "API key required",
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
const response = await app.fetch(
|
|
236
|
+
new Request("http://localhost/api/v1/actions"),
|
|
237
|
+
);
|
|
238
|
+
expect(response.status).toBe(401);
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
it("returns 429 when rate limited", async () => {
|
|
242
|
+
mockCheckRateLimit.mockReturnValueOnce({
|
|
243
|
+
allowed: false,
|
|
244
|
+
retryAfterMs: 30000,
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
const response = await app.fetch(
|
|
248
|
+
new Request("http://localhost/api/v1/actions"),
|
|
249
|
+
);
|
|
250
|
+
expect(response.status).toBe(429);
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
it("returns 500 when authenticateRequest throws", async () => {
|
|
254
|
+
mockAuthenticateRequest.mockRejectedValueOnce(new Error("DB crashed"));
|
|
255
|
+
const response = await app.fetch(
|
|
256
|
+
new Request("http://localhost/api/v1/actions"),
|
|
257
|
+
);
|
|
258
|
+
expect(response.status).toBe(500);
|
|
259
|
+
const body = (await response.json()) as Record<string, unknown>;
|
|
260
|
+
expect(body.error).toBe("auth_error");
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
it("passes userId from auth to listPendingActions", async () => {
|
|
264
|
+
await app.fetch(
|
|
265
|
+
new Request("http://localhost/api/v1/actions"),
|
|
266
|
+
);
|
|
267
|
+
expect(mockListPendingActions).toHaveBeenCalledTimes(1);
|
|
268
|
+
const call = mockListPendingActions.mock.calls[0] as unknown as [{ userId?: string }];
|
|
269
|
+
expect(call[0].userId).toBe("u1");
|
|
270
|
+
});
|
|
271
|
+
|
|
272
|
+
it("passes status query param", async () => {
|
|
273
|
+
await app.fetch(
|
|
274
|
+
new Request("http://localhost/api/v1/actions?status=approved"),
|
|
275
|
+
);
|
|
276
|
+
expect(mockListPendingActions).toHaveBeenCalledTimes(1);
|
|
277
|
+
const call = mockListPendingActions.mock.calls[0] as unknown as [{ status?: string }];
|
|
278
|
+
expect(call[0].status).toBe("approved");
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
it("passes limit query param", async () => {
|
|
282
|
+
await app.fetch(
|
|
283
|
+
new Request("http://localhost/api/v1/actions?limit=10"),
|
|
284
|
+
);
|
|
285
|
+
const call = mockListPendingActions.mock.calls[0] as unknown as [{ limit?: number }];
|
|
286
|
+
expect(call[0].limit).toBe(10);
|
|
287
|
+
});
|
|
288
|
+
|
|
289
|
+
it("returns 500 when listPendingActions throws", async () => {
|
|
290
|
+
mockListPendingActions.mockRejectedValueOnce(new Error("DB connection lost"));
|
|
291
|
+
|
|
292
|
+
const response = await app.fetch(
|
|
293
|
+
new Request("http://localhost/api/v1/actions"),
|
|
294
|
+
);
|
|
295
|
+
expect(response.status).toBe(500);
|
|
296
|
+
|
|
297
|
+
const body = (await response.json()) as Record<string, unknown>;
|
|
298
|
+
expect(body.error).toBe("internal_error");
|
|
299
|
+
});
|
|
300
|
+
|
|
301
|
+
it("?limit=0 defaults to 50", async () => {
|
|
302
|
+
await app.fetch(
|
|
303
|
+
new Request("http://localhost/api/v1/actions?limit=0"),
|
|
304
|
+
);
|
|
305
|
+
expect(mockListPendingActions).toHaveBeenCalledTimes(1);
|
|
306
|
+
const call = mockListPendingActions.mock.calls[0] as unknown as [{ limit?: number }];
|
|
307
|
+
expect(call[0].limit).toBe(50);
|
|
308
|
+
});
|
|
309
|
+
|
|
310
|
+
it("?limit=200 caps at 100", async () => {
|
|
311
|
+
await app.fetch(
|
|
312
|
+
new Request("http://localhost/api/v1/actions?limit=200"),
|
|
313
|
+
);
|
|
314
|
+
expect(mockListPendingActions).toHaveBeenCalledTimes(1);
|
|
315
|
+
const call = mockListPendingActions.mock.calls[0] as unknown as [{ limit?: number }];
|
|
316
|
+
expect(call[0].limit).toBe(100);
|
|
317
|
+
});
|
|
318
|
+
});
|
|
319
|
+
|
|
320
|
+
// -------------------------------------------------------------------------
|
|
321
|
+
// GET /api/v1/actions/:id
|
|
322
|
+
// -------------------------------------------------------------------------
|
|
323
|
+
|
|
324
|
+
describe("GET /api/v1/actions/:id", () => {
|
|
325
|
+
it("returns 200 with action", async () => {
|
|
326
|
+
const action = makeAction();
|
|
327
|
+
mockGetAction.mockResolvedValueOnce(action);
|
|
328
|
+
|
|
329
|
+
const response = await app.fetch(
|
|
330
|
+
new Request(`http://localhost/api/v1/actions/${VALID_ID}`),
|
|
331
|
+
);
|
|
332
|
+
expect(response.status).toBe(200);
|
|
333
|
+
|
|
334
|
+
const body = (await response.json()) as Record<string, unknown>;
|
|
335
|
+
expect(body.id).toBe(VALID_ID);
|
|
336
|
+
expect(body.action_type).toBe("send_email");
|
|
337
|
+
});
|
|
338
|
+
|
|
339
|
+
it("returns 404 when not found", async () => {
|
|
340
|
+
mockGetAction.mockResolvedValueOnce(null);
|
|
341
|
+
|
|
342
|
+
const response = await app.fetch(
|
|
343
|
+
new Request(`http://localhost/api/v1/actions/${VALID_ID}`),
|
|
344
|
+
);
|
|
345
|
+
expect(response.status).toBe(404);
|
|
346
|
+
|
|
347
|
+
const body = (await response.json()) as Record<string, unknown>;
|
|
348
|
+
expect(body.error).toBe("not_found");
|
|
349
|
+
});
|
|
350
|
+
|
|
351
|
+
it("returns 400 for invalid UUID", async () => {
|
|
352
|
+
const response = await app.fetch(
|
|
353
|
+
new Request("http://localhost/api/v1/actions/not-a-uuid"),
|
|
354
|
+
);
|
|
355
|
+
expect(response.status).toBe(400);
|
|
356
|
+
const body = (await response.json()) as Record<string, unknown>;
|
|
357
|
+
expect(body.error).toBe("invalid_request");
|
|
358
|
+
});
|
|
359
|
+
|
|
360
|
+
it("returns 404 when no internal DB", async () => {
|
|
361
|
+
delete process.env.DATABASE_URL;
|
|
362
|
+
|
|
363
|
+
const response = await app.fetch(
|
|
364
|
+
new Request(`http://localhost/api/v1/actions/${VALID_ID}`),
|
|
365
|
+
);
|
|
366
|
+
expect(response.status).toBe(404);
|
|
367
|
+
});
|
|
368
|
+
|
|
369
|
+
it("returns 404 when action belongs to different user (IDOR)", async () => {
|
|
370
|
+
const action = makeAction({ requested_by: "other-user" });
|
|
371
|
+
mockGetAction.mockResolvedValueOnce(action);
|
|
372
|
+
|
|
373
|
+
const response = await app.fetch(
|
|
374
|
+
new Request(`http://localhost/api/v1/actions/${VALID_ID}`),
|
|
375
|
+
);
|
|
376
|
+
expect(response.status).toBe(404);
|
|
377
|
+
|
|
378
|
+
const body = (await response.json()) as Record<string, unknown>;
|
|
379
|
+
expect(body.error).toBe("not_found");
|
|
380
|
+
});
|
|
381
|
+
});
|
|
382
|
+
|
|
383
|
+
// -------------------------------------------------------------------------
|
|
384
|
+
// POST /api/v1/actions/:id/approve
|
|
385
|
+
// -------------------------------------------------------------------------
|
|
386
|
+
|
|
387
|
+
describe("POST /api/v1/actions/:id/approve", () => {
|
|
388
|
+
it("returns 200 on successful approval", async () => {
|
|
389
|
+
const action = makeAction();
|
|
390
|
+
const approvedAction = makeAction({
|
|
391
|
+
status: "approved",
|
|
392
|
+
resolved_at: "2024-06-01T01:00:00Z",
|
|
393
|
+
approved_by: "u1",
|
|
394
|
+
});
|
|
395
|
+
mockGetAction.mockResolvedValueOnce(action);
|
|
396
|
+
mockApproveAction.mockResolvedValueOnce(approvedAction);
|
|
397
|
+
|
|
398
|
+
const response = await app.fetch(
|
|
399
|
+
new Request(`http://localhost/api/v1/actions/${VALID_ID}/approve`, {
|
|
400
|
+
method: "POST",
|
|
401
|
+
}),
|
|
402
|
+
);
|
|
403
|
+
expect(response.status).toBe(200);
|
|
404
|
+
|
|
405
|
+
const body = (await response.json()) as Record<string, unknown>;
|
|
406
|
+
expect(body.status).toBe("approved");
|
|
407
|
+
expect(body.approved_by).toBe("u1");
|
|
408
|
+
});
|
|
409
|
+
|
|
410
|
+
it("returns 409 when action already resolved", async () => {
|
|
411
|
+
const action = makeAction({ status: "approved" });
|
|
412
|
+
mockGetAction.mockResolvedValueOnce(action);
|
|
413
|
+
mockApproveAction.mockResolvedValueOnce(null);
|
|
414
|
+
|
|
415
|
+
const response = await app.fetch(
|
|
416
|
+
new Request(`http://localhost/api/v1/actions/${VALID_ID}/approve`, {
|
|
417
|
+
method: "POST",
|
|
418
|
+
}),
|
|
419
|
+
);
|
|
420
|
+
expect(response.status).toBe(409);
|
|
421
|
+
|
|
422
|
+
const body = (await response.json()) as Record<string, unknown>;
|
|
423
|
+
expect(body.error).toBe("conflict");
|
|
424
|
+
});
|
|
425
|
+
|
|
426
|
+
it("returns 400 for invalid UUID", async () => {
|
|
427
|
+
const response = await app.fetch(
|
|
428
|
+
new Request("http://localhost/api/v1/actions/not-a-uuid/approve", {
|
|
429
|
+
method: "POST",
|
|
430
|
+
}),
|
|
431
|
+
);
|
|
432
|
+
expect(response.status).toBe(400);
|
|
433
|
+
const body = (await response.json()) as Record<string, unknown>;
|
|
434
|
+
expect(body.error).toBe("invalid_request");
|
|
435
|
+
});
|
|
436
|
+
|
|
437
|
+
it("returns 404 when action not found", async () => {
|
|
438
|
+
mockGetAction.mockResolvedValueOnce(null);
|
|
439
|
+
|
|
440
|
+
const response = await app.fetch(
|
|
441
|
+
new Request(`http://localhost/api/v1/actions/${VALID_ID}/approve`, {
|
|
442
|
+
method: "POST",
|
|
443
|
+
}),
|
|
444
|
+
);
|
|
445
|
+
expect(response.status).toBe(404);
|
|
446
|
+
|
|
447
|
+
const body = (await response.json()) as Record<string, unknown>;
|
|
448
|
+
expect(body.error).toBe("not_found");
|
|
449
|
+
});
|
|
450
|
+
|
|
451
|
+
it("returns 404 when no internal DB", async () => {
|
|
452
|
+
delete process.env.DATABASE_URL;
|
|
453
|
+
|
|
454
|
+
const response = await app.fetch(
|
|
455
|
+
new Request(`http://localhost/api/v1/actions/${VALID_ID}/approve`, {
|
|
456
|
+
method: "POST",
|
|
457
|
+
}),
|
|
458
|
+
);
|
|
459
|
+
expect(response.status).toBe(404);
|
|
460
|
+
});
|
|
461
|
+
|
|
462
|
+
it("passes approverId from auth user", async () => {
|
|
463
|
+
const action = makeAction();
|
|
464
|
+
const approvedAction = makeAction({ status: "approved", approved_by: "u1" });
|
|
465
|
+
mockGetAction.mockResolvedValueOnce(action);
|
|
466
|
+
mockApproveAction.mockResolvedValueOnce(approvedAction);
|
|
467
|
+
|
|
468
|
+
await app.fetch(
|
|
469
|
+
new Request(`http://localhost/api/v1/actions/${VALID_ID}/approve`, {
|
|
470
|
+
method: "POST",
|
|
471
|
+
}),
|
|
472
|
+
);
|
|
473
|
+
|
|
474
|
+
expect(mockApproveAction).toHaveBeenCalledTimes(1);
|
|
475
|
+
const call = mockApproveAction.mock.calls[0] as unknown as [string, string, unknown];
|
|
476
|
+
expect(call[0]).toBe(VALID_ID);
|
|
477
|
+
expect(call[1]).toBe("u1");
|
|
478
|
+
});
|
|
479
|
+
|
|
480
|
+
it("looks up executor via getActionExecutor with action ID", async () => {
|
|
481
|
+
const action = makeAction({ action_type: "send_email" });
|
|
482
|
+
const approvedAction = makeAction({ status: "approved" });
|
|
483
|
+
mockGetAction.mockResolvedValueOnce(action);
|
|
484
|
+
mockGetActionExecutor.mockReturnValueOnce(undefined);
|
|
485
|
+
mockApproveAction.mockResolvedValueOnce(approvedAction);
|
|
486
|
+
|
|
487
|
+
await app.fetch(
|
|
488
|
+
new Request(`http://localhost/api/v1/actions/${VALID_ID}/approve`, {
|
|
489
|
+
method: "POST",
|
|
490
|
+
}),
|
|
491
|
+
);
|
|
492
|
+
|
|
493
|
+
expect(mockGetActionExecutor).toHaveBeenCalledWith(VALID_ID);
|
|
494
|
+
});
|
|
495
|
+
|
|
496
|
+
it("returns 403 for admin-only action when approver is the requester", async () => {
|
|
497
|
+
const action = makeAction({ requested_by: "u1", action_type: "admin:action" });
|
|
498
|
+
mockGetAction.mockResolvedValueOnce(action);
|
|
499
|
+
mockGetActionConfig.mockReturnValueOnce({ approval: "admin-only" });
|
|
500
|
+
|
|
501
|
+
const response = await app.fetch(
|
|
502
|
+
new Request(`http://localhost/api/v1/actions/${VALID_ID}/approve`, {
|
|
503
|
+
method: "POST",
|
|
504
|
+
}),
|
|
505
|
+
);
|
|
506
|
+
expect(response.status).toBe(403);
|
|
507
|
+
|
|
508
|
+
const body = (await response.json()) as Record<string, unknown>;
|
|
509
|
+
expect(body.error).toBe("forbidden");
|
|
510
|
+
});
|
|
511
|
+
});
|
|
512
|
+
|
|
513
|
+
// -------------------------------------------------------------------------
|
|
514
|
+
// POST /api/v1/actions/:id/deny
|
|
515
|
+
// -------------------------------------------------------------------------
|
|
516
|
+
|
|
517
|
+
describe("POST /api/v1/actions/:id/deny", () => {
|
|
518
|
+
it("returns 200 on successful denial", async () => {
|
|
519
|
+
const action = makeAction();
|
|
520
|
+
mockGetAction.mockResolvedValueOnce(action);
|
|
521
|
+
const deniedAction = makeAction({
|
|
522
|
+
status: "denied",
|
|
523
|
+
resolved_at: "2024-06-01T01:00:00Z",
|
|
524
|
+
approved_by: "u1",
|
|
525
|
+
});
|
|
526
|
+
mockDenyAction.mockResolvedValueOnce(deniedAction);
|
|
527
|
+
|
|
528
|
+
const response = await app.fetch(
|
|
529
|
+
new Request(`http://localhost/api/v1/actions/${VALID_ID}/deny`, {
|
|
530
|
+
method: "POST",
|
|
531
|
+
}),
|
|
532
|
+
);
|
|
533
|
+
expect(response.status).toBe(200);
|
|
534
|
+
|
|
535
|
+
const body = (await response.json()) as Record<string, unknown>;
|
|
536
|
+
expect(body.status).toBe("denied");
|
|
537
|
+
});
|
|
538
|
+
|
|
539
|
+
it("returns 404 when action not found", async () => {
|
|
540
|
+
mockGetAction.mockResolvedValueOnce(null);
|
|
541
|
+
|
|
542
|
+
const response = await app.fetch(
|
|
543
|
+
new Request(`http://localhost/api/v1/actions/${VALID_ID}/deny`, {
|
|
544
|
+
method: "POST",
|
|
545
|
+
}),
|
|
546
|
+
);
|
|
547
|
+
expect(response.status).toBe(404);
|
|
548
|
+
|
|
549
|
+
const body = (await response.json()) as Record<string, unknown>;
|
|
550
|
+
expect(body.error).toBe("not_found");
|
|
551
|
+
});
|
|
552
|
+
|
|
553
|
+
it("returns 409 when action already resolved", async () => {
|
|
554
|
+
const action = makeAction();
|
|
555
|
+
mockGetAction.mockResolvedValueOnce(action);
|
|
556
|
+
mockDenyAction.mockResolvedValueOnce(null);
|
|
557
|
+
|
|
558
|
+
const response = await app.fetch(
|
|
559
|
+
new Request(`http://localhost/api/v1/actions/${VALID_ID}/deny`, {
|
|
560
|
+
method: "POST",
|
|
561
|
+
}),
|
|
562
|
+
);
|
|
563
|
+
expect(response.status).toBe(409);
|
|
564
|
+
|
|
565
|
+
const body = (await response.json()) as Record<string, unknown>;
|
|
566
|
+
expect(body.error).toBe("conflict");
|
|
567
|
+
});
|
|
568
|
+
|
|
569
|
+
it("returns 400 for invalid UUID", async () => {
|
|
570
|
+
const response = await app.fetch(
|
|
571
|
+
new Request("http://localhost/api/v1/actions/not-a-uuid/deny", {
|
|
572
|
+
method: "POST",
|
|
573
|
+
}),
|
|
574
|
+
);
|
|
575
|
+
expect(response.status).toBe(400);
|
|
576
|
+
const body = (await response.json()) as Record<string, unknown>;
|
|
577
|
+
expect(body.error).toBe("invalid_request");
|
|
578
|
+
});
|
|
579
|
+
|
|
580
|
+
it("returns 404 when no internal DB", async () => {
|
|
581
|
+
delete process.env.DATABASE_URL;
|
|
582
|
+
|
|
583
|
+
const response = await app.fetch(
|
|
584
|
+
new Request(`http://localhost/api/v1/actions/${VALID_ID}/deny`, {
|
|
585
|
+
method: "POST",
|
|
586
|
+
}),
|
|
587
|
+
);
|
|
588
|
+
expect(response.status).toBe(404);
|
|
589
|
+
});
|
|
590
|
+
|
|
591
|
+
it("accepts reason in body", async () => {
|
|
592
|
+
const action = makeAction();
|
|
593
|
+
mockGetAction.mockResolvedValueOnce(action);
|
|
594
|
+
const deniedAction = makeAction({
|
|
595
|
+
status: "denied",
|
|
596
|
+
error: "Not appropriate",
|
|
597
|
+
});
|
|
598
|
+
mockDenyAction.mockResolvedValueOnce(deniedAction);
|
|
599
|
+
|
|
600
|
+
const response = await app.fetch(
|
|
601
|
+
new Request(`http://localhost/api/v1/actions/${VALID_ID}/deny`, {
|
|
602
|
+
method: "POST",
|
|
603
|
+
headers: { "Content-Type": "application/json" },
|
|
604
|
+
body: JSON.stringify({ reason: "Not appropriate" }),
|
|
605
|
+
}),
|
|
606
|
+
);
|
|
607
|
+
expect(response.status).toBe(200);
|
|
608
|
+
|
|
609
|
+
expect(mockDenyAction).toHaveBeenCalledTimes(1);
|
|
610
|
+
const call = mockDenyAction.mock.calls[0] as unknown as [string, string, string | undefined];
|
|
611
|
+
expect(call[0]).toBe(VALID_ID);
|
|
612
|
+
expect(call[1]).toBe("u1");
|
|
613
|
+
expect(call[2]).toBe("Not appropriate");
|
|
614
|
+
});
|
|
615
|
+
|
|
616
|
+
it("works without a body (reason is optional)", async () => {
|
|
617
|
+
const action = makeAction();
|
|
618
|
+
mockGetAction.mockResolvedValueOnce(action);
|
|
619
|
+
const deniedAction = makeAction({ status: "denied" });
|
|
620
|
+
mockDenyAction.mockResolvedValueOnce(deniedAction);
|
|
621
|
+
|
|
622
|
+
const response = await app.fetch(
|
|
623
|
+
new Request(`http://localhost/api/v1/actions/${VALID_ID}/deny`, {
|
|
624
|
+
method: "POST",
|
|
625
|
+
}),
|
|
626
|
+
);
|
|
627
|
+
expect(response.status).toBe(200);
|
|
628
|
+
|
|
629
|
+
const call = mockDenyAction.mock.calls[0] as unknown as [string, string, string | undefined];
|
|
630
|
+
expect(call[2]).toBeUndefined();
|
|
631
|
+
});
|
|
632
|
+
|
|
633
|
+
it("passes denierId from auth user", async () => {
|
|
634
|
+
const action = makeAction();
|
|
635
|
+
mockGetAction.mockResolvedValueOnce(action);
|
|
636
|
+
const deniedAction = makeAction({ status: "denied", approved_by: "u1" });
|
|
637
|
+
mockDenyAction.mockResolvedValueOnce(deniedAction);
|
|
638
|
+
|
|
639
|
+
await app.fetch(
|
|
640
|
+
new Request(`http://localhost/api/v1/actions/${VALID_ID}/deny`, {
|
|
641
|
+
method: "POST",
|
|
642
|
+
}),
|
|
643
|
+
);
|
|
644
|
+
|
|
645
|
+
const call = mockDenyAction.mock.calls[0] as unknown as [string, string, string | undefined];
|
|
646
|
+
expect(call[0]).toBe(VALID_ID);
|
|
647
|
+
expect(call[1]).toBe("u1");
|
|
648
|
+
});
|
|
649
|
+
|
|
650
|
+
it("returns 403 for admin-only action when denier is the requester", async () => {
|
|
651
|
+
const action = makeAction({ requested_by: "u1", action_type: "admin:action" });
|
|
652
|
+
mockGetAction.mockResolvedValueOnce(action);
|
|
653
|
+
mockGetActionConfig.mockReturnValueOnce({ approval: "admin-only" });
|
|
654
|
+
|
|
655
|
+
const response = await app.fetch(
|
|
656
|
+
new Request(`http://localhost/api/v1/actions/${VALID_ID}/deny`, {
|
|
657
|
+
method: "POST",
|
|
658
|
+
}),
|
|
659
|
+
);
|
|
660
|
+
expect(response.status).toBe(403);
|
|
661
|
+
|
|
662
|
+
const body = (await response.json()) as Record<string, unknown>;
|
|
663
|
+
expect(body.error).toBe("forbidden");
|
|
664
|
+
});
|
|
665
|
+
|
|
666
|
+
it("returns 400 when Content-Type is application/json but body is invalid JSON", async () => {
|
|
667
|
+
const action = makeAction();
|
|
668
|
+
mockGetAction.mockResolvedValueOnce(action);
|
|
669
|
+
|
|
670
|
+
const response = await app.fetch(
|
|
671
|
+
new Request(`http://localhost/api/v1/actions/${VALID_ID}/deny`, {
|
|
672
|
+
method: "POST",
|
|
673
|
+
headers: { "Content-Type": "application/json" },
|
|
674
|
+
body: "not valid json{",
|
|
675
|
+
}),
|
|
676
|
+
);
|
|
677
|
+
expect(response.status).toBe(400);
|
|
678
|
+
|
|
679
|
+
const body = (await response.json()) as Record<string, unknown>;
|
|
680
|
+
expect(body.error).toBe("invalid_request");
|
|
681
|
+
});
|
|
682
|
+
});
|
|
683
|
+
});
|