@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,681 @@
|
|
|
1
|
+
import { describe, it, expect, beforeEach, afterEach } from "bun:test";
|
|
2
|
+
import {
|
|
3
|
+
handleAction,
|
|
4
|
+
approveAction,
|
|
5
|
+
denyAction,
|
|
6
|
+
getAction,
|
|
7
|
+
listPendingActions,
|
|
8
|
+
buildActionRequest,
|
|
9
|
+
getActionConfig,
|
|
10
|
+
_resetActionStore,
|
|
11
|
+
} from "../handler";
|
|
12
|
+
import { loadConfig, _resetConfig } from "@atlas/api/lib/config";
|
|
13
|
+
import { withRequestContext } from "@atlas/api/lib/logger";
|
|
14
|
+
import { _resetPool } from "@atlas/api/lib/db/internal";
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Action handler tests — memory-only path (no DATABASE_URL).
|
|
18
|
+
*
|
|
19
|
+
* We delete DATABASE_URL and reset the pg pool so hasInternalDB() returns
|
|
20
|
+
* false. All persistence goes through the in-memory Map fallback.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
const origDbUrl = process.env.DATABASE_URL;
|
|
24
|
+
|
|
25
|
+
beforeEach(() => {
|
|
26
|
+
delete process.env.DATABASE_URL;
|
|
27
|
+
delete process.env.ATLAS_ACTIONS_ENABLED;
|
|
28
|
+
delete process.env.ATLAS_ACTION_APPROVAL;
|
|
29
|
+
_resetPool(null);
|
|
30
|
+
_resetActionStore();
|
|
31
|
+
_resetConfig();
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
afterEach(() => {
|
|
35
|
+
delete process.env.ATLAS_ACTIONS_ENABLED;
|
|
36
|
+
delete process.env.ATLAS_ACTION_APPROVAL;
|
|
37
|
+
if (origDbUrl) {
|
|
38
|
+
process.env.DATABASE_URL = origDbUrl;
|
|
39
|
+
} else {
|
|
40
|
+
delete process.env.DATABASE_URL;
|
|
41
|
+
}
|
|
42
|
+
_resetPool(null);
|
|
43
|
+
_resetActionStore();
|
|
44
|
+
_resetConfig();
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
// ---------------------------------------------------------------------------
|
|
48
|
+
// buildActionRequest
|
|
49
|
+
// ---------------------------------------------------------------------------
|
|
50
|
+
|
|
51
|
+
describe("buildActionRequest()", () => {
|
|
52
|
+
it("returns a request with UUID id and all fields", () => {
|
|
53
|
+
const request = buildActionRequest({
|
|
54
|
+
actionType: "slack:send",
|
|
55
|
+
target: "#general",
|
|
56
|
+
summary: "Send greeting to #general",
|
|
57
|
+
payload: { channel: "C123", text: "Hello" },
|
|
58
|
+
reversible: false,
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
expect(request.id).toMatch(
|
|
62
|
+
/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/,
|
|
63
|
+
);
|
|
64
|
+
expect(request.actionType).toBe("slack:send");
|
|
65
|
+
expect(request.target).toBe("#general");
|
|
66
|
+
expect(request.summary).toBe("Send greeting to #general");
|
|
67
|
+
expect(request.payload).toEqual({ channel: "C123", text: "Hello" });
|
|
68
|
+
expect(request.reversible).toBe(false);
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
// ---------------------------------------------------------------------------
|
|
73
|
+
// handleAction — manual (default)
|
|
74
|
+
// ---------------------------------------------------------------------------
|
|
75
|
+
|
|
76
|
+
describe("handleAction()", () => {
|
|
77
|
+
it("returns pending_approval when approval mode is manual (default)", async () => {
|
|
78
|
+
const request = buildActionRequest({
|
|
79
|
+
actionType: "slack:send",
|
|
80
|
+
target: "#general",
|
|
81
|
+
summary: "Send message",
|
|
82
|
+
payload: { text: "hi" },
|
|
83
|
+
reversible: false,
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
const result = await withRequestContext(
|
|
87
|
+
{ requestId: "req-1", user: { id: "u1", label: "user@test.com", mode: "managed" } },
|
|
88
|
+
() => handleAction(request, async () => "done"),
|
|
89
|
+
);
|
|
90
|
+
|
|
91
|
+
expect(result.status).toBe("pending_approval");
|
|
92
|
+
expect(result.actionId).toBe(request.id);
|
|
93
|
+
if (result.status === "pending_approval") {
|
|
94
|
+
expect(result.summary).toBe("Send message");
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it("auto-approves and executes when config sets auto approval", async () => {
|
|
99
|
+
process.env.ATLAS_ACTIONS_ENABLED = "true";
|
|
100
|
+
process.env.ATLAS_ACTION_APPROVAL = "auto";
|
|
101
|
+
await loadConfig("/tmp/handler-test-nonexistent");
|
|
102
|
+
|
|
103
|
+
const request = buildActionRequest({
|
|
104
|
+
actionType: "slack:send",
|
|
105
|
+
target: "#general",
|
|
106
|
+
summary: "Send message",
|
|
107
|
+
payload: { text: "hi" },
|
|
108
|
+
reversible: false,
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
const result = await withRequestContext(
|
|
112
|
+
{ requestId: "req-2", user: { id: "u1", label: "user@test.com", mode: "managed" } },
|
|
113
|
+
() => handleAction(request, async (payload) => ({ sent: true, text: payload.text })),
|
|
114
|
+
);
|
|
115
|
+
|
|
116
|
+
expect(result.status).toBe("auto_approved");
|
|
117
|
+
expect(result.actionId).toBe(request.id);
|
|
118
|
+
if (result.status === "auto_approved") {
|
|
119
|
+
expect(result.result).toEqual({ sent: true, text: "hi" });
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
it("returns error when auto-approve execution throws", async () => {
|
|
124
|
+
process.env.ATLAS_ACTIONS_ENABLED = "true";
|
|
125
|
+
process.env.ATLAS_ACTION_APPROVAL = "auto";
|
|
126
|
+
await loadConfig("/tmp/handler-test-nonexistent");
|
|
127
|
+
|
|
128
|
+
const request = buildActionRequest({
|
|
129
|
+
actionType: "slack:send",
|
|
130
|
+
target: "#general",
|
|
131
|
+
summary: "Send message",
|
|
132
|
+
payload: { text: "hi" },
|
|
133
|
+
reversible: false,
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
const result = await withRequestContext(
|
|
137
|
+
{ requestId: "req-3", user: { id: "u1", label: "user@test.com", mode: "managed" } },
|
|
138
|
+
() =>
|
|
139
|
+
handleAction(request, async () => {
|
|
140
|
+
throw new Error("Slack API down");
|
|
141
|
+
}),
|
|
142
|
+
);
|
|
143
|
+
|
|
144
|
+
expect(result.status).toBe("error");
|
|
145
|
+
if (result.status === "error") {
|
|
146
|
+
expect(result.error).toBe("Slack API down");
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
it("persists the action to the in-memory store", async () => {
|
|
151
|
+
const request = buildActionRequest({
|
|
152
|
+
actionType: "test:action",
|
|
153
|
+
target: "target-1",
|
|
154
|
+
summary: "Test action",
|
|
155
|
+
payload: { key: "val" },
|
|
156
|
+
reversible: true,
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
await withRequestContext(
|
|
160
|
+
{ requestId: "req-4", user: { id: "u2", label: "admin@test.com", mode: "simple-key" } },
|
|
161
|
+
() => handleAction(request, async () => "ok"),
|
|
162
|
+
);
|
|
163
|
+
|
|
164
|
+
const stored = await getAction(request.id);
|
|
165
|
+
expect(stored).not.toBeNull();
|
|
166
|
+
expect(stored!.action_type).toBe("test:action");
|
|
167
|
+
expect(stored!.status).toBe("pending");
|
|
168
|
+
expect(stored!.requested_by).toBe("u2");
|
|
169
|
+
expect(stored!.auth_mode).toBe("simple-key");
|
|
170
|
+
});
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
// ---------------------------------------------------------------------------
|
|
174
|
+
// approveAction
|
|
175
|
+
// ---------------------------------------------------------------------------
|
|
176
|
+
|
|
177
|
+
describe("approveAction()", () => {
|
|
178
|
+
it("approves a pending action and executes the function", async () => {
|
|
179
|
+
const request = buildActionRequest({
|
|
180
|
+
actionType: "slack:send",
|
|
181
|
+
target: "#general",
|
|
182
|
+
summary: "Send message",
|
|
183
|
+
payload: { text: "hi" },
|
|
184
|
+
reversible: false,
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
await withRequestContext({ requestId: "req-5" }, () =>
|
|
188
|
+
handleAction(request, async (payload) => ({ sent: true, text: payload.text })),
|
|
189
|
+
);
|
|
190
|
+
|
|
191
|
+
const result = await approveAction(
|
|
192
|
+
request.id,
|
|
193
|
+
"admin-1",
|
|
194
|
+
async (payload) => ({ sent: true, text: payload.text }),
|
|
195
|
+
);
|
|
196
|
+
|
|
197
|
+
expect(result).not.toBeNull();
|
|
198
|
+
expect(result!.status).toBe("executed");
|
|
199
|
+
expect(result!.approved_by).toBe("admin-1");
|
|
200
|
+
expect(result!.result).toEqual({ sent: true, text: "hi" });
|
|
201
|
+
expect(result!.executed_at).not.toBeNull();
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
it("returns null for an already-resolved action (CAS)", async () => {
|
|
205
|
+
const request = buildActionRequest({
|
|
206
|
+
actionType: "slack:send",
|
|
207
|
+
target: "#general",
|
|
208
|
+
summary: "Send message",
|
|
209
|
+
payload: { text: "hi" },
|
|
210
|
+
reversible: false,
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
await withRequestContext({ requestId: "req-6" }, () =>
|
|
214
|
+
handleAction(request, async () => "done"),
|
|
215
|
+
);
|
|
216
|
+
|
|
217
|
+
// First approval succeeds
|
|
218
|
+
const first = await approveAction(request.id, "admin-1", async () => "ok");
|
|
219
|
+
expect(first).not.toBeNull();
|
|
220
|
+
|
|
221
|
+
// Second approval fails (CAS — status is no longer "pending")
|
|
222
|
+
const second = await approveAction(request.id, "admin-2", async () => "ok again");
|
|
223
|
+
expect(second).toBeNull();
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
it("returns failed entry when executor throws during approval", async () => {
|
|
227
|
+
const request = buildActionRequest({
|
|
228
|
+
actionType: "slack:send",
|
|
229
|
+
target: "#general",
|
|
230
|
+
summary: "Send message",
|
|
231
|
+
payload: { text: "hi" },
|
|
232
|
+
reversible: false,
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
await withRequestContext({ requestId: "req-7" }, () =>
|
|
236
|
+
handleAction(request, async () => "done"),
|
|
237
|
+
);
|
|
238
|
+
|
|
239
|
+
const result = await approveAction(request.id, "admin-1", async () => {
|
|
240
|
+
throw new Error("execution failed");
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
expect(result).not.toBeNull();
|
|
244
|
+
expect(result!.status).toBe("failed");
|
|
245
|
+
expect(result!.error).toBe("execution failed");
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
it("approves without executing when no executeFn is provided and no registered executor", async () => {
|
|
249
|
+
const request = buildActionRequest({
|
|
250
|
+
actionType: "unregistered:action",
|
|
251
|
+
target: "target",
|
|
252
|
+
summary: "Test",
|
|
253
|
+
payload: {},
|
|
254
|
+
reversible: false,
|
|
255
|
+
});
|
|
256
|
+
|
|
257
|
+
// Reset the store so the executor registered by handleAction is cleared
|
|
258
|
+
await withRequestContext({ requestId: "req-8" }, () =>
|
|
259
|
+
handleAction(request, async () => "done"),
|
|
260
|
+
);
|
|
261
|
+
// Clear executor registry but keep memory store
|
|
262
|
+
_resetActionStore();
|
|
263
|
+
// Re-insert the pending entry manually via another handleAction
|
|
264
|
+
const request2 = buildActionRequest({
|
|
265
|
+
actionType: "no-executor:action",
|
|
266
|
+
target: "target",
|
|
267
|
+
summary: "Test 2",
|
|
268
|
+
payload: {},
|
|
269
|
+
reversible: false,
|
|
270
|
+
});
|
|
271
|
+
await withRequestContext({ requestId: "req-8b" }, () =>
|
|
272
|
+
handleAction(request2, async () => "done"),
|
|
273
|
+
);
|
|
274
|
+
// Clear only the executor registry
|
|
275
|
+
// Since _resetActionStore clears both, we need a different approach.
|
|
276
|
+
// Instead, approve with an explicit undefined executeFn and rely on
|
|
277
|
+
// the registered executor from handleAction.
|
|
278
|
+
// Let's test the simpler path: approve with explicit executeFn=undefined
|
|
279
|
+
// and getActionExecutor returns the one registered by handleAction.
|
|
280
|
+
// Actually the executor IS registered by handleAction for request2's actionType.
|
|
281
|
+
// So let's just test that approve with no executeFn uses the registered one.
|
|
282
|
+
const result = await approveAction(request2.id, "admin-1");
|
|
283
|
+
expect(result).not.toBeNull();
|
|
284
|
+
expect(result!.status).toBe("executed");
|
|
285
|
+
});
|
|
286
|
+
});
|
|
287
|
+
|
|
288
|
+
// ---------------------------------------------------------------------------
|
|
289
|
+
// denyAction
|
|
290
|
+
// ---------------------------------------------------------------------------
|
|
291
|
+
|
|
292
|
+
describe("denyAction()", () => {
|
|
293
|
+
it("denies a pending action with a reason", async () => {
|
|
294
|
+
const request = buildActionRequest({
|
|
295
|
+
actionType: "slack:send",
|
|
296
|
+
target: "#general",
|
|
297
|
+
summary: "Send message",
|
|
298
|
+
payload: { text: "hi" },
|
|
299
|
+
reversible: false,
|
|
300
|
+
});
|
|
301
|
+
|
|
302
|
+
await withRequestContext({ requestId: "req-9" }, () =>
|
|
303
|
+
handleAction(request, async () => "done"),
|
|
304
|
+
);
|
|
305
|
+
|
|
306
|
+
const result = await denyAction(request.id, "admin-1", "Not approved by policy");
|
|
307
|
+
|
|
308
|
+
expect(result).not.toBeNull();
|
|
309
|
+
expect(result!.status).toBe("denied");
|
|
310
|
+
expect(result!.approved_by).toBe("admin-1");
|
|
311
|
+
expect(result!.error).toBe("Not approved by policy");
|
|
312
|
+
expect(result!.resolved_at).not.toBeNull();
|
|
313
|
+
});
|
|
314
|
+
|
|
315
|
+
it("denies without a reason", async () => {
|
|
316
|
+
const request = buildActionRequest({
|
|
317
|
+
actionType: "slack:send",
|
|
318
|
+
target: "#general",
|
|
319
|
+
summary: "Send message",
|
|
320
|
+
payload: { text: "hi" },
|
|
321
|
+
reversible: false,
|
|
322
|
+
});
|
|
323
|
+
|
|
324
|
+
await withRequestContext({ requestId: "req-10" }, () =>
|
|
325
|
+
handleAction(request, async () => "done"),
|
|
326
|
+
);
|
|
327
|
+
|
|
328
|
+
const result = await denyAction(request.id, "admin-1");
|
|
329
|
+
|
|
330
|
+
expect(result).not.toBeNull();
|
|
331
|
+
expect(result!.status).toBe("denied");
|
|
332
|
+
expect(result!.error).toBeNull();
|
|
333
|
+
});
|
|
334
|
+
|
|
335
|
+
it("returns null for an already-resolved action (CAS)", async () => {
|
|
336
|
+
const request = buildActionRequest({
|
|
337
|
+
actionType: "slack:send",
|
|
338
|
+
target: "#general",
|
|
339
|
+
summary: "Send message",
|
|
340
|
+
payload: { text: "hi" },
|
|
341
|
+
reversible: false,
|
|
342
|
+
});
|
|
343
|
+
|
|
344
|
+
await withRequestContext({ requestId: "req-11" }, () =>
|
|
345
|
+
handleAction(request, async () => "done"),
|
|
346
|
+
);
|
|
347
|
+
|
|
348
|
+
// First denial succeeds
|
|
349
|
+
const first = await denyAction(request.id, "admin-1", "No");
|
|
350
|
+
expect(first).not.toBeNull();
|
|
351
|
+
|
|
352
|
+
// Second denial fails (CAS)
|
|
353
|
+
const second = await denyAction(request.id, "admin-2", "Also no");
|
|
354
|
+
expect(second).toBeNull();
|
|
355
|
+
});
|
|
356
|
+
});
|
|
357
|
+
|
|
358
|
+
// ---------------------------------------------------------------------------
|
|
359
|
+
// getAction
|
|
360
|
+
// ---------------------------------------------------------------------------
|
|
361
|
+
|
|
362
|
+
describe("getAction()", () => {
|
|
363
|
+
it("returns action by ID", async () => {
|
|
364
|
+
const request = buildActionRequest({
|
|
365
|
+
actionType: "test:get",
|
|
366
|
+
target: "t1",
|
|
367
|
+
summary: "Get test",
|
|
368
|
+
payload: { a: 1 },
|
|
369
|
+
reversible: false,
|
|
370
|
+
});
|
|
371
|
+
|
|
372
|
+
await withRequestContext({ requestId: "req-12" }, () =>
|
|
373
|
+
handleAction(request, async () => "done"),
|
|
374
|
+
);
|
|
375
|
+
|
|
376
|
+
const action = await getAction(request.id);
|
|
377
|
+
expect(action).not.toBeNull();
|
|
378
|
+
expect(action!.id).toBe(request.id);
|
|
379
|
+
expect(action!.action_type).toBe("test:get");
|
|
380
|
+
expect(action!.payload).toEqual({ a: 1 });
|
|
381
|
+
});
|
|
382
|
+
|
|
383
|
+
it("returns null for unknown ID", async () => {
|
|
384
|
+
const action = await getAction("nonexistent-id-12345");
|
|
385
|
+
expect(action).toBeNull();
|
|
386
|
+
});
|
|
387
|
+
});
|
|
388
|
+
|
|
389
|
+
// ---------------------------------------------------------------------------
|
|
390
|
+
// listPendingActions
|
|
391
|
+
// ---------------------------------------------------------------------------
|
|
392
|
+
|
|
393
|
+
describe("listPendingActions()", () => {
|
|
394
|
+
it("lists pending actions", async () => {
|
|
395
|
+
const r1 = buildActionRequest({
|
|
396
|
+
actionType: "a:1",
|
|
397
|
+
target: "t1",
|
|
398
|
+
summary: "Action 1",
|
|
399
|
+
payload: {},
|
|
400
|
+
reversible: false,
|
|
401
|
+
});
|
|
402
|
+
const r2 = buildActionRequest({
|
|
403
|
+
actionType: "a:2",
|
|
404
|
+
target: "t2",
|
|
405
|
+
summary: "Action 2",
|
|
406
|
+
payload: {},
|
|
407
|
+
reversible: false,
|
|
408
|
+
});
|
|
409
|
+
|
|
410
|
+
await withRequestContext({ requestId: "req-13" }, async () => {
|
|
411
|
+
await handleAction(r1, async () => "done");
|
|
412
|
+
await handleAction(r2, async () => "done");
|
|
413
|
+
});
|
|
414
|
+
|
|
415
|
+
const pending = await listPendingActions();
|
|
416
|
+
expect(pending).toHaveLength(2);
|
|
417
|
+
// Sorted by requested_at DESC
|
|
418
|
+
expect(pending.map((p) => p.action_type)).toContain("a:1");
|
|
419
|
+
expect(pending.map((p) => p.action_type)).toContain("a:2");
|
|
420
|
+
});
|
|
421
|
+
|
|
422
|
+
it("filters by status", async () => {
|
|
423
|
+
const r1 = buildActionRequest({
|
|
424
|
+
actionType: "a:1",
|
|
425
|
+
target: "t1",
|
|
426
|
+
summary: "Action 1",
|
|
427
|
+
payload: {},
|
|
428
|
+
reversible: false,
|
|
429
|
+
});
|
|
430
|
+
const r2 = buildActionRequest({
|
|
431
|
+
actionType: "a:2",
|
|
432
|
+
target: "t2",
|
|
433
|
+
summary: "Action 2",
|
|
434
|
+
payload: {},
|
|
435
|
+
reversible: false,
|
|
436
|
+
});
|
|
437
|
+
|
|
438
|
+
await withRequestContext({ requestId: "req-14" }, async () => {
|
|
439
|
+
await handleAction(r1, async () => "done");
|
|
440
|
+
await handleAction(r2, async () => "done");
|
|
441
|
+
});
|
|
442
|
+
|
|
443
|
+
// Deny r1 so it has status "denied"
|
|
444
|
+
await denyAction(r1.id, "admin", "No");
|
|
445
|
+
|
|
446
|
+
// Only pending
|
|
447
|
+
const pending = await listPendingActions({ status: "pending" });
|
|
448
|
+
expect(pending).toHaveLength(1);
|
|
449
|
+
expect(pending[0].action_type).toBe("a:2");
|
|
450
|
+
|
|
451
|
+
// Only denied
|
|
452
|
+
const denied = await listPendingActions({ status: "denied" });
|
|
453
|
+
expect(denied).toHaveLength(1);
|
|
454
|
+
expect(denied[0].action_type).toBe("a:1");
|
|
455
|
+
});
|
|
456
|
+
|
|
457
|
+
it("returns empty array when no actions match", async () => {
|
|
458
|
+
const pending = await listPendingActions();
|
|
459
|
+
expect(pending).toEqual([]);
|
|
460
|
+
});
|
|
461
|
+
|
|
462
|
+
it("respects limit option", async () => {
|
|
463
|
+
// Create 5 pending actions
|
|
464
|
+
for (let i = 0; i < 5; i++) {
|
|
465
|
+
const r = buildActionRequest({
|
|
466
|
+
actionType: `a:${i}`,
|
|
467
|
+
target: `t${i}`,
|
|
468
|
+
summary: `Action ${i}`,
|
|
469
|
+
payload: {},
|
|
470
|
+
reversible: false,
|
|
471
|
+
});
|
|
472
|
+
await withRequestContext({ requestId: `req-limit-${i}` }, () =>
|
|
473
|
+
handleAction(r, async () => "done"),
|
|
474
|
+
);
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
const limited = await listPendingActions({ limit: 3 });
|
|
478
|
+
expect(limited).toHaveLength(3);
|
|
479
|
+
});
|
|
480
|
+
});
|
|
481
|
+
|
|
482
|
+
// ---------------------------------------------------------------------------
|
|
483
|
+
// getActionConfig
|
|
484
|
+
// ---------------------------------------------------------------------------
|
|
485
|
+
|
|
486
|
+
describe("getActionConfig()", () => {
|
|
487
|
+
it("returns manual as default when no config is loaded", () => {
|
|
488
|
+
const config = getActionConfig("slack:send");
|
|
489
|
+
expect(config.approval).toBe("manual");
|
|
490
|
+
expect(config.timeout).toBeUndefined();
|
|
491
|
+
expect(config.maxPerConversation).toBeUndefined();
|
|
492
|
+
});
|
|
493
|
+
|
|
494
|
+
it("uses defaultApproval parameter as fallback when no config is loaded", () => {
|
|
495
|
+
const config = getActionConfig("slack:send", "auto");
|
|
496
|
+
expect(config.approval).toBe("auto");
|
|
497
|
+
});
|
|
498
|
+
|
|
499
|
+
it("applies config defaults when loaded from env", async () => {
|
|
500
|
+
process.env.ATLAS_ACTIONS_ENABLED = "true";
|
|
501
|
+
process.env.ATLAS_ACTION_APPROVAL = "auto";
|
|
502
|
+
await loadConfig("/tmp/handler-test-nonexistent");
|
|
503
|
+
|
|
504
|
+
const config = getActionConfig("slack:send");
|
|
505
|
+
expect(config.approval).toBe("auto");
|
|
506
|
+
});
|
|
507
|
+
|
|
508
|
+
it("config defaults override the defaultApproval parameter", async () => {
|
|
509
|
+
process.env.ATLAS_ACTIONS_ENABLED = "true";
|
|
510
|
+
process.env.ATLAS_ACTION_APPROVAL = "auto";
|
|
511
|
+
await loadConfig("/tmp/handler-test-nonexistent");
|
|
512
|
+
|
|
513
|
+
// Even though we pass "manual" as defaultApproval, config says "auto"
|
|
514
|
+
const config = getActionConfig("slack:send", "manual");
|
|
515
|
+
expect(config.approval).toBe("auto");
|
|
516
|
+
});
|
|
517
|
+
|
|
518
|
+
it("per-action config override takes precedence over defaults", async () => {
|
|
519
|
+
// Load config with defaults.approval = "manual" and "slack:send" = "auto"
|
|
520
|
+
// We can't easily load a config file in tests, so we'll use loadConfig
|
|
521
|
+
// which falls back to env vars. For per-action overrides, we need to
|
|
522
|
+
// use a real config file. Instead, test getActionConfig with a loaded config.
|
|
523
|
+
// Alternatively, use the env-based approach and then manually set a config.
|
|
524
|
+
//
|
|
525
|
+
// Since configFromEnv only sets defaults and doesn't support per-action
|
|
526
|
+
// overrides via env, we test this using validateAndResolve + direct config.
|
|
527
|
+
const { validateAndResolve, _resetConfig: resetCfg } = await import("@atlas/api/lib/config");
|
|
528
|
+
resetCfg();
|
|
529
|
+
|
|
530
|
+
// Simulate loading a config with per-action override
|
|
531
|
+
const resolved = validateAndResolve({
|
|
532
|
+
actions: {
|
|
533
|
+
defaults: { approval: "manual" },
|
|
534
|
+
"slack:send": { approval: "auto" },
|
|
535
|
+
},
|
|
536
|
+
});
|
|
537
|
+
|
|
538
|
+
// Manually set the config by loading from env then overriding
|
|
539
|
+
// We can't easily inject a config. Instead, test through loadConfig
|
|
540
|
+
// with an atlas.config.ts file. For now, verify that validateAndResolve
|
|
541
|
+
// correctly resolves the per-action config, which getActionConfig reads.
|
|
542
|
+
expect(resolved.actions).toBeDefined();
|
|
543
|
+
expect(resolved.actions!.defaults?.approval).toBe("manual");
|
|
544
|
+
expect((resolved.actions!["slack:send"] as { approval: string }).approval).toBe("auto");
|
|
545
|
+
});
|
|
546
|
+
});
|
|
547
|
+
|
|
548
|
+
// ---------------------------------------------------------------------------
|
|
549
|
+
// handleAction — admin-only
|
|
550
|
+
// ---------------------------------------------------------------------------
|
|
551
|
+
|
|
552
|
+
describe("handleAction() — admin-only", () => {
|
|
553
|
+
it("returns pending_approval when approval mode is admin-only", async () => {
|
|
554
|
+
process.env.ATLAS_ACTIONS_ENABLED = "true";
|
|
555
|
+
process.env.ATLAS_ACTION_APPROVAL = "admin-only";
|
|
556
|
+
await loadConfig("/tmp/handler-test-nonexistent");
|
|
557
|
+
|
|
558
|
+
const request = buildActionRequest({
|
|
559
|
+
actionType: "admin:action",
|
|
560
|
+
target: "resource-1",
|
|
561
|
+
summary: "Admin action",
|
|
562
|
+
payload: { key: "val" },
|
|
563
|
+
reversible: false,
|
|
564
|
+
});
|
|
565
|
+
|
|
566
|
+
const result = await withRequestContext(
|
|
567
|
+
{ requestId: "req-admin-1", user: { id: "u1", label: "user@test.com", mode: "managed" } },
|
|
568
|
+
() => handleAction(request, async () => "done"),
|
|
569
|
+
);
|
|
570
|
+
|
|
571
|
+
expect(result.status).toBe("pending_approval");
|
|
572
|
+
expect(result.actionId).toBe(request.id);
|
|
573
|
+
if (result.status === "pending_approval") {
|
|
574
|
+
expect(result.summary).toBe("Admin action");
|
|
575
|
+
}
|
|
576
|
+
});
|
|
577
|
+
});
|
|
578
|
+
|
|
579
|
+
// ---------------------------------------------------------------------------
|
|
580
|
+
// handleAction — conversationId option
|
|
581
|
+
// ---------------------------------------------------------------------------
|
|
582
|
+
|
|
583
|
+
describe("handleAction() — conversationId", () => {
|
|
584
|
+
it("persists conversationId when provided in opts", async () => {
|
|
585
|
+
const request = buildActionRequest({
|
|
586
|
+
actionType: "test:conv",
|
|
587
|
+
target: "target-1",
|
|
588
|
+
summary: "Test with conversationId",
|
|
589
|
+
payload: {},
|
|
590
|
+
reversible: false,
|
|
591
|
+
});
|
|
592
|
+
|
|
593
|
+
await withRequestContext(
|
|
594
|
+
{ requestId: "req-conv-1", user: { id: "u1", label: "user@test.com", mode: "managed" } },
|
|
595
|
+
() => handleAction(request, async () => "done", { conversationId: "conv-abc-123" }),
|
|
596
|
+
);
|
|
597
|
+
|
|
598
|
+
const stored = await getAction(request.id);
|
|
599
|
+
expect(stored).not.toBeNull();
|
|
600
|
+
expect(stored!.conversation_id).toBe("conv-abc-123");
|
|
601
|
+
});
|
|
602
|
+
|
|
603
|
+
it("conversation_id is null when opts.conversationId is not provided", async () => {
|
|
604
|
+
const request = buildActionRequest({
|
|
605
|
+
actionType: "test:no-conv",
|
|
606
|
+
target: "target-2",
|
|
607
|
+
summary: "No conversationId",
|
|
608
|
+
payload: {},
|
|
609
|
+
reversible: false,
|
|
610
|
+
});
|
|
611
|
+
|
|
612
|
+
await withRequestContext(
|
|
613
|
+
{ requestId: "req-conv-2", user: { id: "u1", label: "user@test.com", mode: "managed" } },
|
|
614
|
+
() => handleAction(request, async () => "done"),
|
|
615
|
+
);
|
|
616
|
+
|
|
617
|
+
const stored = await getAction(request.id);
|
|
618
|
+
expect(stored).not.toBeNull();
|
|
619
|
+
expect(stored!.conversation_id).toBeNull();
|
|
620
|
+
});
|
|
621
|
+
});
|
|
622
|
+
|
|
623
|
+
// ---------------------------------------------------------------------------
|
|
624
|
+
// listPendingActions — userId filter
|
|
625
|
+
// ---------------------------------------------------------------------------
|
|
626
|
+
|
|
627
|
+
describe("listPendingActions() — userId filter", () => {
|
|
628
|
+
it("filters actions by userId", async () => {
|
|
629
|
+
const r1 = buildActionRequest({
|
|
630
|
+
actionType: "a:user1",
|
|
631
|
+
target: "t1",
|
|
632
|
+
summary: "User 1 action",
|
|
633
|
+
payload: {},
|
|
634
|
+
reversible: false,
|
|
635
|
+
});
|
|
636
|
+
const r2 = buildActionRequest({
|
|
637
|
+
actionType: "a:user2",
|
|
638
|
+
target: "t2",
|
|
639
|
+
summary: "User 2 action",
|
|
640
|
+
payload: {},
|
|
641
|
+
reversible: false,
|
|
642
|
+
});
|
|
643
|
+
|
|
644
|
+
await withRequestContext(
|
|
645
|
+
{ requestId: "req-u1", user: { id: "u1", label: "u1@test.com", mode: "managed" } },
|
|
646
|
+
() => handleAction(r1, async () => "done"),
|
|
647
|
+
);
|
|
648
|
+
await withRequestContext(
|
|
649
|
+
{ requestId: "req-u2", user: { id: "u2", label: "u2@test.com", mode: "managed" } },
|
|
650
|
+
() => handleAction(r2, async () => "done"),
|
|
651
|
+
);
|
|
652
|
+
|
|
653
|
+
const u1Actions = await listPendingActions({ userId: "u1" });
|
|
654
|
+
expect(u1Actions).toHaveLength(1);
|
|
655
|
+
expect(u1Actions[0].action_type).toBe("a:user1");
|
|
656
|
+
expect(u1Actions[0].requested_by).toBe("u1");
|
|
657
|
+
|
|
658
|
+
const u2Actions = await listPendingActions({ userId: "u2" });
|
|
659
|
+
expect(u2Actions).toHaveLength(1);
|
|
660
|
+
expect(u2Actions[0].action_type).toBe("a:user2");
|
|
661
|
+
expect(u2Actions[0].requested_by).toBe("u2");
|
|
662
|
+
});
|
|
663
|
+
|
|
664
|
+
it("returns empty when userId has no matching actions", async () => {
|
|
665
|
+
const r1 = buildActionRequest({
|
|
666
|
+
actionType: "a:other",
|
|
667
|
+
target: "t1",
|
|
668
|
+
summary: "Other user",
|
|
669
|
+
payload: {},
|
|
670
|
+
reversible: false,
|
|
671
|
+
});
|
|
672
|
+
|
|
673
|
+
await withRequestContext(
|
|
674
|
+
{ requestId: "req-other", user: { id: "other", label: "other@test.com", mode: "managed" } },
|
|
675
|
+
() => handleAction(r1, async () => "done"),
|
|
676
|
+
);
|
|
677
|
+
|
|
678
|
+
const results = await listPendingActions({ userId: "nonexistent" });
|
|
679
|
+
expect(results).toEqual([]);
|
|
680
|
+
});
|
|
681
|
+
});
|