import { describe, it, expect } from 'vitest';
import { workspaceDirRole } from './workspaceDirs';

describe('workspaceDirRole', () => {
  it('returns a writable role for known top-level dirs', () => {
    for (const name of ['input', 'output', 'logs', 'apps']) {
      const role = workspaceDirRole(name, name, 'directory');
      expect(role, name).not.toBeNull();
      expect(role!.writable).toBe(true);
      expect(role!.label.length).toBeGreaterThan(0);
    }
  });

  it('marks readonly/ as NOT writable (the enforced read-only dir)', () => {
    const role = workspaceDirRole('readonly', 'readonly', 'directory');
    expect(role).not.toBeNull();
    expect(role!.writable).toBe(false);
    expect(role!.label).toBe('閲覧のみ');
  });

  it('returns null for files even if named like a role dir', () => {
    expect(workspaceDirRole('output', 'output', 'file')).toBeNull();
  });

  it('returns null for nested directories (roles only apply at workspace root)', () => {
    expect(workspaceDirRole('output/input', 'input', 'directory')).toBeNull();
    expect(workspaceDirRole('input/readonly', 'readonly', 'directory')).toBeNull();
  });

  it('returns null for unknown top-level dirs', () => {
    expect(workspaceDirRole('misc', 'misc', 'directory')).toBeNull();
  });
});
