agent-ecosystem/test/main/ipc/configValidation.test.ts
matt ff0c8cc978 Implement Claude root path configuration and management
- Introduced functionality to select and manage the local Claude root folder, allowing users to specify a custom path.
- Added IPC handlers for selecting the Claude root folder and retrieving its information.
- Enhanced configuration validation to ensure the specified Claude root path is an absolute path.
- Updated the ServiceContext to reconfigure based on changes to the Claude root path, improving context management.
- Refactored related components to support the new Claude root path features, including updates to the UI and state management.
2026-02-14 13:43:56 +09:00

113 lines
3.2 KiB
TypeScript

import { describe, expect, it } from 'vitest';
import * as path from 'path';
import { validateConfigUpdatePayload } from '../../../src/main/ipc/configValidation';
describe('configValidation', () => {
it('accepts valid general updates', () => {
const result = validateConfigUpdatePayload('general', {
theme: 'system',
launchAtLogin: true,
});
expect(result.valid).toBe(true);
if (result.valid) {
expect(result.section).toBe('general');
expect(result.data).toEqual({
theme: 'system',
launchAtLogin: true,
});
}
});
it('accepts absolute general.claudeRootPath updates', () => {
const result = validateConfigUpdatePayload('general', {
claudeRootPath: '/Users/test/.claude',
});
expect(result.valid).toBe(true);
if (result.valid) {
expect(result.section).toBe('general');
expect(result.data).toEqual({
claudeRootPath: path.resolve('/Users/test/.claude'),
});
}
});
it('rejects relative general.claudeRootPath updates', () => {
const result = validateConfigUpdatePayload('general', {
claudeRootPath: '.claude',
});
expect(result.valid).toBe(false);
if (!result.valid) {
expect(result.error).toContain('absolute path');
}
});
it('rejects invalid section names', () => {
const result = validateConfigUpdatePayload('invalid-section', { theme: 'dark' });
expect(result.valid).toBe(false);
if (!result.valid) {
expect(result.error).toContain('Section must be one of');
}
});
it('rejects unknown notification keys', () => {
const result = validateConfigUpdatePayload('notifications', { unknownField: true });
expect(result.valid).toBe(false);
if (!result.valid) {
expect(result.error).toContain('not supported');
}
});
it('accepts valid notifications.triggers payload', () => {
const result = validateConfigUpdatePayload('notifications', {
triggers: [
{
id: 'trigger-1',
name: 'test',
enabled: true,
contentType: 'tool_result',
mode: 'error_status',
requireError: true,
},
],
});
expect(result.valid).toBe(true);
});
it('rejects invalid notifications.triggers payload', () => {
const result = validateConfigUpdatePayload('notifications', {
triggers: [{ id: 'missing-required-fields' }],
});
expect(result.valid).toBe(false);
if (!result.valid) {
expect(result.error).toContain('valid trigger');
}
});
it('rejects out-of-range snoozeMinutes', () => {
const result = validateConfigUpdatePayload('notifications', { snoozeMinutes: 0 });
expect(result.valid).toBe(false);
if (!result.valid) {
expect(result.error).toContain('between 1 and');
}
});
it('accepts valid display updates', () => {
const result = validateConfigUpdatePayload('display', {
compactMode: true,
syntaxHighlighting: false,
});
expect(result.valid).toBe(true);
if (result.valid) {
expect(result.section).toBe('display');
expect(result.data).toEqual({
compactMode: true,
syntaxHighlighting: false,
});
}
});
});