@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.
@@ -1,91 +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 { bootstrapEnvFile, listEnvStatus, resolveEnvExample, upsertEnvVariables, } from '../env.js';
11
- describe('env helpers', () => {
12
- let tempDir;
13
- beforeEach(() => {
14
- tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'hexabot-env-'));
15
- });
16
- afterEach(() => {
17
- fs.rmSync(tempDir, { recursive: true, force: true });
18
- jest.restoreAllMocks();
19
- });
20
- it('copies the example env file when the target is missing', () => {
21
- const example = '.env.example';
22
- const target = '.env';
23
- fs.writeFileSync(path.join(tempDir, example), 'KEY=value');
24
- const result = bootstrapEnvFile(tempDir, example, target);
25
- expect(result).toBe(true);
26
- expect(fs.readFileSync(path.join(tempDir, target), 'utf-8')).toBe('KEY=value');
27
- });
28
- it('skips copying when the target exists unless forced', () => {
29
- const example = '.env.example';
30
- const target = '.env';
31
- fs.writeFileSync(path.join(tempDir, example), 'NEW=value');
32
- fs.writeFileSync(path.join(tempDir, target), 'OLD=value');
33
- const logSpy = jest.spyOn(console, 'log').mockImplementation(() => { });
34
- const skipped = bootstrapEnvFile(tempDir, example, target, {
35
- quiet: false,
36
- });
37
- expect(skipped).toBe(false);
38
- expect(fs.readFileSync(path.join(tempDir, target), 'utf-8')).toBe('OLD=value');
39
- expect(logSpy).toHaveBeenCalled();
40
- const forced = bootstrapEnvFile(tempDir, example, target, { force: true });
41
- expect(forced).toBe(true);
42
- expect(fs.readFileSync(path.join(tempDir, target), 'utf-8')).toBe('NEW=value');
43
- });
44
- it('lists env file statuses using the provided config', () => {
45
- const config = {
46
- env: {
47
- local: '.env',
48
- localExample: '.env.example',
49
- docker: '.env.docker',
50
- dockerExample: '.env.docker.example',
51
- },
52
- };
53
- fs.writeFileSync(path.join(tempDir, '.env.example'), '');
54
- fs.writeFileSync(path.join(tempDir, '.env'), '');
55
- const statuses = listEnvStatus(tempDir, config);
56
- expect(statuses).toEqual([
57
- expect.objectContaining({ file: '.env.example', exists: true }),
58
- expect.objectContaining({ file: '.env', exists: true }),
59
- expect.objectContaining({ file: '.env.docker.example', exists: false }),
60
- expect.objectContaining({ file: '.env.docker', exists: false }),
61
- ]);
62
- });
63
- it('resolves env example files relative to the project root', () => {
64
- const envFile = '.env.local';
65
- const defaultExample = '.env.example';
66
- const examplePath = path.join(tempDir, `${envFile}.example`);
67
- fs.writeFileSync(examplePath, '');
68
- expect(resolveEnvExample(tempDir, envFile, defaultExample)).toBe(`${envFile}.example`);
69
- expect(resolveEnvExample(tempDir, '.missing', defaultExample)).toBe(defaultExample);
70
- });
71
- it('upserts env variables without duplicating existing keys', () => {
72
- fs.writeFileSync(path.join(tempDir, '.env'), [
73
- 'PORT=3000',
74
- 'SEED_ADMIN_EMAIL=old@example.com',
75
- 'SEED_ADMIN_EMAIL=legacy@example.com',
76
- ].join('\n'));
77
- upsertEnvVariables(tempDir, '.env', {
78
- SEED_ADMIN_EMAIL: 'new@example.com',
79
- SEED_ADMIN_PASSWORD: 'P@ss "word"',
80
- });
81
- const nextEnv = fs.readFileSync(path.join(tempDir, '.env'), 'utf-8');
82
- const emailMatches = nextEnv.match(/^SEED_ADMIN_EMAIL=/gm) || [];
83
- expect(emailMatches).toHaveLength(1);
84
- expect(nextEnv).toContain('SEED_ADMIN_EMAIL=new@example.com');
85
- expect(nextEnv).toContain('SEED_ADMIN_PASSWORD="P@ss \\"word\\""');
86
- expect(nextEnv.endsWith('\n')).toBe(true);
87
- });
88
- it('throws when attempting to upsert a missing env file', () => {
89
- expect(() => upsertEnvVariables(tempDir, '.missing', { KEY: 'value' })).toThrow('Env file ".missing" is missing.');
90
- });
91
- });
@@ -1,95 +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
- const readPackageJson = jest.fn();
11
- const execSync = jest.fn();
12
- jest.unstable_mockModule('../project.js', () => ({
13
- readPackageJson,
14
- }));
15
- jest.unstable_mockModule('child_process', () => ({
16
- execSync,
17
- }));
18
- let normalizePackageManager;
19
- let detectPackageManager;
20
- let runPackageScript;
21
- let installDependencies;
22
- beforeAll(async () => {
23
- ({
24
- normalizePackageManager,
25
- detectPackageManager,
26
- runPackageScript,
27
- installDependencies,
28
- } = await import('../package-manager.js'));
29
- });
30
- afterEach(() => {
31
- jest.resetAllMocks();
32
- });
33
- describe('normalizePackageManager', () => {
34
- it('returns normalized package manager names', () => {
35
- expect(normalizePackageManager('PNPM')).toBe('pnpm');
36
- expect(normalizePackageManager(undefined)).toBeUndefined();
37
- });
38
- it('exits when the package manager is unsupported', () => {
39
- const exitSpy = jest.spyOn(process, 'exit').mockImplementation((() => {
40
- throw new Error('exit:1');
41
- }));
42
- jest.spyOn(console, 'error').mockImplementation(() => { });
43
- expect(() => normalizePackageManager('foo')).toThrow('exit:1');
44
- expect(exitSpy).toHaveBeenCalledWith(1);
45
- });
46
- });
47
- describe('detectPackageManager', () => {
48
- let tempDir;
49
- beforeEach(() => {
50
- tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'hexabot-pm-'));
51
- });
52
- afterEach(() => {
53
- fs.rmSync(tempDir, { recursive: true, force: true });
54
- });
55
- it('detects the package manager based on lockfiles', () => {
56
- fs.writeFileSync(path.join(tempDir, 'pnpm-lock.yaml'), '');
57
- expect(detectPackageManager(tempDir)).toBe('pnpm');
58
- });
59
- it('falls back to npm when no lockfiles are found', () => {
60
- expect(detectPackageManager(tempDir)).toBe('npm');
61
- });
62
- });
63
- describe('installDependencies & runPackageScript', () => {
64
- const projectRoot = '/tmp/project';
65
- beforeEach(() => {
66
- readPackageJson.mockReturnValue({
67
- scripts: {
68
- build: 'tsc',
69
- },
70
- });
71
- });
72
- it('runs installation commands for the chosen package manager', () => {
73
- installDependencies('yarn', projectRoot);
74
- expect(execSync).toHaveBeenCalledWith('yarn install', {
75
- cwd: projectRoot,
76
- stdio: 'inherit',
77
- });
78
- });
79
- it('runs package scripts after ensuring the script exists', () => {
80
- runPackageScript('pnpm', 'build', projectRoot, ['--watch']);
81
- expect(execSync).toHaveBeenCalledWith('pnpm run build -- --watch', {
82
- cwd: projectRoot,
83
- stdio: 'inherit',
84
- });
85
- });
86
- it('exits when the script is missing from package.json', () => {
87
- readPackageJson.mockReturnValue({ scripts: {} });
88
- const exitSpy = jest.spyOn(process, 'exit').mockImplementation((() => {
89
- throw new Error('exit:1');
90
- }));
91
- jest.spyOn(console, 'error').mockImplementation(() => { });
92
- expect(() => runPackageScript('npm', 'dev', projectRoot)).toThrow('exit:1');
93
- expect(exitSpy).toHaveBeenCalledWith(1);
94
- });
95
- });
@@ -1,49 +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 { ensureDockerFolder, resolveDockerFolder } from '../project.js';
11
- describe('project helpers', () => {
12
- let tempDirs = [];
13
- afterEach(() => {
14
- jest.restoreAllMocks();
15
- tempDirs.forEach((dir) => fs.rmSync(dir, {
16
- recursive: true,
17
- force: true,
18
- }));
19
- tempDirs = [];
20
- });
21
- const createTempDir = (withDockerFolder) => {
22
- const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'hexabot-project-'));
23
- tempDirs.push(dir);
24
- if (withDockerFolder) {
25
- fs.mkdirSync(path.join(dir, 'docker'));
26
- }
27
- return dir;
28
- };
29
- it('resolves the docker folder relative to the working directory', () => {
30
- jest.spyOn(process, 'cwd').mockReturnValue('/workspace/hexabot');
31
- expect(resolveDockerFolder()).toBe(path.resolve('/workspace/hexabot', './docker'));
32
- });
33
- it('returns the folder path when it exists', () => {
34
- const cwd = createTempDir(true);
35
- jest.spyOn(process, 'cwd').mockReturnValue(cwd);
36
- expect(ensureDockerFolder()).toBe(path.resolve(cwd, './docker'));
37
- });
38
- it('exits the process when the docker folder is missing', () => {
39
- const cwd = createTempDir(false);
40
- jest.spyOn(process, 'cwd').mockReturnValue(cwd);
41
- jest.spyOn(console, 'error').mockImplementation(() => { });
42
- jest.spyOn(console, 'log').mockImplementation(() => { });
43
- const exitSpy = jest.spyOn(process, 'exit').mockImplementation(((code) => {
44
- throw new Error(`exit:${code}`);
45
- }));
46
- expect(() => ensureDockerFolder()).toThrow('exit:1');
47
- expect(exitSpy).toHaveBeenCalledWith(1);
48
- });
49
- });
@@ -1,18 +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 { parseServices } from '../services.js';
7
- describe('parseServices', () => {
8
- it('splits and trims comma separated values', () => {
9
- expect(parseServices('api, postgres,worker')).toEqual([
10
- 'api',
11
- 'postgres',
12
- 'worker',
13
- ]);
14
- });
15
- it('filters out empty service values', () => {
16
- expect(parseServices(' , , ')).toEqual([]);
17
- });
18
- });
@@ -1,17 +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 { validateProjectName } from '../validation.js';
7
- describe('validateProjectName', () => {
8
- it('accepts lowercase alphanumeric names with dashes', () => {
9
- expect(validateProjectName('hexabot-bot01')).toBe(true);
10
- });
11
- it('rejects names that do not start with a letter', () => {
12
- expect(validateProjectName('1hexabot')).toBe(false);
13
- });
14
- it('rejects names containing uppercase characters or spaces', () => {
15
- expect(validateProjectName('Hexabot Agent')).toBe(false);
16
- });
17
- });
@@ -1,27 +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 path from 'path';
8
- import { jest } from '@jest/globals';
9
- import { getCliVersion } from '../version.js';
10
- describe('getCliVersion', () => {
11
- afterEach(() => {
12
- jest.restoreAllMocks();
13
- });
14
- it('returns the version from the package.json file', () => {
15
- const packageJsonPath = path.resolve(process.cwd(), 'package.json');
16
- const { version } = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));
17
- expect(getCliVersion()).toBe(version);
18
- });
19
- it('falls back to the default version when package.json cannot be read', () => {
20
- const errorSpy = jest.spyOn(console, 'error').mockImplementation(() => { });
21
- const failingReader = () => {
22
- throw new Error('file error');
23
- };
24
- expect(getCliVersion(failingReader)).toBe('3.0.0');
25
- expect(errorSpy).toHaveBeenCalled();
26
- });
27
- });