@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,374 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Integration tests for getExploreBackend() sandbox plugin path.
|
|
3
|
+
*
|
|
4
|
+
* Validates that the explore module correctly discovers, sorts, and falls
|
|
5
|
+
* back through sandbox plugins before delegating to built-in backends.
|
|
6
|
+
*
|
|
7
|
+
* Uses mock.module() for the plugin registry. Each test gets a fresh
|
|
8
|
+
* explore module via cache-busting dynamic imports.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { describe, it, expect, beforeEach, afterEach, mock } from "bun:test";
|
|
12
|
+
import type { ExploreBackend, ExecResult } from "../../tools/explore";
|
|
13
|
+
|
|
14
|
+
// ---------------------------------------------------------------------------
|
|
15
|
+
// Mocks — must register before any import of explore.ts
|
|
16
|
+
// ---------------------------------------------------------------------------
|
|
17
|
+
|
|
18
|
+
// Mock logger (all exports from @atlas/api/lib/logger)
|
|
19
|
+
mock.module("@atlas/api/lib/logger", () => ({
|
|
20
|
+
createLogger: () => ({
|
|
21
|
+
info: () => {},
|
|
22
|
+
warn: () => {},
|
|
23
|
+
error: () => {},
|
|
24
|
+
debug: () => {},
|
|
25
|
+
child: () => ({
|
|
26
|
+
info: () => {},
|
|
27
|
+
warn: () => {},
|
|
28
|
+
error: () => {},
|
|
29
|
+
debug: () => {},
|
|
30
|
+
}),
|
|
31
|
+
}),
|
|
32
|
+
getLogger: () => ({
|
|
33
|
+
info: () => {},
|
|
34
|
+
warn: () => {},
|
|
35
|
+
error: () => {},
|
|
36
|
+
debug: () => {},
|
|
37
|
+
child: () => ({
|
|
38
|
+
info: () => {},
|
|
39
|
+
warn: () => {},
|
|
40
|
+
error: () => {},
|
|
41
|
+
debug: () => {},
|
|
42
|
+
}),
|
|
43
|
+
}),
|
|
44
|
+
withRequestContext: <T>(ctx: unknown, fn: () => T) => fn(),
|
|
45
|
+
getRequestContext: () => undefined,
|
|
46
|
+
redactPaths: [],
|
|
47
|
+
}));
|
|
48
|
+
|
|
49
|
+
// Mock tracing (all exports from @atlas/api/lib/tracing)
|
|
50
|
+
mock.module("@atlas/api/lib/tracing", () => ({
|
|
51
|
+
withSpan: async <T>(_name: string, _attrs: unknown, fn: () => Promise<T>) => fn(),
|
|
52
|
+
}));
|
|
53
|
+
|
|
54
|
+
// Mock hooks (all exports from @atlas/api/lib/plugins/hooks)
|
|
55
|
+
mock.module("@atlas/api/lib/plugins/hooks", () => ({
|
|
56
|
+
dispatchHook: async () => {},
|
|
57
|
+
dispatchMutableHook: async <T extends Record<string, unknown>, K extends string & keyof T>(
|
|
58
|
+
_hookName: string,
|
|
59
|
+
context: T,
|
|
60
|
+
mutateKey: K,
|
|
61
|
+
) => context[mutateKey],
|
|
62
|
+
}));
|
|
63
|
+
|
|
64
|
+
// ---------------------------------------------------------------------------
|
|
65
|
+
// Mutable sandbox plugin list — tests control what getByType("sandbox") returns
|
|
66
|
+
// ---------------------------------------------------------------------------
|
|
67
|
+
|
|
68
|
+
let mockSandboxPlugins: Array<{
|
|
69
|
+
id: string;
|
|
70
|
+
type: string;
|
|
71
|
+
version: string;
|
|
72
|
+
sandbox: {
|
|
73
|
+
create(root: string): Promise<ExploreBackend> | ExploreBackend;
|
|
74
|
+
priority?: number;
|
|
75
|
+
};
|
|
76
|
+
[k: string]: unknown;
|
|
77
|
+
}> = [];
|
|
78
|
+
|
|
79
|
+
mock.module("@atlas/api/lib/plugins/registry", () => ({
|
|
80
|
+
plugins: {
|
|
81
|
+
getByType: (type: string) => {
|
|
82
|
+
if (type === "sandbox") return mockSandboxPlugins;
|
|
83
|
+
return [];
|
|
84
|
+
},
|
|
85
|
+
getAllHealthy: () => [],
|
|
86
|
+
get: () => undefined,
|
|
87
|
+
getStatus: () => undefined,
|
|
88
|
+
describe: () => [],
|
|
89
|
+
size: 0,
|
|
90
|
+
register: () => {},
|
|
91
|
+
initializeAll: async () => ({ succeeded: [], failed: [] }),
|
|
92
|
+
healthCheckAll: async () => new Map(),
|
|
93
|
+
teardownAll: async () => {},
|
|
94
|
+
_reset: () => {},
|
|
95
|
+
},
|
|
96
|
+
PluginRegistry: class {},
|
|
97
|
+
}));
|
|
98
|
+
|
|
99
|
+
// ---------------------------------------------------------------------------
|
|
100
|
+
// Helpers
|
|
101
|
+
// ---------------------------------------------------------------------------
|
|
102
|
+
|
|
103
|
+
let importCounter = 0;
|
|
104
|
+
|
|
105
|
+
/** Import a fresh copy of explore.ts with all module state reset. */
|
|
106
|
+
async function freshExploreModule() {
|
|
107
|
+
importCounter++;
|
|
108
|
+
return await import(`@atlas/api/lib/tools/explore?plugin_test=${importCounter}`);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function makeMockBackend(tag: string): ExploreBackend {
|
|
112
|
+
return {
|
|
113
|
+
exec: async (command: string): Promise<ExecResult> => ({
|
|
114
|
+
stdout: `[${tag}] ${command}`,
|
|
115
|
+
stderr: "",
|
|
116
|
+
exitCode: 0,
|
|
117
|
+
}),
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// ---------------------------------------------------------------------------
|
|
122
|
+
// Tests
|
|
123
|
+
// ---------------------------------------------------------------------------
|
|
124
|
+
|
|
125
|
+
describe("explore sandbox plugin integration", () => {
|
|
126
|
+
const originalEnv = { ...process.env };
|
|
127
|
+
|
|
128
|
+
beforeEach(() => {
|
|
129
|
+
mockSandboxPlugins = [];
|
|
130
|
+
// Ensure built-in backends are not detected
|
|
131
|
+
delete process.env.ATLAS_RUNTIME;
|
|
132
|
+
delete process.env.VERCEL;
|
|
133
|
+
delete process.env.ATLAS_SANDBOX;
|
|
134
|
+
delete process.env.ATLAS_SANDBOX_URL;
|
|
135
|
+
delete process.env.ATLAS_NSJAIL_PATH;
|
|
136
|
+
// Force PATH to not find nsjail
|
|
137
|
+
process.env.PATH = "/usr/bin:/bin";
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
afterEach(() => {
|
|
141
|
+
process.env = { ...originalEnv };
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
it("selects a registered sandbox plugin over built-in backends", async () => {
|
|
145
|
+
const backend = makeMockBackend("plugin-a");
|
|
146
|
+
mockSandboxPlugins = [
|
|
147
|
+
{
|
|
148
|
+
id: "plugin-a",
|
|
149
|
+
type: "sandbox",
|
|
150
|
+
version: "1.0.0",
|
|
151
|
+
sandbox: { create: async () => backend },
|
|
152
|
+
},
|
|
153
|
+
];
|
|
154
|
+
|
|
155
|
+
const mod = await freshExploreModule();
|
|
156
|
+
const result = await mod.explore.execute(
|
|
157
|
+
{ command: "ls" },
|
|
158
|
+
{ toolCallId: "test", messages: [], abortSignal: new AbortController().signal },
|
|
159
|
+
);
|
|
160
|
+
|
|
161
|
+
expect(result).toContain("[plugin-a]");
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
it("higher priority plugin wins when multiple are registered", async () => {
|
|
165
|
+
mockSandboxPlugins = [
|
|
166
|
+
{
|
|
167
|
+
id: "low-priority",
|
|
168
|
+
type: "sandbox",
|
|
169
|
+
version: "1.0.0",
|
|
170
|
+
sandbox: {
|
|
171
|
+
create: async () => makeMockBackend("low"),
|
|
172
|
+
priority: 40,
|
|
173
|
+
},
|
|
174
|
+
},
|
|
175
|
+
{
|
|
176
|
+
id: "high-priority",
|
|
177
|
+
type: "sandbox",
|
|
178
|
+
version: "1.0.0",
|
|
179
|
+
sandbox: {
|
|
180
|
+
create: async () => makeMockBackend("high"),
|
|
181
|
+
priority: 90,
|
|
182
|
+
},
|
|
183
|
+
},
|
|
184
|
+
];
|
|
185
|
+
|
|
186
|
+
const mod = await freshExploreModule();
|
|
187
|
+
const result = await mod.explore.execute(
|
|
188
|
+
{ command: "ls" },
|
|
189
|
+
{ toolCallId: "test", messages: [], abortSignal: new AbortController().signal },
|
|
190
|
+
);
|
|
191
|
+
|
|
192
|
+
expect(result).toContain("[high]");
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
it("falls through to next plugin when first create() throws", async () => {
|
|
196
|
+
mockSandboxPlugins = [
|
|
197
|
+
{
|
|
198
|
+
id: "broken-plugin",
|
|
199
|
+
type: "sandbox",
|
|
200
|
+
version: "1.0.0",
|
|
201
|
+
sandbox: {
|
|
202
|
+
create: async () => { throw new Error("init failed"); },
|
|
203
|
+
priority: 90,
|
|
204
|
+
},
|
|
205
|
+
},
|
|
206
|
+
{
|
|
207
|
+
id: "working-plugin",
|
|
208
|
+
type: "sandbox",
|
|
209
|
+
version: "1.0.0",
|
|
210
|
+
sandbox: {
|
|
211
|
+
create: async () => makeMockBackend("working"),
|
|
212
|
+
priority: 50,
|
|
213
|
+
},
|
|
214
|
+
},
|
|
215
|
+
];
|
|
216
|
+
|
|
217
|
+
const mod = await freshExploreModule();
|
|
218
|
+
const result = await mod.explore.execute(
|
|
219
|
+
{ command: "ls" },
|
|
220
|
+
{ toolCallId: "test", messages: [], abortSignal: new AbortController().signal },
|
|
221
|
+
);
|
|
222
|
+
|
|
223
|
+
expect(result).toContain("[working]");
|
|
224
|
+
expect(mod.getActiveSandboxPluginId()).toBe("working-plugin");
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
it("falls back to built-in backends when all plugins fail", async () => {
|
|
228
|
+
mockSandboxPlugins = [
|
|
229
|
+
{
|
|
230
|
+
id: "broken-1",
|
|
231
|
+
type: "sandbox",
|
|
232
|
+
version: "1.0.0",
|
|
233
|
+
sandbox: {
|
|
234
|
+
create: async () => { throw new Error("fail 1"); },
|
|
235
|
+
},
|
|
236
|
+
},
|
|
237
|
+
{
|
|
238
|
+
id: "broken-2",
|
|
239
|
+
type: "sandbox",
|
|
240
|
+
version: "1.0.0",
|
|
241
|
+
sandbox: {
|
|
242
|
+
create: async () => { throw new Error("fail 2"); },
|
|
243
|
+
},
|
|
244
|
+
},
|
|
245
|
+
];
|
|
246
|
+
|
|
247
|
+
const mod = await freshExploreModule();
|
|
248
|
+
// No plugin succeeds, so it should fall through to just-bash.
|
|
249
|
+
// just-bash may fail in test env too (no semantic/ dir), but the key assertion
|
|
250
|
+
// is that _activeSandboxPluginId is NOT set.
|
|
251
|
+
expect(mod.getActiveSandboxPluginId()).toBeNull();
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
it("sets _activeSandboxPluginId on successful plugin selection", async () => {
|
|
255
|
+
mockSandboxPlugins = [
|
|
256
|
+
{
|
|
257
|
+
id: "my-sandbox",
|
|
258
|
+
type: "sandbox",
|
|
259
|
+
version: "2.0.0",
|
|
260
|
+
sandbox: { create: async () => makeMockBackend("my-sandbox") },
|
|
261
|
+
},
|
|
262
|
+
];
|
|
263
|
+
|
|
264
|
+
const mod = await freshExploreModule();
|
|
265
|
+
await mod.explore.execute(
|
|
266
|
+
{ command: "ls" },
|
|
267
|
+
{ toolCallId: "test", messages: [], abortSignal: new AbortController().signal },
|
|
268
|
+
);
|
|
269
|
+
|
|
270
|
+
expect(mod.getActiveSandboxPluginId()).toBe("my-sandbox");
|
|
271
|
+
});
|
|
272
|
+
|
|
273
|
+
it("getExploreBackendType() returns 'plugin' when _activeSandboxPluginId is set", async () => {
|
|
274
|
+
mockSandboxPlugins = [
|
|
275
|
+
{
|
|
276
|
+
id: "test-plugin",
|
|
277
|
+
type: "sandbox",
|
|
278
|
+
version: "1.0.0",
|
|
279
|
+
sandbox: { create: async () => makeMockBackend("test") },
|
|
280
|
+
},
|
|
281
|
+
];
|
|
282
|
+
|
|
283
|
+
const mod = await freshExploreModule();
|
|
284
|
+
// Before any explore call, plugin is not yet active
|
|
285
|
+
expect(mod.getExploreBackendType()).not.toBe("plugin");
|
|
286
|
+
|
|
287
|
+
// Trigger backend init
|
|
288
|
+
await mod.explore.execute(
|
|
289
|
+
{ command: "ls" },
|
|
290
|
+
{ toolCallId: "test", messages: [], abortSignal: new AbortController().signal },
|
|
291
|
+
);
|
|
292
|
+
|
|
293
|
+
expect(mod.getExploreBackendType()).toBe("plugin");
|
|
294
|
+
});
|
|
295
|
+
|
|
296
|
+
it("invalidateExploreBackend() clears _activeSandboxPluginId", async () => {
|
|
297
|
+
mockSandboxPlugins = [
|
|
298
|
+
{
|
|
299
|
+
id: "clearable-plugin",
|
|
300
|
+
type: "sandbox",
|
|
301
|
+
version: "1.0.0",
|
|
302
|
+
sandbox: { create: async () => makeMockBackend("clearable") },
|
|
303
|
+
},
|
|
304
|
+
];
|
|
305
|
+
|
|
306
|
+
const mod = await freshExploreModule();
|
|
307
|
+
await mod.explore.execute(
|
|
308
|
+
{ command: "ls" },
|
|
309
|
+
{ toolCallId: "test", messages: [], abortSignal: new AbortController().signal },
|
|
310
|
+
);
|
|
311
|
+
|
|
312
|
+
expect(mod.getActiveSandboxPluginId()).toBe("clearable-plugin");
|
|
313
|
+
|
|
314
|
+
mod.invalidateExploreBackend();
|
|
315
|
+
expect(mod.getActiveSandboxPluginId()).toBeNull();
|
|
316
|
+
});
|
|
317
|
+
|
|
318
|
+
it("skips plugins when ATLAS_SANDBOX=nsjail is set", async () => {
|
|
319
|
+
process.env.ATLAS_SANDBOX = "nsjail";
|
|
320
|
+
|
|
321
|
+
mockSandboxPlugins = [
|
|
322
|
+
{
|
|
323
|
+
id: "should-be-skipped",
|
|
324
|
+
type: "sandbox",
|
|
325
|
+
version: "1.0.0",
|
|
326
|
+
sandbox: { create: async () => makeMockBackend("skipped") },
|
|
327
|
+
},
|
|
328
|
+
];
|
|
329
|
+
|
|
330
|
+
const mod = await freshExploreModule();
|
|
331
|
+
// Trigger backend init — it should skip plugins and go straight to nsjail
|
|
332
|
+
// nsjail will fail (not installed in test), but the key assertion is
|
|
333
|
+
// that the plugin was NOT used
|
|
334
|
+
await mod.explore.execute(
|
|
335
|
+
{ command: "ls" },
|
|
336
|
+
{ toolCallId: "test", messages: [], abortSignal: new AbortController().signal },
|
|
337
|
+
);
|
|
338
|
+
|
|
339
|
+
expect(mod.getActiveSandboxPluginId()).toBeNull();
|
|
340
|
+
});
|
|
341
|
+
|
|
342
|
+
it("uses default priority (60) when plugin omits priority", async () => {
|
|
343
|
+
mockSandboxPlugins = [
|
|
344
|
+
{
|
|
345
|
+
id: "explicit-low",
|
|
346
|
+
type: "sandbox",
|
|
347
|
+
version: "1.0.0",
|
|
348
|
+
sandbox: {
|
|
349
|
+
create: async () => makeMockBackend("explicit-low"),
|
|
350
|
+
priority: 50,
|
|
351
|
+
},
|
|
352
|
+
},
|
|
353
|
+
{
|
|
354
|
+
id: "default-priority",
|
|
355
|
+
type: "sandbox",
|
|
356
|
+
version: "1.0.0",
|
|
357
|
+
sandbox: {
|
|
358
|
+
// No priority — defaults to 60 (SANDBOX_DEFAULT_PRIORITY)
|
|
359
|
+
create: async () => makeMockBackend("default"),
|
|
360
|
+
},
|
|
361
|
+
},
|
|
362
|
+
];
|
|
363
|
+
|
|
364
|
+
const mod = await freshExploreModule();
|
|
365
|
+
const result = await mod.explore.execute(
|
|
366
|
+
{ command: "ls" },
|
|
367
|
+
{ toolCallId: "test", messages: [], abortSignal: new AbortController().signal },
|
|
368
|
+
);
|
|
369
|
+
|
|
370
|
+
// Default priority (60) > explicit (50), so default-priority plugin wins
|
|
371
|
+
expect(result).toContain("[default]");
|
|
372
|
+
expect(mod.getActiveSandboxPluginId()).toBe("default-priority");
|
|
373
|
+
});
|
|
374
|
+
});
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Compile-time drift guard: Plugin SDK <-> API explore types.
|
|
3
|
+
*
|
|
4
|
+
* Verifies that PluginExecResult is structurally identical to ExecResult and
|
|
5
|
+
* PluginExploreBackend is structurally identical to ExploreBackend. If either
|
|
6
|
+
* side adds a new required field without updating the other, the type-level
|
|
7
|
+
* assertions will fail at compile time.
|
|
8
|
+
*
|
|
9
|
+
* Both types are defined in this file to avoid a cross-package import
|
|
10
|
+
* (@atlas/api does not depend on @atlas/plugin-sdk by design).
|
|
11
|
+
*/
|
|
12
|
+
import { describe, test, expect } from "bun:test";
|
|
13
|
+
import type { ExecResult, ExploreBackend } from "../explore";
|
|
14
|
+
|
|
15
|
+
// Structural mirrors of the plugin SDK types — kept in sync manually.
|
|
16
|
+
// If the SDK types change, update these mirrors AND the type assertions below.
|
|
17
|
+
interface SDKExecResult {
|
|
18
|
+
stdout: string;
|
|
19
|
+
stderr: string;
|
|
20
|
+
exitCode: number;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
interface SDKExploreBackend {
|
|
24
|
+
exec(command: string): Promise<SDKExecResult>;
|
|
25
|
+
close?(): Promise<void>;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
describe("explore SDK compatibility — structural drift guard", () => {
|
|
29
|
+
test("ExecResult and SDK mirror have identical shape", () => {
|
|
30
|
+
// Forward: SDK -> API
|
|
31
|
+
const sdk: SDKExecResult = { stdout: "out", stderr: "", exitCode: 0 };
|
|
32
|
+
const _api: ExecResult = sdk;
|
|
33
|
+
expect(_api.stdout).toBe("out");
|
|
34
|
+
|
|
35
|
+
// Backward: API -> SDK
|
|
36
|
+
const api: ExecResult = { stdout: "data", stderr: "warn", exitCode: 1 };
|
|
37
|
+
const _sdk: SDKExecResult = api;
|
|
38
|
+
expect(_sdk.exitCode).toBe(1);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
test("ExploreBackend and SDK mirror have identical shape", () => {
|
|
42
|
+
// Forward: SDK -> API
|
|
43
|
+
const sdk: SDKExploreBackend = {
|
|
44
|
+
exec: async () => ({ stdout: "", stderr: "", exitCode: 0 }),
|
|
45
|
+
};
|
|
46
|
+
const _api: ExploreBackend = sdk;
|
|
47
|
+
expect(typeof _api.exec).toBe("function");
|
|
48
|
+
|
|
49
|
+
// Backward: API -> SDK
|
|
50
|
+
const api: ExploreBackend = {
|
|
51
|
+
exec: async () => ({ stdout: "", stderr: "", exitCode: 0 }),
|
|
52
|
+
close: async () => {},
|
|
53
|
+
};
|
|
54
|
+
const _sdk: SDKExploreBackend = api;
|
|
55
|
+
expect(typeof _sdk.close).toBe("function");
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
// Type-level assertions — fail at compile time if shapes diverge
|
|
59
|
+
test("type-level: SDKExecResult extends ExecResult", () => {
|
|
60
|
+
type Check = SDKExecResult extends ExecResult ? true : false;
|
|
61
|
+
const _: Check = true;
|
|
62
|
+
expect(_).toBe(true);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
test("type-level: ExecResult extends SDKExecResult", () => {
|
|
66
|
+
type Check = ExecResult extends SDKExecResult ? true : false;
|
|
67
|
+
const _: Check = true;
|
|
68
|
+
expect(_).toBe(true);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
test("type-level: SDKExploreBackend extends ExploreBackend", () => {
|
|
72
|
+
type Check = SDKExploreBackend extends ExploreBackend ? true : false;
|
|
73
|
+
const _: Check = true;
|
|
74
|
+
expect(_).toBe(true);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
test("type-level: ExploreBackend extends SDKExploreBackend", () => {
|
|
78
|
+
type Check = ExploreBackend extends SDKExploreBackend ? true : false;
|
|
79
|
+
const _: Check = true;
|
|
80
|
+
expect(_).toBe(true);
|
|
81
|
+
});
|
|
82
|
+
});
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
import { describe, expect, it, afterEach, spyOn } from "bun:test";
|
|
2
|
+
|
|
3
|
+
// ---------------------------------------------------------------------------
|
|
4
|
+
// Mock fetch — intercept HTTP calls to the sidecar
|
|
5
|
+
// ---------------------------------------------------------------------------
|
|
6
|
+
|
|
7
|
+
let fetchCalls: { url: string; options: RequestInit }[] = [];
|
|
8
|
+
|
|
9
|
+
const originalFetch = globalThis.fetch;
|
|
10
|
+
|
|
11
|
+
function mockFetch(
|
|
12
|
+
handler: (url: string, options: RequestInit) => Response | Promise<Response>,
|
|
13
|
+
) {
|
|
14
|
+
fetchCalls = [];
|
|
15
|
+
globalThis.fetch = (async (input: string | URL | Request, init?: RequestInit) => {
|
|
16
|
+
const url = typeof input === "string" ? input : input.toString();
|
|
17
|
+
const options = init ?? {};
|
|
18
|
+
fetchCalls.push({ url, options });
|
|
19
|
+
return handler(url, options);
|
|
20
|
+
}) as typeof fetch;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function restoreFetch() {
|
|
24
|
+
globalThis.fetch = originalFetch;
|
|
25
|
+
fetchCalls = [];
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// ---------------------------------------------------------------------------
|
|
29
|
+
// Import after mocks
|
|
30
|
+
// ---------------------------------------------------------------------------
|
|
31
|
+
|
|
32
|
+
import { createSidecarBackend } from "@atlas/api/lib/tools/explore-sidecar";
|
|
33
|
+
|
|
34
|
+
// ---------------------------------------------------------------------------
|
|
35
|
+
// Tests
|
|
36
|
+
// ---------------------------------------------------------------------------
|
|
37
|
+
|
|
38
|
+
describe("createSidecarBackend", () => {
|
|
39
|
+
afterEach(() => {
|
|
40
|
+
restoreFetch();
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it("rejects invalid URLs", async () => {
|
|
44
|
+
await expect(createSidecarBackend("not-a-url")).rejects.toThrow(
|
|
45
|
+
"Invalid ATLAS_SANDBOX_URL",
|
|
46
|
+
);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it("creates a backend with valid URL", async () => {
|
|
50
|
+
const backend = await createSidecarBackend("http://localhost:8080");
|
|
51
|
+
expect(backend).toBeDefined();
|
|
52
|
+
expect(typeof backend.exec).toBe("function");
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
describe("sidecar exec", () => {
|
|
57
|
+
afterEach(() => {
|
|
58
|
+
restoreFetch();
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it("sends POST to /exec with command and timeout", async () => {
|
|
62
|
+
mockFetch(() =>
|
|
63
|
+
Response.json({ stdout: "file1.yml\n", stderr: "", exitCode: 0 }),
|
|
64
|
+
);
|
|
65
|
+
|
|
66
|
+
const backend = await createSidecarBackend("http://localhost:8080");
|
|
67
|
+
const result = await backend.exec("ls");
|
|
68
|
+
|
|
69
|
+
expect(result.stdout).toBe("file1.yml\n");
|
|
70
|
+
expect(result.stderr).toBe("");
|
|
71
|
+
expect(result.exitCode).toBe(0);
|
|
72
|
+
|
|
73
|
+
expect(fetchCalls).toHaveLength(1);
|
|
74
|
+
expect(fetchCalls[0].url).toBe("http://localhost:8080/exec");
|
|
75
|
+
|
|
76
|
+
const body = JSON.parse(fetchCalls[0].options.body as string);
|
|
77
|
+
expect(body.command).toBe("ls");
|
|
78
|
+
expect(body.timeout).toBe(10_000);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it("returns stderr and non-zero exit code", async () => {
|
|
82
|
+
mockFetch(() =>
|
|
83
|
+
Response.json({
|
|
84
|
+
stdout: "",
|
|
85
|
+
stderr: "ls: cannot access '/foo': No such file\n",
|
|
86
|
+
exitCode: 1,
|
|
87
|
+
}),
|
|
88
|
+
);
|
|
89
|
+
|
|
90
|
+
const backend = await createSidecarBackend("http://localhost:8080");
|
|
91
|
+
const result = await backend.exec("ls /foo");
|
|
92
|
+
|
|
93
|
+
expect(result.exitCode).toBe(1);
|
|
94
|
+
expect(result.stderr).toContain("No such file");
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
it("returns timeout error on AbortError", async () => {
|
|
98
|
+
mockFetch(() => {
|
|
99
|
+
throw new DOMException("The operation was aborted", "AbortError");
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
// Suppress log output during test
|
|
103
|
+
const warnSpy = spyOn(console, "warn").mockImplementation(() => {});
|
|
104
|
+
|
|
105
|
+
const backend = await createSidecarBackend("http://localhost:8080");
|
|
106
|
+
const result = await backend.exec("sleep 999");
|
|
107
|
+
|
|
108
|
+
expect(result.exitCode).toBe(124);
|
|
109
|
+
expect(result.stderr).toContain("timed out");
|
|
110
|
+
|
|
111
|
+
warnSpy.mockRestore();
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
it("throws on connection refused and invalidates backend", async () => {
|
|
115
|
+
let invalidated = false;
|
|
116
|
+
|
|
117
|
+
// Mock the dynamic import of explore module
|
|
118
|
+
const exploreModule = await import("@atlas/api/lib/tools/explore");
|
|
119
|
+
const invalidateSpy = spyOn(
|
|
120
|
+
exploreModule,
|
|
121
|
+
"invalidateExploreBackend",
|
|
122
|
+
).mockImplementation(() => {
|
|
123
|
+
invalidated = true;
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
mockFetch(() => {
|
|
127
|
+
throw new TypeError("fetch failed: ECONNREFUSED");
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
const errorSpy = spyOn(console, "error").mockImplementation(() => {});
|
|
131
|
+
|
|
132
|
+
const backend = await createSidecarBackend("http://localhost:8080");
|
|
133
|
+
await expect(backend.exec("ls")).rejects.toThrow("Sidecar unreachable");
|
|
134
|
+
|
|
135
|
+
expect(invalidated).toBe(true);
|
|
136
|
+
|
|
137
|
+
errorSpy.mockRestore();
|
|
138
|
+
invalidateSpy.mockRestore();
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
it("handles HTTP 400 errors gracefully", async () => {
|
|
142
|
+
mockFetch(
|
|
143
|
+
() => new Response("Bad Request", { status: 400 }),
|
|
144
|
+
);
|
|
145
|
+
|
|
146
|
+
const errorSpy = spyOn(console, "error").mockImplementation(() => {});
|
|
147
|
+
|
|
148
|
+
const backend = await createSidecarBackend("http://localhost:8080");
|
|
149
|
+
const result = await backend.exec("ls");
|
|
150
|
+
|
|
151
|
+
expect(result.exitCode).toBe(1);
|
|
152
|
+
expect(result.stderr).toContain("HTTP 400");
|
|
153
|
+
|
|
154
|
+
errorSpy.mockRestore();
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
it("handles HTTP 500 with exec response shape", async () => {
|
|
158
|
+
mockFetch(
|
|
159
|
+
() =>
|
|
160
|
+
new Response(
|
|
161
|
+
JSON.stringify({
|
|
162
|
+
error: "Execution failed",
|
|
163
|
+
stdout: "",
|
|
164
|
+
stderr: "command not found",
|
|
165
|
+
exitCode: 127,
|
|
166
|
+
}),
|
|
167
|
+
{ status: 500, headers: { "Content-Type": "application/json" } },
|
|
168
|
+
),
|
|
169
|
+
);
|
|
170
|
+
|
|
171
|
+
const errorSpy = spyOn(console, "error").mockImplementation(() => {});
|
|
172
|
+
|
|
173
|
+
const backend = await createSidecarBackend("http://localhost:8080");
|
|
174
|
+
const result = await backend.exec("nonexistent-cmd");
|
|
175
|
+
|
|
176
|
+
expect(result.exitCode).toBe(127);
|
|
177
|
+
expect(result.stderr).toContain("command not found");
|
|
178
|
+
|
|
179
|
+
errorSpy.mockRestore();
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
it("handles malformed JSON response", async () => {
|
|
183
|
+
mockFetch(
|
|
184
|
+
() => new Response("not json", { status: 200 }),
|
|
185
|
+
);
|
|
186
|
+
|
|
187
|
+
const errorSpy = spyOn(console, "error").mockImplementation(() => {});
|
|
188
|
+
|
|
189
|
+
const backend = await createSidecarBackend("http://localhost:8080");
|
|
190
|
+
const result = await backend.exec("ls");
|
|
191
|
+
|
|
192
|
+
expect(result.exitCode).toBe(1);
|
|
193
|
+
expect(result.stderr).toContain("Failed to parse sidecar response");
|
|
194
|
+
|
|
195
|
+
errorSpy.mockRestore();
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
it("handles missing fields in response with defaults", async () => {
|
|
199
|
+
mockFetch(() => Response.json({ exitCode: 0 }));
|
|
200
|
+
|
|
201
|
+
const backend = await createSidecarBackend("http://localhost:8080");
|
|
202
|
+
const result = await backend.exec("ls");
|
|
203
|
+
|
|
204
|
+
expect(result.stdout).toBe("");
|
|
205
|
+
expect(result.stderr).toBe("");
|
|
206
|
+
expect(result.exitCode).toBe(0);
|
|
207
|
+
});
|
|
208
|
+
});
|