tools-cc 1.0.4 → 1.0.6

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,37 +0,0 @@
1
- import { describe, it, expect, beforeEach, afterEach } from 'vitest';
2
- import fs from 'fs-extra';
3
- import path from 'path';
4
- import { loadGlobalConfig, saveGlobalConfig } from '../../src/core/config';
5
-
6
- describe('Config Module', () => {
7
- const testConfigDir = path.join(__dirname, '../fixtures/.tools-cc');
8
-
9
- beforeEach(async () => {
10
- await fs.ensureDir(testConfigDir);
11
- });
12
-
13
- afterEach(async () => {
14
- await fs.remove(testConfigDir);
15
- });
16
-
17
- it('should create default config if not exists', async () => {
18
- const config = await loadGlobalConfig(testConfigDir);
19
- expect(config.sourcesDir).toBeDefined();
20
- expect(config.sources).toEqual({});
21
- });
22
-
23
- it('should save and load config correctly', async () => {
24
- const testConfig = {
25
- sourcesDir: '/test/sources',
26
- sources: {
27
- 'test-source': { type: 'git' as const, url: 'https://github.com/test/repo.git' }
28
- }
29
- };
30
-
31
- await saveGlobalConfig(testConfig, testConfigDir);
32
- const loaded = await loadGlobalConfig(testConfigDir);
33
-
34
- expect(loaded.sourcesDir).toBe('/test/sources');
35
- expect(loaded.sources['test-source'].type).toBe('git');
36
- });
37
- });
@@ -1,37 +0,0 @@
1
- import { describe, it, expect, beforeEach, afterEach } from 'vitest';
2
- import fs from 'fs-extra';
3
- import path from 'path';
4
- import { loadManifest, scanSource } from '../../src/core/manifest';
5
-
6
- describe('Manifest Module', () => {
7
- const testSourceDir = path.join(__dirname, '../fixtures/test-source');
8
-
9
- beforeEach(async () => {
10
- await fs.ensureDir(path.join(testSourceDir, 'skills', 'test-skill'));
11
- await fs.ensureDir(path.join(testSourceDir, 'commands'));
12
- await fs.ensureDir(path.join(testSourceDir, 'agents'));
13
- });
14
-
15
- afterEach(async () => {
16
- await fs.remove(testSourceDir);
17
- });
18
-
19
- it('should scan source directory without manifest', async () => {
20
- const manifest = await scanSource(testSourceDir);
21
- expect(manifest.name).toBe(path.basename(testSourceDir));
22
- expect(manifest.skills).toContain('test-skill');
23
- });
24
-
25
- it('should load existing manifest', async () => {
26
- const manifestPath = path.join(testSourceDir, 'manifest.json');
27
- await fs.writeJson(manifestPath, {
28
- name: 'custom-name',
29
- version: '2.0.0',
30
- skills: ['skill1']
31
- });
32
-
33
- const manifest = await loadManifest(testSourceDir);
34
- expect(manifest.name).toBe('custom-name');
35
- expect(manifest.version).toBe('2.0.0');
36
- });
37
- });
@@ -1,50 +0,0 @@
1
- import { describe, it, expect, beforeEach, afterEach } from 'vitest';
2
- import fs from 'fs-extra';
3
- import path from 'path';
4
- import { initProject, useSource, unuseSource, listUsedSources } from '../../src/core/project';
5
-
6
- describe('Project Module', () => {
7
- const testProjectDir = path.join(__dirname, '../fixtures/test-project');
8
- const testSourceDir = path.join(__dirname, '../fixtures/test-source');
9
-
10
- beforeEach(async () => {
11
- await fs.ensureDir(testProjectDir);
12
- await fs.ensureDir(path.join(testSourceDir, 'skills', 'test-skill'));
13
- });
14
-
15
- afterEach(async () => {
16
- await fs.remove(testProjectDir);
17
- await fs.remove(testSourceDir);
18
- });
19
-
20
- it('should initialize project with .toolscc directory', async () => {
21
- await initProject(testProjectDir);
22
- expect(await fs.pathExists(path.join(testProjectDir, '.toolscc'))).toBe(true);
23
- expect(await fs.pathExists(path.join(testProjectDir, 'tools-cc.json'))).toBe(true);
24
- });
25
-
26
- it('should use source and copy components', async () => {
27
- await initProject(testProjectDir);
28
- await useSource('test-source', testSourceDir, testProjectDir);
29
-
30
- // skills should be flattened with prefix
31
- expect(await fs.pathExists(path.join(testProjectDir, '.toolscc', 'skills', 'test-source-test-skill'))).toBe(true);
32
- });
33
-
34
- it('should unuse source and remove components', async () => {
35
- await initProject(testProjectDir);
36
- await useSource('test-source', testSourceDir, testProjectDir);
37
- await unuseSource('test-source', testProjectDir);
38
-
39
- const config = await fs.readJson(path.join(testProjectDir, 'tools-cc.json'));
40
- expect(config.sources).not.toContain('test-source');
41
- });
42
-
43
- it('should list used sources', async () => {
44
- await initProject(testProjectDir);
45
- await useSource('test-source', testSourceDir, testProjectDir);
46
-
47
- const sources = await listUsedSources(testProjectDir);
48
- expect(sources).toContain('test-source');
49
- });
50
- });
@@ -1,75 +0,0 @@
1
- import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest';
2
- import fs from 'fs-extra';
3
- import path from 'path';
4
- import { addSource, listSources, removeSource, updateSource, getSourcePath } from '../../src/core/source';
5
-
6
- describe('Source Module', () => {
7
- const testConfigDir = path.join(__dirname, '../fixtures/.tools-cc-test');
8
- const testSourcesDir = path.join(__dirname, '../fixtures/sources');
9
-
10
- beforeEach(async () => {
11
- await fs.ensureDir(testConfigDir);
12
- await fs.ensureDir(testSourcesDir);
13
- });
14
-
15
- afterEach(async () => {
16
- await fs.remove(testConfigDir);
17
- await fs.remove(testSourcesDir);
18
- });
19
-
20
- it('should add a local source', async () => {
21
- const result = await addSource('test-local', testSourcesDir, testConfigDir);
22
- expect(result.type).toBe('local');
23
- expect(result.path).toBe(testSourcesDir);
24
- });
25
-
26
- it('should list sources', async () => {
27
- await addSource('test-1', testSourcesDir, testConfigDir);
28
- const sources = await listSources(testConfigDir);
29
- expect(sources).toHaveProperty('test-1');
30
- });
31
-
32
- it('should remove a source', async () => {
33
- await addSource('test-remove', testSourcesDir, testConfigDir);
34
- await removeSource('test-remove', testConfigDir);
35
- const sources = await listSources(testConfigDir);
36
- expect(sources).not.toHaveProperty('test-remove');
37
- });
38
-
39
- describe('updateSource', () => {
40
- it('should throw error when source not found', async () => {
41
- await expect(updateSource('non-existent', testConfigDir)).rejects.toThrow('Source not found: non-existent');
42
- });
43
-
44
- it('should skip update for local source', async () => {
45
- await addSource('local-source', testSourcesDir, testConfigDir);
46
- const consoleSpy = vi.spyOn(console, 'log');
47
- await updateSource('local-source', testConfigDir);
48
- expect(consoleSpy).toHaveBeenCalledWith(expect.stringContaining('is local, no update needed'));
49
- consoleSpy.mockRestore();
50
- });
51
- });
52
-
53
- describe('getSourcePath', () => {
54
- it('should throw error when source not found', async () => {
55
- await expect(getSourcePath('non-existent', testConfigDir)).rejects.toThrow('Source not found: non-existent');
56
- });
57
-
58
- it('should return path for local source', async () => {
59
- await addSource('local-path-test', testSourcesDir, testConfigDir);
60
- const result = await getSourcePath('local-path-test', testConfigDir);
61
- expect(result).toBe(testSourcesDir);
62
- });
63
- });
64
-
65
- describe('error handling', () => {
66
- it('should throw error when adding non-existent local path', async () => {
67
- const nonExistentPath = path.join(__dirname, 'non-existent-path');
68
- await expect(addSource('invalid', nonExistentPath, testConfigDir)).rejects.toThrow('Path does not exist');
69
- });
70
-
71
- it('should throw error when removing non-existent source', async () => {
72
- await expect(removeSource('non-existent', testConfigDir)).rejects.toThrow('Source not found: non-existent');
73
- });
74
- });
75
- });
@@ -1,39 +0,0 @@
1
- import { describe, it, expect, beforeEach, afterEach } from 'vitest';
2
- import fs from 'fs-extra';
3
- import path from 'path';
4
- import { createSymlink, removeSymlink, isSymlink } from '../../src/core/symlink';
5
-
6
- describe('Symlink Module', () => {
7
- const testDir = path.join(__dirname, '../fixtures/symlink-test');
8
- const targetDir = path.join(testDir, 'target');
9
- const linkPath = path.join(testDir, 'link');
10
-
11
- beforeEach(async () => {
12
- await fs.ensureDir(targetDir);
13
- await fs.writeJson(path.join(targetDir, 'test.json'), { test: true });
14
- });
15
-
16
- afterEach(async () => {
17
- await fs.remove(testDir);
18
- });
19
-
20
- it('should create symlink', async () => {
21
- await createSymlink(targetDir, linkPath);
22
- expect(await isSymlink(linkPath)).toBe(true);
23
- });
24
-
25
- it('should remove symlink', async () => {
26
- await createSymlink(targetDir, linkPath);
27
- await removeSymlink(linkPath);
28
- expect(await fs.pathExists(linkPath)).toBe(false);
29
- expect(await fs.pathExists(targetDir)).toBe(true);
30
- });
31
-
32
- it('should replace existing directory with symlink', async () => {
33
- await fs.ensureDir(linkPath);
34
- await fs.writeFile(path.join(linkPath, 'old.txt'), 'old');
35
-
36
- await createSymlink(targetDir, linkPath, true);
37
- expect(await isSymlink(linkPath)).toBe(true);
38
- });
39
- });