mirror of
https://github.com/tiennm99/ccs.git
synced 2026-10-16 10:15:10 +00:00
refactor: extract plugin path normalizer
This commit is contained in:
1 parent
7569c6ce2d
commit
3330229686
3 files changed
+121
-80
No files matched your search
@@ -2,9 +2,13 @@ import { afterEach, beforeEach, describe, expect, it, mock, spyOn } from 'bun:te
|
||||
import * as fs from 'fs';
|
||||
import * as os from 'os';
|
||||
import * as path from 'path';
|
||||
import SharedManager, {
|
||||
import {
|
||||
normalizePluginMetadataContent,
|
||||
normalizePluginMetadataPathString,
|
||||
} from '../../src/management/plugin-path-normalizer';
|
||||
import SharedManager, {
|
||||
normalizePluginMetadataContent as normalizeSharedManagerPluginMetadataContent,
|
||||
normalizePluginMetadataPathString as normalizeSharedManagerPluginMetadataPathString,
|
||||
} from '../../src/management/shared-manager';
|
||||
|
||||
describe('SharedManager', () => {
|
||||
@@ -144,6 +148,12 @@ describe('SharedManager', () => {
|
||||
expect(normalizePluginMetadataPathString(input, targetConfigDir)).toBe(input);
|
||||
});
|
||||
|
||||
it('preserves original JSON content when no plugin path changes are needed', () => {
|
||||
const original = JSON.stringify({ plugins: { 'plugin-a': { enabled: true } } }, null, 4);
|
||||
|
||||
expect(normalizePluginMetadataContent(original, instanceDir('work'))).toBe(original);
|
||||
});
|
||||
|
||||
it('handles Windows path separators', () => {
|
||||
const targetConfigDir = 'C:\\Users\\user\\.claude';
|
||||
const input = 'C:\\Users\\user\\.ccs\\instances\\work\\plugins\\marketplaces\\official';
|
||||
@@ -152,6 +162,27 @@ describe('SharedManager', () => {
|
||||
'C:\\Users\\user\\.claude\\plugins\\marketplaces\\official'
|
||||
);
|
||||
});
|
||||
|
||||
it('uses the current home directory when target config dir is omitted', () => {
|
||||
const input = path.join(tempRoot, '.ccs', 'shared', 'plugins', 'cache', 'plugin-a');
|
||||
|
||||
expect(normalizePluginMetadataPathString(input)).toBe(
|
||||
path.join(tempRoot, '.claude', 'plugins', 'cache', 'plugin-a')
|
||||
);
|
||||
});
|
||||
|
||||
it('keeps the legacy shared-manager helper export compatible', () => {
|
||||
const targetConfigDir = instanceDir('work');
|
||||
const input = path.join(tempRoot, '.ccs', 'shared', 'plugins', 'cache', 'plugin-a');
|
||||
const content = JSON.stringify({ installPath: input }, null, 2);
|
||||
|
||||
expect(normalizeSharedManagerPluginMetadataPathString(input, targetConfigDir)).toBe(
|
||||
normalizePluginMetadataPathString(input, targetConfigDir)
|
||||
);
|
||||
expect(normalizeSharedManagerPluginMetadataContent(content, targetConfigDir)).toBe(
|
||||
normalizePluginMetadataContent(content, targetConfigDir)
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('shared symlink lifecycle', () => {
|
||||
|
||||
Reference in new issue
Block a user