import { describe, it, expect } from 'vitest';
import { encodeWtKey, decodeWtKey } from '../src/wt-key.js';

describe('wt-key', () => {
  it('encode puis decode restitue le chemin (aller-retour)', () => {
    for (const p of ['/home/johan/repo', '/a/b c/é', '/tmp/x-y_z', 'C:/Users/x/proj']) {
      expect(decodeWtKey(encodeWtKey(p))).toBe(p);
    }
  });

  it('un segment base64url ne contient ni %, ni +, ni /, ni =', () => {
    const k = encodeWtKey('/home/johan/mon repo/sous-dossier');
    expect(k).not.toMatch(/[%+/=]/);
  });

  it('décode aussi un chemin percent-encodé (ancien deep-link VS Code)', () => {
    const raw = encodeURIComponent('/home/johan/repo');
    expect(decodeWtKey(raw)).toBe('/home/johan/repo');
  });

  it('ne lève pas sur une clé invalide', () => {
    expect(() => decodeWtKey('!!!not-valid')).not.toThrow();
  });
});
