update semantics and terminology from 'brand rules' to 'rules profiles'
This commit is contained in:
@@ -1,67 +1,204 @@
|
||||
import {
|
||||
BRAND_PROFILES,
|
||||
BRAND_NAMES,
|
||||
isValidBrand,
|
||||
getBrandProfile
|
||||
isValidProfile,
|
||||
getRulesProfile
|
||||
} from '../../src/utils/rule-transformer.js';
|
||||
import { BRAND_RULE_OPTIONS } from '../../src/constants/rules.js';
|
||||
import { RULES_PROFILES } from '../../src/constants/profiles.js';
|
||||
|
||||
describe('Rule Transformer - General', () => {
|
||||
describe('Brand Configuration Validation', () => {
|
||||
it('should have BRAND_PROFILES that match BRAND_RULE_OPTIONS', () => {
|
||||
// Ensure BRAND_PROFILES keys match the authoritative list from constants/rules.js
|
||||
const profileKeys = Object.keys(BRAND_PROFILES).sort();
|
||||
const ruleOptions = [...BRAND_RULE_OPTIONS].sort();
|
||||
describe('Profile Configuration Validation', () => {
|
||||
it('should use RULES_PROFILES as the single source of truth', () => {
|
||||
// Ensure RULES_PROFILES is properly defined and contains expected profiles
|
||||
expect(Array.isArray(RULES_PROFILES)).toBe(true);
|
||||
expect(RULES_PROFILES.length).toBeGreaterThan(0);
|
||||
|
||||
expect(profileKeys).toEqual(ruleOptions);
|
||||
// Verify expected profiles are present
|
||||
const expectedProfiles = ['cline', 'cursor', 'roo', 'windsurf'];
|
||||
expectedProfiles.forEach(profile => {
|
||||
expect(RULES_PROFILES).toContain(profile);
|
||||
});
|
||||
});
|
||||
|
||||
it('should have BRAND_NAMES derived from BRAND_PROFILES', () => {
|
||||
const expectedNames = Object.keys(BRAND_PROFILES);
|
||||
expect(BRAND_NAMES).toEqual(expectedNames);
|
||||
});
|
||||
|
||||
it('should validate brands correctly with isValidBrand', () => {
|
||||
// Test valid brands
|
||||
BRAND_RULE_OPTIONS.forEach(brand => {
|
||||
expect(isValidBrand(brand)).toBe(true);
|
||||
it('should validate profiles correctly with isValidProfile', () => {
|
||||
// Test valid profiles
|
||||
RULES_PROFILES.forEach((profile) => {
|
||||
expect(isValidProfile(profile)).toBe(true);
|
||||
});
|
||||
|
||||
// Test invalid brands
|
||||
expect(isValidBrand('invalid')).toBe(false);
|
||||
expect(isValidBrand('vscode')).toBe(false);
|
||||
expect(isValidBrand('')).toBe(false);
|
||||
expect(isValidBrand(null)).toBe(false);
|
||||
expect(isValidBrand(undefined)).toBe(false);
|
||||
// Test invalid profiles
|
||||
expect(isValidProfile('invalid')).toBe(false);
|
||||
expect(isValidProfile('')).toBe(false);
|
||||
expect(isValidProfile(null)).toBe(false);
|
||||
expect(isValidProfile(undefined)).toBe(false);
|
||||
});
|
||||
|
||||
it('should return correct brand profiles with getBrandProfile', () => {
|
||||
BRAND_RULE_OPTIONS.forEach(brand => {
|
||||
const profile = getBrandProfile(brand);
|
||||
expect(profile).toBeDefined();
|
||||
expect(profile.brandName.toLowerCase()).toBe(brand);
|
||||
it('should return correct rules profile with getRulesProfile', () => {
|
||||
// Test valid profiles
|
||||
RULES_PROFILES.forEach((profile) => {
|
||||
const profileConfig = getRulesProfile(profile);
|
||||
expect(profileConfig).toBeDefined();
|
||||
expect(profileConfig.profileName.toLowerCase()).toBe(profile);
|
||||
});
|
||||
|
||||
// Test invalid brand
|
||||
expect(getBrandProfile('invalid')).toBeUndefined();
|
||||
// Test invalid profile - should return null
|
||||
expect(getRulesProfile('invalid')).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
describe('Brand Profile Structure', () => {
|
||||
it('should have all required properties for each brand profile', () => {
|
||||
BRAND_RULE_OPTIONS.forEach(brand => {
|
||||
const profile = BRAND_PROFILES[brand];
|
||||
|
||||
describe('Profile Structure', () => {
|
||||
it('should have all required properties for each profile', () => {
|
||||
RULES_PROFILES.forEach((profile) => {
|
||||
const profileConfig = getRulesProfile(profile);
|
||||
|
||||
// Check required properties
|
||||
expect(profile).toHaveProperty('brandName');
|
||||
expect(profile).toHaveProperty('conversionConfig');
|
||||
expect(profile).toHaveProperty('fileMap');
|
||||
expect(profile).toHaveProperty('rulesDir');
|
||||
expect(profile).toHaveProperty('brandDir');
|
||||
|
||||
// Verify brand name matches (brandName is capitalized in profiles)
|
||||
expect(profile.brandName.toLowerCase()).toBe(brand);
|
||||
expect(profileConfig).toHaveProperty('profileName');
|
||||
expect(profileConfig).toHaveProperty('conversionConfig');
|
||||
expect(profileConfig).toHaveProperty('fileMap');
|
||||
expect(profileConfig).toHaveProperty('rulesDir');
|
||||
expect(profileConfig).toHaveProperty('profileDir');
|
||||
|
||||
// Check that conversionConfig has required structure
|
||||
expect(profileConfig.conversionConfig).toHaveProperty('profileTerms');
|
||||
expect(profileConfig.conversionConfig).toHaveProperty('toolNames');
|
||||
expect(profileConfig.conversionConfig).toHaveProperty('toolContexts');
|
||||
expect(profileConfig.conversionConfig).toHaveProperty('toolGroups');
|
||||
expect(profileConfig.conversionConfig).toHaveProperty('docUrls');
|
||||
expect(profileConfig.conversionConfig).toHaveProperty('fileReferences');
|
||||
|
||||
// Verify arrays are actually arrays
|
||||
expect(Array.isArray(profileConfig.conversionConfig.profileTerms)).toBe(
|
||||
true
|
||||
);
|
||||
expect(typeof profileConfig.conversionConfig.toolNames).toBe('object');
|
||||
expect(Array.isArray(profileConfig.conversionConfig.toolContexts)).toBe(
|
||||
true
|
||||
);
|
||||
expect(Array.isArray(profileConfig.conversionConfig.toolGroups)).toBe(
|
||||
true
|
||||
);
|
||||
expect(Array.isArray(profileConfig.conversionConfig.docUrls)).toBe(
|
||||
true
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
it('should have valid fileMap with required files for each profile', () => {
|
||||
const expectedFiles = ['cursor_rules.mdc', 'dev_workflow.mdc', 'self_improve.mdc', 'taskmaster.mdc'];
|
||||
|
||||
RULES_PROFILES.forEach((profile) => {
|
||||
const profileConfig = getRulesProfile(profile);
|
||||
|
||||
// Check that fileMap exists and is an object
|
||||
expect(profileConfig.fileMap).toBeDefined();
|
||||
expect(typeof profileConfig.fileMap).toBe('object');
|
||||
expect(profileConfig.fileMap).not.toBeNull();
|
||||
|
||||
// Check that fileMap is not empty
|
||||
const fileMapKeys = Object.keys(profileConfig.fileMap);
|
||||
expect(fileMapKeys.length).toBeGreaterThan(0);
|
||||
|
||||
// Check that all expected source files are defined in fileMap
|
||||
expectedFiles.forEach(expectedFile => {
|
||||
expect(fileMapKeys).toContain(expectedFile);
|
||||
expect(typeof profileConfig.fileMap[expectedFile]).toBe('string');
|
||||
expect(profileConfig.fileMap[expectedFile].length).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
// Verify fileMap has exactly the expected files
|
||||
expect(fileMapKeys.sort()).toEqual(expectedFiles.sort());
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('MCP Configuration Properties', () => {
|
||||
it('should have all required MCP properties for each profile', () => {
|
||||
RULES_PROFILES.forEach((profile) => {
|
||||
const profileConfig = getRulesProfile(profile);
|
||||
|
||||
// Check MCP-related properties exist
|
||||
expect(profileConfig).toHaveProperty('mcpConfig');
|
||||
expect(profileConfig).toHaveProperty('mcpConfigName');
|
||||
expect(profileConfig).toHaveProperty('mcpConfigPath');
|
||||
|
||||
// Check types
|
||||
expect(typeof profileConfig.mcpConfig).toBe('boolean');
|
||||
expect(typeof profileConfig.mcpConfigName).toBe('string');
|
||||
expect(typeof profileConfig.mcpConfigPath).toBe('string');
|
||||
|
||||
// Check that mcpConfigPath is properly constructed
|
||||
expect(profileConfig.mcpConfigPath).toBe(
|
||||
`${profileConfig.profileDir}/${profileConfig.mcpConfigName}`
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
it('should have correct MCP configuration for each profile', () => {
|
||||
const expectedConfigs = {
|
||||
cursor: {
|
||||
mcpConfig: true,
|
||||
mcpConfigName: 'mcp.json',
|
||||
expectedPath: '.cursor/mcp.json'
|
||||
},
|
||||
windsurf: {
|
||||
mcpConfig: true,
|
||||
mcpConfigName: 'mcp.json',
|
||||
expectedPath: '.windsurf/mcp.json'
|
||||
},
|
||||
roo: {
|
||||
mcpConfig: true,
|
||||
mcpConfigName: 'mcp.json',
|
||||
expectedPath: '.roo/mcp.json'
|
||||
},
|
||||
cline: {
|
||||
mcpConfig: false,
|
||||
mcpConfigName: 'cline_mcp_settings.json',
|
||||
expectedPath: '.clinerules/cline_mcp_settings.json'
|
||||
}
|
||||
};
|
||||
|
||||
RULES_PROFILES.forEach((profile) => {
|
||||
const profileConfig = getRulesProfile(profile);
|
||||
const expected = expectedConfigs[profile];
|
||||
|
||||
expect(profileConfig.mcpConfig).toBe(expected.mcpConfig);
|
||||
expect(profileConfig.mcpConfigName).toBe(expected.mcpConfigName);
|
||||
expect(profileConfig.mcpConfigPath).toBe(expected.expectedPath);
|
||||
});
|
||||
});
|
||||
|
||||
it('should have consistent profileDir and mcpConfigPath relationship', () => {
|
||||
RULES_PROFILES.forEach((profile) => {
|
||||
const profileConfig = getRulesProfile(profile);
|
||||
|
||||
// The mcpConfigPath should start with the profileDir
|
||||
expect(profileConfig.mcpConfigPath).toMatch(
|
||||
new RegExp(`^${profileConfig.profileDir.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}/`)
|
||||
);
|
||||
|
||||
// The mcpConfigPath should end with the mcpConfigName
|
||||
expect(profileConfig.mcpConfigPath).toMatch(
|
||||
new RegExp(`${profileConfig.mcpConfigName.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}$`)
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
it('should have unique profile directories', () => {
|
||||
const profileDirs = RULES_PROFILES.map((profile) => {
|
||||
const profileConfig = getRulesProfile(profile);
|
||||
return profileConfig.profileDir;
|
||||
});
|
||||
|
||||
const uniqueProfileDirs = [...new Set(profileDirs)];
|
||||
expect(uniqueProfileDirs).toHaveLength(profileDirs.length);
|
||||
});
|
||||
|
||||
it('should have unique MCP config paths', () => {
|
||||
const mcpConfigPaths = RULES_PROFILES.map((profile) => {
|
||||
const profileConfig = getRulesProfile(profile);
|
||||
return profileConfig.mcpConfigPath;
|
||||
});
|
||||
|
||||
const uniqueMcpConfigPaths = [...new Set(mcpConfigPaths)];
|
||||
expect(uniqueMcpConfigPaths).toHaveLength(mcpConfigPaths.length);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user