@hexabot-ai/cli 3.2.6 → 3.2.7-beta.0

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/AGENTS.md CHANGED
@@ -6,7 +6,7 @@ This file is the authoritative cheat-sheet for the Hexabot CLI. It summarizes th
6
6
 
7
7
  - **Entry point**: `src/index.ts` prints the banner (`printBanner()`) and calls `checkPrerequisites({ silent: true })` before instantiating the Commander program. That pre-flight verifies Node.js (see below) so user-facing commands can assume a supported runtime.
8
8
  - **CLI factory**: `createCliProgram()` (`src/cli.ts`) builds the `Command` instance, configures name/description/version (`getCliVersion()`), and registers `check`, `create`, `config`, `dev`, `docker`, `env`, `start`, and `migrate` commands.
9
- - **Prerequisite gate**: `checkPrerequisites()` / `checkNodeVersion()` / `checkDocker()` (`src/core/prerequisites.ts`) centralize system checks. The top-level bootstrap validates Node (>= 20.19.0) while Docker checks are performed by commands that actually need Docker.
9
+ - **Prerequisite gate**: `checkPrerequisites()` / `checkNodeVersion()` / `checkDocker()` (`src/core/prerequisites.ts`) centralize system checks. The top-level bootstrap validates Node (>= 24.17.0) while Docker checks are performed by commands that actually need Docker.
10
10
  - **Project guard**: `assertHexabotProject()` / `isHexabotProject()` (`src/core/project.ts`) enforce that commands run inside a workspace whose `package.json` depends on `@hexabot-ai/api`. Docker-aware commands also call `ensureDockerFolder()` which ensures `<projectRoot>/docker/` exists before touching compose files.
11
11
  - **Service parsing**: `parseServices()` (`src/utils/services.ts`) normalizes the shared `--services` flag to a de-duped string array so Docker helpers can safely compose per-service overlays.
12
12
 
package/README.md CHANGED
@@ -8,7 +8,7 @@ Not yet familiar with [Hexabot](https://hexabot.ai/)? Hexabot v3 is an agentic A
8
8
 
9
9
  ### Prerequisites
10
10
 
11
- - Node.js >= 20.19.0
11
+ - Node.js >= 24.17.0
12
12
  - One package manager (`npm`, `pnpm`, `yarn`, or `bun`)
13
13
  - Docker Desktop/Engine (only required when you pass `--docker` or use `hexabot docker ...`)
14
14
 
@@ -6,7 +6,7 @@
6
6
  import chalk from 'chalk';
7
7
  import { loadProjectConfig } from '../core/config.js';
8
8
  import { listEnvStatus } from '../core/env.js';
9
- import { checkDocker, checkNodeVersion } from '../core/prerequisites.js';
9
+ import { checkDocker, checkDockerCompose, checkNodeVersion, } from '../core/prerequisites.js';
10
10
  import { isHexabotProject } from '../core/project.js';
11
11
  export const registerCheckCommand = (program) => {
12
12
  program
@@ -60,6 +60,15 @@ const runDiagnostics = (options) => {
60
60
  ok: dockerResult.ok,
61
61
  message: dockerResult.message,
62
62
  });
63
+ const dockerComposeResult = checkDockerCompose({
64
+ fatal: false,
65
+ silent: true,
66
+ });
67
+ results.push({
68
+ label: 'Docker Compose',
69
+ ok: dockerComposeResult.ok,
70
+ message: dockerComposeResult.message,
71
+ });
63
72
  }
64
73
  const hasErrors = results.some((result) => !result.ok);
65
74
  results.forEach((result) => printResult(result));
@@ -5,11 +5,12 @@
5
5
  */
6
6
  import { execSync } from 'child_process';
7
7
  import chalk from 'chalk';
8
- const REQUIRED_NODE_VERSION = '20.19.0';
8
+ const REQUIRED_NODE_VERSION = '24.17.0';
9
9
  export const checkPrerequisites = (options = {}) => {
10
10
  checkNodeVersion(options);
11
11
  if (options.docker) {
12
12
  checkDocker(options);
13
+ checkDockerCompose(options);
13
14
  }
14
15
  };
15
16
  export const checkNodeVersion = (options = {}) => {
@@ -28,7 +29,7 @@ export const checkNodeVersion = (options = {}) => {
28
29
  return { ok: false, message };
29
30
  }
30
31
  catch (error) {
31
- const message = "Node.js is not accessible or installed correctly. Install Node.js v20.19.0+ and ensure it's in your PATH.";
32
+ const message = "Node.js is not accessible or installed correctly. Install Node.js v24.17.0+ and ensure it's in your PATH.";
32
33
  handleFailure(message, options, error);
33
34
  return { ok: false, message, details: error.message };
34
35
  }
@@ -48,6 +49,21 @@ export const checkDocker = (options = {}) => {
48
49
  return { ok: false, message, details: error.message };
49
50
  }
50
51
  };
52
+ export const checkDockerCompose = (options = {}) => {
53
+ try {
54
+ const composeVersion = execSync('docker compose version', {
55
+ encoding: 'utf-8',
56
+ }).trim();
57
+ const message = `Docker Compose is installed: ${composeVersion}`;
58
+ logSuccess(message, options);
59
+ return { ok: true, message };
60
+ }
61
+ catch (error) {
62
+ const message = 'Docker Compose (v2) is required for this command. Please install or update Docker Desktop / the Compose plugin.';
63
+ handleFailure(message, options, error);
64
+ return { ok: false, message, details: error.message };
65
+ }
66
+ };
51
67
  const normalizeVersion = (version) => {
52
68
  return version.startsWith('v') ? version.slice(1) : version;
53
69
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hexabot-ai/cli",
3
- "version": "3.2.6",
3
+ "version": "3.2.7-beta.0",
4
4
  "description": "Official Hexabot CLI for creating and managing AI chatbot/agent projects built with Hexabot.",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",
@@ -8,7 +8,7 @@
8
8
  "hexabot": "dist/index.js"
9
9
  },
10
10
  "engines": {
11
- "node": ">=20.19.0"
11
+ "node": ">=24.17.0"
12
12
  },
13
13
  "keywords": [],
14
14
  "author": "Hexastack",
@@ -27,6 +27,7 @@
27
27
  "figlet": "^1.7.0"
28
28
  },
29
29
  "devDependencies": {
30
+ "@jest/globals": "^30.4.1",
30
31
  "@types/chalk": "^2.2.0",
31
32
  "@types/commander": "^2.12.2",
32
33
  "@types/decompress": "^4.2.7",
@@ -10,6 +10,7 @@ import { Command } from 'commander';
10
10
  const loadProjectConfig = jest.fn();
11
11
  const listEnvStatus = jest.fn();
12
12
  const checkDocker = jest.fn();
13
+ const checkDockerCompose = jest.fn();
13
14
  const checkNodeVersion = jest.fn();
14
15
  const isHexabotProject = jest.fn();
15
16
 
@@ -23,6 +24,7 @@ jest.unstable_mockModule('../../core/env.js', () => ({
23
24
 
24
25
  jest.unstable_mockModule('../../core/prerequisites.js', () => ({
25
26
  checkDocker,
27
+ checkDockerCompose,
26
28
  checkNodeVersion,
27
29
  }));
28
30
 
@@ -55,6 +57,10 @@ describe('registerCheckCommand', () => {
55
57
  { file: '.env.docker', exists: true },
56
58
  ]);
57
59
  checkDocker.mockReturnValue({ ok: true, message: 'Docker OK' });
60
+ checkDockerCompose.mockReturnValue({
61
+ ok: true,
62
+ message: 'Docker Compose OK',
63
+ });
58
64
  const logs: string[] = [];
59
65
  jest.spyOn(console, 'log').mockImplementation((message?: string) => {
60
66
  logs.push(String(message));
@@ -68,11 +74,16 @@ describe('registerCheckCommand', () => {
68
74
  expect(logs.join('\n')).toContain('Hexabot project');
69
75
  expect(logs.join('\n')).toContain('Env file .env');
70
76
  expect(logs.join('\n')).toContain('Docker');
77
+ expect(logs.join('\n')).toContain('Docker Compose');
71
78
  expect(process.exitCode).toBeUndefined();
72
79
  });
73
80
 
74
81
  it('supports docker-only and no-docker modes', async () => {
75
82
  checkDocker.mockReturnValue({ ok: true, message: 'Docker OK' });
83
+ checkDockerCompose.mockReturnValue({
84
+ ok: true,
85
+ message: 'Docker Compose OK',
86
+ });
76
87
  checkNodeVersion.mockReturnValue({ ok: true, message: 'Node OK' });
77
88
 
78
89
  const dockerOnlyProgram = new Command();
@@ -87,20 +98,30 @@ describe('registerCheckCommand', () => {
87
98
  expect(checkNodeVersion).not.toHaveBeenCalled();
88
99
  expect(isHexabotProject).not.toHaveBeenCalled();
89
100
  expect(checkDocker).toHaveBeenCalled();
101
+ expect(checkDockerCompose).toHaveBeenCalled();
90
102
 
91
103
  jest.clearAllMocks();
92
104
  checkDocker.mockReturnValue({ ok: true, message: 'Docker OK' });
105
+ checkDockerCompose.mockReturnValue({
106
+ ok: true,
107
+ message: 'Docker Compose OK',
108
+ });
93
109
  checkNodeVersion.mockReturnValue({ ok: true, message: 'Node OK' });
94
110
  const noDockerProgram = new Command();
95
111
  registerCheckCommand(noDockerProgram);
96
112
  await noDockerProgram.parseAsync(['node', 'test', 'check', '--no-docker']);
97
113
  expect(checkDocker).not.toHaveBeenCalled();
114
+ expect(checkDockerCompose).not.toHaveBeenCalled();
98
115
  });
99
116
 
100
117
  it('sets process exit code when checks fail', async () => {
101
118
  checkNodeVersion.mockReturnValue({ ok: true, message: 'Node OK' });
102
119
  isHexabotProject.mockReturnValue(false);
103
120
  checkDocker.mockReturnValue({ ok: false, message: 'Docker missing' });
121
+ checkDockerCompose.mockReturnValue({
122
+ ok: false,
123
+ message: 'Docker Compose missing',
124
+ });
104
125
  const logs: string[] = [];
105
126
  jest.spyOn(console, 'log').mockImplementation((message?: string) => {
106
127
  logs.push(String(message));
@@ -9,7 +9,11 @@ import { Command } from 'commander';
9
9
 
10
10
  import { loadProjectConfig } from '../core/config.js';
11
11
  import { listEnvStatus } from '../core/env.js';
12
- import { checkDocker, checkNodeVersion } from '../core/prerequisites.js';
12
+ import {
13
+ checkDocker,
14
+ checkDockerCompose,
15
+ checkNodeVersion,
16
+ } from '../core/prerequisites.js';
13
17
  import { isHexabotProject } from '../core/project.js';
14
18
 
15
19
  interface CheckCommandOptions {
@@ -78,6 +82,16 @@ const runDiagnostics = (options: {
78
82
  ok: dockerResult.ok,
79
83
  message: dockerResult.message,
80
84
  });
85
+
86
+ const dockerComposeResult = checkDockerCompose({
87
+ fatal: false,
88
+ silent: true,
89
+ });
90
+ results.push({
91
+ label: 'Docker Compose',
92
+ ok: dockerComposeResult.ok,
93
+ message: dockerComposeResult.message,
94
+ });
81
95
  }
82
96
 
83
97
  const hasErrors = results.some((result) => !result.ok);
@@ -8,7 +8,7 @@ import { execSync } from 'child_process';
8
8
 
9
9
  import chalk from 'chalk';
10
10
 
11
- const REQUIRED_NODE_VERSION = '20.19.0';
11
+ const REQUIRED_NODE_VERSION = '24.17.0';
12
12
 
13
13
  export interface PrerequisiteOptions {
14
14
  docker?: boolean;
@@ -26,6 +26,7 @@ export const checkPrerequisites = (options: PrerequisiteOptions = {}) => {
26
26
  checkNodeVersion(options);
27
27
  if (options.docker) {
28
28
  checkDocker(options);
29
+ checkDockerCompose(options);
29
30
  }
30
31
  };
31
32
 
@@ -51,7 +52,7 @@ export const checkNodeVersion = (
51
52
  return { ok: false, message };
52
53
  } catch (error) {
53
54
  const message =
54
- "Node.js is not accessible or installed correctly. Install Node.js v20.19.0+ and ensure it's in your PATH.";
55
+ "Node.js is not accessible or installed correctly. Install Node.js v24.17.0+ and ensure it's in your PATH.";
55
56
 
56
57
  handleFailure(message, options, error);
57
58
 
@@ -79,6 +80,26 @@ export const checkDocker = (
79
80
  }
80
81
  };
81
82
 
83
+ export const checkDockerCompose = (
84
+ options: PrerequisiteOptions = {},
85
+ ): PrerequisiteCheckResult => {
86
+ try {
87
+ const composeVersion = execSync('docker compose version', {
88
+ encoding: 'utf-8',
89
+ }).trim();
90
+ const message = `Docker Compose is installed: ${composeVersion}`;
91
+ logSuccess(message, options);
92
+
93
+ return { ok: true, message };
94
+ } catch (error) {
95
+ const message =
96
+ 'Docker Compose (v2) is required for this command. Please install or update Docker Desktop / the Compose plugin.';
97
+ handleFailure(message, options, error);
98
+
99
+ return { ok: false, message, details: (error as Error).message };
100
+ }
101
+ };
102
+
82
103
  const normalizeVersion = (version: string) => {
83
104
  return version.startsWith('v') ? version.slice(1) : version;
84
105
  };
package/tsconfig.json CHANGED
@@ -11,5 +11,5 @@
11
11
  "skipLibCheck": true
12
12
  },
13
13
  "include": ["src"],
14
- "exclude": ["node_modules", "dist"]
14
+ "exclude": ["node_modules", "dist", "src/**/__tests__/**", "src/**/*.test.ts", "src/**/*.spec.ts"]
15
15
  }
@@ -1,97 +0,0 @@
1
- /*
2
- * Hexabot — Fair Core License (FCL-1.0-ALv2)
3
- * Copyright (c) 2025 Hexastack.
4
- * Full terms: see LICENSE.md.
5
- */
6
- import { jest } from '@jest/globals';
7
- import { Command } from 'commander';
8
- const loadProjectConfig = jest.fn();
9
- const listEnvStatus = jest.fn();
10
- const checkDocker = jest.fn();
11
- const checkNodeVersion = jest.fn();
12
- const isHexabotProject = jest.fn();
13
- jest.unstable_mockModule('../../core/config.js', () => ({
14
- loadProjectConfig,
15
- }));
16
- jest.unstable_mockModule('../../core/env.js', () => ({
17
- listEnvStatus,
18
- }));
19
- jest.unstable_mockModule('../../core/prerequisites.js', () => ({
20
- checkDocker,
21
- checkNodeVersion,
22
- }));
23
- jest.unstable_mockModule('../../core/project.js', () => ({
24
- isHexabotProject,
25
- }));
26
- let registerCheckCommand;
27
- beforeAll(async () => {
28
- ({ registerCheckCommand } = await import('../check.js'));
29
- });
30
- beforeEach(() => {
31
- jest.resetAllMocks();
32
- process.exitCode = undefined;
33
- });
34
- describe('registerCheckCommand', () => {
35
- it('runs full diagnostics by default', async () => {
36
- checkNodeVersion.mockReturnValue({ ok: true, message: 'Node OK' });
37
- isHexabotProject.mockReturnValue(true);
38
- loadProjectConfig.mockReturnValue({
39
- env: {
40
- local: '.env',
41
- },
42
- });
43
- listEnvStatus.mockReturnValue([
44
- { file: '.env', exists: true },
45
- { file: '.env.docker', exists: true },
46
- ]);
47
- checkDocker.mockReturnValue({ ok: true, message: 'Docker OK' });
48
- const logs = [];
49
- jest.spyOn(console, 'log').mockImplementation((message) => {
50
- logs.push(String(message));
51
- });
52
- const program = new Command();
53
- registerCheckCommand(program);
54
- await program.parseAsync(['node', 'test', 'check']);
55
- expect(logs.join('\n')).toContain('Node.js version');
56
- expect(logs.join('\n')).toContain('Hexabot project');
57
- expect(logs.join('\n')).toContain('Env file .env');
58
- expect(logs.join('\n')).toContain('Docker');
59
- expect(process.exitCode).toBeUndefined();
60
- });
61
- it('supports docker-only and no-docker modes', async () => {
62
- checkDocker.mockReturnValue({ ok: true, message: 'Docker OK' });
63
- checkNodeVersion.mockReturnValue({ ok: true, message: 'Node OK' });
64
- const dockerOnlyProgram = new Command();
65
- registerCheckCommand(dockerOnlyProgram);
66
- await dockerOnlyProgram.parseAsync([
67
- 'node',
68
- 'test',
69
- 'check',
70
- '--docker-only',
71
- ]);
72
- expect(checkNodeVersion).not.toHaveBeenCalled();
73
- expect(isHexabotProject).not.toHaveBeenCalled();
74
- expect(checkDocker).toHaveBeenCalled();
75
- jest.clearAllMocks();
76
- checkDocker.mockReturnValue({ ok: true, message: 'Docker OK' });
77
- checkNodeVersion.mockReturnValue({ ok: true, message: 'Node OK' });
78
- const noDockerProgram = new Command();
79
- registerCheckCommand(noDockerProgram);
80
- await noDockerProgram.parseAsync(['node', 'test', 'check', '--no-docker']);
81
- expect(checkDocker).not.toHaveBeenCalled();
82
- });
83
- it('sets process exit code when checks fail', async () => {
84
- checkNodeVersion.mockReturnValue({ ok: true, message: 'Node OK' });
85
- isHexabotProject.mockReturnValue(false);
86
- checkDocker.mockReturnValue({ ok: false, message: 'Docker missing' });
87
- const logs = [];
88
- jest.spyOn(console, 'log').mockImplementation((message) => {
89
- logs.push(String(message));
90
- });
91
- const program = new Command();
92
- registerCheckCommand(program);
93
- await program.parseAsync(['node', 'test', 'check', '--no-docker']);
94
- expect(logs.join('\n')).toContain('Hexabot project');
95
- expect(process.exitCode).toBe(1);
96
- });
97
- });
@@ -1,80 +0,0 @@
1
- /*
2
- * Hexabot — Fair Core License (FCL-1.0-ALv2)
3
- * Copyright (c) 2025 Hexastack.
4
- * Full terms: see LICENSE.md.
5
- */
6
- import { jest } from '@jest/globals';
7
- import { Command } from 'commander';
8
- const loadProjectConfig = jest.fn();
9
- const updateProjectConfig = jest.fn();
10
- const normalizePackageManager = jest.fn();
11
- const assertHexabotProject = jest.fn();
12
- jest.unstable_mockModule('../../core/config.js', () => ({
13
- loadProjectConfig,
14
- updateProjectConfig,
15
- }));
16
- jest.unstable_mockModule('../../core/package-manager.js', () => ({
17
- normalizePackageManager,
18
- }));
19
- jest.unstable_mockModule('../../core/project.js', () => ({
20
- assertHexabotProject,
21
- }));
22
- let registerConfigCommand;
23
- beforeAll(async () => {
24
- ({ registerConfigCommand } = await import('../config.js'));
25
- });
26
- beforeEach(() => {
27
- jest.resetAllMocks();
28
- loadProjectConfig.mockReturnValue({ packageManager: 'npm' });
29
- normalizePackageManager.mockImplementation((value) => typeof value === 'string' ? value.toLowerCase() : undefined);
30
- });
31
- describe('registerConfigCommand', () => {
32
- it('prints the current project config', async () => {
33
- const logs = [];
34
- jest.spyOn(console, 'log').mockImplementation((message) => {
35
- logs.push(String(message));
36
- });
37
- const program = new Command();
38
- registerConfigCommand(program);
39
- await program.parseAsync(['node', 'test', 'config', 'show']);
40
- expect(logs.some((line) => line.includes('"packageManager"'))).toBe(true);
41
- });
42
- it('updates configuration values with automatic parsing', async () => {
43
- const program = new Command();
44
- registerConfigCommand(program);
45
- await program.parseAsync([
46
- 'node',
47
- 'test',
48
- 'config',
49
- 'set',
50
- 'packageManager',
51
- 'PNPM',
52
- ]);
53
- expect(normalizePackageManager).toHaveBeenCalledWith('PNPM');
54
- expect(updateProjectConfig).toHaveBeenCalledWith(expect.any(String), {
55
- packageManager: 'pnpm',
56
- });
57
- await program.parseAsync([
58
- 'node',
59
- 'test',
60
- 'config',
61
- 'set',
62
- 'docker.defaultServices',
63
- 'api, postgres',
64
- ]);
65
- expect(updateProjectConfig).toHaveBeenCalledWith(expect.any(String), {
66
- docker: { defaultServices: ['api', 'postgres'] },
67
- });
68
- await program.parseAsync([
69
- 'node',
70
- 'test',
71
- 'config',
72
- 'set',
73
- 'limits.rate',
74
- '50',
75
- ]);
76
- expect(updateProjectConfig).toHaveBeenCalledWith(expect.any(String), {
77
- limits: { rate: 50 },
78
- });
79
- });
80
- });
@@ -1,210 +0,0 @@
1
- /*
2
- * Hexabot — Fair Core License (FCL-1.0-ALv2)
3
- * Copyright (c) 2025 Hexastack.
4
- * Full terms: see LICENSE.md.
5
- */
6
- import fs from 'fs';
7
- import * as os from 'os';
8
- import * as path from 'path';
9
- import { jest } from '@jest/globals';
10
- import { Command } from 'commander';
11
- const ensureProjectConfig = jest.fn();
12
- const loadProjectConfig = jest.fn();
13
- const bootstrapEnvFile = jest.fn();
14
- const upsertEnvVariables = jest.fn();
15
- const detectPackageManager = jest.fn();
16
- const installDependencies = jest.fn();
17
- const normalizePackageManager = jest.fn();
18
- const downloadAndExtractTemplate = jest.fn();
19
- const validateProjectName = jest.fn();
20
- const runDev = jest.fn();
21
- const input = jest.fn();
22
- const password = jest.fn();
23
- jest.unstable_mockModule('../../core/config.js', () => ({
24
- ensureProjectConfig,
25
- loadProjectConfig,
26
- }));
27
- jest.unstable_mockModule('../../core/env.js', () => ({
28
- bootstrapEnvFile,
29
- upsertEnvVariables,
30
- }));
31
- jest.unstable_mockModule('../../core/package-manager.js', () => ({
32
- detectPackageManager,
33
- installDependencies,
34
- normalizePackageManager,
35
- }));
36
- jest.unstable_mockModule('../../services/templates.js', () => ({
37
- downloadAndExtractTemplate,
38
- }));
39
- jest.unstable_mockModule('../../utils/validation.js', () => ({
40
- validateProjectName,
41
- }));
42
- jest.unstable_mockModule('../dev.js', () => ({
43
- runDev,
44
- }));
45
- jest.unstable_mockModule('@inquirer/prompts', () => ({
46
- input,
47
- password,
48
- }));
49
- let registerCreateCommand;
50
- const initialCwd = process.cwd();
51
- const initialStdinTTY = Object.getOwnPropertyDescriptor(process.stdin, 'isTTY');
52
- const initialStdoutTTY = Object.getOwnPropertyDescriptor(process.stdout, 'isTTY');
53
- let tempDir;
54
- let exitSpy;
55
- const restoreTTY = () => {
56
- if (initialStdinTTY) {
57
- Object.defineProperty(process.stdin, 'isTTY', initialStdinTTY);
58
- }
59
- else {
60
- delete process.stdin.isTTY;
61
- }
62
- if (initialStdoutTTY) {
63
- Object.defineProperty(process.stdout, 'isTTY', initialStdoutTTY);
64
- }
65
- else {
66
- delete process.stdout.isTTY;
67
- }
68
- };
69
- const setTTY = (enabled) => {
70
- Object.defineProperty(process.stdin, 'isTTY', {
71
- configurable: true,
72
- value: enabled,
73
- });
74
- Object.defineProperty(process.stdout, 'isTTY', {
75
- configurable: true,
76
- value: enabled,
77
- });
78
- };
79
- beforeAll(async () => {
80
- ({ registerCreateCommand } = await import('../create.js'));
81
- });
82
- beforeEach(() => {
83
- jest.resetAllMocks();
84
- tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'hexabot-create-'));
85
- process.chdir(tempDir);
86
- setTTY(true);
87
- validateProjectName.mockReturnValue(true);
88
- detectPackageManager.mockReturnValue('pnpm');
89
- bootstrapEnvFile.mockReturnValue(true);
90
- normalizePackageManager.mockImplementation((value) => {
91
- return typeof value === 'string' ? value.toLowerCase() : undefined;
92
- });
93
- loadProjectConfig.mockReturnValue({
94
- packageManager: 'pnpm',
95
- env: {
96
- local: '.env',
97
- localExample: '.env.example',
98
- docker: '.env.docker',
99
- dockerExample: '.env.docker.example',
100
- },
101
- });
102
- globalThis.fetch = jest.fn(async () => ({
103
- ok: true,
104
- json: async () => ({ tag_name: 'v1.0.0' }),
105
- }));
106
- exitSpy = jest.spyOn(process, 'exit').mockImplementation((code) => {
107
- throw new Error(`process.exit:${code ?? ''}`);
108
- });
109
- });
110
- afterEach(() => {
111
- process.chdir(initialCwd);
112
- fs.rmSync(tempDir, { recursive: true, force: true });
113
- restoreTTY();
114
- jest.restoreAllMocks();
115
- });
116
- describe('registerCreateCommand', () => {
117
- it('prompts admin credentials and persists create env values', async () => {
118
- const logSpy = jest.spyOn(console, 'log').mockImplementation(() => { });
119
- input
120
- .mockResolvedValueOnce('Anis')
121
- .mockResolvedValueOnce('Bot')
122
- .mockResolvedValueOnce('anis@example.com');
123
- password
124
- .mockResolvedValueOnce('Admin#123')
125
- .mockResolvedValueOnce('Admin#123');
126
- const program = new Command();
127
- registerCreateCommand(program);
128
- await program.parseAsync([
129
- 'node',
130
- 'test',
131
- 'create',
132
- 'anisbot',
133
- '--template',
134
- 'marrouchi/hexabot-v3-template',
135
- ]);
136
- const [templateUrl, projectPath] = downloadAndExtractTemplate.mock
137
- .calls[0];
138
- expect(templateUrl).toBe('https://github.com/marrouchi/hexabot-v3-template/archive/refs/tags/v1.0.0.zip');
139
- expect(projectPath.endsWith(`${path.sep}anisbot`)).toBe(true);
140
- expect(bootstrapEnvFile).toHaveBeenCalledWith(projectPath, '.env.example', '.env', { quiet: true });
141
- expect(bootstrapEnvFile).toHaveBeenCalledWith(projectPath, '.env.docker.example', '.env.docker', { quiet: true });
142
- expect(upsertEnvVariables).toHaveBeenCalledWith(projectPath, '.env', {
143
- SEED_ADMIN_FIRST_NAME: 'Anis',
144
- SEED_ADMIN_LAST_NAME: 'Bot',
145
- SEED_ADMIN_EMAIL: 'anis@example.com',
146
- SEED_ADMIN_PASSWORD: 'Admin#123',
147
- });
148
- expect(upsertEnvVariables).toHaveBeenCalledWith(projectPath, '.env.docker', {
149
- SEED_ADMIN_FIRST_NAME: 'Anis',
150
- SEED_ADMIN_LAST_NAME: 'Bot',
151
- SEED_ADMIN_EMAIL: 'anis@example.com',
152
- SEED_ADMIN_PASSWORD: 'Admin#123',
153
- COMPOSE_PROJECT_NAME: 'anisbot',
154
- });
155
- expect(exitSpy).not.toHaveBeenCalled();
156
- expect(input).toHaveBeenCalledTimes(3);
157
- expect(input).toHaveBeenNthCalledWith(1, expect.objectContaining({ message: 'First name:' }));
158
- expect(input).toHaveBeenNthCalledWith(2, expect.objectContaining({ message: 'Last name:' }));
159
- expect(input).toHaveBeenNthCalledWith(3, expect.objectContaining({ message: 'Email:' }));
160
- expect(password).toHaveBeenCalledTimes(2);
161
- expect(password).toHaveBeenNthCalledWith(1, expect.objectContaining({ message: 'Password:' }));
162
- expect(password).toHaveBeenNthCalledWith(2, expect.objectContaining({ message: 'Confirm password:' }));
163
- expect(bootstrapEnvFile).toHaveBeenCalledTimes(2);
164
- expect(upsertEnvVariables).toHaveBeenCalledTimes(2);
165
- const output = logSpy.mock.calls.flat().join('\n');
166
- expect(output).toContain('Admin account');
167
- expect(output).toContain('These details will be used to create the first admin user during setup.');
168
- expect(output).toContain('You can update them later from the generated environment file before starting the app.');
169
- expect(output).toContain('Start local dev with SQLite:');
170
- expect(output).toContain('hexabot dev');
171
- expect(output).toContain('Or start dev with Docker and Postgres:');
172
- expect(output).toContain('hexabot dev --docker --services postgres');
173
- expect(output).toContain('Optional: install Hexabot AI coding skills');
174
- expect(output).toContain('Use these with AI coding agents to generate actions and workflows faster:');
175
- expect(output).toContain('After starting Hexabot, you can generate an MCP token from your profile and connect your favorite AI coding agent.');
176
- });
177
- it('skips Docker env values when the Docker env file is unavailable', async () => {
178
- bootstrapEnvFile.mockImplementation((_projectRoot, _exampleFile, targetFile) => targetFile === '.env');
179
- input
180
- .mockResolvedValueOnce('Anis')
181
- .mockResolvedValueOnce('Bot')
182
- .mockResolvedValueOnce('anis@example.com');
183
- password
184
- .mockResolvedValueOnce('Admin#123')
185
- .mockResolvedValueOnce('Admin#123');
186
- const program = new Command();
187
- registerCreateCommand(program);
188
- await program.parseAsync(['node', 'test', 'create', 'anisbot']);
189
- const [, projectPath] = downloadAndExtractTemplate.mock.calls[0];
190
- expect(bootstrapEnvFile).toHaveBeenCalledWith(projectPath, '.env.docker.example', '.env.docker', { quiet: true });
191
- expect(upsertEnvVariables).toHaveBeenCalledTimes(1);
192
- expect(upsertEnvVariables).toHaveBeenCalledWith(projectPath, '.env', {
193
- SEED_ADMIN_FIRST_NAME: 'Anis',
194
- SEED_ADMIN_LAST_NAME: 'Bot',
195
- SEED_ADMIN_EMAIL: 'anis@example.com',
196
- SEED_ADMIN_PASSWORD: 'Admin#123',
197
- });
198
- });
199
- it('fails cleanly when create runs in a non-interactive terminal', async () => {
200
- setTTY(false);
201
- const errorSpy = jest.spyOn(console, 'error').mockImplementation(() => { });
202
- const program = new Command();
203
- registerCreateCommand(program);
204
- await expect(program.parseAsync(['node', 'test', 'create', 'anisbot'])).rejects.toThrow('process.exit:1');
205
- expect(errorSpy).toHaveBeenCalled();
206
- expect(input).not.toHaveBeenCalled();
207
- expect(password).not.toHaveBeenCalled();
208
- expect(upsertEnvVariables).not.toHaveBeenCalled();
209
- });
210
- });