/**
 * Properties 路由单元测试
 */
import { describe, it, expect } from 'vitest';
describe('properties route validation', () => {
    it('requires content for write', () => {
        const validateWriteRequest = (body) => {
            if (!body.content || !String(body.content).trim())
                return { valid: false, error: 'content is required' };
            return { valid: true };
        };
        expect(validateWriteRequest({}).valid).toBe(false);
        expect(validateWriteRequest({ content: '' }).valid).toBe(false);
        expect(validateWriteRequest({ content: 'key=value' }).valid).toBe(true);
    });
});
describe('properties file operations', () => {
    it('resolves relative propertiesPath', () => {
        const resolvePath = (workspacePath, propertiesPath) => {
            const defaultPath = '.agentswork/my.properties';
            const resolved = propertiesPath || defaultPath;
            if (workspacePath && !resolved.startsWith('/'))
                return `${workspacePath}/${resolved}`;
            return resolved;
        };
        expect(resolvePath('/project', 'config/app.properties')).toBe('/project/config/app.properties');
        expect(resolvePath('/project')).toBe('/project/.agentswork/my.properties');
    });
    it('parses properties content', () => {
        const parseProperties = (content) => {
            const result = {};
            const lines = content.split('\n');
            for (const line of lines) {
                const trimmed = line.trim();
                if (!trimmed || trimmed.startsWith('#') || trimmed.startsWith('!'))
                    continue;
                const eqIndex = trimmed.indexOf('=');
                if (eqIndex > 0) {
                    result[trimmed.slice(0, eqIndex).trim()] = trimmed.slice(eqIndex + 1).trim();
                }
            }
            return result;
        };
        const props = parseProperties(`
# Comment
agent.role.name=Backend Developer
project.workspace.path=/home/project
    `);
        expect(props['agent.role.name']).toBe('Backend Developer');
        expect(props['project.workspace.path']).toBe('/home/project');
    });
    it('handles empty content', () => {
        const parseProperties = (content) => {
            if (!content.trim())
                return {};
            const result = {};
            const lines = content.split('\n');
            for (const line of lines) {
                const trimmed = line.trim();
                if (!trimmed || trimmed.startsWith('#'))
                    continue;
                const eqIndex = trimmed.indexOf('=');
                if (eqIndex > 0) {
                    result[trimmed.slice(0, eqIndex).trim()] = trimmed.slice(eqIndex + 1).trim();
                }
            }
            return result;
        };
        expect(parseProperties('')).toEqual({});
        expect(parseProperties('# Only comments')).toEqual({});
    });
});
