slackhive 0.1.37 → 0.1.39
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/.dockerignore +14 -0
- package/.env.example +44 -0
- package/.github/ISSUE_TEMPLATE/bug_report.yml +65 -0
- package/.github/ISSUE_TEMPLATE/config.yml +5 -0
- package/.github/ISSUE_TEMPLATE/feature_request.yml +38 -0
- package/.github/PULL_REQUEST_TEMPLATE.md +27 -0
- package/.github/dependabot.yml +20 -0
- package/.github/workflows/audit.yml +149 -0
- package/.github/workflows/ci.yml +135 -0
- package/CHANGELOG.md +52 -0
- package/CODE_OF_CONDUCT.md +37 -0
- package/CONTRIBUTING.md +204 -0
- package/LICENSE +21 -0
- package/README.md +19 -0
- package/SECURITY.md +47 -0
- package/apps/runner/Dockerfile +33 -0
- package/apps/runner/dist/__tests__/channel-restrictions.test.d.ts +8 -0
- package/apps/runner/dist/__tests__/channel-restrictions.test.js +63 -0
- package/apps/runner/dist/__tests__/channel-restrictions.test.js.map +1 -0
- package/apps/runner/dist/__tests__/claude-handler-resolve.test.d.ts +20 -0
- package/apps/runner/dist/__tests__/claude-handler-resolve.test.js +178 -0
- package/apps/runner/dist/__tests__/claude-handler-resolve.test.js.map +1 -0
- package/apps/runner/dist/__tests__/compile-claude-md.test.d.ts +13 -0
- package/apps/runner/dist/__tests__/compile-claude-md.test.js +144 -0
- package/apps/runner/dist/__tests__/compile-claude-md.test.js.map +1 -0
- package/apps/runner/dist/__tests__/memory-sync.test.d.ts +11 -0
- package/apps/runner/dist/__tests__/memory-sync.test.js +56 -0
- package/apps/runner/dist/__tests__/memory-sync.test.js.map +1 -0
- package/apps/runner/dist/__tests__/slack-file-support.test.d.ts +9 -0
- package/apps/runner/dist/__tests__/slack-file-support.test.js +271 -0
- package/apps/runner/dist/__tests__/slack-file-support.test.js.map +1 -0
- package/apps/runner/dist/__tests__/slack-formatting.test.d.ts +12 -0
- package/apps/runner/dist/__tests__/slack-formatting.test.js +400 -0
- package/apps/runner/dist/__tests__/slack-formatting.test.js.map +1 -0
- package/apps/runner/dist/__tests__/thread-context.test.d.ts +12 -0
- package/apps/runner/dist/__tests__/thread-context.test.js +182 -0
- package/apps/runner/dist/__tests__/thread-context.test.js.map +1 -0
- package/apps/runner/dist/agent-runner.d.ts +118 -0
- package/apps/runner/dist/agent-runner.js +352 -0
- package/apps/runner/dist/agent-runner.js.map +1 -0
- package/apps/runner/dist/claude-handler.d.ts +122 -0
- package/apps/runner/dist/claude-handler.js +402 -0
- package/apps/runner/dist/claude-handler.js.map +1 -0
- package/apps/runner/dist/compile-claude-md.d.ts +59 -0
- package/apps/runner/dist/compile-claude-md.js +291 -0
- package/apps/runner/dist/compile-claude-md.js.map +1 -0
- package/apps/runner/dist/correction-handler.d.ts +46 -0
- package/apps/runner/dist/correction-handler.js +162 -0
- package/apps/runner/dist/correction-handler.js.map +1 -0
- package/apps/runner/dist/correction-manager.d.ts +53 -0
- package/apps/runner/dist/correction-manager.js +241 -0
- package/apps/runner/dist/correction-manager.js.map +1 -0
- package/apps/runner/dist/db.d.ts +193 -0
- package/apps/runner/dist/db.js +492 -0
- package/apps/runner/dist/db.js.map +1 -0
- package/apps/runner/dist/index.d.ts +9 -0
- package/apps/runner/dist/index.js +43 -0
- package/apps/runner/dist/index.js.map +1 -0
- package/apps/runner/dist/job-scheduler.d.ts +57 -0
- package/apps/runner/dist/job-scheduler.js +150 -0
- package/apps/runner/dist/job-scheduler.js.map +1 -0
- package/apps/runner/dist/logger.d.ts +32 -0
- package/apps/runner/dist/logger.js +52 -0
- package/apps/runner/dist/logger.js.map +1 -0
- package/apps/runner/dist/mcp-process-manager.d.ts +38 -0
- package/apps/runner/dist/mcp-process-manager.js +189 -0
- package/apps/runner/dist/mcp-process-manager.js.map +1 -0
- package/apps/runner/dist/memory-mcp.d.ts +14 -0
- package/apps/runner/dist/memory-mcp.js +88 -0
- package/apps/runner/dist/memory-mcp.js.map +1 -0
- package/apps/runner/dist/memory-watcher.d.ts +78 -0
- package/apps/runner/dist/memory-watcher.js +220 -0
- package/apps/runner/dist/memory-watcher.js.map +1 -0
- package/apps/runner/dist/slack-handler.d.ts +120 -0
- package/apps/runner/dist/slack-handler.js +843 -0
- package/apps/runner/dist/slack-handler.js.map +1 -0
- package/apps/runner/node_modules/.vite/vitest/da39a3ee5e6b4b0d3255bfef95601890afd80709/results.json +1 -0
- package/apps/runner/package.json +42 -0
- package/apps/runner/src/__tests__/channel-restrictions.test.ts +75 -0
- package/apps/runner/src/__tests__/claude-handler-resolve.test.ts +160 -0
- package/apps/runner/src/__tests__/compile-claude-md.test.ts +139 -0
- package/apps/runner/src/__tests__/memory-sync.test.ts +59 -0
- package/apps/runner/src/__tests__/slack-file-support.test.ts +376 -0
- package/apps/runner/src/__tests__/slack-formatting.test.ts +495 -0
- package/apps/runner/src/__tests__/thread-context.test.ts +215 -0
- package/apps/runner/src/agent-runner.ts +397 -0
- package/apps/runner/src/claude-handler.ts +475 -0
- package/apps/runner/src/compile-claude-md.ts +283 -0
- package/apps/runner/src/correction-handler.ts +191 -0
- package/apps/runner/src/correction-manager.ts +285 -0
- package/apps/runner/src/db.ts +604 -0
- package/apps/runner/src/index.ts +46 -0
- package/apps/runner/src/job-scheduler.ts +165 -0
- package/apps/runner/src/logger.ts +49 -0
- package/apps/runner/src/mcp-process-manager.ts +195 -0
- package/apps/runner/src/memory-mcp.ts +85 -0
- package/apps/runner/src/memory-watcher.ts +215 -0
- package/apps/runner/src/slack-handler.ts +929 -0
- package/apps/runner/tsconfig.json +17 -0
- package/apps/runner/vitest.config.mts +17 -0
- package/apps/web/.eslintrc.json +3 -0
- package/apps/web/.next/app-build-manifest.json +323 -0
- package/apps/web/.next/app-path-routes-manifest.json +46 -0
- package/apps/web/.next/build-manifest.json +33 -0
- package/apps/web/.next/cache/.previewinfo +1 -0
- package/apps/web/.next/cache/.rscinfo +1 -0
- package/apps/web/.next/cache/webpack/client-production/0.pack +0 -0
- package/apps/web/.next/cache/webpack/client-production/1.pack +0 -0
- package/apps/web/.next/cache/webpack/client-production/2.pack +0 -0
- package/apps/web/.next/cache/webpack/client-production/3.pack +0 -0
- package/apps/web/.next/cache/webpack/client-production/4.pack +0 -0
- package/apps/web/.next/cache/webpack/client-production/index.pack +0 -0
- package/apps/web/.next/cache/webpack/client-production/index.pack.old +0 -0
- package/apps/web/.next/cache/webpack/edge-server-production/0.pack +0 -0
- package/apps/web/.next/cache/webpack/edge-server-production/1.pack +0 -0
- package/apps/web/.next/cache/webpack/edge-server-production/index.pack +0 -0
- package/apps/web/.next/cache/webpack/edge-server-production/index.pack.old +0 -0
- package/apps/web/.next/cache/webpack/server-production/0.pack +0 -0
- package/apps/web/.next/cache/webpack/server-production/1.pack +0 -0
- package/apps/web/.next/cache/webpack/server-production/2.pack +0 -0
- package/apps/web/.next/cache/webpack/server-production/index.pack +0 -0
- package/apps/web/.next/cache/webpack/server-production/index.pack.old +0 -0
- package/apps/web/.next/diagnostics/build-diagnostics.json +6 -0
- package/apps/web/.next/diagnostics/framework.json +1 -0
- package/apps/web/.next/package.json +1 -0
- package/apps/web/.next/react-loadable-manifest.json +1 -0
- package/apps/web/.next/server/app/_not-found/page.js +2 -0
- package/apps/web/.next/server/app/_not-found/page.js.nft.json +1 -0
- package/apps/web/.next/server/app/_not-found/page_client-reference-manifest.js +1 -0
- package/apps/web/.next/server/app/agents/[slug]/page.js +4 -0
- package/apps/web/.next/server/app/agents/[slug]/page.js.nft.json +1 -0
- package/apps/web/.next/server/app/agents/[slug]/page_client-reference-manifest.js +1 -0
- package/apps/web/.next/server/app/agents/new/page.js +2 -0
- package/apps/web/.next/server/app/agents/new/page.js.nft.json +1 -0
- package/apps/web/.next/server/app/agents/new/page_client-reference-manifest.js +1 -0
- package/apps/web/.next/server/app/api/agents/[id]/access/route.js +1 -0
- package/apps/web/.next/server/app/api/agents/[id]/access/route.js.nft.json +1 -0
- package/apps/web/.next/server/app/api/agents/[id]/access/route_client-reference-manifest.js +1 -0
- package/apps/web/.next/server/app/api/agents/[id]/claude-md/route.js +6 -0
- package/apps/web/.next/server/app/api/agents/[id]/claude-md/route.js.nft.json +1 -0
- package/apps/web/.next/server/app/api/agents/[id]/claude-md/route_client-reference-manifest.js +1 -0
- package/apps/web/.next/server/app/api/agents/[id]/logs/route.js +3 -0
- package/apps/web/.next/server/app/api/agents/[id]/logs/route.js.nft.json +1 -0
- package/apps/web/.next/server/app/api/agents/[id]/logs/route_client-reference-manifest.js +1 -0
- package/apps/web/.next/server/app/api/agents/[id]/manifest/route.js +1 -0
- package/apps/web/.next/server/app/api/agents/[id]/manifest/route.js.nft.json +1 -0
- package/apps/web/.next/server/app/api/agents/[id]/manifest/route_client-reference-manifest.js +1 -0
- package/apps/web/.next/server/app/api/agents/[id]/mcps/route.js +1 -0
- package/apps/web/.next/server/app/api/agents/[id]/mcps/route.js.nft.json +1 -0
- package/apps/web/.next/server/app/api/agents/[id]/mcps/route_client-reference-manifest.js +1 -0
- package/apps/web/.next/server/app/api/agents/[id]/memories/[memId]/route.js +1 -0
- package/apps/web/.next/server/app/api/agents/[id]/memories/[memId]/route.js.nft.json +1 -0
- package/apps/web/.next/server/app/api/agents/[id]/memories/[memId]/route_client-reference-manifest.js +1 -0
- package/apps/web/.next/server/app/api/agents/[id]/memories/route.js +1 -0
- package/apps/web/.next/server/app/api/agents/[id]/memories/route.js.nft.json +1 -0
- package/apps/web/.next/server/app/api/agents/[id]/memories/route_client-reference-manifest.js +1 -0
- package/apps/web/.next/server/app/api/agents/[id]/permissions/route.js +1 -0
- package/apps/web/.next/server/app/api/agents/[id]/permissions/route.js.nft.json +1 -0
- package/apps/web/.next/server/app/api/agents/[id]/permissions/route_client-reference-manifest.js +1 -0
- package/apps/web/.next/server/app/api/agents/[id]/reload/route.js +1 -0
- package/apps/web/.next/server/app/api/agents/[id]/reload/route.js.nft.json +1 -0
- package/apps/web/.next/server/app/api/agents/[id]/reload/route_client-reference-manifest.js +1 -0
- package/apps/web/.next/server/app/api/agents/[id]/restrictions/route.js +1 -0
- package/apps/web/.next/server/app/api/agents/[id]/restrictions/route.js.nft.json +1 -0
- package/apps/web/.next/server/app/api/agents/[id]/restrictions/route_client-reference-manifest.js +1 -0
- package/apps/web/.next/server/app/api/agents/[id]/route.js +33 -0
- package/apps/web/.next/server/app/api/agents/[id]/route.js.nft.json +1 -0
- package/apps/web/.next/server/app/api/agents/[id]/route_client-reference-manifest.js +1 -0
- package/apps/web/.next/server/app/api/agents/[id]/skills/[skillId]/route.js +1 -0
- package/apps/web/.next/server/app/api/agents/[id]/skills/[skillId]/route.js.nft.json +1 -0
- package/apps/web/.next/server/app/api/agents/[id]/skills/[skillId]/route_client-reference-manifest.js +1 -0
- package/apps/web/.next/server/app/api/agents/[id]/skills/route.js +1 -0
- package/apps/web/.next/server/app/api/agents/[id]/skills/route.js.nft.json +1 -0
- package/apps/web/.next/server/app/api/agents/[id]/skills/route_client-reference-manifest.js +1 -0
- package/apps/web/.next/server/app/api/agents/[id]/slack-info/route.js +1 -0
- package/apps/web/.next/server/app/api/agents/[id]/slack-info/route.js.nft.json +1 -0
- package/apps/web/.next/server/app/api/agents/[id]/slack-info/route_client-reference-manifest.js +1 -0
- package/apps/web/.next/server/app/api/agents/[id]/snapshots/[sid]/restore/route.js +1 -0
- package/apps/web/.next/server/app/api/agents/[id]/snapshots/[sid]/restore/route.js.nft.json +1 -0
- package/apps/web/.next/server/app/api/agents/[id]/snapshots/[sid]/restore/route_client-reference-manifest.js +1 -0
- package/apps/web/.next/server/app/api/agents/[id]/snapshots/[sid]/route.js +1 -0
- package/apps/web/.next/server/app/api/agents/[id]/snapshots/[sid]/route.js.nft.json +1 -0
- package/apps/web/.next/server/app/api/agents/[id]/snapshots/[sid]/route_client-reference-manifest.js +1 -0
- package/apps/web/.next/server/app/api/agents/[id]/snapshots/route.js +1 -0
- package/apps/web/.next/server/app/api/agents/[id]/snapshots/route.js.nft.json +1 -0
- package/apps/web/.next/server/app/api/agents/[id]/snapshots/route_client-reference-manifest.js +1 -0
- package/apps/web/.next/server/app/api/agents/[id]/start/route.js +1 -0
- package/apps/web/.next/server/app/api/agents/[id]/start/route.js.nft.json +1 -0
- package/apps/web/.next/server/app/api/agents/[id]/start/route_client-reference-manifest.js +1 -0
- package/apps/web/.next/server/app/api/agents/[id]/stop/route.js +1 -0
- package/apps/web/.next/server/app/api/agents/[id]/stop/route.js.nft.json +1 -0
- package/apps/web/.next/server/app/api/agents/[id]/stop/route_client-reference-manifest.js +1 -0
- package/apps/web/.next/server/app/api/agents/route.js +91 -0
- package/apps/web/.next/server/app/api/agents/route.js.nft.json +1 -0
- package/apps/web/.next/server/app/api/agents/route_client-reference-manifest.js +1 -0
- package/apps/web/.next/server/app/api/auth/login/route.js +1 -0
- package/apps/web/.next/server/app/api/auth/login/route.js.nft.json +1 -0
- package/apps/web/.next/server/app/api/auth/login/route_client-reference-manifest.js +1 -0
- package/apps/web/.next/server/app/api/auth/logout/route.js +1 -0
- package/apps/web/.next/server/app/api/auth/logout/route.js.nft.json +1 -0
- package/apps/web/.next/server/app/api/auth/logout/route_client-reference-manifest.js +1 -0
- package/apps/web/.next/server/app/api/auth/me/route.js +1 -0
- package/apps/web/.next/server/app/api/auth/me/route.js.nft.json +1 -0
- package/apps/web/.next/server/app/api/auth/me/route_client-reference-manifest.js +1 -0
- package/apps/web/.next/server/app/api/auth/users/[id]/route.js +1 -0
- package/apps/web/.next/server/app/api/auth/users/[id]/route.js.nft.json +1 -0
- package/apps/web/.next/server/app/api/auth/users/[id]/route_client-reference-manifest.js +1 -0
- package/apps/web/.next/server/app/api/auth/users/route.js +1 -0
- package/apps/web/.next/server/app/api/auth/users/route.js.nft.json +1 -0
- package/apps/web/.next/server/app/api/auth/users/route_client-reference-manifest.js +1 -0
- package/apps/web/.next/server/app/api/env-vars/[key]/route.js +1 -0
- package/apps/web/.next/server/app/api/env-vars/[key]/route.js.nft.json +1 -0
- package/apps/web/.next/server/app/api/env-vars/[key]/route_client-reference-manifest.js +1 -0
- package/apps/web/.next/server/app/api/env-vars/route.js +1 -0
- package/apps/web/.next/server/app/api/env-vars/route.js.nft.json +1 -0
- package/apps/web/.next/server/app/api/env-vars/route_client-reference-manifest.js +1 -0
- package/apps/web/.next/server/app/api/jobs/[id]/route.js +1 -0
- package/apps/web/.next/server/app/api/jobs/[id]/route.js.nft.json +1 -0
- package/apps/web/.next/server/app/api/jobs/[id]/route_client-reference-manifest.js +1 -0
- package/apps/web/.next/server/app/api/jobs/[id]/runs/route.js +1 -0
- package/apps/web/.next/server/app/api/jobs/[id]/runs/route.js.nft.json +1 -0
- package/apps/web/.next/server/app/api/jobs/[id]/runs/route_client-reference-manifest.js +1 -0
- package/apps/web/.next/server/app/api/jobs/route.js +1 -0
- package/apps/web/.next/server/app/api/jobs/route.js.nft.json +1 -0
- package/apps/web/.next/server/app/api/jobs/route_client-reference-manifest.js +1 -0
- package/apps/web/.next/server/app/api/mcps/[id]/route.js +1 -0
- package/apps/web/.next/server/app/api/mcps/[id]/route.js.nft.json +1 -0
- package/apps/web/.next/server/app/api/mcps/[id]/route_client-reference-manifest.js +1 -0
- package/apps/web/.next/server/app/api/mcps/[id]/test/route.js +1 -0
- package/apps/web/.next/server/app/api/mcps/[id]/test/route.js.nft.json +1 -0
- package/apps/web/.next/server/app/api/mcps/[id]/test/route_client-reference-manifest.js +1 -0
- package/apps/web/.next/server/app/api/mcps/route.js +1 -0
- package/apps/web/.next/server/app/api/mcps/route.js.nft.json +1 -0
- package/apps/web/.next/server/app/api/mcps/route_client-reference-manifest.js +1 -0
- package/apps/web/.next/server/app/api/settings/route.js +1 -0
- package/apps/web/.next/server/app/api/settings/route.js.nft.json +1 -0
- package/apps/web/.next/server/app/api/settings/route_client-reference-manifest.js +1 -0
- package/apps/web/.next/server/app/icon.svg/route.js +1 -0
- package/apps/web/.next/server/app/icon.svg/route.js.nft.json +1 -0
- package/apps/web/.next/server/app/jobs/page.js +2 -0
- package/apps/web/.next/server/app/jobs/page.js.nft.json +1 -0
- package/apps/web/.next/server/app/jobs/page_client-reference-manifest.js +1 -0
- package/apps/web/.next/server/app/login/page.js +2 -0
- package/apps/web/.next/server/app/login/page.js.nft.json +1 -0
- package/apps/web/.next/server/app/login/page_client-reference-manifest.js +1 -0
- package/apps/web/.next/server/app/page.js +2 -0
- package/apps/web/.next/server/app/page.js.nft.json +1 -0
- package/apps/web/.next/server/app/page_client-reference-manifest.js +1 -0
- package/apps/web/.next/server/app/settings/env-vars/page.js +2 -0
- package/apps/web/.next/server/app/settings/env-vars/page.js.nft.json +1 -0
- package/apps/web/.next/server/app/settings/env-vars/page_client-reference-manifest.js +1 -0
- package/apps/web/.next/server/app/settings/mcps/page.js +2 -0
- package/apps/web/.next/server/app/settings/mcps/page.js.nft.json +1 -0
- package/apps/web/.next/server/app/settings/mcps/page_client-reference-manifest.js +1 -0
- package/apps/web/.next/server/app/settings/page.js +2 -0
- package/apps/web/.next/server/app/settings/page.js.nft.json +1 -0
- package/apps/web/.next/server/app/settings/page_client-reference-manifest.js +1 -0
- package/apps/web/.next/server/app-paths-manifest.json +46 -0
- package/apps/web/.next/server/chunks/1157.js +9 -0
- package/apps/web/.next/server/chunks/2287.js +1 -0
- package/apps/web/.next/server/chunks/3444.js +1 -0
- package/apps/web/.next/server/chunks/383.js +6 -0
- package/apps/web/.next/server/chunks/4012.js +58 -0
- package/apps/web/.next/server/chunks/6791.js +1 -0
- package/apps/web/.next/server/chunks/7171.js +1 -0
- package/apps/web/.next/server/chunks/8819.js +22 -0
- package/apps/web/.next/server/edge-runtime-webpack.js +2 -0
- package/apps/web/.next/server/edge-runtime-webpack.js.map +1 -0
- package/apps/web/.next/server/interception-route-rewrite-manifest.js +1 -0
- package/apps/web/.next/server/middleware-build-manifest.js +1 -0
- package/apps/web/.next/server/middleware-manifest.json +32 -0
- package/apps/web/.next/server/middleware-react-loadable-manifest.js +1 -0
- package/apps/web/.next/server/next-font-manifest.js +1 -0
- package/apps/web/.next/server/next-font-manifest.json +1 -0
- package/apps/web/.next/server/pages/_app.js +1 -0
- package/apps/web/.next/server/pages/_app.js.nft.json +1 -0
- package/apps/web/.next/server/pages/_document.js +1 -0
- package/apps/web/.next/server/pages/_document.js.nft.json +1 -0
- package/apps/web/.next/server/pages/_error.js +19 -0
- package/apps/web/.next/server/pages/_error.js.nft.json +1 -0
- package/apps/web/.next/server/pages-manifest.json +5 -0
- package/apps/web/.next/server/server-reference-manifest.js +1 -0
- package/apps/web/.next/server/server-reference-manifest.json +1 -0
- package/apps/web/.next/server/src/middleware.js +14 -0
- package/apps/web/.next/server/src/middleware.js.map +1 -0
- package/apps/web/.next/server/webpack-runtime.js +1 -0
- package/apps/web/.next/static/chunks/18-90b700ea37b686a2.js +1 -0
- package/apps/web/.next/static/chunks/87c73c54-24122e7b92478d00.js +1 -0
- package/apps/web/.next/static/chunks/9664-af80478aa73ba424.js +1 -0
- package/apps/web/.next/static/chunks/app/_not-found/page-b9cee17ed89ca24a.js +1 -0
- package/apps/web/.next/static/chunks/app/agents/[slug]/page-18369fc3fe1a9a7b.js +1 -0
- package/apps/web/.next/static/chunks/app/agents/new/page-bf11cf8901c7e2cd.js +1 -0
- package/apps/web/.next/static/chunks/app/api/agents/[id]/access/route-07f0f73ac9839899.js +1 -0
- package/apps/web/.next/static/chunks/app/api/agents/[id]/claude-md/route-07f0f73ac9839899.js +1 -0
- package/apps/web/.next/static/chunks/app/api/agents/[id]/logs/route-07f0f73ac9839899.js +1 -0
- package/apps/web/.next/static/chunks/app/api/agents/[id]/manifest/route-07f0f73ac9839899.js +1 -0
- package/apps/web/.next/static/chunks/app/api/agents/[id]/mcps/route-07f0f73ac9839899.js +1 -0
- package/apps/web/.next/static/chunks/app/api/agents/[id]/memories/[memId]/route-07f0f73ac9839899.js +1 -0
- package/apps/web/.next/static/chunks/app/api/agents/[id]/memories/route-07f0f73ac9839899.js +1 -0
- package/apps/web/.next/static/chunks/app/api/agents/[id]/permissions/route-07f0f73ac9839899.js +1 -0
- package/apps/web/.next/static/chunks/app/api/agents/[id]/reload/route-07f0f73ac9839899.js +1 -0
- package/apps/web/.next/static/chunks/app/api/agents/[id]/restrictions/route-07f0f73ac9839899.js +1 -0
- package/apps/web/.next/static/chunks/app/api/agents/[id]/route-07f0f73ac9839899.js +1 -0
- package/apps/web/.next/static/chunks/app/api/agents/[id]/skills/[skillId]/route-07f0f73ac9839899.js +1 -0
- package/apps/web/.next/static/chunks/app/api/agents/[id]/skills/route-07f0f73ac9839899.js +1 -0
- package/apps/web/.next/static/chunks/app/api/agents/[id]/slack-info/route-07f0f73ac9839899.js +1 -0
- package/apps/web/.next/static/chunks/app/api/agents/[id]/snapshots/[sid]/restore/route-07f0f73ac9839899.js +1 -0
- package/apps/web/.next/static/chunks/app/api/agents/[id]/snapshots/[sid]/route-07f0f73ac9839899.js +1 -0
- package/apps/web/.next/static/chunks/app/api/agents/[id]/snapshots/route-07f0f73ac9839899.js +1 -0
- package/apps/web/.next/static/chunks/app/api/agents/[id]/start/route-07f0f73ac9839899.js +1 -0
- package/apps/web/.next/static/chunks/app/api/agents/[id]/stop/route-07f0f73ac9839899.js +1 -0
- package/apps/web/.next/static/chunks/app/api/agents/route-07f0f73ac9839899.js +1 -0
- package/apps/web/.next/static/chunks/app/api/auth/login/route-07f0f73ac9839899.js +1 -0
- package/apps/web/.next/static/chunks/app/api/auth/logout/route-07f0f73ac9839899.js +1 -0
- package/apps/web/.next/static/chunks/app/api/auth/me/route-07f0f73ac9839899.js +1 -0
- package/apps/web/.next/static/chunks/app/api/auth/users/[id]/route-07f0f73ac9839899.js +1 -0
- package/apps/web/.next/static/chunks/app/api/auth/users/route-07f0f73ac9839899.js +1 -0
- package/apps/web/.next/static/chunks/app/api/env-vars/[key]/route-07f0f73ac9839899.js +1 -0
- package/apps/web/.next/static/chunks/app/api/env-vars/route-07f0f73ac9839899.js +1 -0
- package/apps/web/.next/static/chunks/app/api/jobs/[id]/route-07f0f73ac9839899.js +1 -0
- package/apps/web/.next/static/chunks/app/api/jobs/[id]/runs/route-07f0f73ac9839899.js +1 -0
- package/apps/web/.next/static/chunks/app/api/jobs/route-07f0f73ac9839899.js +1 -0
- package/apps/web/.next/static/chunks/app/api/mcps/[id]/route-07f0f73ac9839899.js +1 -0
- package/apps/web/.next/static/chunks/app/api/mcps/[id]/test/route-07f0f73ac9839899.js +1 -0
- package/apps/web/.next/static/chunks/app/api/mcps/route-07f0f73ac9839899.js +1 -0
- package/apps/web/.next/static/chunks/app/api/settings/route-07f0f73ac9839899.js +1 -0
- package/apps/web/.next/static/chunks/app/jobs/page-f5aa89a47c50efd8.js +1 -0
- package/apps/web/.next/static/chunks/app/layout-2079f4964aa7314e.js +1 -0
- package/apps/web/.next/static/chunks/app/login/layout-07f0f73ac9839899.js +1 -0
- package/apps/web/.next/static/chunks/app/login/page-aa259283dc38e8f9.js +1 -0
- package/apps/web/.next/static/chunks/app/page-e83437b608104dff.js +1 -0
- package/apps/web/.next/static/chunks/app/settings/env-vars/page-06479dbdfb78b76b.js +1 -0
- package/apps/web/.next/static/chunks/app/settings/mcps/page-75650686ed6490c7.js +1 -0
- package/apps/web/.next/static/chunks/app/settings/page-e1e62fc41ff6cddd.js +1 -0
- package/apps/web/.next/static/chunks/framework-811407f832a33072.js +1 -0
- package/apps/web/.next/static/chunks/main-3f1cddbdd67b1546.js +1 -0
- package/apps/web/.next/static/chunks/main-app-cebd8a6a5ccbf72d.js +1 -0
- package/apps/web/.next/static/chunks/pages/_app-50fa07b56b2d29ac.js +1 -0
- package/apps/web/.next/static/chunks/pages/_error-fed8688bdd23f211.js +1 -0
- package/apps/web/.next/static/chunks/polyfills-42372ed130431b0a.js +1 -0
- package/apps/web/.next/static/chunks/webpack-6c05566dba553c97.js +1 -0
- package/apps/web/.next/static/css/15371687405525e2.css +5 -0
- package/apps/web/.next/static/ikfNbLhuw7jntn35bz0lk/_buildManifest.js +1 -0
- package/apps/web/.next/static/ikfNbLhuw7jntn35bz0lk/_ssgManifest.js +1 -0
- package/apps/web/.next/trace +5 -0
- package/apps/web/.next/types/app/agents/[slug]/page.ts +84 -0
- package/apps/web/.next/types/app/agents/new/page.ts +84 -0
- package/apps/web/.next/types/app/api/agents/[id]/access/route.ts +347 -0
- package/apps/web/.next/types/app/api/agents/[id]/claude-md/route.ts +347 -0
- package/apps/web/.next/types/app/api/agents/[id]/logs/route.ts +347 -0
- package/apps/web/.next/types/app/api/agents/[id]/manifest/route.ts +347 -0
- package/apps/web/.next/types/app/api/agents/[id]/mcps/route.ts +347 -0
- package/apps/web/.next/types/app/api/agents/[id]/memories/[memId]/route.ts +347 -0
- package/apps/web/.next/types/app/api/agents/[id]/memories/route.ts +347 -0
- package/apps/web/.next/types/app/api/agents/[id]/permissions/route.ts +347 -0
- package/apps/web/.next/types/app/api/agents/[id]/reload/route.ts +347 -0
- package/apps/web/.next/types/app/api/agents/[id]/restrictions/route.ts +347 -0
- package/apps/web/.next/types/app/api/agents/[id]/route.ts +347 -0
- package/apps/web/.next/types/app/api/agents/[id]/skills/[skillId]/route.ts +347 -0
- package/apps/web/.next/types/app/api/agents/[id]/skills/route.ts +347 -0
- package/apps/web/.next/types/app/api/agents/[id]/slack-info/route.ts +347 -0
- package/apps/web/.next/types/app/api/agents/[id]/snapshots/[sid]/restore/route.ts +347 -0
- package/apps/web/.next/types/app/api/agents/[id]/snapshots/[sid]/route.ts +347 -0
- package/apps/web/.next/types/app/api/agents/[id]/snapshots/route.ts +347 -0
- package/apps/web/.next/types/app/api/agents/[id]/start/route.ts +347 -0
- package/apps/web/.next/types/app/api/agents/[id]/stop/route.ts +347 -0
- package/apps/web/.next/types/app/api/agents/route.ts +347 -0
- package/apps/web/.next/types/app/api/auth/login/route.ts +347 -0
- package/apps/web/.next/types/app/api/auth/logout/route.ts +347 -0
- package/apps/web/.next/types/app/api/auth/me/route.ts +347 -0
- package/apps/web/.next/types/app/api/auth/users/[id]/route.ts +347 -0
- package/apps/web/.next/types/app/api/auth/users/route.ts +347 -0
- package/apps/web/.next/types/app/api/env-vars/[key]/route.ts +347 -0
- package/apps/web/.next/types/app/api/env-vars/route.ts +347 -0
- package/apps/web/.next/types/app/api/jobs/[id]/route.ts +347 -0
- package/apps/web/.next/types/app/api/jobs/[id]/runs/route.ts +347 -0
- package/apps/web/.next/types/app/api/jobs/route.ts +347 -0
- package/apps/web/.next/types/app/api/mcps/[id]/route.ts +347 -0
- package/apps/web/.next/types/app/api/mcps/[id]/test/route.ts +347 -0
- package/apps/web/.next/types/app/api/mcps/route.ts +347 -0
- package/apps/web/.next/types/app/api/settings/route.ts +347 -0
- package/apps/web/.next/types/app/jobs/page.ts +84 -0
- package/apps/web/.next/types/app/login/layout.ts +84 -0
- package/apps/web/.next/types/app/login/page.ts +84 -0
- package/apps/web/.next/types/app/page.ts +84 -0
- package/apps/web/.next/types/app/settings/env-vars/page.ts +84 -0
- package/apps/web/.next/types/app/settings/mcps/page.ts +84 -0
- package/apps/web/.next/types/app/settings/page.ts +84 -0
- package/apps/web/.next/types/cache-life.d.ts +141 -0
- package/apps/web/.next/types/package.json +1 -0
- package/apps/web/.next/types/routes.d.ts +114 -0
- package/apps/web/.next/types/validator.ts +448 -0
- package/apps/web/Dockerfile +37 -0
- package/apps/web/next-env.d.ts +6 -0
- package/apps/web/next.config.js +6 -0
- package/apps/web/node_modules/.vite/vitest/da39a3ee5e6b4b0d3255bfef95601890afd80709/results.json +1 -0
- package/apps/web/package.json +48 -0
- package/apps/web/postcss.config.js +3 -0
- package/apps/web/public/logo.svg +17 -0
- package/apps/web/src/app/agents/[slug]/page.tsx +2235 -0
- package/apps/web/src/app/agents/new/page.tsx +1161 -0
- package/apps/web/src/app/api/agents/[id]/access/route.ts +76 -0
- package/apps/web/src/app/api/agents/[id]/claude-md/route.ts +111 -0
- package/apps/web/src/app/api/agents/[id]/logs/route.ts +84 -0
- package/apps/web/src/app/api/agents/[id]/manifest/route.ts +32 -0
- package/apps/web/src/app/api/agents/[id]/mcps/route.ts +73 -0
- package/apps/web/src/app/api/agents/[id]/memories/[memId]/route.ts +31 -0
- package/apps/web/src/app/api/agents/[id]/memories/route.ts +56 -0
- package/apps/web/src/app/api/agents/[id]/permissions/route.ts +74 -0
- package/apps/web/src/app/api/agents/[id]/reload/route.ts +33 -0
- package/apps/web/src/app/api/agents/[id]/restrictions/route.ts +85 -0
- package/apps/web/src/app/api/agents/[id]/route.ts +81 -0
- package/apps/web/src/app/api/agents/[id]/skills/[skillId]/route.ts +52 -0
- package/apps/web/src/app/api/agents/[id]/skills/route.ts +80 -0
- package/apps/web/src/app/api/agents/[id]/slack-info/route.ts +38 -0
- package/apps/web/src/app/api/agents/[id]/snapshots/[sid]/restore/route.ts +61 -0
- package/apps/web/src/app/api/agents/[id]/snapshots/[sid]/route.ts +53 -0
- package/apps/web/src/app/api/agents/[id]/snapshots/route.ts +84 -0
- package/apps/web/src/app/api/agents/[id]/start/route.ts +35 -0
- package/apps/web/src/app/api/agents/[id]/stop/route.ts +35 -0
- package/apps/web/src/app/api/agents/route.ts +99 -0
- package/apps/web/src/app/api/auth/login/route.ts +39 -0
- package/apps/web/src/app/api/auth/logout/route.ts +21 -0
- package/apps/web/src/app/api/auth/me/route.ts +24 -0
- package/apps/web/src/app/api/auth/users/[id]/route.ts +48 -0
- package/apps/web/src/app/api/auth/users/route.ts +63 -0
- package/apps/web/src/app/api/env-vars/[key]/route.ts +66 -0
- package/apps/web/src/app/api/env-vars/route.ts +59 -0
- package/apps/web/src/app/api/jobs/[id]/route.ts +51 -0
- package/apps/web/src/app/api/jobs/[id]/runs/route.ts +24 -0
- package/apps/web/src/app/api/jobs/route.ts +42 -0
- package/apps/web/src/app/api/mcps/[id]/route.ts +60 -0
- package/apps/web/src/app/api/mcps/[id]/test/route.ts +195 -0
- package/apps/web/src/app/api/mcps/route.ts +72 -0
- package/apps/web/src/app/api/settings/route.ts +42 -0
- package/apps/web/src/app/globals.css +124 -0
- package/apps/web/src/app/icon.svg +17 -0
- package/apps/web/src/app/jobs/page.tsx +543 -0
- package/apps/web/src/app/layout-shell.tsx +89 -0
- package/apps/web/src/app/layout.tsx +18 -0
- package/apps/web/src/app/login/layout.tsx +9 -0
- package/apps/web/src/app/login/page.tsx +150 -0
- package/apps/web/src/app/page.tsx +573 -0
- package/apps/web/src/app/settings/env-vars/page.tsx +216 -0
- package/apps/web/src/app/settings/mcps/page.tsx +763 -0
- package/apps/web/src/app/settings/page.tsx +528 -0
- package/apps/web/src/app/sidebar.tsx +345 -0
- package/apps/web/src/lib/__tests__/api-guard.test.ts +189 -0
- package/apps/web/src/lib/__tests__/auth.test.ts +262 -0
- package/apps/web/src/lib/__tests__/boss-registry.test.ts +323 -0
- package/apps/web/src/lib/__tests__/compile.test.ts +161 -0
- package/apps/web/src/lib/__tests__/db-agent-hierarchy.test.ts +136 -0
- package/apps/web/src/lib/__tests__/db-env-vars.test.ts +216 -0
- package/apps/web/src/lib/__tests__/db-restrictions.test.ts +117 -0
- package/apps/web/src/lib/__tests__/db.integration.test.ts +271 -0
- package/apps/web/src/lib/__tests__/diff.test.ts +102 -0
- package/apps/web/src/lib/__tests__/mcp-mask.test.ts +274 -0
- package/apps/web/src/lib/__tests__/skill-templates.test.ts +237 -0
- package/apps/web/src/lib/__tests__/slack-manifest.test.ts +105 -0
- package/apps/web/src/lib/api-guard.ts +68 -0
- package/apps/web/src/lib/auth-context.tsx +71 -0
- package/apps/web/src/lib/auth.ts +128 -0
- package/apps/web/src/lib/boss-registry.ts +90 -0
- package/apps/web/src/lib/compile.ts +51 -0
- package/apps/web/src/lib/db.ts +1196 -0
- package/apps/web/src/lib/diff.ts +43 -0
- package/apps/web/src/lib/mcp-mask.ts +91 -0
- package/apps/web/src/lib/portal.tsx +23 -0
- package/apps/web/src/lib/skill-templates.ts +148 -0
- package/apps/web/src/lib/slack-manifest.ts +85 -0
- package/apps/web/src/middleware.ts +68 -0
- package/apps/web/tailwind.config.js +6 -0
- package/apps/web/tsconfig.json +23 -0
- package/apps/web/vitest.config.mts +21 -0
- package/cli/.claude/settings.local.json +6 -0
- package/cli/README.md +281 -0
- package/cli/node_modules/.package-lock.json +427 -0
- package/cli/node_modules/commander/LICENSE +22 -0
- package/cli/node_modules/commander/Readme.md +1157 -0
- package/cli/node_modules/commander/esm.mjs +16 -0
- package/cli/node_modules/commander/index.js +24 -0
- package/cli/node_modules/commander/lib/argument.js +149 -0
- package/cli/node_modules/commander/lib/command.js +2509 -0
- package/cli/node_modules/commander/lib/error.js +39 -0
- package/cli/node_modules/commander/lib/help.js +520 -0
- package/cli/node_modules/commander/lib/option.js +330 -0
- package/cli/node_modules/commander/lib/suggestSimilar.js +101 -0
- package/cli/node_modules/commander/package-support.json +16 -0
- package/cli/node_modules/commander/package.json +84 -0
- package/cli/node_modules/commander/typings/esm.d.mts +3 -0
- package/cli/node_modules/commander/typings/index.d.ts +969 -0
- package/cli/package-lock.json +449 -0
- package/cli/package.json +44 -0
- package/cli/src/commands/init.ts +514 -0
- package/cli/src/commands/manage.ts +115 -0
- package/cli/src/index.ts +63 -0
- package/cli/tsconfig.json +14 -0
- package/docker-compose.yml +122 -0
- package/docs/agents/boss-agents.mdx +108 -0
- package/docs/agents/creating-agents.mdx +132 -0
- package/docs/agents/memory.mdx +113 -0
- package/docs/agents/tools.mdx +103 -0
- package/docs/configuration/env-vars.mdx +166 -0
- package/docs/configuration/mcp-servers.mdx +203 -0
- package/docs/configuration/slack-app.mdx +175 -0
- package/docs/docs.json +79 -0
- package/docs/favicon.svg +17 -0
- package/docs/features/history.mdx +60 -0
- package/docs/features/import-export.mdx +77 -0
- package/docs/features/logs.mdx +131 -0
- package/docs/features/multi-workspace.mdx +90 -0
- package/docs/features/scheduled-jobs.mdx +231 -0
- package/docs/features/users.mdx +92 -0
- package/docs/introduction.mdx +160 -0
- package/docs/logo/dark.svg +17 -0
- package/docs/logo/light.svg +17 -0
- package/docs/logo/wide-dark.svg +12 -0
- package/docs/logo/wide-light.svg +12 -0
- package/docs/quickstart.mdx +270 -0
- package/docs/self-hosting/docker.mdx +151 -0
- package/docs/self-hosting/production.mdx +176 -0
- package/package.json +20 -36
- package/packages/shared/dist/index.d.ts +8 -0
- package/packages/shared/dist/index.d.ts.map +1 -0
- package/packages/shared/dist/index.js +24 -0
- package/packages/shared/dist/index.js.map +1 -0
- package/packages/shared/dist/types.d.ts +584 -0
- package/packages/shared/dist/types.d.ts.map +1 -0
- package/packages/shared/dist/types.js +39 -0
- package/packages/shared/dist/types.js.map +1 -0
- package/packages/shared/package.json +15 -0
- package/packages/shared/src/db/schema.sql +354 -0
- package/packages/shared/src/index.ts +8 -0
- package/packages/shared/src/types.ts +683 -0
- package/packages/shared/tsconfig.json +17 -0
- package/scripts/dev.sh +45 -0
- /package/{dist → cli/dist}/commands/init.d.ts +0 -0
- /package/{dist → cli/dist}/commands/init.js +0 -0
- /package/{dist → cli/dist}/commands/manage.d.ts +0 -0
- /package/{dist → cli/dist}/commands/manage.js +0 -0
- /package/{dist → cli/dist}/index.d.ts +0 -0
- /package/{dist → cli/dist}/index.js +0 -0
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Unit tests for compile.ts — compileSkillsOnly and skillToSnapshotSkill.
|
|
3
|
+
*
|
|
4
|
+
* All tests use inline mock data; no database connection required.
|
|
5
|
+
*
|
|
6
|
+
* @module web/lib/__tests__/compile.test
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { describe, it, expect } from 'vitest';
|
|
10
|
+
import { compileSkillsOnly, skillToSnapshotSkill } from '@/lib/compile';
|
|
11
|
+
import type { Skill } from '@slackhive/shared';
|
|
12
|
+
|
|
13
|
+
// ---------------------------------------------------------------------------
|
|
14
|
+
// Helpers
|
|
15
|
+
// ---------------------------------------------------------------------------
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Creates a minimal {@link Skill} object for testing purposes.
|
|
19
|
+
*
|
|
20
|
+
* @param {Partial<Skill>} overrides - Fields to override from defaults.
|
|
21
|
+
* @returns {Skill}
|
|
22
|
+
*/
|
|
23
|
+
function makeSkill(overrides: Partial<Skill>): Skill {
|
|
24
|
+
return {
|
|
25
|
+
id: 'skill-id',
|
|
26
|
+
agentId: 'agent-id',
|
|
27
|
+
category: '00-core',
|
|
28
|
+
filename: 'main.md',
|
|
29
|
+
content: '# Main',
|
|
30
|
+
sortOrder: 0,
|
|
31
|
+
createdAt: new Date('2024-01-01'),
|
|
32
|
+
updatedAt: new Date('2024-01-01'),
|
|
33
|
+
...overrides,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// ---------------------------------------------------------------------------
|
|
38
|
+
// compileSkillsOnly
|
|
39
|
+
// ---------------------------------------------------------------------------
|
|
40
|
+
|
|
41
|
+
describe('compileSkillsOnly', () => {
|
|
42
|
+
it('returns empty string for empty skills array with no fallback', () => {
|
|
43
|
+
expect(compileSkillsOnly([])).toBe('');
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it('returns identity block for empty skills array with fallback', () => {
|
|
47
|
+
const result = compileSkillsOnly([], {
|
|
48
|
+
name: 'TestBot',
|
|
49
|
+
description: 'A test bot',
|
|
50
|
+
persona: 'Friendly helper',
|
|
51
|
+
});
|
|
52
|
+
expect(result).toContain('# TestBot');
|
|
53
|
+
expect(result).toContain('A test bot');
|
|
54
|
+
expect(result).toContain('Friendly helper');
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it('returns identity block using default persona when persona is undefined', () => {
|
|
58
|
+
const result = compileSkillsOnly([], { name: 'TestBot', description: 'Desc' });
|
|
59
|
+
expect(result).toContain('A helpful assistant.');
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it('returns trimmed content for a single skill', () => {
|
|
63
|
+
const skill = makeSkill({ content: ' # Identity\n\nHello world ' });
|
|
64
|
+
const result = compileSkillsOnly([skill]);
|
|
65
|
+
expect(result).toBe('# Identity\n\nHello world');
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it('joins multiple skills with double newline sorted by sortOrder', () => {
|
|
69
|
+
const skills = [
|
|
70
|
+
makeSkill({ sortOrder: 2, content: 'Third' }),
|
|
71
|
+
makeSkill({ sortOrder: 0, content: 'First' }),
|
|
72
|
+
makeSkill({ sortOrder: 1, content: 'Second' }),
|
|
73
|
+
];
|
|
74
|
+
const result = compileSkillsOnly(skills);
|
|
75
|
+
expect(result).toBe('First\n\nSecond\n\nThird');
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it('strips <!-- skill:... --> header comments from output', () => {
|
|
79
|
+
const skill = makeSkill({
|
|
80
|
+
content: '<!-- skill:identity -->\n# Identity\n\nContent here',
|
|
81
|
+
});
|
|
82
|
+
const result = compileSkillsOnly([skill]);
|
|
83
|
+
expect(result).not.toContain('<!-- skill:identity -->');
|
|
84
|
+
expect(result).toContain('# Identity');
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it('correctly sorts skills passed out of order', () => {
|
|
88
|
+
const skills = [
|
|
89
|
+
makeSkill({ sortOrder: 10, content: 'Last' }),
|
|
90
|
+
makeSkill({ sortOrder: 1, content: 'First' }),
|
|
91
|
+
makeSkill({ sortOrder: 5, content: 'Middle' }),
|
|
92
|
+
];
|
|
93
|
+
const result = compileSkillsOnly(skills);
|
|
94
|
+
const parts = result.split('\n\n');
|
|
95
|
+
expect(parts[0]).toBe('First');
|
|
96
|
+
expect(parts[1]).toBe('Middle');
|
|
97
|
+
expect(parts[2]).toBe('Last');
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it('returns empty string for a skill with only whitespace content', () => {
|
|
101
|
+
const skill = makeSkill({ content: ' \n\t\n ' });
|
|
102
|
+
const result = compileSkillsOnly([skill]);
|
|
103
|
+
expect(result).toBe('');
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it('produces deterministic output for skills with duplicate sortOrder', () => {
|
|
107
|
+
const skills = [
|
|
108
|
+
makeSkill({ sortOrder: 1, content: 'A', filename: 'a.md' }),
|
|
109
|
+
makeSkill({ sortOrder: 1, content: 'B', filename: 'b.md' }),
|
|
110
|
+
];
|
|
111
|
+
const result1 = compileSkillsOnly(skills);
|
|
112
|
+
const result2 = compileSkillsOnly([...skills].reverse());
|
|
113
|
+
// Both calls should contain both skills — order may vary but output must not crash
|
|
114
|
+
expect(result1).toContain('A');
|
|
115
|
+
expect(result1).toContain('B');
|
|
116
|
+
expect(result2).toContain('A');
|
|
117
|
+
expect(result2).toContain('B');
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
it('returns identity block with empty heading when fallback name is empty string', () => {
|
|
121
|
+
const result = compileSkillsOnly([], { name: '' });
|
|
122
|
+
expect(result).toContain('#');
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
it('does not mutate the original skills array order', () => {
|
|
126
|
+
const skills = [
|
|
127
|
+
makeSkill({ sortOrder: 2, content: 'B' }),
|
|
128
|
+
makeSkill({ sortOrder: 1, content: 'A' }),
|
|
129
|
+
];
|
|
130
|
+
const originalOrder = skills.map(s => s.content);
|
|
131
|
+
compileSkillsOnly(skills);
|
|
132
|
+
expect(skills.map(s => s.content)).toEqual(originalOrder);
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
// ---------------------------------------------------------------------------
|
|
137
|
+
// skillToSnapshotSkill
|
|
138
|
+
// ---------------------------------------------------------------------------
|
|
139
|
+
|
|
140
|
+
describe('skillToSnapshotSkill', () => {
|
|
141
|
+
it('maps category, filename, content, and sortOrder -> sort_order correctly', () => {
|
|
142
|
+
const skill = makeSkill({
|
|
143
|
+
category: '01-knowledge',
|
|
144
|
+
filename: 'schema.md',
|
|
145
|
+
content: '## Schema\n\nDetails',
|
|
146
|
+
sortOrder: 42,
|
|
147
|
+
});
|
|
148
|
+
const snapshot = skillToSnapshotSkill(skill);
|
|
149
|
+
expect(snapshot.category).toBe('01-knowledge');
|
|
150
|
+
expect(snapshot.filename).toBe('schema.md');
|
|
151
|
+
expect(snapshot.content).toBe('## Schema\n\nDetails');
|
|
152
|
+
expect(snapshot.sort_order).toBe(42);
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
it('does not include id or agentId in the result', () => {
|
|
156
|
+
const skill = makeSkill({ id: 'some-uuid', agentId: 'agent-uuid' });
|
|
157
|
+
const snapshot = skillToSnapshotSkill(skill);
|
|
158
|
+
expect(snapshot).not.toHaveProperty('id');
|
|
159
|
+
expect(snapshot).not.toHaveProperty('agentId');
|
|
160
|
+
});
|
|
161
|
+
});
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Unit tests for agent hierarchy / enabled fields in db.ts.
|
|
3
|
+
*
|
|
4
|
+
* Covers:
|
|
5
|
+
* - updateAgentEnabled sets the enabled column correctly
|
|
6
|
+
* - updateAgent supports isBoss and reportsTo fields
|
|
7
|
+
* - rowToAgent maps the enabled column (defaults true when missing)
|
|
8
|
+
*
|
|
9
|
+
* No real database required — pg.Pool is mocked via vi.mock.
|
|
10
|
+
*
|
|
11
|
+
* @module web/lib/__tests__/db-agent-hierarchy.test
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
15
|
+
|
|
16
|
+
// ─── Mock pg ──────────────────────────────────────────────────────────────────
|
|
17
|
+
|
|
18
|
+
const mockQuery = vi.fn();
|
|
19
|
+
|
|
20
|
+
vi.mock('pg', () => ({
|
|
21
|
+
Pool: vi.fn().mockImplementation(function() { return { query: mockQuery }; }),
|
|
22
|
+
}));
|
|
23
|
+
|
|
24
|
+
process.env.DATABASE_URL = 'postgresql://mock/db';
|
|
25
|
+
process.env.ENV_SECRET_KEY = 'test-secret-key-32-chars-padding!';
|
|
26
|
+
|
|
27
|
+
import { updateAgentEnabled, updateAgent, getAgentById } from '@/lib/db';
|
|
28
|
+
|
|
29
|
+
// ─── Helpers ──────────────────────────────────────────────────────────────────
|
|
30
|
+
|
|
31
|
+
const AGENT_ID = 'agent-uuid-001';
|
|
32
|
+
|
|
33
|
+
const BASE_ROW = {
|
|
34
|
+
id: AGENT_ID,
|
|
35
|
+
slug: 'test-agent',
|
|
36
|
+
name: 'Test Agent',
|
|
37
|
+
persona: null,
|
|
38
|
+
description: null,
|
|
39
|
+
slack_bot_token: 'xoxb-test',
|
|
40
|
+
slack_app_token: 'xapp-test',
|
|
41
|
+
slack_signing_secret: 'secret',
|
|
42
|
+
slack_bot_user_id: null,
|
|
43
|
+
model: 'claude-sonnet-4-6',
|
|
44
|
+
status: 'stopped',
|
|
45
|
+
enabled: true,
|
|
46
|
+
is_boss: false,
|
|
47
|
+
reports_to: [],
|
|
48
|
+
claude_md: '',
|
|
49
|
+
created_by: 'system',
|
|
50
|
+
created_at: new Date(),
|
|
51
|
+
updated_at: new Date(),
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
beforeEach(() => {
|
|
55
|
+
mockQuery.mockReset();
|
|
56
|
+
mockQuery.mockResolvedValue({ rows: [] });
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
// ─── updateAgentEnabled ────────────────────────────────────────────────────────
|
|
60
|
+
|
|
61
|
+
describe('updateAgentEnabled', () => {
|
|
62
|
+
it('sets enabled = true', async () => {
|
|
63
|
+
await updateAgentEnabled(AGENT_ID, true);
|
|
64
|
+
expect(mockQuery).toHaveBeenCalledOnce();
|
|
65
|
+
const [sql, params] = mockQuery.mock.calls[0];
|
|
66
|
+
expect(sql).toContain('enabled = $1');
|
|
67
|
+
expect(params).toEqual([true, AGENT_ID]);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it('sets enabled = false', async () => {
|
|
71
|
+
await updateAgentEnabled(AGENT_ID, false);
|
|
72
|
+
const [, params] = mockQuery.mock.calls[0];
|
|
73
|
+
expect(params[0]).toBe(false);
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
// ─── updateAgent — isBoss + reportsTo ─────────────────────────────────────────
|
|
78
|
+
|
|
79
|
+
describe('updateAgent — hierarchy fields', () => {
|
|
80
|
+
beforeEach(() => {
|
|
81
|
+
mockQuery.mockResolvedValue({ rows: [BASE_ROW] });
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it('includes is_boss when isBoss is provided', async () => {
|
|
85
|
+
await updateAgent(AGENT_ID, { isBoss: true });
|
|
86
|
+
const [sql, params] = mockQuery.mock.calls[0];
|
|
87
|
+
expect(sql).toContain('is_boss =');
|
|
88
|
+
expect(params).toContain(true);
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it('includes reports_to when reportsTo is provided', async () => {
|
|
92
|
+
const bosses = ['boss-uuid-1', 'boss-uuid-2'];
|
|
93
|
+
await updateAgent(AGENT_ID, { reportsTo: bosses });
|
|
94
|
+
const [sql, params] = mockQuery.mock.calls[0];
|
|
95
|
+
expect(sql).toContain('reports_to =');
|
|
96
|
+
expect(params).toContain(bosses);
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it('sets both isBoss and reportsTo together', async () => {
|
|
100
|
+
await updateAgent(AGENT_ID, { isBoss: false, reportsTo: ['boss-uuid-1'] });
|
|
101
|
+
const [sql, params] = mockQuery.mock.calls[0];
|
|
102
|
+
expect(sql).toContain('is_boss =');
|
|
103
|
+
expect(sql).toContain('reports_to =');
|
|
104
|
+
expect(params).toContain(false);
|
|
105
|
+
expect(params).toContainEqual(['boss-uuid-1']);
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
it('does not include is_boss when isBoss is omitted', async () => {
|
|
109
|
+
await updateAgent(AGENT_ID, { name: 'New Name' });
|
|
110
|
+
const [sql] = mockQuery.mock.calls[0];
|
|
111
|
+
expect(sql).not.toContain('is_boss');
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
// ─── rowToAgent — enabled field mapping ───────────────────────────────────────
|
|
116
|
+
|
|
117
|
+
describe('getAgentById — enabled field', () => {
|
|
118
|
+
it('maps enabled = true from DB row', async () => {
|
|
119
|
+
mockQuery.mockResolvedValue({ rows: [{ ...BASE_ROW, enabled: true }] });
|
|
120
|
+
const agent = await getAgentById(AGENT_ID);
|
|
121
|
+
expect(agent?.enabled).toBe(true);
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
it('maps enabled = false from DB row', async () => {
|
|
125
|
+
mockQuery.mockResolvedValue({ rows: [{ ...BASE_ROW, enabled: false }] });
|
|
126
|
+
const agent = await getAgentById(AGENT_ID);
|
|
127
|
+
expect(agent?.enabled).toBe(false);
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
it('defaults enabled to true when column is null/undefined', async () => {
|
|
131
|
+
const { enabled: _omit, ...rowWithoutEnabled } = BASE_ROW;
|
|
132
|
+
mockQuery.mockResolvedValue({ rows: [rowWithoutEnabled] });
|
|
133
|
+
const agent = await getAgentById(AGENT_ID);
|
|
134
|
+
expect(agent?.enabled).toBe(true);
|
|
135
|
+
});
|
|
136
|
+
});
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Unit tests for env var functions in db.ts.
|
|
3
|
+
*
|
|
4
|
+
* Verifies that setEnvVar, getEnvVarValues, getAllEnvVars, updateEnvVarDescription,
|
|
5
|
+
* and deleteEnvVar issue the correct SQL — in particular that setEnvVar uses
|
|
6
|
+
* AES-256 encryption (cipher-algo=aes256) rather than the pgcrypto default.
|
|
7
|
+
*
|
|
8
|
+
* No real database required — pg.Pool is mocked via vi.mock.
|
|
9
|
+
*
|
|
10
|
+
* @module web/lib/__tests__/db-env-vars.test
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
14
|
+
|
|
15
|
+
// ─── Mock pg ─────────────────────────────────────────────────────────────────
|
|
16
|
+
|
|
17
|
+
const mockQuery = vi.fn();
|
|
18
|
+
|
|
19
|
+
vi.mock('pg', () => {
|
|
20
|
+
return {
|
|
21
|
+
Pool: vi.fn().mockImplementation(function() { return { query: mockQuery }; }),
|
|
22
|
+
};
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
// Set required env vars before importing db so the singleton pool initialises.
|
|
26
|
+
process.env.DATABASE_URL = 'postgresql://mock/db';
|
|
27
|
+
process.env.ENV_SECRET_KEY = 'test-secret-key-32-chars-padding!';
|
|
28
|
+
|
|
29
|
+
import {
|
|
30
|
+
setEnvVar,
|
|
31
|
+
getEnvVarValues,
|
|
32
|
+
getAllEnvVars,
|
|
33
|
+
updateEnvVarDescription,
|
|
34
|
+
deleteEnvVar,
|
|
35
|
+
} from '@/lib/db';
|
|
36
|
+
|
|
37
|
+
// ─── Helpers ──────────────────────────────────────────────────────────────────
|
|
38
|
+
|
|
39
|
+
beforeEach(() => {
|
|
40
|
+
mockQuery.mockReset();
|
|
41
|
+
mockQuery.mockResolvedValue({ rows: [] });
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
// ─── setEnvVar ────────────────────────────────────────────────────────────────
|
|
45
|
+
|
|
46
|
+
describe('setEnvVar', () => {
|
|
47
|
+
it('calls query with the correct number of parameters', async () => {
|
|
48
|
+
await setEnvVar('MY_KEY', 'my-value');
|
|
49
|
+
expect(mockQuery).toHaveBeenCalledOnce();
|
|
50
|
+
const [, params] = mockQuery.mock.calls[0];
|
|
51
|
+
// $1=key, $2=value, $3=encKey, $4=description
|
|
52
|
+
expect(params).toHaveLength(4);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it('passes the key as $1', async () => {
|
|
56
|
+
await setEnvVar('DB_URL', 'postgres://localhost');
|
|
57
|
+
const [, params] = mockQuery.mock.calls[0];
|
|
58
|
+
expect(params[0]).toBe('DB_URL');
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it('passes the plaintext value as $2 (encryption done in SQL)', async () => {
|
|
62
|
+
await setEnvVar('DB_URL', 'postgres://localhost');
|
|
63
|
+
const [, params] = mockQuery.mock.calls[0];
|
|
64
|
+
expect(params[1]).toBe('postgres://localhost');
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it('passes ENV_SECRET_KEY as $3', async () => {
|
|
68
|
+
await setEnvVar('MY_KEY', 'val');
|
|
69
|
+
const [, params] = mockQuery.mock.calls[0];
|
|
70
|
+
expect(params[2]).toBe('test-secret-key-32-chars-padding!');
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it('passes null as $4 when description is omitted', async () => {
|
|
74
|
+
await setEnvVar('MY_KEY', 'val');
|
|
75
|
+
const [, params] = mockQuery.mock.calls[0];
|
|
76
|
+
expect(params[3]).toBeNull();
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it('passes description as $4 when provided', async () => {
|
|
80
|
+
await setEnvVar('MY_KEY', 'val', 'My description');
|
|
81
|
+
const [, params] = mockQuery.mock.calls[0];
|
|
82
|
+
expect(params[3]).toBe('My description');
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it('uses pgp_sym_encrypt with cipher-algo=aes256 for INSERT', async () => {
|
|
86
|
+
await setEnvVar('MY_KEY', 'val');
|
|
87
|
+
const [sql] = mockQuery.mock.calls[0];
|
|
88
|
+
expect(sql).toContain("pgp_sym_encrypt($2, $3, 'cipher-algo=aes256')");
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it('uses pgp_sym_encrypt with cipher-algo=aes256 for ON CONFLICT UPDATE', async () => {
|
|
92
|
+
await setEnvVar('MY_KEY', 'val');
|
|
93
|
+
const [sql] = mockQuery.mock.calls[0];
|
|
94
|
+
// Both the INSERT value and the UPSERT update value must use AES-256
|
|
95
|
+
const matches = (sql as string).match(/cipher-algo=aes256/g);
|
|
96
|
+
expect(matches).toHaveLength(2);
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it('uses an INSERT … ON CONFLICT upsert pattern', async () => {
|
|
100
|
+
await setEnvVar('MY_KEY', 'val');
|
|
101
|
+
const [sql] = mockQuery.mock.calls[0];
|
|
102
|
+
expect(sql).toMatch(/INSERT INTO env_vars/i);
|
|
103
|
+
expect(sql).toMatch(/ON CONFLICT/i);
|
|
104
|
+
expect(sql).toMatch(/DO UPDATE SET/i);
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
// ─── getEnvVarValues ──────────────────────────────────────────────────────────
|
|
109
|
+
|
|
110
|
+
describe('getEnvVarValues', () => {
|
|
111
|
+
it('decrypts values with pgp_sym_decrypt', async () => {
|
|
112
|
+
mockQuery.mockResolvedValue({ rows: [] });
|
|
113
|
+
await getEnvVarValues();
|
|
114
|
+
const [sql] = mockQuery.mock.calls[0];
|
|
115
|
+
expect(sql).toContain('pgp_sym_decrypt');
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
it('passes ENV_SECRET_KEY as parameter', async () => {
|
|
119
|
+
mockQuery.mockResolvedValue({ rows: [] });
|
|
120
|
+
await getEnvVarValues();
|
|
121
|
+
const [, params] = mockQuery.mock.calls[0];
|
|
122
|
+
expect(params[0]).toBe('test-secret-key-32-chars-padding!');
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
it('returns a key→value record from query rows', async () => {
|
|
126
|
+
mockQuery.mockResolvedValue({
|
|
127
|
+
rows: [
|
|
128
|
+
{ key: 'FOO', value: 'bar' },
|
|
129
|
+
{ key: 'BAZ', value: 'qux' },
|
|
130
|
+
],
|
|
131
|
+
});
|
|
132
|
+
const result = await getEnvVarValues();
|
|
133
|
+
expect(result).toEqual({ FOO: 'bar', BAZ: 'qux' });
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
it('returns an empty object when no rows', async () => {
|
|
137
|
+
mockQuery.mockResolvedValue({ rows: [] });
|
|
138
|
+
const result = await getEnvVarValues();
|
|
139
|
+
expect(result).toEqual({});
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
// ─── getAllEnvVars ────────────────────────────────────────────────────────────
|
|
144
|
+
|
|
145
|
+
describe('getAllEnvVars', () => {
|
|
146
|
+
it('queries key, description, and updated_at', async () => {
|
|
147
|
+
await getAllEnvVars();
|
|
148
|
+
const [sql] = mockQuery.mock.calls[0];
|
|
149
|
+
expect(sql).toContain('key');
|
|
150
|
+
expect(sql).toContain('description');
|
|
151
|
+
expect(sql).toContain('updated_at');
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
it('never selects the encrypted value column', async () => {
|
|
155
|
+
await getAllEnvVars();
|
|
156
|
+
const [sql] = mockQuery.mock.calls[0];
|
|
157
|
+
expect(sql).not.toContain('pgp_sym_decrypt');
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
it('maps rows to objects with key, description, and updatedAt', async () => {
|
|
161
|
+
const now = new Date();
|
|
162
|
+
mockQuery.mockResolvedValue({
|
|
163
|
+
rows: [{ key: 'MY_KEY', description: 'desc', updated_at: now }],
|
|
164
|
+
});
|
|
165
|
+
const result = await getAllEnvVars();
|
|
166
|
+
expect(result).toEqual([{ key: 'MY_KEY', description: 'desc', updatedAt: now }]);
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
it('sets description to undefined when null in DB', async () => {
|
|
170
|
+
const now = new Date();
|
|
171
|
+
mockQuery.mockResolvedValue({
|
|
172
|
+
rows: [{ key: 'MY_KEY', description: null, updated_at: now }],
|
|
173
|
+
});
|
|
174
|
+
const [row] = await getAllEnvVars();
|
|
175
|
+
expect(row.description).toBeUndefined();
|
|
176
|
+
});
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
// ─── updateEnvVarDescription ──────────────────────────────────────────────────
|
|
180
|
+
|
|
181
|
+
describe('updateEnvVarDescription', () => {
|
|
182
|
+
it('issues an UPDATE on env_vars', async () => {
|
|
183
|
+
await updateEnvVarDescription('MY_KEY', 'new desc');
|
|
184
|
+
const [sql] = mockQuery.mock.calls[0];
|
|
185
|
+
expect(sql).toMatch(/UPDATE env_vars/i);
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
it('passes key and description as parameters', async () => {
|
|
189
|
+
await updateEnvVarDescription('MY_KEY', 'new desc');
|
|
190
|
+
const [, params] = mockQuery.mock.calls[0];
|
|
191
|
+
expect(params).toContain('MY_KEY');
|
|
192
|
+
expect(params).toContain('new desc');
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
it('does not touch the encrypted value column', async () => {
|
|
196
|
+
await updateEnvVarDescription('MY_KEY', 'new desc');
|
|
197
|
+
const [sql] = mockQuery.mock.calls[0];
|
|
198
|
+
expect(sql).not.toContain('pgp_sym_encrypt');
|
|
199
|
+
});
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
// ─── deleteEnvVar ─────────────────────────────────────────────────────────────
|
|
203
|
+
|
|
204
|
+
describe('deleteEnvVar', () => {
|
|
205
|
+
it('issues a DELETE on env_vars', async () => {
|
|
206
|
+
await deleteEnvVar('MY_KEY');
|
|
207
|
+
const [sql] = mockQuery.mock.calls[0];
|
|
208
|
+
expect(sql).toMatch(/DELETE FROM env_vars/i);
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
it('passes the key as the only parameter', async () => {
|
|
212
|
+
await deleteEnvVar('MY_KEY');
|
|
213
|
+
const [, params] = mockQuery.mock.calls[0];
|
|
214
|
+
expect(params).toEqual(['MY_KEY']);
|
|
215
|
+
});
|
|
216
|
+
});
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Unit tests for agent restriction functions in db.ts.
|
|
3
|
+
*
|
|
4
|
+
* Verifies that getAgentRestrictions and upsertRestrictions issue correct SQL.
|
|
5
|
+
* No real database required — pg.Pool is mocked via vi.mock.
|
|
6
|
+
*
|
|
7
|
+
* @module web/lib/__tests__/db-restrictions.test
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
11
|
+
|
|
12
|
+
// ─── Mock pg ─────────────────────────────────────────────────────────────────
|
|
13
|
+
|
|
14
|
+
const mockQuery = vi.fn();
|
|
15
|
+
|
|
16
|
+
vi.mock('pg', () => ({
|
|
17
|
+
Pool: vi.fn().mockImplementation(function() { return { query: mockQuery }; }),
|
|
18
|
+
}));
|
|
19
|
+
|
|
20
|
+
process.env.DATABASE_URL = 'postgresql://mock/db';
|
|
21
|
+
process.env.ENV_SECRET_KEY = 'test-secret-key-32-chars-padding!';
|
|
22
|
+
|
|
23
|
+
import { getAgentRestrictions, upsertRestrictions } from '@/lib/db';
|
|
24
|
+
|
|
25
|
+
// ─── Helpers ──────────────────────────────────────────────────────────────────
|
|
26
|
+
|
|
27
|
+
const AGENT_ID = 'agent-uuid-001';
|
|
28
|
+
|
|
29
|
+
const RESTRICTION_ROW = {
|
|
30
|
+
id: 'r-001',
|
|
31
|
+
agent_id: AGENT_ID,
|
|
32
|
+
allowed_channels: ['C_ABC', 'C_DEF'],
|
|
33
|
+
updated_at: new Date('2026-01-01'),
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
beforeEach(() => {
|
|
37
|
+
mockQuery.mockReset();
|
|
38
|
+
mockQuery.mockResolvedValue({ rows: [] });
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
// ─── getAgentRestrictions ────────────────────────────────────────────────────
|
|
42
|
+
|
|
43
|
+
describe('getAgentRestrictions', () => {
|
|
44
|
+
it('queries agent_restrictions by agent_id', async () => {
|
|
45
|
+
await getAgentRestrictions(AGENT_ID);
|
|
46
|
+
const [sql] = mockQuery.mock.calls[0];
|
|
47
|
+
expect(sql).toContain('agent_restrictions');
|
|
48
|
+
expect(sql).toContain('agent_id');
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it('passes agentId as query parameter', async () => {
|
|
52
|
+
await getAgentRestrictions(AGENT_ID);
|
|
53
|
+
const [, params] = mockQuery.mock.calls[0];
|
|
54
|
+
expect(params).toContain(AGENT_ID);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it('returns null when no row found', async () => {
|
|
58
|
+
mockQuery.mockResolvedValue({ rows: [] });
|
|
59
|
+
const result = await getAgentRestrictions(AGENT_ID);
|
|
60
|
+
expect(result).toBeNull();
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it('maps row to Restriction with correct fields', async () => {
|
|
64
|
+
mockQuery.mockResolvedValue({ rows: [RESTRICTION_ROW] });
|
|
65
|
+
const result = await getAgentRestrictions(AGENT_ID);
|
|
66
|
+
expect(result).not.toBeNull();
|
|
67
|
+
expect(result!.id).toBe('r-001');
|
|
68
|
+
expect(result!.agentId).toBe(AGENT_ID);
|
|
69
|
+
expect(result!.allowedChannels).toEqual(['C_ABC', 'C_DEF']);
|
|
70
|
+
expect(result!.updatedAt).toEqual(RESTRICTION_ROW.updated_at);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it('defaults allowedChannels to [] when column is null', async () => {
|
|
74
|
+
mockQuery.mockResolvedValue({
|
|
75
|
+
rows: [{ ...RESTRICTION_ROW, allowed_channels: null }],
|
|
76
|
+
});
|
|
77
|
+
const result = await getAgentRestrictions(AGENT_ID);
|
|
78
|
+
expect(result!.allowedChannels).toEqual([]);
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
// ─── upsertRestrictions ──────────────────────────────────────────────────────
|
|
83
|
+
|
|
84
|
+
describe('upsertRestrictions', () => {
|
|
85
|
+
it('uses INSERT … ON CONFLICT DO UPDATE', async () => {
|
|
86
|
+
await upsertRestrictions(AGENT_ID, ['C_ABC']);
|
|
87
|
+
const [sql] = mockQuery.mock.calls[0];
|
|
88
|
+
expect(sql).toMatch(/INSERT INTO agent_restrictions/i);
|
|
89
|
+
expect(sql).toMatch(/ON CONFLICT/i);
|
|
90
|
+
expect(sql).toMatch(/DO UPDATE/i);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it('passes agentId as first parameter', async () => {
|
|
94
|
+
await upsertRestrictions(AGENT_ID, ['C_ABC']);
|
|
95
|
+
const [, params] = mockQuery.mock.calls[0];
|
|
96
|
+
expect(params[0]).toBe(AGENT_ID);
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it('passes allowedChannels array as second parameter', async () => {
|
|
100
|
+
const channels = ['C_1', 'C_2', 'C_3'];
|
|
101
|
+
await upsertRestrictions(AGENT_ID, channels);
|
|
102
|
+
const [, params] = mockQuery.mock.calls[0];
|
|
103
|
+
expect(params[1]).toEqual(channels);
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it('accepts an empty allowedChannels array (unrestricted)', async () => {
|
|
107
|
+
await upsertRestrictions(AGENT_ID, []);
|
|
108
|
+
const [, params] = mockQuery.mock.calls[0];
|
|
109
|
+
expect(params[1]).toEqual([]);
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
it('updates allowed_channels in the SET clause', async () => {
|
|
113
|
+
await upsertRestrictions(AGENT_ID, ['C_NEW']);
|
|
114
|
+
const [sql] = mockQuery.mock.calls[0];
|
|
115
|
+
expect(sql).toContain('allowed_channels');
|
|
116
|
+
});
|
|
117
|
+
});
|