/**
 * YAML 路由单元测试
 */
import { describe, it, expect } from 'vitest';
describe('yml route validation', () => {
    it('requires workspacePath for read', () => {
        const validateReadRequest = (body) => {
            const normalizedWorkspace = body.workspacePath ? String(body.workspacePath).trim() : '';
            if (!normalizedWorkspace)
                return { valid: false, error: 'workspacePath is required' };
            return { valid: true };
        };
        expect(validateReadRequest({}).valid).toBe(false);
        expect(validateReadRequest({ workspacePath: '/valid/path' }).valid).toBe(true);
    });
    it('requires workspacePath and content for write', () => {
        const validateWriteRequest = (body) => {
            const normalizedWorkspace = body.workspacePath ? String(body.workspacePath).trim() : '';
            if (!normalizedWorkspace)
                return { valid: false, error: 'workspacePath is required' };
            if (!body.content || !String(body.content).trim())
                return { valid: false, error: 'content is required' };
            return { valid: true };
        };
        expect(validateWriteRequest({}).valid).toBe(false);
        expect(validateWriteRequest({ workspacePath: '/path', content: 'test' }).valid).toBe(true);
    });
    it('uses default ymlPath when not provided', () => {
        const resolveYmlPath = (ymlPath) => {
            return ymlPath ? String(ymlPath).trim() || 'vibe-coding/my.yml' : 'vibe-coding/my.yml';
        };
        expect(resolveYmlPath()).toBe('vibe-coding/my.yml');
        expect(resolveYmlPath('custom/path.yml')).toBe('custom/path.yml');
    });
});
describe('response building', () => {
    it('builds correct response for existing file', () => {
        const response = {
            ok: true,
            workspacePath: '/project/workspace',
            filePath: '/project/vibe-coding/my.yml',
            exists: true,
            content: 'agent:\n  - name: test',
        };
        expect(response.ok).toBe(true);
        expect(response.exists).toBe(true);
    });
    it('builds correct response for non-existing file', () => {
        const response = {
            ok: true,
            exists: false,
            fullContent: null,
            isTemplate: true,
        };
        expect(response.exists).toBe(false);
        expect(response.isTemplate).toBe(true);
    });
});
